diff --git a/fsw/cfe-core/src/es/cfe_es_api.c b/fsw/cfe-core/src/es/cfe_es_api.c index d4d639de1..a5fa86811 100644 --- a/fsw/cfe-core/src/es/cfe_es_api.c +++ b/fsw/cfe-core/src/es/cfe_es_api.c @@ -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); @@ -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__); diff --git a/fsw/cfe-core/unit-test/es_UT.c b/fsw/cfe-core/unit-test/es_UT.c index bff84dc8b..2e006ca34 100644 --- a/fsw/cfe-core/unit-test/es_UT.c +++ b/fsw/cfe-core/unit-test/es_UT.c @@ -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)); @@ -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), @@ -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)); @@ -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),