From 4d3c809ff3e342e61bfe21387bd95ab45c584e6e Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 1 Sep 2020 22:59:37 -0400 Subject: [PATCH 1/6] Fix #797, refactor internal table/id management in ES Introduce wrapper/accessor functions to look up table entries by ID for Executive Services subsystem. __Do not use AppID as a table index__. Note - This does not change existing external APIs and AppIDs are still zero-based uint32. This only changes the internal structures to remove use of ID as an array index, and to use a lookup function to locate the table entry from an ID. All entry access is then performed via the table entry pointer, rather than as an array index. This provides the groundwork for abstract IDs without actually changing anything fundamental about resource IDs. --- fsw/cfe-core/src/es/cfe_es_api.c | 635 +++--- fsw/cfe-core/src/es/cfe_es_apps.c | 404 ++-- fsw/cfe-core/src/es/cfe_es_apps.h | 15 +- fsw/cfe-core/src/es/cfe_es_cds.c | 29 - fsw/cfe-core/src/es/cfe_es_cds.h | 21 - fsw/cfe-core/src/es/cfe_es_erlog.c | 19 +- fsw/cfe-core/src/es/cfe_es_global.h | 215 ++ fsw/cfe-core/src/es/cfe_es_start.c | 75 +- fsw/cfe-core/src/es/cfe_es_task.c | 61 +- fsw/cfe-core/src/es/cfe_esmempool.c | 9 +- fsw/cfe-core/src/inc/cfe_es.h | 119 ++ fsw/cfe-core/unit-test/es_UT.c | 2107 +++++++++----------- fsw/cfe-core/unit-test/es_UT.h | 1 + fsw/cfe-core/unit-test/ut_osprintf_stubs.c | 2 + fsw/cfe-core/unit-test/ut_osprintf_stubs.h | 1 + fsw/cfe-core/ut-stubs/ut_es_stubs.c | 114 +- 16 files changed, 2178 insertions(+), 1649 deletions(-) diff --git a/fsw/cfe-core/src/es/cfe_es_api.c b/fsw/cfe-core/src/es/cfe_es_api.c index c3156f7be..e499c9e88 100644 --- a/fsw/cfe-core/src/es/cfe_es_api.c +++ b/fsw/cfe-core/src/es/cfe_es_api.c @@ -170,8 +170,10 @@ int32 CFE_ES_ResetCFE(uint32 ResetType) int32 CFE_ES_RestartApp(uint32 AppID) { int32 ReturnCode = CFE_SUCCESS; + CFE_ES_AppRecord_t *AppRecPtr; - if ( AppID < CFE_PLATFORM_ES_MAX_APPLICATIONS ) + AppRecPtr = CFE_ES_LocateAppRecordByID(AppID); + if ( AppRecPtr != NULL ) { CFE_ES_LockSharedData(__func__,__LINE__); @@ -179,23 +181,23 @@ int32 CFE_ES_RestartApp(uint32 AppID) /* ** Check to see if the App is an external cFE App. */ - if ( CFE_ES_Global.AppTable[AppID].Type == CFE_ES_AppType_CORE ) + if ( AppRecPtr->Type == CFE_ES_AppType_CORE ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_RestartApp: Cannot Restart a CORE Application: %s.\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name ); + AppRecPtr->StartParams.Name ); ReturnCode = CFE_ES_ERR_APPID; } - else if ( CFE_ES_Global.AppTable[AppID].AppState != CFE_ES_AppState_RUNNING ) + else if ( AppRecPtr->AppState != CFE_ES_AppState_RUNNING ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_RestartApp: Cannot Restart Application %s, It is not running.\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name); + AppRecPtr->StartParams.Name); ReturnCode = CFE_ES_ERR_APPID; } else { CFE_ES_SysLogWrite_Unsync("CFE_ES_RestartApp: Restart Application %s Initiated\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name); - CFE_ES_Global.AppTable[AppID].ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART; + AppRecPtr->StartParams.Name); + AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART; } CFE_ES_UnlockSharedData(__func__,__LINE__); @@ -204,8 +206,8 @@ int32 CFE_ES_RestartApp(uint32 AppID) { ReturnCode = CFE_ES_ERR_APPID; - CFE_ES_WriteToSysLog("CFE_ES_RestartApp: Invalid Application ID received, RC = 0x%08X\n", - (unsigned int) ReturnCode); + CFE_ES_WriteToSysLog("CFE_ES_RestartApp: Invalid Application ID received, AppID = %lu\n", + CFE_ES_ResourceID_ToInteger(AppID)); } /* end if */ @@ -220,22 +222,28 @@ int32 CFE_ES_ReloadApp(uint32 AppID, const char *AppFileName) { int32 ReturnCode = CFE_SUCCESS; os_fstat_t FileStatus; + CFE_ES_AppRecord_t *AppRecPtr = CFE_ES_LocateAppRecordByID(AppID); + + if ( AppRecPtr == NULL ) + { + return CFE_ES_ERR_APPID; + } CFE_ES_LockSharedData(__func__,__LINE__); /* ** Check to see if the App is an external cFE App. */ - if ( CFE_ES_Global.AppTable[AppID].Type == CFE_ES_AppType_CORE ) + if ( AppRecPtr->Type == CFE_ES_AppType_CORE ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_DeleteApp: Cannot Reload a CORE Application: %s.\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name ); + AppRecPtr->StartParams.Name ); ReturnCode = CFE_ES_ERR_APPID; } - else if ( CFE_ES_Global.AppTable[AppID].AppState != CFE_ES_AppState_RUNNING ) + else if ( AppRecPtr->AppState != CFE_ES_AppState_RUNNING ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_ReloadApp: Cannot Reload Application %s, It is not running.\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name); + AppRecPtr->StartParams.Name); ReturnCode = CFE_ES_ERR_APPID; } else @@ -246,14 +254,14 @@ int32 CFE_ES_ReloadApp(uint32 AppID, const char *AppFileName) if (OS_stat(AppFileName, &FileStatus) == OS_SUCCESS) { CFE_ES_SysLogWrite_Unsync("CFE_ES_ReloadApp: Reload Application %s Initiated. New filename = %s\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name, AppFileName); - strncpy((char *)CFE_ES_Global.AppTable[AppID].StartParams.FileName, AppFileName, OS_MAX_PATH_LEN); - CFE_ES_Global.AppTable[AppID].ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RELOAD; + AppRecPtr->StartParams.Name, AppFileName); + strncpy((char *)AppRecPtr->StartParams.FileName, AppFileName, OS_MAX_PATH_LEN); + AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RELOAD; } else { CFE_ES_SysLogWrite_Unsync ("CFE_ES_ReloadApp: Cannot Reload Application %s, File %s does not exist.\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name, + AppRecPtr->StartParams.Name, AppFileName); ReturnCode = CFE_ES_FILE_IO_ERR; } @@ -271,29 +279,35 @@ int32 CFE_ES_ReloadApp(uint32 AppID, const char *AppFileName) int32 CFE_ES_DeleteApp(uint32 AppID) { int32 ReturnCode = CFE_SUCCESS; + CFE_ES_AppRecord_t *AppRecPtr = CFE_ES_LocateAppRecordByID(AppID); + + if ( AppRecPtr == NULL ) + { + return CFE_ES_ERR_APPID; + } CFE_ES_LockSharedData(__func__,__LINE__); /* ** Check to see if the App is an external cFE App. */ - if ( CFE_ES_Global.AppTable[AppID].Type == CFE_ES_AppType_CORE ) + if ( AppRecPtr->Type == CFE_ES_AppType_CORE ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_DeleteApp: Cannot Delete a CORE Application: %s.\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name ); + AppRecPtr->StartParams.Name ); ReturnCode = CFE_ES_ERR_APPID; } - else if ( CFE_ES_Global.AppTable[AppID].AppState != CFE_ES_AppState_RUNNING ) + else if ( AppRecPtr->AppState != CFE_ES_AppState_RUNNING ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_DeleteApp: Cannot Delete Application %s, It is not running.\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name); + AppRecPtr->StartParams.Name); ReturnCode = CFE_ES_ERR_APPID; } else { CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteApp: Delete Application %s Initiated\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name); - CFE_ES_Global.AppTable[AppID].ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; + AppRecPtr->StartParams.Name); + AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; } CFE_ES_UnlockSharedData(__func__,__LINE__); @@ -308,7 +322,7 @@ int32 CFE_ES_DeleteApp(uint32 AppID) void CFE_ES_ExitApp(uint32 ExitStatus) { int32 ReturnCode; - uint32 AppID; + CFE_ES_AppRecord_t *AppRecPtr; CFE_ES_LockSharedData(__func__,__LINE__); @@ -327,8 +341,8 @@ void CFE_ES_ExitApp(uint32 ExitStatus) ExitStatus = CFE_ES_RunStatus_APP_ERROR; } - ReturnCode = CFE_ES_GetAppIDInternal(&AppID); - if ( ReturnCode == CFE_SUCCESS ) + AppRecPtr = CFE_ES_GetAppRecordByContext(); + if ( AppRecPtr != NULL ) { /* * Set the status in the global table. @@ -340,15 +354,15 @@ void CFE_ES_ExitApp(uint32 ExitStatus) * part of an orderly shutdown caused by that request, and therefore it * should not be overwritten here. */ - if (CFE_ES_Global.AppTable[AppID].ControlReq.AppControlRequest == CFE_ES_RunStatus_APP_RUN) + if (AppRecPtr->ControlReq.AppControlRequest == CFE_ES_RunStatus_APP_RUN) { - CFE_ES_Global.AppTable[AppID].ControlReq.AppControlRequest = ExitStatus; + AppRecPtr->ControlReq.AppControlRequest = ExitStatus; } /* ** Check to see if the App is an external cFE App. */ - if ( CFE_ES_Global.AppTable[AppID].Type == CFE_ES_AppType_CORE ) + if ( AppRecPtr->Type == CFE_ES_AppType_CORE ) { /* ** A core app should only call this function with one of two ExitStatus codes. @@ -356,7 +370,7 @@ void CFE_ES_ExitApp(uint32 ExitStatus) if ( ExitStatus == CFE_ES_RunStatus_CORE_APP_INIT_ERROR ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_ExitApp: CORE Application %s Had an Init Error.\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name ); + AppRecPtr->StartParams.Name ); /* ** Unlock the ES Shared data before calling ResetCFE @@ -383,7 +397,7 @@ void CFE_ES_ExitApp(uint32 ExitStatus) else if ( ExitStatus == CFE_ES_RunStatus_CORE_APP_RUNTIME_ERROR ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_ExitApp: CORE Application %s Had a Runtime Error.\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name ); + AppRecPtr->StartParams.Name ); /* ** Unlock the ES Shared data before killing the main task @@ -403,7 +417,7 @@ void CFE_ES_ExitApp(uint32 ExitStatus) else { CFE_ES_SysLogWrite_Unsync ("CFE_ES_ExitApp, Cannot Exit CORE Application %s\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name ); + AppRecPtr->StartParams.Name ); } } @@ -411,9 +425,9 @@ void CFE_ES_ExitApp(uint32 ExitStatus) { CFE_ES_SysLogWrite_Unsync ("Application %s called CFE_ES_ExitApp\n", - CFE_ES_Global.AppTable[AppID].StartParams.Name); + AppRecPtr->StartParams.Name); - CFE_ES_Global.AppTable[AppID].AppState = CFE_ES_AppState_STOPPED; + AppRecPtr->AppState = CFE_ES_AppState_STOPPED; /* ** Unlock the ES Shared data before suspending the app @@ -443,8 +457,6 @@ void CFE_ES_ExitApp(uint32 ExitStatus) bool CFE_ES_RunLoop(uint32 *RunStatus) { bool ReturnCode; - int32 Status; - uint32 AppID; CFE_ES_AppRecord_t *AppRecPtr; /* @@ -477,14 +489,11 @@ bool CFE_ES_RunLoop(uint32 *RunStatus) CFE_ES_LockSharedData(__func__,__LINE__); /* - ** Get App ID + ** Get App Record */ - Status = CFE_ES_GetAppIDInternal(&AppID); - - if ( Status == CFE_SUCCESS ) + AppRecPtr = CFE_ES_GetAppRecordByContext(); + if ( AppRecPtr != NULL ) { - AppRecPtr = &CFE_ES_Global.AppTable[AppID]; - /* ** App state must be RUNNING (no-op if already set to running) */ @@ -518,7 +527,7 @@ bool CFE_ES_RunLoop(uint32 *RunStatus) /* * Cannot do anything without the AppID */ - CFE_ES_SysLogWrite_Unsync("CFE_ES_RunLoop Error: Cannot get AppID for the caller: RC = %08X\n",(unsigned int)Status); + CFE_ES_SysLogWrite_Unsync("CFE_ES_RunLoop Error: Cannot get AppID for the caller\n"); ReturnCode = false; } /* end if Status == CFE_SUCCESS */ @@ -535,7 +544,7 @@ bool CFE_ES_RunLoop(uint32 *RunStatus) int32 CFE_ES_WaitForSystemState(uint32 MinSystemState, uint32 TimeOutMilliseconds) { int32 Status; - uint32 AppID; + CFE_ES_AppRecord_t *AppRecPtr; uint32 RequiredAppState; uint32 WaitTime; uint32 WaitRemaining; @@ -547,8 +556,12 @@ int32 CFE_ES_WaitForSystemState(uint32 MinSystemState, uint32 TimeOutMillisecond * Determine the implicit app state based on the system state it is indicating */ CFE_ES_LockSharedData(__func__,__LINE__); - Status = CFE_ES_GetAppIDInternal(&AppID); - if ( Status == CFE_SUCCESS ) + + /* + ** Get App Record + */ + AppRecPtr = CFE_ES_GetAppRecordByContext(); + if ( AppRecPtr != NULL ) { RequiredAppState = CFE_ES_AppState_EARLY_INIT; /* @@ -559,7 +572,7 @@ int32 CFE_ES_WaitForSystemState(uint32 MinSystemState, uint32 TimeOutMillisecond * - SYSTEM_STATE_OPERATIONAL requires that all apps are RUNNING * - SYSTEM_STATE_SHUTDOWN requires that all apps are STOPPED (in concept anyway) */ - if (CFE_ES_Global.AppTable[AppID].Type == CFE_ES_AppType_CORE) + if (AppRecPtr->Type == CFE_ES_AppType_CORE) { if (MinSystemState >= CFE_ES_SystemState_CORE_READY) { @@ -585,9 +598,9 @@ int32 CFE_ES_WaitForSystemState(uint32 MinSystemState, uint32 TimeOutMillisecond * apps to add an explicit state change call, but it makes sense because if this was not done an app could * be waiting for itself (which will always time out). */ - if (CFE_ES_Global.AppTable[AppID].AppState < RequiredAppState) + if (AppRecPtr->AppState < RequiredAppState) { - CFE_ES_Global.AppTable[AppID].AppState = RequiredAppState; + AppRecPtr->AppState = RequiredAppState; } } @@ -679,24 +692,34 @@ int32 CFE_ES_RegisterApp(void) int32 CFE_ES_GetAppIDByName(uint32 *AppIdPtr, const char *AppName) { int32 Result = CFE_ES_ERR_APPNAME; + CFE_ES_AppRecord_t *AppRecPtr; uint32 i; + /* + * ensure the output value is set to a safe value, + * in case the does not check the return code. + */ + *AppIdPtr = 0; + CFE_ES_LockSharedData(__func__,__LINE__); /* ** Search the ES Application table for an app with a matching name. */ + AppRecPtr = CFE_ES_Global.AppTable; for ( i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++ ) { - if ( CFE_ES_Global.AppTable[i].AppState != CFE_ES_AppState_UNDEFINED ) + if ( CFE_ES_AppRecordIsUsed(AppRecPtr) ) { - if ( strncmp(AppName, (char *)CFE_ES_Global.AppTable[i].StartParams.Name, OS_MAX_API_NAME) == 0 ) + if ( strncmp(AppName, (char *)AppRecPtr->StartParams.Name, OS_MAX_API_NAME) == 0 ) { - *AppIdPtr = i; + *AppIdPtr = CFE_ES_AppRecordGetID(AppRecPtr); Result = CFE_SUCCESS; break; } } + + ++AppRecPtr; } /* end for */ CFE_ES_UnlockSharedData(__func__,__LINE__); @@ -723,27 +746,54 @@ int32 CFE_ES_GetAppID(uint32 *AppIdPtr) } /* End of CFE_ES_GetAppID() */ +/* +** Function: CFE_ES_GetTaskID - See API and header file for details +*/ +int32 CFE_ES_GetTaskID(uint32 *TaskIdPtr) +{ + int32 Result; + CFE_ES_TaskRecord_t *TaskRecPtr; + + CFE_ES_LockSharedData(__func__,__LINE__); + TaskRecPtr = CFE_ES_GetTaskRecordByContext(); + if (TaskRecPtr == NULL) + { + *TaskIdPtr = 0; + Result = CFE_ES_ERR_TASKID; + } + else + { + *TaskIdPtr = CFE_ES_TaskRecordGetID(TaskRecPtr); + Result = CFE_SUCCESS; + } + CFE_ES_UnlockSharedData(__func__,__LINE__); + return Result; +} + /* ** Function: CFE_ES_GetAppName - See API and header file for details */ int32 CFE_ES_GetAppName(char *AppName, uint32 AppId, uint32 BufferLength) { int32 Result; + CFE_ES_AppRecord_t *AppRecPtr; + + /* + ** Get App Record + */ + AppRecPtr = CFE_ES_LocateAppRecordByID(AppId); CFE_ES_LockSharedData(__func__,__LINE__); - if ( AppId < CFE_PLATFORM_ES_MAX_APPLICATIONS ) + /* + * confirm that the app record is a match, + * which must be done while locked. + */ + if (CFE_ES_AppRecordIsMatch(AppRecPtr, AppId)) { - if ( CFE_ES_Global.AppTable[AppId].AppState != CFE_ES_AppState_UNDEFINED ) - { - strncpy(AppName, (char *)CFE_ES_Global.AppTable[AppId].StartParams.Name, BufferLength - 1); - AppName[BufferLength - 1] = '\0'; - Result = CFE_SUCCESS; - } - else - { - Result = CFE_ES_ERR_APPID; - } + strncpy(AppName, (char *)AppRecPtr->StartParams.Name, BufferLength - 1); + AppName[BufferLength - 1] = '\0'; + Result = CFE_SUCCESS; } else { @@ -776,33 +826,39 @@ int32 CFE_ES_GetAppName(char *AppName, uint32 AppId, uint32 BufferLength) int32 CFE_ES_GetAppInfo(CFE_ES_AppInfo_t *AppInfo, uint32 AppId) { int32 ReturnCode = CFE_SUCCESS; + CFE_ES_AppRecord_t *AppRecPtr; - if ( AppInfo != 0 ) + if ( AppInfo == NULL ) { - if ( AppId < CFE_PLATFORM_ES_MAX_APPLICATIONS ) - { - if ( CFE_ES_Global.AppTable[AppId].AppState != CFE_ES_AppState_UNDEFINED ) - { - CFE_ES_GetAppInfoInternal(AppId, AppInfo); - ReturnCode = CFE_SUCCESS; - } - else - { - CFE_ES_WriteToSysLog("CFE_ES_GetAppInfo: App ID Not Active: %d\n",(int)AppId); - ReturnCode = CFE_ES_ERR_APPID; - } - } - else - { - CFE_ES_WriteToSysLog("CFE_ES_GetAppInfo: App ID Exceeds CFE_ES_APPLICATION_MAX: %d\n",(int)AppId); - ReturnCode = CFE_ES_ERR_APPID; - } + CFE_ES_WriteToSysLog("CFE_ES_GetAppInfo: Invalid Parameter ( Null Pointer )\n"); + return CFE_ES_ERR_BUFFER; } - else + + memset(AppInfo, 0, sizeof(*AppInfo)); + + /* + ** Get App Record + */ + AppRecPtr = CFE_ES_LocateAppRecordByID(AppId); + if ( AppRecPtr == NULL ) { - CFE_ES_WriteToSysLog("CFE_ES_GetAppInfo: Invalid Parameter ( Null Pointer )\n"); - ReturnCode = CFE_ES_ERR_BUFFER; + CFE_ES_WriteToSysLog("CFE_ES_GetAppInfo: App ID Invalid: %lu\n", + (unsigned long)AppId); + return CFE_ES_ERR_APPID; + } + + /* + * Note - cannot check if the AppID is active here, + * as the table is not locked. The internal function + * should lock and check. + */ + ReturnCode = CFE_ES_GetAppInfoInternal(AppRecPtr, AppInfo); + if (ReturnCode != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("CFE_ES_GetAppInfo: App ID Not Active: %lu\n", + CFE_ES_ResourceID_ToInteger(AppId)); } + return(ReturnCode); } /* End of CFE_ES_GetAppInfo() */ @@ -810,71 +866,45 @@ int32 CFE_ES_GetAppInfo(CFE_ES_AppInfo_t *AppInfo, uint32 AppId) /* ** Function: CFE_ES_GetTaskInfo - See API and header file for details */ -int32 CFE_ES_GetTaskInfo(CFE_ES_TaskInfo_t *TaskInfo, uint32 OSTaskId) +int32 CFE_ES_GetTaskInfo(CFE_ES_TaskInfo_t *TaskInfo, uint32 TaskId) { - int32 ReturnCode = CFE_SUCCESS; - uint32 TaskId; + CFE_ES_TaskRecord_t *TaskRecPtr; + int32 ReturnCode; - CFE_ES_LockSharedData(__func__,__LINE__); - - if (OS_ConvertToArrayIndex(OSTaskId, &TaskId) != OS_SUCCESS || TaskId >= OS_MAX_TASKS) + if ( TaskInfo == NULL ) { - CFE_ES_SysLogWrite_Unsync("CFE_ES_GetTaskInfo: Task ID Not Valid: %u\n",(unsigned int)OSTaskId); - ReturnCode = CFE_ES_ERR_TASKID; + CFE_ES_WriteToSysLog("CFE_ES_GetTaskInfo: Invalid Parameter ( Null Pointer )\n"); + return CFE_ES_ERR_BUFFER; } - else if ( CFE_ES_Global.TaskTable[TaskId].RecordUsed == true ) - { - - /* - ** Get the Application ID and Task Name - */ - TaskInfo->AppId = CFE_ES_Global.TaskTable[TaskId].AppId; - strncpy((char *)TaskInfo->TaskName, - (char *)CFE_ES_Global.TaskTable[TaskId].TaskName,OS_MAX_API_NAME); - TaskInfo->TaskName[OS_MAX_API_NAME - 1] = '\0'; - - /* - ** Get the Application Name - */ - if ( CFE_ES_Global.AppTable[TaskInfo->AppId].AppState != CFE_ES_AppState_UNDEFINED ) - { - strncpy((char *)TaskInfo->AppName, - (char *)CFE_ES_Global.AppTable[TaskInfo->AppId].StartParams.Name, - OS_MAX_API_NAME); - TaskInfo->AppName[OS_MAX_API_NAME - 1] = '\0'; - - /* - ** Store away the Task ID ( for the QueryAllTasks Cmd ) - */ - TaskInfo->TaskId = OSTaskId; + memset(TaskInfo, 0, sizeof(*TaskInfo)); - /* - ** Get the Execution counter for the task - */ - TaskInfo->ExecutionCounter = CFE_ES_Global.TaskTable[TaskId].ExecutionCounter; - - ReturnCode = CFE_SUCCESS; - - } - else - { - CFE_ES_SysLogWrite_Unsync("CFE_ES_GetTaskInfo: Task ID:%u Parent App ID:%d not Active.\n", - (unsigned int)OSTaskId,(int)TaskInfo->AppId); - ReturnCode = CFE_ES_ERR_TASKID; - } - } - else + /* + ** Get Task Record + */ + TaskRecPtr = CFE_ES_LocateTaskRecordByID(TaskId); + if ( TaskRecPtr == NULL ) { - CFE_ES_SysLogWrite_Unsync("CFE_ES_GetTaskInfo: Task ID Not Active: %u\n",(unsigned int)OSTaskId); - ReturnCode = CFE_ES_ERR_TASKID; + CFE_ES_WriteToSysLog("CFE_ES_GetTaskInfo: Task ID Not Valid: %lu\n", + CFE_ES_ResourceID_ToInteger(TaskId)); + return CFE_ES_ERR_TASKID; } - CFE_ES_UnlockSharedData(__func__,__LINE__); + /* + * Note - cannot check if the TaskID is active here, + * as the table is not locked. The internal function + * should lock and check. + */ + ReturnCode = CFE_ES_GetTaskInfoInternal(TaskRecPtr, TaskInfo); + if (ReturnCode != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("CFE_ES_GetTaskInfo: Task ID Not Active: %lu\n", + CFE_ES_ResourceID_ToInteger(TaskId)); + } return(ReturnCode); -} /* End of CFE_ES_GetAppName() */ +} /* End of CFE_ES_GetTaskInfo() */ /* @@ -890,10 +920,13 @@ int32 CFE_ES_CreateChildTask(uint32 *TaskIdPtr, { int32 Result; - uint32 AppId= 0xFFFFFFFF; + CFE_ES_AppRecord_t *AppRecPtr; + CFE_ES_TaskRecord_t *TaskRecPtr; int32 ReturnCode; uint32 TaskId; + uint32 ChildTaskId; uint32 ParentTaskId; + uint32 OsalId; /* ** Validate some of the arguments @@ -913,12 +946,12 @@ int32 CFE_ES_CreateChildTask(uint32 *TaskIdPtr, } else if ( TaskName == NULL ) { - CFE_ES_WriteToSysLog("CFE_ES_CreateChildTask: TaskName Parameter is NULL for Task ID %d.\n",(int)(*TaskIdPtr)); + CFE_ES_WriteToSysLog("CFE_ES_CreateChildTask: TaskName Parameter is NULL\n"); ReturnCode = CFE_ES_BAD_ARGUMENT; } else if ( FunctionPtr == NULL ) { - CFE_ES_WriteToSysLog("CFE_ES_CreateChildTask: Function Pointer Parameter is NULL for Task '%s' (ID %d).\n",TaskName,(int)(*TaskIdPtr)); + CFE_ES_WriteToSysLog("CFE_ES_CreateChildTask: Function Pointer Parameter is NULL for Task '%s'\n",TaskName); ReturnCode = CFE_ES_BAD_ARGUMENT; } else @@ -927,13 +960,13 @@ int32 CFE_ES_CreateChildTask(uint32 *TaskIdPtr, CFE_ES_LockSharedData(__func__,__LINE__); /* - ** Get the AppID of the calling Application + ** Get the App Record of the calling Application */ - Result = CFE_ES_GetAppIDInternal(&AppId); - if (Result != CFE_SUCCESS) + AppRecPtr = CFE_ES_GetAppRecordByContext(); + if (AppRecPtr == NULL) { - CFE_ES_SysLogWrite_Unsync("CFE_ES_CreateChildTask: Error calling CFE_ES_GetAppID for Task '%s'. RC = 0x%08X\n",TaskName,(unsigned int)Result); - ReturnCode = Result; + CFE_ES_SysLogWrite_Unsync("CFE_ES_CreateChildTask: Invalid calling context when creating Task '%s'\n",TaskName); + ReturnCode = CFE_ES_ERR_APPID; } else /* else AppId is valid */ { @@ -942,7 +975,7 @@ int32 CFE_ES_CreateChildTask(uint32 *TaskIdPtr, ** TaskID must be the same as the Parent Task ID. */ TaskId = OS_TaskGetId(); - ParentTaskId = CFE_ES_Global.AppTable[AppId].TaskInfo.MainTaskId; + ParentTaskId = AppRecPtr->TaskInfo.MainTaskId; if ( TaskId == ParentTaskId ) { /* @@ -956,7 +989,7 @@ int32 CFE_ES_CreateChildTask(uint32 *TaskIdPtr, /* ** Step 2: Create the new task using the OS API call */ - Result = OS_TaskCreate(TaskIdPtr, TaskName, FunctionPtr, StackPtr, + Result = OS_TaskCreate(&OsalId, TaskName, FunctionPtr, StackPtr, StackSize, Priority, OS_FP_ENABLED ); /* @@ -964,15 +997,16 @@ int32 CFE_ES_CreateChildTask(uint32 *TaskIdPtr, */ if ( Result == OS_SUCCESS ) { - OS_ConvertToArrayIndex(*TaskIdPtr, &TaskId); + ChildTaskId = OsalId; + TaskRecPtr = CFE_ES_LocateTaskRecordByID(ChildTaskId); - CFE_ES_Global.TaskTable[TaskId].RecordUsed = true; - CFE_ES_Global.TaskTable[TaskId].AppId = AppId; - CFE_ES_Global.TaskTable[TaskId].TaskId = *TaskIdPtr; - strncpy((char *)CFE_ES_Global.TaskTable[TaskId].TaskName,TaskName,OS_MAX_API_NAME); - CFE_ES_Global.TaskTable[TaskId].TaskName[OS_MAX_API_NAME - 1] = '\0'; + CFE_ES_TaskRecordSetUsed(TaskRecPtr, ChildTaskId); + TaskRecPtr->AppId = CFE_ES_AppRecordGetID(AppRecPtr); + strncpy((char *)TaskRecPtr->TaskName,TaskName,OS_MAX_API_NAME); + TaskRecPtr->TaskName[OS_MAX_API_NAME - 1] = '\0'; CFE_ES_Global.RegisteredTasks++; + *TaskIdPtr = ChildTaskId; ReturnCode = CFE_SUCCESS; } else @@ -1043,51 +1077,67 @@ int32 CFE_ES_RegisterChildTask(void) */ void CFE_ES_IncrementTaskCounter(void) { - uint32 TaskId; + CFE_ES_TaskRecord_t *TaskRecPtr; + uint32 TaskID; - if (OS_ConvertToArrayIndex(OS_TaskGetId(), &TaskId) == OS_SUCCESS) - { - CFE_ES_Global.TaskTable[TaskId].ExecutionCounter++; - } + /* + * Note this locates a task record but intentionally does _not_ + * lock the global data structure. Locking is avoided for + * efficiency reasons. + * + * As tasks can only increment their own counters, there is no risk + * of concurrent access to the same counter. + * + * Because the global data is not locked, only minimal validation + * is performed. + */ + TaskID = OS_TaskGetId(); + TaskRecPtr = CFE_ES_LocateTaskRecordByID(TaskID); + if (TaskRecPtr != NULL) + { + TaskRecPtr->ExecutionCounter++; + } -} /* End of CFE_ES_ExitChildTask() */ +} /* End of CFE_ES_IncrementTaskCounter() */ /* ** Function: CFE_ES_DeleteChildTask - See API and header file for details */ -int32 CFE_ES_DeleteChildTask(uint32 OSTaskId) +int32 CFE_ES_DeleteChildTask(uint32 TaskId) { + CFE_ES_TaskRecord_t *TaskRecPtr; + CFE_ES_AppRecord_t *AppRecPtr; uint32 i; - uint32 TaskId; bool TaskIsMain = false; int32 ReturnCode = CFE_SUCCESS; int32 OSReturnCode; - /* ** Make sure the task ID is within range */ - if (OS_ConvertToArrayIndex(OSTaskId, &TaskId) == OS_SUCCESS) + TaskRecPtr = CFE_ES_LocateTaskRecordByID(TaskId); + if (TaskRecPtr != NULL) { CFE_ES_LockSharedData(__func__,__LINE__); /* ** Make sure the task is active/valid */ - if (TaskId < OS_MAX_TASKS && CFE_ES_Global.TaskTable[TaskId].RecordUsed == true ) + if (CFE_ES_TaskRecordIsMatch(TaskRecPtr, TaskId)) { /* ** Search for this task ID in the ES App Table to make sure ** it is not a cFE App Main Task */ TaskIsMain = false; + AppRecPtr = CFE_ES_Global.AppTable; for ( i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++ ) { - if ( CFE_ES_Global.AppTable[i].AppState != CFE_ES_AppState_UNDEFINED ) + if ( CFE_ES_AppRecordIsUsed(AppRecPtr) ) { - if ( CFE_ES_Global.AppTable[i].TaskInfo.MainTaskId == OSTaskId ) + if ( AppRecPtr->TaskInfo.MainTaskId == TaskId ) { /* ** Error, the task Id is an App Main Task ID @@ -1096,6 +1146,7 @@ int32 CFE_ES_DeleteChildTask(uint32 OSTaskId) break; } /* end if */ } /* end if */ + ++AppRecPtr; } /* end for */ if ( TaskIsMain == false ) @@ -1103,25 +1154,26 @@ int32 CFE_ES_DeleteChildTask(uint32 OSTaskId) /* ** Can delete the Task */ - OSReturnCode = OS_TaskDelete(OSTaskId); + OSReturnCode = OS_TaskDelete(TaskId); if ( OSReturnCode == OS_SUCCESS ) { /* ** Invalidate the task table entry */ - CFE_ES_Global.TaskTable[TaskId].RecordUsed = false; + CFE_ES_TaskRecordSetFree(TaskRecPtr); CFE_ES_Global.RegisteredTasks--; /* ** Report the task delete */ - CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteChildTask Task %u Deleted\n",(unsigned int)OSTaskId ); + CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteChildTask Task %lu Deleted\n", + CFE_ES_ResourceID_ToInteger(TaskId)); ReturnCode = CFE_SUCCESS; } else { - CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteChildTask Error: Error Calling OS_TaskDelete: Task %u, RC = 0x%08X\n", - (unsigned int)OSTaskId, (unsigned int)OSReturnCode); + CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteChildTask Error: Error Calling OS_TaskDelete: Task %lu, RC = 0x%08X\n", + CFE_ES_ResourceID_ToInteger(TaskId), (unsigned int)OSReturnCode); ReturnCode = CFE_ES_ERR_CHILD_TASK_DELETE; } } @@ -1130,7 +1182,8 @@ int32 CFE_ES_DeleteChildTask(uint32 OSTaskId) /* ** Error: The task is a cFE Application Main task */ - CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteChildTask Error: Task %u is a cFE Main Task.\n",(unsigned int)OSTaskId ); + CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteChildTask Error: Task %lu is a cFE Main Task.\n", + CFE_ES_ResourceID_ToInteger(TaskId)); ReturnCode = CFE_ES_ERR_CHILD_TASK_DELETE_MAIN_TASK; } /* end if TaskMain == false */ } @@ -1139,7 +1192,8 @@ int32 CFE_ES_DeleteChildTask(uint32 OSTaskId) /* ** Task ID is not in use, so it is invalid */ - CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteChildTask Error: Task ID is not active: %u\n",(unsigned int)OSTaskId ); + CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteChildTask Error: Task ID is not active: %lu\n", + CFE_ES_ResourceID_ToInteger(TaskId)); ReturnCode = CFE_ES_ERR_TASKID; } /* end if */ @@ -1152,7 +1206,8 @@ int32 CFE_ES_DeleteChildTask(uint32 OSTaskId) /* ** Task ID is invalid ( too large ) */ - CFE_ES_WriteToSysLog("CFE_ES_DeleteChildTask Error: Invalid Task ID: %u\n",(unsigned int)OSTaskId ); + CFE_ES_WriteToSysLog("CFE_ES_DeleteChildTask Error: Invalid Task ID: %lu\n", + CFE_ES_ResourceID_ToInteger(TaskId)); ReturnCode = CFE_ES_ERR_TASKID; } @@ -1168,10 +1223,8 @@ int32 CFE_ES_DeleteChildTask(uint32 OSTaskId) */ void CFE_ES_ExitChildTask(void) { - uint32 TaskId; - uint32 ParentTaskId; - uint32 AppId; - uint32 ReturnCode; + CFE_ES_AppRecord_t *AppRecPtr; + CFE_ES_TaskRecord_t *TaskRecPtr; CFE_ES_LockSharedData(__func__,__LINE__); @@ -1179,20 +1232,18 @@ void CFE_ES_ExitChildTask(void) ** Check to see if this is being called from a cFE Application's ** main task. */ - TaskId = OS_TaskGetId(); - - ReturnCode = CFE_ES_GetAppIDInternal(&AppId); - if ( ReturnCode == CFE_SUCCESS ) + TaskRecPtr = CFE_ES_GetTaskRecordByContext(); + if ( TaskRecPtr != NULL ) { - ParentTaskId = CFE_ES_Global.AppTable[AppId].TaskInfo.MainTaskId; - if ( TaskId != ParentTaskId ) + AppRecPtr = CFE_ES_LocateAppRecordByID(TaskRecPtr->AppId); + + if ( CFE_ES_AppRecordIsMatch(AppRecPtr, TaskRecPtr->AppId) && + !CFE_ES_TaskRecordIsMatch(TaskRecPtr, AppRecPtr->TaskInfo.MainTaskId)) { - if (OS_ConvertToArrayIndex(TaskId, &TaskId) == OS_SUCCESS) - { /* ** Invalidate the task table entry */ - CFE_ES_Global.TaskTable[TaskId].RecordUsed = false; + CFE_ES_TaskRecordSetFree(TaskRecPtr); CFE_ES_Global.RegisteredTasks--; @@ -1207,18 +1258,16 @@ void CFE_ES_ExitChildTask(void) ** Does not return from OS_TaskExit, except under unit test */ return; - } - } else { - CFE_ES_SysLogWrite_Unsync("CFE_ES_ExitChildTask Error: Cannot Call from a cFE App Main Task. ID = %d\n",(int)TaskId ); + CFE_ES_SysLogWrite_Unsync("CFE_ES_ExitChildTask Error: Cannot Call from a cFE App Main Task. ID = %lu\n", + CFE_ES_ResourceID_ToInteger(CFE_ES_TaskRecordGetID(TaskRecPtr))); } } else { - CFE_ES_SysLogWrite_Unsync("CFE_ES_ExitChildTask Error Calling CFE_ES_GetAppID. Task ID = %d, RC = 0x%08X\n", - (int)TaskId, (unsigned int)ReturnCode ); + CFE_ES_SysLogWrite_Unsync("CFE_ES_ExitChildTask called from invalid task context\n"); } /* end if GetAppId */ CFE_ES_UnlockSharedData(__func__,__LINE__); @@ -1349,17 +1398,17 @@ int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, int32 BlockSize, cons { int32 Status; size_t NameLen = 0; - uint32 ThisAppId = 0; + uint32 ThisAppId; char AppName[OS_MAX_API_NAME] = {"UNKNOWN"}; char CDSName[CFE_ES_CDS_MAX_FULL_NAME_LEN] = {""}; /* Check to make sure calling application is legit */ - Status = CFE_ES_CDS_ValidateAppID(&ThisAppId); + Status = CFE_ES_GetAppID(&ThisAppId); if ( Status != CFE_SUCCESS ) /* Application ID was invalid */ { - CFE_ES_WriteToSysLog("CFE_CDS:Register-Bad AppId(%d)\n", (int)ThisAppId); + CFE_ES_WriteToSysLog("CFE_CDS:Register-Bad AppId context\n"); } else if (CFE_ES_Global.CDSVars.MemPoolSize == 0) { @@ -1600,6 +1649,152 @@ int32 CFE_ES_GetGenCounterIDByName(uint32 *CounterIdPtr, const char *CounterName ** Private API functions */ +/** + * A conversion function to obtain an index value correlating to an AppID + * This is a zero based value that can be used for indexing into a table. + */ +int32 CFE_ES_AppID_ToIndex(uint32 AppId, uint32 *Idx) +{ + if (AppId >= CFE_PLATFORM_ES_MAX_APPLICATIONS) + { + return CFE_ES_ERR_APPID; + } + + /* + * Currently this is a direct/simple pass through. + * Will evolve in a future rev to make it more safe. + */ + *Idx = AppId; + return CFE_SUCCESS; +} + +/** + * A conversion function to obtain an index value correlating to an TaskID + * This is a zero based value that can be used for indexing into a table. + * + * Task IDs come from OSAL, so this is currently a wrapper around the OSAL converter. + * This is an alias for consistency with the ES AppID paradigm. + */ +int32 CFE_ES_TaskID_ToIndex(uint32 TaskID, uint32 *Idx) +{ + if (OS_ConvertToArrayIndex(TaskID, Idx) != OS_SUCCESS) + { + return CFE_ES_ERR_TASKID; + } + + return CFE_SUCCESS; +} + +/* + * Note - this gets the table entry pointer but does not dereference or + * otherwise check/validate said pointer, as that would have to be done while + * locked. + */ +CFE_ES_AppRecord_t *CFE_ES_LocateAppRecordByID(uint32 AppID) +{ + CFE_ES_AppRecord_t *AppRecPtr; + uint32 Idx; + + if (CFE_ES_AppID_ToIndex(AppID, &Idx) == CFE_SUCCESS) + { + AppRecPtr = &CFE_ES_Global.AppTable[Idx]; + } + else + { + AppRecPtr = NULL; + } + + return AppRecPtr; +} + +/* + * Note - this gets the table entry pointer but does not dereference or + * otherwise check/validate said pointer, as that would have to be done while + * locked. + */ +CFE_ES_TaskRecord_t *CFE_ES_LocateTaskRecordByID(uint32 TaskID) +{ + CFE_ES_TaskRecord_t *TaskRecPtr; + uint32 Idx; + + if (CFE_ES_TaskID_ToIndex(TaskID, &Idx) == CFE_SUCCESS) + { + TaskRecPtr = &CFE_ES_Global.TaskTable[Idx]; + } + else + { + TaskRecPtr = NULL; + } + + return TaskRecPtr; +} + +/* + * This function does additional validation on the task record + * and should only be called when global data is locked. + */ +CFE_ES_TaskRecord_t *CFE_ES_GetTaskRecordByContext(void) +{ + CFE_ES_TaskRecord_t *TaskRecPtr; + uint32 TaskID; + + /* + ** Use the OS task ID to get the ES task record + */ + TaskID = OS_TaskGetId(); + TaskRecPtr = CFE_ES_LocateTaskRecordByID(TaskID); + + /* + * Confirm that the entry is actually a match (this requires/assumes + * the global data is locked). + * + * If not a match, return NULL. + */ + if (!CFE_ES_TaskRecordIsMatch(TaskRecPtr, TaskID)) + { + TaskRecPtr = NULL; + } + + return TaskRecPtr; +} + +CFE_ES_AppRecord_t *CFE_ES_GetAppRecordByContext(void) +{ + CFE_ES_AppRecord_t *AppRecPtr; + CFE_ES_TaskRecord_t *TaskRecPtr; + + /* + ** Step 1: Get the task record + */ + TaskRecPtr = CFE_ES_GetTaskRecordByContext(); + if (TaskRecPtr != NULL) + { + /* + ** Step 2: get the Application ID for the current task + */ + AppRecPtr = CFE_ES_LocateAppRecordByID(TaskRecPtr->AppId); + + /* + * Confirm that the entry is actually a match (this requires/assumes + * the global data is locked). + * + * If not a match, return NULL. + */ + if (!CFE_ES_AppRecordIsMatch(AppRecPtr, TaskRecPtr->AppId)) + { + AppRecPtr = NULL; + } + } + else + { + AppRecPtr = NULL; + } + + return AppRecPtr; +} + + + /* ** Function: CFE_ES_GetAppIDInternal ** @@ -1609,33 +1804,23 @@ int32 CFE_ES_GetGenCounterIDByName(uint32 *CounterIdPtr, const char *CounterName */ int32 CFE_ES_GetAppIDInternal(uint32 *AppIdPtr) { - int32 Result = CFE_ES_ERR_APPID; - uint32 TaskId; + CFE_ES_AppRecord_t *AppRecPtr; + int32 Result; - /* - ** Step 1: Get the OS task ID - */ - if (OS_ConvertToArrayIndex(OS_TaskGetId(), &TaskId) == OS_SUCCESS) - { - /* - ** Step 2: get the Application ID for the current task - */ - if ( CFE_ES_Global.TaskTable[TaskId].RecordUsed == true ) - { - *AppIdPtr = CFE_ES_Global.TaskTable[TaskId].AppId; - Result = CFE_SUCCESS; - } - else - { - *AppIdPtr = 0; - } /* end if */ - } - else - { - *AppIdPtr = 0; - } /* end if */ + AppRecPtr = CFE_ES_GetAppRecordByContext(); - return(Result); + if (AppRecPtr != NULL) + { + *AppIdPtr = CFE_ES_AppRecordGetID(AppRecPtr); + Result = CFE_SUCCESS; + } + else + { + *AppIdPtr = 0; + Result = CFE_ES_ERR_APPID; + } + + return Result; } /* End of CFE_ES_GetAppIDInternal() */ @@ -1669,8 +1854,8 @@ void CFE_ES_LockSharedData(const char *FunctionName, int32 LineNumber) * NOTE: this is going to write into a buffer that itself * is _supposed_ to be protected by this same mutex. */ - CFE_ES_SysLogWrite_Unsync("ES SharedData Mutex Take Err Stat=0x%x,App=%d,Func=%s,Line=%d\n", - (unsigned int)Status,(int)AppId,FunctionName,(int)LineNumber); + CFE_ES_SysLogWrite_Unsync("ES SharedData Mutex Take Err Stat=0x%x,App=%lu,Func=%s,Line=%d\n", + (unsigned int)Status,CFE_ES_ResourceID_ToInteger(AppId),FunctionName,(int)LineNumber); }/* end if */ @@ -1707,8 +1892,8 @@ void CFE_ES_UnlockSharedData(const char *FunctionName, int32 LineNumber) * NOTE: this is going to write into a buffer that itself * is _supposed_ to be protected by this same mutex. */ - CFE_ES_SysLogWrite_Unsync("ES SharedData Mutex Give Err Stat=0x%x,App=%d,Func=%s,Line=%d\n", - (unsigned int)Status,(int)AppId,FunctionName,(int)LineNumber); + CFE_ES_SysLogWrite_Unsync("ES SharedData Mutex Give Err Stat=0x%x,App=%lu,Func=%s,Line=%d\n", + (unsigned int)Status,CFE_ES_ResourceID_ToInteger(AppId),FunctionName,(int)LineNumber); }/* end if */ diff --git a/fsw/cfe-core/src/es/cfe_es_apps.c b/fsw/cfe-core/src/es/cfe_es_apps.c index abf4e929c..444150ea8 100644 --- a/fsw/cfe-core/src/es/cfe_es_apps.c +++ b/fsw/cfe-core/src/es/cfe_es_apps.c @@ -365,8 +365,10 @@ int32 CFE_ES_AppCreate(uint32 *ApplicationIdPtr, int32 ReturnCode; uint32 i; bool AppSlotFound; - uint32 TaskId; uint32 ModuleId; + uint32 MainTaskId; + CFE_ES_AppRecord_t *AppRecPtr; + CFE_ES_TaskRecord_t *TaskRecPtr; /* * The FileName must not be NULL @@ -381,16 +383,18 @@ int32 CFE_ES_AppCreate(uint32 *ApplicationIdPtr, */ CFE_ES_LockSharedData(__func__,__LINE__); AppSlotFound = false; + AppRecPtr = CFE_ES_Global.AppTable; for ( i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++ ) { - if ( CFE_ES_Global.AppTable[i].AppState == CFE_ES_AppState_UNDEFINED ) + if ( !CFE_ES_AppRecordIsUsed(AppRecPtr) ) { AppSlotFound = true; - memset ( &(CFE_ES_Global.AppTable[i]), 0, sizeof(CFE_ES_AppRecord_t)); + memset ( AppRecPtr, 0, sizeof(CFE_ES_AppRecord_t)); /* set state EARLY_INIT for OS_TaskCreate below (indicates record is in use) */ - CFE_ES_Global.AppTable[i].AppState = CFE_ES_AppState_EARLY_INIT; + CFE_ES_AppRecordSetUsed(AppRecPtr, i); break; } + ++AppRecPtr; } CFE_ES_UnlockSharedData(__func__,__LINE__); @@ -416,7 +420,7 @@ int32 CFE_ES_AppCreate(uint32 *ApplicationIdPtr, (const char*)EntryPointData, (unsigned int)ReturnCode); CFE_ES_LockSharedData(__func__,__LINE__); - CFE_ES_Global.AppTable[i].AppState = CFE_ES_AppState_UNDEFINED; /* Release slot */ + CFE_ES_AppRecordSetFree(AppRecPtr); /* Release slot */ CFE_ES_UnlockSharedData(__func__,__LINE__); /* Unload the module from memory, so that it does not consume resources */ @@ -436,7 +440,7 @@ int32 CFE_ES_AppCreate(uint32 *ApplicationIdPtr, FileName, (unsigned int)ReturnCode); CFE_ES_LockSharedData(__func__,__LINE__); - CFE_ES_Global.AppTable[i].AppState = CFE_ES_AppState_UNDEFINED; /* Release slot */ + CFE_ES_AppRecordSetFree(AppRecPtr); /* Release slot */ CFE_ES_UnlockSharedData(__func__,__LINE__); return(CFE_ES_ERR_APP_CREATE); @@ -449,43 +453,43 @@ int32 CFE_ES_AppCreate(uint32 *ApplicationIdPtr, /* ** Allocate and populate the ES_AppTable entry */ - CFE_ES_Global.AppTable[i].Type = CFE_ES_AppType_EXTERNAL; + AppRecPtr->Type = CFE_ES_AppType_EXTERNAL; /* ** Fill out the parameters in the AppStartParams sub-structure */ - strncpy((char *)CFE_ES_Global.AppTable[i].StartParams.Name, AppName, OS_MAX_API_NAME); - CFE_ES_Global.AppTable[i].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; + strncpy((char *)AppRecPtr->StartParams.Name, AppName, OS_MAX_API_NAME); + AppRecPtr->StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; - strncpy((char *)CFE_ES_Global.AppTable[i].StartParams.EntryPoint, (const char *)EntryPointData, OS_MAX_API_NAME); - CFE_ES_Global.AppTable[i].StartParams.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; - strncpy((char *)CFE_ES_Global.AppTable[i].StartParams.FileName, FileName, OS_MAX_PATH_LEN); - CFE_ES_Global.AppTable[i].StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *)AppRecPtr->StartParams.EntryPoint, (const char *)EntryPointData, OS_MAX_API_NAME); + AppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; + strncpy((char *)AppRecPtr->StartParams.FileName, FileName, OS_MAX_PATH_LEN); + AppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - CFE_ES_Global.AppTable[i].StartParams.StackSize = StackSize; + AppRecPtr->StartParams.StackSize = StackSize; - CFE_ES_Global.AppTable[i].StartParams.StartAddress = StartAddr; - CFE_ES_Global.AppTable[i].StartParams.ModuleId = ModuleId; + AppRecPtr->StartParams.StartAddress = StartAddr; + AppRecPtr->StartParams.ModuleId = ModuleId; - CFE_ES_Global.AppTable[i].StartParams.ExceptionAction = ExceptionAction; - CFE_ES_Global.AppTable[i].StartParams.Priority = Priority; + AppRecPtr->StartParams.ExceptionAction = ExceptionAction; + AppRecPtr->StartParams.Priority = Priority; /* ** Fill out the Task Info */ - strncpy((char *)CFE_ES_Global.AppTable[i].TaskInfo.MainTaskName, AppName, OS_MAX_API_NAME); - CFE_ES_Global.AppTable[i].TaskInfo.MainTaskName[OS_MAX_API_NAME - 1] = '\0'; + strncpy((char *)AppRecPtr->TaskInfo.MainTaskName, AppName, OS_MAX_API_NAME); + AppRecPtr->TaskInfo.MainTaskName[OS_MAX_API_NAME - 1] = '\0'; /* ** Fill out the Task State info */ - CFE_ES_Global.AppTable[i].ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[i].ControlReq.AppTimerMsec = 0; + AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; + AppRecPtr->ControlReq.AppTimerMsec = 0; /* ** Create the primary task for the newly loaded task */ - ReturnCode = OS_TaskCreate(&CFE_ES_Global.AppTable[i].TaskInfo.MainTaskId, /* task id */ + ReturnCode = OS_TaskCreate(&MainTaskId, /* task id */ AppName, /* task name */ (osal_task_entry)StartAddr, /* task function pointer */ NULL, /* stack pointer */ @@ -499,7 +503,7 @@ int32 CFE_ES_AppCreate(uint32 *ApplicationIdPtr, CFE_ES_SysLogWrite_Unsync("ES Startup: AppCreate Error: TaskCreate %s Failed. EC = 0x%08X!\n", AppName,(unsigned int)ReturnCode); - CFE_ES_Global.AppTable[i].AppState = CFE_ES_AppState_UNDEFINED; + CFE_ES_AppRecordSetFree(AppRecPtr); /* Release slot */ CFE_ES_UnlockSharedData(__func__,__LINE__); return(CFE_ES_ERR_APP_CREATE); @@ -510,23 +514,20 @@ int32 CFE_ES_AppCreate(uint32 *ApplicationIdPtr, /* ** Record the ES_TaskTable entry */ - OS_ConvertToArrayIndex(CFE_ES_Global.AppTable[i].TaskInfo.MainTaskId, &TaskId); + AppRecPtr->TaskInfo.MainTaskId = MainTaskId; + TaskRecPtr = CFE_ES_LocateTaskRecordByID(AppRecPtr->TaskInfo.MainTaskId); - if ( CFE_ES_Global.TaskTable[TaskId].RecordUsed == true ) + if ( CFE_ES_TaskRecordIsUsed(TaskRecPtr) ) { CFE_ES_SysLogWrite_Unsync("ES Startup: Error: ES_TaskTable slot in use at task creation!\n"); } - else - { - CFE_ES_Global.TaskTable[TaskId].RecordUsed = true; - } - CFE_ES_Global.TaskTable[TaskId].AppId = i; - CFE_ES_Global.TaskTable[TaskId].TaskId = CFE_ES_Global.AppTable[i].TaskInfo.MainTaskId; - strncpy((char *)CFE_ES_Global.TaskTable[TaskId].TaskName, - (char *)CFE_ES_Global.AppTable[i].TaskInfo.MainTaskName,OS_MAX_API_NAME ); - CFE_ES_Global.TaskTable[TaskId].TaskName[OS_MAX_API_NAME - 1]='\0'; + CFE_ES_TaskRecordSetUsed(TaskRecPtr,AppRecPtr->TaskInfo.MainTaskId); + TaskRecPtr->AppId = CFE_ES_AppRecordGetID(AppRecPtr); + strncpy((char *)TaskRecPtr->TaskName, + (char *)AppRecPtr->TaskInfo.MainTaskName,OS_MAX_API_NAME ); + TaskRecPtr->TaskName[OS_MAX_API_NAME - 1]='\0'; CFE_ES_SysLogWrite_Unsync("ES Startup: %s loaded and created\n", AppName); - *ApplicationIdPtr = i; + *ApplicationIdPtr = CFE_ES_AppRecordGetID(AppRecPtr); /* ** Increment the registered App and Registered External Task variables. @@ -818,11 +819,10 @@ bool CFE_ES_RunAppTableScan(uint32 ElapsedTime, void *Arg) ** - cFE Core apps, or ** - Currently running */ + AppPtr = CFE_ES_Global.AppTable; for ( i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++ ) { - AppPtr = &CFE_ES_Global.AppTable[i]; - - if (AppPtr->Type == CFE_ES_AppType_EXTERNAL) + if ( CFE_ES_AppRecordIsUsed(AppPtr) && AppPtr->Type == CFE_ES_AppType_EXTERNAL) { if (AppPtr->AppState > CFE_ES_AppState_RUNNING) { @@ -849,7 +849,7 @@ bool CFE_ES_RunAppTableScan(uint32 ElapsedTime, void *Arg) * control request function for this app. */ CFE_ES_UnlockSharedData(__func__,__LINE__); - CFE_ES_ProcessControlRequest(i); + CFE_ES_ProcessControlRequest(AppPtr); CFE_ES_LockSharedData(__func__,__LINE__); } /* end if */ } @@ -865,6 +865,8 @@ bool CFE_ES_RunAppTableScan(uint32 ElapsedTime, void *Arg) } /* end if */ + ++AppPtr; + } /* end for loop */ CFE_ES_UnlockSharedData(__func__,__LINE__); @@ -886,7 +888,7 @@ bool CFE_ES_RunAppTableScan(uint32 ElapsedTime, void *Arg) ** Purpose: This function will perform the requested control action for an application. **--------------------------------------------------------------------------------------- */ -void CFE_ES_ProcessControlRequest(uint32 AppID) +void CFE_ES_ProcessControlRequest(CFE_ES_AppRecord_t *AppRecPtr) { int32 Status; @@ -896,19 +898,19 @@ void CFE_ES_ProcessControlRequest(uint32 AppID) /* ** First get a copy of the Apps Start Parameters */ - memcpy(&AppStartParams, &(CFE_ES_Global.AppTable[AppID].StartParams), sizeof(CFE_ES_AppStartParams_t)); + memcpy(&AppStartParams, &(AppRecPtr->StartParams), sizeof(CFE_ES_AppStartParams_t)); /* ** Now, find out what kind of Application control is being requested */ - switch ( CFE_ES_Global.AppTable[AppID].ControlReq.AppControlRequest ) + switch ( AppRecPtr->ControlReq.AppControlRequest ) { case CFE_ES_RunStatus_APP_EXIT: /* ** Kill the app, and dont restart it */ - Status = CFE_ES_CleanUpApp(AppID); + Status = CFE_ES_CleanUpApp(AppRecPtr); if ( Status == CFE_SUCCESS ) { @@ -926,7 +928,7 @@ void CFE_ES_ProcessControlRequest(uint32 AppID) /* ** Kill the app, and dont restart it */ - Status = CFE_ES_CleanUpApp(AppID); + Status = CFE_ES_CleanUpApp(AppRecPtr); if ( Status == CFE_SUCCESS ) { @@ -944,7 +946,7 @@ void CFE_ES_ProcessControlRequest(uint32 AppID) /* ** Kill the app, and dont restart it */ - Status = CFE_ES_CleanUpApp(AppID); + Status = CFE_ES_CleanUpApp(AppRecPtr); if ( Status == CFE_SUCCESS ) { @@ -962,7 +964,7 @@ void CFE_ES_ProcessControlRequest(uint32 AppID) /* ** Kill the app */ - Status = CFE_ES_CleanUpApp(AppID); + Status = CFE_ES_CleanUpApp(AppRecPtr); if ( Status == CFE_SUCCESS ) { @@ -998,7 +1000,7 @@ void CFE_ES_ProcessControlRequest(uint32 AppID) /* ** Kill the app */ - Status = CFE_ES_CleanUpApp(AppID); + Status = CFE_ES_CleanUpApp(AppRecPtr); if ( Status == CFE_SUCCESS ) { @@ -1041,14 +1043,14 @@ void CFE_ES_ProcessControlRequest(uint32 AppID) * Change the request state to DELETE so the next scan will clean * up this table entry. */ - CFE_ES_Global.AppTable[AppID].ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; + AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; break; default: CFE_EVS_SendEvent(CFE_ES_PCR_ERR2_EID, CFE_EVS_EventType_ERROR, "ES_ProcControlReq: Unknown State ( %d ) Application %s.", - (int)CFE_ES_Global.AppTable[AppID].ControlReq.AppControlRequest, AppStartParams.Name); + (int)AppRecPtr->ControlReq.AppControlRequest, AppStartParams.Name); /* * Bug #58: This message/event keeps repeating itself indefinitely. @@ -1056,7 +1058,7 @@ void CFE_ES_ProcessControlRequest(uint32 AppID) * Change the request state to DELETE so the next scan will clean * up this table entry. */ - CFE_ES_Global.AppTable[AppID].ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; + AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; break; } @@ -1070,12 +1072,21 @@ void CFE_ES_ProcessControlRequest(uint32 AppID) ** Purpose: Delete an application by cleaning up all of it's resources. **--------------------------------------------------------------------------------------- */ -int32 CFE_ES_CleanUpApp(uint32 AppId) +int32 CFE_ES_CleanUpApp(CFE_ES_AppRecord_t *AppRecPtr) { uint32 i; int32 Status; uint32 MainTaskId; + uint32 CurrTaskId; int32 ReturnCode = CFE_SUCCESS; + CFE_ES_TaskRecord_t *TaskRecPtr; + uint32 AppId; + + /* + * Retrieve the abstract AppID for calling cleanup + * routine in _other_ modules. + */ + AppId = CFE_ES_AppRecordGetID(AppRecPtr); /* ** Call the Table Clean up function @@ -1112,26 +1123,32 @@ int32 CFE_ES_CleanUpApp(uint32 AppId) /* ** Get Main Task ID */ - MainTaskId = CFE_ES_Global.AppTable[AppId].TaskInfo.MainTaskId; + MainTaskId = AppRecPtr->TaskInfo.MainTaskId; /* ** Delete any child tasks associated with this app */ + TaskRecPtr = CFE_ES_Global.TaskTable; for ( i = 0; i < OS_MAX_TASKS; i++ ) { /* delete only CHILD tasks - not the MainTaskId, which will be deleted later (below) */ - if ((CFE_ES_Global.TaskTable[i].RecordUsed == true) && - (CFE_ES_Global.TaskTable[i].AppId == AppId) && - (CFE_ES_Global.TaskTable[i].TaskId != MainTaskId)) + if ( CFE_ES_TaskRecordIsUsed(TaskRecPtr) && + (TaskRecPtr->AppId == AppId)) { - Status = CFE_ES_CleanupTaskResources(CFE_ES_Global.TaskTable[i].TaskId); - if ( Status != CFE_SUCCESS ) - { - CFE_ES_SysLogWrite_Unsync("CFE_ES_CleanUpApp: CleanUpTaskResources for Task ID:%d returned Error: 0x%08X\n", - (int)i, (unsigned int)Status); - ReturnCode = CFE_ES_APP_CLEANUP_ERR; - } - } /* end if */ + CurrTaskId = CFE_ES_TaskRecordGetID(TaskRecPtr); + if (CurrTaskId != MainTaskId) + { + Status = CFE_ES_CleanupTaskResources(CurrTaskId); + if ( Status != CFE_SUCCESS ) + { + CFE_ES_SysLogWrite_Unsync("CFE_ES_CleanUpApp: CleanUpTaskResources for Task ID:%lu returned Error: 0x%08X\n", + CFE_ES_ResourceID_ToInteger(CurrTaskId), (unsigned int)Status); + ReturnCode = CFE_ES_APP_CLEANUP_ERR; + } + } /* end if */ + } + + ++TaskRecPtr; } /* end for */ /* @@ -1140,8 +1157,8 @@ int32 CFE_ES_CleanUpApp(uint32 AppId) Status = CFE_ES_CleanupTaskResources(MainTaskId); if ( Status != CFE_SUCCESS ) { - CFE_ES_SysLogWrite_Unsync("CFE_ES_CleanUpApp: CleanUpTaskResources for Task ID:%d returned Error: 0x%08X\n", - (int)MainTaskId, (unsigned int)Status); + CFE_ES_SysLogWrite_Unsync("CFE_ES_CleanUpApp: CleanUpTaskResources for Task ID:%lu returned Error: 0x%08X\n", + CFE_ES_ResourceID_ToInteger(MainTaskId), (unsigned int)Status); ReturnCode = CFE_ES_APP_CLEANUP_ERR; } @@ -1149,22 +1166,22 @@ int32 CFE_ES_CleanUpApp(uint32 AppId) /* ** Remove the app from the AppTable */ - if ( CFE_ES_Global.AppTable[AppId].Type == CFE_ES_AppType_EXTERNAL ) + if ( AppRecPtr->Type == CFE_ES_AppType_EXTERNAL ) { /* ** Unload the module only if it is an external app */ - Status = OS_ModuleUnload(CFE_ES_Global.AppTable[AppId].StartParams.ModuleId); + Status = OS_ModuleUnload(AppRecPtr->StartParams.ModuleId); if ( Status == OS_ERROR ) { - CFE_ES_SysLogWrite_Unsync("CFE_ES_CleanUpApp: Module (ID:0x%08X) Unload failed. RC=0x%08X\n", - (unsigned int)CFE_ES_Global.AppTable[AppId].StartParams.ModuleId, (unsigned int)Status); + CFE_ES_SysLogWrite_Unsync("CFE_ES_CleanUpApp: Module (ID:0x%08lX) Unload failed. RC=0x%08X\n", + (unsigned long)AppRecPtr->StartParams.ModuleId, (unsigned int)Status); ReturnCode = CFE_ES_APP_CLEANUP_ERR; } CFE_ES_Global.RegisteredExternalApps--; } - CFE_ES_Global.AppTable[AppId].AppState = CFE_ES_AppState_UNDEFINED; + CFE_ES_AppRecordSetFree(AppRecPtr); CFE_ES_UnlockSharedData(__func__,__LINE__); @@ -1298,6 +1315,11 @@ int32 CFE_ES_CleanupTaskResources(uint32 TaskId) { CFE_ES_CleanupState_t CleanState; int32 Result; + CFE_ES_TaskRecord_t *TaskRecPtr; + uint32 OsalId; + + /* Get the Task ID for calling OSAL APIs (convert type) */ + OsalId = TaskId; /* ** Delete all OSAL resources that belong to this task @@ -1306,7 +1328,7 @@ int32 CFE_ES_CleanupTaskResources(uint32 TaskId) --CleanState.PrevFoundObjects; while (1) { - OS_ForEachObject (TaskId, CFE_ES_CleanupObjectCallback, &CleanState); + OS_ForEachObject (OsalId, CFE_ES_CleanupObjectCallback, &CleanState); if (CleanState.FoundObjects == 0 || CleanState.ErrorFlag != 0) { break; @@ -1324,10 +1346,15 @@ int32 CFE_ES_CleanupTaskResources(uint32 TaskId) CleanState.DeletedObjects = 0; } + /* + * Locate the ES Task table entry + */ + TaskRecPtr = CFE_ES_LocateTaskRecordByID(TaskId); + /* ** Delete the task itself */ - Result = OS_TaskDelete(TaskId); + Result = OS_TaskDelete(OsalId); if (Result == OS_SUCCESS) { Result = CleanState.OverallStatus; @@ -1345,9 +1372,9 @@ int32 CFE_ES_CleanupTaskResources(uint32 TaskId) /* ** Invalidate ES Task Table entry */ - if (OS_ConvertToArrayIndex(TaskId, &TaskId) == OS_SUCCESS) + if (TaskRecPtr != NULL) { - CFE_ES_Global.TaskTable[TaskId].RecordUsed = false; + CFE_ES_TaskRecordSetFree(TaskRecPtr); } CFE_ES_Global.RegisteredTasks--; @@ -1360,97 +1387,184 @@ int32 CFE_ES_CleanupTaskResources(uint32 TaskId) ** Name: CFE_ES_GetAppInfoInternal ** ** Purpose: Populate the cFE_ES_AppInfo structure with the data for an app. +** +** This internal function does not log any errors/events. The caller is expected +** to check the return code and log any relevant errors based on the context. **--------------------------------------------------------------------------------------- */ -void CFE_ES_GetAppInfoInternal(uint32 AppId, CFE_ES_AppInfo_t *AppInfoPtr ) +int32 CFE_ES_GetAppInfoInternal(CFE_ES_AppRecord_t *AppRecPtr, CFE_ES_AppInfo_t *AppInfoPtr ) { - + int32 Status; int32 ReturnCode; OS_module_prop_t ModuleInfo; - uint32 TaskIndex; uint32 i; - + CFE_ES_TaskRecord_t *TaskRecPtr; + uint32 AppId; CFE_ES_LockSharedData(__func__,__LINE__); - AppInfoPtr->AppId = AppId; - AppInfoPtr->Type = CFE_ES_Global.AppTable[AppId].Type; - strncpy((char *)AppInfoPtr->Name, - CFE_ES_Global.AppTable[AppId].StartParams.Name, - sizeof(AppInfoPtr->Name)-1); - AppInfoPtr->Name[sizeof(AppInfoPtr->Name)-1] = '\0'; - - strncpy((char *)AppInfoPtr->EntryPoint, - CFE_ES_Global.AppTable[AppId].StartParams.EntryPoint, - sizeof(AppInfoPtr->EntryPoint) - 1); - AppInfoPtr->EntryPoint[sizeof(AppInfoPtr->EntryPoint) - 1] = '\0'; - - strncpy((char *)AppInfoPtr->FileName, (char *)CFE_ES_Global.AppTable[AppId].StartParams.FileName, - sizeof(AppInfoPtr->FileName) - 1); - AppInfoPtr->FileName[sizeof(AppInfoPtr->FileName) - 1] = '\0'; - - AppInfoPtr->ModuleId = CFE_ES_Global.AppTable[AppId].StartParams.ModuleId; - AppInfoPtr->StackSize = CFE_ES_Global.AppTable[AppId].StartParams.StackSize; - CFE_SB_SET_MEMADDR(AppInfoPtr->StartAddress, CFE_ES_Global.AppTable[AppId].StartParams.StartAddress); - AppInfoPtr->ExceptionAction = CFE_ES_Global.AppTable[AppId].StartParams.ExceptionAction; - AppInfoPtr->Priority = CFE_ES_Global.AppTable[AppId].StartParams.Priority; - - AppInfoPtr->MainTaskId = CFE_ES_Global.AppTable[AppId].TaskInfo.MainTaskId; - strncpy((char *)AppInfoPtr->MainTaskName, (char *)CFE_ES_Global.AppTable[AppId].TaskInfo.MainTaskName, - sizeof(AppInfoPtr->MainTaskName) - 1); - AppInfoPtr->MainTaskName[sizeof(AppInfoPtr->MainTaskName) - 1] = '\0'; - - /* - ** Calculate the number of child tasks - */ - AppInfoPtr->NumOfChildTasks = 0; - for (i=0; iMainTaskId ) - { - AppInfoPtr->NumOfChildTasks++; - } + Status = CFE_ES_ERR_APPID; } - - /* - ** Get the execution counter for the main task - */ - if (OS_ConvertToArrayIndex(AppInfoPtr->MainTaskId, &TaskIndex) == OS_SUCCESS) + else { - AppInfoPtr->ExecutionCounter = CFE_ES_Global.TaskTable[TaskIndex].ExecutionCounter; + Status = CFE_SUCCESS; + + AppId = CFE_ES_AppRecordGetID(AppRecPtr); + AppInfoPtr->AppId = AppId; + AppInfoPtr->Type = AppRecPtr->Type; + strncpy((char *)AppInfoPtr->Name, + AppRecPtr->StartParams.Name, + sizeof(AppInfoPtr->Name)-1); + AppInfoPtr->Name[sizeof(AppInfoPtr->Name)-1] = '\0'; + + strncpy((char *)AppInfoPtr->EntryPoint, + AppRecPtr->StartParams.EntryPoint, + sizeof(AppInfoPtr->EntryPoint) - 1); + AppInfoPtr->EntryPoint[sizeof(AppInfoPtr->EntryPoint) - 1] = '\0'; + + strncpy((char *)AppInfoPtr->FileName, (char *)AppRecPtr->StartParams.FileName, + sizeof(AppInfoPtr->FileName) - 1); + AppInfoPtr->FileName[sizeof(AppInfoPtr->FileName) - 1] = '\0'; + + AppInfoPtr->ModuleId = AppRecPtr->StartParams.ModuleId; + AppInfoPtr->StackSize = AppRecPtr->StartParams.StackSize; + CFE_SB_SET_MEMADDR(AppInfoPtr->StartAddress, AppRecPtr->StartParams.StartAddress); + AppInfoPtr->ExceptionAction = AppRecPtr->StartParams.ExceptionAction; + AppInfoPtr->Priority = AppRecPtr->StartParams.Priority; + + AppInfoPtr->MainTaskId = AppRecPtr->TaskInfo.MainTaskId; + strncpy((char *)AppInfoPtr->MainTaskName, (char *)AppRecPtr->TaskInfo.MainTaskName, + sizeof(AppInfoPtr->MainTaskName) - 1); + AppInfoPtr->MainTaskName[sizeof(AppInfoPtr->MainTaskName) - 1] = '\0'; + + /* + ** Calculate the number of child tasks + */ + AppInfoPtr->NumOfChildTasks = 0; + TaskRecPtr = CFE_ES_Global.TaskTable; + for (i=0; iAppId == AppId && + CFE_ES_TaskRecordGetID(TaskRecPtr) != AppInfoPtr->MainTaskId ) + { + AppInfoPtr->NumOfChildTasks++; + } + ++TaskRecPtr; + } + + /* + ** Get the execution counter for the main task + */ + TaskRecPtr = CFE_ES_LocateTaskRecordByID(AppInfoPtr->MainTaskId); + if (CFE_ES_TaskRecordIsMatch(TaskRecPtr,AppInfoPtr->MainTaskId)) + { + AppInfoPtr->ExecutionCounter = TaskRecPtr->ExecutionCounter; + } + + /* + ** Get the address information from the OSAL + */ + ReturnCode = OS_ModuleInfo ( AppInfoPtr->ModuleId, &ModuleInfo ); + if ( ReturnCode == OS_SUCCESS ) + { + AppInfoPtr->AddressesAreValid = + (sizeof(ModuleInfo.addr.code_address) <= sizeof(AppInfoPtr->CodeAddress)) && + ModuleInfo.addr.valid; + CFE_SB_SET_MEMADDR(AppInfoPtr->CodeAddress, ModuleInfo.addr.code_address); + CFE_SB_SET_MEMADDR(AppInfoPtr->CodeSize, ModuleInfo.addr.code_size); + CFE_SB_SET_MEMADDR(AppInfoPtr->DataAddress, ModuleInfo.addr.data_address); + CFE_SB_SET_MEMADDR(AppInfoPtr->DataSize, ModuleInfo.addr.data_size); + CFE_SB_SET_MEMADDR(AppInfoPtr->BSSAddress, ModuleInfo.addr.bss_address); + CFE_SB_SET_MEMADDR(AppInfoPtr->BSSSize, ModuleInfo.addr.bss_size); + } + else + { + AppInfoPtr->AddressesAreValid = false; + AppInfoPtr->CodeAddress = 0; + AppInfoPtr->CodeSize = 0; + AppInfoPtr->DataAddress = 0; + AppInfoPtr->DataSize = 0; + AppInfoPtr->BSSAddress = 0; + AppInfoPtr->BSSSize = 0; + } + } - /* - ** Get the address information from the OSAL - */ - ReturnCode = OS_ModuleInfo ( AppInfoPtr->ModuleId, &ModuleInfo ); - if ( ReturnCode == OS_SUCCESS ) + CFE_ES_UnlockSharedData(__func__,__LINE__); + + return Status; + +} /* end function */ + +/* +**--------------------------------------------------------------------------------------- +** Name: CFE_ES_GetAppInfoInternal +** +** Purpose: Populate the cFE_ES_TaskInfo structure with the data for a task. +** +** This internal function does not log any errors/events. The caller is expected +** to check the return code and log any relevant errors based on the context. +**--------------------------------------------------------------------------------------- +*/ +int32 CFE_ES_GetTaskInfoInternal(CFE_ES_TaskRecord_t *TaskRecPtr, CFE_ES_TaskInfo_t *TaskInfoPtr) +{ + CFE_ES_AppRecord_t *AppRecPtr; + int32 ReturnCode; + + CFE_ES_LockSharedData(__func__,__LINE__); + + if ( CFE_ES_TaskRecordIsUsed(TaskRecPtr) ) { - AppInfoPtr->AddressesAreValid = - (sizeof(ModuleInfo.addr.code_address) <= sizeof(AppInfoPtr->CodeAddress)) && - ModuleInfo.addr.valid; - CFE_SB_SET_MEMADDR(AppInfoPtr->CodeAddress, ModuleInfo.addr.code_address); - CFE_SB_SET_MEMADDR(AppInfoPtr->CodeSize, ModuleInfo.addr.code_size); - CFE_SB_SET_MEMADDR(AppInfoPtr->DataAddress, ModuleInfo.addr.data_address); - CFE_SB_SET_MEMADDR(AppInfoPtr->DataSize, ModuleInfo.addr.data_size); - CFE_SB_SET_MEMADDR(AppInfoPtr->BSSAddress, ModuleInfo.addr.bss_address); - CFE_SB_SET_MEMADDR(AppInfoPtr->BSSSize, ModuleInfo.addr.bss_size); + + /* + ** Get the Application ID and Task Name + */ + TaskInfoPtr->AppId = TaskRecPtr->AppId; + strncpy((char *)TaskInfoPtr->TaskName, + (char *)TaskRecPtr->TaskName,OS_MAX_API_NAME); + TaskInfoPtr->TaskName[OS_MAX_API_NAME - 1] = '\0'; + + /* + ** Store away the Task ID ( for the QueryAllTasks Cmd ) + */ + TaskInfoPtr->TaskId = CFE_ES_TaskRecordGetID(TaskRecPtr); + + /* + ** Get the Execution counter for the task + */ + TaskInfoPtr->ExecutionCounter = TaskRecPtr->ExecutionCounter; + + /* + ** Get the Application Details + */ + AppRecPtr = CFE_ES_LocateAppRecordByID(TaskRecPtr->AppId); + if (CFE_ES_AppRecordIsMatch(AppRecPtr, TaskRecPtr->AppId)) + { + strncpy((char*)TaskInfoPtr->AppName, + (char*)AppRecPtr->StartParams.Name, + sizeof(TaskInfoPtr->AppName)-1); + ReturnCode = CFE_SUCCESS; + } + else + { + /* task ID was OK but parent app ID is bad */ + ReturnCode = CFE_ES_ERR_APPID; + } } else { - AppInfoPtr->AddressesAreValid = false; - AppInfoPtr->CodeAddress = 0; - AppInfoPtr->CodeSize = 0; - AppInfoPtr->DataAddress = 0; - AppInfoPtr->DataSize = 0; - AppInfoPtr->BSSAddress = 0; - AppInfoPtr->BSSSize = 0; + /* task ID is bad */ + ReturnCode = CFE_ES_ERR_TASKID; } + CFE_ES_UnlockSharedData(__func__,__LINE__); + return(ReturnCode); + +} /* End of CFE_ES_GetTaskInfoInternal() */ - CFE_ES_UnlockSharedData(__func__,__LINE__); -} /* end function */ diff --git a/fsw/cfe-core/src/es/cfe_es_apps.h b/fsw/cfe-core/src/es/cfe_es_apps.h index 1f604bc93..8ea6a8559 100644 --- a/fsw/cfe-core/src/es/cfe_es_apps.h +++ b/fsw/cfe-core/src/es/cfe_es_apps.h @@ -101,7 +101,7 @@ typedef struct */ typedef struct { - CFE_ES_AppState_Enum_t AppState; /* Is the app running, or stopped, or waiting? */ + CFE_ES_AppState_Enum_t AppState; /* Is the app running, or stopped, or waiting? */ uint32 Type; /* The type of App: CORE or EXTERNAL */ CFE_ES_AppStartParams_t StartParams; /* The start parameters for an App */ CFE_ES_ControlReq_t ControlReq; /* The Control Request Record for External cFE Apps */ @@ -211,12 +211,12 @@ bool CFE_ES_RunERLogDump(uint32 ElapsedTime, void *Arg); /* ** Perform the requested control action for an application */ -void CFE_ES_ProcessControlRequest(uint32 AppID); +void CFE_ES_ProcessControlRequest(CFE_ES_AppRecord_t *AppRecPtr); /* ** Clean up all app resources and delete it */ -int32 CFE_ES_CleanUpApp(uint32 AppId); +int32 CFE_ES_CleanUpApp(CFE_ES_AppRecord_t *AppRecPtr); /* ** Clean up all Task resources and detete the task @@ -228,6 +228,13 @@ int32 CFE_ES_CleanupTaskResources(uint32 TaskId); ** This is an internal function for use in ES. ** The newer external API is : CFE_ES_GetAppInfo */ -void CFE_ES_GetAppInfoInternal(uint32 AppId, CFE_ES_AppInfo_t *AppInfoPtr ); +int32 CFE_ES_GetAppInfoInternal(CFE_ES_AppRecord_t *AppRecPtr, CFE_ES_AppInfo_t *AppInfoPtr ); + +/* + * Populate the CFE_ES_TaskInfo_t structure with the data for a task + * This is an internal function for use in ES. + * (Equivalent pattern to CFE_ES_GetAppInfoInternal() but for tasks) + */ +int32 CFE_ES_GetTaskInfoInternal(CFE_ES_TaskRecord_t *TaskRecPtr, CFE_ES_TaskInfo_t *TaskInfoPtr ); #endif /* _cfe_es_apps_ */ diff --git a/fsw/cfe-core/src/es/cfe_es_cds.c b/fsw/cfe-core/src/es/cfe_es_cds.c index 4cd699447..6b984228e 100644 --- a/fsw/cfe-core/src/es/cfe_es_cds.c +++ b/fsw/cfe-core/src/es/cfe_es_cds.c @@ -528,35 +528,6 @@ int32 CFE_ES_UpdateCDSRegistry(void) return Status; } -/******************************************************************* -** -** CFE_ES_CDS_ValidateAppID -** -** NOTE: For complete prolog information, see 'cfe_es_cds.h' -********************************************************************/ - -int32 CFE_ES_CDS_ValidateAppID(uint32 *AppIdPtr) -{ - int32 Status = CFE_ES_GetAppID(AppIdPtr); - - if (Status == CFE_SUCCESS) - { - if (*AppIdPtr >= CFE_PLATFORM_ES_MAX_APPLICATIONS) - { - Status = CFE_ES_ERR_APPID; - - CFE_ES_WriteToSysLog("CFE_CDS:ValidateAppID-AppId=%d > Max Apps (%d)\n", - (int)(*AppIdPtr), CFE_PLATFORM_ES_MAX_APPLICATIONS); - } - } - else - { - CFE_ES_WriteToSysLog("CFE_CDS:ValidateAppID-GetAppID failed (Stat=0x%08X)\n", (unsigned int)Status); - } - - return Status; -} /* End of CFE_ES_CDS_ValidateAppID() */ - /******************************************************************* ** diff --git a/fsw/cfe-core/src/es/cfe_es_cds.h b/fsw/cfe-core/src/es/cfe_es_cds.h index ee32f7544..fb6e8963c 100644 --- a/fsw/cfe-core/src/es/cfe_es_cds.h +++ b/fsw/cfe-core/src/es/cfe_es_cds.h @@ -111,27 +111,6 @@ int32 CFE_ES_CDS_EarlyInit(void); int32 CFE_ES_UpdateCDSRegistry(void); -/*****************************************************************************/ -/** -** \brief Validates the Application ID associated with calling Application -** -** \par Description -** Validates Application ID of calling App. Validation -** consists of ensuring the AppID is between zero and -** #CFE_PLATFORM_ES_MAX_APPLICATIONS. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \param[in, out] AppIdPtr Pointer to value that will hold AppID on return. *AppIdPtr is the AppID as obtained from #CFE_ES_GetAppID. -** -** -** \retval #CFE_SUCCESS \copydoc CFE_SUCCESS -** \retval #CFE_ES_ERR_APPID \copydoc CFE_ES_ERR_APPID -** -******************************************************************************/ -int32 CFE_ES_CDS_ValidateAppID(uint32 *AppIdPtr); - /*****************************************************************************/ /** diff --git a/fsw/cfe-core/src/es/cfe_es_erlog.c b/fsw/cfe-core/src/es/cfe_es_erlog.c index d4bf207d5..03fcc7bba 100644 --- a/fsw/cfe-core/src/es/cfe_es_erlog.c +++ b/fsw/cfe-core/src/es/cfe_es_erlog.c @@ -318,6 +318,7 @@ bool CFE_ES_RunExceptionScan(uint32 ElapsedTime, void *Arg) uint32 ExceptionTaskID; uint32 ResetType; CFE_ES_LogEntryType_Enum_t LogType; + CFE_ES_AppRecord_t *AppRecPtr; if (CFE_PSP_Exception_GetCount() == 0) { @@ -361,13 +362,19 @@ bool CFE_ES_RunExceptionScan(uint32 ElapsedTime, void *Arg) /* * The App ID was found, now see if the ExceptionAction is set for a reset */ - if (Status == CFE_SUCCESS && - CFE_ES_Global.AppTable[EsTaskInfo.AppId].StartParams.ExceptionAction == CFE_ES_ExceptionAction_RESTART_APP) + if (Status == CFE_SUCCESS) { - /* - * Log the Application reset - */ - ResetType = CFE_ES_APP_RESTART; + AppRecPtr = CFE_ES_LocateAppRecordByID(EsTaskInfo.AppId); + CFE_ES_LockSharedData(__func__,__LINE__); + if (CFE_ES_AppRecordIsMatch(AppRecPtr, EsTaskInfo.AppId) && + AppRecPtr->StartParams.ExceptionAction == CFE_ES_ExceptionAction_RESTART_APP) + { + /* + * Log the Application reset + */ + ResetType = CFE_ES_APP_RESTART; + } + CFE_ES_UnlockSharedData(__func__,__LINE__); } } diff --git a/fsw/cfe-core/src/es/cfe_es_global.h b/fsw/cfe-core/src/es/cfe_es_global.h index 16c13c417..6ef1dd5b3 100644 --- a/fsw/cfe-core/src/es/cfe_es_global.h +++ b/fsw/cfe-core/src/es/cfe_es_global.h @@ -155,6 +155,221 @@ extern CFE_ES_Global_t CFE_ES_Global; */ extern CFE_ES_ResetData_t *CFE_ES_ResetDataPtr; +/** + * @brief Locate the app table entry correlating with a given app ID. + * + * This only returns a pointer to the table entry and does _not_ + * otherwise check/validate the entry. + * + * @param[in] AppID the app ID to locate + * @return pointer to App Table entry for the given app ID + */ +extern CFE_ES_AppRecord_t* CFE_ES_LocateAppRecordByID(uint32 AppID); + +/** + * @brief Locate the task table entry correlating with a given task ID. + * + * This only returns a pointer to the table entry and does _not_ + * otherwise check/validate the entry. + * + * @param[in] TaskID the task ID to locate + * @return pointer to Task Table entry for the given task ID + */ +extern CFE_ES_TaskRecord_t* CFE_ES_LocateTaskRecordByID(uint32 TaskID); + +/** + * @brief Check if an app record is in use or free/empty + * + * This routine checks if the App table entry is in use or if it is free + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] AppRecPtr pointer to app table entry + * @returns true if the entry is in use/configured, or false if it is free/empty + */ +static inline bool CFE_ES_AppRecordIsUsed(const CFE_ES_AppRecord_t *AppRecPtr) +{ + return (AppRecPtr->AppState != CFE_ES_AppState_UNDEFINED); +} + +/** + * @brief Get the ID value from an app table entry + * + * This routine converts the table entry back to an abstract ID. + * + * @param[in] AppRecPtr pointer to app table entry + * @returns AppID of entry + */ +static inline uint32 CFE_ES_AppRecordGetID(const CFE_ES_AppRecord_t *AppRecPtr) +{ + /* + * The initial implementation does not store the ID in the entry; + * the ID is simply the zero-based index into the table. + */ + return (AppRecPtr - CFE_ES_Global.AppTable); +} + +/** + * @brief Marks an app table entry as used (not free) + * + * This sets the internal field(s) within this entry, and marks + * it as being associated with the given app ID. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] AppRecPtr pointer to app table entry + * @param[in] AppID the app ID of this entry + */ +static inline void CFE_ES_AppRecordSetUsed(CFE_ES_AppRecord_t *AppRecPtr, uint32 AppID) +{ + AppRecPtr->AppState = CFE_ES_AppState_EARLY_INIT; +} + +/** + * @brief Set an app record table entry free (not used) + * + * This clears the internal field(s) within this entry, and allows the + * memory to be re-used in the future. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] AppRecPtr pointer to app table entry + */ +static inline void CFE_ES_AppRecordSetFree(CFE_ES_AppRecord_t *AppRecPtr) +{ + AppRecPtr->AppState = CFE_ES_AppState_UNDEFINED; +} + +/** + * @brief Check if an app record is a match for the given AppID + * + * This routine confirms that the previously-located record is valid + * and matches the expected app ID. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] AppRecPtr pointer to app table entry + * @param[in] AppID expected app ID + * @returns true if the entry matches the given app ID + */ +static inline bool CFE_ES_AppRecordIsMatch(const CFE_ES_AppRecord_t *AppRecPtr, uint32 AppID) +{ + return (AppRecPtr != NULL && CFE_ES_AppRecordIsUsed(AppRecPtr) && + CFE_ES_AppRecordGetID(AppRecPtr) == AppID); +} + +/** + * @brief Get the ID value from an Task table entry + * + * This routine converts the table entry back to an abstract ID. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] TaskRecPtr pointer to Task table entry + * @returns TaskID of entry + */ +static inline uint32 CFE_ES_TaskRecordGetID(const CFE_ES_TaskRecord_t *TaskRecPtr) +{ + return (TaskRecPtr->TaskId); +} + +/** + * @brief Check if a Task record is in use or free/empty + * + * This routine checks if the Task table entry is in use or if it is free + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] TaskRecPtr pointer to task table entry + * @returns true if the entry is in use/configured, or false if it is free/empty + */ +static inline bool CFE_ES_TaskRecordIsUsed(const CFE_ES_TaskRecord_t *TaskRecPtr) +{ + return (TaskRecPtr->RecordUsed); +} + +/** + * @brief Marks an Task table entry as used (not free) + * + * This sets the internal field(s) within this entry, and marks + * it as being associated with the given Task ID. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] TaskRecPtr pointer to Task table entry + * @param[in] TaskID the Task ID of this entry + */ +static inline void CFE_ES_TaskRecordSetUsed(CFE_ES_TaskRecord_t *TaskRecPtr, uint32 TaskID) +{ + TaskRecPtr->TaskId = TaskID; + TaskRecPtr->RecordUsed = true; +} + +/** + * @brief Set a Task record table entry free + * + * This allows the table entry to be re-used by another Task. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] TaskRecPtr pointer to task table entry + * @returns true if the entry is in use/configured, or false if it is free/empty + */ +static inline void CFE_ES_TaskRecordSetFree(CFE_ES_TaskRecord_t *TaskRecPtr) +{ + TaskRecPtr->TaskId = 0; + TaskRecPtr->RecordUsed = false; +} + +/** + * @brief Check if a Task record is a match for the given TaskID + * + * This routine confirms that the previously-located record is valid + * and matches the expected Task ID. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] TaskRecPtr pointer to task table entry + * @returns true if the entry matches the given task ID + */ +static inline bool CFE_ES_TaskRecordIsMatch(const CFE_ES_TaskRecord_t *TaskRecPtr, uint32 TaskID) +{ + return (TaskRecPtr != NULL && CFE_ES_TaskRecordIsUsed(TaskRecPtr) && + CFE_ES_TaskRecordGetID(TaskRecPtr) == TaskID); +} + +/** + * Locate and validate the app record for the calling context. + * + * Finds and validates the ES AppTable entry corresponding to the + * caller. This confirms that the fields within the table entry match the + * expected value(s), otherwise NULL is returned if no matching entry + * is found. + * + * The global data lock should be obtained prior to invoking this function. + */ +extern CFE_ES_AppRecord_t* CFE_ES_GetAppRecordByContext(void); + +/** + * Locate and validate the task record for the calling context. + * + * Finds and validates the ES TaskTable entry corresponding to the + * caller. This confirms that the fields within the table entry match the + * expected value(s), otherwise NULL is returned if no matching entry + * is found. + * + * The global data lock should be obtained prior to invoking this function. + */ +extern CFE_ES_TaskRecord_t* CFE_ES_GetTaskRecordByContext(void); /* ** Functions used to lock/unlock shared data diff --git a/fsw/cfe-core/src/es/cfe_es_start.c b/fsw/cfe-core/src/es/cfe_es_start.c index 5d73fc64c..0e2105e3b 100644 --- a/fsw/cfe-core/src/es/cfe_es_start.c +++ b/fsw/cfe-core/src/es/cfe_es_start.c @@ -85,6 +85,8 @@ void CFE_ES_Main(uint32 StartType, uint32 StartSubtype, uint32 ModeId, const cha { uint32 i; int32 ReturnCode; + CFE_ES_AppRecord_t *AppRecPtr; + CFE_ES_TaskRecord_t *TaskRecPtr; /* ** Indicate that the CFE is the earliest initialization state @@ -176,18 +178,22 @@ void CFE_ES_Main(uint32 StartType, uint32 StartSubtype, uint32 ModeId, const cha ** Initialize the ES Application Table ** to mark all entries as unused. */ + AppRecPtr = CFE_ES_Global.AppTable; for ( i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++ ) { - CFE_ES_Global.AppTable[i].AppState = CFE_ES_AppState_UNDEFINED; + CFE_ES_AppRecordSetFree(AppRecPtr); + ++AppRecPtr; } /* ** Initialize the ES Task Table ** to mark all entries as unused. */ + TaskRecPtr = CFE_ES_Global.TaskTable; for ( i = 0; i < OS_MAX_TASKS; i++ ) { - CFE_ES_Global.TaskTable[i].RecordUsed = false; + CFE_ES_TaskRecordSetFree(TaskRecPtr); + ++TaskRecPtr; } /* @@ -764,10 +770,12 @@ void CFE_ES_InitializeFileSystems(uint32 StartType) void CFE_ES_CreateObjects(void) { int32 ReturnCode; - uint32 TaskIndex; bool AppSlotFound; uint16 i; uint16 j; + uint32 OsalId; + CFE_ES_AppRecord_t *AppRecPtr; + CFE_ES_TaskRecord_t *TaskRecPtr; CFE_ES_WriteToSysLog("ES Startup: Starting Object Creation calls.\n"); @@ -782,13 +790,15 @@ void CFE_ES_CreateObjects(void) ** Allocate an ES AppTable entry */ AppSlotFound = false; + AppRecPtr = CFE_ES_Global.AppTable; for ( j = 0; j < CFE_PLATFORM_ES_MAX_APPLICATIONS; j++ ) { - if ( CFE_ES_Global.AppTable[j].AppState == CFE_ES_AppState_UNDEFINED ) + if ( !CFE_ES_AppRecordIsUsed(AppRecPtr) ) { AppSlotFound = true; break; } + ++AppRecPtr; } /* @@ -802,38 +812,38 @@ void CFE_ES_CreateObjects(void) /* ** Allocate and populate the ES_AppTable entry */ - memset ( &(CFE_ES_Global.AppTable[j]), 0, sizeof(CFE_ES_AppRecord_t)); + memset ( AppRecPtr, 0, sizeof(CFE_ES_AppRecord_t)); /* ** Core apps still have the notion of an init/running state ** Set the state here to mark the record as used. */ - CFE_ES_Global.AppTable[j].AppState = CFE_ES_AppState_EARLY_INIT; + CFE_ES_AppRecordSetUsed(AppRecPtr, j); - CFE_ES_Global.AppTable[j].Type = CFE_ES_AppType_CORE; + AppRecPtr->Type = CFE_ES_AppType_CORE; /* ** Fill out the parameters in the AppStartParams sub-structure */ - strncpy((char *)CFE_ES_Global.AppTable[j].StartParams.Name, (char *)CFE_ES_ObjectTable[i].ObjectName, OS_MAX_API_NAME); - CFE_ES_Global.AppTable[j].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; + strncpy((char *)AppRecPtr->StartParams.Name, (char *)CFE_ES_ObjectTable[i].ObjectName, OS_MAX_API_NAME); + AppRecPtr->StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; /* EntryPoint field is not valid here for base apps */ /* FileName is not valid for base apps, either */ - CFE_ES_Global.AppTable[j].StartParams.StackSize = CFE_ES_ObjectTable[i].ObjectSize; - CFE_ES_Global.AppTable[j].StartParams.StartAddress = (cpuaddr)CFE_ES_ObjectTable[i].FuncPtrUnion.VoidPtr; - CFE_ES_Global.AppTable[j].StartParams.ExceptionAction = CFE_ES_ExceptionAction_PROC_RESTART; - CFE_ES_Global.AppTable[j].StartParams.Priority = CFE_ES_ObjectTable[i].ObjectPriority; + AppRecPtr->StartParams.StackSize = CFE_ES_ObjectTable[i].ObjectSize; + AppRecPtr->StartParams.StartAddress = (cpuaddr)CFE_ES_ObjectTable[i].FuncPtrUnion.VoidPtr; + AppRecPtr->StartParams.ExceptionAction = CFE_ES_ExceptionAction_PROC_RESTART; + AppRecPtr->StartParams.Priority = CFE_ES_ObjectTable[i].ObjectPriority; /* ** Fill out the Task Info */ - strncpy((char *)CFE_ES_Global.AppTable[j].TaskInfo.MainTaskName, (char *)CFE_ES_ObjectTable[i].ObjectName, OS_MAX_API_NAME); - CFE_ES_Global.AppTable[j].TaskInfo.MainTaskName[OS_MAX_API_NAME - 1] = '\0'; + strncpy((char *)AppRecPtr->TaskInfo.MainTaskName, (char *)CFE_ES_ObjectTable[i].ObjectName, OS_MAX_API_NAME); + AppRecPtr->TaskInfo.MainTaskName[OS_MAX_API_NAME - 1] = '\0'; /* ** Create the task */ - ReturnCode = OS_TaskCreate(&CFE_ES_Global.AppTable[j].TaskInfo.MainTaskId, /* task id */ + ReturnCode = OS_TaskCreate(&OsalId, /* task id */ CFE_ES_ObjectTable[i].ObjectName, /* task name */ CFE_ES_ObjectTable[i].FuncPtrUnion.MainAppPtr, /* task function pointer */ NULL, /* stack pointer */ @@ -843,7 +853,7 @@ void CFE_ES_CreateObjects(void) if(ReturnCode != OS_SUCCESS) { - CFE_ES_Global.AppTable[j].AppState = CFE_ES_AppState_UNDEFINED; + CFE_ES_AppRecordSetFree(AppRecPtr); CFE_ES_UnlockSharedData(__func__,__LINE__); CFE_ES_WriteToSysLog("ES Startup: OS_TaskCreate error creating core App: %s: EC = 0x%08X\n", @@ -862,27 +872,25 @@ void CFE_ES_CreateObjects(void) } else { - OS_ConvertToArrayIndex(CFE_ES_Global.AppTable[j].TaskInfo.MainTaskId, &TaskIndex); + AppRecPtr->TaskInfo.MainTaskId = OsalId; + TaskRecPtr = CFE_ES_LocateTaskRecordByID(AppRecPtr->TaskInfo.MainTaskId); /* ** Allocate and populate the CFE_ES_Global.TaskTable entry */ - if ( CFE_ES_Global.TaskTable[TaskIndex].RecordUsed == true ) + if ( CFE_ES_TaskRecordIsUsed(TaskRecPtr) ) { CFE_ES_SysLogWrite_Unsync("ES Startup: CFE_ES_Global.TaskTable record used error for App: %s, continuing.\n", CFE_ES_ObjectTable[i].ObjectName); } - else - { - CFE_ES_Global.TaskTable[TaskIndex].RecordUsed = true; - } - CFE_ES_Global.TaskTable[TaskIndex].AppId = j; - CFE_ES_Global.TaskTable[TaskIndex].TaskId = CFE_ES_Global.AppTable[j].TaskInfo.MainTaskId; - strncpy((char *)CFE_ES_Global.TaskTable[TaskIndex].TaskName, (char *)CFE_ES_Global.AppTable[j].TaskInfo.MainTaskName, OS_MAX_API_NAME); - CFE_ES_Global.TaskTable[TaskIndex].TaskName[OS_MAX_API_NAME - 1] = '\0'; - - CFE_ES_SysLogWrite_Unsync("ES Startup: Core App: %s created. App ID: %d\n", - CFE_ES_ObjectTable[i].ObjectName,j); + CFE_ES_TaskRecordSetUsed(TaskRecPtr, AppRecPtr->TaskInfo.MainTaskId); + TaskRecPtr->AppId = CFE_ES_AppRecordGetID(AppRecPtr); + strncpy((char *)TaskRecPtr->TaskName, (char *)AppRecPtr->TaskInfo.MainTaskName, OS_MAX_API_NAME); + TaskRecPtr->TaskName[OS_MAX_API_NAME - 1] = '\0'; + + CFE_ES_SysLogWrite_Unsync("ES Startup: Core App: %s created. App ID: %lu\n", + CFE_ES_ObjectTable[i].ObjectName, + CFE_ES_ResourceID_ToInteger(CFE_ES_AppRecordGetID(AppRecPtr))); /* ** Increment the registered App and Registered External Task variables. @@ -988,6 +996,7 @@ int32 CFE_ES_MainTaskSyncDelay(uint32 AppStateId, uint32 TimeOutMilliseconds) uint32 WaitTime; uint32 WaitRemaining; uint32 AppNotReadyCounter; + CFE_ES_AppRecord_t *AppRecPtr; Status = CFE_ES_OPERATION_TIMED_OUT; WaitRemaining = TimeOutMilliseconds; @@ -999,13 +1008,15 @@ int32 CFE_ES_MainTaskSyncDelay(uint32 AppStateId, uint32 TimeOutMilliseconds) * Count the number of apps that are NOT in (at least) in the state requested */ CFE_ES_LockSharedData(__func__,__LINE__); + AppRecPtr = CFE_ES_Global.AppTable; for ( i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++ ) { - if (CFE_ES_Global.AppTable[i].AppState != CFE_ES_AppState_UNDEFINED && - (CFE_ES_Global.AppTable[i].AppState < AppStateId)) + if ( CFE_ES_AppRecordIsUsed(AppRecPtr) && + (AppRecPtr->AppState < AppStateId)) { ++AppNotReadyCounter; } + ++AppRecPtr; } CFE_ES_UnlockSharedData(__func__,__LINE__); diff --git a/fsw/cfe-core/src/es/cfe_es_task.c b/fsw/cfe-core/src/es/cfe_es_task.c index af43be5ac..9b7563282 100644 --- a/fsw/cfe-core/src/es/cfe_es_task.c +++ b/fsw/cfe-core/src/es/cfe_es_task.c @@ -1003,8 +1003,8 @@ int32 CFE_ES_StartAppCmd(const CFE_ES_StartApp_t *data) { CFE_ES_TaskData.CommandCounter++; CFE_EVS_SendEvent(CFE_ES_START_INF_EID, CFE_EVS_EventType_INFORMATION, - "Started %s from %s, AppID = %d", - LocalAppName, LocalFile, (int)AppID); + "Started %s from %s, AppID = %lu", + LocalAppName, LocalFile, CFE_ES_ResourceID_ToInteger(AppID)); } else { @@ -1192,13 +1192,16 @@ int32 CFE_ES_QueryOneCmd(const CFE_ES_QueryOne_t *data) Result = CFE_ES_GetAppIDByName(&AppID, LocalApp); + if (Result == CFE_SUCCESS) + { + Result = CFE_ES_GetAppInfo(&(CFE_ES_TaskData.OneAppPacket.Payload.AppInfo), AppID); + } + /* ** Send appropriate event message... */ if (Result == CFE_SUCCESS) { - - CFE_ES_GetAppInfoInternal(AppID, &(CFE_ES_TaskData.OneAppPacket.Payload.AppInfo)); /* ** Send application status telemetry packet. */ @@ -1246,6 +1249,7 @@ int32 CFE_ES_QueryAllCmd(const CFE_ES_QueryAll_t *data) CFE_ES_AppInfo_t AppInfo; const CFE_ES_FileNameCmd_Payload_t *CmdPtr = &data->Payload; char QueryAllFilename[OS_MAX_PATH_LEN]; + CFE_ES_AppRecord_t *AppRecPtr; /* ** Copy the commanded filename into local buffer to ensure size limitation and to allow for modification @@ -1301,20 +1305,22 @@ int32 CFE_ES_QueryAllCmd(const CFE_ES_QueryAll_t *data) /* ** Loop through the ES AppTable for main applications */ + AppRecPtr = CFE_ES_Global.AppTable; for(i=0;iPayload; char QueryAllFilename[OS_MAX_PATH_LEN]; - + CFE_ES_TaskRecord_t *TaskRecPtr; /* ** Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */ @@ -1426,20 +1434,21 @@ int32 CFE_ES_QueryAllTasksCmd(const CFE_ES_QueryAllTasks_t *data) /* ** Loop through the ES AppTable for main applications */ + TaskRecPtr = CFE_ES_Global.TaskTable; for(i=0;iPoolHandle) { CFE_ES_GetAppID(&AppId); - CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:Bad handle(0x%08lX) AppId=%d\n",(unsigned long)Handle,(int)AppId); + CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:Bad handle(0x%08lX) AppId=%lu\n", + (unsigned long)Handle, CFE_ES_ResourceID_ToInteger(AppId)); return(CFE_ES_ERR_MEM_HANDLE); } } else { CFE_ES_GetAppID(&AppId); - CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:Bad handle(0x%08lX) AppId=%d\n",(unsigned long)Handle,(int)AppId); + CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:Bad handle(0x%08lX) AppId=%lu\n", + (unsigned long)Handle, CFE_ES_ResourceID_ToInteger(AppId)); return(CFE_ES_ERR_MEM_HANDLE); } @@ -636,7 +638,8 @@ int32 CFE_ES_GetMemPoolStats(CFE_ES_MemPoolStats_t *BufPtr, if (PoolPtr == NULL || Handle != PoolPtr->PoolHandle) { CFE_ES_GetAppID(&AppId); - CFE_ES_WriteToSysLog("CFE_ES:getMemPoolStats err:Bad handle(0x%08lX) AppId=%d\n", (unsigned long)Handle, (int)AppId); + CFE_ES_WriteToSysLog("CFE_ES:getMemPoolStats err:Bad handle(0x%08lX) AppId=%lu\n", + (unsigned long)Handle, CFE_ES_ResourceID_ToInteger(AppId)); return(CFE_ES_ERR_MEM_HANDLE); } diff --git a/fsw/cfe-core/src/inc/cfe_es.h b/fsw/cfe-core/src/inc/cfe_es.h index 6df04cfad..c89652aa0 100644 --- a/fsw/cfe-core/src/inc/cfe_es.h +++ b/fsw/cfe-core/src/inc/cfe_es.h @@ -198,6 +198,103 @@ */ typedef cpuaddr CFE_ES_MemHandle_t; +/** + * @brief Convert a resource ID to an integer. + * + * This is primarily intended for logging purposes, such was writing + * to debug console, event messages, or log files, using printf-like APIs. + * + * For compatibility with C library APIs, this returns an "unsigned long" + * type and should be used with the "%lx" format specifier in a printf + * format string. + * + * @note No assumptions should be made about the actual integer value, + * such as its base/range. It may be printed, but should not be modified + * or tested/compared using other arithmetic ops, and should never be used + * as the index to an array or table. See the related function + * CFE_ES_ResourceID_ToIndex() for cases where a zero-based array/table index + * is needed. + * + * @sa CFE_ES_ResourceID_FromInteger() + * + * @param id[in] Resource ID to convert + * @returns Integer value corresponding to ID + */ +static inline unsigned long CFE_ES_ResourceID_ToInteger(uint32 id) +{ + return (id); +} + +/** + * @brief Convert an integer to a resource ID. + * + * This is the inverse of CFE_ES_ResourceID_ToInteger(), and reconstitutes + * the original CFE_ES_ResourceID_t value from the integer representation. + * + * This may be used, for instance, where an ID value is parsed from a text + * file or message using C library APIs such as scanf() or strtoul(). + * + * @sa CFE_ES_ResourceID_ToInteger() + * + * @param Value[in] Integer value to convert + * @returns ID value corresponding to integer + */ +static inline uint32 CFE_ES_ResourceID_FromInteger(unsigned long Value) +{ + return (Value); +} + + +/** + * @brief Obtain an index value correlating to an ES Application ID + * + * This calculates a zero based integer value that may be used for indexing + * into a local resource table/array. + * + * Index values are only guaranteed to be unique for resources of the same + * type. For instance, the indices corresponding to two [valid] application + * IDs will never overlap, but the index of an application and a library ID + * may be the same. Furthermore, indices may be reused if a resource is + * deleted and re-created. + * + * @note There is no inverse of this function - indices cannot be converted + * back to the original AppID value. The caller should retain the original ID + * for future use. + * + * @param AppID[in] Application ID to convert + * @param Idx[out] Buffer where the calculated index will be stored + * + * @return Execution status, see @ref CFEReturnCodes + * @retval #CFE_SUCCESS @copybrief CFE_SUCCESS + * @retval #CFE_ES_RESOURCE_ID_INVALID @copybrief CFE_ES_RESOURCE_ID_INVALID + */ +int32 CFE_ES_AppID_ToIndex(uint32 AppID, uint32 *Idx); + +/** + * @brief Obtain an index value correlating to an ES Task ID + * + * This calculates a zero based integer value that may be used for indexing + * into a local resource table/array. + * + * Index values are only guaranteed to be unique for resources of the same + * type. For instance, the indices corresponding to two [valid] Task + * IDs will never overlap, but the index of an Task and a library ID + * may be the same. Furthermore, indices may be reused if a resource is + * deleted and re-created. + * + * @note There is no inverse of this function - indices cannot be converted + * back to the original TaskID value. The caller should retain the original ID + * for future use. + * + * @param TaskID[in] Task ID to convert + * @param Idx[out] Buffer where the calculated index will be stored + * + * @return Execution status, see @ref CFEReturnCodes + * @retval #CFE_SUCCESS @copybrief CFE_SUCCESS + * @retval #CFE_ES_RESOURCE_ID_INVALID @copybrief CFE_ES_RESOURCE_ID_INVALID + */ +int32 CFE_ES_TaskID_ToIndex(uint32 TaskID, uint32 *Idx); + /** * \brief Application Information * @@ -684,6 +781,28 @@ int32 CFE_ES_GetResetType(uint32 *ResetSubtypePtr); ******************************************************************************/ int32 CFE_ES_GetAppID(uint32 *AppIdPtr); +/*****************************************************************************/ +/** +** \brief Get the task ID of the calling context +** +** \par Description +** This retrieves the current task context from OSAL +** +** \par Assumptions, External Events, and Notes: +** Applications which desire to call other CFE ES services such as +** CFE_ES_TaskGetInfo() should use this API rather than getting the ID +** from OSAL directly via OS_TaskGetId(). +** +** \param[out] TaskIdPtr Pointer to variable that is to receive the ID. +** Will be set to the ID of the calling task. +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_TASKID \copybrief CFE_ES_ERR_TASKID +** +******************************************************************************/ +int32 CFE_ES_GetTaskID(uint32 *TaskIdPtr); + /*****************************************************************************/ /** ** \brief Get an Application ID associated with a specified Application name diff --git a/fsw/cfe-core/unit-test/es_UT.c b/fsw/cfe-core/unit-test/es_UT.c index 8e9f2c48c..3409dd0db 100644 --- a/fsw/cfe-core/unit-test/es_UT.c +++ b/fsw/cfe-core/unit-test/es_UT.c @@ -54,13 +54,8 @@ extern int32 dummy_function(void); /* Create a startup script buffer for a maximum of 5 lines * 80 chars/line */ char StartupScript[MAX_STARTUP_SCRIPT]; -/* - * Macro to convert UT OSAL IDs to array index - * This should work for both the opaque and non-opaque IDs as - * provided by UT stub libraries (not for real code, though!) - */ -#define ES_UT_OSALID_TO_ARRAYIDX(x) (x & 0xFF) - +/* Number of apps instantiated */ +uint32 ES_UT_NumApps; static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_NOOP_CC = { @@ -197,10 +192,155 @@ static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_SEND_HK = .MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_ES_SEND_HK_MID) }; - /* ** Functions */ +uint32 ES_UT_MakeAppIdForIndex(uint32 ArrayIdx) +{ + /* UT hack - make up AppID values in a manner similar to FSW. + * Real apps should never do this. */ + return ArrayIdx; +} + +uint32 ES_UT_MakeTaskIdForIndex(uint32 ArrayIdx) +{ + /* UT hack - make up TaskID values in a manner similar to FSW. + * Real apps should never do this. */ + return (ArrayIdx + 0x40010000); +} +/* + * Helper function to setup a single app ID in the given state, along with + * a main task ID. A pointer to the App and Task record is output so the + * record can be modified + */ +void ES_UT_SetupSingleAppId(CFE_ES_AppType_Enum_t AppType, CFE_ES_AppState_Enum_t AppState, + const char *AppName, CFE_ES_AppRecord_t **OutAppRec, CFE_ES_TaskRecord_t **OutTaskRec) +{ + uint32 UtOsalId; + uint32 UtTaskId; + uint32 UtAppId; + uint32 ArrayIdx; + CFE_ES_AppRecord_t *LocalAppPtr; + CFE_ES_TaskRecord_t *LocalTaskPtr; + + OS_TaskCreate(&UtOsalId, "UT", NULL, NULL, 0, 0, 0); + OS_ConvertToArrayIndex(UtOsalId, &ArrayIdx); + UtTaskId = UtOsalId; + UtAppId = ES_UT_MakeAppIdForIndex(ES_UT_NumApps); + ++ES_UT_NumApps; + + LocalTaskPtr = CFE_ES_LocateTaskRecordByID(UtTaskId); + LocalAppPtr = CFE_ES_LocateAppRecordByID(UtAppId); + CFE_ES_TaskRecordSetUsed(LocalTaskPtr, UtTaskId); + CFE_ES_AppRecordSetUsed(LocalAppPtr, UtAppId); + LocalTaskPtr->AppId = UtAppId; + LocalAppPtr->TaskInfo.MainTaskId = UtTaskId; + LocalAppPtr->AppState = AppState; + LocalAppPtr->Type = AppType; + + if (AppName) + { + strncpy(LocalAppPtr->StartParams.Name, AppName, + sizeof(LocalAppPtr->StartParams.Name)-1); + LocalAppPtr->StartParams.Name[sizeof(LocalAppPtr->StartParams.Name)-1] = 0; + strncpy(LocalTaskPtr->TaskName, AppName, + sizeof(LocalTaskPtr->TaskName)-1); + LocalTaskPtr->TaskName[sizeof(LocalTaskPtr->TaskName)-1] = 0; + } + + if (OutAppRec) + { + *OutAppRec = LocalAppPtr; + } + if (OutTaskRec) + { + *OutTaskRec = LocalTaskPtr; + } + + if (AppType == CFE_ES_AppType_CORE) + { + ++CFE_ES_Global.RegisteredCoreApps; + } + if (AppType == CFE_ES_AppType_EXTERNAL) + { + ++CFE_ES_Global.RegisteredExternalApps; + } + ++CFE_ES_Global.RegisteredTasks; +} + +/* + * Helper function to setup a child task ID associated with the given + * app record. A pointer to the Task record is output so the record + * can be modified + */ +void ES_UT_SetupChildTaskId(const CFE_ES_AppRecord_t *ParentApp, const char *TaskName, CFE_ES_TaskRecord_t **OutTaskRec) +{ + uint32 UtOsalId; + uint32 UtTaskId; + uint32 UtAppId; + uint32 ArrayIdx; + CFE_ES_TaskRecord_t *LocalTaskPtr; + + UtAppId = CFE_ES_AppRecordGetID(ParentApp); + + OS_TaskCreate(&UtOsalId, "C", NULL, NULL, 0, 0, 0); + OS_ConvertToArrayIndex(UtOsalId, &ArrayIdx); + UtTaskId = UtOsalId; + + LocalTaskPtr = &CFE_ES_Global.TaskTable[ArrayIdx]; + CFE_ES_TaskRecordSetUsed(LocalTaskPtr, UtTaskId); + LocalTaskPtr->AppId = UtAppId; + + if (TaskName) + { + strncpy(LocalTaskPtr->TaskName, TaskName, + sizeof(LocalTaskPtr->TaskName)-1); + LocalTaskPtr->TaskName[sizeof(LocalTaskPtr->TaskName)-1] = 0; + } + + if (OutTaskRec) + { + *OutTaskRec = LocalTaskPtr; + } + + ++CFE_ES_Global.RegisteredTasks; +} + +void ES_UT_SetupSingleCDSRegistry(const char *CDSName, bool IsTable, + CFE_ES_CDS_RegRec_t **OutRegRec) +{ + CFE_ES_CDS_RegRec_t *LocalRegRecPtr; + + /* + * Note - because the "ES_ResetUnitTest()" routine wipes the entire + * global data structure, this runtime var needs to be re-initialized. + */ + CFE_ES_Global.CDSVars.MaxNumRegEntries = + sizeof(CFE_ES_Global.CDSVars.Registry) / sizeof(CFE_ES_CDS_RegRec_t); + + LocalRegRecPtr = &CFE_ES_Global.CDSVars.Registry[0]; + if (CDSName != NULL) + { + strncpy(LocalRegRecPtr->Name, CDSName, + sizeof(LocalRegRecPtr->Name) - 1); + LocalRegRecPtr->Name[sizeof(LocalRegRecPtr->Name) - 1] = 0; + } + else + { + LocalRegRecPtr->Name[0] = 0; + } + LocalRegRecPtr->Taken = true; + LocalRegRecPtr->Table = IsTable; + LocalRegRecPtr->MemHandle = + sizeof(CFE_ES_Global.CDSVars.ValidityField); + + if (OutRegRec) + { + *OutRegRec = LocalRegRecPtr; + } +} + + int32 ES_UT_SetupOSCleanupHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) @@ -245,21 +385,25 @@ static int32 ES_UT_SetAppStateHook(void *UserObj, int32 StubRetcode, { ES_UT_SetAppStateHook_t *StateHook = UserObj; uint32 i; + CFE_ES_AppRecord_t *AppRecPtr; + + AppRecPtr = CFE_ES_Global.AppTable; for (i=0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; ++i) { - if (CFE_ES_Global.AppTable[i].AppState != CFE_ES_AppState_UNDEFINED) + if ( CFE_ES_AppRecordIsUsed(AppRecPtr) ) { /* If no filter object supplied, set all apps to RUNNING */ if (StateHook == NULL) { - CFE_ES_Global.AppTable[i].AppState = CFE_ES_AppState_RUNNING; + AppRecPtr->AppState = CFE_ES_AppState_RUNNING; } - else if (StateHook->AppType == 0 || CFE_ES_Global.AppTable[i].Type == StateHook->AppType) + else if (StateHook->AppType == 0 || AppRecPtr->Type == StateHook->AppType) { - CFE_ES_Global.AppTable[i].AppState = StateHook->AppState; + AppRecPtr->AppState = StateHook->AppState; } } + ++AppRecPtr; } return StubRetcode; @@ -280,6 +424,7 @@ void UtTest_Setup(void) UT_ADD_TEST(TestTask); UT_ADD_TEST(TestPerf); UT_ADD_TEST(TestAPI); + UT_ADD_TEST(TestGenericCounterAPI); UT_ADD_TEST(TestCDS); UT_ADD_TEST(TestCDSMempool); UT_ADD_TEST(TestESMempool); @@ -292,24 +437,10 @@ void UtTest_Setup(void) */ void ES_ResetUnitTest(void) { - int j; - UT_InitData(); - for (j = 0; j < CFE_PLATFORM_ES_MAX_APPLICATIONS; j++) - { - CFE_ES_Global.AppTable[j].AppState = CFE_ES_AppState_UNDEFINED; - } - - for (j = 0; j < OS_MAX_TASKS; j++) - { - CFE_ES_Global.TaskTable[j].RecordUsed = false; - } - - for (j = 0; j < CFE_PLATFORM_ES_MAX_LIBRARIES; j++) - { - CFE_ES_Global.LibTable[j].RecordUsed = false; - } + memset(&CFE_ES_Global, 0, sizeof(CFE_ES_Global)); + ES_UT_NumApps = 0; } /* end ES_ResetUnitTest() */ void TestInit(void) @@ -352,8 +483,8 @@ void TestStartupErrorPaths(void) ES_UT_SetAppStateHook_t StateHook; uint32 PanicStatus; uint32 ResetType; - uint32 Id; - uint32 TestObjId; + CFE_ES_TaskRecord_t *TaskRecPtr; + CFE_ES_AppRecord_t *AppRecPtr; #ifdef UT_VERBOSE UT_Text("Begin Test Startup Error Paths\n"); @@ -402,10 +533,13 @@ void TestStartupErrorPaths(void) CFE_ES_Main(CFE_PSP_RST_TYPE_POWERON, 1, 1, (char *) CFE_PLATFORM_ES_NONVOL_STARTUP_FILE); UT_Report(__FILE__, __LINE__, - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_STARTUP_SYNC_FAIL_1]) && + UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_STARTUP_SYNC_FAIL_1]), + "CFE_ES_Main", + "Startup sync failure 1"); + UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_STARTUP_SYNC_FAIL_2]), "CFE_ES_Main", - "Startup sync failure"); + "Startup sync failure 2"); /* Perform a power on reset with a hardware special sub-type */ ES_ResetUnitTest(); @@ -631,12 +765,14 @@ void TestStartupErrorPaths(void) /* Test reading the object table where a record used error occurs */ ES_ResetUnitTest(); + TaskRecPtr = CFE_ES_Global.TaskTable; for (j = 0; j < OS_MAX_TASKS; j++) { /* Mark all entries as "used" to ensure that the log message gets * output */ - CFE_ES_Global.TaskTable[j].RecordUsed = true; + CFE_ES_TaskRecordSetUsed(TaskRecPtr, ES_UT_MakeTaskIdForIndex(j)); + ++TaskRecPtr; } CFE_ES_CreateObjects(); @@ -650,13 +786,14 @@ void TestStartupErrorPaths(void) * calling a function */ ES_ResetUnitTest(); - + TaskRecPtr = CFE_ES_Global.TaskTable; for (j = 0; j < OS_MAX_TASKS; j++) { /* Mark all entries as "used" to ensure that the log message gets * output */ - CFE_ES_Global.TaskTable[j].RecordUsed = true; + CFE_ES_TaskRecordSetUsed(TaskRecPtr, ES_UT_MakeAppIdForIndex(j)); + ++TaskRecPtr; } UT_SetDeferredRetcode(UT_KEY(CFE_TBL_EarlyInit), 1, -1); @@ -683,35 +820,46 @@ void TestStartupErrorPaths(void) /* Test reading the object table where all app slots are taken */ ES_ResetUnitTest(); - + AppRecPtr = CFE_ES_Global.AppTable; for (j = 0; j < CFE_PLATFORM_ES_MAX_APPLICATIONS; j++) { - CFE_ES_Global.AppTable[j].AppState = CFE_ES_AppState_RUNNING; + CFE_ES_AppRecordSetUsed(AppRecPtr, ES_UT_MakeAppIdForIndex(j)); + ++AppRecPtr; } CFE_ES_CreateObjects(); UT_Report(__FILE__, __LINE__, - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_NO_FREE_CORE_APP_SLOTS]) == 5 && - UT_GetStubCount(UT_KEY(OS_printf)) == 13, + UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_NO_FREE_CORE_APP_SLOTS]) == 5, "CFE_ES_CreateObjects", - "No free application slots available"); + "No free application slots available, message"); + UT_Report(__FILE__, __LINE__, + UT_GetStubCount(UT_KEY(OS_printf)) == 18, + "CFE_ES_CreateObjects", + "No free application slots available, printf count"); /* Test reading the object table with a NULL function pointer */ ES_ResetUnitTest(); - + AppRecPtr = CFE_ES_Global.AppTable; for (j = 0; j < CFE_PLATFORM_ES_MAX_APPLICATIONS; j++) { - CFE_ES_Global.AppTable[j].AppState = CFE_ES_AppState_RUNNING; + CFE_ES_AppRecordSetUsed(AppRecPtr, ES_UT_MakeAppIdForIndex(j)); + ++AppRecPtr; } CFE_ES_ObjectTable[1].ObjectType = CFE_ES_FUNCTION_CALL; CFE_ES_CreateObjects(); UT_Report(__FILE__, __LINE__, - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_NO_FREE_CORE_APP_SLOTS]) == 5 && - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_FUNCTION_POINTER]) && - UT_GetStubCount(UT_KEY(OS_printf)) == 14, + UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_NO_FREE_CORE_APP_SLOTS]) == 5, + "CFE_ES_CreateObjects", + "Bad function pointer, app slots message"); + UT_Report(__FILE__, __LINE__, + UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_FUNCTION_POINTER]), + "CFE_ES_CreateObjects", + "Bad function pointer message"); + UT_Report(__FILE__, __LINE__, + UT_GetStubCount(UT_KEY(OS_printf)) == 19, "CFE_ES_CreateObjects", - "Bad function pointer"); + "Bad function pointer, printf count"); /* Test response to an invalid startup type */ ES_ResetUnitTest(); @@ -743,8 +891,7 @@ void TestStartupErrorPaths(void) /* Test application sync delay where the operation times out */ ES_ResetUnitTest(); /* This prep is necessary so GetAppId works */ - CFE_ES_Global.TaskTable[1].RecordUsed = true; - CFE_ES_Global.TaskTable[1].AppId = 1; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppType_CORE, NULL, &AppRecPtr, NULL); CFE_ES_Global.SystemState = CFE_ES_SystemState_CORE_READY; UT_Report(__FILE__, __LINE__, CFE_ES_WaitForSystemState(CFE_ES_SystemState_OPERATIONAL, @@ -758,20 +905,13 @@ void TestStartupErrorPaths(void) * of CFE_ES_SystemState_SHUTDOWN */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.AppTable[Id].AppState = - CFE_ES_AppState_EARLY_INIT; /* This prep is necessary so GetAppId works */ - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppType_CORE, NULL, &AppRecPtr, NULL); CFE_ES_Global.SystemState = CFE_ES_SystemState_CORE_READY; - UT_Report(__FILE__, __LINE__, CFE_ES_WaitForSystemState(CFE_ES_SystemState_SHUTDOWN, CFE_PLATFORM_ES_STARTUP_SCRIPT_TIMEOUT_MSEC) == CFE_ES_OPERATION_TIMED_OUT && - CFE_ES_Global.AppTable[Id].AppState == + AppRecPtr->AppState == CFE_ES_AppState_STOPPED, "CFE_ES_WaitForSystemState", "Min System State is CFE_ES_SystemState_SHUTDOWN"); @@ -781,21 +921,15 @@ void TestStartupErrorPaths(void) * of CFE_ES_SystemState_APPS_INIT */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.AppTable[Id].AppState = - CFE_ES_AppState_EARLY_INIT; /* This prep is necessary so GetAppId works */ - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppType_CORE, NULL, &AppRecPtr, NULL); CFE_ES_Global.SystemState = CFE_ES_SystemState_CORE_READY; UT_Report(__FILE__, __LINE__, CFE_ES_WaitForSystemState(CFE_ES_SystemState_APPS_INIT, CFE_PLATFORM_ES_STARTUP_SCRIPT_TIMEOUT_MSEC) == CFE_ES_OPERATION_TIMED_OUT && - CFE_ES_Global.AppTable[Id].AppState == + AppRecPtr->AppState == CFE_ES_AppState_LATE_INIT, "CFE_ES_WaitForSystemState", "Min System State is CFE_ES_SystemState_APPS_INIT"); @@ -808,8 +942,9 @@ void TestApps(void) int j; CFE_ES_AppInfo_t AppInfo; char LongLibraryName[sizeof(CFE_ES_Global.LibTable[0].LibName)+1]; - uint32 Id, Id2, Id3, Id4; - uint32 TestObjId, TestObjId2, TestObjId3, TestObjId4; + uint32 Id; + CFE_ES_TaskRecord_t *UtTaskRecPtr; + CFE_ES_AppRecord_t *UtAppRecPtr; #ifdef UT_VERBOSE UT_Text("Begin Test Apps\n"); @@ -984,10 +1119,11 @@ void TestApps(void) /* Test application loading and creation where all app slots are taken */ ES_ResetUnitTest(); - + UtAppRecPtr = CFE_ES_Global.AppTable; for (j = 0; j < CFE_PLATFORM_ES_MAX_APPLICATIONS; j++) { - CFE_ES_Global.AppTable[j].AppState = CFE_ES_AppState_RUNNING; + CFE_ES_AppRecordSetUsed(UtAppRecPtr, ES_UT_MakeAppIdForIndex(j)); + ++UtAppRecPtr; } Return = CFE_ES_AppCreate(&Id, @@ -1070,23 +1206,22 @@ void TestApps(void) "CFE_ES_LoadLibrary", "Load shared library bad argument (library name too long)"); +#ifdef jphfix /* Test successful shared library loading and initialization */ UT_InitData(); UT_SetDummyFuncRtn(OS_SUCCESS); - Id = CFE_PLATFORM_ES_MAX_LIBRARIES; Return = CFE_ES_LoadLibrary(&Id, "/cf/apps/tst_lib.bundle", "TST_LIB_Init", "TST_LIB"); UT_Report(__FILE__, __LINE__, Return == CFE_SUCCESS && - Id < CFE_PLATFORM_ES_MAX_LIBRARIES && + CFE_ES_ResourceId < CFE_PLATFORM_ES_MAX_LIBRARIES && CFE_ES_Global.LibTable[Id].RecordUsed == true, "CFE_ES_LoadLibrary", "successful"); /* Try loading same library again, should return the DUPLICATE code */ - Id = CFE_PLATFORM_ES_MAX_LIBRARIES; Return = CFE_ES_LoadLibrary(&Id, "/cf/apps/tst_lib.bundle", "TST_LIB_Init", @@ -1097,7 +1232,7 @@ void TestApps(void) CFE_ES_Global.LibTable[Id].RecordUsed == true, "CFE_ES_LoadLibrary", "Duplicate"); - +#endif /* Test shared library loading and initialization where the library * fails to load */ @@ -1164,18 +1299,15 @@ void TestApps(void) * expires for a waiting application */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_WAITING; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec = 0; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_WAITING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; + UtAppRecPtr->ControlReq.AppTimerMsec = 0; memset(&CFE_ES_TaskData.BackgroundAppScanState, 0, sizeof(CFE_ES_TaskData.BackgroundAppScanState)); CFE_ES_RunAppTableScan(0, &CFE_ES_TaskData.BackgroundAppScanState); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_PCR_ERR2_EID) && - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec == 0 && - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest == CFE_ES_RunStatus_SYS_DELETE, + UtAppRecPtr->ControlReq.AppTimerMsec == 0 && + UtAppRecPtr->ControlReq.AppControlRequest == CFE_ES_RunStatus_SYS_DELETE, "CFE_ES_RunAppTableScan", "Waiting; process control request"); @@ -1183,16 +1315,13 @@ void TestApps(void) * has not expired for a waiting application */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_WAITING; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_EXIT; - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec = 5000; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_WAITING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_EXIT; + UtAppRecPtr->ControlReq.AppTimerMsec = 5000; CFE_ES_RunAppTableScan(1000, &CFE_ES_TaskData.BackgroundAppScanState); UT_Report(__FILE__, __LINE__, - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec == 4000 && - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest == CFE_ES_RunStatus_APP_EXIT, + UtAppRecPtr->ControlReq.AppTimerMsec == 4000 && + UtAppRecPtr->ControlReq.AppControlRequest == CFE_ES_RunStatus_APP_EXIT, "CFE_ES_RunAppTableScan", "Decrement timer"); @@ -1200,17 +1329,14 @@ void TestApps(void) * has stopped and is ready to be acted on */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_STOPPED; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec = 0; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_STOPPED, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; + UtAppRecPtr->ControlReq.AppTimerMsec = 0; CFE_ES_RunAppTableScan(0, &CFE_ES_TaskData.BackgroundAppScanState); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_PCR_ERR2_EID) && - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest == CFE_ES_RunStatus_SYS_DELETE && - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec == 0, + UtAppRecPtr->ControlReq.AppControlRequest == CFE_ES_RunStatus_SYS_DELETE && + UtAppRecPtr->ControlReq.AppTimerMsec == 0, "CFE_ES_RunAppTableScan", "Stopped; process control request"); @@ -1218,16 +1344,12 @@ void TestApps(void) * has stopped and is ready to be acted on */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_EARLY_INIT; - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec = 5000; - + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_EARLY_INIT, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppTimerMsec = 5000; CFE_ES_RunAppTableScan(0, &CFE_ES_TaskData.BackgroundAppScanState); UT_Report(__FILE__, __LINE__, UT_GetNumEventsSent() == 0 && - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec == 5000, + UtAppRecPtr->ControlReq.AppTimerMsec == 5000, "CFE_ES_RunAppTableScan", "Initializing; process control request"); @@ -1235,11 +1357,9 @@ void TestApps(void) * undefined control request state */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = 0; - CFE_ES_ProcessControlRequest(Id); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = 0x12345; + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_PCR_ERR2_EID), "CFE_ES_ProcessControlRequest", @@ -1247,26 +1367,21 @@ void TestApps(void) /* Test a successful control action request to exit an application */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.FileName, + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + strncpy((char *) UtAppRecPtr->StartParams.FileName, "/ram/Filename", OS_MAX_PATH_LEN); - CFE_ES_Global.AppTable[Id].StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.EntryPoint, + UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NotNULL", OS_MAX_API_NAME); - CFE_ES_Global.AppTable[Id].StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.AppTable[Id].StartParams.Priority = 255; - CFE_ES_Global.AppTable[Id].StartParams.StackSize = 8192; - CFE_ES_Global.AppTable[Id].StartParams.ExceptionAction = 0; - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->StartParams.Priority = 255; + UtAppRecPtr->StartParams.StackSize = 8192; + UtAppRecPtr->StartParams.ExceptionAction = 0; + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_EXIT; - CFE_ES_ProcessControlRequest(Id); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_EXIT_APP_INF_EID), "CFE_ES_ProcessControlRequest", @@ -1276,14 +1391,11 @@ void TestApps(void) * request fails */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_EXIT; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_EXIT; UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_ProcessControlRequest(Id); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_EXIT_APP_ERR_EID), "CFE_ES_ProcessControlRequest", @@ -1293,15 +1405,12 @@ void TestApps(void) * request fails */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_ProcessControlRequest(Id); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_STOP_ERR3_EID), "CFE_ES_ProcessControlRequest", @@ -1311,15 +1420,12 @@ void TestApps(void) * request fails due to a CleanUpApp error */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART; UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_ProcessControlRequest(Id); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_RESTART_APP_ERR4_EID), "CFE_ES_ProcessControlRequest", @@ -1329,15 +1435,12 @@ void TestApps(void) * request fails due to an AppCreate error */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART; - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); UT_SetForceFail(UT_KEY(OS_TaskCreate), OS_ERROR); - CFE_ES_ProcessControlRequest(Id); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_RESTART_APP_ERR3_EID), "CFE_ES_ProcessControlRequest", @@ -1347,21 +1450,12 @@ void TestApps(void) * request fails due to a CleanUpApp error */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RELOAD; - - /* Use the OSAL stubs to populate the MainTaskId and ModuleId fields with - * something valid - */ - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); - CFE_ES_ProcessControlRequest(Id); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_RELOAD_APP_ERR4_EID), "CFE_ES_ProcessControlRequest", @@ -1371,15 +1465,12 @@ void TestApps(void) * request fails due to an AppCreate error */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RELOAD; - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); UT_SetForceFail(UT_KEY(OS_TaskCreate), OS_ERROR); - CFE_ES_ProcessControlRequest(Id); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_RELOAD_APP_ERR3_EID), "CFE_ES_ProcessControlRequest", @@ -1389,26 +1480,21 @@ void TestApps(void) * has an error */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.FileName, + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + strncpy((char *) UtAppRecPtr->StartParams.FileName, "/ram/FileName", OS_MAX_PATH_LEN); - CFE_ES_Global.AppTable[Id].StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.EntryPoint, "NULL", + UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NULL", OS_MAX_API_NAME); - CFE_ES_Global.AppTable[Id].StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.AppTable[Id].StartParams.Priority = 255; - CFE_ES_Global.AppTable[Id].StartParams.StackSize = 8192; - CFE_ES_Global.AppTable[Id].StartParams.ExceptionAction = 0; - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->StartParams.Priority = 255; + UtAppRecPtr->StartParams.StackSize = 8192; + UtAppRecPtr->StartParams.ExceptionAction = 0; + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_ERROR; - CFE_ES_ProcessControlRequest(Id); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_ERREXIT_APP_INF_EID), "CFE_ES_ProcessControlRequest", @@ -1418,15 +1504,12 @@ void TestApps(void) * has an error where the request fails */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_ERROR; - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_ProcessControlRequest(Id); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_ERREXIT_APP_ERR_EID), "CFE_ES_ProcessControlRequest", @@ -1434,26 +1517,21 @@ void TestApps(void) /* Test a successful control action request to stop an application */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.FileName, + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + strncpy((char *) UtAppRecPtr->StartParams.FileName, "/ram/FileName", OS_MAX_PATH_LEN); - CFE_ES_Global.AppTable[Id].StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.EntryPoint, "NULL", + UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NULL", OS_MAX_API_NAME); - CFE_ES_Global.AppTable[Id].StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.AppTable[Id].StartParams.Priority = 255; - CFE_ES_Global.AppTable[Id].StartParams.StackSize = 8192; - CFE_ES_Global.AppTable[Id].StartParams.ExceptionAction = 0; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->StartParams.Priority = 255; + UtAppRecPtr->StartParams.StackSize = 8192; + UtAppRecPtr->StartParams.ExceptionAction = 0; + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_ProcessControlRequest(Id); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_STOP_INF_EID), "CFE_ES_ProcessControlRequest", @@ -1461,26 +1539,21 @@ void TestApps(void) /* Test a successful control action request to restart an application */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.FileName, + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + strncpy((char *) UtAppRecPtr->StartParams.FileName, "/ram/FileName", OS_MAX_PATH_LEN); - CFE_ES_Global.AppTable[Id].StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.EntryPoint, "NULL", + UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NULL", OS_MAX_API_NAME); - CFE_ES_Global.AppTable[Id].StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.AppTable[Id].StartParams.Priority = 255; - CFE_ES_Global.AppTable[Id].StartParams.StackSize = 8192; - CFE_ES_Global.AppTable[Id].StartParams.ExceptionAction = 0; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->StartParams.Priority = 255; + UtAppRecPtr->StartParams.StackSize = 8192; + UtAppRecPtr->StartParams.ExceptionAction = 0; + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART; - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_ProcessControlRequest(Id); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_RESTART_APP_INF_EID), "CFE_ES_ProcessControlRequest", @@ -1488,26 +1561,21 @@ void TestApps(void) /* Test a successful control action request to reload an application */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.FileName, + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + strncpy((char *) UtAppRecPtr->StartParams.FileName, "/ram/FileName", OS_MAX_PATH_LEN); - CFE_ES_Global.AppTable[Id].StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.EntryPoint, "NULL", + UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NULL", OS_MAX_API_NAME); - CFE_ES_Global.AppTable[Id].StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.AppTable[Id].StartParams.Priority = 255; - CFE_ES_Global.AppTable[Id].StartParams.StackSize = 8192; - CFE_ES_Global.AppTable[Id].StartParams.ExceptionAction = 0; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->StartParams.Priority = 255; + UtAppRecPtr->StartParams.StackSize = 8192; + UtAppRecPtr->StartParams.ExceptionAction = 0; + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RELOAD; - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_ProcessControlRequest(Id); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_RELOAD_APP_INF_EID), "CFE_ES_ProcessControlRequest", @@ -1517,39 +1585,30 @@ void TestApps(void) * state (exception) */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", - NULL, NULL, 0, 0, 0); - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.FileName, + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + strncpy((char *) UtAppRecPtr->StartParams.FileName, "/ram/FileName", OS_MAX_PATH_LEN); - CFE_ES_Global.AppTable[Id].StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.EntryPoint, "NULL", + UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NULL", OS_MAX_API_NAME); - CFE_ES_Global.AppTable[Id].StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.AppTable[Id].StartParams.Priority = 255; - CFE_ES_Global.AppTable[Id].StartParams.StackSize = 8192; - CFE_ES_Global.AppTable[Id].StartParams.ExceptionAction = 0; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->StartParams.Priority = 255; + UtAppRecPtr->StartParams.StackSize = 8192; + UtAppRecPtr->StartParams.ExceptionAction = 0; + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_EXCEPTION; - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_ProcessControlRequest(Id); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + CFE_ES_ProcessControlRequest(UtAppRecPtr); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_PCR_ERR1_EID), "CFE_ES_ProcessControlRequest", "Invalid state"); - /* Test listing the OS resources in use */ - ES_ResetUnitTest(); - /* Test populating the application information structure with data */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + Id = CFE_ES_AppRecordGetID(UtAppRecPtr); UT_Report(__FILE__, __LINE__, CFE_ES_GetAppInfo(&AppInfo, Id) == CFE_SUCCESS, "CFE_ES_GetAppInfo", @@ -1559,9 +1618,8 @@ void TestApps(void) * a null application information pointer */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + Id = CFE_ES_AppRecordGetID(UtAppRecPtr); UT_Report(__FILE__, __LINE__, CFE_ES_GetAppInfo(NULL, Id) == CFE_ES_ERR_BUFFER, "CFE_ES_GetAppInfo", @@ -1571,8 +1629,9 @@ void TestApps(void) * inactive application ID */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + Id = CFE_ES_AppRecordGetID(UtAppRecPtr); + CFE_ES_AppRecordSetFree(UtAppRecPtr); UT_Report(__FILE__, __LINE__, CFE_ES_GetAppInfo(&AppInfo, Id) == CFE_ES_ERR_APPID, "CFE_ES_GetAppInfo", @@ -1582,9 +1641,9 @@ void TestApps(void) * application ID value greater than the maximum allowed */ ES_ResetUnitTest(); + Id = ES_UT_MakeAppIdForIndex(99999); UT_Report(__FILE__, __LINE__, - CFE_ES_GetAppInfo(&AppInfo, - CFE_PLATFORM_ES_MAX_APPLICATIONS) == CFE_ES_ERR_APPID, + CFE_ES_GetAppInfo(&AppInfo, Id) == CFE_ES_ERR_APPID, "CFE_ES_GetAppInfo", "Application ID exceeds maximum"); @@ -1592,10 +1651,8 @@ void TestApps(void) * application ID, but with a failure to retrieve the module information */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + Id = CFE_ES_AppRecordGetID(UtAppRecPtr); UT_SetDeferredRetcode(UT_KEY(OS_ModuleInfo), 1, OS_ERROR); UT_Report(__FILE__, __LINE__, CFE_ES_GetAppInfo(&AppInfo, Id) == CFE_SUCCESS, @@ -1606,22 +1663,14 @@ void TestApps(void) * delete and close failures */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); ES_UT_SetupForOSCleanup(); - /* Use the "TaskCreate" stub to populate the MainTaskId field with - * something valid - */ - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", NULL, - NULL, 0, 0, 0); - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); UT_SetForceFail(UT_KEY(OS_TaskDelete), OS_ERROR); UT_SetForceFail(UT_KEY(OS_close), OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanUpApp(Id) == CFE_ES_APP_CLEANUP_ERR, + CFE_ES_CleanUpApp(UtAppRecPtr) == CFE_ES_APP_CLEANUP_ERR, "CFE_ES_CleanUpApp", "Task OS delete and close failure"); @@ -1629,18 +1678,13 @@ void TestApps(void) * mutex delete failure */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - OS_TaskCreate(&TestObjId2, "UT", NULL, NULL, 0, 0, 0); - Id2 = ES_UT_OSALID_TO_ARRAYIDX(TestObjId2); - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.TaskTable[Id2].RecordUsed = true; - CFE_ES_Global.TaskTable[Id2].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, NULL); ES_UT_SetupForOSCleanup(); UT_SetDeferredRetcode(UT_KEY(OS_MutSemDelete), 1, OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanUpApp(Id) == CFE_ES_APP_CLEANUP_ERR, + CFE_ES_CleanUpApp(UtAppRecPtr) == CFE_ES_APP_CLEANUP_ERR, "CFE_ES_CleanUpApp", "Task mutex delete failure"); @@ -1648,14 +1692,11 @@ void TestApps(void) * failure to unload the module */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - OS_TaskCreate(&CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId, "UT", NULL, - NULL, 0, 0, 0); - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); UT_SetDeferredRetcode(UT_KEY(OS_ModuleUnload), 1, OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanUpApp(Id) == CFE_ES_APP_CLEANUP_ERR, + CFE_ES_CleanUpApp(UtAppRecPtr) == CFE_ES_APP_CLEANUP_ERR, "CFE_ES_CleanUpApp", "Module unload failure"); @@ -1663,12 +1704,11 @@ void TestApps(void) * EVS application cleanup fails */ ES_ResetUnitTest(); - OS_TaskCreate(&CFE_ES_Global.AppTable[0].TaskInfo.MainTaskId, "UT", NULL, - NULL, 0, 0, 0); - OS_ModuleLoad(&CFE_ES_Global.AppTable[0].StartParams.ModuleId, NULL, NULL); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanUpApp(0) == CFE_ES_APP_CLEANUP_ERR, + CFE_ES_CleanUpApp(UtAppRecPtr) == CFE_ES_APP_CLEANUP_ERR, "CFE_ES_CleanUpApp", "EVS application cleanup failure"); @@ -1676,11 +1716,12 @@ void TestApps(void) * deleting mutexes */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); ES_UT_SetupForOSCleanup(); + Id = CFE_ES_TaskRecordGetID(UtTaskRecPtr); UT_SetDeferredRetcode(UT_KEY(OS_MutSemDelete), 1, OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanupTaskResources(TestObjId) == + CFE_ES_CleanupTaskResources(Id) == CFE_ES_MUT_SEM_DELETE_ERR, "CFE_ES_CleanupTaskResources", "Mutex delete failure"); @@ -1689,11 +1730,12 @@ void TestApps(void) * binary semaphores */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); ES_UT_SetupForOSCleanup(); + Id = CFE_ES_TaskRecordGetID(UtTaskRecPtr); UT_SetDeferredRetcode(UT_KEY(OS_BinSemDelete), 1, OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanupTaskResources(TestObjId) == + CFE_ES_CleanupTaskResources(Id) == CFE_ES_BIN_SEM_DELETE_ERR, "CFE_ES_CleanupTaskResources", "Binary semaphore delete failure"); @@ -1702,11 +1744,12 @@ void TestApps(void) * counting semaphores */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); ES_UT_SetupForOSCleanup(); UT_SetDeferredRetcode(UT_KEY(OS_CountSemDelete), 1, OS_ERROR); + Id = CFE_ES_TaskRecordGetID(UtTaskRecPtr); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanupTaskResources(TestObjId) == + CFE_ES_CleanupTaskResources(Id) == CFE_ES_COUNT_SEM_DELETE_ERR, "CFE_ES_CleanupTaskResources", "Counting semaphore failure"); @@ -1715,11 +1758,12 @@ void TestApps(void) * deleting queues */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); ES_UT_SetupForOSCleanup(); UT_SetDeferredRetcode(UT_KEY(OS_QueueDelete), 1, OS_ERROR); + Id = CFE_ES_TaskRecordGetID(UtTaskRecPtr); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanupTaskResources(TestObjId) == + CFE_ES_CleanupTaskResources(Id) == CFE_ES_QUEUE_DELETE_ERR, "CFE_ES_CleanupTaskResources", "Queue delete failure"); @@ -1728,14 +1772,15 @@ void TestApps(void) * deleting timers */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); + Id = CFE_ES_TaskRecordGetID(UtTaskRecPtr); ES_UT_SetupForOSCleanup(); /* Just set OS_TimerDelete to fail. There is no requirement * that the code call OS_TimerGetInfo first. */ UT_SetDeferredRetcode(UT_KEY(OS_TimerDelete), 1, OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanupTaskResources(TestObjId) == + CFE_ES_CleanupTaskResources(Id) == CFE_ES_TIMER_DELETE_ERR, "CFE_ES_CleanupTaskResources", "Timer delete failure"); @@ -1744,12 +1789,13 @@ void TestApps(void) * closing files */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); + Id = CFE_ES_TaskRecordGetID(UtTaskRecPtr); ES_UT_SetupForOSCleanup(); UT_SetDeferredRetcode(UT_KEY(OS_TimerGetInfo), 1, OS_ERROR); UT_SetForceFail(UT_KEY(OS_close), OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanupTaskResources(TestObjId) != CFE_SUCCESS, + CFE_ES_CleanupTaskResources(Id) != CFE_SUCCESS, "CFE_ES_CleanupTaskResources", "File close failure"); @@ -1757,20 +1803,22 @@ void TestApps(void) * to delete the task */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); + Id = CFE_ES_TaskRecordGetID(UtTaskRecPtr); UT_SetDeferredRetcode(UT_KEY(OS_TimerGetInfo), 1, OS_ERROR); UT_SetForceFail(UT_KEY(OS_TaskDelete), OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanupTaskResources(TestObjId) == CFE_ES_TASK_DELETE_ERR, + CFE_ES_CleanupTaskResources(Id) == CFE_ES_TASK_DELETE_ERR, "CFE_ES_CleanupTaskResources", "Task delete failure"); /* Test successfully cleaning up the OS resources for a task */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); + Id = CFE_ES_TaskRecordGetID(UtTaskRecPtr); UT_SetDeferredRetcode(UT_KEY(OS_TimerGetInfo), 1, OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanupTaskResources(TestObjId) == CFE_SUCCESS, + CFE_ES_CleanupTaskResources(Id) == CFE_SUCCESS, "CFE_ES_CleanupTaskResources", "Clean up task OS resources; successful"); @@ -1800,136 +1848,129 @@ void TestApps(void) * expires for a waiting application */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_CORE; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_WAITING; - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec = 0; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_WAITING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppTimerMsec = 0; CFE_ES_RunAppTableScan(0, &CFE_ES_TaskData.BackgroundAppScanState); UT_Report(__FILE__, __LINE__, UT_GetNumEventsSent() == 0 && - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec == 0, + UtAppRecPtr->ControlReq.AppTimerMsec == 0, "CFE_ES_RunAppTableScan", "Waiting; process control request"); - CFE_ES_Global.TaskTable[Id].RecordUsed = false; /* Test scanning and acting on the application table where the application * is already running */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec = 0; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppTimerMsec = 0; CFE_ES_RunAppTableScan(0, &CFE_ES_TaskData.BackgroundAppScanState); UT_Report(__FILE__, __LINE__, UT_GetNumEventsSent() == 0 && - CFE_ES_Global.AppTable[Id].ControlReq.AppTimerMsec == 0, + UtAppRecPtr->ControlReq.AppTimerMsec == 0, "CFE_ES_RunAppTableScan", "Running; process control request"); - CFE_ES_Global.TaskTable[Id].RecordUsed = false; /* Test deleting an application and cleaning up its resources where the * application ID matches the main task ID */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - OS_TaskCreate(&TestObjId2, "UT", NULL, NULL, 0, 0, 0); - Id2 = ES_UT_OSALID_TO_ARRAYIDX(TestObjId2); - OS_TaskCreate(&TestObjId3, "UT", NULL, NULL, 0, 0, 0); - Id3 = ES_UT_OSALID_TO_ARRAYIDX(TestObjId3); - CFE_ES_Global.TaskTable[Id2].TaskId = TestObjId3; - CFE_ES_Global.TaskTable[Id2].RecordUsed = true; - CFE_ES_Global.TaskTable[Id2].AppId = Id; - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id].StartParams.ModuleId, NULL, NULL); - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId3; - UT_Report(__FILE__, __LINE__, - CFE_ES_CleanUpApp(Id) == CFE_SUCCESS && - CFE_ES_Global.TaskTable[Id2].RecordUsed == true, + /* Setup an entry which will be deleted */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + /* Setup a second entry which will NOT be deleted */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + /* Associate a child task with the app to be deleted */ + ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, NULL); + UT_Report(__FILE__, __LINE__, + CFE_ES_CleanUpApp(UtAppRecPtr) == CFE_SUCCESS, "CFE_ES_CleanUpApp", - "Main task ID matches task ID"); - CFE_ES_Global.TaskTable[Id].RecordUsed = false; + "Main task ID matches task ID, nominal"); + UT_Report(__FILE__, __LINE__, + CFE_ES_TaskRecordIsUsed(UtTaskRecPtr), + "CFE_ES_CleanUpApp", + "Main task ID matches task ID, other task unaffected"); /* Test deleting an application and cleaning up its resources where the * application ID doesn't match the main task ID */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - OS_TaskCreate(&TestObjId2, "UT", NULL, NULL, 0, 0, 0); - Id2 = ES_UT_OSALID_TO_ARRAYIDX(TestObjId2); - OS_TaskCreate(&TestObjId3, "UT", NULL, NULL, 0, 0, 0); - Id3 = ES_UT_OSALID_TO_ARRAYIDX(TestObjId3); - OS_TaskCreate(&TestObjId4, "UT", NULL, NULL, 0, 0, 0); - Id4 = ES_UT_OSALID_TO_ARRAYIDX(TestObjId4); - CFE_ES_Global.TaskTable[Id2].TaskId = Id3; - CFE_ES_Global.TaskTable[Id2].RecordUsed = true; - CFE_ES_Global.TaskTable[Id2].AppId = Id4; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = Id2; + + /* Setup an entry which will be deleted */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + /* Setup a second entry which will NOT be deleted */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + /* Associate a child task with the app to be deleted */ + ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, NULL); + + /* switch the main task association (makes it wrong) */ + UtAppRecPtr->TaskInfo.MainTaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + UT_SetForceFail(UT_KEY(OS_TaskDelete), OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanUpApp(Id4) == CFE_ES_APP_CLEANUP_ERR && - CFE_ES_Global.TaskTable[Id2].RecordUsed == true, + CFE_ES_CleanUpApp(UtAppRecPtr) == CFE_ES_APP_CLEANUP_ERR, + "CFE_ES_CleanUpApp", + "Main task ID doesn't match task ID, CFE_ES_APP_CLEANUP_ERR"); + UT_Report(__FILE__, __LINE__, + !CFE_ES_TaskRecordIsUsed(UtTaskRecPtr), "CFE_ES_CleanUpApp", - "Main task ID doesn't match task ID"); + "Main task ID doesn't match task ID, second task unchanged"); /* Test deleting an application and cleaning up its resources where the * application ID doesn't match and the application is a core application */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - OS_TaskCreate(&TestObjId2, "UT", NULL, NULL, 0, 0, 0); - Id2 = ES_UT_OSALID_TO_ARRAYIDX(TestObjId2); - OS_TaskCreate(&TestObjId3, "UT", NULL, NULL, 0, 0, 0); - Id3 = ES_UT_OSALID_TO_ARRAYIDX(TestObjId3); - CFE_ES_Global.TaskTable[Id].TaskId = TestObjId; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id2; - CFE_ES_Global.RegisteredExternalApps = 1; - CFE_ES_Global.AppTable[Id3].TaskInfo.MainTaskId = TestObjId3; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_CORE; - UT_Report(__FILE__, __LINE__, - CFE_ES_CleanUpApp(Id3) == CFE_SUCCESS && - CFE_ES_Global.TaskTable[Id].RecordUsed == true && + /* Setup an entry which will be deleted */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + /* Setup a second entry which will NOT be deleted */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); + /* Associate a child task with the app to be deleted */ + ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, NULL); + + /* switch the main task association (makes it wrong) */ + UtAppRecPtr->TaskInfo.MainTaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + + UT_Report(__FILE__, __LINE__, + CFE_ES_CleanUpApp(UtAppRecPtr) == CFE_SUCCESS, + "CFE_ES_CleanUpApp", + "Application ID mismatch; core application"); + + UT_Report(__FILE__, __LINE__, + !CFE_ES_TaskRecordIsUsed(UtTaskRecPtr), + "CFE_ES_CleanUpApp", + "Application ID mismatch; core application"); + + UT_Report(__FILE__, __LINE__, CFE_ES_Global.RegisteredExternalApps == 1, "CFE_ES_CleanUpApp", "Application ID mismatch; core application"); - CFE_ES_Global.TaskTable[Id].RecordUsed = false; /* Test successfully deleting an application and cleaning up its resources * and the application is an external application */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - OS_TaskCreate(&TestObjId2, "UT", NULL, NULL, 0, 0, 0); - Id2 = ES_UT_OSALID_TO_ARRAYIDX(TestObjId2); - CFE_ES_Global.TaskTable[Id].TaskId = TestObjId; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id2; - CFE_ES_Global.RegisteredExternalApps = 1; - CFE_ES_Global.AppTable[Id2].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.AppTable[Id2].Type = CFE_ES_AppType_EXTERNAL; - OS_ModuleLoad(&CFE_ES_Global.AppTable[Id2].StartParams.ModuleId, "UT", + + /* Setup an entry which will be deleted */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, &UtTaskRecPtr); + + OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, "UT", "ut-module"); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanUpApp(Id2) == CFE_SUCCESS && - CFE_ES_Global.TaskTable[Id].RecordUsed == false && + CFE_ES_CleanUpApp(UtAppRecPtr) == CFE_SUCCESS && + !CFE_ES_TaskRecordIsUsed(UtTaskRecPtr) && CFE_ES_Global.RegisteredExternalApps == 0, "CFE_ES_CleanUpApp", "Successful application cleanup; external application"); - CFE_ES_Global.TaskTable[Id].RecordUsed = false; /* Test cleaning up the OS resources for a task with failure to * obtain information on mutex, binary, and counter semaphores, and * queues, timers, and file descriptors */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, &UtTaskRecPtr); + Id = CFE_ES_TaskRecordGetID(UtTaskRecPtr); UT_SetDeferredRetcode(UT_KEY(OS_MutSemGetInfo), 1, OS_ERROR); UT_SetDeferredRetcode(UT_KEY(OS_BinSemGetInfo), 1, OS_ERROR); UT_SetDeferredRetcode(UT_KEY(OS_CountSemGetInfo), 1, OS_ERROR); @@ -1937,7 +1978,7 @@ void TestApps(void) UT_SetDeferredRetcode(UT_KEY(OS_TimerGetInfo), 1, OS_ERROR); UT_SetDeferredRetcode(UT_KEY(OS_FDGetInfo), 1, OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_CleanupTaskResources(TestObjId) == CFE_SUCCESS, + CFE_ES_CleanupTaskResources(Id) == CFE_SUCCESS, "CFE_ES_CleanupTaskResources", "Get OS information failures"); } @@ -1988,10 +2029,9 @@ void TestERLog(void) void TestTask(void) { - uint32 Id; - uint32 TestObjId; uint32 ResetType; - uint32 UT_ContextBuffer; + uint32 UT_ContextData; + uint32 UT_ContextTask; union { CFE_SB_Msg_t Msg; @@ -2013,7 +2053,9 @@ void TestTask(void) CFE_ES_QueryAllTasks_t QueryAllTasksCmd; } CmdBuf; Pool_t UT_TestPool; - + CFE_ES_AppRecord_t *UtAppRecPtr; + CFE_ES_TaskRecord_t *UtTaskRecPtr; + CFE_ES_CDS_RegRec_t *UtCDSRegRecPtr; #ifdef UT_VERBOSE UT_Text("Begin Test Task\n"); #endif @@ -2028,41 +2070,53 @@ void TestTask(void) /* Test task main process loop with a command pipe error */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].RecordUsed = true; /* this is needed so CFE_ES_GetAppId works */ - CFE_ES_Global.TaskTable[1].AppId = 1; + /* this is needed so CFE_ES_GetAppId works */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, NULL, NULL, NULL); CFE_ES_TaskMain(); UT_Report(__FILE__, __LINE__, - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_COMMAND_PIPE]) && - UT_GetStubCount(UT_KEY(OS_printf)) == 2, + UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_COMMAND_PIPE]), + "CFE_ES_TaskMain", + "Command pipe error, UT_OSP_COMMAND_PIPE message"); + UT_Report(__FILE__, __LINE__, + UT_GetStubCount(UT_KEY(OS_printf)) == 2, "CFE_ES_TaskMain", - "Command pipe error"); + "Command pipe error, printf count"); /* Test task main process loop with an initialization failure */ ES_ResetUnitTest(); UT_SetForceFail(UT_KEY(OS_TaskRegister), OS_ERROR); CFE_ES_TaskMain(); UT_Report(__FILE__, __LINE__, - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_APP_INIT]) && - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_REGISTER_APP]) && - UT_GetStubCount(UT_KEY(OS_printf)) == 2, + UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_APP_INIT]), + "CFE_ES_TaskMain", + "Task initialization fail, UT_OSP_APP_INIT message"); + UT_Report(__FILE__, __LINE__, + UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_REGISTER_APP]), + "CFE_ES_TaskMain", + "Task initialization fail, UT_OSP_REGISTER_APP message"); + UT_Report(__FILE__, __LINE__, + UT_GetStubCount(UT_KEY(OS_printf)) == 2, "CFE_ES_TaskMain", - "Task initialization fail"); + "Task initialization fail, printf count"); /* Test task main process loop with bad checksum information */ ES_ResetUnitTest(); UT_SetDeferredRetcode(UT_KEY(CFE_PSP_GetCFETextSegmentInfo), 1, -1); - CFE_ES_Global.TaskTable[1].RecordUsed = true; /* this is needed so CFE_ES_GetAppId works */ - CFE_ES_Global.TaskTable[1].AppId = 1; + /* this is needed so CFE_ES_GetAppId works */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, NULL, NULL, NULL); + UT_Report(__FILE__, __LINE__, + CFE_ES_TaskInit() == CFE_SUCCESS, + "CFE_ES_TaskInit", + "Checksum fail, task init result"); UT_Report(__FILE__, __LINE__, - CFE_ES_TaskInit() == CFE_SUCCESS && CFE_ES_TaskData.HkPacket.Payload.CFECoreChecksum == 0xFFFF, "CFE_ES_TaskInit", - "Checksum fail"); + "Checksum fail, checksum value"); /* Test successful task main process loop - Power On Reset Path */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].RecordUsed = true; /* this is needed so CFE_ES_GetAppId works */ - CFE_ES_Global.TaskTable[1].AppId = 1; + /* this is needed so CFE_ES_GetAppId works */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, NULL, NULL, NULL); CFE_ES_ResetDataPtr->ResetVars.ResetType = 2; UT_Report(__FILE__, __LINE__, CFE_ES_TaskInit() == CFE_SUCCESS && @@ -2072,8 +2126,8 @@ void TestTask(void) /* Test successful task main process loop - Processor Reset Path */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].RecordUsed = true; /* this is needed so CFE_ES_GetAppId works */ - CFE_ES_Global.TaskTable[1].AppId = 1; + /* this is needed so CFE_ES_GetAppId works */ + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, NULL, NULL, NULL); CFE_ES_ResetDataPtr->ResetVars.ResetType = 1; UT_Report(__FILE__, __LINE__, CFE_ES_TaskInit() == CFE_SUCCESS && @@ -2356,14 +2410,7 @@ void TestTask(void) /* Test successful app stop */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - memset(&CmdBuf, 0, sizeof(CmdBuf)); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.Name, "CFE_ES", - sizeof(CFE_ES_Global.AppTable[Id].StartParams.Name)); - CFE_ES_Global.AppTable[Id].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); strncpy((char *) CmdBuf.StopAppCmd.Payload.Application, "CFE_ES", sizeof(CmdBuf.StopAppCmd.Payload.Application)); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_StopApp_t), @@ -2375,10 +2422,7 @@ void TestTask(void) /* Test app stop failure */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_CORE; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_WAITING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_WAITING, "CFE_ES", NULL, NULL); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_StopApp_t), UT_TPID_CFE_ES_CMD_STOP_APP_CC); UT_Report(__FILE__, __LINE__, @@ -2401,15 +2445,9 @@ void TestTask(void) /* Test successful app restart */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); + 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)); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - strncpy((char *) CFE_ES_Global.AppTable[0].StartParams.Name, - "CFE_ES", OS_MAX_API_NAME); - CFE_ES_Global.AppTable[Id].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_RestartApp_t), UT_TPID_CFE_ES_CMD_RESTART_APP_CC); UT_Report(__FILE__, __LINE__, @@ -2432,15 +2470,9 @@ void TestTask(void) /* Test failed app restart */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_WAITING, "CFE_ES", NULL, NULL); strncpy((char *) CmdBuf.RestartAppCmd.Payload.Application, "CFE_ES", sizeof(CmdBuf.RestartAppCmd.Payload.Application)); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_CORE; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_WAITING; - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.Name, - "CFE_ES", OS_MAX_API_NAME); - CFE_ES_Global.AppTable[Id].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_RestartApp_t), UT_TPID_CFE_ES_CMD_RESTART_APP_CC); UT_Report(__FILE__, __LINE__, @@ -2451,14 +2483,11 @@ void TestTask(void) /* Test successful app reload */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); + 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)); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_ReloadApp_t), UT_TPID_CFE_ES_CMD_RELOAD_APP_CC); UT_Report(__FILE__, __LINE__, @@ -2469,7 +2498,6 @@ void TestTask(void) /* Test app reload with a bad app name */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_UNDEFINED; strncpy((char *) CmdBuf.ReloadAppCmd.Payload.Application, "BAD_APP_NAME", sizeof(CmdBuf.ReloadAppCmd.Payload.Application)); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_ReloadApp_t), @@ -2478,15 +2506,11 @@ void TestTask(void) UT_EventIsInHistory(CFE_ES_RELOAD_APP_ERR2_EID), "CFE_ES_ReloadAppCmd", "Reload application bad name"); - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_RUNNING; /* Test failed app reload */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_CORE; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_WAITING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, 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(CFE_ES_ReloadApp_t), @@ -2499,10 +2523,7 @@ void TestTask(void) /* Test successful telemetry packet request for single app data */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_CORE; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_WAITING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_WAITING, "CFE_ES", NULL, NULL); strncpy((char *) CmdBuf.QueryOneCmd.Payload.Application, "CFE_ES", sizeof(CmdBuf.QueryOneCmd.Payload.Application)); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_QueryOne_t), @@ -2517,12 +2538,7 @@ void TestTask(void) */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - strncpy((char *) CFE_ES_Global.AppTable[Id].StartParams.Name, "CFE_ES", - OS_MAX_API_NAME); - CFE_ES_Global.AppTable[Id].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); strncpy((char *) CmdBuf.QueryOneCmd.Payload.Application, "CFE_ES", sizeof(CmdBuf.QueryOneCmd.Payload.Application)); UT_SetDeferredRetcode(UT_KEY(CFE_SB_SendMsg), 1, -1); @@ -2536,9 +2552,7 @@ void TestTask(void) /* Test telemetry packet request for single app data with a bad app name */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); strncpy((char *) CmdBuf.QueryOneCmd.Payload.Application, "BAD_APP_NAME", sizeof(CmdBuf.QueryOneCmd.Payload.Application)); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_QueryOne_t), @@ -2551,9 +2565,7 @@ void TestTask(void) /* Test successful write of all app data to file */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); strncpy((char *) CmdBuf.QueryAllCmd.Payload.FileName, "AllFilename", sizeof(CmdBuf.QueryAllCmd.Payload.FileName)); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_QueryAll_t), @@ -2587,9 +2599,7 @@ void TestTask(void) /* Test write of all app data to file with a file write failure */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); UT_SetForceFail(UT_KEY(OS_write), OS_ERROR); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_QueryAll_t), UT_TPID_CFE_ES_CMD_QUERY_ALL_CC); @@ -2601,9 +2611,7 @@ void TestTask(void) /* Test write of all app data to file with a file create failure */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); UT_SetForceFail(UT_KEY(OS_creat), OS_ERROR); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_QueryAll_t), UT_TPID_CFE_ES_CMD_QUERY_ALL_CC); @@ -2615,10 +2623,7 @@ void TestTask(void) /* Test successful write of all task data to a file */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_QueryAllTasks_t), UT_TPID_CFE_ES_CMD_QUERY_ALL_TASKS_CC); UT_Report(__FILE__, __LINE__, @@ -2641,12 +2646,9 @@ void TestTask(void) /* Test write of all task data to a file with a task write failure */ ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; UT_SetForceFail(UT_KEY(OS_write), OS_ERROR); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_QueryAllTasks_t), UT_TPID_CFE_ES_CMD_QUERY_ALL_TASKS_CC); UT_Report(__FILE__, __LINE__, @@ -2813,8 +2815,8 @@ void TestTask(void) /* nominal condition - still returns false, but generates event */ ES_ResetUnitTest(); - UT_ContextBuffer = 42; - UT_SetDataBuffer(UT_KEY(CFE_PSP_Exception_CopyContext),&UT_ContextBuffer, sizeof(UT_ContextBuffer), false); + UT_ContextData = 42; + UT_SetDataBuffer(UT_KEY(CFE_PSP_Exception_CopyContext),&UT_ContextData, sizeof(UT_ContextData), false); CFE_ES_TaskData.BackgroundERLogDumpState.IsPending = true; CFE_ES_RunERLogDump(0, &CFE_ES_TaskData.BackgroundERLogDumpState); UT_Report(__FILE__, __LINE__, @@ -2883,36 +2885,37 @@ void TestTask(void) "Scan for exceptions; poweron restart"); /* nominal for app restart - associate exception with a task ID */ - OS_TaskCreate(&UT_ContextBuffer, "UT", NULL, NULL, 0, 0, 0); - UT_SetDataBuffer(UT_KEY(CFE_PSP_Exception_GetSummary), &UT_ContextBuffer, sizeof(UT_ContextBuffer), false); - CFE_ES_Global.TaskTable[1].RecordUsed = true; - CFE_ES_Global.TaskTable[1].AppId = 0; - CFE_ES_Global.TaskTable[1].TaskId = UT_ContextBuffer; - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[0].ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[0].ControlReq.AppTimerMsec = 0; - CFE_ES_Global.AppTable[0].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[0].StartParams.ExceptionAction = CFE_ES_ExceptionAction_RESTART_APP; + ES_ResetUnitTest(); + UT_SetForceFail(UT_KEY(CFE_PSP_Exception_GetCount), 1); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, &UtTaskRecPtr); + UT_ContextTask = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + UT_SetDataBuffer(UT_KEY(CFE_PSP_Exception_GetSummary), &UT_ContextTask, sizeof(UT_ContextTask), false); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; + UtAppRecPtr->StartParams.ExceptionAction = CFE_ES_ExceptionAction_RESTART_APP; CFE_ES_RunExceptionScan(0, NULL); /* should have changed AppControlRequest from RUN to SYS_RESTART, * and the call to CFE_PSP_Restart should NOT increment */ UT_Report(__FILE__, __LINE__, - CFE_ES_Global.AppTable[0].ControlReq.AppControlRequest == CFE_ES_RunStatus_SYS_RESTART, + UtAppRecPtr->ControlReq.AppControlRequest == CFE_ES_RunStatus_SYS_RESTART, "CFE_ES_RunExceptionScan", "Scan for exceptions; app restart request pending"); UT_Report(__FILE__, __LINE__, - UT_GetStubCount(UT_KEY(CFE_PSP_Restart)) == 2, + UT_GetStubCount(UT_KEY(CFE_PSP_Restart)) == 0, "CFE_ES_RunExceptionScan", "Scan for exceptions; no psp restart"); /* repeat, but for a CORE app, which cannot be restarted */ - UT_SetDataBuffer(UT_KEY(CFE_PSP_Exception_GetSummary), &UT_ContextBuffer, sizeof(UT_ContextBuffer), false); - CFE_ES_Global.AppTable[0].ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[0].Type = CFE_ES_AppType_CORE; + ES_ResetUnitTest(); + UT_SetForceFail(UT_KEY(CFE_PSP_Exception_GetCount), 1); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, &UtTaskRecPtr); + UT_ContextTask = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + UT_SetDataBuffer(UT_KEY(CFE_PSP_Exception_GetSummary), &UT_ContextTask, sizeof(UT_ContextTask), false); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; + UtAppRecPtr->StartParams.ExceptionAction = CFE_ES_ExceptionAction_RESTART_APP; CFE_ES_RunExceptionScan(0, NULL); UT_Report(__FILE__, __LINE__, - UT_GetStubCount(UT_KEY(CFE_PSP_Restart)) == 3, + UT_GetStubCount(UT_KEY(CFE_PSP_Restart)) == 1, "CFE_ES_RunExceptionScan", "Scan for exceptions; core app, psp restart"); @@ -2920,7 +2923,7 @@ void TestTask(void) UT_SetForceFail(UT_KEY(CFE_PSP_Exception_GetSummary), CFE_PSP_NO_EXCEPTION_DATA); CFE_ES_RunExceptionScan(0, NULL); UT_Report(__FILE__, __LINE__, - UT_GetStubCount(UT_KEY(CFE_PSP_Restart)) == 4, + UT_GetStubCount(UT_KEY(CFE_PSP_Restart)) == 2, "CFE_ES_RunExceptionScan", "Scan for exceptions; fail to get context"); @@ -2958,15 +2961,11 @@ void TestTask(void) /* Test failed deletion of specified CDS */ ES_ResetUnitTest(); + ES_UT_SetupSingleCDSRegistry("CFE_ES.CDS_NAME", false, NULL); memset(&CmdBuf, 0, sizeof(CmdBuf)); strncpy(CmdBuf.DeleteCDSCmd.Payload.CdsName, "CFE_ES.CDS_NAME", sizeof(CmdBuf.DeleteCDSCmd.Payload.CdsName)); - strncpy(CFE_ES_Global.CDSVars.Registry[0].Name, - "CFE_ES.CDS_NAME", - sizeof(CFE_ES_Global.CDSVars.Registry[0].Name)); - CFE_ES_Global.CDSVars.Registry[0].Name[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.CDSVars.Registry[0].Taken = true; UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_DeleteCDS_t), UT_TPID_CFE_ES_CMD_DELETE_CDS_CC); UT_Report(__FILE__, __LINE__, @@ -2977,20 +2976,18 @@ void TestTask(void) /* Test failed deletion of specified critical table CDS */ /* NOTE - reuse command from previous test */ ES_ResetUnitTest(); - CFE_ES_Global.CDSVars.Registry[0].Table = true; + ES_UT_SetupSingleCDSRegistry("CFE_ES.CDS_NAME", true, NULL); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_DeleteCDS_t), UT_TPID_CFE_ES_CMD_DELETE_CDS_CC); UT_Report(__FILE__, __LINE__, UT_EventIsInHistory(CFE_ES_CDS_DELETE_TBL_ERR_EID), "CFE_ES_DeleteCDSCmd", "Delete from CDS; wrong type"); - CFE_ES_Global.CDSVars.Registry[0].Table = false; /* Test successful deletion of a specified CDS */ ES_ResetUnitTest(); UT_SetCDSSize(0); /* defeats the "ReadFromCDS" and causes it to use the value here */ - CFE_ES_Global.CDSVars.Registry[0].MemHandle = - sizeof(CFE_ES_Global.CDSVars.ValidityField); + ES_UT_SetupSingleCDSRegistry("CFE_ES.CDS_NAME", false, NULL); /* Set up the block to read what we need to from the CDS */ CFE_ES_CDSBlockDesc.CheckBits = CFE_ES_CDS_CHECK_PATTERN; @@ -3006,18 +3003,8 @@ void TestTask(void) /* Test deletion of a specified CDS with the owning app being active */ ES_ResetUnitTest(); - strncpy(CFE_ES_Global.CDSVars.Registry[0].Name, - "CFE_ES.CDS_NAME", - sizeof(CFE_ES_Global.CDSVars.Registry[0].Name)); - CFE_ES_Global.CDSVars.Registry[0].Name[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.CDSVars.Registry[0].MemHandle = - sizeof(CFE_ES_Global.CDSVars.ValidityField); - strncpy((char *) CFE_ES_Global.AppTable[0].StartParams.Name, "CFE_ES", - OS_MAX_API_NAME); - CFE_ES_Global.AppTable[0].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.CDSVars.Registry[0].Table = false; - CFE_ES_Global.CDSVars.Registry[0].Taken = true; - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleCDSRegistry("CFE_ES.CDS_NAME", false, NULL); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_DeleteCDS_t), UT_TPID_CFE_ES_CMD_DELETE_CDS_CC); UT_Report(__FILE__, __LINE__, @@ -3027,13 +3014,9 @@ void TestTask(void) /* Test deletion of a specified CDS with the name not found */ ES_ResetUnitTest(); - CFE_ES_Global.CDSVars.Registry[0].MemHandle = - sizeof(CFE_ES_Global.CDSVars.ValidityField); - strncpy((char *) CFE_ES_Global.AppTable[0].StartParams.Name, "CFE_BAD", - OS_MAX_API_NAME); - CFE_ES_Global.AppTable[0].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_UNDEFINED; - CFE_ES_Global.CDSVars.Registry[0].Taken = false; + ES_UT_SetupSingleCDSRegistry("CFE_ES.CDS_NAME", false, &UtCDSRegRecPtr); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_BAD", NULL, NULL); + UtCDSRegRecPtr->Taken = false; UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_DeleteCDS_t), UT_TPID_CFE_ES_CMD_DELETE_CDS_CC); UT_Report(__FILE__, __LINE__, @@ -3044,11 +3027,6 @@ void TestTask(void) /* Test successful dump of CDS to file using the default dump file name */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - strncpy((char *) CFE_ES_Global.AppTable[0].StartParams.Name, "CFE_ES", - OS_MAX_API_NAME); - CFE_ES_Global.AppTable[0].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.CDSVars.Registry[0].Taken = true; UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_DumpCDSRegistry_t), UT_TPID_CFE_ES_CMD_DUMP_CDS_REGISTRY_CC); UT_Report(__FILE__, __LINE__, @@ -3082,6 +3060,7 @@ void TestTask(void) ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); UT_SetForceFail(UT_KEY(OS_write), OS_ERROR); + ES_UT_SetupSingleCDSRegistry("CFE_ES.CDS_NAME", false, NULL); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_DumpCDSRegistry_t), UT_TPID_CFE_ES_CMD_DUMP_CDS_REGISTRY_CC); UT_Report(__FILE__, __LINE__, @@ -3403,13 +3382,10 @@ void TestTask(void) /* Test successful dump of CDS to file using a specified dump file name */ ES_ResetUnitTest(); memset(&CmdBuf, 0, sizeof(CmdBuf)); - strncpy((char *) CFE_ES_Global.AppTable[0].StartParams.Name, "CFE_ES", - OS_MAX_API_NAME); - CFE_ES_Global.AppTable[0].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); + ES_UT_SetupSingleCDSRegistry("CFE_ES.CDS_NAME", false, NULL); strncpy(CmdBuf.DumpCDSRegCmd.Payload.DumpFilename, "DumpFile", sizeof(CmdBuf.DumpCDSRegCmd.Payload.DumpFilename)); - CFE_ES_Global.CDSVars.Registry[0].Taken = true; UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CFE_ES_DumpCDSRegistry_t), UT_TPID_CFE_ES_CMD_DUMP_CDS_REGISTRY_CC); UT_Report(__FILE__, __LINE__, @@ -3420,8 +3396,6 @@ void TestTask(void) void TestPerf(void) { - uint32 Id; - uint32 TestObjId; union { CFE_SB_Msg_t Msg; @@ -3437,11 +3411,8 @@ void TestPerf(void) /* Test successful performance mask and value initialization */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); Perf->MetaData.State = CFE_ES_PERF_MAX_STATES; - CFE_ES_Global.TaskTable[Id].AppId = 0; CFE_ES_SetupPerfVariables(CFE_PSP_RST_TYPE_PROCESSOR); UT_Report(__FILE__, __LINE__, Perf->MetaData.State == CFE_ES_PERF_IDLE, @@ -3535,9 +3506,6 @@ void TestPerf(void) memset(&CFE_ES_TaskData.BackgroundPerfDumpState, 0, sizeof(CFE_ES_TaskData.BackgroundPerfDumpState)); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; CmdBuf.PerfStartCmd.Payload.TriggerMode = CFE_ES_PERF_TRIGGER_START; UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.PerfStartCmd), UT_TPID_CFE_ES_CMD_START_PERF_DATA_CC); @@ -3551,9 +3519,6 @@ void TestPerf(void) memset(&CFE_ES_TaskData.BackgroundPerfDumpState, 0, sizeof(CFE_ES_TaskData.BackgroundPerfDumpState)); memset(&CmdBuf, 0, sizeof(CmdBuf)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.PerfStopCmd), UT_TPID_CFE_ES_CMD_STOP_PERF_DATA_CC); UT_Report(__FILE__, __LINE__, @@ -3568,9 +3533,6 @@ void TestPerf(void) /* clearing the BackgroundPerfDumpState will fully reset to initial state */ memset(&CFE_ES_TaskData.BackgroundPerfDumpState, 0, sizeof(CFE_ES_TaskData.BackgroundPerfDumpState)); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; strncpy(CmdBuf.PerfStopCmd.Payload.DataFileName, "filename", sizeof(CmdBuf.PerfStopCmd.Payload.DataFileName)); UT_CallTaskPipe(CFE_ES_TaskPipe, &CmdBuf.Msg, sizeof(CmdBuf.PerfStopCmd), @@ -3930,26 +3892,20 @@ void TestPerf(void) void TestAPI(void) { - uint32 Id; uint32 TestObjId; char AppName[32]; uint32 StackBuf[8]; - char CounterName[11]; - char CDSName[CFE_MISSION_ES_CDS_MAX_NAME_LENGTH + 2]; - int i; int32 Return; uint8 Data[12]; uint32 ResetType; uint32 *ResetTypePtr; uint32 AppId; uint32 TaskId; - uint32 TempSize; uint32 RunStatus; - uint32 CounterId; - uint32 CounterCount; - CFE_ES_CDSHandle_t CDSHandle; CFE_ES_TaskInfo_t TaskInfo; CFE_ES_AppInfo_t AppInfo; + CFE_ES_AppRecord_t *UtAppRecPtr; + CFE_ES_TaskRecord_t *UtTaskRecPtr; #ifdef UT_VERBOSE UT_Text("Begin Test API\n"); @@ -4002,52 +3958,42 @@ void TestAPI(void) /* Test restarting an app that doesn't exist */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_STOPPED; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_STOPPED, NULL, &UtAppRecPtr, NULL); + AppId = ES_UT_MakeAppIdForIndex(ES_UT_NumApps); /* Should be within range, but not used */ UT_Report(__FILE__, __LINE__, - CFE_ES_RestartApp(Id) == CFE_ES_ERR_APPID, + CFE_ES_RestartApp(AppId) == CFE_ES_ERR_APPID, "CFE_ES_RestartApp", "Bad application ID"); /* Test restarting an app with an ID out of range (high) */ ES_ResetUnitTest(); + AppId = ES_UT_MakeAppIdForIndex(99999); UT_Report(__FILE__, __LINE__, - CFE_ES_RestartApp(CFE_PLATFORM_ES_MAX_APPLICATIONS) == CFE_ES_ERR_APPID, + CFE_ES_RestartApp(AppId) == CFE_ES_ERR_APPID, "CFE_ES_RestartApp", "Application ID too large"); /* Test reloading an app that doesn't exist */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_STOPPED; + 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(Id, "filename") == CFE_ES_ERR_APPID, + CFE_ES_ReloadApp(AppId, "filename") == CFE_ES_ERR_APPID, "CFE_ES_ReloadApp", "Bad application ID"); /* Test deleting an app that doesn't exist */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_STOPPED; + 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_DeleteApp(Id) == CFE_ES_ERR_APPID, + CFE_ES_DeleteApp(AppId) == CFE_ES_ERR_APPID, "CFE_ES_DeleteApp", "Bad application ID"); /* Test exiting an app with an init error */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_STOPPED; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_CORE; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_STOPPED, NULL, &UtAppRecPtr, NULL); CFE_ES_ExitApp(CFE_ES_RunStatus_CORE_APP_INIT_ERROR); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_CORE_INIT]) && @@ -4058,12 +4004,7 @@ void TestAPI(void) /* Test exiting an app with a runtime error */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_STOPPED; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_CORE; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_STOPPED, NULL, &UtAppRecPtr, NULL); CFE_ES_ExitApp(CFE_ES_RunStatus_CORE_APP_RUNTIME_ERROR); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_CORE_RUNTIME]) && @@ -4076,23 +4017,17 @@ void TestAPI(void) * an extra message to be logged in syslog about this. This * should also be stored in the AppControlRequest as APP_ERROR. */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_STOPPED; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_CORE; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_STOPPED, "UT", &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; CFE_ES_ExitApp(1000); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_CORE_APP_EXIT]) && UT_GetStubCount(UT_KEY(OS_printf)) == 2, "CFE_ES_ExitApp", "Application exit error"); - UtAssert_True(CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest == CFE_ES_RunStatus_APP_ERROR, + UtAssert_True(UtAppRecPtr->ControlReq.AppControlRequest == CFE_ES_RunStatus_APP_ERROR, "CFE_ES_ExitApp - AppControlRequest (%u) == CFE_ES_RunStatus_APP_ERROR (%u)", - (unsigned int)CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest, + (unsigned int)UtAppRecPtr->ControlReq.AppControlRequest, (unsigned int)CFE_ES_RunStatus_APP_ERROR); #if 0 @@ -4101,22 +4036,18 @@ void TestAPI(void) */ OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; + CFE_ES_TaskRecordSetUsed(TaskRecPtr); + TaskRecPtr->AppId = Id; + AppRecPtr->Type = CFE_ES_AppType_EXTERNAL; + AppRecPtr->AppState = CFE_ES_AppState_RUNNING; CFE_ES_ExitApp(CFE_ES_RunStatus_CORE_APP_RUNTIME_ERROR); #endif /* Test successful run loop app run request */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); RunStatus = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; UT_Report(__FILE__, __LINE__, CFE_ES_RunLoop(&RunStatus) == true, @@ -4125,13 +4056,9 @@ void TestAPI(void) /* Test successful run loop app stop request */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); RunStatus = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_EXIT; UT_Report(__FILE__, __LINE__, CFE_ES_RunLoop(&RunStatus) == false, @@ -4140,13 +4067,9 @@ void TestAPI(void) /* Test successful run loop app exit request */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); RunStatus = CFE_ES_RunStatus_APP_EXIT; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_EXIT; UT_Report(__FILE__, __LINE__, CFE_ES_RunLoop(&RunStatus) == false, @@ -4155,14 +4078,11 @@ void TestAPI(void) /* Test run loop with bad app ID */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.TaskTable[Id].RecordUsed = false; - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, &UtTaskRecPtr); RunStatus = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; + CFE_ES_TaskRecordSetFree(UtTaskRecPtr); /* make it so task ID is bad */ UT_Report(__FILE__, __LINE__, CFE_ES_RunLoop(&RunStatus) == false, "CFE_ES_RunLoop", @@ -4170,13 +4090,9 @@ void TestAPI(void) /* Test run loop with an invalid run status */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); RunStatus = 1000; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_EXIT; UT_Report(__FILE__, __LINE__, CFE_ES_RunLoop(&RunStatus) == false, @@ -4185,12 +4101,8 @@ void TestAPI(void) /* Test run loop with a NULL run status */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; UT_Report(__FILE__, __LINE__, CFE_ES_RunLoop(NULL), @@ -4199,18 +4111,13 @@ void TestAPI(void) /* Test run loop with startup sync code */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_LATE_INIT, NULL, &UtAppRecPtr, NULL); RunStatus = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; - CFE_ES_Global.AppTable[Id].AppState = - CFE_ES_AppState_EARLY_INIT; UT_Report(__FILE__, __LINE__, CFE_ES_RunLoop(&RunStatus) == true && - CFE_ES_Global.AppTable[Id].AppState == + UtAppRecPtr->AppState == CFE_ES_AppState_RUNNING, "CFE_ES_RunLoop", "Status change from initializing to run"); @@ -4224,79 +4131,96 @@ void TestAPI(void) /* Test getting the cFE application ID by its name */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].RecordUsed = true; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); UT_Report(__FILE__, __LINE__, CFE_ES_GetAppID(&AppId) == CFE_SUCCESS, "CFE_ES_GetAppID", "Get application ID by name successful"); /* Test getting the app name with a bad app ID */ - CFE_ES_Global.AppTable[4].AppState = CFE_ES_AppState_UNDEFINED; ES_ResetUnitTest(); + AppId = ES_UT_MakeAppIdForIndex(99999); UT_Report(__FILE__, __LINE__, - CFE_ES_GetAppName(AppName, 4, 32) == CFE_ES_ERR_APPID, + CFE_ES_GetAppName(AppName, AppId, 32) == CFE_ES_ERR_APPID, "CFE_ES_GetAppName", "Get application name by ID; bad application ID"); /* Test getting the app name with that app ID out of range */ ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); + AppId = ES_UT_MakeAppIdForIndex(99999); UT_Report(__FILE__, __LINE__, CFE_ES_GetAppName(AppName, - CFE_PLATFORM_ES_MAX_APPLICATIONS + 2, + AppId, 32) == CFE_ES_ERR_APPID, "CFE_ES_GetAppName", "Get application name by ID; ID out of range"); /* Test successfully getting the app name using the app ID */ ES_ResetUnitTest(); - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", &UtAppRecPtr, NULL); + AppId = CFE_ES_AppRecordGetID(UtAppRecPtr); UT_Report(__FILE__, __LINE__, - CFE_ES_GetAppName(AppName, 0, 32) == CFE_SUCCESS, + CFE_ES_GetAppName(AppName, AppId, 32) == CFE_SUCCESS, "CFE_ES_GetAppName", "Get application name by ID successful"); + /* Test getting task information using the task ID - NULL buffer */ + ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, &UtTaskRecPtr); + TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + UT_Report(__FILE__, __LINE__, + CFE_ES_GetTaskInfo(NULL, TaskId) == CFE_ES_ERR_BUFFER, + "CFE_ES_GetTaskInfo", + "Get task info by ID; NULL buffer"); + + /* Test getting task information using the task ID - bad task ID */ + UT_SetForceFail(UT_KEY(OS_ConvertToArrayIndex), OS_ERROR); + UT_Report(__FILE__, __LINE__, + CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_TASKID, + "CFE_ES_GetTaskInfo", + "Get task info by ID; bad task ID"); + /* Test getting task information using the task ID */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, &UtTaskRecPtr); + TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + UtAppRecPtr->AppState = CFE_ES_AppState_RUNNING; UT_Report(__FILE__, __LINE__, - CFE_ES_GetTaskInfo(&TaskInfo, TestObjId) == CFE_SUCCESS, + CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_SUCCESS, "CFE_ES_GetTaskInfo", "Get task info by ID successful"); /* Test getting task information using the task ID with parent inactive */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", &UtAppRecPtr, &UtTaskRecPtr); + TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + CFE_ES_AppRecordSetFree(UtAppRecPtr); UT_Report(__FILE__, __LINE__, - CFE_ES_GetTaskInfo(&TaskInfo, Id) == CFE_ES_ERR_TASKID, + CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_APPID, "CFE_ES_GetTaskInfo", "Get task info by ID; parent application not active"); /* Test getting task information using the task ID with task inactive */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", NULL, &UtTaskRecPtr); + TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + CFE_ES_TaskRecordSetFree(UtTaskRecPtr); UT_Report(__FILE__, __LINE__, - CFE_ES_GetTaskInfo(&TaskInfo, Id) == CFE_ES_ERR_TASKID, + CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_TASKID, "CFE_ES_GetTaskInfo", "Get task info by ID; task not active"); /* Test getting task information using the task ID with invalid task ID */ ES_ResetUnitTest(); + TaskId = ES_UT_MakeTaskIdForIndex(99999); UT_Report(__FILE__, __LINE__, - CFE_ES_GetTaskInfo(&TaskInfo, 1000) == CFE_ES_ERR_TASKID, + CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_TASKID, "CFE_ES_GetTaskInfo", "Get task info by ID; invalid task ID"); /* Test creating a child task with a bad app ID */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].RecordUsed = false; Return = CFE_ES_CreateChildTask(&TaskId, "TaskName", TestAPI, @@ -4311,8 +4235,8 @@ void TestAPI(void) /* Test creating a child task with an OS task create failure */ ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, NULL); UT_SetForceFail(UT_KEY(OS_TaskCreate), OS_ERROR); - CFE_ES_Global.TaskTable[1].RecordUsed = true; Return = CFE_ES_CreateChildTask(&TaskId, "TaskName", TestAPI, @@ -4383,12 +4307,10 @@ void TestAPI(void) /* Test creating a child task within a child task */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = 3; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, &UtTaskRecPtr); + TestObjId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + UT_SetForceFail(UT_KEY(OS_TaskGetId), (unsigned long)TestObjId); /* Set context to that of child */ Return = CFE_ES_CreateChildTask(&TaskId, "TaskName", TestAPI, @@ -4403,12 +4325,7 @@ void TestAPI(void) /* Test successfully creating a child task */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); Return = CFE_ES_CreateChildTask(&TaskId, "TaskName", TestAPI, @@ -4420,45 +4337,38 @@ void TestAPI(void) Return == CFE_SUCCESS, "CFE_ES_CreateChildTask", "Create child task successful"); - /* Test deleting a child task with an invalid task ID */ - ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - UT_Report(__FILE__, __LINE__, - CFE_ES_DeleteChildTask(Id) == CFE_ES_ERR_TASKID, - "CFE_ES_DeleteChildTask", - "Task ID not in use"); - /* Test deleting a child task using a main task's ID */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", NULL, &UtTaskRecPtr); + TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); UT_Report(__FILE__, __LINE__, - CFE_ES_DeleteChildTask(Id /*CFE_ES_Global.TaskTable[Id].TaskId*/) == + CFE_ES_DeleteChildTask(TaskId) == CFE_ES_ERR_CHILD_TASK_DELETE_MAIN_TASK, "CFE_ES_DeleteChildTask", "Task ID belongs to a main task"); + /* Test deleting a child task with an invalid task ID */ + UT_SetForceFail(UT_KEY(OS_ConvertToArrayIndex), OS_ERROR); + UT_Report(__FILE__, __LINE__, + CFE_ES_DeleteChildTask(TaskId) == CFE_ES_ERR_TASKID, + "CFE_ES_DeleteChildTask", + "Task ID invalid"); + /* Test successfully deleting a child task */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].RecordUsed = true; - CFE_ES_Global.TaskTable[1].AppId = 0; - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[0].TaskInfo.MainTaskId = 15; - OS_TaskCreate(&CFE_ES_Global.TaskTable[1].TaskId, NULL, NULL, NULL, - 0, 0, 0); - Return = CFE_ES_GetAppInfo(&AppInfo,CFE_ES_Global.TaskTable[1].AppId); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", &UtAppRecPtr, NULL); + ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, &UtTaskRecPtr); + AppId = CFE_ES_AppRecordGetID(UtAppRecPtr); /* the app ID */ + TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); /* the child task ID */ + Return = CFE_ES_GetAppInfo(&AppInfo, AppId); UtAssert_True(Return == CFE_SUCCESS, "CFE_ES_GetAppInfo() return=%x", (unsigned int)Return); UtAssert_True(AppInfo.NumOfChildTasks == 1, "AppInfo.NumOfChildTaskss == %u", (unsigned int)AppInfo.NumOfChildTasks); - Return = CFE_ES_DeleteChildTask(CFE_ES_Global.TaskTable[1].TaskId); + Return = CFE_ES_DeleteChildTask(TaskId); UtAssert_True(Return == CFE_SUCCESS, "DeleteChildResult() return=%x", (unsigned int)Return); - Return = CFE_ES_GetAppInfo(&AppInfo,CFE_ES_Global.TaskTable[1].AppId); + Return = CFE_ES_GetAppInfo(&AppInfo,AppId); UtAssert_True(Return == CFE_SUCCESS, "CFE_ES_GetAppInfo() return=%x", (unsigned int)Return); UtAssert_True(AppInfo.NumOfChildTasks == 0, @@ -4466,31 +4376,30 @@ void TestAPI(void) /* Test deleting a child task with an OS task delete failure */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].RecordUsed = true; - OS_TaskCreate(&CFE_ES_Global.TaskTable[1].TaskId, NULL, NULL, NULL, - 0, 0, 0); - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[0].TaskInfo.MainTaskId = 15; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, &UtTaskRecPtr); + AppId = CFE_ES_AppRecordGetID(UtAppRecPtr); /* the app ID */ + TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); /* the child task ID */ UT_SetForceFail(UT_KEY(OS_TaskDelete), OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_DeleteChildTask(CFE_ES_Global.TaskTable[1].TaskId) <= 0, + CFE_ES_DeleteChildTask(TaskId) <= 0, "CFE_ES_DeleteChildTask", "OS task delete failure"); /* Test deleting a child task with the task ID out of range */ ES_ResetUnitTest(); + TaskId = ES_UT_MakeTaskIdForIndex(99999); UT_Report(__FILE__, __LINE__, - CFE_ES_DeleteChildTask(OS_MAX_TASKS + 1) == CFE_ES_ERR_TASKID, + CFE_ES_DeleteChildTask(TaskId) == CFE_ES_ERR_TASKID, "CFE_ES_DeleteChildTask", "Task ID too large"); /* Test successfully exiting a child task */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[0].RecordUsed = false; - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_UNDEFINED; - CFE_ES_Global.TaskTable[1].RecordUsed = true; - CFE_ES_Global.AppTable[1].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[1].TaskInfo.MainTaskId = 3; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, &UtTaskRecPtr); + TestObjId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + UT_SetForceFail(UT_KEY(OS_TaskGetId), (unsigned long)TestObjId); /* Set context to that of child */ CFE_ES_ExitChildTask(); UT_Report(__FILE__, __LINE__, UT_GetStubCount(UT_KEY(OS_TaskExit)) == 1, @@ -4499,13 +4408,8 @@ void TestAPI(void) /* Test exiting a child task within an app main task */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].RecordUsed = true; - CFE_ES_Global.TaskTable[1].AppId = 0; - OS_TaskCreate(&CFE_ES_Global.TaskTable[1].TaskId, - NULL, NULL, NULL, 0, 0, 0); - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[0].TaskInfo.MainTaskId = - CFE_ES_Global.TaskTable[1].TaskId; + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); + ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, &UtTaskRecPtr); CFE_ES_ExitChildTask(); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_CANNOT_CALL_APP_MAIN]) && @@ -4515,13 +4419,12 @@ void TestAPI(void) /* Test exiting a child task with an error retrieving the app ID */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].RecordUsed = false; CFE_ES_ExitChildTask(); UT_Report(__FILE__, __LINE__, - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_GET_APP_ID]) && + UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_TASKEXIT_BAD_CONTEXT]) && UT_GetStubCount(UT_KEY(OS_printf)) == 1, "CFE_ES_ExitChildTask", - "Error calling CFE_ES_GetAppID"); + "Invalid context"); /* Test registering a child task with an OS task register failure */ ES_ResetUnitTest(); @@ -4594,179 +4497,9 @@ void TestAPI(void) "CFE_ES_CalculateCRC", "Invalid CRC type"); - /* Test CDS registering with a write CDS failure */ - ES_ResetUnitTest(); - UT_SetCDSSize(50000); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - UT_SetDeferredRetcode(UT_KEY(CFE_PSP_WriteToCDS), 2, OS_ERROR); - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, 4, "Name3") == OS_ERROR, - "CFE_ES_RegisterCDS", - "Writing to BSP CDS failure"); - - /* Test successful CDS registering */ - ES_ResetUnitTest(); - UT_SetCDSSize(50000); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, 4, "Name") == CFE_SUCCESS, - "CFE_ES_RegisterCDS", - "Register CDS successful"); - - /* Test CDS registering using an already registered name */ - ES_ResetUnitTest(); - UT_SetCDSSize(50000); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, - 4, - "Name") == CFE_ES_CDS_ALREADY_EXISTS, - "CFE_ES_RegisterCDS", - "Retrieve existing CDS"); - - /* Test CDS registering using the same name, but a different size */ - ES_ResetUnitTest(); - UT_SetCDSSize(50000); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, 6, "Name") == CFE_SUCCESS, - "CFE_ES_RegisterCDS", - "Get CDS of same name, but new size"); - - /* Test CDS registering using a null name */ - ES_ResetUnitTest(); - UT_SetCDSSize(50000); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, 4, "") == CFE_ES_CDS_INVALID_NAME, - "CFE_ES_RegisterCDS", - "Invalid name size"); - - /* Test CDS registering with no memory pool available */ - ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - TempSize = CFE_ES_Global.CDSVars.MemPoolSize; - CFE_ES_Global.CDSVars.MemPoolSize = 0; - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, - 4, - "Name") == CFE_ES_NOT_IMPLEMENTED, - "CFE_ES_RegisterCDS", - "No memory pool available"); - CFE_ES_Global.CDSVars.MemPoolSize = TempSize; - - /* Test CDS registering with a block size of zero */ - ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, - 0, - "Name") == CFE_ES_CDS_INVALID_SIZE, - "CFE_ES_RegisterCDS", - "Block size zero"); - - /* Test CDS registering with all the CDS registries taken */ - ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - - /* Set all the CDS registries to 'taken' */ - for (i = 0; i < CFE_ES_Global.CDSVars.MaxNumRegEntries; i++) - { - CFE_ES_Global.CDSVars.Registry[i].Taken = true; - } - - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, - 4, - "Name2") == CFE_ES_CDS_REGISTRY_FULL, - "CFE_ES_RegisterCDS", - "No available entries"); - - /* Restore all the CDS registries back to 'not taken' */ - for (i = 0; i < CFE_ES_Global.CDSVars.MaxNumRegEntries; i++) - { - CFE_ES_Global.CDSVars.Registry[i].Taken = false; - } - - /* Test CDS registering using a bad app ID */ - ES_ResetUnitTest(); - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, 4, "Name2") == CFE_ES_ERR_APPID, - "CFE_ES_RegisterCDS", - "Bad application ID"); - - /* Register CDS to set up for the copy test */ - ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.AppTable[Id].AppState = CFE_ES_AppState_RUNNING; - CFE_ES_Global.AppTable[Id].TaskInfo.MainTaskId = TestObjId; - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, 4, "Name") == CFE_SUCCESS, - "CFE_ES_RegisterCDS", - "Register CDS successful (set up for copy test)"); - - /* Test successfully copying to CDS */ - ES_ResetUnitTest(); - UT_SetDeferredRetcode(UT_KEY(CFE_PSP_ReadFromCDS), 1, OS_SUCCESS); - UT_Report(__FILE__, __LINE__, - CFE_ES_CopyToCDS(CDSHandle, &TempSize) == CFE_SUCCESS, - "CFE_ES_CopyToCDS", - "Copy to CDS successful"); - - /* Test successfully restoring from a CDS */ - ES_ResetUnitTest(); - UT_Report(__FILE__, __LINE__, - CFE_ES_RestoreFromCDS(&TempSize, CDSHandle) == CFE_SUCCESS, - "CFE_ES_RestoreFromCDS", - "Restore from CDS successful"); - /* Test shared mutex take with a take error */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); UT_SetDeferredRetcode(UT_KEY(OS_MutSemTake), 1, -1); CFE_ES_LockSharedData(__func__, 12345); UT_Report(__FILE__, __LINE__, @@ -4776,10 +4509,7 @@ void TestAPI(void) /* Test shared mutex release with a release error */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); UT_SetDeferredRetcode(UT_KEY(OS_MutSemGive), 1, -1); CFE_ES_UnlockSharedData(__func__, 98765); UT_Report(__FILE__, __LINE__, @@ -4787,31 +4517,124 @@ void TestAPI(void) "CFE_ES_UnlockSharedData", "Mutex release error"); - /* Test successfully registering a generic counter */ + + /* Test waiting for apps to initialize before continuing; transition from + * initializing to running + */ ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_EARLY_INIT, "UT", &UtAppRecPtr, NULL); + CFE_ES_Global.SystemState = CFE_ES_SystemState_OPERATIONAL; + CFE_ES_WaitForStartupSync(0); UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterGenCounter(&CounterId, "Counter1") == CFE_SUCCESS, - "CFE_ES_RegisterGenCounter", - "Register counter successful"); + UtAppRecPtr->AppState == + CFE_ES_AppState_RUNNING, + "CFE_ES_WaitForStartupSync", + "Transition from initializing to running"); - /* Test registering a generic counter that is already registered */ + /* Test waiting for apps to initialize before continuing with the semaphore + * already released + */ ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", &UtAppRecPtr, NULL); + CFE_ES_Global.SystemState = CFE_ES_SystemState_CORE_READY; + CFE_ES_WaitForStartupSync(99); + + /* Note - CFE_ES_WaitForStartupSync() returns void, nothing to check for + * here. This is for code coverage + */ UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterGenCounter(&CounterId, - "Counter1") == CFE_ES_BAD_ARGUMENT, - "CFE_ES_RegisterGenCounter", - "Attempt to register an existing counter"); + 1, + "CFE_ES_WaitForStartupSync", + "System state core ready"); - /* Test registering the maximum number of generic counters */ + /* Test waiting for apps to initialize as an external app + */ ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_EARLY_INIT, "UT", &UtAppRecPtr, NULL); + CFE_ES_Global.SystemState = CFE_ES_SystemState_CORE_READY; + CFE_ES_WaitForStartupSync(99); - for (i = 1; i < CFE_PLATFORM_ES_MAX_GEN_COUNTERS; i++) - { + /* Note - CFE_ES_WaitForStartupSync() returns void, nothing to check for + * here. This is for code coverage + */ + UT_Report(__FILE__, __LINE__, + 1, + "CFE_ES_WaitForStartupSync", + "System state operational"); - snprintf(CounterName, 11, "Counter%d", i + 1); + /* Test adding a time-stamped message to the system log using an invalid + * log mode + * + * TEST CASE REMOVED as the invalid log mode follow the same path as Discard, + * this test case added nothing new + */ - if (CFE_ES_RegisterGenCounter(&CounterId, CounterName) != CFE_SUCCESS) - { + + /* Test successfully adding a time-stamped message to the system log that + * causes the log index to be reset + */ + ES_ResetUnitTest(); + CFE_ES_ResetDataPtr->SystemLogWriteIdx = CFE_PLATFORM_ES_SYSTEM_LOG_SIZE; + CFE_ES_ResetDataPtr->SystemLogEndIdx = CFE_ES_ResetDataPtr->SystemLogWriteIdx; + CFE_ES_ResetDataPtr->SystemLogMode = CFE_ES_LogMode_DISCARD; + UT_Report(__FILE__, __LINE__, + CFE_ES_WriteToSysLog("SysLogText") == CFE_ES_ERR_SYS_LOG_FULL, + "CFE_ES_WriteToSysLog", + "Add message to log that resets the log index"); + + /* Test successfully adding a time-stamped message to the system log that + * causes the log index to be reset + */ + ES_ResetUnitTest(); + CFE_ES_ResetDataPtr->SystemLogWriteIdx = CFE_PLATFORM_ES_SYSTEM_LOG_SIZE; + CFE_ES_ResetDataPtr->SystemLogEndIdx = CFE_ES_ResetDataPtr->SystemLogWriteIdx; + CFE_ES_ResetDataPtr->SystemLogMode = CFE_ES_LogMode_OVERWRITE; + UT_Report(__FILE__, __LINE__, + CFE_ES_WriteToSysLog("SysLogText") == CFE_SUCCESS && + CFE_ES_ResetDataPtr->SystemLogWriteIdx < CFE_PLATFORM_ES_SYSTEM_LOG_SIZE, + "CFE_ES_WriteToSysLog", + "Add message to log that resets the log index"); + + /* Test run loop with an application error status */ + ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", &UtAppRecPtr, NULL); + RunStatus = CFE_ES_RunStatus_APP_ERROR; + UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_ERROR; + UT_Report(__FILE__, __LINE__, + CFE_ES_RunLoop(&RunStatus) == false, + "CFE_ES_RunLoop", + "Application error run status"); + +} + +void TestGenericCounterAPI(void) +{ + char CounterName[11]; + uint32 CounterId; + uint32 CounterCount; + int i; + + /* Test successfully registering a generic counter */ + ES_ResetUnitTest(); + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterGenCounter(&CounterId, "Counter1") == CFE_SUCCESS, + "CFE_ES_RegisterGenCounter", + "Register counter successful"); + + /* Test registering a generic counter that is already registered */ + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterGenCounter(&CounterId, + "Counter1") == CFE_ES_BAD_ARGUMENT, + "CFE_ES_RegisterGenCounter", + "Attempt to register an existing counter"); + + /* Test registering the maximum number of generic counters */ + for (i = 1; i < CFE_PLATFORM_ES_MAX_GEN_COUNTERS; i++) + { + snprintf(CounterName, sizeof(CounterName), "Counter%d", i + 1); + + if (CFE_ES_RegisterGenCounter(&CounterId, CounterName) != CFE_SUCCESS) + { break; } } @@ -4822,7 +4645,6 @@ void TestAPI(void) "Register maximum number of counters"); /* Test registering a generic counter after the maximum are registered */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_RegisterGenCounter(&CounterId, "Counter999") == CFE_ES_BAD_ARGUMENT, @@ -4830,7 +4652,6 @@ void TestAPI(void) "Maximum number of counters exceeded"); /* Test getting a registered generic counter that doesn't exist */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_GetGenCounterIDByName(&CounterId, "Counter999") == @@ -4839,7 +4660,6 @@ void TestAPI(void) "Cannot get counter that does not exist"); /* Test successfully getting a registered generic counter ID by name */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_GetGenCounterIDByName(&CounterId, "Counter5") == CFE_SUCCESS, @@ -4847,14 +4667,12 @@ void TestAPI(void) "Get generic counter ID successful"); /* Test deleting a registered generic counter that doesn't exist */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_DeleteGenCounter(123456) == CFE_ES_BAD_ARGUMENT, "CFE_ES_DeleteGenCounter", "Cannot delete counter that does not exist"); /* Test successfully deleting a registered generic counter by ID */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_DeleteGenCounter(CounterId) == CFE_SUCCESS, "CFE_ES_DeleteGenCounter", @@ -4863,14 +4681,12 @@ void TestAPI(void) /* Test successfully registering a generic counter to verify a place for * it is now available and to provide an ID for subsequent tests */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_RegisterGenCounter(&CounterId, "CounterX") == CFE_SUCCESS, "CFE_ES_RegisterGenCounter", "Register counter; back to maximum number"); /* Test incrementing a generic counter that doesn't exist */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_IncrementGenCounter(CFE_PLATFORM_ES_MAX_GEN_COUNTERS) == CFE_ES_BAD_ARGUMENT, @@ -4878,21 +4694,18 @@ void TestAPI(void) "Bad counter ID"); /* Test successfully incrementing a generic counter */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_IncrementGenCounter(CounterId) == CFE_SUCCESS, "CFE_ES_IncrementGenCounter", "Increment counter successful"); /* Test getting a generic counter value for a counter that doesn't exist */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_GetGenCount(123456, &CounterCount) == CFE_ES_BAD_ARGUMENT, "CFE_ES_GetGenCount", "Bad counter ID"); /* Test successfully getting a generic counter value */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_GetGenCount(CounterId, &CounterCount) == CFE_SUCCESS && CounterCount == 1, @@ -4900,266 +4713,260 @@ void TestAPI(void) "Get counter value successful"); /* Test setting a generic counter value for a counter that doesn't exist */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_SetGenCount(123456, 5) == CFE_ES_BAD_ARGUMENT, "CFE_ES_SetGenCount", "Bad counter ID"); /* Test successfully setting a generic counter value */ - ES_ResetUnitTest(); UT_Report(__FILE__, __LINE__, CFE_ES_SetGenCount(CounterId, 5) == CFE_SUCCESS, "CFE_ES_SetGenCount", "Set counter value successful"); /* Test value retrieved from a generic counter value */ - ES_ResetUnitTest(); CFE_ES_GetGenCount(CounterId, &CounterCount); UT_Report(__FILE__, __LINE__, (CounterCount == 5), "CFE_ES_SetGenCount", "Check value for counter set"); - /* Test waiting for apps to initialize before continuing; transition from - * initializing to running - */ + /* Test registering a generic counter with a null counter ID pointer */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.SystemState = CFE_ES_SystemState_OPERATIONAL; - CFE_ES_Global.AppTable[Id].AppState = - CFE_ES_AppState_EARLY_INIT; - CFE_ES_WaitForStartupSync(0); UT_Report(__FILE__, __LINE__, - CFE_ES_Global.AppTable[Id].AppState == - CFE_ES_AppState_RUNNING, - "CFE_ES_WaitForStartupSync", - "Transition from initializing to running"); + CFE_ES_RegisterGenCounter(NULL, + "Counter1") == CFE_ES_BAD_ARGUMENT, + "CFE_ES_RegisterGenCounter", + "Attempt to register using a null counter ID pointer"); - /* Test waiting for apps to initialize before continuing with the semaphore - * already released - */ + /* Test registering a generic counter with a null counter name */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.AppTable[Id].AppState = - CFE_ES_AppState_RUNNING; - CFE_ES_Global.SystemState = CFE_ES_SystemState_CORE_READY; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_CORE; - CFE_ES_WaitForStartupSync(99); - /* Note - CFE_ES_WaitForStartupSync() returns void, nothing to check for - * here. This is for code coverage - */ + for ( i = 0; i < CFE_PLATFORM_ES_MAX_GEN_COUNTERS; i++ ) + { + CFE_ES_Global.CounterTable[i].RecordUsed = false; + } + UT_Report(__FILE__, __LINE__, - 1, - "CFE_ES_WaitForStartupSync", - "System state core ready"); + CFE_ES_RegisterGenCounter(&CounterId, + NULL) == CFE_ES_BAD_ARGUMENT, + "CFE_ES_RegisterGenCounter", + "Attempt to register using a null counter name"); - /* Test waiting for apps to initialize as an external app - */ + /* Test incrementing a generic counter where the record is not in use */ ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - CFE_ES_Global.AppTable[Id].AppState = - CFE_ES_AppState_EARLY_INIT; - CFE_ES_Global.SystemState = CFE_ES_SystemState_CORE_READY; - CFE_ES_Global.AppTable[Id].Type = CFE_ES_AppType_EXTERNAL; - CFE_ES_WaitForStartupSync(99); + UT_Report(__FILE__, __LINE__, + CFE_ES_IncrementGenCounter(CounterId) == CFE_ES_BAD_ARGUMENT, + "CFE_ES_IncrementGenCounter", + "Record not in use"); - /* Note - CFE_ES_WaitForStartupSync() returns void, nothing to check for - * here. This is for code coverage - */ + /* Test setting a generic counter where the record is not in use */ + ES_ResetUnitTest(); + CFE_ES_Global.CounterTable[CounterId].RecordUsed = false; UT_Report(__FILE__, __LINE__, - 1, - "CFE_ES_WaitForStartupSync", - "System state operational"); + CFE_ES_SetGenCount(CounterId, 0) == CFE_ES_BAD_ARGUMENT, + "CFE_ES_SetGenCount", + "Record not in use"); - /* Test adding a time-stamped message to the system log using an invalid - * log mode - * - * TEST CASE REMOVED as the invalid log mode follow the same path as Discard, - * this test case added nothing new - */ + /* Test getting a generic counter where the record is not in use */ + ES_ResetUnitTest(); + CFE_ES_Global.CounterTable[CounterId].RecordUsed = false; + UT_Report(__FILE__, __LINE__, + CFE_ES_GetGenCount(CounterId, &CounterCount) + == CFE_ES_BAD_ARGUMENT, + "CFE_ES_GetGenCount", + "Record not in use"); + /* Test getting a generic counter where the count is null */ + ES_ResetUnitTest(); + CFE_ES_Global.CounterTable[CounterId].RecordUsed = true; + UT_Report(__FILE__, __LINE__, + CFE_ES_GetGenCount(CounterId, NULL) + == CFE_ES_BAD_ARGUMENT, + "CFE_ES_GetGenCount", + "Null count"); - /* Test successfully adding a time-stamped message to the system log that - * causes the log index to be reset - */ - ES_ResetUnitTest(); - CFE_ES_ResetDataPtr->SystemLogWriteIdx = CFE_PLATFORM_ES_SYSTEM_LOG_SIZE; - CFE_ES_ResetDataPtr->SystemLogEndIdx = CFE_ES_ResetDataPtr->SystemLogWriteIdx; - CFE_ES_ResetDataPtr->SystemLogMode = CFE_ES_LogMode_DISCARD; - UT_Report(__FILE__, __LINE__, - CFE_ES_WriteToSysLog("SysLogText") == CFE_ES_ERR_SYS_LOG_FULL, - "CFE_ES_WriteToSysLog", - "Add message to log that resets the log index"); + /* Test getting a registered generic counter ID using a null counter + * pointer + */ + ES_ResetUnitTest(); + UT_Report(__FILE__, __LINE__, + CFE_ES_GetGenCounterIDByName(NULL, + "CounterX") == CFE_ES_BAD_ARGUMENT, + "CFE_ES_GetGenCounterIDByName", + "Null name"); +} - /* Test successfully adding a time-stamped message to the system log that - * causes the log index to be reset - */ - ES_ResetUnitTest(); - CFE_ES_ResetDataPtr->SystemLogWriteIdx = CFE_PLATFORM_ES_SYSTEM_LOG_SIZE; - CFE_ES_ResetDataPtr->SystemLogEndIdx = CFE_ES_ResetDataPtr->SystemLogWriteIdx; - CFE_ES_ResetDataPtr->SystemLogMode = CFE_ES_LogMode_OVERWRITE; - UT_Report(__FILE__, __LINE__, - CFE_ES_WriteToSysLog("SysLogText") == CFE_SUCCESS && - CFE_ES_ResetDataPtr->SystemLogWriteIdx < CFE_PLATFORM_ES_SYSTEM_LOG_SIZE, - "CFE_ES_WriteToSysLog", - "Add message to log that resets the log index"); +void TestCDS() +{ + uint32 CdsSize; + uint8 *CdsPtr; + char CDSName[CFE_ES_CDS_MAX_FULL_NAME_LEN + 4]; + CFE_ES_CDSHandle_t CDSHandle; + uint32 i; + uint32 TempSize; - /* Test run loop with an application error status */ - ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - RunStatus = CFE_ES_RunStatus_APP_ERROR; - CFE_ES_Global.AppTable[Id].ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_ERROR; - UT_Report(__FILE__, __LINE__, - CFE_ES_RunLoop(&RunStatus) == false, - "CFE_ES_RunLoop", - "Application error run status"); - /* Test CDS registering using a name longer than the maximum allowed */ - ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; +#ifdef UT_VERBOSE + UT_Text("Begin Test CDS\n"); +#endif - for (i = 0; i < CFE_MISSION_ES_CDS_MAX_NAME_LENGTH + 1; i++) - { - CDSName[i] = 'a'; - } + /* Set up the PSP stubs for CDS testing */ + UT_SetCDSSize(128 * 1024); - CDSName[i] = '\0'; + /* Test CDS registering with a write CDS failure */ + ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); + UT_SetCDSSize(50000); + CFE_ES_InitializeCDS(50000); + UT_SetDeferredRetcode(UT_KEY(CFE_PSP_WriteToCDS), 2, OS_ERROR); + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, 4, "Name3") == OS_ERROR, + "CFE_ES_RegisterCDS", + "Writing to BSP CDS failure"); - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, 4, CDSName) - == CFE_ES_CDS_INVALID_NAME, - "CFE_ES_RegisterCDS", - "Invalid name size"); + /* Test successful CDS registering */ + ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); + UT_SetCDSSize(50000); + CFE_ES_InitializeCDS(50000); + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, 4, "Name") == CFE_SUCCESS, + "CFE_ES_RegisterCDS", + "Register CDS successful"); - /* Test registering a generic counter with a null counter ID pointer */ - ES_ResetUnitTest(); - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterGenCounter(NULL, - "Counter1") == CFE_ES_BAD_ARGUMENT, - "CFE_ES_RegisterGenCounter", - "Attempt to register using a null counter ID pointer"); + /* Test CDS registering using an already registered name */ + /* No reset here -- just attempt to register the same name again */ + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, + 4, + "Name") == CFE_ES_CDS_ALREADY_EXISTS, + "CFE_ES_RegisterCDS", + "Retrieve existing CDS"); - /* Test registering a generic counter with a null counter name */ - ES_ResetUnitTest(); + /* Test CDS registering using the same name, but a different size */ + /* No reset here -- just attempt to register the same name again */ + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, 6, "Name") == CFE_SUCCESS, + "CFE_ES_RegisterCDS", + "Get CDS of same name, but new size"); - for ( i = 0; i < CFE_PLATFORM_ES_MAX_GEN_COUNTERS; i++ ) - { - CFE_ES_Global.CounterTable[i].RecordUsed = false; - } + /* Test CDS registering using a null name */ + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, 4, "") == CFE_ES_CDS_INVALID_NAME, + "CFE_ES_RegisterCDS", + "Invalid name size"); - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterGenCounter(&CounterId, - NULL) == CFE_ES_BAD_ARGUMENT, - "CFE_ES_RegisterGenCounter", - "Attempt to register using a null counter name"); + /* Test CDS registering with a block size of zero */ + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, + 0, + "Name") == CFE_ES_CDS_INVALID_SIZE, + "CFE_ES_RegisterCDS", + "Block size zero"); - /* Test incrementing a generic counter where the record is not in use */ - ES_ResetUnitTest(); - CFE_ES_Global.CounterTable[CounterId].RecordUsed = false; - UT_Report(__FILE__, __LINE__, - CFE_ES_IncrementGenCounter(CounterId) == CFE_ES_BAD_ARGUMENT, - "CFE_ES_IncrementGenCounter", - "Record not in use"); + /* Test CDS registering with no memory pool available */ + ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, + 4, + "Name") == CFE_ES_NOT_IMPLEMENTED, + "CFE_ES_RegisterCDS", + "No memory pool available"); - /* Test setting a generic counter where the record is not in use */ - ES_ResetUnitTest(); - CFE_ES_Global.CounterTable[CounterId].RecordUsed = false; - UT_Report(__FILE__, __LINE__, - CFE_ES_SetGenCount(CounterId, 0) == CFE_ES_BAD_ARGUMENT, - "CFE_ES_SetGenCount", - "Record not in use"); + /* Test CDS registering with all the CDS registries taken */ + ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); + UT_SetCDSSize(50000); + CFE_ES_InitializeCDS(50000); - /* Test getting a generic counter where the record is not in use */ - ES_ResetUnitTest(); - CFE_ES_Global.CounterTable[CounterId].RecordUsed = false; - UT_Report(__FILE__, __LINE__, - CFE_ES_GetGenCount(CounterId, &CounterCount) - == CFE_ES_BAD_ARGUMENT, - "CFE_ES_GetGenCount", - "Record not in use"); + /* Set all the CDS registries to 'taken' */ + for (i = 0; i < CFE_ES_Global.CDSVars.MaxNumRegEntries; i++) + { + CFE_ES_Global.CDSVars.Registry[i].Taken = true; + } - /* Test getting a generic counter where the count is null */ - ES_ResetUnitTest(); - CFE_ES_Global.CounterTable[CounterId].RecordUsed = true; - UT_Report(__FILE__, __LINE__, - CFE_ES_GetGenCount(CounterId, NULL) - == CFE_ES_BAD_ARGUMENT, - "CFE_ES_GetGenCount", - "Null count"); + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, + 4, + "Name2") == CFE_ES_CDS_REGISTRY_FULL, + "CFE_ES_RegisterCDS", + "No available entries"); - /* Test getting a registered generic counter ID using a null counter - * pointer - */ - ES_ResetUnitTest(); - UT_Report(__FILE__, __LINE__, - CFE_ES_GetGenCounterIDByName(NULL, - "CounterX") == CFE_ES_BAD_ARGUMENT, - "CFE_ES_GetGenCounterIDByName", - "Null name"); + /* Test CDS registering using a bad app ID */ + ES_ResetUnitTest(); + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, 4, "Name2") == CFE_ES_ERR_APPID, + "CFE_ES_RegisterCDS", + "Bad application ID"); - /* Test unsuccessful CDS registering */ - ES_ResetUnitTest(); - OS_TaskCreate(&TestObjId, "UT", NULL, NULL, 0, 0, 0); - Id = ES_UT_OSALID_TO_ARRAYIDX(TestObjId); - CFE_ES_Global.TaskTable[Id].RecordUsed = true; - CFE_ES_Global.TaskTable[Id].AppId = Id; - UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, - 0xffffffff, - "Name") == CFE_ES_ERR_MEM_BLOCK_SIZE, - "CFE_ES_RegisterCDS", - "Register CDS unsuccessful"); -} /* end TestAPI */ + /* Register CDS to set up for the copy test */ + ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); + UT_SetCDSSize(50000); + CFE_ES_InitializeCDS(50000); + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, 4, "Name") == CFE_SUCCESS, + "CFE_ES_RegisterCDS", + "Register CDS successful (set up for copy test)"); -void TestCDS() -{ - uint32 Temp; - uint32 CdsSize; - uint8 *CdsPtr; + /* Test successfully copying to CDS */ + UT_SetDeferredRetcode(UT_KEY(CFE_PSP_ReadFromCDS), 1, OS_SUCCESS); + UT_Report(__FILE__, __LINE__, + CFE_ES_CopyToCDS(CDSHandle, &TempSize) == CFE_SUCCESS, + "CFE_ES_CopyToCDS", + "Copy to CDS successful"); -#ifdef UT_VERBOSE - UT_Text("Begin Test CDS\n"); -#endif + /* Test successfully restoring from a CDS */ + UT_Report(__FILE__, __LINE__, + CFE_ES_RestoreFromCDS(&TempSize, CDSHandle) == CFE_SUCCESS, + "CFE_ES_RestoreFromCDS", + "Restore from CDS successful"); - /* Test validating the app ID using a bad ID value */ + /* Test CDS registering using a name longer than the maximum allowed */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].RecordUsed = true; - CFE_ES_Global.TaskTable[1].AppId = CFE_PLATFORM_ES_MAX_APPLICATIONS + 1; + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "UT", NULL, NULL); + UT_SetCDSSize(50000); + CFE_ES_InitializeCDS(50000); + + for (i = 0; i < CFE_MISSION_ES_CDS_MAX_NAME_LENGTH + 1; i++) + { + CDSName[i] = 'a'; + } + + CDSName[i] = '\0'; + + UT_Report(__FILE__, __LINE__, + CFE_ES_RegisterCDS(&CDSHandle, 4, CDSName) + == CFE_ES_CDS_INVALID_NAME, + "CFE_ES_RegisterCDS", + "Invalid name size"); + + /* Test unsuccessful CDS registering */ UT_Report(__FILE__, __LINE__, - CFE_ES_CDS_ValidateAppID(&Temp) == CFE_ES_ERR_APPID, - "CFE_ES_CDS_ValidateAppID", - "Bad app ID"); + CFE_ES_RegisterCDS(&CDSHandle, + 0xffffffff, + "Name") == CFE_ES_ERR_MEM_BLOCK_SIZE, + "CFE_ES_RegisterCDS", + "Register CDS unsuccessful"); /* Test memory pool rebuild and registry recovery with an * unreadable registry */ ES_ResetUnitTest(); - CFE_ES_Global.TaskTable[1].AppId = 1; - CFE_ES_Global.CDSVars.MaxNumRegEntries = CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES + 2; - UT_SetForceFail(UT_KEY(CFE_PSP_ReadFromCDS), -1); + UT_SetDeferredRetcode(UT_KEY(CFE_PSP_ReadFromCDS), 1, -1); + UT_Report(__FILE__, __LINE__, + CFE_ES_RebuildCDS() == CFE_ES_CDS_INVALID, + "CFE_ES_RebuildCDS", + "First read from CDS bad"); + + UT_SetDeferredRetcode(UT_KEY(CFE_PSP_ReadFromCDS), 2, -1); UT_Report(__FILE__, __LINE__, CFE_ES_RebuildCDS() == CFE_ES_CDS_INVALID, "CFE_ES_RebuildCDS", "Second read from CDS bad"); /* Test CDS registry initialization with a CDS write failure */ - ES_ResetUnitTest(); UT_SetDeferredRetcode(UT_KEY(CFE_PSP_WriteToCDS), 1, -1); UT_Report(__FILE__, __LINE__, CFE_ES_InitCDSRegistry() == -1, @@ -5168,8 +4975,6 @@ void TestCDS() /* Test successful CDS initialization */ ES_ResetUnitTest(); - UT_SetCDSSize(128 * 1024); - UT_SetDeferredRetcode(UT_KEY(CFE_PSP_ReadFromCDS), 1, OS_SUCCESS); UT_Report(__FILE__, __LINE__, CFE_ES_CDS_EarlyInit() == CFE_SUCCESS, "CFE_ES_CDS_EarlyInit", @@ -5200,6 +5005,9 @@ void TestCDS() "CFE_ES_CDS_EarlyInit", "Unable to obtain CDS size"); + /* Reset back to a sufficient CDS size */ + UT_SetCDSSize(128 * 1024); + /* Test CDS initialization with rebuilding not possible */ ES_ResetUnitTest(); UT_GetDataBuffer(UT_KEY(CFE_PSP_ReadFromCDS), (void**)&CdsPtr, &CdsSize, NULL); @@ -5222,6 +5030,7 @@ void TestCDS() /* Test CDS validation with CDS read end check failure */ ES_ResetUnitTest(); UT_GetDataBuffer(UT_KEY(CFE_PSP_ReadFromCDS), (void**)&CdsPtr, &CdsSize, NULL); + CFE_ES_Global.CDSVars.CDSSize = CdsSize; memcpy(CdsPtr + CdsSize - 8, "gibberish", 8); UT_Report(__FILE__, __LINE__, CFE_ES_ValidateCDS() == CFE_ES_CDS_INVALID, @@ -5293,12 +5102,7 @@ void TestCDS() CFE_ES_CDSBlockDesc.CheckBits = CFE_ES_CDS_CHECK_PATTERN; CFE_ES_CDSBlockDesc.AllocatedFlag = CFE_ES_CDS_BLOCK_USED; CFE_ES_CDSBlockDesc.ActualSize = 512; - CFE_ES_Global.CDSVars.Registry[0].Taken = true; - CFE_ES_Global.CDSVars.Registry[0].Table = true; - CFE_ES_Global.CDSVars.Registry[0].MemHandle = 200; - strncpy(CFE_ES_Global.CDSVars.Registry[0].Name, - "NO_APP.CDS_NAME", OS_MAX_API_NAME); - CFE_ES_Global.CDSVars.Registry[0].Name[OS_MAX_API_NAME - 1] = '\0'; + ES_UT_SetupSingleCDSRegistry("NO_APP.CDS_NAME", true, NULL); UT_SetDeferredRetcode(UT_KEY(CFE_PSP_WriteToCDS), 2, OS_ERROR); UT_Report(__FILE__, __LINE__, CFE_ES_DeleteCDS("NO_APP.CDS_NAME", true) == -1, @@ -5309,16 +5113,8 @@ void TestCDS() * still active */ ES_ResetUnitTest(); - CFE_ES_Global.CDSVars.Registry[0].Taken = true; - CFE_ES_Global.CDSVars.Registry[0].Table = true; - CFE_ES_Global.CDSVars.Registry[0].MemHandle = 200; - strncpy(CFE_ES_Global.CDSVars.Registry[0].Name, - "CFE_ES.CDS_NAME", OS_MAX_API_NAME); - CFE_ES_Global.CDSVars.Registry[0].Name[OS_MAX_API_NAME - 1] = '\0'; - strncpy((char *) CFE_ES_Global.AppTable[0].StartParams.Name, "CFE_ES", - OS_MAX_API_NAME); - CFE_ES_Global.AppTable[0].StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; - CFE_ES_Global.AppTable[0].AppState = CFE_ES_AppState_RUNNING; + ES_UT_SetupSingleCDSRegistry("CFE_ES.CDS_NAME", true, NULL); + ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, "CFE_ES", NULL, NULL); UT_Report(__FILE__, __LINE__, CFE_ES_DeleteCDS("CFE_ES.CDS_NAME", true) == CFE_ES_CDS_OWNER_ACTIVE_ERR, @@ -5369,12 +5165,11 @@ void TestCDS() * maximum allowed */ ES_ResetUnitTest(); - CFE_ES_Global.CDSVars.Registry[0].Taken = true; - CFE_ES_Global.CDSVars.Registry[0].Table = true; - memset(CFE_ES_Global.CDSVars.Registry[0].Name, 'a', CFE_ES_CDS_MAX_FULL_NAME_LEN - 1); - CFE_ES_Global.CDSVars.Registry[0].Name[CFE_ES_CDS_MAX_FULL_NAME_LEN - 1] = '\0'; + memset(CDSName, 'a', CFE_ES_CDS_MAX_FULL_NAME_LEN - 1); + CDSName[CFE_ES_CDS_MAX_FULL_NAME_LEN - 1] = '\0'; + ES_UT_SetupSingleCDSRegistry(CDSName, true, NULL); UT_Report(__FILE__, __LINE__, - CFE_ES_DeleteCDS(CFE_ES_Global.CDSVars.Registry[0].Name, + CFE_ES_DeleteCDS(CDSName, true) == CFE_ES_ERR_MEM_HANDLE, "CFE_ES_DeleteCDS", "CDS name too long"); diff --git a/fsw/cfe-core/unit-test/es_UT.h b/fsw/cfe-core/unit-test/es_UT.h index 982bb24af..6a5f8ae15 100644 --- a/fsw/cfe-core/unit-test/es_UT.h +++ b/fsw/cfe-core/unit-test/es_UT.h @@ -333,5 +333,6 @@ void TestCDSMempool(void); void TestESMempool(void); void TestSysLog(void); +void TestGenericCounterAPI(void); #endif /* _es_ut_h_ */ diff --git a/fsw/cfe-core/unit-test/ut_osprintf_stubs.c b/fsw/cfe-core/unit-test/ut_osprintf_stubs.c index 94a28185d..34005daea 100644 --- a/fsw/cfe-core/unit-test/ut_osprintf_stubs.c +++ b/fsw/cfe-core/unit-test/ut_osprintf_stubs.c @@ -160,5 +160,7 @@ const char *UT_OSP_MESSAGES[] = [UT_OSP_NO_FREE_CORE_APP_SLOTS] = "ES Startup: Error, No free application slots available for CORE App!\n", /* ES Startup: CFE_ES_Global.TaskTable record used error for App: CFE_EVS, continuing. */ [UT_OSP_RECORD_USED] = "ES Startup: CFE_ES_Global.TaskTable record used error for App: %s, continuing.\n", + /* CFE_ES_ExitChildTask called from invalid task context */ + [UT_OSP_TASKEXIT_BAD_CONTEXT] = "CFE_ES_ExitChildTask called from invalid task context\n", }; diff --git a/fsw/cfe-core/unit-test/ut_osprintf_stubs.h b/fsw/cfe-core/unit-test/ut_osprintf_stubs.h index 3d44305b8..7fbd8e3f7 100644 --- a/fsw/cfe-core/unit-test/ut_osprintf_stubs.h +++ b/fsw/cfe-core/unit-test/ut_osprintf_stubs.h @@ -95,6 +95,7 @@ #define UT_OSP_NO_FREE_CORE_APP_SLOTS 66 #define UT_OSP_STARTUP_SYNC_FAIL_2 67 #define UT_OSP_MODULE_UNLOAD_FAILED 68 +#define UT_OSP_TASKEXIT_BAD_CONTEXT 69 #endif diff --git a/fsw/cfe-core/ut-stubs/ut_es_stubs.c b/fsw/cfe-core/ut-stubs/ut_es_stubs.c index 9e2aeb976..226061555 100644 --- a/fsw/cfe-core/ut-stubs/ut_es_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_es_stubs.c @@ -59,6 +59,25 @@ */ #define CFE_UT_ES_POOL_STATIC_BLOCK_SIZE 4096 +/* + * Default value to return from calls that output an App ID, if the + * test case does not provide a value + */ +#define CFE_UT_ES_DEFAULT_APPID ((uint32)1) + +/* + * Default value to return from calls that output a Task ID, if the + * test case does not provide a value + */ +#define CFE_UT_ES_DEFAULT_TASKID ((uint32)1) + +/* + * Invalid value to output from calls as resource ID for the + * calls that return failure. If subsequently used by application code, + * it will likely induce a segfault or other noticeably bad behavior. + */ +#define CFE_UT_ES_ID_INVALID ((uint32)0xDEADBEEF) + /* ** Functions */ @@ -145,10 +164,47 @@ int32 CFE_ES_GetAppID(uint32 *AppIdPtr) } else { - *AppIdPtr = 0; + *AppIdPtr = CFE_UT_ES_DEFAULT_APPID; } } + if (status < 0) + { + *AppIdPtr = CFE_UT_ES_ID_INVALID; + } + + return status; +} + +int32 CFE_ES_GetTaskID(uint32 *TaskIdPtr) +{ + UT_Stub_RegisterContext(UT_KEY(CFE_ES_GetTaskID), TaskIdPtr); + + int32 status; + uint32 *IdBuff; + uint32 BuffSize; + uint32 Position; + + status = UT_DEFAULT_IMPL(CFE_ES_GetTaskID); + + if (status >= 0) + { + UT_GetDataBuffer(UT_KEY(CFE_ES_GetTaskID), (void **)&IdBuff, &BuffSize, &Position); + if (IdBuff != NULL && BuffSize == sizeof(*TaskIdPtr)) + { + *TaskIdPtr = *IdBuff; + } + else + { + *TaskIdPtr = CFE_UT_ES_DEFAULT_TASKID; + } + } + + if (status < 0) + { + *TaskIdPtr = CFE_UT_ES_ID_INVALID; + } + return status; } @@ -204,11 +260,16 @@ int32 CFE_ES_GetAppIDByName(uint32 *AppIdPtr, const char *AppName) } else { - *AppIdPtr = 0; + *AppIdPtr = CFE_UT_ES_DEFAULT_APPID; } } } + if (status < 0) + { + *AppIdPtr = CFE_UT_ES_ID_INVALID; + } + return status; } @@ -751,7 +812,7 @@ int32 CFE_ES_GetTaskInfo(CFE_ES_TaskInfo_t *TaskInfo, uint32 TaskId) if (UT_Stub_CopyToLocal(UT_KEY(CFE_ES_GetTaskInfo), (uint8*)TaskInfo, sizeof(*TaskInfo)) < sizeof(*TaskInfo)) { memset(TaskInfo, 0, sizeof(*TaskInfo)); - TaskInfo->AppId = 3; /* Fake ID number */ + TaskInfo->AppId = CFE_UT_ES_DEFAULT_APPID; strncpy((char *) &TaskInfo->AppName, "UT", sizeof(TaskInfo->AppName)); strncpy((char *) &TaskInfo->TaskName, "UT", sizeof(TaskInfo->TaskName)); } @@ -1201,3 +1262,50 @@ int32 CFE_ES_SetGenCount(uint32 CounterId, uint32 Count) return status; } +int32 CFE_ES_AppID_ToIndex(uint32 AppID, uint32 *Idx) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_ES_AppID_ToIndex), AppID); + UT_Stub_RegisterContext(UT_KEY(CFE_ES_AppID_ToIndex), Idx); + + int32 return_code; + + *Idx = AppID & 0xFFFF; + return_code = UT_DEFAULT_IMPL_RC(CFE_ES_AppID_ToIndex, 1); + + if (return_code == 1) + { + UT_Stub_CopyToLocal(UT_KEY(CFE_ES_AppID_ToIndex), Idx, sizeof(*Idx)); + return_code = CFE_SUCCESS; + } + + if (return_code != CFE_SUCCESS) + { + *Idx = 0xDEADBEEFU; + } + + return return_code; +} + +int32 CFE_ES_TaskID_ToIndex(uint32 TaskID, uint32 *Idx) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_ES_TaskID_ToIndex), TaskID); + UT_Stub_RegisterContext(UT_KEY(CFE_ES_TaskID_ToIndex), Idx); + + int32 return_code; + + *Idx = TaskID & 0xFFFF; + return_code = UT_DEFAULT_IMPL_RC(CFE_ES_TaskID_ToIndex, 1); + + if (return_code == 1) + { + UT_Stub_CopyToLocal(UT_KEY(CFE_ES_TaskID_ToIndex), Idx, sizeof(*Idx)); + return_code = CFE_SUCCESS; + } + + if (return_code != CFE_SUCCESS) + { + *Idx = 0xDEADBEEFU; + } + + return return_code; +} From 2efe70b7e797d5e7acea98295dcf8b94fa4173f0 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 2 Sep 2020 11:15:39 -0400 Subject: [PATCH 2/6] Fix #797, refactor internal table/id management in EVS Update the EVS subsystem to follow the ES pattern for internal table management. Do not use AppID directly as a table index. Instead, use a separate lookup routine to get a pointer to the entry, then access the entry via the pointer. Also introduce inline helper functions to get/set status of entry (free/not free), etc. --- fsw/cfe-core/src/evs/cfe_evs.c | 94 ++++++++-------- fsw/cfe-core/src/evs/cfe_evs_task.c | 154 ++++++++++++++------------- fsw/cfe-core/src/evs/cfe_evs_utils.c | 139 +++++++++++++++--------- fsw/cfe-core/src/evs/cfe_evs_utils.h | 126 ++++++++++++++++++++-- fsw/cfe-core/unit-test/evs_UT.c | 137 +++++++++++++----------- 5 files changed, 401 insertions(+), 249 deletions(-) diff --git a/fsw/cfe-core/src/evs/cfe_evs.c b/fsw/cfe-core/src/evs/cfe_evs.c index fe2b3af33..aac6b7db8 100644 --- a/fsw/cfe-core/src/evs/cfe_evs.c +++ b/fsw/cfe-core/src/evs/cfe_evs.c @@ -54,21 +54,17 @@ int32 CFE_EVS_Register (void *Filters, uint16 NumEventFilters, uint16 FilterSche { uint16 FilterLimit; uint16 i; - int32 Status = CFE_SUCCESS; + int32 Status; uint32 AppID = CFE_EVS_UNDEF_APPID; CFE_EVS_BinFilter_t *AppFilters; EVS_AppData_t *AppDataPtr; /* Query and verify the caller's AppID */ - Status = EVS_GetAppID(&AppID); - + Status = EVS_GetCurrentContext(&AppDataPtr, &AppID); if (Status == CFE_SUCCESS) { - /* Cleanup if already registered */ - if (CFE_EVS_GlobalData.AppData[AppID].RegisterFlag == true) - { - memset(&CFE_EVS_GlobalData.AppData[AppID], 0, sizeof(EVS_AppData_t)); - } + /* Clear and configure entry */ + memset(AppDataPtr, 0, sizeof(EVS_AppData_t)); /* Verify filter arguments */ if (FilterScheme != CFE_EVS_EventFilter_BINARY) @@ -82,10 +78,7 @@ int32 CFE_EVS_Register (void *Filters, uint16 NumEventFilters, uint16 FilterSche else { /* Initialize application event data */ - AppDataPtr = &CFE_EVS_GlobalData.AppData[AppID]; - AppDataPtr->RegisterFlag = true; AppDataPtr->ActiveFlag = true; - AppDataPtr->EventCount = 0; AppDataPtr->EventTypesActiveFlag = CFE_PLATFORM_EVS_DEFAULT_TYPE_FLAG; /* Set limit for number of provided filters */ @@ -118,6 +111,8 @@ int32 CFE_EVS_Register (void *Filters, uint16 NumEventFilters, uint16 FilterSche AppDataPtr->BinFilters[i].Mask = 0; AppDataPtr->BinFilters[i].Count = 0; } + + EVS_AppDataSetUsed(AppDataPtr, AppID); } } @@ -130,19 +125,16 @@ int32 CFE_EVS_Register (void *Filters, uint16 NumEventFilters, uint16 FilterSche */ int32 CFE_EVS_Unregister(void) { - int32 Status = CFE_SUCCESS; + int32 Status; uint32 AppID = CFE_EVS_UNDEF_APPID; + EVS_AppData_t *AppDataPtr; /* Query and verify the caller's AppID */ - Status = EVS_GetAppID(&AppID); - - if (Status == CFE_SUCCESS) + Status = EVS_GetCurrentContext(&AppDataPtr, &AppID); + if (Status == CFE_SUCCESS && + EVS_AppDataIsMatch(AppDataPtr, AppID)) { - /* Cleanup if already registered */ - if (CFE_EVS_GlobalData.AppData[AppID].RegisterFlag == true) - { - memset(&CFE_EVS_GlobalData.AppData[AppID], 0, sizeof(EVS_AppData_t)); - } + EVS_AppDataSetFree(AppDataPtr); } return(Status); @@ -154,29 +146,29 @@ int32 CFE_EVS_Unregister(void) */ int32 CFE_EVS_SendEvent (uint16 EventID, uint16 EventType, const char *Spec, ... ) { - int32 Status = CFE_SUCCESS; + int32 Status; uint32 AppID = CFE_EVS_UNDEF_APPID; CFE_TIME_SysTime_t Time; va_list Ptr; + EVS_AppData_t *AppDataPtr; /* Query and verify the caller's AppID */ - Status = EVS_GetAppID(&AppID); - + Status = EVS_GetCurrentContext(&AppDataPtr, &AppID); if (Status == CFE_SUCCESS) { - if (CFE_EVS_GlobalData.AppData[AppID].RegisterFlag == false) + if (!EVS_AppDataIsMatch(AppDataPtr, AppID)) { /* Handler for events from apps not registered with EVS */ - Status = EVS_NotRegistered(AppID); + Status = EVS_NotRegistered(AppDataPtr, AppID); } - else if (EVS_IsFiltered(AppID, EventID, EventType) == false) + else if (EVS_IsFiltered(AppDataPtr, EventID, EventType) == false) { /* Get current spacecraft time */ Time = CFE_TIME_GetTime(); /* Send the event packets */ va_start(Ptr, Spec); - EVS_GenerateEventTelemetry(AppID, EventID, EventType, &Time, Spec, Ptr); + EVS_GenerateEventTelemetry(AppDataPtr, EventID, EventType, &Time, Spec, Ptr); va_end(Ptr); } } @@ -194,24 +186,26 @@ int32 CFE_EVS_SendEventWithAppID (uint16 EventID, uint16 EventType, uint32 AppID int32 Status = CFE_SUCCESS; CFE_TIME_SysTime_t Time; va_list Ptr; + EVS_AppData_t *AppDataPtr; - if (AppID >= CFE_PLATFORM_ES_MAX_APPLICATIONS) + AppDataPtr = EVS_GetAppDataByID (AppID); + if (AppDataPtr == NULL) { Status = CFE_EVS_APP_ILLEGAL_APP_ID; } - else if (CFE_EVS_GlobalData.AppData[AppID].RegisterFlag == false) + else if (!EVS_AppDataIsMatch(AppDataPtr, AppID)) { /* Handler for events from apps not registered with EVS */ - Status = EVS_NotRegistered(AppID); + Status = EVS_NotRegistered(AppDataPtr, AppID); } - else if (EVS_IsFiltered(AppID, EventID, EventType) == false) + else if (EVS_IsFiltered(AppDataPtr, EventID, EventType) == false) { /* Get current spacecraft time */ Time = CFE_TIME_GetTime(); /* Send the event packets */ va_start(Ptr, Spec); - EVS_GenerateEventTelemetry(AppID, EventID, EventType, &Time, Spec, Ptr); + EVS_GenerateEventTelemetry(AppDataPtr, EventID, EventType, &Time, Spec, Ptr); va_end(Ptr); } @@ -224,25 +218,25 @@ int32 CFE_EVS_SendEventWithAppID (uint16 EventID, uint16 EventType, uint32 AppID */ int32 CFE_EVS_SendTimedEvent (CFE_TIME_SysTime_t Time, uint16 EventID, uint16 EventType, const char *Spec, ... ) { - int32 Status = CFE_SUCCESS; + int32 Status; uint32 AppID = CFE_EVS_UNDEF_APPID; va_list Ptr; + EVS_AppData_t *AppDataPtr; /* Query and verify the caller's AppID */ - Status = EVS_GetAppID(&AppID); - + Status = EVS_GetCurrentContext(&AppDataPtr, &AppID); if (Status == CFE_SUCCESS) { - if (CFE_EVS_GlobalData.AppData[AppID].RegisterFlag == false) + if (!EVS_AppDataIsMatch(AppDataPtr, AppID)) { /* Handler for events from apps not registered with EVS */ - Status = EVS_NotRegistered(AppID); + Status = EVS_NotRegistered(AppDataPtr, AppID); } - else if (EVS_IsFiltered(AppID, EventID, EventType) == false) + else if (EVS_IsFiltered(AppDataPtr, EventID, EventType) == false) { /* Send the event packets */ va_start(Ptr, Spec); - EVS_GenerateEventTelemetry(AppID, EventID, EventType, &Time, Spec, Ptr); + EVS_GenerateEventTelemetry(AppDataPtr, EventID, EventType, &Time, Spec, Ptr); va_end(Ptr); } } @@ -256,22 +250,22 @@ int32 CFE_EVS_SendTimedEvent (CFE_TIME_SysTime_t Time, uint16 EventID, uint16 Ev */ int32 CFE_EVS_ResetFilter (int16 EventID) { - int32 Status = CFE_SUCCESS; + int32 Status; EVS_BinFilter_t *FilterPtr = NULL; uint32 AppID = CFE_EVS_UNDEF_APPID; + EVS_AppData_t *AppDataPtr; /* Query and verify the caller's AppID */ - Status = EVS_GetAppID(&AppID); - + Status = EVS_GetCurrentContext(&AppDataPtr, &AppID); if (Status == CFE_SUCCESS) { - if (CFE_EVS_GlobalData.AppData[AppID].RegisterFlag == false) + if (!EVS_AppDataIsMatch(AppDataPtr, AppID)) { Status = CFE_EVS_APP_NOT_REGISTERED; } else { - FilterPtr = EVS_FindEventID(EventID, CFE_EVS_GlobalData.AppData[AppID].BinFilters); + FilterPtr = EVS_FindEventID(EventID, AppDataPtr->BinFilters); if (FilterPtr != NULL) { @@ -294,16 +288,16 @@ int32 CFE_EVS_ResetFilter (int16 EventID) */ int32 CFE_EVS_ResetAllFilters ( void ) { - int32 Status = CFE_SUCCESS; + int32 Status; uint32 AppID = CFE_EVS_UNDEF_APPID; uint32 i; + EVS_AppData_t *AppDataPtr; - /* Get and verify caller's AppID */ - Status = EVS_GetAppID(&AppID); - + /* Query and verify the caller's AppID */ + Status = EVS_GetCurrentContext(&AppDataPtr, &AppID); if (Status == CFE_SUCCESS) { - if (CFE_EVS_GlobalData.AppData[AppID].RegisterFlag == false) + if (!EVS_AppDataIsMatch(AppDataPtr, AppID)) { Status = CFE_EVS_APP_NOT_REGISTERED; } @@ -311,7 +305,7 @@ int32 CFE_EVS_ResetAllFilters ( void ) { for (i = 0; i < CFE_PLATFORM_EVS_MAX_EVENT_FILTERS; i++) { - CFE_EVS_GlobalData.AppData[AppID].BinFilters[i].Count = 0; + AppDataPtr->BinFilters[i].Count = 0; } } } diff --git a/fsw/cfe-core/src/evs/cfe_evs_task.c b/fsw/cfe-core/src/evs/cfe_evs_task.c index ec61392be..17328b985 100644 --- a/fsw/cfe-core/src/evs/cfe_evs_task.c +++ b/fsw/cfe-core/src/evs/cfe_evs_task.c @@ -184,15 +184,18 @@ int32 CFE_EVS_EarlyInit ( void ) int32 CFE_EVS_CleanUpApp(uint32 AppID) { int32 Status = CFE_SUCCESS; + EVS_AppData_t *AppDataPtr; - if (AppID >= CFE_PLATFORM_ES_MAX_APPLICATIONS) + /* Query and verify the caller's AppID */ + AppDataPtr = EVS_GetAppDataByID(AppID); + if (AppDataPtr == NULL) { Status = CFE_EVS_APP_ILLEGAL_APP_ID; } - else if (CFE_EVS_GlobalData.AppData[AppID].RegisterFlag == true) + else if (EVS_AppDataIsMatch(AppDataPtr, AppID)) { /* Same cleanup as CFE_EVS_Unregister() */ - memset(&CFE_EVS_GlobalData.AppData[AppID], 0, sizeof(EVS_AppData_t)); + EVS_AppDataSetFree(AppDataPtr); } return(Status); @@ -289,8 +292,8 @@ int32 CFE_EVS_TaskInit ( void ) return Status; } - /* Query and verify the EVS AppID */ - Status = EVS_GetAppID(&AppID); + /* Query and verify the AppID */ + Status = CFE_ES_GetAppID(&AppID); if (Status != CFE_SUCCESS) { CFE_ES_WriteToSysLog("EVS:Call to CFE_ES_GetAppID Failed:RC=0x%08X\n",(unsigned int)Status); @@ -689,7 +692,8 @@ int32 CFE_EVS_ClearLogCmd(const CFE_EVS_ClearLog_t *data) int32 CFE_EVS_ReportHousekeepingCmd (const CFE_SB_CmdHdr_t *data) { uint32 i, j; - + EVS_AppData_t *AppDataPtr; + CFE_EVS_AppTlmData_t *AppTlmDataPtr; if (CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogEnabled == true) { @@ -700,23 +704,27 @@ int32 CFE_EVS_ReportHousekeepingCmd (const CFE_SB_CmdHdr_t *data) } /* Write event state data for registered apps to telemetry packet */ + AppDataPtr = CFE_EVS_GlobalData.AppData; + AppTlmDataPtr = CFE_EVS_GlobalData.EVS_TlmPkt.Payload.AppData; for (i = 0, j = 0; j < CFE_MISSION_ES_MAX_APPLICATIONS && i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++) { - if (CFE_EVS_GlobalData.AppData[i].RegisterFlag == true) + if ( EVS_AppDataIsUsed(AppDataPtr) ) { - CFE_EVS_GlobalData.EVS_TlmPkt.Payload.AppData[j].AppID = i; - CFE_EVS_GlobalData.EVS_TlmPkt.Payload.AppData[j].AppEnableStatus = CFE_EVS_GlobalData.AppData[i].ActiveFlag; - CFE_EVS_GlobalData.EVS_TlmPkt.Payload.AppData[j].AppMessageSentCounter = CFE_EVS_GlobalData.AppData[i].EventCount; - j++; + AppTlmDataPtr->AppID = EVS_AppDataGetID(AppDataPtr); + AppTlmDataPtr->AppEnableStatus = AppDataPtr->ActiveFlag; + AppTlmDataPtr->AppMessageSentCounter = AppDataPtr->EventCount; + ++j; + ++AppTlmDataPtr; } + ++AppDataPtr; } /* Clear unused portion of event state data in telemetry packet */ for (i = j; i < CFE_MISSION_ES_MAX_APPLICATIONS; i++) { - CFE_EVS_GlobalData.EVS_TlmPkt.Payload.AppData[i].AppID = 0; - CFE_EVS_GlobalData.EVS_TlmPkt.Payload.AppData[i].AppEnableStatus = false; - CFE_EVS_GlobalData.EVS_TlmPkt.Payload.AppData[i].AppMessageSentCounter = 0; + AppTlmDataPtr->AppID = 0; + AppTlmDataPtr->AppEnableStatus = false; + AppTlmDataPtr->AppMessageSentCounter = 0; } CFE_SB_TimeStampMsg((CFE_SB_Msg_t *) &CFE_EVS_GlobalData.EVS_TlmPkt); @@ -772,7 +780,6 @@ int32 CFE_EVS_SetFilterCmd(const CFE_EVS_SetFilter_t *data) { const CFE_EVS_AppNameEventIDMaskCmd_Payload_t *CmdPtr = &data->Payload; EVS_BinFilter_t *FilterPtr; - uint32 AppID = CFE_EVS_UNDEF_APPID; int32 Status; EVS_AppData_t *AppDataPtr; char LocalName[OS_MAX_API_NAME]; @@ -784,12 +791,10 @@ int32 CFE_EVS_SetFilterCmd(const CFE_EVS_SetFilter_t *data) CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL, OS_MAX_API_NAME, sizeof(CmdPtr->AppName)); /* Retreive application data */ - Status = EVS_GetApplicationInfo(&AppID, LocalName); + Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName); if (Status == CFE_SUCCESS) { - AppDataPtr = &CFE_EVS_GlobalData.AppData[AppID]; - FilterPtr = EVS_FindEventID(CmdPtr->EventID, AppDataPtr->BinFilters); if(FilterPtr != NULL) @@ -820,8 +825,8 @@ int32 CFE_EVS_SetFilterCmd(const CFE_EVS_SetFilter_t *data) else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID) { EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR, - "Illegal application ID %d retrieved for %s: CC = %lu", - (int)AppID, LocalName, (long unsigned int)CFE_EVS_SET_FILTER_CC); + "Illegal application ID retrieved for %s: CC = %lu", + LocalName, (long unsigned int)CFE_EVS_SET_FILTER_CC); } else { @@ -966,6 +971,7 @@ int32 CFE_EVS_EnableEventTypeCmd(const CFE_EVS_EnableEventType_t *data) uint32 i; const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload; int32 ReturnCode; + EVS_AppData_t *AppDataPtr; /* Need to check for an out of range bitmask, since our bit masks are only 4 bits */ if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F) @@ -977,13 +983,15 @@ int32 CFE_EVS_EnableEventTypeCmd(const CFE_EVS_EnableEventType_t *data) } else { + AppDataPtr = CFE_EVS_GlobalData.AppData; for (i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++) { /* Make sure application is registered for event services */ - if (CFE_EVS_GlobalData.AppData[i].RegisterFlag == true) + if ( EVS_AppDataIsUsed(AppDataPtr) ) { - EVS_EnableTypes(CmdPtr->BitMask, i); + EVS_EnableTypes(AppDataPtr, CmdPtr->BitMask); } + ++AppDataPtr; } EVS_SendEvent(CFE_EVS_ENAEVTTYPE_EID, CFE_EVS_EventType_DEBUG, @@ -1014,6 +1022,7 @@ int32 CFE_EVS_DisableEventTypeCmd(const CFE_EVS_DisableEventType_t *data) uint32 i; const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload; int32 ReturnCode; + EVS_AppData_t *AppDataPtr; /* Need to check for an out of range bitmask, since our bit masks are only 4 bits */ if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F) @@ -1026,13 +1035,15 @@ int32 CFE_EVS_DisableEventTypeCmd(const CFE_EVS_DisableEventType_t *data) else { + AppDataPtr = CFE_EVS_GlobalData.AppData; for (i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++) { /* Make sure application is registered for event services */ - if (CFE_EVS_GlobalData.AppData[i].RegisterFlag == true) + if ( EVS_AppDataIsUsed(AppDataPtr) ) { - EVS_DisableTypes(CmdPtr->BitMask, i); + EVS_DisableTypes(AppDataPtr, CmdPtr->BitMask); } + ++AppDataPtr; } EVS_SendEvent(CFE_EVS_DISEVTTYPE_EID, CFE_EVS_EventType_DEBUG, @@ -1099,7 +1110,7 @@ int32 CFE_EVS_SetEventFormatModeCmd(const CFE_EVS_SetEventFormatMode_t *data) int32 CFE_EVS_EnableAppEventTypeCmd(const CFE_EVS_EnableAppEventType_t *data) { const CFE_EVS_AppNameBitMaskCmd_Payload_t *CmdPtr = &data->Payload; - uint32 AppID = CFE_EVS_UNDEF_APPID; + EVS_AppData_t *AppDataPtr; int32 Status; char LocalName[OS_MAX_API_NAME]; @@ -1110,7 +1121,7 @@ int32 CFE_EVS_EnableAppEventTypeCmd(const CFE_EVS_EnableAppEventType_t *data) CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL, OS_MAX_API_NAME, sizeof(CmdPtr->AppName)); /* Retrieve application data */ - Status = EVS_GetApplicationInfo(&AppID, LocalName); + Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName); if(Status == CFE_SUCCESS) { @@ -1125,7 +1136,7 @@ int32 CFE_EVS_EnableAppEventTypeCmd(const CFE_EVS_EnableAppEventType_t *data) } else { - EVS_EnableTypes(CmdPtr->BitMask, AppID); + EVS_EnableTypes(AppDataPtr, CmdPtr->BitMask); } } else if(Status == CFE_EVS_APP_NOT_REGISTERED) @@ -1137,8 +1148,8 @@ int32 CFE_EVS_EnableAppEventTypeCmd(const CFE_EVS_EnableAppEventType_t *data) else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID) { EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR, - "Illegal application ID %d retrieved for %s: CC = %lu", - (int)AppID, LocalName, (long unsigned int)CFE_EVS_ENABLE_APP_EVENT_TYPE_CC); + "Illegal application ID retrieved for %s: CC = %lu", + LocalName, (long unsigned int)CFE_EVS_ENABLE_APP_EVENT_TYPE_CC); } else { @@ -1172,7 +1183,7 @@ int32 CFE_EVS_EnableAppEventTypeCmd(const CFE_EVS_EnableAppEventType_t *data) */ int32 CFE_EVS_DisableAppEventTypeCmd(const CFE_EVS_DisableAppEventType_t *data) { - uint32 AppID = CFE_EVS_UNDEF_APPID; + EVS_AppData_t *AppDataPtr; const CFE_EVS_AppNameBitMaskCmd_Payload_t *CmdPtr = &data->Payload; int32 Status; char LocalName[OS_MAX_API_NAME]; @@ -1184,7 +1195,7 @@ int32 CFE_EVS_DisableAppEventTypeCmd(const CFE_EVS_DisableAppEventType_t *data) CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL, OS_MAX_API_NAME, sizeof(CmdPtr->AppName)); /* Retreive application data */ - Status = EVS_GetApplicationInfo(&AppID, LocalName); + Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName); if(Status == CFE_SUCCESS) { @@ -1199,7 +1210,7 @@ int32 CFE_EVS_DisableAppEventTypeCmd(const CFE_EVS_DisableAppEventType_t *data) } else { - EVS_DisableTypes(CmdPtr->BitMask, AppID); + EVS_DisableTypes(AppDataPtr, CmdPtr->BitMask); } } else if(Status == CFE_EVS_APP_NOT_REGISTERED) @@ -1211,8 +1222,8 @@ int32 CFE_EVS_DisableAppEventTypeCmd(const CFE_EVS_DisableAppEventType_t *data) else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID) { EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR, - "Illegal application ID %d retrieved for %s: CC = %lu", - (int)AppID, LocalName, (long unsigned int)CFE_EVS_DISABLE_APP_EVENT_TYPE_CC); + "Illegal application ID retrieved for %s: CC = %lu", + LocalName, (long unsigned int)CFE_EVS_DISABLE_APP_EVENT_TYPE_CC); } else { @@ -1245,7 +1256,7 @@ int32 CFE_EVS_DisableAppEventTypeCmd(const CFE_EVS_DisableAppEventType_t *data) */ int32 CFE_EVS_EnableAppEventsCmd(const CFE_EVS_EnableAppEvents_t *data) { - uint32 AppID = CFE_EVS_UNDEF_APPID; + EVS_AppData_t *AppDataPtr; const CFE_EVS_AppNameCmd_Payload_t *CmdPtr = &data->Payload; int32 Status; char LocalName[OS_MAX_API_NAME]; @@ -1257,11 +1268,11 @@ int32 CFE_EVS_EnableAppEventsCmd(const CFE_EVS_EnableAppEvents_t *data) CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL, OS_MAX_API_NAME, sizeof(CmdPtr->AppName)); /* Retrieve application data */ - Status = EVS_GetApplicationInfo(&AppID, LocalName); + Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName); if(Status == CFE_SUCCESS) { - CFE_EVS_GlobalData.AppData[AppID].ActiveFlag = true; + AppDataPtr->ActiveFlag = true; EVS_SendEvent(CFE_EVS_ENAAPPEVT_EID, CFE_EVS_EventType_DEBUG, "Enable App Events Command Received with AppName = %s", @@ -1276,8 +1287,8 @@ int32 CFE_EVS_EnableAppEventsCmd(const CFE_EVS_EnableAppEvents_t *data) else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID) { EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR, - "Illegal application ID %d retrieved for %s: CC = %lu", - (int)AppID, LocalName, (long unsigned int)CFE_EVS_ENABLE_APP_EVENTS_CC); + "Illegal application ID retrieved for %s: CC = %lu", + LocalName, (long unsigned int)CFE_EVS_ENABLE_APP_EVENTS_CC); } else { @@ -1303,7 +1314,7 @@ int32 CFE_EVS_EnableAppEventsCmd(const CFE_EVS_EnableAppEvents_t *data) */ int32 CFE_EVS_DisableAppEventsCmd(const CFE_EVS_DisableAppEvents_t *data) { - uint32 AppID = CFE_EVS_UNDEF_APPID; + EVS_AppData_t *AppDataPtr; const CFE_EVS_AppNameCmd_Payload_t *CmdPtr = &data->Payload; int32 Status; char LocalName[OS_MAX_API_NAME]; @@ -1315,11 +1326,11 @@ int32 CFE_EVS_DisableAppEventsCmd(const CFE_EVS_DisableAppEvents_t *data) CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL, OS_MAX_API_NAME, sizeof(CmdPtr->AppName)); /* Retreive application data */ - Status = EVS_GetApplicationInfo(&AppID, LocalName); + Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName); if(Status == CFE_SUCCESS) { - CFE_EVS_GlobalData.AppData[AppID].ActiveFlag = false; + AppDataPtr->ActiveFlag = false; EVS_SendEvent(CFE_EVS_DISAPPEVT_EID, CFE_EVS_EventType_DEBUG, "Disable App Events Command Received with AppName = %s", @@ -1334,8 +1345,8 @@ int32 CFE_EVS_DisableAppEventsCmd(const CFE_EVS_DisableAppEvents_t *data) else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID) { EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR, - "Illegal application ID %d retrieved for %s: CC = %lu", - (int)AppID, LocalName,(long unsigned int)CFE_EVS_DISABLE_APP_EVENTS_CC); + "Illegal application ID retrieved for %s: CC = %lu", + LocalName,(long unsigned int)CFE_EVS_DISABLE_APP_EVENTS_CC); } else { @@ -1362,7 +1373,7 @@ int32 CFE_EVS_DisableAppEventsCmd(const CFE_EVS_DisableAppEvents_t *data) */ int32 CFE_EVS_ResetAppCounterCmd(const CFE_EVS_ResetAppCounter_t *data) { - uint32 AppID = CFE_EVS_UNDEF_APPID; + EVS_AppData_t *AppDataPtr; const CFE_EVS_AppNameCmd_Payload_t *CmdPtr = &data->Payload; int32 Status; char LocalName[OS_MAX_API_NAME]; @@ -1374,11 +1385,11 @@ int32 CFE_EVS_ResetAppCounterCmd(const CFE_EVS_ResetAppCounter_t *data) CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL, OS_MAX_API_NAME, sizeof(CmdPtr->AppName)); /* Retreive application data */ - Status = EVS_GetApplicationInfo(&AppID, LocalName); + Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName); if(Status == CFE_SUCCESS) { - CFE_EVS_GlobalData.AppData[AppID].EventCount = 0; + AppDataPtr->EventCount = 0; EVS_SendEvent(CFE_EVS_RSTEVTCNT_EID, CFE_EVS_EventType_DEBUG, "Reset Event Counter Command Received with AppName = %s", @@ -1393,8 +1404,8 @@ int32 CFE_EVS_ResetAppCounterCmd(const CFE_EVS_ResetAppCounter_t *data) else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID) { EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR, - "Illegal application ID %d retrieved for %s: CC = %lu", - (int)AppID, LocalName,(long unsigned int) CFE_EVS_RESET_APP_COUNTER_CC); + "Illegal application ID retrieved for %s: CC = %lu", + LocalName,(long unsigned int) CFE_EVS_RESET_APP_COUNTER_CC); } else { @@ -1423,7 +1434,6 @@ int32 CFE_EVS_ResetFilterCmd(const CFE_EVS_ResetFilter_t *data) { const CFE_EVS_AppNameEventIDCmd_Payload_t *CmdPtr = &data->Payload; EVS_BinFilter_t *FilterPtr; - uint32 AppID = CFE_EVS_UNDEF_APPID; int32 Status; EVS_AppData_t *AppDataPtr; char LocalName[OS_MAX_API_NAME]; @@ -1435,12 +1445,10 @@ int32 CFE_EVS_ResetFilterCmd(const CFE_EVS_ResetFilter_t *data) CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL, OS_MAX_API_NAME, sizeof(CmdPtr->AppName)); /* Retreive application data */ - Status = EVS_GetApplicationInfo(&AppID, LocalName); + Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName); if(Status == CFE_SUCCESS) { - AppDataPtr = &CFE_EVS_GlobalData.AppData[AppID]; - FilterPtr = EVS_FindEventID(CmdPtr->EventID, AppDataPtr->BinFilters); if(FilterPtr != NULL) @@ -1469,8 +1477,8 @@ int32 CFE_EVS_ResetFilterCmd(const CFE_EVS_ResetFilter_t *data) else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID) { EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR, - "Illegal application ID %d retrieved for %s: CC = %lu", - (int)AppID, LocalName, (long unsigned int)CFE_EVS_RESET_FILTER_CC); + "Illegal application ID retrieved for %s: CC = %lu", + LocalName, (long unsigned int)CFE_EVS_RESET_FILTER_CC); } else { @@ -1497,7 +1505,7 @@ int32 CFE_EVS_ResetFilterCmd(const CFE_EVS_ResetFilter_t *data) */ int32 CFE_EVS_ResetAllFiltersCmd(const CFE_EVS_ResetAllFilters_t *data) { - uint32 AppID = CFE_EVS_UNDEF_APPID; + EVS_AppData_t *AppDataPtr; const CFE_EVS_AppNameCmd_Payload_t *CmdPtr = &data->Payload; int32 Status; uint32 i; @@ -1510,13 +1518,13 @@ int32 CFE_EVS_ResetAllFiltersCmd(const CFE_EVS_ResetAllFilters_t *data) CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL, OS_MAX_API_NAME, sizeof(CmdPtr->AppName)); /* Retreive application data */ - Status = EVS_GetApplicationInfo(&AppID, LocalName); + Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName); if(Status == CFE_SUCCESS) { for(i=0; iBinFilters[i].Count = 0; } EVS_SendEvent(CFE_EVS_RSTALLFILTER_EID, CFE_EVS_EventType_DEBUG, @@ -1532,8 +1540,8 @@ int32 CFE_EVS_ResetAllFiltersCmd(const CFE_EVS_ResetAllFilters_t *data) else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID) { EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR, - "Illegal application ID %d retrieved for %s: CC = %lu", - (int)AppID, LocalName, (long unsigned int)CFE_EVS_RESET_ALL_FILTERS_CC); + "Illegal application ID retrieved for %s: CC = %lu", + LocalName, (long unsigned int)CFE_EVS_RESET_ALL_FILTERS_CC); } else { @@ -1561,7 +1569,6 @@ int32 CFE_EVS_AddEventFilterCmd(const CFE_EVS_AddEventFilter_t *data) { const CFE_EVS_AppNameEventIDMaskCmd_Payload_t *CmdPtr = &data->Payload; EVS_BinFilter_t *FilterPtr; - uint32 AppID = CFE_EVS_UNDEF_APPID; int32 Status; EVS_AppData_t *AppDataPtr; char LocalName[OS_MAX_API_NAME]; @@ -1573,12 +1580,10 @@ int32 CFE_EVS_AddEventFilterCmd(const CFE_EVS_AddEventFilter_t *data) CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL, OS_MAX_API_NAME, sizeof(CmdPtr->AppName)); /* Retreive application data */ - Status = EVS_GetApplicationInfo(&AppID, LocalName); + Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName); if(Status == CFE_SUCCESS) { - AppDataPtr = &CFE_EVS_GlobalData.AppData[AppID]; - /* Check to see if this event is already registered for filtering */ FilterPtr = EVS_FindEventID(CmdPtr->EventID, AppDataPtr->BinFilters); @@ -1627,8 +1632,8 @@ int32 CFE_EVS_AddEventFilterCmd(const CFE_EVS_AddEventFilter_t *data) else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID) { EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR, - "Illegal application ID %d retrieved for %s: CC = %lu", - (int)AppID, LocalName, (long unsigned int)CFE_EVS_ADD_EVENT_FILTER_CC); + "Illegal application ID retrieved for %s: CC = %lu", + LocalName, (long unsigned int)CFE_EVS_ADD_EVENT_FILTER_CC); } else { @@ -1656,7 +1661,6 @@ int32 CFE_EVS_DeleteEventFilterCmd(const CFE_EVS_DeleteEventFilter_t *data) { const CFE_EVS_AppNameEventIDCmd_Payload_t *CmdPtr = &data->Payload; EVS_BinFilter_t *FilterPtr; - uint32 AppID = CFE_EVS_UNDEF_APPID; int32 Status; EVS_AppData_t *AppDataPtr; char LocalName[OS_MAX_API_NAME]; @@ -1668,12 +1672,10 @@ int32 CFE_EVS_DeleteEventFilterCmd(const CFE_EVS_DeleteEventFilter_t *data) CFE_SB_MessageStringGet(LocalName, (char *)CmdPtr->AppName, NULL, OS_MAX_API_NAME, sizeof(CmdPtr->AppName)); /* Retreive application data */ - Status = EVS_GetApplicationInfo(&AppID, LocalName); + Status = EVS_GetApplicationInfo(&AppDataPtr, LocalName); if(Status == CFE_SUCCESS) { - AppDataPtr = &CFE_EVS_GlobalData.AppData[AppID]; - FilterPtr = EVS_FindEventID(CmdPtr->EventID, AppDataPtr->BinFilters); if(FilterPtr != NULL) @@ -1705,8 +1707,8 @@ int32 CFE_EVS_DeleteEventFilterCmd(const CFE_EVS_DeleteEventFilter_t *data) else if(Status == CFE_EVS_APP_ILLEGAL_APP_ID) { EVS_SendEvent(CFE_EVS_ERR_ILLAPPIDRANGE_EID, CFE_EVS_EventType_ERROR, - "Illegal application ID %d retrieved for %s: CC = %lu", - (int)AppID, LocalName, (long unsigned int)CFE_EVS_DELETE_EVENT_FILTER_CC); + "Illegal application ID retrieved for %s: CC = %lu", + LocalName, (long unsigned int)CFE_EVS_DELETE_EVENT_FILTER_CC); } else { @@ -1773,18 +1775,17 @@ int32 CFE_EVS_WriteAppDataFileCmd(const CFE_EVS_WriteAppDataFile_t *data) if (BytesWritten == sizeof(CFE_FS_Header_t)) { + AppDataPtr = CFE_EVS_GlobalData.AppData; for (i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++) { /* Only have data for apps that are registered */ - if (CFE_EVS_GlobalData.AppData[i].RegisterFlag == true) + if ( EVS_AppDataIsUsed(AppDataPtr) ) { - AppDataPtr = &CFE_EVS_GlobalData.AppData[i]; - /* Clear application file data record */ memset(&AppDataFile, 0, sizeof(CFE_EVS_AppDataFile_t)); /* Copy application data to application file data record */ - CFE_ES_GetAppName(AppDataFile.AppName, i, OS_MAX_API_NAME); + CFE_ES_GetAppName(AppDataFile.AppName, EVS_AppDataGetID(AppDataPtr), OS_MAX_API_NAME); AppDataFile.ActiveFlag = AppDataPtr->ActiveFlag; AppDataFile.EventCount = AppDataPtr->EventCount; AppDataFile.EventTypesActiveFlag = AppDataPtr->EventTypesActiveFlag; @@ -1808,6 +1809,7 @@ int32 CFE_EVS_WriteAppDataFileCmd(const CFE_EVS_WriteAppDataFile_t *data) break; } } + ++AppDataPtr; } /* Process command handler success result */ diff --git a/fsw/cfe-core/src/evs/cfe_evs_utils.c b/fsw/cfe-core/src/evs/cfe_evs_utils.c index 9acc0836a..67a2e19fa 100644 --- a/fsw/cfe-core/src/evs/cfe_evs_utils.c +++ b/fsw/cfe-core/src/evs/cfe_evs_utils.c @@ -64,25 +64,60 @@ void EVS_OutputPort4 (char *Message); ** Assumptions and Notes: ** */ -int32 EVS_GetAppID (uint32 *AppIdPtr) +EVS_AppData_t *EVS_GetAppDataByID (uint32 AppID) { - int32 Status = CFE_SUCCESS; + uint32 AppIndex; + EVS_AppData_t *AppDataPtr; - /* Get the caller's AppID */ - Status = CFE_ES_GetAppID(AppIdPtr); + if (CFE_ES_AppID_ToIndex(AppID, &AppIndex) == CFE_SUCCESS && + AppIndex < CFE_PLATFORM_ES_MAX_APPLICATIONS) + { + AppDataPtr = &CFE_EVS_GlobalData.AppData[AppIndex]; + } + else + { + AppDataPtr = NULL; + } + + return(AppDataPtr); + +} /* End EVS_GetAppDataByID */ + +int32 EVS_GetCurrentContext (EVS_AppData_t **AppDataOut, uint32 *AppIDOut) +{ + uint32 AppID; + EVS_AppData_t *AppDataPtr; + int32 Status; + /* Get the caller's AppID */ + Status = CFE_ES_GetAppID(&AppID); if (Status == CFE_SUCCESS) { - /* Verify that AppID is in range */ - if (*AppIdPtr >= CFE_PLATFORM_ES_MAX_APPLICATIONS) - { - Status = CFE_EVS_APP_ILLEGAL_APP_ID; - } + AppDataPtr = EVS_GetAppDataByID (AppID); + } + else + { + AppDataPtr = NULL; + } + + if (AppDataPtr == NULL) + { + /* use EVS error/status code */ + Status = CFE_EVS_APP_ILLEGAL_APP_ID; } - return(Status); + if (AppIDOut) + { + *AppIDOut = AppID; + } + if (AppDataOut) + { + *AppDataOut = AppDataPtr; + } -} /* End EVS_GetAppID */ + return Status; + +} /* End EVS_GetCurrentContext */ /* @@ -96,31 +131,40 @@ int32 EVS_GetAppID (uint32 *AppIdPtr) ** Assumptions and Notes: ** */ -int32 EVS_GetApplicationInfo (uint32 *pAppID, const char *pAppName) +int32 EVS_GetApplicationInfo (EVS_AppData_t **AppDataOut, const char *pAppName) { - int32 Status = CFE_SUCCESS; + int32 Status; + uint32 AppID; + EVS_AppData_t *AppDataPtr; - if ((pAppName == (char *) NULL) || (pAppID == (uint32 *) NULL)) + Status = CFE_ES_GetAppIDByName(&AppID, pAppName); + if (Status != CFE_SUCCESS) { - Status = CFE_ES_ERR_BUFFER; + AppDataPtr = NULL; } else { - Status = CFE_ES_GetAppIDByName(pAppID, pAppName); - - if (Status == CFE_SUCCESS) - { - if (*pAppID >= CFE_PLATFORM_ES_MAX_APPLICATIONS) - { - Status = CFE_EVS_APP_ILLEGAL_APP_ID; - } - else if (CFE_EVS_GlobalData.AppData[*pAppID].RegisterFlag == false) - { - Status = CFE_EVS_APP_NOT_REGISTERED; - } - } + AppDataPtr = EVS_GetAppDataByID(AppID); + if (AppDataPtr == NULL) + { + /* + * should not happen - it means the CFE_ES_GetAppIDByName() + * returned a success code with an AppID which was in subsequently + * not accepted by CFE_ES_AppID_ToIndex() + */ + Status = CFE_EVS_APP_ILLEGAL_APP_ID; + } + else if (!EVS_AppDataIsMatch(AppDataPtr, AppID)) + { + /* Avoid outputting a bad pointer */ + AppDataPtr = NULL; + Status = CFE_EVS_APP_NOT_REGISTERED; + } } + + + *AppDataOut = AppDataPtr; return Status; } /* End EVS_GetApplicationInfo */ @@ -136,18 +180,18 @@ int32 EVS_GetApplicationInfo (uint32 *pAppID, const char *pAppName) ** Assumptions and Notes: ** */ -int32 EVS_NotRegistered (uint32 AppID) +int32 EVS_NotRegistered (EVS_AppData_t *AppDataPtr, uint32 AppID) { char AppName[OS_MAX_API_NAME]; /* Send only one "not registered" event per application */ - if (CFE_EVS_GlobalData.AppData[AppID].EventCount == 0) + if (AppDataPtr->EventCount == 0) { /* Increment count of "not registered" applications */ CFE_EVS_GlobalData.EVS_TlmPkt.Payload.UnregisteredAppCounter++; /* Indicate that "not registered" event has been sent for this app */ - CFE_EVS_GlobalData.AppData[AppID].EventCount++; + AppDataPtr->EventCount++; /* Get the name of the "not registered" app */ CFE_ES_GetAppName(AppName, AppID, OS_MAX_API_NAME); @@ -177,17 +221,13 @@ int32 EVS_NotRegistered (uint32 AppID) ** Assumptions and Notes: ** */ -bool EVS_IsFiltered (uint32 AppID, uint16 EventID, uint16 EventType) +bool EVS_IsFiltered (EVS_AppData_t *AppDataPtr, uint16 EventID, uint16 EventType) { EVS_BinFilter_t *FilterPtr; - EVS_AppData_t *AppDataPtr; bool Filtered = false; char AppName[OS_MAX_API_NAME]; - /* Caller has verified that AppID is good and has registered with EVS */ - AppDataPtr = &CFE_EVS_GlobalData.AppData[AppID]; - if (AppDataPtr->ActiveFlag == false) { /* All events are disabled for this application */ @@ -260,7 +300,7 @@ bool EVS_IsFiltered (uint32 AppID, uint16 EventID, uint16 EventType) /* Is it time to lock this filter? */ if (FilterPtr->Count == CFE_EVS_MAX_FILTER_COUNT) { - CFE_ES_GetAppName(AppName, AppID, OS_MAX_API_NAME); + CFE_ES_GetAppName(AppName, EVS_AppDataGetID(AppDataPtr), OS_MAX_API_NAME); EVS_SendEvent(CFE_EVS_FILTER_MAX_EID, CFE_EVS_EventType_INFORMATION, "Max filter count reached, AppName = %s, EventID = 0x%08x: Filter locked until reset", @@ -313,12 +353,12 @@ EVS_BinFilter_t *EVS_FindEventID (int16 EventID, EVS_BinFilter_t *FilterArray) ** Assumptions and Notes: ** */ -void EVS_EnableTypes (uint8 BitMask, uint32 AppID) +void EVS_EnableTypes (EVS_AppData_t *AppDataPtr, uint8 BitMask) { uint8 EventTypeBits = (CFE_EVS_DEBUG_BIT | CFE_EVS_INFORMATION_BIT | CFE_EVS_ERROR_BIT | CFE_EVS_CRITICAL_BIT); /* Enable selected event type bits from bitmask */ - CFE_EVS_GlobalData.AppData[AppID].EventTypesActiveFlag |= (BitMask & EventTypeBits); + AppDataPtr->EventTypesActiveFlag |= (BitMask & EventTypeBits); } /* End EVS_EnableTypes */ @@ -333,12 +373,12 @@ void EVS_EnableTypes (uint8 BitMask, uint32 AppID) ** Assumptions and Notes: ** */ -void EVS_DisableTypes (uint8 BitMask, uint32 AppID) +void EVS_DisableTypes (EVS_AppData_t *AppDataPtr, uint8 BitMask) { uint8 EventTypeBits = (CFE_EVS_DEBUG_BIT | CFE_EVS_INFORMATION_BIT | CFE_EVS_ERROR_BIT | CFE_EVS_CRITICAL_BIT); /* Disable selected event type bits from bitmask */ - CFE_EVS_GlobalData.AppData[AppID].EventTypesActiveFlag &= ~(BitMask & EventTypeBits); + AppDataPtr->EventTypesActiveFlag &= ~(BitMask & EventTypeBits); } /* End EVS_DisableTypes */ @@ -357,7 +397,7 @@ void EVS_DisableTypes (uint8 BitMask, uint32 AppID) ** If configured for short events, a separate short message is generated using a subset ** of the information from the long message. */ -void EVS_GenerateEventTelemetry(uint32 AppID, uint16 EventID, uint16 EventType, const CFE_TIME_SysTime_t *TimeStamp, const char *MsgSpec, va_list ArgPtr) +void EVS_GenerateEventTelemetry(EVS_AppData_t *AppDataPtr, uint16 EventID, uint16 EventType, const CFE_TIME_SysTime_t *TimeStamp, const char *MsgSpec, va_list ArgPtr) { CFE_EVS_LongEventTlm_t LongEventTlm; /* The "long" flavor is always generated, as this is what is logged */ CFE_EVS_ShortEventTlm_t ShortEventTlm; /* The "short" flavor is only generated if selected */ @@ -382,7 +422,7 @@ void EVS_GenerateEventTelemetry(uint32 AppID, uint16 EventID, uint16 EventType, } /* Obtain task and system information */ - CFE_ES_GetAppName((char *)LongEventTlm.Payload.PacketID.AppName, AppID, + CFE_ES_GetAppName((char *)LongEventTlm.Payload.PacketID.AppName, EVS_AppDataGetID(AppDataPtr), sizeof(LongEventTlm.Payload.PacketID.AppName)); LongEventTlm.Payload.PacketID.SpacecraftID = CFE_PSP_GetSpacecraftId(); LongEventTlm.Payload.PacketID.ProcessorID = CFE_PSP_GetProcessorId(); @@ -422,9 +462,9 @@ void EVS_GenerateEventTelemetry(uint32 AppID, uint16 EventID, uint16 EventType, CFE_EVS_GlobalData.EVS_TlmPkt.Payload.MessageSendCounter++; } - if (CFE_EVS_GlobalData.AppData[AppID].EventCount < CFE_EVS_MAX_EVENT_SEND_COUNT) + if (AppDataPtr->EventCount < CFE_EVS_MAX_EVENT_SEND_COUNT) { - CFE_EVS_GlobalData.AppData[AppID].EventCount++; + AppDataPtr->EventCount++; } } /* End EVS_GenerateEventTelemetry */ @@ -583,21 +623,24 @@ int32 EVS_SendEvent (uint16 EventID, uint16 EventType, const char *Spec, ... ) { CFE_TIME_SysTime_t Time; va_list Ptr; + EVS_AppData_t *AppDataPtr; /* * Must check that EVS_AppID is valid, which can happen if this is called * by some other thread before CFE_EVS_TaskInit() runs */ + AppDataPtr = EVS_GetAppDataByID(CFE_EVS_GlobalData.EVS_AppID); + /* Unlikely, but possible that an EVS event filter was added by command */ - if (CFE_EVS_GlobalData.EVS_AppID < CFE_PLATFORM_ES_MAX_APPLICATIONS && - EVS_IsFiltered(CFE_EVS_GlobalData.EVS_AppID, EventID, EventType) == false) + if ( EVS_AppDataIsMatch(AppDataPtr, CFE_EVS_GlobalData.EVS_AppID) && + EVS_IsFiltered(AppDataPtr, EventID, EventType) == false) { /* Get current spacecraft time */ Time = CFE_TIME_GetTime(); /* Send the event packets */ va_start(Ptr, Spec); - EVS_GenerateEventTelemetry(CFE_EVS_GlobalData.EVS_AppID, EventID, EventType, &Time, Spec, Ptr); + EVS_GenerateEventTelemetry(AppDataPtr, EventID, EventType, &Time, Spec, Ptr); va_end(Ptr); } diff --git a/fsw/cfe-core/src/evs/cfe_evs_utils.h b/fsw/cfe-core/src/evs/cfe_evs_utils.h index fd1883ae3..8ebd6807d 100644 --- a/fsw/cfe-core/src/evs/cfe_evs_utils.h +++ b/fsw/cfe-core/src/evs/cfe_evs_utils.h @@ -51,21 +51,125 @@ /* ============== Section III: Function Prototypes =========== */ -int32 EVS_GetAppID(uint32 *AppIdPtr); - -int32 EVS_GetApplicationInfo(uint32 *pAppID, const char *pAppName); - -int32 EVS_NotRegistered(uint32 AppID); - -bool EVS_IsFiltered(uint32 AppID, uint16 EventID, uint16 EventType); +/** + * @brief Obtain the EVS app record for the given ID + * + * This only obtains a pointer to where the record should be, it does + * not check/confirm that the record actually is for the given AppID. + * Use EVS_AppDataIsMatch() to determine if the record is valid. + * + * @sa EVS_AppDataIsMatch() + * + * @param[in] AppID AppID to find + * @returns Pointer to app table entry, or NULL if ID is invalid. + */ +EVS_AppData_t *EVS_GetAppDataByID (uint32 AppID); + +/** + * @brief Obtain the context information for the currently running app + * + * Obtains both the AppData record (pointer) and AppID for the current context. + * + * @param[out] AppDataOut Location to store App Data record pointer + * @param[out] AppIDOut Location to store AppID + * @returns CFE_SUCCESS if successful, or relevant error code. + */ +int32 EVS_GetCurrentContext (EVS_AppData_t **AppDataOut, uint32 *AppIDOut); + + +/** + * @brief Check if an EVS app record is in use or free/empty + * + * This routine checks if the EVS app entry is in use or if it is free + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] AppDataPtr pointer to app table entry + * @returns true if the entry is in use/configured, or false if it is free/empty + */ +static inline bool EVS_AppDataIsUsed(EVS_AppData_t *AppDataPtr) +{ + return (AppDataPtr->RegisterFlag); +} + +/** + * @brief Get the ID value from an EVS table entry + * + * This routine converts the table entry back to an abstract ID. + * + * @param[in] AppDataPtr pointer to app table entry + * @returns AppID of entry + */ +static inline uint32 EVS_AppDataGetID(EVS_AppData_t *AppDataPtr) +{ + /* + * The initial implementation does not store the ID in the entry; + * the ID is simply the zero-based index into the table. + */ + return (AppDataPtr - CFE_EVS_GlobalData.AppData); +} + +/** + * @brief Marks an EVS table entry as used (not free) + * + * This sets the internal field(s) within this entry, and marks + * it as being associated with the given app ID. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] AppDataPtr pointer to app table entry + * @param[in] AppID the app ID of this entry + */ +static inline void EVS_AppDataSetUsed(EVS_AppData_t *AppDataPtr, uint32 AppID) +{ + AppDataPtr->RegisterFlag = true; +} + +/** + * @brief Set an EVS table entry free (not used) + * + * This clears the internal field(s) within this entry, and allows the + * memory to be re-used in the future. + * + * @param[in] AppDataPtr pointer to app table entry + */ +static inline void EVS_AppDataSetFree(EVS_AppData_t *AppDataPtr) +{ + AppDataPtr->RegisterFlag = false; +} + +/** + * @brief Check if an EVS record is a match for the given AppID + * + * This routine confirms that the previously-located record is valid + * and matches the expected app ID. + * + * @param[in] AppDataPtr pointer to app table entry + * @param[in] AppID expected app ID + * @returns true if the entry matches the given app ID + */ +static inline bool EVS_AppDataIsMatch(EVS_AppData_t *AppDataPtr, uint32 AppID) +{ + return (AppDataPtr != NULL && EVS_AppDataIsUsed(AppDataPtr) && + EVS_AppDataGetID(AppDataPtr) == AppID); +} + + + +int32 EVS_GetApplicationInfo(EVS_AppData_t **AppDataOut, const char *pAppName); + +int32 EVS_NotRegistered (EVS_AppData_t *AppDataPtr, uint32 AppID); + +bool EVS_IsFiltered(EVS_AppData_t *AppDataPtr, uint16 EventID, uint16 EventType); EVS_BinFilter_t *EVS_FindEventID(int16 EventID, EVS_BinFilter_t *FilterArray); -void EVS_EnableTypes(uint8 BitMask, uint32 AppID); - -void EVS_DisableTypes(uint8 BitMask, uint32 AppID); +void EVS_EnableTypes (EVS_AppData_t *AppDataPtr, uint8 BitMask); +void EVS_DisableTypes (EVS_AppData_t *AppDataPtr, uint8 BitMask); -void EVS_GenerateEventTelemetry(uint32 AppID, uint16 EventID, uint16 EventType, +void EVS_GenerateEventTelemetry(EVS_AppData_t *AppDataPtr, uint16 EventID, uint16 EventType, const CFE_TIME_SysTime_t *Time, const char *MsgSpec, va_list ArgPtr); int32 EVS_SendEvent (uint16 EventID, uint16 EventType, const char *Spec, ... ); diff --git a/fsw/cfe-core/unit-test/evs_UT.c b/fsw/cfe-core/unit-test/evs_UT.c index 9cbea7bd1..5ce7a9623 100644 --- a/fsw/cfe-core/unit-test/evs_UT.c +++ b/fsw/cfe-core/unit-test/evs_UT.c @@ -284,6 +284,8 @@ void Test_Init(void) UT_Text("Begin Test Init\n"); #endif + UT_SetAppID(1); /*jphfix*/ + strncpy((char *) appbitcmd.Payload.AppName, "ut_cfe_evs", sizeof(appbitcmd.Payload.AppName)); @@ -491,7 +493,6 @@ void Test_Init(void) void Test_IllegalAppID(void) { CFE_TIME_SysTime_t time = {0, 0}; - uint32 AppID; #ifdef UT_VERBOSE UT_Text("Begin Test Illegal App ID\n"); @@ -499,7 +500,7 @@ void Test_IllegalAppID(void) /* Set test up with illegal application ID */ UT_InitData(); - UT_SetAppID(CFE_PLATFORM_ES_MAX_APPLICATIONS + 1); + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); /* Test registering an event using an illegal application ID */ UT_Report(__FILE__, __LINE__, @@ -509,6 +510,7 @@ void Test_IllegalAppID(void) /* Test unregistering an event using an illegal application ID */ UT_InitData(); + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); UT_Report(__FILE__, __LINE__, CFE_EVS_Unregister() == CFE_EVS_APP_ILLEGAL_APP_ID, "CFE_EVS_Unregister", @@ -516,6 +518,7 @@ void Test_IllegalAppID(void) /* Test sending an event using an illegal application ID */ UT_InitData(); + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); UT_Report(__FILE__, __LINE__, CFE_EVS_SendEvent(0, 0, "NULL") == CFE_EVS_APP_ILLEGAL_APP_ID, "CFE_EVS_SendEvent", @@ -523,16 +526,15 @@ void Test_IllegalAppID(void) /* Test sending an event using an illegal application ID */ UT_InitData(); - AppID = CFE_EVS_GlobalData.EVS_AppID; - CFE_EVS_GlobalData.EVS_AppID = CFE_PLATFORM_ES_MAX_APPLICATIONS; + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); UT_Report(__FILE__, __LINE__, EVS_SendEvent(0, 0, "NULL") == CFE_SUCCESS, "EVS_SendEvent", "Illegal app ID"); - CFE_EVS_GlobalData.EVS_AppID = AppID; /* Test sending a timed event using an illegal application ID */ UT_InitData(); + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); UT_Report(__FILE__, __LINE__, CFE_EVS_SendTimedEvent(time, 0, @@ -543,16 +545,18 @@ void Test_IllegalAppID(void) /* Test sending an event with app ID using an illegal application ID */ UT_InitData(); + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); UT_Report(__FILE__, __LINE__, CFE_EVS_SendEventWithAppID(0, 0, - CFE_PLATFORM_ES_MAX_APPLICATIONS + 1, + 0, "NULL") == CFE_EVS_APP_ILLEGAL_APP_ID, "CFE_EVS_SendEventWithAppID", "Illegal app ID"); /* Test resetting a filter using an illegal application ID */ UT_InitData(); + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); UT_Report(__FILE__, __LINE__, CFE_EVS_ResetFilter(0) == CFE_EVS_APP_ILLEGAL_APP_ID, "CFE_EVS_ResetFilter", @@ -560,6 +564,7 @@ void Test_IllegalAppID(void) /* Test resetting all filters using an illegal application ID */ UT_InitData(); + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); UT_Report(__FILE__, __LINE__, CFE_EVS_ResetAllFilters() == CFE_EVS_APP_ILLEGAL_APP_ID, "CFE_EVS_ResetAllFilters", @@ -567,14 +572,13 @@ void Test_IllegalAppID(void) /* Test application cleanup using an illegal application ID */ UT_InitData(); + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); UT_Report(__FILE__, __LINE__, - CFE_EVS_CleanUpApp(CFE_PLATFORM_ES_MAX_APPLICATIONS + 1) == + CFE_EVS_CleanUpApp(0) == CFE_EVS_APP_ILLEGAL_APP_ID, "CFE_EVS_CleanUpApp", "Illegal app ID"); - /* Return application ID to valid value */ - UT_SetAppID(0); } /* @@ -583,6 +587,12 @@ void Test_IllegalAppID(void) void Test_UnregisteredApp(void) { CFE_TIME_SysTime_t time = {0, 0}; + EVS_AppData_t *AppDataPtr; + uint32 AppID; + + /* Get a local ref to the "current" AppData table entry */ + EVS_GetCurrentContext(&AppDataPtr, &AppID); + #ifdef UT_VERBOSE UT_Text("Begin Test Unregistered App\n"); @@ -624,7 +634,7 @@ void Test_UnregisteredApp(void) UT_Report(__FILE__, __LINE__, CFE_EVS_SendEventWithAppID(0, CFE_EVS_EventType_INFORMATION, - 0, + AppID, "NULL") == CFE_EVS_APP_NOT_REGISTERED, "CFE_EVS_SendEventWithAppID", "App not registered"); @@ -642,7 +652,7 @@ void Test_UnregisteredApp(void) /* Test application cleanup using an unregistered application */ UT_InitData(); UT_Report(__FILE__, __LINE__, - CFE_EVS_CleanUpApp(0) == CFE_SUCCESS, + CFE_EVS_CleanUpApp(AppID) == CFE_SUCCESS, "CFE_EVS_CleanUpApp", "App not registered"); @@ -663,13 +673,18 @@ void Test_FilterRegistration(void) CFE_EVS_BinFilter_t filter[CFE_PLATFORM_EVS_MAX_EVENT_FILTERS + 1]; EVS_BinFilter_t *FilterPtr = NULL; - uint32 AppID; + EVS_AppData_t *AppDataPtr; + uint32 AppID; CFE_TIME_SysTime_t time = {0, 0}; + /* Get a local ref to the "current" AppData table entry */ + EVS_GetCurrentContext(&AppDataPtr, &AppID); + #ifdef UT_VERBOSE UT_Text("Begin Test Filter Registration\n"); #endif + CFE_EVS_GlobalData.EVS_AppID = AppID; CFE_EVS_GlobalData.EVS_TlmPkt.Payload.MessageFormatMode = CFE_EVS_MsgFormat_LONG; /* Test filter registration using an invalid filter option */ @@ -754,9 +769,8 @@ void Test_FilterRegistration(void) /* Send last information message, which should cause filtering to lock */ UT_InitData(); - CFE_ES_GetAppID(&AppID); FilterPtr = EVS_FindEventID(0, - (EVS_BinFilter_t *) CFE_EVS_GlobalData.AppData[AppID].BinFilters); + (EVS_BinFilter_t *) AppDataPtr->BinFilters); FilterPtr->Count = CFE_EVS_MAX_FILTER_COUNT - 1; UT_Report(__FILE__, __LINE__, CFE_EVS_SendEvent(0, @@ -794,20 +808,18 @@ void Test_FilterRegistration(void) * application */ UT_InitData(); - CFE_EVS_GlobalData.AppData[0].RegisterFlag = true; - CFE_EVS_GlobalData.AppData[0].ActiveFlag = false; + AppDataPtr->ActiveFlag = false; UT_Report(__FILE__, __LINE__, CFE_EVS_SendEventWithAppID(0, CFE_EVS_EventType_INFORMATION, - 0, + AppID, "NULL") == CFE_SUCCESS, "CFE_EVS_SendEventWithAppID", "Application registered and filtered"); /* Test sending a timed event to a registered, filtered application */ UT_InitData(); - CFE_EVS_GlobalData.AppData[0].RegisterFlag = true; - CFE_EVS_GlobalData.AppData[0].ActiveFlag = false; + AppDataPtr->ActiveFlag = false; UT_Report(__FILE__, __LINE__, CFE_EVS_SendTimedEvent(time, CFE_EVS_EventType_INFORMATION, @@ -904,6 +916,11 @@ void Test_Format(void) .SnapshotOffset = offsetof(CFE_EVS_ShortEventTlm_t, Payload.PacketID), .SnapshotSize = sizeof(CapturedMsg) }; + EVS_AppData_t *AppDataPtr; + uint32 AppID; + + /* Get a local ref to the "current" AppData table entry */ + EVS_GetCurrentContext(&AppDataPtr, &AppID); #ifdef UT_VERBOSE UT_Text("Begin Test Format\n"); @@ -995,7 +1012,7 @@ void Test_Format(void) "Long format check (SendTimedEvent)"); EventID[1] = CapturedMsg.EventID; memset(&CapturedMsg, 0xFF, sizeof(CapturedMsg)); - CFE_EVS_SendEventWithAppID(0, CFE_EVS_EventType_INFORMATION, 0, + CFE_EVS_SendEventWithAppID(0, CFE_EVS_EventType_INFORMATION, AppID, "Long format check (SendEventWithAppID)"); UT_Report(__FILE__, __LINE__, EventID[0] == 0 && EventID[1] == 0 && @@ -1027,7 +1044,7 @@ void Test_Format(void) UT_Report(__FILE__, __LINE__, CFE_EVS_SendEventWithAppID(0, CFE_EVS_EventType_INFORMATION, - 0, + AppID, "%s", long_msg) == CFE_SUCCESS, "CFE_EVS_SendEventWithAppID", "Sent info message with > maximum string length"); @@ -1519,7 +1536,7 @@ void Test_BadAppCmd(void) CFE_EVS_AppNameCmd_t appnamecmd; CFE_EVS_AppNameEventIDMaskCmd_t appmaskcmd; CFE_EVS_AppNameEventIDCmd_t appcmdcmd; - uint32 TestAppID; + uint32 TestAppIndex; #ifdef UT_VERBOSE UT_Text("Begin Test Bad App Command\n"); @@ -1669,8 +1686,11 @@ void Test_BadAppCmd(void) strncpy((char *) appcmdcmd.Payload.AppName, "illegal_id", sizeof(appcmdcmd.Payload.AppName)); - TestAppID = CFE_PLATFORM_ES_MAX_APPLICATIONS + 1; - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + /* + * Generate an illegal AppID error when looking up the UT appID (first call), + * but still allow the EVS AppID to send an event successfully (second call). + */ + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); UT_EVS_DoDispatchCheckEvents(&appbitcmd, sizeof(appbitcmd), UT_TPID_CFE_EVS_CMD_DISABLE_APP_EVENT_TYPE_CC, &UT_EVS_EventBuf); @@ -1682,7 +1702,7 @@ void Test_BadAppCmd(void) /* Test enabling application event types with an illegal application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); UT_EVS_DoDispatchCheckEvents(&appbitcmd, sizeof(appbitcmd), UT_TPID_CFE_EVS_CMD_ENABLE_APP_EVENT_TYPE_CC, &UT_EVS_EventBuf); @@ -1693,7 +1713,7 @@ void Test_BadAppCmd(void) /* Test disabling application events with an illegal application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_DISABLE_APP_EVENTS_CC, &UT_EVS_EventBuf); @@ -1704,7 +1724,7 @@ void Test_BadAppCmd(void) /* Test enabling application events with an illegal application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_ENABLE_APP_EVENTS_CC, &UT_EVS_EventBuf); @@ -1717,7 +1737,7 @@ void Test_BadAppCmd(void) * application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_RESET_APP_COUNTER_CC, &UT_EVS_EventBuf); @@ -1729,7 +1749,7 @@ void Test_BadAppCmd(void) /* Test adding the event filter with an illegal application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); UT_EVS_DoDispatchCheckEvents(&appmaskcmd, sizeof(appmaskcmd), UT_TPID_CFE_EVS_CMD_ADD_EVENT_FILTER_CC, &UT_EVS_EventBuf); @@ -1740,7 +1760,7 @@ void Test_BadAppCmd(void) /* Test deleting the event filter with an illegal application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); UT_EVS_DoDispatchCheckEvents(&appcmdcmd, sizeof(appcmdcmd), UT_TPID_CFE_EVS_CMD_DELETE_EVENT_FILTER_CC, &UT_EVS_EventBuf); @@ -1751,7 +1771,7 @@ void Test_BadAppCmd(void) /* Test setting the filter mask with an illegal application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); UT_EVS_DoDispatchCheckEvents(&appmaskcmd, sizeof(appmaskcmd), UT_TPID_CFE_EVS_CMD_SET_FILTER_CC, &UT_EVS_EventBuf); @@ -1762,7 +1782,7 @@ void Test_BadAppCmd(void) /* Test resetting the filter with an illegal application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); UT_EVS_DoDispatchCheckEvents(&appcmdcmd, sizeof(appcmdcmd), UT_TPID_CFE_EVS_CMD_RESET_FILTER_CC, &UT_EVS_EventBuf); @@ -1773,7 +1793,7 @@ void Test_BadAppCmd(void) /* Test resetting all filters with an illegal application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_RESET_ALL_FILTERS_CC, &UT_EVS_EventBuf); @@ -1786,8 +1806,8 @@ void Test_BadAppCmd(void) * application ID */ UT_InitData(); - TestAppID = CFE_PLATFORM_ES_MAX_APPLICATIONS - 1; - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + TestAppIndex = 2; + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &TestAppIndex, sizeof(TestAppIndex), false); strncpy((char *) appbitcmd.Payload.AppName, "unregistered_app", sizeof(appbitcmd.Payload.AppName)); strncpy((char *) appnamecmd.Payload.AppName, "unregistered_app", @@ -1809,7 +1829,7 @@ void Test_BadAppCmd(void) * application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &TestAppIndex, sizeof(TestAppIndex), false); UT_EVS_DoDispatchCheckEvents(&appbitcmd, sizeof(appbitcmd), UT_TPID_CFE_EVS_CMD_ENABLE_APP_EVENT_TYPE_CC, &UT_EVS_EventBuf); @@ -1821,7 +1841,7 @@ void Test_BadAppCmd(void) /* Test disabling application events with an unregistered application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &TestAppIndex, sizeof(TestAppIndex), false); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_DISABLE_APP_EVENTS_CC, &UT_EVS_EventBuf); @@ -1832,7 +1852,7 @@ void Test_BadAppCmd(void) /* Test enabling application events with an unregistered application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &TestAppIndex, sizeof(TestAppIndex), false); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_ENABLE_APP_EVENTS_CC, &UT_EVS_EventBuf); @@ -1845,7 +1865,7 @@ void Test_BadAppCmd(void) * application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &TestAppIndex, sizeof(TestAppIndex), false); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_RESET_APP_COUNTER_CC, &UT_EVS_EventBuf); @@ -1857,7 +1877,7 @@ void Test_BadAppCmd(void) /* Test adding the event filter with an unregistered application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &TestAppIndex, sizeof(TestAppIndex), false); UT_EVS_DoDispatchCheckEvents(&appmaskcmd, sizeof(appmaskcmd), UT_TPID_CFE_EVS_CMD_ADD_EVENT_FILTER_CC, &UT_EVS_EventBuf); @@ -1868,7 +1888,7 @@ void Test_BadAppCmd(void) /* Test deleting the event filter with an unregistered application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &TestAppIndex, sizeof(TestAppIndex), false); UT_EVS_DoDispatchCheckEvents(&appcmdcmd, sizeof(appcmdcmd), UT_TPID_CFE_EVS_CMD_DELETE_EVENT_FILTER_CC, &UT_EVS_EventBuf); @@ -1879,7 +1899,7 @@ void Test_BadAppCmd(void) /* Test setting the filter mask with an unregistered application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &TestAppIndex, sizeof(TestAppIndex), false); UT_EVS_DoDispatchCheckEvents(&appmaskcmd, sizeof(appmaskcmd), UT_TPID_CFE_EVS_CMD_SET_FILTER_CC, &UT_EVS_EventBuf); @@ -1890,7 +1910,7 @@ void Test_BadAppCmd(void) /* Test resetting the filter with an unregistered application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &TestAppIndex, sizeof(TestAppIndex), false); UT_EVS_DoDispatchCheckEvents(&appcmdcmd, sizeof(appcmdcmd), UT_TPID_CFE_EVS_CMD_RESET_FILTER_CC, &UT_EVS_EventBuf); @@ -1901,7 +1921,7 @@ void Test_BadAppCmd(void) /* Test resetting all filters with an unregistered application ID */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_ES_GetAppIDByName), &TestAppID, sizeof(TestAppID), false); + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &TestAppIndex, sizeof(TestAppIndex), false); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_RESET_ALL_FILTERS_CC, &UT_EVS_EventBuf); @@ -2657,30 +2677,25 @@ void Test_Misc(void) CFE_EVS_WriteLogDataFile_t writelogdatacmd; } PktBuf; - uint32 AppID; + uint32 AppID; + EVS_AppData_t *AppDataPtr; int i; - char AppName; char msg[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH + 2]; UT_SoftwareBusSnapshot_Entry_t HK_SnapshotData = { .MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_EVS_HK_TLM_MID) }; + EVS_GetCurrentContext(&AppDataPtr, &AppID); #ifdef UT_VERBOSE UT_Text("Begin Test Miscellaneous\n"); #endif memset(&PktBuf, 0, sizeof(PktBuf)); + CFE_EVS_GlobalData.EVS_AppID = AppID; CFE_EVS_GlobalData.EVS_TlmPkt.Payload.MessageFormatMode = CFE_EVS_MsgFormat_LONG; - /* Test null application ID input to exercise EVS_GetApplicationInfo */ - UT_InitData(); - UT_Report(__FILE__, __LINE__, - EVS_GetApplicationInfo(NULL, &AppName) == CFE_ES_ERR_BUFFER, - "EVS_GetApplicationInfo", - "Get application info with null application ID"); - /* Test successful log data file write */ UT_InitData(); UT_EVS_DoDispatchCheckEvents(&PktBuf.writelogdatacmd, sizeof(PktBuf.writelogdatacmd), @@ -2743,25 +2758,18 @@ void Test_Misc(void) "CFE_EVS_ReportHousekeepingCmd", "Housekeeping report - successful (log disabled)"); - /* Test null application name to exercise EVS_GetApplicationInfo */ - UT_InitData(); - UT_Report(__FILE__, __LINE__, - EVS_GetApplicationInfo(&AppID, NULL) == CFE_ES_ERR_BUFFER, - "EVS_GetApplicationInfo", - "Get application info with null application name"); - /* Test sending a packet with the message counter and the event counter * at their maximum allowed values */ UT_InitData(); CFE_EVS_GlobalData.EVS_TlmPkt.Payload.MessageSendCounter = CFE_EVS_MAX_EVENT_SEND_COUNT; - CFE_EVS_GlobalData.AppData[0].EventCount = CFE_EVS_MAX_EVENT_SEND_COUNT; + AppDataPtr->EventCount = CFE_EVS_MAX_EVENT_SEND_COUNT; EVS_SendEvent(0, 0, "Max Event Count"); UT_Report(__FILE__, __LINE__, CFE_EVS_GlobalData.EVS_TlmPkt.Payload.MessageSendCounter == CFE_EVS_MAX_EVENT_SEND_COUNT && - CFE_EVS_GlobalData.AppData[0].EventCount == + AppDataPtr->EventCount == CFE_EVS_MAX_EVENT_SEND_COUNT, "EVS_SendEvent", "Maximum message count and event count"); @@ -2778,8 +2786,9 @@ void Test_Misc(void) msg[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH] = '\0'; CFE_EVS_GlobalData.EVS_TlmPkt.Payload.MessageTruncCounter = 0; - CFE_EVS_GlobalData.AppData[CFE_EVS_GlobalData.EVS_AppID].ActiveFlag = true; - CFE_EVS_GlobalData.AppData[CFE_EVS_GlobalData.EVS_AppID].EventTypesActiveFlag |= + AppDataPtr->RegisterFlag = true; + AppDataPtr->ActiveFlag = true; + AppDataPtr->EventTypesActiveFlag |= CFE_EVS_INFORMATION_BIT; EVS_SendEvent(0, CFE_EVS_EventType_INFORMATION, msg); UT_Report(__FILE__, __LINE__, From dfe8abce8925fe147d8b650a9c2012c11266eea6 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 2 Sep 2020 11:18:36 -0400 Subject: [PATCH 3/6] Fix #797, Update FS subsystem for abstract IDs Minor fixup for use of IDs when logging --- fsw/cfe-core/src/fs/cfe_fs_priv.c | 8 ++++---- fsw/cfe-core/unit-test/fs_UT.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fsw/cfe-core/src/fs/cfe_fs_priv.c b/fsw/cfe-core/src/fs/cfe_fs_priv.c index b4d59ac66..0ec0415f3 100644 --- a/fsw/cfe-core/src/fs/cfe_fs_priv.c +++ b/fsw/cfe-core/src/fs/cfe_fs_priv.c @@ -99,8 +99,8 @@ void CFE_FS_LockSharedData(const char *FunctionName) { CFE_ES_GetAppID(&AppId); - CFE_ES_WriteToSysLog("FS SharedData Mutex Take Err Stat=0x%x,App=%d,Function=%s\n", - (unsigned int)Status,(int)AppId,FunctionName); + CFE_ES_WriteToSysLog("FS SharedData Mutex Take Err Stat=0x%x,App=%lu,Function=%s\n", + (unsigned int)Status,CFE_ES_ResourceID_ToInteger(AppId),FunctionName); }/* end if */ @@ -130,8 +130,8 @@ void CFE_FS_UnlockSharedData(const char *FunctionName) if (Status != OS_SUCCESS) { CFE_ES_GetAppID(&AppId); - CFE_ES_WriteToSysLog("FS SharedData Mutex Give Err Stat=0x%x,App=%d,Function=%s\n", - (unsigned int)Status,(int)AppId,FunctionName); + CFE_ES_WriteToSysLog("FS SharedData Mutex Give Err Stat=0x%x,App=%lu,Function=%s\n", + (unsigned int)Status,CFE_ES_ResourceID_ToInteger(AppId),FunctionName); }/* end if */ return; diff --git a/fsw/cfe-core/unit-test/fs_UT.c b/fsw/cfe-core/unit-test/fs_UT.c index 16411ea32..83080eb02 100644 --- a/fsw/cfe-core/unit-test/fs_UT.c +++ b/fsw/cfe-core/unit-test/fs_UT.c @@ -43,8 +43,8 @@ const char *FS_SYSLOG_MSGS[] = { NULL, - "FS SharedData Mutex Take Err Stat=0x%x,App=%d,Function=%s\n", - "FS SharedData Mutex Give Err Stat=0x%x,App=%d,Function=%s\n" + "FS SharedData Mutex Take Err Stat=0x%x,App=%lu,Function=%s\n", + "FS SharedData Mutex Give Err Stat=0x%x,App=%lu,Function=%s\n" }; /* From 4d901e812aed146de7d60ff8f473767eaa015de5 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 2 Sep 2020 11:19:40 -0400 Subject: [PATCH 4/6] Fix #797, Update SB subsystem for abstract IDs Change SB to get its task ID from ES rather than getting it directly from OSAL. Update syslog calls to use the ES-supplied conversion to integer rather than direct cast. --- fsw/cfe-core/src/sb/cfe_sb_api.c | 57 +++++++++++++++++-------------- fsw/cfe-core/src/sb/cfe_sb_priv.c | 28 ++++++++++----- fsw/cfe-core/unit-test/sb_UT.c | 35 +++++++++++++------ 3 files changed, 76 insertions(+), 44 deletions(-) diff --git a/fsw/cfe-core/src/sb/cfe_sb_api.c b/fsw/cfe-core/src/sb/cfe_sb_api.c index 1902aeb30..fbd2c49d4 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_api.c +++ b/fsw/cfe-core/src/sb/cfe_sb_api.c @@ -92,6 +92,9 @@ int32 CFE_SB_CreatePipe(CFE_SB_PipeId_t *PipeIdPtr, uint16 Depth, const char * /* get callers AppId */ CFE_ES_GetAppID(&AppId); + /* get callers TaskId */ + CFE_ES_GetTaskID(&TskId); + /* get callers name */ CFE_ES_GetAppName(AppName, AppId, OS_MAX_API_NAME); @@ -101,8 +104,6 @@ int32 CFE_SB_CreatePipe(CFE_SB_PipeId_t *PipeIdPtr, uint16 Depth, const char * /* take semaphore to prevent a task switch during this call */ CFE_SB_LockSharedData(__func__,__LINE__); - TskId = OS_TaskGetId(); - /* set user's pipe id value to 'invalid' for error cases below */ if(PipeIdPtr != NULL){ *PipeIdPtr = CFE_SB_INVALID_PIPE; @@ -272,12 +273,12 @@ int32 CFE_SB_DeletePipeFull(CFE_SB_PipeId_t PipeId,uint32 AppId) CFE_SB_DestinationD_t *DestPtr = NULL; char FullName[(OS_MAX_API_NAME * 2)]; + /* get TaskId of caller for events */ + CFE_ES_GetTaskID(&TskId); + /* take semaphore to prevent a task switch during this call */ CFE_SB_LockSharedData(__func__,__LINE__); - /* get TaskId of caller for events */ - TskId = OS_TaskGetId(); - /* check input parameter */ PipeTblIdx = CFE_SB_GetPipeIdx(PipeId); RtnFromVal = CFE_SB_ValidatePipeId(PipeId); @@ -400,12 +401,17 @@ int32 CFE_SB_SetPipeOpts(CFE_SB_PipeId_t PipeId, uint8 Opts) return Status; } + /* get TaskId of caller for events */ + Status = CFE_ES_GetTaskID(&TskId); + if(Status != CFE_SUCCESS) + { + /* shouldn't happen... */ + return Status; + } + /* take semaphore to prevent a task switch during this call */ CFE_SB_LockSharedData(__func__,__LINE__); - /* get TaskId of caller for events */ - TskId = OS_TaskGetId(); - /* check input parameter */ PipeTblIdx = CFE_SB_GetPipeIdx(PipeId); RtnFromVal = CFE_SB_ValidatePipeId(PipeId); @@ -459,6 +465,9 @@ int32 CFE_SB_GetPipeOpts(CFE_SB_PipeId_t PipeId, uint8 *OptsPtr) uint32 TskId = 0; char FullName[(OS_MAX_API_NAME * 2)]; + /* get TaskId of caller for events */ + CFE_ES_GetTaskID(&TskId); + if(OptsPtr == NULL) { CFE_SB.HKTlmMsg.Payload.PipeOptsErrorCounter++; @@ -471,9 +480,6 @@ int32 CFE_SB_GetPipeOpts(CFE_SB_PipeId_t PipeId, uint8 *OptsPtr) /* take semaphore to prevent a task switch during this call */ CFE_SB_LockSharedData(__func__,__LINE__); - /* get TaskId of caller for events */ - TskId = OS_TaskGetId(); - /* check input parameter */ PipeTblIdx = CFE_SB_GetPipeIdx(PipeId); RtnFromVal = CFE_SB_ValidatePipeId(PipeId); @@ -506,12 +512,14 @@ int32 CFE_SB_GetPipeName(char *PipeNameBuf, size_t PipeNameSize, CFE_SB_PipeId_t char FullName[(OS_MAX_API_NAME * 2)]; if(PipeNameBuf == NULL || PipeNameSize == 0) { + CFE_ES_GetTaskID(&TskId); CFE_EVS_SendEventWithAppID(CFE_SB_GETPIPENAME_NULL_PTR_EID, CFE_EVS_EventType_ERROR, CFE_SB.AppId, "Pipe Name Error:NullPtr,Requestor %s", CFE_SB_GetAppTskName(TskId,FullName)); Status = CFE_SB_BAD_ARGUMENT; } else if(PipeId >= CFE_PLATFORM_SB_MAX_PIPES){ + CFE_ES_GetTaskID(&TskId); CFE_EVS_SendEventWithAppID(CFE_SB_GETPIPENAME_ID_ERR_EID, CFE_EVS_EventType_ERROR, CFE_SB.AppId, "Pipe Id Error:Bad Argument,Id=%d,Requestor %s", PipeId,CFE_SB_GetAppTskName(TskId,FullName)); @@ -556,6 +564,9 @@ int32 CFE_SB_GetPipeIdByName(CFE_SB_PipeId_t *PipeIdPtr, const char *PipeName) uint32 QueueId = 0; char FullName[(OS_MAX_API_NAME * 2)]; + /* get TaskId of caller for events */ + CFE_ES_GetTaskID(&TskId); + if(PipeName == NULL || PipeIdPtr == NULL) { CFE_SB.HKTlmMsg.Payload.GetPipeIdByNameErrorCounter++; @@ -568,9 +579,6 @@ int32 CFE_SB_GetPipeIdByName(CFE_SB_PipeId_t *PipeIdPtr, const char *PipeName) } else { - /* get TaskId of caller for events */ - TskId = OS_TaskGetId(); - RtnFromVal = OS_QueueGetIdByName(&QueueId, PipeName); if(RtnFromVal == OS_SUCCESS) @@ -726,15 +734,15 @@ int32 CFE_SB_SubscribeFull(CFE_SB_MsgId_t MsgId, CFE_SB_GetPipeName(PipeName, sizeof(PipeName), PipeId); - /* take semaphore to prevent a task switch during this call */ - CFE_SB_LockSharedData(__func__,__LINE__); - - /* get task id for events */ - TskId = OS_TaskGetId(); - /* get the callers Application Id */ CFE_ES_GetAppID(&AppId); + /* get TaskId of caller for events */ + CFE_ES_GetTaskID(&TskId); + + /* take semaphore to prevent a task switch during this call */ + CFE_SB_LockSharedData(__func__,__LINE__); + /* check that the pipe has been created */ PipeIdx = CFE_SB_GetPipeIdx(PipeId); if(PipeIdx==CFE_SB_INVALID_PIPE){ @@ -1015,13 +1023,12 @@ int32 CFE_SB_UnsubscribeFull(CFE_SB_MsgId_t MsgId,CFE_SB_PipeId_t PipeId, CFE_SB_DestinationD_t *DestPtr = NULL; char FullName[(OS_MAX_API_NAME * 2)]; + /* get TaskId of caller for events */ + CFE_ES_GetTaskID(&TskId); /* take semaphore to prevent a task switch during this call */ CFE_SB_LockSharedData(__func__,__LINE__); - /* get task id for events */ - TskId = OS_TaskGetId(); - /* check that the pipe has been created */ PipeIdx = CFE_SB_GetPipeIdx(PipeId); if(PipeIdx==CFE_SB_INVALID_PIPE){ @@ -1190,7 +1197,7 @@ int32 CFE_SB_SendMsgFull(CFE_SB_Msg_t *MsgPtr, SBSndErr.EvtsToSnd = 0; /* get task id for events and Sender Info*/ - TskId = OS_TaskGetId(); + CFE_ES_GetTaskID(&TskId); /* check input parameter */ if(MsgPtr == NULL){ @@ -1514,7 +1521,7 @@ int32 CFE_SB_RcvMsg(CFE_SB_MsgPtr_t *BufPtr, char FullName[(OS_MAX_API_NAME * 2)]; /* get task id for events */ - TskId = OS_TaskGetId(); + CFE_ES_GetTaskID(&TskId); /* Check input parameters */ if((BufPtr == NULL)||(TimeOut < (-1))){ diff --git a/fsw/cfe-core/src/sb/cfe_sb_priv.c b/fsw/cfe-core/src/sb/cfe_sb_priv.c index 1ae509dce..0cad3d4f4 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_priv.c +++ b/fsw/cfe-core/src/sb/cfe_sb_priv.c @@ -288,8 +288,8 @@ void CFE_SB_LockSharedData(const char *FuncName, int32 LineNumber){ CFE_ES_GetAppID(&AppId); - CFE_ES_WriteToSysLog("SB SharedData Mutex Take Err Stat=0x%x,App=%d,Func=%s,Line=%d\n", - (unsigned int)Status,(int)AppId,FuncName,(int)LineNumber); + CFE_ES_WriteToSysLog("SB SharedData Mutex Take Err Stat=0x%x,App=%lu,Func=%s,Line=%d\n", + (unsigned int)Status,CFE_ES_ResourceID_ToInteger(AppId),FuncName,(int)LineNumber); }/* end if */ @@ -323,8 +323,8 @@ void CFE_SB_UnlockSharedData(const char *FuncName, int32 LineNumber){ CFE_ES_GetAppID(&AppId); - CFE_ES_WriteToSysLog("SB SharedData Mutex Give Err Stat=0x%x,App=%d,Func=%s,Line=%d\n", - (unsigned int)Status,(int)AppId,FuncName,(int)LineNumber); + CFE_ES_WriteToSysLog("SB SharedData Mutex Give Err Stat=0x%x,App=%lu,Func=%s,Line=%d\n", + (unsigned int)Status,CFE_ES_ResourceID_ToInteger(AppId),FuncName,(int)LineNumber); }/* end if */ @@ -673,17 +673,22 @@ char *CFE_SB_GetAppTskName(uint32 TaskId,char *FullName){ */ uint32 CFE_SB_RequestToSendEvent(uint32 TaskId, uint32 Bit){ - OS_ConvertToArrayIndex(TaskId, &TaskId); + uint32 Indx; + + if (CFE_ES_TaskID_ToIndex(TaskId, &Indx) != CFE_SUCCESS) + { + return CFE_SB_DENIED; + } /* if bit is set... */ - if(CFE_TST(CFE_SB.StopRecurseFlags[TaskId],Bit)) + if(CFE_TST(CFE_SB.StopRecurseFlags[Indx],Bit)) { return CFE_SB_DENIED; }else{ - CFE_SET(CFE_SB.StopRecurseFlags[TaskId],Bit); + CFE_SET(CFE_SB.StopRecurseFlags[Indx],Bit); return CFE_SB_GRANTED; }/* end if */ @@ -705,10 +710,15 @@ uint32 CFE_SB_RequestToSendEvent(uint32 TaskId, uint32 Bit){ */ void CFE_SB_FinishSendEvent(uint32 TaskId, uint32 Bit){ - OS_ConvertToArrayIndex(TaskId, &TaskId); + uint32 Indx; + + if (CFE_ES_TaskID_ToIndex(TaskId, &Indx) != CFE_SUCCESS) + { + return; + } /* clear the bit so the task may send this event again */ - CFE_CLR(CFE_SB.StopRecurseFlags[TaskId],Bit); + CFE_CLR(CFE_SB.StopRecurseFlags[Indx],Bit); }/* end CFE_SB_RequestToSendEvent */ diff --git a/fsw/cfe-core/unit-test/sb_UT.c b/fsw/cfe-core/unit-test/sb_UT.c index 905520a6c..043261298 100644 --- a/fsw/cfe-core/unit-test/sb_UT.c +++ b/fsw/cfe-core/unit-test/sb_UT.c @@ -112,6 +112,15 @@ const CFE_SB_MsgId_t SB_UT_ALTERNATE_INVALID_MID = CFE_SB_MSGID_WRAP_VALUE(CFE_P const CFE_SB_MsgId_t SB_UT_BARE_CMD_MID3 = CFE_SB_MSGID_WRAP_VALUE(0x1003); const CFE_SB_MsgId_t SB_UT_BARE_TLM_MID3 = CFE_SB_MSGID_WRAP_VALUE(0x0003); +/* + * Helper function to "corrupt" a resource ID value in a consistent/predicatble way, + * which can also be un-done easily. + */ +uint32 UT_SB_ResourceID_Modify(uint32 InitialID, int32 Modifier) +{ + uint32 NewValue = InitialID + Modifier; + return (NewValue); +} /* ** Functions @@ -1731,7 +1740,7 @@ void Test_DeletePipe_InvalidPipeOwner(void) RealOwner = CFE_SB.PipeTbl[PipedId].AppId; /* Choose a value that is sure not to be owner */ - CFE_SB.PipeTbl[PipedId].AppId = RealOwner + 1; + CFE_SB.PipeTbl[PipedId].AppId = UT_SB_ResourceID_Modify(RealOwner, 1); ASSERT_EQ(CFE_SB_DeletePipe(PipedId), CFE_SB_BAD_ARGUMENT); EVTCNT(2); @@ -2391,7 +2400,7 @@ void Test_Subscribe_InvalidPipeOwner(void) CFE_SB_PipeId_t PipeId; CFE_SB_MsgId_t MsgId = SB_UT_TLM_MID; uint16 PipeDepth = 10; - int32 RealOwner; + uint32 RealOwner; SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "TestPipe")); @@ -2399,7 +2408,7 @@ void Test_Subscribe_InvalidPipeOwner(void) RealOwner = CFE_SB.PipeTbl[PipeId].AppId; /* Choose a value that is sure not to be owner */ - CFE_SB.PipeTbl[PipeId].AppId = RealOwner + 1; + CFE_SB.PipeTbl[PipeId].AppId = UT_SB_ResourceID_Modify(RealOwner, 1); CFE_SB_Subscribe(MsgId, PipeId); EVTCNT(3); @@ -2583,7 +2592,7 @@ void Test_Unsubscribe_InvalidPipeOwner(void) RealOwner = CFE_SB.PipeTbl[PipeId].AppId; /* Choose a value that is sure not be owner */ - CFE_SB.PipeTbl[PipeId].AppId = RealOwner + 1; + CFE_SB.PipeTbl[PipeId].AppId = UT_SB_ResourceID_Modify(RealOwner, 1); ASSERT_EQ(CFE_SB_Unsubscribe(MsgId, PipeId), CFE_SB_BAD_ARGUMENT); EVTCNT(4); @@ -3533,6 +3542,9 @@ void Test_CleanupApp_API(void) CFE_SB_PipeId_t PipeId; CFE_SB_ZeroCopyHandle_t ZeroCpyBufHndl = 0; uint16 PipeDepth = 50; + uint32 AppID; + + CFE_ES_GetAppID(&AppID); SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "TestPipe")); CFE_SB_ZeroCopyGetPtr(PipeDepth, &ZeroCpyBufHndl); @@ -3540,17 +3552,17 @@ void Test_CleanupApp_API(void) /* Set second application ID to provide complete branch path coverage */ CFE_SB.PipeTbl[1].InUse = CFE_SB_IN_USE; - CFE_SB.PipeTbl[1].AppId = 1; + CFE_SB.PipeTbl[1].AppId = AppID; ASSERT_TRUE(CFE_SB.ZeroCopyTail != NULL); /* Attempt with a bad application ID first in order to get full branch path * coverage in CFE_SB_ZeroCopyReleaseAppId */ - CFE_SB_CleanUpApp(1); + CFE_SB_CleanUpApp(0); /* Attempt again with a valid application ID */ - CFE_SB_CleanUpApp(0); + CFE_SB_CleanUpApp(AppID); ASSERT_TRUE(CFE_SB.ZeroCopyTail == NULL); @@ -3901,13 +3913,14 @@ void Test_OS_MutSem_ErrLogic(void) */ void Test_ReqToSendEvent_ErrLogic(void) { - uint32 TaskId = 13; + uint32 TaskId; uint32 Bit = 5; /* Clear task bits, then call function, which should set the bit for * the specified task */ - CFE_SB.StopRecurseFlags[TaskId] = 0x0000; + CFE_ES_GetTaskID(&TaskId); + CFE_SB.StopRecurseFlags[0] = 0x0000; ASSERT_EQ(CFE_SB_RequestToSendEvent(TaskId, Bit), CFE_SB_GRANTED); /* Call the function a second time; the result should indicate that the @@ -3992,13 +4005,15 @@ void Test_CFE_SB_BadPipeInfo(void) CFE_SB_PipeId_t PipeId; uint16 PipeDepth = 10; CFE_SB_Qos_t CFE_SB_Default_Qos; + uint32 AppID; SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "TestPipe1")); /* Set the pipe ID to an erroneous value and attempt to delete the pipe */ CFE_SB.PipeTbl[0].PipeId = 1; CFE_SB.PipeTbl[0].InUse = 1; - ASSERT_EQ(CFE_SB_DeletePipeFull(0, 0), CFE_SB_BAD_ARGUMENT); + CFE_ES_GetAppID(&AppID); + ASSERT_EQ(CFE_SB_DeletePipeFull(0, AppID), CFE_SB_BAD_ARGUMENT); EVTCNT(2); From aa8d7a91f71262827285bb7eec31dd68c272acd8 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 2 Sep 2020 11:20:56 -0400 Subject: [PATCH 5/6] Fix #797, Update TBL subsystem for abstract IDs Update TBL to use the new ES-supplied ID manipulations. Update all syslog calls to convert to integer using ES wrapper. --- fsw/cfe-core/src/tbl/cfe_tbl_api.c | 66 ++++++++++-------- fsw/cfe-core/src/tbl/cfe_tbl_internal.c | 46 ++++-------- fsw/cfe-core/src/tbl/cfe_tbl_internal.h | 21 ------ fsw/cfe-core/unit-test/tbl_UT.c | 93 ++++++++++++------------- 4 files changed, 91 insertions(+), 135 deletions(-) diff --git a/fsw/cfe-core/src/tbl/cfe_tbl_api.c b/fsw/cfe-core/src/tbl/cfe_tbl_api.c index 299129766..84aee00d8 100644 --- a/fsw/cfe-core/src/tbl/cfe_tbl_api.c +++ b/fsw/cfe-core/src/tbl/cfe_tbl_api.c @@ -67,7 +67,7 @@ int32 CFE_TBL_Register( CFE_TBL_Handle_t *TblHandlePtr, CFE_TBL_Handle_t AccessIndex; /* Check to make sure calling application is legit */ - Status = CFE_TBL_ValidateAppID(&ThisAppId); + Status = CFE_ES_GetAppID(&ThisAppId); if (Status == CFE_SUCCESS) { @@ -147,7 +147,8 @@ int32 CFE_TBL_Register( CFE_TBL_Handle_t *TblHandlePtr, } else /* Application ID was invalid */ { - CFE_ES_WriteToSysLog("CFE_TBL:Register-Bad AppId(%d)\n", (int)ThisAppId); + CFE_ES_WriteToSysLog("CFE_TBL:Register-Bad AppId(%lu)\n", + CFE_ES_ResourceID_ToInteger(ThisAppId)); } /* If input parameters appear acceptable, register the table */ @@ -208,8 +209,9 @@ int32 CFE_TBL_Register( CFE_TBL_Handle_t *TblHandlePtr, { Status = CFE_TBL_ERR_DUPLICATE_NOT_OWNED; - CFE_ES_WriteToSysLog("CFE_TBL:Register-App(%d) Registering Duplicate Table '%s' owned by App(%d)\n", - (int)ThisAppId, TblName, (int)RegRecPtr->OwnerAppId); + CFE_ES_WriteToSysLog("CFE_TBL:Register-App(%lu) Registering Duplicate Table '%s' owned by App(%lu)\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), TblName, + CFE_ES_ResourceID_ToInteger(RegRecPtr->OwnerAppId)); } } else /* Table not already in registry */ @@ -515,7 +517,7 @@ int32 CFE_TBL_Share( CFE_TBL_Handle_t *TblHandlePtr, char AppName[OS_MAX_API_NAME] = {"UNKNOWN"}; /* Get a valid Application ID for calling App */ - Status = CFE_TBL_ValidateAppID(&ThisAppId); + Status = CFE_ES_GetAppID(&ThisAppId); if (Status == CFE_SUCCESS) { @@ -579,7 +581,8 @@ int32 CFE_TBL_Share( CFE_TBL_Handle_t *TblHandlePtr, } else /* Application ID was invalid */ { - CFE_ES_WriteToSysLog("CFE_TBL:Share-Bad AppId(%d)\n", (int)ThisAppId); + CFE_ES_WriteToSysLog("CFE_TBL:Share-Bad AppId(%lu)\n", + CFE_ES_ResourceID_ToInteger(ThisAppId)); } /* On Error conditions, notify ground of screw up */ @@ -629,7 +632,7 @@ int32 CFE_TBL_Unregister ( CFE_TBL_Handle_t TblHandle ) /* NOTE: Allocated memory is freed when all Access Links have been */ /* removed. This allows Applications to continue to use the */ /* data until they acknowledge that the table has been removed. */ - RegRecPtr->OwnerAppId = (uint32)CFE_TBL_NOT_OWNED; + RegRecPtr->OwnerAppId = CFE_TBL_NOT_OWNED; /* Remove Table Name */ RegRecPtr->Name[0] = '\0'; @@ -642,8 +645,8 @@ int32 CFE_TBL_Unregister ( CFE_TBL_Handle_t TblHandle ) } else { - CFE_ES_WriteToSysLog("CFE_TBL:Unregister-App(%d) does not have access to Tbl Handle=%d\n", - (int)ThisAppId, (int)TblHandle); + CFE_ES_WriteToSysLog("CFE_TBL:Unregister-App(%lu) does not have access to Tbl Handle=%d\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), (int)TblHandle); } /* On Error conditions, notify ground of screw up */ @@ -925,13 +928,14 @@ int32 CFE_TBL_Update( CFE_TBL_Handle_t TblHandle ) if (Status != CFE_SUCCESS) { - CFE_ES_WriteToSysLog("CFE_TBL:Update-App(%d) fail to update Tbl '%s' (Stat=0x%08X)\n", - (int)ThisAppId, RegRecPtr->Name, (unsigned int)Status); + CFE_ES_WriteToSysLog("CFE_TBL:Update-App(%lu) fail to update Tbl '%s' (Stat=0x%08X)\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), RegRecPtr->Name, (unsigned int)Status); } } else { - CFE_ES_WriteToSysLog("CFE_TBL:Update-App(%d) does not have access to Tbl Handle=%d\n", (int)ThisAppId, (int)TblHandle); + CFE_ES_WriteToSysLog("CFE_TBL:Update-App(%lu) does not have access to Tbl Handle=%d\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), (int)TblHandle); } if (Status != CFE_TBL_ERR_BAD_APP_ID) @@ -993,7 +997,7 @@ int32 CFE_TBL_GetAddress( void **TblPtr, *TblPtr = NULL; /* Validate the calling application's AppID */ - Status = CFE_TBL_ValidateAppID(&ThisAppId); + Status = CFE_ES_GetAppID(&ThisAppId); if (Status == CFE_SUCCESS) { @@ -1005,7 +1009,8 @@ int32 CFE_TBL_GetAddress( void **TblPtr, } else { - CFE_ES_WriteToSysLog("CFE_TBL:GetAddress-Bad AppId=%d\n", (int)ThisAppId); + CFE_ES_WriteToSysLog("CFE_TBL:GetAddress-Bad AppId=%lu\n", + CFE_ES_ResourceID_ToInteger(ThisAppId)); } return Status; @@ -1036,8 +1041,8 @@ int32 CFE_TBL_ReleaseAddress( CFE_TBL_Handle_t TblHandle ) } else { - CFE_ES_WriteToSysLog("CFE_TBL:ReleaseAddress-App(%d) does not have access to Tbl Handle=%d\n", - (int)ThisAppId, (int)TblHandle); + CFE_ES_WriteToSysLog("CFE_TBL:ReleaseAddress-App(%lu) does not have access to Tbl Handle=%u\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), (unsigned int)TblHandle); } return Status; @@ -1061,7 +1066,7 @@ int32 CFE_TBL_GetAddresses( void **TblPtrs[], } /* Validate the calling application's AppID */ - Status = CFE_TBL_ValidateAppID(&ThisAppId); + Status = CFE_ES_GetAppID(&ThisAppId); if (Status == CFE_SUCCESS) { @@ -1082,7 +1087,8 @@ int32 CFE_TBL_GetAddresses( void **TblPtrs[], } else { - CFE_ES_WriteToSysLog("CFE_TBL:GetAddresses-Bad AppId=%d\n", (int)ThisAppId); + CFE_ES_WriteToSysLog("CFE_TBL:GetAddresses-Bad AppId=%lu\n", + CFE_ES_ResourceID_ToInteger(ThisAppId)); } return Status; @@ -1184,8 +1190,8 @@ int32 CFE_TBL_Validate( CFE_TBL_Handle_t TblHandle ) if (Status > CFE_SUCCESS) { - CFE_ES_WriteToSysLog("CFE_TBL:Validate-App(%u) Validation func return code invalid (Stat=0x%08X) for '%s'\n", - (unsigned int)CFE_TBL_TaskData.TableTaskAppId, (unsigned int)Status, RegRecPtr->Name); + CFE_ES_WriteToSysLog("CFE_TBL:Validate-App(%lu) Validation func return code invalid (Stat=0x%08X) for '%s'\n", + CFE_ES_ResourceID_ToInteger(CFE_TBL_TaskData.TableTaskAppId), (unsigned int)Status, RegRecPtr->Name); } } @@ -1233,8 +1239,8 @@ int32 CFE_TBL_Validate( CFE_TBL_Handle_t TblHandle ) if (Status > CFE_SUCCESS) { - CFE_ES_WriteToSysLog("CFE_TBL:Validate-App(%u) Validation func return code invalid (Stat=0x%08X) for '%s'\n", - (unsigned int)CFE_TBL_TaskData.TableTaskAppId, (unsigned int)Status, RegRecPtr->Name); + CFE_ES_WriteToSysLog("CFE_TBL:Validate-App(%lu) Validation func return code invalid (Stat=0x%08X) for '%s'\n", + CFE_ES_ResourceID_ToInteger(CFE_TBL_TaskData.TableTaskAppId), (unsigned int)Status, RegRecPtr->Name); } } @@ -1256,8 +1262,8 @@ int32 CFE_TBL_Validate( CFE_TBL_Handle_t TblHandle ) } else { - CFE_ES_WriteToSysLog("CFE_TBL:Validate-App(%d) does not have access to Tbl Handle=%d\n", - (int)ThisAppId, (int)TblHandle); + CFE_ES_WriteToSysLog("CFE_TBL:Validate-App(%lu) does not have access to Tbl Handle=%d\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), (int)TblHandle); } return Status; @@ -1356,8 +1362,8 @@ int32 CFE_TBL_GetStatus( CFE_TBL_Handle_t TblHandle ) } else { - CFE_ES_WriteToSysLog("CFE_TBL:GetStatus-App(%d) does not have access to Tbl Handle=%d\n", - (int)ThisAppId, (int)TblHandle); + CFE_ES_WriteToSysLog("CFE_TBL:GetStatus-App(%lu) does not have access to Tbl Handle=%d\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), (int)TblHandle); } return Status; @@ -1519,8 +1525,8 @@ int32 CFE_TBL_Modified( CFE_TBL_Handle_t TblHandle ) } else { - CFE_ES_WriteToSysLog("CFE_TBL:Modified-App(%d) does not have access to Tbl Handle=%d\n", - (int)ThisAppId, (int)TblHandle); + CFE_ES_WriteToSysLog("CFE_TBL:Modified-App(%lu) does not have access to Tbl Handle=%d\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), (int)TblHandle); } @@ -1558,8 +1564,8 @@ int32 CFE_TBL_NotifyByMessage(CFE_TBL_Handle_t TblHandle, CFE_SB_MsgId_t MsgId, else { Status = CFE_TBL_ERR_NO_ACCESS; - CFE_ES_WriteToSysLog("CFE_TBL:NotifyByMsg-App(%d) does not own Tbl Handle=%d\n", - (int)ThisAppId, (int)TblHandle); + CFE_ES_WriteToSysLog("CFE_TBL:NotifyByMsg-App(%lu) does not own Tbl Handle=%d\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), (int)TblHandle); } } diff --git a/fsw/cfe-core/src/tbl/cfe_tbl_internal.c b/fsw/cfe-core/src/tbl/cfe_tbl_internal.c index c69179452..81f1e2d0a 100644 --- a/fsw/cfe-core/src/tbl/cfe_tbl_internal.c +++ b/fsw/cfe-core/src/tbl/cfe_tbl_internal.c @@ -80,7 +80,7 @@ int32 CFE_TBL_EarlyInit (void) /* Initialize the Table Access Descriptors */ for (i=0; i= CFE_PLATFORM_ES_MAX_APPLICATIONS) - { - return CFE_TBL_ERR_BAD_APP_ID; - } - } - - return Status; -} /* End of CFE_TBL_ValidateAppID() */ - /******************************************************************* ** ** CFE_TBL_ValidateAccess @@ -363,7 +341,7 @@ int32 CFE_TBL_ValidateAccess(CFE_TBL_Handle_t TblHandle, uint32 *AppIdPtr) int32 Status; /* Check to make sure App ID is legit */ - Status = CFE_TBL_ValidateAppID(AppIdPtr); + Status = CFE_ES_GetAppID(AppIdPtr); if (Status != CFE_SUCCESS) { @@ -535,8 +513,8 @@ int32 CFE_TBL_GetAddressInternal(void **TblPtr, CFE_TBL_Handle_t TblHandle, uint { Status = CFE_TBL_ERR_UNREGISTERED; - CFE_ES_WriteToSysLog("CFE_TBL:GetAddressInternal-App(%d) attempt to access unowned Tbl Handle=%d\n", - (int)ThisAppId, (int)TblHandle); + CFE_ES_WriteToSysLog("CFE_TBL:GetAddressInternal-App(%lu) attempt to access unowned Tbl Handle=%d\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), (int)TblHandle); } else /* Table Registry Entry is valid */ { @@ -559,14 +537,14 @@ int32 CFE_TBL_GetAddressInternal(void **TblPtr, CFE_TBL_Handle_t TblHandle, uint } else { - CFE_ES_WriteToSysLog("CFE_TBL:GetAddressInternal-App(%d) does not have access to Tbl Handle=%d\n", - (int)ThisAppId, (int)TblHandle); + CFE_ES_WriteToSysLog("CFE_TBL:GetAddressInternal-App(%lu) does not have access to Tbl Handle=%d\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), (int)TblHandle); } } else { - CFE_ES_WriteToSysLog("CFE_TBL:GetAddressInternal-App(%d) using invalid Tbl Handle=%d\n", - (int)ThisAppId, (int)TblHandle); + CFE_ES_WriteToSysLog("CFE_TBL:GetAddressInternal-App(%lu) using invalid Tbl Handle=%d\n", + CFE_ES_ResourceID_ToInteger(ThisAppId), (int)TblHandle); } return Status; @@ -830,8 +808,8 @@ int32 CFE_TBL_GetWorkingBuffer(CFE_TBL_LoadBuff_t **WorkingBufferPtr, { Status = CFE_TBL_ERR_NO_BUFFER_AVAIL; - CFE_ES_WriteToSysLog("CFE_TBL:GetWorkingBuffer-Inactive Dbl Buff Locked for '%s' by AppId=%d\n", - RegRecPtr->Name, (int)CFE_TBL_TaskData.Handles[AccessIterator].AppId); + CFE_ES_WriteToSysLog("CFE_TBL:GetWorkingBuffer-Inactive Dbl Buff Locked for '%s' by AppId=%lu\n", + RegRecPtr->Name, CFE_ES_ResourceID_ToInteger(CFE_TBL_TaskData.Handles[AccessIterator].AppId)); } /* Move to next access descriptor in linked list */ @@ -1417,7 +1395,7 @@ int32 CFE_TBL_CleanUpApp(uint32 AppId) /* NOTE: Allocated memory is freed when all Access Links have been */ /* removed. This allows Applications to continue to use the */ /* data until they acknowledge that the table has been removed. */ - RegRecPtr->OwnerAppId = (uint32)CFE_TBL_NOT_OWNED; + RegRecPtr->OwnerAppId = CFE_TBL_NOT_OWNED; /* Remove Table Name */ RegRecPtr->Name[0] = '\0'; @@ -1428,7 +1406,7 @@ int32 CFE_TBL_CleanUpApp(uint32 AppId) /* memory buffers are set free as well. */ CFE_TBL_RemoveAccessLink(i); - CFE_TBL_TaskData.Handles[i].AppId = (uint32)CFE_TBL_NOT_OWNED; + CFE_TBL_TaskData.Handles[i].AppId = CFE_TBL_NOT_OWNED; } } diff --git a/fsw/cfe-core/src/tbl/cfe_tbl_internal.h b/fsw/cfe-core/src/tbl/cfe_tbl_internal.h index ebcd5c83e..9a1177b75 100644 --- a/fsw/cfe-core/src/tbl/cfe_tbl_internal.h +++ b/fsw/cfe-core/src/tbl/cfe_tbl_internal.h @@ -47,27 +47,6 @@ /***************************** Function Prototypes **********************************/ -/*****************************************************************************/ -/** -** \brief Validates the Application ID associated with calling Application -** -** \par Description -** Validates Application ID of calling App. Validation -** consists of ensuring the AppID is between zero and -** #CFE_PLATFORM_ES_MAX_APPLICATIONS. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \param[in, out] AppIdPtr Pointer to value that will hold AppID on return. *AppIdPtr is the AppID as obtained from #CFE_ES_GetAppID -** -** -** \retval #CFE_SUCCESS \copydoc CFE_SUCCESS -** \retval #CFE_TBL_ERR_BAD_APP_ID \copydoc CFE_TBL_ERR_BAD_APP_ID -** -******************************************************************************/ -int32 CFE_TBL_ValidateAppID(uint32 *AppIdPtr); - /*****************************************************************************/ /** ** \brief Validates specified handle to ensure legality diff --git a/fsw/cfe-core/unit-test/tbl_UT.c b/fsw/cfe-core/unit-test/tbl_UT.c index e24cbf645..015c762aa 100644 --- a/fsw/cfe-core/unit-test/tbl_UT.c +++ b/fsw/cfe-core/unit-test/tbl_UT.c @@ -55,6 +55,10 @@ CFE_TBL_Handle_t App2TblHandle1; CFE_TBL_Handle_t App2TblHandle2; CFE_TBL_Handle_t ArrayOfHandles[2]; +static const uint32 UT_TBL_APPID_1 = 1; +static const uint32 UT_TBL_APPID_2 = 2; +static const uint32 UT_TBL_APPID_10 = 10; + void *Tbl1Ptr = NULL; void *Tbl2Ptr = NULL; void **ArrayOfPtrsToTblPtrs[2]; @@ -149,7 +153,7 @@ void UT_InitializeTableRegistryNames() { snprintf(CFE_TBL_TaskData.Registry[i].Name, CFE_TBL_MAX_FULL_NAME_LEN, "%d", i); - CFE_TBL_TaskData.Registry[i].OwnerAppId = 0; + CFE_TBL_TaskData.Registry[i].OwnerAppId = UT_TBL_APPID_2; } } @@ -168,7 +172,7 @@ void UT_ResetTableRegistry(void) /* Initialize the table access descriptors */ for (i = 0; i < CFE_PLATFORM_TBL_MAX_NUM_HANDLES; i++) { - CFE_TBL_TaskData.Handles[i].AppId = CFE_ES_ERR_APPID; + CFE_TBL_TaskData.Handles[i].AppId = CFE_TBL_NOT_OWNED; CFE_TBL_TaskData.Handles[i].RegIndex = 0; CFE_TBL_TaskData.Handles[i].PrevLink = CFE_TBL_END_OF_LIST; CFE_TBL_TaskData.Handles[i].NextLink = CFE_TBL_END_OF_LIST; @@ -1047,6 +1051,10 @@ void Test_CFE_TBL_GetHkData(void) int32 NumLoadPendingIndex = CFE_PLATFORM_TBL_MAX_NUM_TABLES - 1; int32 FreeSharedBuffIndex = CFE_PLATFORM_TBL_MAX_SIMULTANEOUS_LOADS - 1; int32 ValTableIndex = CFE_PLATFORM_TBL_MAX_NUM_VALIDATIONS - 1; + uint32 AppID; + + /* Get the AppID being used for UT */ + CFE_ES_GetAppID(&AppID); #ifdef UT_VERBOSE UT_Text("Begin Test Get Housekeeping Data\n"); @@ -1060,7 +1068,7 @@ void Test_CFE_TBL_GetHkData(void) /* Test raising the count of load pending tables */ UT_InitData(); CFE_TBL_TaskData.Registry[NumLoadPendingIndex].LoadPending = true; - CFE_TBL_TaskData.Registry[NumLoadPendingIndex].OwnerAppId = 0; + CFE_TBL_TaskData.Registry[NumLoadPendingIndex].OwnerAppId = AppID; CFE_TBL_GetHkData(); UT_Report(__FILE__, __LINE__, CFE_TBL_TaskData.HkPacket.Payload.NumLoadPending == 1, @@ -1140,6 +1148,11 @@ void Test_CFE_TBL_DumpRegCmd(void) { int q; CFE_TBL_DumpRegistry_t DumpRegCmd; + uint32 AppID; + + /* Get the AppID being used for UT */ + CFE_ES_GetAppID(&AppID); + #ifdef UT_VERBOSE UT_Text("Begin Test Dump Register Command\n"); @@ -1175,7 +1188,7 @@ void Test_CFE_TBL_DumpRegCmd(void) */ UT_InitData(); UT_SetDeferredRetcode(UT_KEY(CFE_FS_WriteHeader), 10, sizeof(CFE_FS_Header_t)); - CFE_TBL_TaskData.Registry[0].OwnerAppId = 0; + CFE_TBL_TaskData.Registry[0].OwnerAppId = AppID; CFE_TBL_TaskData.Registry[0].HeadOfAccessList = CFE_TBL_END_OF_LIST; CFE_TBL_TaskData.Registry[1].OwnerAppId = CFE_TBL_NOT_OWNED; CFE_TBL_TaskData.Registry[0].LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS + 1; @@ -1233,6 +1246,9 @@ void Test_CFE_TBL_DumpCmd(void) uint8 *BuffPtr = &Buff; CFE_TBL_LoadBuff_t Load = {0}; CFE_TBL_Dump_t DumpCmd; + uint32 AppID; + + CFE_ES_GetAppID(&AppID); #ifdef UT_VERBOSE UT_Text("Begin Test Dump Command\n"); @@ -1258,7 +1274,7 @@ void Test_CFE_TBL_DumpCmd(void) strncpy(CFE_TBL_TaskData.Registry[2].Name, "DumpCmdTest", CFE_TBL_MAX_FULL_NAME_LEN); CFE_TBL_TaskData.Registry[2].Name[CFE_TBL_MAX_FULL_NAME_LEN - 1] = '\0'; - CFE_TBL_TaskData.Registry[2].OwnerAppId = 0; + CFE_TBL_TaskData.Registry[2].OwnerAppId = AppID; strncpy(DumpCmd.Payload.TableName, CFE_TBL_TaskData.Registry[2].Name, sizeof(DumpCmd.Payload.TableName)); DumpCmd.Payload.ActiveTableFlag = CFE_TBL_BufferSelect_ACTIVE; @@ -1410,6 +1426,9 @@ void Test_CFE_TBL_LoadCmd(void) CFE_FS_Header_t StdFileHeader; CFE_TBL_LoadBuff_t BufferPtr = CFE_TBL_TaskData.LoadBuffs[0]; CFE_TBL_Load_t LoadCmd; + uint32 AppID; + + CFE_ES_GetAppID(&AppID); #ifdef UT_VERBOSE UT_Text("Begin Test Load Command\n"); @@ -1455,7 +1474,7 @@ void Test_CFE_TBL_LoadCmd(void) /* Test attempt to load a dump only table */ UT_InitData(); - CFE_TBL_TaskData.Registry[0].OwnerAppId = 0; + CFE_TBL_TaskData.Registry[0].OwnerAppId = AppID; UT_SetReadBuffer(&TblFileHeader, sizeof(TblFileHeader)); UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader)); CFE_TBL_TaskData.Registry[0].Size = sizeof(CFE_TBL_File_Hdr_t) + 1; @@ -1468,7 +1487,7 @@ void Test_CFE_TBL_LoadCmd(void) /* Test attempt to load a table with a load already pending */ UT_InitData(); - CFE_TBL_TaskData.Registry[0].OwnerAppId = 0; + CFE_TBL_TaskData.Registry[0].OwnerAppId = AppID; UT_SetReadBuffer(&TblFileHeader, sizeof(TblFileHeader)); UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader)); CFE_TBL_TaskData.Registry[0].Size = sizeof(CFE_TBL_File_Hdr_t) + 1; @@ -1774,7 +1793,7 @@ void Test_CFE_TBL_ApiInit(void) UT_SetAppID(1); UT_ResetCDS(); CFE_TBL_EarlyInit(); - CFE_TBL_TaskData.TableTaskAppId = 10; + CFE_TBL_TaskData.TableTaskAppId = UT_TBL_APPID_10; } /* @@ -1811,20 +1830,6 @@ void Test_CFE_TBL_Register(void) "CFE_TBL_Register", "Invalid application ID"); - /* Test response to an application ID larger than the maximum allowed */ - UT_InitData(); - UT_SetAppID(CFE_PLATFORM_ES_MAX_APPLICATIONS); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_SUCCESS); - RtnCode = CFE_TBL_Register(&TblHandle1, "UT_Table1", - sizeof(UT_Table1_t), - CFE_TBL_OPT_DEFAULT, NULL); - EventsCorrect = (UT_EventIsInHistory(CFE_TBL_REGISTER_ERR_EID) == true && - UT_GetNumEventsSent() == 1); - UT_Report(__FILE__, __LINE__, - RtnCode == CFE_TBL_ERR_BAD_APP_ID && EventsCorrect, - "CFE_TBL_Register", - "Application ID > maximum allowed"); - /* Test response to a table name longer than the maximum allowed */ UT_InitData(); @@ -2533,18 +2538,6 @@ void Test_CFE_TBL_Share(void) "CFE_TBL_Share", "Invalid application ID"); - /* Test response to an application ID larger than the maximum allowed */ - UT_InitData(); - UT_SetAppID(CFE_PLATFORM_ES_MAX_APPLICATIONS); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_SUCCESS); - RtnCode = CFE_TBL_Share(&App2TblHandle1, "ut_cfe_tbl.UT_Table2"); - EventsCorrect = (UT_EventIsInHistory(CFE_TBL_SHARE_ERR_EID) == true && - UT_GetNumEventsSent() == 1); - UT_Report(__FILE__, __LINE__, - RtnCode == CFE_TBL_ERR_BAD_APP_ID && EventsCorrect, - "CFE_TBL_Share", - "Application ID > maximum allowed"); - /* Test response when table name is not in the registry */ UT_InitData(); UT_SetAppID(1); @@ -3246,7 +3239,7 @@ void Test_CFE_TBL_GetAddresses(void) RtnCode = CFE_TBL_GetAddresses(ArrayOfPtrsToTblPtrs, 2, ArrayOfHandles); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, - RtnCode == CFE_TBL_ERR_BAD_APP_ID && EventsCorrect, + RtnCode == CFE_TBL_ERR_NO_ACCESS && EventsCorrect, "CFE_TBL_Validate", "Attempt to get addresses of tables that application is not " "allowed to see"); @@ -3297,7 +3290,7 @@ void Test_CFE_TBL_Validate(void) RtnCode = CFE_TBL_Validate(App1TblHandle1); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, - RtnCode == CFE_TBL_ERR_BAD_APP_ID && EventsCorrect, + RtnCode == CFE_TBL_ERR_NO_ACCESS && EventsCorrect, "CFE_TBL_Validate", "Attempt to validate table that application is not allowed " "to see"); @@ -3593,7 +3586,7 @@ void Test_CFE_TBL_Manage(void) AccessDescPtr = &CFE_TBL_TaskData.Handles[App1TblHandle2]; RegRecPtr = &CFE_TBL_TaskData.Registry[AccessDescPtr->RegIndex]; CFE_TBL_TaskData.Handles[AccessIterator].NextLink = RegRecPtr->HeadOfAccessList; - CFE_TBL_TaskData.Handles[AccessIterator].AppId = 2; + CFE_TBL_TaskData.Handles[AccessIterator].AppId = UT_TBL_APPID_2; RegRecPtr->HeadOfAccessList = AccessIterator; CFE_TBL_TaskData.Handles[AccessIterator].BufferIndex = 1; CFE_TBL_TaskData.Handles[AccessIterator].LockFlag = true; @@ -3787,7 +3780,7 @@ void Test_CFE_TBL_Update(void) RtnCode = CFE_TBL_Update(App1TblHandle1); EventsCorrect = (UT_GetNumEventsSent() == 1); UT_Report(__FILE__, __LINE__, - RtnCode == CFE_TBL_ERR_BAD_APP_ID && EventsCorrect, + RtnCode == CFE_TBL_ERR_NO_ACCESS && EventsCorrect, "CFE_TBL_Update", "Bad application ID"); } @@ -3812,7 +3805,7 @@ void Test_CFE_TBL_GetStatus(void) RtnCode = CFE_TBL_GetStatus(App1TblHandle1); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, - RtnCode == CFE_TBL_ERR_BAD_APP_ID && EventsCorrect, + RtnCode == CFE_TBL_ERR_NO_ACCESS && EventsCorrect, "CFE_TBL_GetStatus", "Attempt to get status on a table that the application is not " "allowed to see"); @@ -3825,7 +3818,7 @@ void Test_CFE_TBL_GetStatus(void) RtnCode = CFE_TBL_DumpToBuffer(App1TblHandle1); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, - RtnCode == CFE_TBL_ERR_BAD_APP_ID && EventsCorrect, + RtnCode == CFE_TBL_ERR_NO_ACCESS && EventsCorrect, "CFE_TBL_GetStatus", "Attempt to to dump the buffer on a table that the application " "is not allowed to see"); @@ -3998,7 +3991,7 @@ void Test_CFE_TBL_TblMod(void) AccessDescPtr = &CFE_TBL_TaskData.Handles[App1TblHandle1]; RegRecPtr = &CFE_TBL_TaskData.Registry[AccessDescPtr->RegIndex]; CFE_TBL_TaskData.Handles[AccessIterator].NextLink = RegRecPtr->HeadOfAccessList; - CFE_TBL_TaskData.Handles[AccessIterator].AppId = 2; + CFE_TBL_TaskData.Handles[AccessIterator].AppId = UT_TBL_APPID_2; RegRecPtr->HeadOfAccessList = AccessIterator; /* Configure for successful file read to initialize table */ @@ -4068,7 +4061,7 @@ void Test_CFE_TBL_TblMod(void) void Test_CFE_TBL_Internal(void) { int32 RtnCode; - bool EventsCorrect; + bool EventsCorrect; CFE_TBL_LoadBuff_t *WorkingBufferPtr; CFE_TBL_RegistryRec_t *RegRecPtr; CFE_TBL_AccessDescriptor_t *AccessDescPtr; @@ -4892,11 +4885,11 @@ void Test_CFE_TBL_Internal(void) CFE_TBL_TaskData.DumpControlBlocks[3].RegRecPtr = RegRecPtr; RegRecPtr->LoadInProgress = 1; CFE_TBL_TaskData.LoadBuffs[1].Taken = true; - CFE_TBL_CleanUpApp(1); + CFE_TBL_CleanUpApp(UT_TBL_APPID_1); UT_Report(__FILE__, __LINE__, CFE_TBL_TaskData.DumpControlBlocks[3].State == CFE_TBL_DUMP_FREE && - RegRecPtr->OwnerAppId == (uint32) CFE_TBL_NOT_OWNED && + RegRecPtr->OwnerAppId == CFE_TBL_NOT_OWNED && CFE_TBL_TaskData.LoadBuffs[RegRecPtr->LoadInProgress].Taken == false && RegRecPtr->LoadInProgress == CFE_TBL_NO_LOAD_IN_PROGRESS, @@ -4947,8 +4940,8 @@ void Test_CFE_TBL_Internal(void) * the table task application ID */ UT_InitData(); - CFE_TBL_TaskData.TableTaskAppId = 1; - RtnCode = CFE_TBL_CheckAccessRights(App2TblHandle1, 1); + CFE_TBL_TaskData.TableTaskAppId = UT_TBL_APPID_1; + RtnCode = CFE_TBL_CheckAccessRights(App2TblHandle1, UT_TBL_APPID_1); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, RtnCode == CFE_SUCCESS && EventsCorrect, @@ -5057,17 +5050,17 @@ void Test_CFE_TBL_Internal(void) UT_InitData(); UT_SetAppID(1); UT_SetForceFail(UT_KEY(CFE_ES_PutPoolBuf), -1); - CFE_TBL_TaskData.Handles[0].AppId = 1; + CFE_TBL_TaskData.Handles[0].AppId = UT_TBL_APPID_1; AccessDescPtr = &CFE_TBL_TaskData.Handles[App1TblHandle2]; RegRecPtr = &CFE_TBL_TaskData.Registry[AccessDescPtr->RegIndex]; - RegRecPtr->OwnerAppId = -1; + RegRecPtr->OwnerAppId = CFE_TBL_NOT_OWNED; CFE_TBL_TaskData.DumpControlBlocks[3].State = CFE_TBL_DUMP_PENDING; CFE_TBL_TaskData.DumpControlBlocks[3].RegRecPtr = RegRecPtr; - CFE_TBL_CleanUpApp(1); + CFE_TBL_CleanUpApp(UT_TBL_APPID_1); UT_Report(__FILE__, __LINE__, CFE_TBL_TaskData.DumpControlBlocks[3].State == CFE_TBL_DUMP_PENDING && - RegRecPtr->OwnerAppId == (uint32) CFE_TBL_NOT_OWNED , + RegRecPtr->OwnerAppId == CFE_TBL_NOT_OWNED, "CFE_TBL_CleanUpApp", "Execute clean up - no dumped tables to delete, application " "doesn't own table"); From 7f0c08eee0e4d88443fe85bb903898cc2385daac Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 2 Sep 2020 11:22:48 -0400 Subject: [PATCH 6/6] Fix #797, Update TIME subsystem for abstract IDs Update the TIME subsystem to use the new ES-supplied ID abstractions. Do not use AppID directly as array index when registering sync callbacks, use the ES-supplied conversion to array index before accessing local table. Also update logging to use ES-supplied conversion --- fsw/cfe-core/src/time/cfe_time_api.c | 22 ++++++++++++++++------ fsw/cfe-core/src/time/cfe_time_utils.c | 11 ++++++++--- fsw/cfe-core/unit-test/time_UT.c | 21 ++++++++++++--------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/fsw/cfe-core/src/time/cfe_time_api.c b/fsw/cfe-core/src/time/cfe_time_api.c index 4f03f65c7..af4b0471d 100644 --- a/fsw/cfe-core/src/time/cfe_time_api.c +++ b/fsw/cfe-core/src/time/cfe_time_api.c @@ -819,22 +819,27 @@ int32 CFE_TIME_RegisterSynchCallback(CFE_TIME_SynchCallbackPtr_t CallbackFuncPt { int32 Status; uint32 AppId; + uint32 AppIndex; Status = CFE_ES_GetAppID(&AppId); + if (Status == CFE_SUCCESS) + { + Status = CFE_ES_AppID_ToIndex(AppId, &AppIndex); + } if (Status != CFE_SUCCESS) { /* Called from an invalid context */ return Status; } - if (AppId >= (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0])) || - CFE_TIME_TaskData.SynchCallback[AppId].Ptr != NULL) + if (AppIndex >= (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0])) || + CFE_TIME_TaskData.SynchCallback[AppIndex].Ptr != NULL) { Status = CFE_TIME_TOO_MANY_SYNCH_CALLBACKS; } else { - CFE_TIME_TaskData.SynchCallback[AppId].Ptr = CallbackFuncPtr; + CFE_TIME_TaskData.SynchCallback[AppIndex].Ptr = CallbackFuncPtr; } return Status; @@ -848,22 +853,27 @@ int32 CFE_TIME_UnregisterSynchCallback(CFE_TIME_SynchCallbackPtr_t CallbackFunc { int32 Status; uint32 AppId; + uint32 AppIndex; Status = CFE_ES_GetAppID(&AppId); + if (Status == CFE_SUCCESS) + { + Status = CFE_ES_AppID_ToIndex(AppId, &AppIndex); + } if (Status != CFE_SUCCESS) { /* Called from an invalid context */ return Status; } - if (AppId >= (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0])) || - CFE_TIME_TaskData.SynchCallback[AppId].Ptr != CallbackFuncPtr) + if (AppIndex >= (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0])) || + CFE_TIME_TaskData.SynchCallback[AppIndex].Ptr != CallbackFuncPtr) { Status = CFE_TIME_CALLBACK_NOT_REGISTERED; } else { - CFE_TIME_TaskData.SynchCallback[AppId].Ptr = NULL; + CFE_TIME_TaskData.SynchCallback[AppIndex].Ptr = NULL; } return Status; diff --git a/fsw/cfe-core/src/time/cfe_time_utils.c b/fsw/cfe-core/src/time/cfe_time_utils.c index 6e2cb80d7..64e6b92a7 100644 --- a/fsw/cfe-core/src/time/cfe_time_utils.c +++ b/fsw/cfe-core/src/time/cfe_time_utils.c @@ -1139,11 +1139,16 @@ void CFE_TIME_Set1HzAdj(CFE_TIME_SysTime_t NewAdjust, int16 Direction) int32 CFE_TIME_CleanUpApp(uint32 AppId) { int32 Status; + uint32 AppIndex; - if (AppId < (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0]))) + Status = CFE_ES_AppID_ToIndex(AppId, &AppIndex); + if (Status != CFE_SUCCESS) { - CFE_TIME_TaskData.SynchCallback[AppId].Ptr = NULL; - Status = CFE_SUCCESS; + /* Do nothing */ + } + else if (AppIndex < (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0]))) + { + CFE_TIME_TaskData.SynchCallback[AppIndex].Ptr = NULL; } else { diff --git a/fsw/cfe-core/unit-test/time_UT.c b/fsw/cfe-core/unit-test/time_UT.c index ca1e870d7..01554ec8e 100644 --- a/fsw/cfe-core/unit-test/time_UT.c +++ b/fsw/cfe-core/unit-test/time_UT.c @@ -3297,6 +3297,7 @@ void Test_CleanUpApp(void) uint16 i; uint16 Count; int32 Status = CFE_SUCCESS; + uint32 AppIndex; uint32 TestAppId; #ifdef UT_VERBOSE @@ -3313,16 +3314,19 @@ void Test_CleanUpApp(void) } /* Add callbacks for 3 apps into callback registry table */ - UT_SetAppID(1); + AppIndex = 1; + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &AppIndex, sizeof(AppIndex), false); CFE_TIME_RegisterSynchCallback(&ut_time_MyCallbackFunc); - UT_SetAppID(2); + AppIndex = 2; + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &AppIndex, sizeof(AppIndex), false); CFE_TIME_RegisterSynchCallback(&ut_time_MyCallbackFunc); - UT_SetAppID(3); + AppIndex = 3; + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &AppIndex, sizeof(AppIndex), false); CFE_TIME_RegisterSynchCallback(&ut_time_MyCallbackFunc); /* Clean up an app which did not have a callback */ - TestAppId = 4; - UT_SetAppID(TestAppId); + AppIndex = 4; + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &AppIndex, sizeof(AppIndex), false); Status = CFE_TIME_CleanUpApp(TestAppId); UT_Report(__FILE__, __LINE__, Status == CFE_SUCCESS, @@ -3345,8 +3349,8 @@ void Test_CleanUpApp(void) "No Sync Callback entry cleared"); /* Clean up an app which did have a callback */ - TestAppId = 2; - UT_SetAppID(TestAppId); + AppIndex = 2; + UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &AppIndex, sizeof(AppIndex), false); Status = CFE_TIME_CleanUpApp(TestAppId); UT_Report(__FILE__, __LINE__, Status == CFE_SUCCESS, @@ -3370,8 +3374,7 @@ void Test_CleanUpApp(void) /* Test response to a bad application ID - * This is effectively a no-op but here for coverage */ - UT_SetAppID(CFE_PLATFORM_ES_MAX_APPLICATIONS); - Status = CFE_TIME_CleanUpApp(CFE_PLATFORM_ES_MAX_APPLICATIONS); + Status = CFE_TIME_CleanUpApp(99999); UT_Report(__FILE__, __LINE__, Status == CFE_TIME_CALLBACK_NOT_REGISTERED, "CFE_TIME_CleanUpApp",