Skip to content

Commit

Permalink
Add eeprom_notimpl
Browse files Browse the repository at this point in the history
  • Loading branch information
jphickey committed Aug 1, 2024
1 parent 336b593 commit 71f4897
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 240 deletions.
1 change: 1 addition & 0 deletions unit-test-coverage/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ add_subdirectory(ram_notimpl)
add_subdirectory(ram_direct)
add_subdirectory(port_notimpl)
add_subdirectory(port_direct)
add_subdirectory(eeprom_notimpl)
8 changes: 4 additions & 4 deletions unit-test-coverage/modules/eeprom_notimpl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#
add_definitions(-D_CFE_PSP_MODULE_)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/inc")
include_directories("${CFEPSP_SOURCE_DIR}/fsw/modules/iodriver/inc")
include_directories("${CFEPSP_SOURCE_DIR}/fsw/modules/eeprom_notimpl")
#include_directories("${CFEPSP_SOURCE_DIR}/fsw/modules/iodriver/inc")
#include_directories("${CFEPSP_SOURCE_DIR}/fsw/modules/eeprom_notimpl")

add_psp_covtest(eeprom_notimpl src/coveragetest-eeprom_notimpl.c
${CFEPSP_SOURCE_DIR}/fsw/modules/eeprom_notimpl/eeprom_notimpl.c
add_psp_covtest(eeprom_notimpl coveragetest-eeprom_notimpl.c
${CFEPSP_SOURCE_DIR}/fsw/modules/eeprom_notimpl/cfe_psp_eeprom_notimpl.c
)
285 changes: 49 additions & 236 deletions unit-test-coverage/modules/eeprom_notimpl/coveragetest-eeprom_notimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,279 +43,92 @@
#include "cfe_psp_config.h"
#include "cfe_psp_module.h"

#include "PCS_arch_ppc_vxPpcLib.h"
extern void eeprom_notimpl_Init(uint32 PspModuleId);

/*
* Reference to the API entry point for the module
*/
extern CFE_PSP_ModuleApi_t CFE_PSP_timebase_vxworks_API;

const CFE_PSP_ModuleApi_t *TgtAPI = &CFE_PSP_timebase_vxworks_API;

UT_PSP_TimeBase_VxWorks_TestConfig_t UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG;

typedef struct
void Test_eeprom_notimpl_Init(void)
{
uint32 u;
uint32 l;
} PSP_VxWorks_TimeBaseVal_t;
/*
void eeprom_notimpl_Init(uint32 PspModuleId)
*/

void ModuleTest_ResetState(void)
{
memset(&UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG, 0, sizeof(UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG));
UtAssert_VOIDCALL(eeprom_notimpl_Init(1));
}

int32 UTHOOK_vxTimeBaseGet(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context)
void Test_CFE_PSP_EepromWrite32(void)
{
PSP_VxWorks_TimeBaseVal_t *val = UserObj;
uint32 * u = UT_Hook_GetArgValueByName(Context, "u", uint32 *);
uint32 * l = UT_Hook_GetArgValueByName(Context, "l", uint32 *);

*u = val->u;
*l = val->l;

return StubRetcode;
/*
int32 CFE_PSP_EepromWrite32(cpuaddr MemoryAddress, uint32 uint32Value)
*/
UtAssert_INT32_EQ(CFE_PSP_EepromWrite32(0, 1), CFE_PSP_ERROR_NOT_IMPLEMENTED);
}

void Test_Nominal(void)
void Test_CFE_PSP_EepromWrite16(void)
{
OS_time_t OsTime;
PSP_VxWorks_TimeBaseVal_t VxTime;

memset(&OsTime, 0, sizeof(OsTime));

/* Nominal test with a simple 1:1 ratio */
UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodNumerator = 1;
UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodDenominator = 1;
TgtAPI->Init(0);
UtAssert_UINT32_EQ(CFE_PSP_GetTimerTicksPerSecond(), 1000000000);

/* Check operation of CFE_PSP_GetTime() */
UT_SetHookFunction(UT_KEY(PCS_vxTimeBaseGet), UTHOOK_vxTimeBaseGet, &VxTime);
VxTime.u = 0;
VxTime.l = 10000;
CFE_PSP_GetTime(&OsTime);

UtAssert_UINT32_EQ(OS_TimeGetNanosecondsPart(OsTime), 10000);
/*
int32 CFE_PSP_EepromWrite16(cpuaddr MemoryAddress, uint16 uint16Value)
*/
UtAssert_INT32_EQ(CFE_PSP_EepromWrite16(0, 1), CFE_PSP_ERROR_NOT_IMPLEMENTED);
}

void Test_Non_Reducible(void)
void Test_CFE_PSP_EepromWrite8(void)
{
OS_time_t OsTime;
PSP_VxWorks_TimeBaseVal_t VxTime;
int64 TestTime;

memset(&OsTime, 0, sizeof(OsTime));

/* Use an oddball ratio of of some primes, will not be reducible */
/* Ratio is 43*3 / 53*2 => 129/106 */
/* This translates to about ~1.217ns per tick */
UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodNumerator = 43 * 3;
UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodDenominator = 53 * 2;
TgtAPI->Init(0);
UtAssert_UINT32_EQ(CFE_PSP_GetTimerTicksPerSecond(), 821705426);

/*
* Check operation of CFE_PSP_GetTime()
*
* This test requires that the conversion uses the actual ratio,
* otherwise a rounding error will be noticed.
* For example:
* Conversion using 1.217ns/tick yields 52269758 usec (wrong).
* Conversion using actual ratio yields 52268947 usec.
*/

UT_SetHookFunction(UT_KEY(PCS_vxTimeBaseGet), UTHOOK_vxTimeBaseGet, &VxTime);
VxTime.u = 10;
VxTime.l = 5000;
CFE_PSP_GetTime(&OsTime);

TestTime = OS_TimeGetTotalMicroseconds(OsTime);
UtAssert_True(TestTime == 52268947, "CFE_PSP_GetTime() Microseconds (%lld) == 52268947", (long long)TestTime);
int32 CFE_PSP_EepromWrite8(cpuaddr MemoryAddress, uint8 ByteValue)
*/
UtAssert_INT32_EQ(CFE_PSP_EepromWrite8(0, 1), CFE_PSP_ERROR_NOT_IMPLEMENTED);
}

void Test_Reducible_1(void)
void Test_CFE_PSP_EepromWriteEnable(void)
{
OS_time_t OsTime;
PSP_VxWorks_TimeBaseVal_t VxTime;
int64 TestTime;

memset(&OsTime, 0, sizeof(OsTime));

/* Test with a ratio that is also 1:1, but can be reduced */
UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodNumerator = 1000;
UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodDenominator = 1000;
TgtAPI->Init(0);
UtAssert_UINT32_EQ(CFE_PSP_GetTimerTicksPerSecond(), 1000000000);

/*
* Check operation of CFE_PSP_GetTime()
*
* Externally calculated value should be 10376293541461622 usec.
* If overflow occurs then value will be wrong.
*/
UT_SetHookFunction(UT_KEY(PCS_vxTimeBaseGet), UTHOOK_vxTimeBaseGet, &VxTime);
VxTime.u = 0x90000000; /* nearing 64-bit limit */
VxTime.l = 0;
CFE_PSP_GetTime(&OsTime);

TestTime = OS_TimeGetTotalMicroseconds(OsTime);
UtAssert_True(TestTime == 10376293541461622, "CFE_PSP_GetTime() Microseconds (%lld) == 10376293541461622",
(long long)TestTime);
int32 CFE_PSP_EepromWriteEnable(uint32 Bank)
*/
UtAssert_INT32_EQ(CFE_PSP_EepromWriteEnable(1), CFE_PSP_ERROR_NOT_IMPLEMENTED);
}

void Test_Reducible_2(void)
void Test_CFE_PSP_EepromWriteDisable(void)
{
OS_time_t OsTime;
PSP_VxWorks_TimeBaseVal_t VxTime;
int64 TestTime;

memset(&OsTime, 0, sizeof(OsTime));

/* Test with a ratio that can be reduced */
/* Final reduced ratio should be 12:5 with 100ns OS ticks */
UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodNumerator = 84000;
UT_PSP_TIMEBASE_VXWORKS_TESTCONFIG.PeriodDenominator = 350;
TgtAPI->Init(0);
UtAssert_UINT32_EQ(CFE_PSP_GetTimerTicksPerSecond(), 4166666);

/*
* Check operation of CFE_PSP_GetTime()
*
* Externally calculated value should be 276701161105643274 usec.
* If overflow occurs then value will be wrong.
*/
UT_SetHookFunction(UT_KEY(PCS_vxTimeBaseGet), UTHOOK_vxTimeBaseGet, &VxTime);
VxTime.u = 0x10000000; /* nearing 64-bit limit */
VxTime.l = 0;
CFE_PSP_GetTime(&OsTime);

TestTime = OS_TimeGetTotalMicroseconds(OsTime);
UtAssert_True(TestTime == 276701161105643274, "CFE_PSP_GetTime() Microseconds(%lld) == 276701161105643274",
(long long)TestTime);
int32 CFE_PSP_EepromWriteDisable(uint32 Bank)
*/
UtAssert_INT32_EQ(CFE_PSP_EepromWriteDisable(1), CFE_PSP_ERROR_NOT_IMPLEMENTED);
}

void Test_Rollover(void)
void Test_CFE_PSP_EepromPowerUp(void)
{
/* This function always returns 0 */
UtAssert_UINT32_EQ(CFE_PSP_GetTimerLow32Rollover(), 0);
/*
int32 CFE_PSP_EepromPowerUp(uint32 Bank)
*/
UtAssert_INT32_EQ(CFE_PSP_EepromPowerUp(1), CFE_PSP_ERROR_NOT_IMPLEMENTED);
}

/******************************************************************************
**
** Purpose:
** Provides a common interface to system timebase. This routine
** is in the BSP because it is sometimes implemented in hardware and
** sometimes taken care of by the RTOS.
**
** Arguments:
**
** Return:
** Timebase register value
*/
void Test_Get_Timebase(void)
void Test_CFE_PSP_EepromPowerDown(void)
{
PSP_VxWorks_TimeBaseVal_t VxTime;
uint32 tbu;
uint32 tbl;

/* The value from vxTimeBaseGet() should be passed through unchanged */
UT_SetHookFunction(UT_KEY(PCS_vxTimeBaseGet), UTHOOK_vxTimeBaseGet, &VxTime);
VxTime.u = 0x00112233;
VxTime.l = 0x44556677;
/*
int32 CFE_PSP_EepromPowerDown(uint32 Bank)
*/
UtAssert_INT32_EQ(CFE_PSP_EepromPowerDown(1), CFE_PSP_ERROR_NOT_IMPLEMENTED);
}

CFE_PSP_Get_Timebase(&tbu, &tbl);

UtAssert_UINT32_EQ(tbu, VxTime.u);
UtAssert_UINT32_EQ(tbl, VxTime.l);
}

