Skip to content

Commit

Permalink
Fix nasa#915, Check for file existence in CFE_ES_RestartApp
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Jan 27, 2021
1 parent 4374482 commit 79c4210
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 8 deletions.
20 changes: 17 additions & 3 deletions fsw/cfe-core/src/es/cfe_es_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ int32 CFE_ES_ResetCFE(uint32 ResetType)
int32 CFE_ES_RestartApp(CFE_ES_ResourceID_t AppID)
{
int32 ReturnCode = CFE_SUCCESS;
os_fstat_t FileStatus;
CFE_ES_AppRecord_t *AppRecPtr;

AppRecPtr = CFE_ES_LocateAppRecordByID(AppID);
Expand All @@ -196,9 +197,22 @@ int32 CFE_ES_RestartApp(CFE_ES_ResourceID_t AppID)
}
else
{
CFE_ES_SysLogWrite_Unsync("CFE_ES_RestartApp: Restart Application %s Initiated\n",
CFE_ES_AppRecordGetName(AppRecPtr));
AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART;
/*
** Check to see if the file exists
*/
if (OS_stat(AppRecPtr->StartParams.BasicInfo.FileName, &FileStatus) == OS_SUCCESS)
{
CFE_ES_SysLogWrite_Unsync("CFE_ES_RestartApp: Restart Application %s Initiated\n",
CFE_ES_AppRecordGetName(AppRecPtr));
AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART;
}
else
{
CFE_ES_SysLogWrite_Unsync ("CFE_ES_RestartApp: Cannot Restart Application %s, File %s does not exist.\n",
CFE_ES_AppRecordGetName(AppRecPtr), AppRecPtr->StartParams.BasicInfo.FileName);
ReturnCode = CFE_ES_FILE_IO_ERR;
}

}

CFE_ES_UnlockSharedData(__func__,__LINE__);
Expand Down
71 changes: 66 additions & 5 deletions fsw/cfe-core/unit-test/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -3040,6 +3040,21 @@ void TestTask(void)
"CFE_ES_RestartAppCmd",
"Restart application initiated");

/* Test app restart with failed file check */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
UT_SetDefaultReturnValue(UT_KEY(OS_stat), OS_ERROR);
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL);
strncpy(CmdBuf.RestartAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.RestartAppCmd.Payload.Application));
CmdBuf.RestartAppCmd.Payload.Application[sizeof(CmdBuf.RestartAppCmd.Payload.Application) - 1] = '\0';
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.RestartAppCmd),
UT_TPID_CFE_ES_CMD_RESTART_APP_CC);
UT_Report(__FILE__, __LINE__,
UT_EventIsInHistory(CFE_ES_RESTART_APP_ERR1_EID),
"CFE_ES_RestartAppCmd",
"Restart application failed");

/* Test app restart with a bad app name */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
Expand All @@ -3053,10 +3068,10 @@ void TestTask(void)
"CFE_ES_RestartAppCmd",
"Restart application bad name");

/* Test failed app restart */
/* Test failed app restart, core app */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_WAITING, "CFE_ES", NULL, NULL);
ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL);
strncpy(CmdBuf.RestartAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.RestartAppCmd.Payload.Application) - 1);
CmdBuf.RestartAppCmd.Payload.Application[sizeof(CmdBuf.RestartAppCmd.Payload.Application) - 1] = '\0';
Expand All @@ -3067,6 +3082,20 @@ void TestTask(void)
"CFE_ES_RestartAppCmd",
"Restart application failed");

/* Test failed app restart, not running */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_WAITING, "CFE_ES", NULL, NULL);
strncpy(CmdBuf.RestartAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.RestartAppCmd.Payload.Application));
CmdBuf.RestartAppCmd.Payload.Application[sizeof(CmdBuf.RestartAppCmd.Payload.Application) - 1] = '\0';
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.RestartAppCmd),
UT_TPID_CFE_ES_CMD_RESTART_APP_CC);
UT_Report(__FILE__, __LINE__,
UT_EventIsInHistory(CFE_ES_RESTART_APP_ERR1_EID),
"CFE_ES_RestartAppCmd",
"Restart application failed");

/* Test successful app reload */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
Expand All @@ -3084,6 +3113,24 @@ void TestTask(void)
"CFE_ES_ReloadAppCmd",
"Reload application initiated");

/* Test app reload with missing file */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
UT_SetDefaultReturnValue(UT_KEY(OS_stat), OS_ERROR);
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL);
strncpy(CmdBuf.ReloadAppCmd.Payload.AppFileName, "New_Name",
sizeof(CmdBuf.ReloadAppCmd.Payload.AppFileName));
CmdBuf.ReloadAppCmd.Payload.AppFileName[sizeof(CmdBuf.ReloadAppCmd.Payload.AppFileName) - 1] = '\0';
strncpy(CmdBuf.ReloadAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.ReloadAppCmd.Payload.Application));
CmdBuf.ReloadAppCmd.Payload.Application[sizeof(CmdBuf.ReloadAppCmd.Payload.Application) - 1] = '\0';
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.ReloadAppCmd),
UT_TPID_CFE_ES_CMD_RELOAD_APP_CC);
UT_Report(__FILE__, __LINE__,
UT_EventIsInHistory(CFE_ES_RELOAD_APP_ERR1_EID),
"CFE_ES_ReloadAppCmd",
"Reload application failed");

/* Test app reload with a bad app name */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
Expand All @@ -3097,12 +3144,26 @@ void TestTask(void)
"CFE_ES_ReloadAppCmd",
"Reload application bad name");

/* Test failed app reload */
/* Test failed app reload, core app */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_WAITING, "CFE_ES", NULL, NULL);
ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL);
strncpy(CmdBuf.ReloadAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.ReloadAppCmd.Payload.Application) - 1);
sizeof(CmdBuf.ReloadAppCmd.Payload.Application));
CmdBuf.ReloadAppCmd.Payload.Application[sizeof(CmdBuf.ReloadAppCmd.Payload.Application) - 1] = '\0';
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.ReloadAppCmd),
UT_TPID_CFE_ES_CMD_RELOAD_APP_CC);
UT_Report(__FILE__, __LINE__,
UT_EventIsInHistory(CFE_ES_RELOAD_APP_ERR1_EID),
"CFE_ES_ReloadAppCmd",
"Reload application failed");

/* Test failed app reload, not RUNNING */
ES_ResetUnitTest();
memset(&CmdBuf, 0, sizeof(CmdBuf));
ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_WAITING, "CFE_ES", NULL, NULL);
strncpy(CmdBuf.ReloadAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.ReloadAppCmd.Payload.Application));
CmdBuf.ReloadAppCmd.Payload.Application[sizeof(CmdBuf.ReloadAppCmd.Payload.Application) - 1] = '\0';
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.ReloadAppCmd),
UT_TPID_CFE_ES_CMD_RELOAD_APP_CC);
Expand Down

0 comments on commit 79c4210

Please sign in to comment.