Skip to content

Commit

Permalink
Fix #465, added UT tests for various ES API functions
Browse files Browse the repository at this point in the history
Test CFE_ES_ReloadApp bad AppID, core app, file doesn't exist
Test CFE_ES_GetAppID: NULL AppID pointer
Test CFE_ES_GetAppIDByName: NULL AppID pointer
Test CFE_ES_GetAppIDByName: NULL name pointer
Test CFE_ES_DeleteChildTask: Task inactive/invalid case
Test CFE_ES_RegisterCDS: NULL handle and NULL name
  • Loading branch information
pepepr08 committed Jun 16, 2021
1 parent a16c78e commit c9797d0
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions modules/es/ut-coverage/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -3738,12 +3738,35 @@ void TestAPI(void)
UT_Report(__FILE__, __LINE__, CFE_ES_RestartApp(AppId) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_RestartApp",
"Application ID too large");

/* Test reloading an app that doesn't exist */
/* Test CFE_ES_ReloadApp with bad AppID argument */
ES_ResetUnitTest();
UtAssert_INT32_EQ(CFE_ES_ReloadApp(CFE_ES_APPID_UNDEFINED, "filename"), CFE_ES_ERR_RESOURCEID_NOT_VALID);

/* Test reloading a core app */
ES_ResetUnitTest();
ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL);
AppId = CFE_ES_AppRecordGetID(UtAppRecPtr);
UtAssert_INT32_EQ(CFE_ES_ReloadApp(AppId, "filename"), CFE_ES_ERR_RESOURCEID_NOT_VALID);

/* Test reloading an app that is currently not running */
ES_ResetUnitTest();
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_STOPPED, NULL, &UtAppRecPtr, NULL);
AppId = CFE_ES_AppRecordGetID(UtAppRecPtr);
UT_Report(__FILE__, __LINE__, CFE_ES_ReloadApp(AppId, "filename") == CFE_ES_ERR_RESOURCEID_NOT_VALID,
"CFE_ES_ReloadApp", "Bad application ID");
"CFE_ES_ReloadApp", "App not running");

/* Test success initiating an app reload */
ES_ResetUnitTest();
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL);
AppId = CFE_ES_AppRecordGetID(UtAppRecPtr);
UtAssert_INT32_EQ(CFE_ES_ReloadApp(AppId, "filename"), CFE_SUCCESS);

/* Test Reload app: file doesn't exist*/
ES_ResetUnitTest();
UT_SetDefaultReturnValue(UT_KEY(OS_stat), OS_ERROR);
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL);
AppId = CFE_ES_AppRecordGetID(UtAppRecPtr);
UtAssert_INT32_EQ(CFE_ES_ReloadApp(AppId, "missingfile"), CFE_ES_FILE_IO_ERR);

/* Test deleting an app that doesn't exist */
ES_ResetUnitTest();
Expand Down Expand Up @@ -3855,6 +3878,19 @@ void TestAPI(void)
UT_Report(__FILE__, __LINE__, CFE_ES_GetTaskID(&TaskId) == CFE_SUCCESS, "CFE_ES_GetTaskID",
"Get task ID by context successful");

/* Test CFE_ES_GetAppID error with null pointer parameter */
ES_ResetUnitTest();
UtAssert_INT32_EQ(CFE_ES_GetAppID(NULL), CFE_ES_BAD_ARGUMENT);

/* Test CFE_ES_GetAppIDByName error with null AppID pointer and valid name */
ES_ResetUnitTest();
UtAssert_INT32_EQ(CFE_ES_GetAppIDByName(NULL, "UT"), CFE_ES_BAD_ARGUMENT);

/* Test CFE_ES_GetAppIDByName error with valid AppID and NULL name */
ES_ResetUnitTest();
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", NULL, NULL);
UtAssert_INT32_EQ(CFE_ES_GetAppIDByName(&AppId, NULL), CFE_ES_BAD_ARGUMENT);

/* Test getting the app name with a bad app ID */
ES_ResetUnitTest();
AppId = CFE_ES_APPID_C(ES_UT_MakeAppIdForIndex(99999));
Expand Down Expand Up @@ -3987,6 +4023,13 @@ void TestAPI(void)
CFE_ES_TaskEntryPoint();
UtAssert_STUB_COUNT(ES_UT_TaskFunction, 1);

/* Test deleting a child task when task is not active/valid */
ES_ResetUnitTest();
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", NULL, &UtTaskRecPtr);
TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr);
UtTaskRecPtr->TaskId = TaskId + 1; /* UtTaskRecPtr->TaskId shouldn't match the Child Task ID */
UtAssert_INT32_EQ(CFE_ES_DeleteChildTask(TaskId), CFE_ES_ERR_RESOURCEID_NOT_VALID);

/* Test deleting a child task using a main task's ID */
ES_ResetUnitTest();
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", NULL, &UtTaskRecPtr);
Expand Down Expand Up @@ -4411,6 +4454,14 @@ void TestCDS()
UT_Report(__FILE__, __LINE__, CFE_ES_CDS_CacheFlush(&CFE_ES_Global.CDSVars.Cache) == CFE_ES_CDS_ACCESS_ERROR,
"CFE_ES_CDS_CacheFlush", "Access Error");

/* Test CDS registering with null Handle pointer */
ES_ResetUnitTest();
UtAssert_INT32_EQ(CFE_ES_RegisterCDS(NULL, 4, "Name3"), CFE_ES_BAD_ARGUMENT);

/* Test CDS registering with null name */
ES_ResetUnitTest();
UtAssert_INT32_EQ(CFE_ES_RegisterCDS(&CDSHandle, 4, NULL), CFE_ES_BAD_ARGUMENT);

/* Test CDS registering with a write CDS failure */
ES_ResetUnitTest();
ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", NULL, NULL);
Expand Down

0 comments on commit c9797d0

Please sign in to comment.