Skip to content

Commit

Permalink
Fix #468, Adding coverage for cfe_es_task.c
Browse files Browse the repository at this point in the history
Test the following cases:
- CFE_ES_TaskMain() with a CFE_ES_TaskInit() error
- Query tasks command with valid lib ID
- Error when sending Build Info event
- CFE_ES_GenerateVersionEvents() error when sending mission event
- Loop coverage for CFE_ES_FindConfigKeyValue()
  • Loading branch information
pepepr08 committed Jun 29, 2021
1 parent 9d4fcae commit 07a7430
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
36 changes: 36 additions & 0 deletions modules/es/ut-coverage/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,8 @@ void TestTask(void)
CFE_ES_CDS_RegRec_t * UtCDSRegRecPtr;
CFE_ES_MemPoolRecord_t *UtPoolRecPtr;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
const char * UT_String;
CFE_ConfigKeyValue_t CFE_MODULE_VERSION_TABLE_UT[] = {{"spare", "spare"}, {"Mission", "ut_build"}, {NULL, NULL}};

UtPrintf("Begin Test Task");

Expand All @@ -2107,6 +2109,12 @@ void TestTask(void)
CFE_ES_TaskMain();
CFE_UtAssert_PRINTF(UT_OSP_MESSAGES[UT_OSP_COMMAND_PIPE]);

/* Test task main process with a CFE_ES_TaskInit() error */
ES_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(CFE_EVS_Register), 1, -1);
CFE_ES_TaskMain();
CFE_UtAssert_PRINTF("Application Init Failed");

/* Test task main process loop with bad checksum information */
ES_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(CFE_PSP_GetCFETextSegmentInfo), 1, -1);
Expand Down Expand Up @@ -2477,6 +2485,14 @@ void TestTask(void)
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.QueryAllCmd), UT_TPID_CFE_ES_CMD_QUERY_ALL_CC);
CFE_UtAssert_EVENTSENT(CFE_ES_ALL_APPS_EID);

/* Test Query tasks command with valid lib ID */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL);
CFE_ES_Global.LibTable[0].LibId = CFE_ES_LIBID_C(ES_UT_MakeLibIdForIndex(1));
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.QueryAllCmd), UT_TPID_CFE_ES_CMD_QUERY_ALL_CC);
CFE_UtAssert_EVENTSENT(CFE_ES_ALL_APPS_EID);

/* Test write of all app data to file with a null file name */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
Expand Down Expand Up @@ -2997,6 +3013,26 @@ void TestTask(void)
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.DumpCDSRegistryCmd),
UT_TPID_CFE_ES_CMD_DUMP_CDS_REGISTRY_CC);
CFE_UtAssert_EVENTSENT(CFE_ES_CDS_REG_DUMP_INF_EID);

/* Test error when sending Build Info event */
ES_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(CFE_EVS_SendEvent), 1, CFE_EVS_INVALID_PARAMETER);
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.NoArgsCmd), UT_TPID_CFE_ES_CMD_NOOP_CC);
CFE_UtAssert_PRINTF("Error sending build info event");

/* Test CFE_ES_GenerateVersionEvents error when sending mission event */
ES_ResetUnitTest();
ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, NULL, NULL, NULL);
CFE_ES_Global.ResetDataPtr->ResetVars.ResetType = 1;
UT_SetDeferredRetcode(UT_KEY(CFE_EVS_SendEvent), 3, CFE_EVS_INVALID_PARAMETER);
CFE_ES_TaskInit();
CFE_UtAssert_PRINTF("Error sending mission version event");

/* Test CFE_ES_FindConfigKeyValue loop */
ES_ResetUnitTest();
UT_String = CFE_ES_FindConfigKeyValue(CFE_MODULE_VERSION_TABLE_UT, "Mission");
CFE_UtAssert_STRINGBUF_EQ(UT_String, 8, "ut_build", 8);

} /* end TestTask */

void TestPerf(void)
Expand Down
4 changes: 4 additions & 0 deletions modules/es/ut-coverage/es_UT.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "cfe_version.h"
#include "ut_support.h"
#include "ut_osprintf_stubs.h"
#include "target_config.h"

/* ES unit test functions */
/*****************************************************************************/
Expand Down Expand Up @@ -251,4 +252,7 @@ void TestGenericCounterAPI(void);
void TestGenericPool(void);
void TestLibs(void);

/* Access to internal ES function */
extern const char *CFE_ES_FindConfigKeyValue(const CFE_ConfigKeyValue_t *ConfigList, const char *KeyName);

#endif /* ES_UT_H */

0 comments on commit 07a7430

Please sign in to comment.