/*
* Macro to add a test case to the list of tests to execute
*/
#define ADD_TEST(test) UtTest_Add(test, ModuleTest_ResetState, NULL, #test)
#define ADD_TEST(test) UtTest_Add(test, NULL, NULL, #test)


/*
* Register the test cases to execute with the unit test tool
*/
void UtTest_Setup(void)
{
ADD_TEST(Test_Nominal);
ADD_TEST(Test_Non_Reducible);
ADD_TEST(Test_Reducible_1);
ADD_TEST(Test_Reducible_2);
ADD_TEST(Test_Rollover);
ADD_TEST(Test_Get_Timebase);
}
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/**
* \file
*
* A PSP module to satisfy the "EEPROM" API on systems which
* do not have an EEPROM or otherwise cannot access it.
*
* All functions return CFE_PSP_ERR_NOT_IMPLEMENTED
*/

#include "cfe_psp.h"
#include "cfe_psp_module.h"

CFE_PSP_MODULE_DECLARE_SIMPLE(eeprom_notimpl);

void eeprom_notimpl_Init(uint32 PspModuleId)
{
/* Inform the user that this module is in use */
printf("CFE_PSP: EEPROM access not implemented\n");
}

int32 CFE_PSP_EepromWrite32(cpuaddr MemoryAddress, uint32 uint32Value)
{
return CFE_PSP_ERROR_NOT_IMPLEMENTED;
}

