Skip to content

Commit

Permalink
Fix nasa#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 15, 2021
1 parent a16c78e commit a9db63b
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 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,40 @@ 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();
UT_Report(__FILE__, __LINE__,
CFE_ES_ReloadApp(CFE_ES_APPID_UNDEFINED, "filename") == CFE_ES_ERR_RESOURCEID_NOT_VALID,
"CFE_ES_ReloadApp", "Bad application ID");

/* 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);
UT_Report(__FILE__, __LINE__, CFE_ES_ReloadApp(AppId, "filename") == CFE_ES_ERR_RESOURCEID_NOT_VALID,
"CFE_ES_ReloadApp", "Cannot Reload a CORE App");

/* 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);
UT_Report(__FILE__, __LINE__, CFE_ES_ReloadApp(AppId, "filename") == CFE_SUCCESS, "CFE_ES_ReloadApp",
"Reload 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);
UT_Report(__FILE__, __LINE__, CFE_ES_ReloadApp(AppId, "missingfile") == CFE_ES_FILE_IO_ERR, "CFE_ES_ReloadApp",
"File doesn't exist");

/* Test deleting an app that doesn't exist */
ES_ResetUnitTest();
Expand Down Expand Up @@ -3855,6 +3883,22 @@ 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();
UT_Report(__FILE__, __LINE__, CFE_ES_GetAppID(NULL) == CFE_ES_BAD_ARGUMENT, "CFE_ES_GetAppID",
"NULL AppID pointer");

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

/* 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);
UT_Report(__FILE__, __LINE__, CFE_ES_GetAppIDByName(&AppId, NULL) == CFE_ES_BAD_ARGUMENT, "CFE_ES_GetAppIDByName",
"NULL name pointer");

/* 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 +4031,14 @@ 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 */
UT_Report(__FILE__, __LINE__, CFE_ES_DeleteChildTask(TaskId) == CFE_ES_ERR_RESOURCEID_NOT_VALID,
"CFE_ES_DeleteChildTask", "Task ID is not valid/active");

/* 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 +4463,16 @@ 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();
UT_Report(__FILE__, __LINE__, CFE_ES_RegisterCDS(NULL, 4, "Name3") == CFE_ES_BAD_ARGUMENT, "CFE_ES_RegisterCDS",
"NULL handle pointer");

/* Test CDS registering with null name */
ES_ResetUnitTest();
UT_Report(__FILE__, __LINE__, CFE_ES_RegisterCDS(&CDSHandle, 4, NULL) == CFE_ES_BAD_ARGUMENT, "CFE_ES_RegisterCDS",
"NULL name 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 a9db63b

Please sign in to comment.