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 25, 2021
1 parent c7363c8 commit 40d5b81
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 7 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
64 changes: 60 additions & 4 deletions fsw/cfe-core/unit-test/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,20 @@ 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((char *) CmdBuf.RestartAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.RestartAppCmd.Payload.Application));
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 @@ -3062,10 +3076,23 @@ 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((char *) CmdBuf.RestartAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.RestartAppCmd.Payload.Application));
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 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((char *) CmdBuf.RestartAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.RestartAppCmd.Payload.Application));
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.RestartAppCmd),
Expand All @@ -3090,6 +3117,22 @@ 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((char *) CmdBuf.ReloadAppCmd.Payload.AppFileName, "New_Name",
sizeof(CmdBuf.ReloadAppCmd.Payload.AppFileName));
strncpy((char *) CmdBuf.ReloadAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.ReloadAppCmd.Payload.Application));
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 @@ -3102,10 +3145,23 @@ 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((char *) CmdBuf.ReloadAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.ReloadAppCmd.Payload.Application));
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((char *) CmdBuf.ReloadAppCmd.Payload.Application, "CFE_ES",
sizeof(CmdBuf.ReloadAppCmd.Payload.Application));
UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.ReloadAppCmd),
Expand Down

0 comments on commit 40d5b81

Please sign in to comment.