int32 CFE_PSP_EepromWrite16(cpuaddr MemoryAddress, uint16 uint16Value)
{
return CFE_PSP_ERROR_NOT_IMPLEMENTED;
}

int32 CFE_PSP_EepromWrite8(cpuaddr MemoryAddress, uint8 ByteValue)
{
return CFE_PSP_ERROR_NOT_IMPLEMENTED;
}

int32 CFE_PSP_EepromWriteEnable(uint32 Bank)
{
return CFE_PSP_ERROR_NOT_IMPLEMENTED;
}

int32 CFE_PSP_EepromWriteDisable(uint32 Bank)
{
return CFE_PSP_ERROR_NOT_IMPLEMENTED;
}

int32 CFE_PSP_EepromPowerUp(uint32 Bank)
{
return CFE_PSP_ERROR_NOT_IMPLEMENTED;
}

int32 CFE_PSP_EepromPowerDown(uint32 Bank)
{
return CFE_PSP_ERROR_NOT_IMPLEMENTED;
ADD_TEST(Test_eeprom_notimpl_Init);
ADD_TEST(Test_CFE_PSP_EepromWrite32);
ADD_TEST(Test_CFE_PSP_EepromWrite16);
ADD_TEST(Test_CFE_PSP_EepromWrite8);
ADD_TEST(Test_CFE_PSP_EepromWriteEnable);
ADD_TEST(Test_CFE_PSP_EepromWriteDisable);
ADD_TEST(Test_CFE_PSP_EepromPowerUp);
ADD_TEST(Test_CFE_PSP_EepromPowerDown);
}

0 comments on commit 71f4897

Please sign in to comment.