diff --git a/README.md b/README.md index 3d95fd2e8..c77258fdc 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,12 @@ The detailed cFE user's guide can be viewed at + ### Development Build: 6.8.0-rc1+dev129 - Rather than having a second pool implementation only for CDS, use the generic pool implementation. This also uses the abstract resource identifiers to identify CDS blocks, rather than a direct reference. diff --git a/fsw/cfe-core/src/es/cfe_es_api.c b/fsw/cfe-core/src/es/cfe_es_api.c index 0af796c15..22cbbe1e5 100644 --- a/fsw/cfe-core/src/es/cfe_es_api.c +++ b/fsw/cfe-core/src/es/cfe_es_api.c @@ -44,6 +44,7 @@ #include "cfe_es_cds.h" #include "cfe_es_cds_mempool.h" #include "cfe_es_task.h" +#include "cfe_es_resource.h" #include "cfe_psp.h" #include "cfe_es_log.h" @@ -184,19 +185,19 @@ int32 CFE_ES_RestartApp(CFE_ES_ResourceID_t AppID) if ( AppRecPtr->Type == CFE_ES_AppType_CORE ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_RestartApp: Cannot Restart a CORE Application: %s.\n", - AppRecPtr->StartParams.Name ); - ReturnCode = CFE_ES_ERR_APPID; + CFE_ES_AppRecordGetName(AppRecPtr)); + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } else if ( AppRecPtr->AppState != CFE_ES_AppState_RUNNING ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_RestartApp: Cannot Restart Application %s, It is not running.\n", - AppRecPtr->StartParams.Name); - ReturnCode = CFE_ES_ERR_APPID; + CFE_ES_AppRecordGetName(AppRecPtr)); + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } else { CFE_ES_SysLogWrite_Unsync("CFE_ES_RestartApp: Restart Application %s Initiated\n", - AppRecPtr->StartParams.Name); + CFE_ES_AppRecordGetName(AppRecPtr)); AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART; } @@ -204,7 +205,7 @@ int32 CFE_ES_RestartApp(CFE_ES_ResourceID_t AppID) } else /* App ID is not valid */ { - ReturnCode = CFE_ES_ERR_APPID; + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; CFE_ES_WriteToSysLog("CFE_ES_RestartApp: Invalid Application ID received, AppID = %lu\n", CFE_ES_ResourceID_ToInteger(AppID)); @@ -226,7 +227,7 @@ int32 CFE_ES_ReloadApp(CFE_ES_ResourceID_t AppID, const char *AppFileName) if ( AppRecPtr == NULL ) { - return CFE_ES_ERR_APPID; + return CFE_ES_ERR_RESOURCEID_NOT_VALID; } CFE_ES_LockSharedData(__func__,__LINE__); @@ -237,14 +238,14 @@ int32 CFE_ES_ReloadApp(CFE_ES_ResourceID_t AppID, const char *AppFileName) if ( AppRecPtr->Type == CFE_ES_AppType_CORE ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_DeleteApp: Cannot Reload a CORE Application: %s.\n", - AppRecPtr->StartParams.Name ); - ReturnCode = CFE_ES_ERR_APPID; + CFE_ES_AppRecordGetName(AppRecPtr)); + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } else if ( AppRecPtr->AppState != CFE_ES_AppState_RUNNING ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_ReloadApp: Cannot Reload Application %s, It is not running.\n", - AppRecPtr->StartParams.Name); - ReturnCode = CFE_ES_ERR_APPID; + CFE_ES_AppRecordGetName(AppRecPtr)); + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } else { @@ -254,15 +255,14 @@ int32 CFE_ES_ReloadApp(CFE_ES_ResourceID_t 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", - AppRecPtr->StartParams.Name, AppFileName); + CFE_ES_AppRecordGetName(AppRecPtr), 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", - AppRecPtr->StartParams.Name, - AppFileName); + CFE_ES_AppRecordGetName(AppRecPtr), AppFileName); ReturnCode = CFE_ES_FILE_IO_ERR; } } @@ -283,7 +283,7 @@ int32 CFE_ES_DeleteApp(CFE_ES_ResourceID_t AppID) if ( AppRecPtr == NULL ) { - return CFE_ES_ERR_APPID; + return CFE_ES_ERR_RESOURCEID_NOT_VALID; } CFE_ES_LockSharedData(__func__,__LINE__); @@ -294,19 +294,19 @@ int32 CFE_ES_DeleteApp(CFE_ES_ResourceID_t AppID) if ( AppRecPtr->Type == CFE_ES_AppType_CORE ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_DeleteApp: Cannot Delete a CORE Application: %s.\n", - AppRecPtr->StartParams.Name ); - ReturnCode = CFE_ES_ERR_APPID; + CFE_ES_AppRecordGetName(AppRecPtr)); + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } else if ( AppRecPtr->AppState != CFE_ES_AppState_RUNNING ) { CFE_ES_SysLogWrite_Unsync ("CFE_ES_DeleteApp: Cannot Delete Application %s, It is not running.\n", - AppRecPtr->StartParams.Name); - ReturnCode = CFE_ES_ERR_APPID; + CFE_ES_AppRecordGetName(AppRecPtr)); + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } else { CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteApp: Delete Application %s Initiated\n", - AppRecPtr->StartParams.Name); + CFE_ES_AppRecordGetName(AppRecPtr)); AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; } @@ -370,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", - AppRecPtr->StartParams.Name ); + CFE_ES_AppRecordGetName(AppRecPtr)); /* ** Unlock the ES Shared data before calling ResetCFE @@ -397,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", - AppRecPtr->StartParams.Name ); + CFE_ES_AppRecordGetName(AppRecPtr)); /* ** Unlock the ES Shared data before killing the main task @@ -417,7 +417,7 @@ void CFE_ES_ExitApp(uint32 ExitStatus) else { CFE_ES_SysLogWrite_Unsync ("CFE_ES_ExitApp, Cannot Exit CORE Application %s\n", - AppRecPtr->StartParams.Name ); + CFE_ES_AppRecordGetName(AppRecPtr)); } } @@ -425,7 +425,7 @@ void CFE_ES_ExitApp(uint32 ExitStatus) { CFE_ES_SysLogWrite_Unsync ("Application %s called CFE_ES_ExitApp\n", - AppRecPtr->StartParams.Name); + CFE_ES_AppRecordGetName(AppRecPtr)); AppRecPtr->AppState = CFE_ES_AppState_STOPPED; @@ -691,54 +691,127 @@ int32 CFE_ES_RegisterApp(void) */ int32 CFE_ES_GetAppIDByName(CFE_ES_ResourceID_t *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 = CFE_ES_RESOURCEID_UNDEFINED; + CFE_ES_AppRecord_t *AppRecPtr; + int32 Result; - CFE_ES_LockSharedData(__func__,__LINE__); + if (AppName == NULL || AppIdPtr == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } - /* - ** 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_AppRecordIsUsed(AppRecPtr) ) - { - if ( strncmp(AppName, (char *)AppRecPtr->StartParams.Name, OS_MAX_API_NAME) == 0 ) - { - *AppIdPtr = CFE_ES_AppRecordGetID(AppRecPtr); - Result = CFE_SUCCESS; - break; - } - } + CFE_ES_LockSharedData(__func__,__LINE__); - ++AppRecPtr; - } /* end for */ + AppRecPtr = CFE_ES_LocateAppRecordByName(AppName); + if (AppRecPtr == NULL) + { + /* + * ensure the output value is set to a safe value, + * in case the does not check the return code. + */ + Result = CFE_ES_ERR_NAME_NOT_FOUND; + *AppIdPtr = CFE_ES_RESOURCEID_UNDEFINED; + } + else + { + Result = CFE_SUCCESS; + *AppIdPtr = CFE_ES_AppRecordGetID(AppRecPtr); + } - CFE_ES_UnlockSharedData(__func__,__LINE__); + CFE_ES_UnlockSharedData(__func__,__LINE__); - return(Result); + return(Result); } /* End of CFE_ES_GetAppIDByName() */ +/* +** Function: CFE_ES_GetLibIDByName - See API and header file for details +*/ +int32 CFE_ES_GetLibIDByName(CFE_ES_ResourceID_t *LibIdPtr, const char *LibName) +{ + CFE_ES_LibRecord_t *LibRecPtr; + int32 Result; + + if (LibName == NULL || LibIdPtr == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } + + CFE_ES_LockSharedData(__func__,__LINE__); + + LibRecPtr = CFE_ES_LocateLibRecordByName(LibName); + if (LibRecPtr == NULL) + { + /* + * ensure the output value is set to a safe value, + * in case the does not check the return code. + */ + Result = CFE_ES_ERR_NAME_NOT_FOUND; + *LibIdPtr = CFE_ES_RESOURCEID_UNDEFINED; + } + else + { + Result = CFE_SUCCESS; + *LibIdPtr = CFE_ES_LibRecordGetID(LibRecPtr); + } + + CFE_ES_UnlockSharedData(__func__,__LINE__); + + return(Result); +} /* End of CFE_ES_GetLibIDByName() */ + +/* +** Function: CFE_ES_GetTaskIDByName - See API and header file for details +*/ +CFE_Status_t CFE_ES_GetTaskIDByName(CFE_ES_ResourceID_t *TaskIdPtr, const char *TaskName) +{ + osal_id_t OsalId; + int32 Status; + CFE_Status_t Result; + + if (TaskName == NULL || TaskIdPtr == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } + + /* For tasks IDs, defer to OSAL for name lookup */ + Status = OS_TaskGetIdByName(&OsalId, TaskName); + if (Status == OS_SUCCESS) + { + Result = CFE_SUCCESS; + *TaskIdPtr = CFE_ES_ResourceID_FromOSAL(OsalId); + } + else + { + Result = CFE_ES_ERR_NAME_NOT_FOUND; + *TaskIdPtr = CFE_ES_RESOURCEID_UNDEFINED; + } + + return(Result); +} /* End of CFE_ES_GetTaskIDByName() */ + /* ** Function: CFE_ES_GetAppID - See API and header file for details */ int32 CFE_ES_GetAppID(CFE_ES_ResourceID_t *AppIdPtr) { - int32 Result; + CFE_ES_AppRecord_t *AppRecPtr; + int32 Result; CFE_ES_LockSharedData(__func__,__LINE__); - Result = CFE_ES_GetAppIDInternal(AppIdPtr); + AppRecPtr = CFE_ES_GetAppRecordByContext(); + + if (AppRecPtr != NULL) + { + *AppIdPtr = CFE_ES_AppRecordGetID(AppRecPtr); + Result = CFE_SUCCESS; + } + else + { + *AppIdPtr = CFE_ES_RESOURCEID_UNDEFINED; + Result = CFE_ES_ERR_RESOURCEID_NOT_VALID; + } CFE_ES_UnlockSharedData(__func__,__LINE__); @@ -759,7 +832,7 @@ int32 CFE_ES_GetTaskID(CFE_ES_ResourceID_t *TaskIdPtr) if (TaskRecPtr == NULL) { *TaskIdPtr = CFE_ES_RESOURCEID_UNDEFINED; - Result = CFE_ES_ERR_TASKID; + Result = CFE_ES_ERR_RESOURCEID_NOT_VALID; } else { @@ -778,6 +851,11 @@ int32 CFE_ES_GetAppName(char *AppName, CFE_ES_ResourceID_t AppId, uint32 BufferL int32 Result; CFE_ES_AppRecord_t *AppRecPtr; + if (BufferLength == 0 || AppName == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } + /* ** Get App Record */ @@ -791,34 +869,96 @@ int32 CFE_ES_GetAppName(char *AppName, CFE_ES_ResourceID_t AppId, uint32 BufferL */ if (CFE_ES_AppRecordIsMatch(AppRecPtr, AppId)) { - strncpy(AppName, (char *)AppRecPtr->StartParams.Name, BufferLength - 1); + strncpy(AppName, CFE_ES_AppRecordGetName(AppRecPtr), BufferLength); AppName[BufferLength - 1] = '\0'; Result = CFE_SUCCESS; } else { - Result = CFE_ES_ERR_APPID; + AppName[0] = 0; + Result = CFE_ES_ERR_RESOURCEID_NOT_VALID; } CFE_ES_UnlockSharedData(__func__,__LINE__); + return(Result); + +} /* End of CFE_ES_GetAppName() */ + +/* +** Function: CFE_ES_GetLibName - See API and header file for details +*/ +int32 CFE_ES_GetLibName(char *LibName, CFE_ES_ResourceID_t LibId, uint32 BufferLength) +{ + int32 Result; + CFE_ES_LibRecord_t *LibRecPtr; + + if (BufferLength == 0 || LibName == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } + + /* + ** Get Lib Record + */ + LibRecPtr = CFE_ES_LocateLibRecordByID(LibId); + + CFE_ES_LockSharedData(__func__,__LINE__); + /* - * Appeasement for poorly-behaved callers: - * - * There is a fair amount of existing code that calls this function but - * does not correctly check the return code. Although these callers are - * incorrect, this at least ensures that if the output buffer will be - * appropriately null terminated (empty string) in the failure case. + * confirm that the Lib record is a match, + * which must be done while locked. */ - if (Result != CFE_SUCCESS) + if (CFE_ES_LibRecordIsMatch(LibRecPtr, LibId)) { - AppName[0] = 0; + strncpy(LibName, CFE_ES_LibRecordGetName(LibRecPtr), BufferLength - 1); + LibName[BufferLength - 1] = '\0'; + Result = CFE_SUCCESS; + } + else + { + LibName[0] = 0; + Result = CFE_ES_ERR_RESOURCEID_NOT_VALID; } + CFE_ES_UnlockSharedData(__func__,__LINE__); + return(Result); -} /* End of CFE_ES_GetAppName() */ +} /* End of CFE_ES_GetLibName() */ + +/* +** Function: CFE_ES_GetTaskName - See API and header file for details +*/ +int32 CFE_ES_GetTaskName(char *TaskName, CFE_ES_ResourceID_t TaskId, uint32 BufferLength) +{ + int32 Result; + osal_id_t OsalId; + if (BufferLength == 0 || TaskName == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } + + if (!CFE_ES_ResourceID_IsDefined(TaskId)) + { + return CFE_ES_ERR_RESOURCEID_NOT_VALID; + } + + /* + * Query OSAL to get the task ID + */ + OsalId = CFE_ES_ResourceID_ToOSAL(TaskId); + Result = OS_GetResourceName(OsalId, TaskName, BufferLength); + + if (Result != OS_SUCCESS) + { + return CFE_ES_ERR_RESOURCEID_NOT_VALID; + } + + return CFE_SUCCESS; + +} /* End of CFE_ES_GetTaskName() */ /* ** Function: CFE_ES_GetAppInfo - See API and header file for details @@ -844,7 +984,7 @@ int32 CFE_ES_GetAppInfo(CFE_ES_AppInfo_t *AppInfo, CFE_ES_ResourceID_t AppId) { CFE_ES_WriteToSysLog("CFE_ES_GetAppInfo: App ID Invalid: %lu\n", CFE_ES_ResourceID_ToInteger(AppId)); - return CFE_ES_ERR_APPID; + return CFE_ES_ERR_RESOURCEID_NOT_VALID; } /* @@ -887,7 +1027,7 @@ int32 CFE_ES_GetTaskInfo(CFE_ES_TaskInfo_t *TaskInfo, CFE_ES_ResourceID_t TaskId { CFE_ES_WriteToSysLog("CFE_ES_GetTaskInfo: Task ID Not Valid: %lu\n", CFE_ES_ResourceID_ToInteger(TaskId)); - return CFE_ES_ERR_TASKID; + return CFE_ES_ERR_RESOURCEID_NOT_VALID; } /* @@ -966,7 +1106,7 @@ int32 CFE_ES_CreateChildTask(CFE_ES_ResourceID_t *TaskIdPtr, if (AppRecPtr == NULL) { CFE_ES_SysLogWrite_Unsync("CFE_ES_CreateChildTask: Invalid calling context when creating Task '%s'\n",TaskName); - ReturnCode = CFE_ES_ERR_APPID; + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } else /* else AppId is valid */ { @@ -976,7 +1116,7 @@ int32 CFE_ES_CreateChildTask(CFE_ES_ResourceID_t *TaskIdPtr, */ OsalId = OS_TaskGetId(); TaskId = CFE_ES_ResourceID_FromOSAL(OsalId); - ParentTaskId = AppRecPtr->TaskInfo.MainTaskId; + ParentTaskId = AppRecPtr->MainTaskId; if ( CFE_ES_ResourceID_Equal(TaskId, ParentTaskId) ) { /* @@ -1111,7 +1251,7 @@ int32 CFE_ES_DeleteChildTask(CFE_ES_ResourceID_t TaskId) CFE_ES_TaskRecord_t *TaskRecPtr; CFE_ES_AppRecord_t *AppRecPtr; uint32 i; - bool TaskIsMain = false; + bool TaskIsMain; int32 ReturnCode = CFE_SUCCESS; int32 OSReturnCode; osal_id_t OsalId; @@ -1139,7 +1279,7 @@ int32 CFE_ES_DeleteChildTask(CFE_ES_ResourceID_t TaskId) { if ( CFE_ES_AppRecordIsUsed(AppRecPtr) ) { - if ( CFE_ES_ResourceID_Equal(AppRecPtr->TaskInfo.MainTaskId, TaskId) ) + if ( CFE_ES_ResourceID_Equal(AppRecPtr->MainTaskId, TaskId) ) { /* ** Error, the task Id is an App Main Task ID @@ -1197,7 +1337,7 @@ int32 CFE_ES_DeleteChildTask(CFE_ES_ResourceID_t TaskId) */ 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; + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } /* end if */ @@ -1211,7 +1351,7 @@ int32 CFE_ES_DeleteChildTask(CFE_ES_ResourceID_t TaskId) */ CFE_ES_WriteToSysLog("CFE_ES_DeleteChildTask Error: Invalid Task ID: %lu\n", CFE_ES_ResourceID_ToInteger(TaskId)); - ReturnCode = CFE_ES_ERR_TASKID; + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } return(ReturnCode); @@ -1241,7 +1381,7 @@ void CFE_ES_ExitChildTask(void) AppRecPtr = CFE_ES_LocateAppRecordByID(TaskRecPtr->AppId); if ( CFE_ES_AppRecordIsMatch(AppRecPtr, TaskRecPtr->AppId) && - !CFE_ES_TaskRecordIsMatch(TaskRecPtr, AppRecPtr->TaskInfo.MainTaskId)) + !CFE_ES_TaskRecordIsMatch(TaskRecPtr, AppRecPtr->MainTaskId)) { /* ** Invalidate the task table entry @@ -1400,7 +1540,7 @@ uint32 CFE_ES_CalculateCRC(const void *DataPtr, uint32 DataLength, uint32 InputC int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, CFE_ES_CDS_Offset_t BlockSize, const char *Name) { int32 Status; - size_t NameLen = 0; + size_t NameLen; CFE_ES_ResourceID_t ThisAppId; char AppName[OS_MAX_API_NAME] = {"UNKNOWN"}; @@ -1471,6 +1611,87 @@ int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, CFE_ES_CDS_Offset_t B return Status; } /* End of CFE_ES_RegisterCDS */ +/* + * Function: CFE_ES_GetCDSBlockIDByName + * + * Purpose: Obtain CDS Block ID from name + * See full API description in header file + */ +CFE_Status_t CFE_ES_GetCDSBlockIDByName(CFE_ES_ResourceID_t *BlockIdPtr, const char *BlockName) +{ + CFE_Status_t Status; + CFE_ES_CDS_RegRec_t *RegRecPtr; + + if (BlockName == NULL || BlockIdPtr == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } + if (!CFE_ES_Global.CDSIsAvailable) + { + return CFE_ES_NOT_IMPLEMENTED; + } + + CFE_ES_LockCDS(); + + RegRecPtr = CFE_ES_LocateCDSBlockRecordByName(BlockName); + + if (RegRecPtr != NULL) + { + *BlockIdPtr = CFE_ES_CDSBlockRecordGetID(RegRecPtr); + Status = CFE_SUCCESS; + } + else + { + *BlockIdPtr = CFE_ES_RESOURCEID_UNDEFINED; + Status = CFE_ES_ERR_NAME_NOT_FOUND; + } + + CFE_ES_UnlockCDS(); + + return Status; +} + +/* + * Function: CFE_ES_GetCDSBlockName + * + * Purpose: Obtain CDS Block Name from ID + * See full API description in header file + */ +CFE_Status_t CFE_ES_GetCDSBlockName(char *BlockName, CFE_ES_ResourceID_t BlockId, uint32 BufferLength) +{ + CFE_Status_t Status; + CFE_ES_CDS_RegRec_t *RegRecPtr; + + if (BufferLength == 0 || BlockName == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } + if (!CFE_ES_Global.CDSIsAvailable) + { + return CFE_ES_NOT_IMPLEMENTED; + } + + RegRecPtr = CFE_ES_LocateCDSBlockRecordByID(BlockId); + + CFE_ES_LockCDS(); + + if ( CFE_ES_CDSBlockRecordIsMatch(RegRecPtr, BlockId) ) + { + strncpy(BlockName, RegRecPtr->Name, BufferLength-1); + BlockName[BufferLength-1] = 0; + Status = CFE_SUCCESS; + } + else + { + BlockName[0] = 0; + Status = CFE_ES_ERR_RESOURCEID_NOT_VALID; + } + + CFE_ES_UnlockCDS(); + + return Status; +} + /* ** Function: CFE_ES_CopyToCDS ** @@ -1498,39 +1719,59 @@ int32 CFE_ES_RestoreFromCDS(void *RestoreToMemory, CFE_ES_CDSHandle_t Handle) int32 CFE_ES_RegisterGenCounter(CFE_ES_ResourceID_t *CounterIdPtr, const char *CounterName) { - int32 ReturnCode = CFE_ES_BAD_ARGUMENT; - CFE_ES_ResourceID_t CheckPtr; - int32 Status; - uint32 i; CFE_ES_GenCounterRecord_t *CountRecPtr; + CFE_ES_ResourceID_t PendingCounterId; + int32 Status; - Status = CFE_ES_GetGenCounterIDByName(&CheckPtr, CounterName); + if (CounterName == NULL || CounterIdPtr == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } - if ((CounterIdPtr != NULL) && (CounterName != NULL) && (Status != CFE_SUCCESS)) + if (strlen(CounterName) >= sizeof(CountRecPtr->CounterName)) { - CFE_ES_LockSharedData(__func__,__LINE__); - CountRecPtr = CFE_ES_Global.CounterTable; - for ( i = 0; i < CFE_PLATFORM_ES_MAX_GEN_COUNTERS; i++ ) - { - if ( !CFE_ES_CounterRecordIsUsed(CountRecPtr) ) - { - strncpy(CountRecPtr->CounterName,CounterName,OS_MAX_API_NAME); - CountRecPtr->Counter = 0; - CFE_ES_CounterRecordSetUsed(CountRecPtr, - CFE_ES_ResourceID_FromInteger(i + CFE_ES_COUNTID_BASE)); - *CounterIdPtr = CFE_ES_CounterRecordGetID(CountRecPtr); - break; - } - ++CountRecPtr; - } - if (i < CFE_PLATFORM_ES_MAX_GEN_COUNTERS) - { - ReturnCode = CFE_SUCCESS; - } - CFE_ES_UnlockSharedData(__func__,__LINE__); + return CFE_ES_BAD_ARGUMENT; } - return ReturnCode; + + CFE_ES_LockSharedData(__func__,__LINE__); + + /* + * Check for an existing entry with the same name. + */ + CountRecPtr = CFE_ES_LocateCounterRecordByName(CounterName); + if (CountRecPtr != NULL) + { + CFE_ES_SysLogWrite_Unsync("ES Startup: Duplicate Counter name '%s'\n", CounterName); + Status = CFE_ES_ERR_DUPLICATE_NAME; + PendingCounterId = CFE_ES_RESOURCEID_UNDEFINED; + } + else + { + /* scan for a free slot */ + PendingCounterId = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastCounterId, CFE_PLATFORM_ES_MAX_GEN_COUNTERS); + CountRecPtr = CFE_ES_LocateCounterRecordByID(PendingCounterId); + + if (CountRecPtr == NULL) + { + CFE_ES_SysLogWrite_Unsync("ES Startup: No free Counter slots available\n"); + Status = CFE_ES_NO_RESOURCE_IDS_AVAILABLE; + } + else + { + strncpy(CountRecPtr->CounterName,CounterName, + sizeof(CountRecPtr->CounterName)); + CountRecPtr->Counter = 0; + CFE_ES_CounterRecordSetUsed(CountRecPtr, PendingCounterId); + CFE_ES_Global.LastCounterId = PendingCounterId; + Status = CFE_SUCCESS; + } + } + + CFE_ES_UnlockSharedData(__func__,__LINE__); + + *CounterIdPtr = PendingCounterId; + return Status; } @@ -1626,52 +1867,76 @@ int32 CFE_ES_GetGenCount(CFE_ES_ResourceID_t CounterId, uint32 *Count) int32 CFE_ES_GetGenCounterIDByName(CFE_ES_ResourceID_t *CounterIdPtr, const char *CounterName) { - CFE_ES_GenCounterRecord_t *CountRecPtr; - int32 Result = CFE_ES_BAD_ARGUMENT; - uint32 i; + CFE_ES_GenCounterRecord_t *CounterRecPtr; + int32 Result; + + if (CounterName == NULL || CounterIdPtr == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } /* ** Search the ES Generic Counter table for a counter with a matching name. */ CFE_ES_LockSharedData(__func__,__LINE__); - CountRecPtr = CFE_ES_Global.CounterTable; - for ( i = 0; i < CFE_PLATFORM_ES_MAX_GEN_COUNTERS; i++ ) + CounterRecPtr = CFE_ES_LocateCounterRecordByName(CounterName); + if (CounterRecPtr == NULL) { - if ( CFE_ES_CounterRecordIsUsed(CountRecPtr) ) - { - if ( strncmp(CounterName, CountRecPtr->CounterName, OS_MAX_API_NAME) == 0 ) - { - if(CounterIdPtr != NULL) - { - *CounterIdPtr = CFE_ES_CounterRecordGetID(CountRecPtr); - Result = CFE_SUCCESS; - } - break; - } - } - ++CountRecPtr; - } /* end for */ + /* + * ensure the output value is set to a safe value, + * in case the does not check the return code. + */ + Result = CFE_ES_ERR_NAME_NOT_FOUND; + *CounterIdPtr = CFE_ES_RESOURCEID_UNDEFINED; + } + else + { + Result = CFE_SUCCESS; + *CounterIdPtr = CFE_ES_CounterRecordGetID(CounterRecPtr); + } + CFE_ES_UnlockSharedData(__func__,__LINE__); return(Result); } /* End of CFE_ES_GetGenCounterIDByName() */ - /* - * A conversion function to obtain an index value correlating to a generic resource ID - * This is a zero based value that can be used as an array index. + * Function: CFE_ES_GetGenCounterName + * + * Purpose: Obtain Counter Name from ID + * See full API description in header file */ -int32 CFE_ES_ResourceID_ToIndex_Internal(uint32 Serial, uint32 TableSize, uint32 *Idx) +CFE_Status_t CFE_ES_GetGenCounterName(char *CounterName, CFE_ES_ResourceID_t CounterId, uint32 BufferLength) { - if (Serial > CFE_ES_RESOURCEID_MAX) + CFE_ES_GenCounterRecord_t *CountRecPtr; + CFE_Status_t Status; + + if (BufferLength == 0 || CounterName == NULL) { - return CFE_ES_RESOURCE_ID_INVALID; + return CFE_ES_BAD_ARGUMENT; } - *Idx = Serial % TableSize; - return CFE_SUCCESS; + CountRecPtr = CFE_ES_LocateCounterRecordByID(CounterId); + + CFE_ES_LockSharedData(__func__,__LINE__); + + if (CFE_ES_CounterRecordIsMatch(CountRecPtr, CounterId)) + { + strncpy(CounterName, CFE_ES_CounterRecordGetName(CountRecPtr), BufferLength-1); + CounterName[BufferLength-1] = 0; + Status = CFE_SUCCESS; + } + else + { + CounterName[0] = 0; + Status = CFE_ES_ERR_RESOURCEID_NOT_VALID; + } + + CFE_ES_UnlockSharedData(__func__,__LINE__); + + return Status; } /* @@ -1711,13 +1976,13 @@ int32 CFE_ES_TaskID_ToIndex(CFE_ES_ResourceID_t TaskID, uint32 *Idx) if (!CFE_ES_ResourceID_IsDefined(TaskID)) { - return CFE_ES_ERR_TASKID; + return CFE_ES_ERR_RESOURCEID_NOT_VALID; } OsalID = CFE_ES_ResourceID_ToOSAL(TaskID); if (OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TASK, OsalID, Idx) != OS_SUCCESS) { - return CFE_ES_ERR_TASKID; + return CFE_ES_ERR_RESOURCEID_NOT_VALID; } return CFE_SUCCESS; @@ -1739,209 +2004,6 @@ int32 CFE_ES_CounterID_ToIndex(CFE_ES_ResourceID_t CounterId, uint32 *Idx) ** Private API functions */ -/** - * Convert a CFE_ES_ResourceID_t type to an OSAL ID type. - * - * This should only be used on ES resource IDs that are known to refer to - * an OSAL resource (e.g. a task ID). - * - * Note this may result in an invalid OSAL ID if the CFE_ES_ResourceID_t did - * not actually refer to an OSAL resource. - */ -osal_id_t CFE_ES_ResourceID_ToOSAL(CFE_ES_ResourceID_t id) -{ - unsigned long val = CFE_ES_ResourceID_ToInteger(id); - return OS_ObjectIdFromInteger(val ^ CFE_ES_RESOURCEID_MARK); -} - -/** - * Convert an OSAL ID type to a CFE_ES_ResourceID_t type. - * - * Any OSAL ID can also be represented as a CFE_ES_ResourceID_t - */ -CFE_ES_ResourceID_t CFE_ES_ResourceID_FromOSAL(osal_id_t id) -{ - unsigned long val = OS_ObjectIdToInteger(id); - return CFE_ES_ResourceID_FromInteger(val ^ CFE_ES_RESOURCEID_MARK); -} - - -/* - * 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(CFE_ES_ResourceID_t 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; -} - -extern CFE_ES_LibRecord_t* CFE_ES_LocateLibRecordByID(CFE_ES_ResourceID_t LibID) -{ - CFE_ES_LibRecord_t *LibRecPtr; - uint32 Idx; - - if (CFE_ES_LibID_ToIndex(LibID, &Idx) == CFE_SUCCESS) - { - LibRecPtr = &CFE_ES_Global.LibTable[Idx]; - } - else - { - LibRecPtr = NULL; - } - - return LibRecPtr; -} - - -/* - * 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(CFE_ES_ResourceID_t 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; -} - -CFE_ES_GenCounterRecord_t* CFE_ES_LocateCounterRecordByID(CFE_ES_ResourceID_t CounterID) -{ - CFE_ES_GenCounterRecord_t *CounterRecPtr; - uint32 Idx; - - if (CFE_ES_CounterID_ToIndex(CounterID, &Idx) == CFE_SUCCESS) - { - CounterRecPtr = &CFE_ES_Global.CounterTable[Idx]; - } - else - { - CounterRecPtr = NULL; - } - - return CounterRecPtr; -} - - -/* - * 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; - CFE_ES_ResourceID_t TaskID; - - /* - ** Use the OS task ID to get the ES task record - */ - TaskID = CFE_ES_ResourceID_FromOSAL(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 -** -** Purpose: Return the Caller's cFE Application ID. This internal version is needed -** so there are not nested calls to the ES Shared Data mutex lock. -** -*/ -int32 CFE_ES_GetAppIDInternal(CFE_ES_ResourceID_t *AppIdPtr) -{ - CFE_ES_AppRecord_t *AppRecPtr; - int32 Result; - - AppRecPtr = CFE_ES_GetAppRecordByContext(); - - if (AppRecPtr != NULL) - { - *AppIdPtr = CFE_ES_AppRecordGetID(AppRecPtr); - Result = CFE_SUCCESS; - } - else - { - *AppIdPtr = CFE_ES_RESOURCEID_UNDEFINED; - Result = CFE_ES_ERR_APPID; - } - - return Result; - -} /* End of CFE_ES_GetAppIDInternal() */ - - /****************************************************************************** ** Function: CFE_ES_LockSharedData() ** @@ -1958,21 +2020,17 @@ int32 CFE_ES_GetAppIDInternal(CFE_ES_ResourceID_t *AppIdPtr) */ void CFE_ES_LockSharedData(const char *FunctionName, int32 LineNumber) { - int32 Status; - CFE_ES_ResourceID_t AppId; Status = OS_MutSemTake(CFE_ES_Global.SharedDataMutex); if (Status != OS_SUCCESS) { - CFE_ES_GetAppIDInternal(&AppId); - /* * 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=%lu,Func=%s,Line=%d\n", - (unsigned int)Status,CFE_ES_ResourceID_ToInteger(AppId),FunctionName,(int)LineNumber); + CFE_ES_SysLogWrite_Unsync("ES SharedData Mutex Take Err Stat=0x%x,Func=%s,Line=%d\n", + (unsigned int)Status,FunctionName,(int)LineNumber); }/* end if */ @@ -1997,20 +2055,16 @@ void CFE_ES_LockSharedData(const char *FunctionName, int32 LineNumber) void CFE_ES_UnlockSharedData(const char *FunctionName, int32 LineNumber) { int32 Status; - CFE_ES_ResourceID_t AppId; Status = OS_MutSemGive(CFE_ES_Global.SharedDataMutex); if (Status != OS_SUCCESS) { - - CFE_ES_GetAppIDInternal(&AppId); - /* * 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=%lu,Func=%s,Line=%d\n", - (unsigned int)Status,CFE_ES_ResourceID_ToInteger(AppId),FunctionName,(int)LineNumber); + CFE_ES_SysLogWrite_Unsync("ES SharedData Mutex Give Err Stat=0x%x,Func=%s,Line=%d\n", + (unsigned int)Status,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 3a4499e9e..ebd7916de 100644 --- a/fsw/cfe-core/src/es/cfe_es_apps.c +++ b/fsw/cfe-core/src/es/cfe_es_apps.c @@ -43,6 +43,7 @@ #include "cfe_es_task.h" #include "cfe_es_apps.h" #include "cfe_es_log.h" +#include "cfe_es_resource.h" #include #include /* memset() */ @@ -78,7 +79,7 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath ) char ES_AppLoadBuffer[ES_START_BUFF_SIZE]; /* A buffer of for a line in a file */ const char *TokenList[CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE]; uint32 NumTokens; - uint32 BuffLen = 0; /* Length of the current buffer */ + uint32 BuffLen; /* Length of the current buffer */ osal_id_t AppFile; int32 Status; char c; @@ -363,45 +364,82 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, { cpuaddr StartAddr; int32 ReturnCode; - uint32 i; - bool AppSlotFound; + CFE_Status_t Status; osal_id_t ModuleId; osal_id_t MainTaskId; CFE_ES_AppRecord_t *AppRecPtr; CFE_ES_TaskRecord_t *TaskRecPtr; + CFE_ES_ResourceID_t PendingAppId; /* * The FileName must not be NULL */ - if (FileName == NULL) + if (FileName == NULL || AppName == NULL) { - return CFE_ES_ERR_APP_CREATE; + return CFE_ES_BAD_ARGUMENT; + } + + if (strlen(AppName) >= OS_MAX_API_NAME) + { + return CFE_ES_BAD_ARGUMENT; } /* ** Allocate an ES_AppTable entry */ CFE_ES_LockSharedData(__func__,__LINE__); - AppSlotFound = false; - AppRecPtr = CFE_ES_Global.AppTable; - for ( i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++ ) + + /* + ** Find an ES AppTable entry, and set to RESERVED + ** + ** In this state, the entry is no longer free, but also will not pass the + ** validation test. So this function effectively has exclusive access + ** without holding the global lock. + ** + ** IMPORTANT: it must set the ID to something else before leaving + ** this function or else the resource will be leaked. After this + ** point, execution must proceed to the end of the function to + ** guarantee that the entry is either completed or freed. + */ + + /* + * Check for an existing entry with the same name. + * Also check for a matching Library name. + * (Apps and libraries should be uniquely named) + */ + AppRecPtr = CFE_ES_LocateAppRecordByName(AppName); + if (AppRecPtr != NULL) { - if ( !CFE_ES_AppRecordIsUsed(AppRecPtr) ) - { - AppSlotFound = true; - memset ( AppRecPtr, 0, sizeof(CFE_ES_AppRecord_t)); - /* set state EARLY_INIT for OS_TaskCreate below (indicates record is in use) */ - CFE_ES_AppRecordSetUsed(AppRecPtr, CFE_ES_ResourceID_FromInteger(i + CFE_ES_APPID_BASE)); - break; - } - ++AppRecPtr; + CFE_ES_SysLogWrite_Unsync("ES Startup: Duplicate app name '%s'\n", AppName); + Status = CFE_ES_ERR_DUPLICATE_NAME; + } + else + { + /* scan for a free slot */ + PendingAppId = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastAppId, CFE_PLATFORM_ES_MAX_APPLICATIONS); + AppRecPtr = CFE_ES_LocateAppRecordByID(PendingAppId); + + if (AppRecPtr == NULL) + { + CFE_ES_SysLogWrite_Unsync("ES Startup: No free application slots available\n"); + Status = CFE_ES_NO_RESOURCE_IDS_AVAILABLE; + } + else + { + /* Fully clear the entry, just in case of stale data */ + memset(AppRecPtr, 0, sizeof(*AppRecPtr)); + CFE_ES_AppRecordSetUsed(AppRecPtr, CFE_ES_RESOURCEID_RESERVED); + CFE_ES_Global.LastAppId = PendingAppId; + Status = CFE_SUCCESS; + } } + CFE_ES_UnlockSharedData(__func__,__LINE__); /* ** If a slot was found, create the application */ - if ( AppSlotFound == true) + if (Status == CFE_SUCCESS) { /* ** Load the module @@ -474,12 +512,6 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, AppRecPtr->StartParams.ExceptionAction = ExceptionAction; AppRecPtr->StartParams.Priority = Priority; - /* - ** Fill out the Task Info - */ - 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 */ @@ -506,7 +538,7 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, CFE_ES_AppRecordSetFree(AppRecPtr); /* Release slot */ CFE_ES_UnlockSharedData(__func__,__LINE__); - return(CFE_ES_ERR_APP_CREATE); + Status = CFE_ES_ERR_APP_CREATE; } else { @@ -514,20 +546,22 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, /* ** Record the ES_TaskTable entry */ - AppRecPtr->TaskInfo.MainTaskId = CFE_ES_ResourceID_FromOSAL(MainTaskId); - TaskRecPtr = CFE_ES_LocateTaskRecordByID(AppRecPtr->TaskInfo.MainTaskId); + AppRecPtr->MainTaskId = CFE_ES_ResourceID_FromOSAL(MainTaskId); + TaskRecPtr = CFE_ES_LocateTaskRecordByID(AppRecPtr->MainTaskId); if ( CFE_ES_TaskRecordIsUsed(TaskRecPtr) ) { CFE_ES_SysLogWrite_Unsync("ES Startup: Error: ES_TaskTable slot in use at task creation!\n"); } - 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_TaskRecordSetUsed(TaskRecPtr,AppRecPtr->MainTaskId); + TaskRecPtr->AppId = PendingAppId; + /* The main task name is the same as the app name */ + strncpy(TaskRecPtr->TaskName, AppName, + sizeof(TaskRecPtr->TaskName)-1); + TaskRecPtr->TaskName[sizeof(TaskRecPtr->TaskName)-1]='\0'; + CFE_ES_AppRecordSetUsed(AppRecPtr, PendingAppId); CFE_ES_SysLogWrite_Unsync("ES Startup: %s loaded and created\n", AppName); - *ApplicationIdPtr = CFE_ES_AppRecordGetID(AppRecPtr); + *ApplicationIdPtr = PendingAppId; /* ** Increment the registered App and Registered External Task variables. @@ -537,15 +571,10 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, CFE_ES_UnlockSharedData(__func__,__LINE__); - return(CFE_SUCCESS); - } /* End If OS_TaskCreate */ } - else /* appSlot not found */ - { - CFE_ES_WriteToSysLog("ES Startup: No free application slots available\n"); - return(CFE_ES_ERR_APP_CREATE); - } + + return Status; } /* End Function */ /* @@ -563,19 +592,20 @@ int32 CFE_ES_LoadLibrary(CFE_ES_ResourceID_t *LibraryIdPtr, { CFE_ES_LibraryEntryFuncPtr_t FunctionPointer; CFE_ES_LibRecord_t * LibSlotPtr; - size_t StringLength; int32 Status; - uint32 LibIndex; CFE_ES_ResourceID_t PendingLibId; osal_id_t ModuleId; bool IsModuleLoaded; /* - * First, should verify that the supplied "LibName" fits within the internal limit - * (currently sized to OS_MAX_API_NAME, but not assuming that will always be) + * The FileName must not be NULL */ - StringLength = strlen(LibName); - if (StringLength >= sizeof(LibSlotPtr->LibName)) + if (FileName == NULL || LibName == NULL) + { + return CFE_ES_BAD_ARGUMENT; + } + + if (strlen(LibName) >= OS_MAX_API_NAME) { return CFE_ES_BAD_ARGUMENT; } @@ -588,65 +618,67 @@ int32 CFE_ES_LoadLibrary(CFE_ES_ResourceID_t *LibraryIdPtr, ModuleId = OS_OBJECT_ID_UNDEFINED; PendingLibId = CFE_ES_RESOURCEID_UNDEFINED; Status = CFE_ES_ERR_LOAD_LIB; /* error that will be returned if no slots found */ + + /* + ** Find an ES AppTable entry, and set to RESERVED + ** + ** In this state, the entry is no longer free, but also will not pass the + ** validation test. So this function effectively has exclusive access + ** without holding the global lock. + ** + ** IMPORTANT: it must set the ID to something else before leaving + ** this function or else the resource will be leaked. After this + ** point, execution must proceed to the end of the function to + ** guarantee that the entry is either completed or freed. + */ CFE_ES_LockSharedData(__func__,__LINE__); - LibSlotPtr = CFE_ES_Global.LibTable; - for ( LibIndex = 0; LibIndex < CFE_PLATFORM_ES_MAX_LIBRARIES; ++LibIndex ) - { - if (CFE_ES_LibRecordIsUsed(LibSlotPtr)) - { - if (strcmp(LibSlotPtr->LibName, LibName) == 0) - { - /* - * Indicate to caller that the library is already loaded. - * (This is when there was a matching LibName in the table) - * - * Do nothing more; not logging this event as it may or may - * not be an error. - */ - *LibraryIdPtr = CFE_ES_LibRecordGetID(LibSlotPtr); - Status = CFE_ES_LIB_ALREADY_LOADED; - break; - } - } - else if (!CFE_ES_ResourceID_IsDefined(PendingLibId)) - { - /* Remember list position as possible place for new entry. */ - PendingLibId = CFE_ES_ResourceID_FromInteger(LibIndex + CFE_ES_LIBID_BASE); - Status = CFE_SUCCESS; - } - else - { - /* No action */ - } - ++LibSlotPtr; + /* + * Check for an existing entry with the same name. + * Also check for a matching Library name. + * (Libs and libraries should be uniquely named) + */ + LibSlotPtr = CFE_ES_LocateLibRecordByName(LibName); + if (LibSlotPtr != NULL || CFE_ES_LocateAppRecordByName(LibName) != NULL) + { + CFE_ES_SysLogWrite_Unsync("ES Startup: Duplicate Lib name '%s'\n", LibName); + if (LibSlotPtr != NULL) + { + PendingLibId = CFE_ES_LibRecordGetID(LibSlotPtr); + } + Status = CFE_ES_ERR_DUPLICATE_NAME; } - - if (Status == CFE_SUCCESS) + else { - /* reset back to the saved index that was free */ + /* scan for a free slot */ + PendingLibId = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastLibId, CFE_PLATFORM_ES_MAX_LIBRARIES); LibSlotPtr = CFE_ES_LocateLibRecordByID(PendingLibId); - /* reserve the slot while still under lock */ - strcpy(LibSlotPtr->LibName, LibName); - CFE_ES_LibRecordSetUsed(LibSlotPtr, CFE_ES_RESOURCEID_RESERVED); - *LibraryIdPtr = PendingLibId; + if (LibSlotPtr == NULL) + { + CFE_ES_SysLogWrite_Unsync("ES Startup: No free library slots available\n"); + Status = CFE_ES_NO_RESOURCE_IDS_AVAILABLE; + } + else + { + /* Fully clear the entry, just in case of stale data */ + memset(LibSlotPtr, 0, sizeof(*LibSlotPtr)); + strcpy(LibSlotPtr->LibName, LibName); /* Size already checked */ + CFE_ES_LibRecordSetUsed(LibSlotPtr, CFE_ES_RESOURCEID_RESERVED); + CFE_ES_Global.LastLibId = PendingLibId; + Status = CFE_SUCCESS; + } } CFE_ES_UnlockSharedData(__func__,__LINE__); /* * If any off-nominal condition exists, skip the rest of this logic. - * Additionally write any extra information about what happened to syslog - * Note - not logging "already loaded" conditions, as this is not necessarily an error. + * (Log message already written) */ if (Status != CFE_SUCCESS) { - if (Status == CFE_ES_ERR_LOAD_LIB) - { - CFE_ES_WriteToSysLog("ES Startup: No free library slots available\n"); - } - + *LibraryIdPtr = PendingLibId; return Status; } @@ -769,8 +801,12 @@ int32 CFE_ES_LoadLibrary(CFE_ES_ResourceID_t *LibraryIdPtr, /* Release Slot - No need to lock as it is resetting just a single value */ CFE_ES_LibRecordSetFree(LibSlotPtr); + + PendingLibId = CFE_ES_RESOURCEID_UNDEFINED; } + *LibraryIdPtr = PendingLibId; + return(Status); } /* End Function */ @@ -1133,7 +1169,7 @@ int32 CFE_ES_CleanUpApp(CFE_ES_AppRecord_t *AppRecPtr) /* ** Get Main Task ID */ - MainTaskId = AppRecPtr->TaskInfo.MainTaskId; + MainTaskId = AppRecPtr->MainTaskId; /* ** Delete any child tasks associated with this app @@ -1447,7 +1483,7 @@ int32 CFE_ES_GetAppInfoInternal(CFE_ES_AppRecord_t *AppRecPtr, CFE_ES_AppInfo_t if ( !CFE_ES_AppRecordIsUsed(AppRecPtr) ) { - Status = CFE_ES_ERR_APPID; + Status = CFE_ES_ERR_RESOURCEID_NOT_VALID; } else { @@ -1456,8 +1492,8 @@ int32 CFE_ES_GetAppInfoInternal(CFE_ES_AppRecord_t *AppRecPtr, CFE_ES_AppInfo_t AppId = CFE_ES_AppRecordGetID(AppRecPtr); AppInfoPtr->AppId = AppId; AppInfoPtr->Type = AppRecPtr->Type; - strncpy((char *)AppInfoPtr->Name, - AppRecPtr->StartParams.Name, + strncpy(AppInfoPtr->Name, + CFE_ES_AppRecordGetName(AppRecPtr), sizeof(AppInfoPtr->Name)-1); AppInfoPtr->Name[sizeof(AppInfoPtr->Name)-1] = '\0'; @@ -1476,10 +1512,7 @@ int32 CFE_ES_GetAppInfoInternal(CFE_ES_AppRecord_t *AppRecPtr, CFE_ES_AppInfo_t 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'; + AppInfoPtr->MainTaskId = AppRecPtr->MainTaskId; /* ** Calculate the number of child tasks @@ -1504,6 +1537,9 @@ int32 CFE_ES_GetAppInfoInternal(CFE_ES_AppRecord_t *AppRecPtr, CFE_ES_AppInfo_t if (CFE_ES_TaskRecordIsMatch(TaskRecPtr,AppInfoPtr->MainTaskId)) { AppInfoPtr->ExecutionCounter = TaskRecPtr->ExecutionCounter; + strncpy(AppInfoPtr->MainTaskName, TaskRecPtr->TaskName, + sizeof(AppInfoPtr->MainTaskName) - 1); + AppInfoPtr->MainTaskName[sizeof(AppInfoPtr->MainTaskName) - 1] = '\0'; } /* @@ -1565,7 +1601,8 @@ int32 CFE_ES_GetTaskInfoInternal(CFE_ES_TaskRecord_t *TaskRecPtr, CFE_ES_TaskInf ** Get the Application ID and Task Name */ TaskInfoPtr->AppId = TaskRecPtr->AppId; - strncpy((char*)TaskInfoPtr->TaskName, TaskRecPtr->TaskName, + strncpy(TaskInfoPtr->TaskName, + CFE_ES_TaskRecordGetName(TaskRecPtr), sizeof(TaskInfoPtr->TaskName)-1); TaskInfoPtr->TaskName[sizeof(TaskInfoPtr->TaskName)-1] = '\0'; @@ -1585,7 +1622,8 @@ int32 CFE_ES_GetTaskInfoInternal(CFE_ES_TaskRecord_t *TaskRecPtr, CFE_ES_TaskInf AppRecPtr = CFE_ES_LocateAppRecordByID(TaskRecPtr->AppId); if (CFE_ES_AppRecordIsMatch(AppRecPtr, TaskRecPtr->AppId)) { - strncpy((char*)TaskInfoPtr->AppName, AppRecPtr->StartParams.Name, + strncpy(TaskInfoPtr->AppName, + CFE_ES_AppRecordGetName(AppRecPtr), sizeof(TaskInfoPtr->AppName)-1); TaskInfoPtr->AppName[sizeof(TaskInfoPtr->AppName)-1] = '\0'; ReturnCode = CFE_SUCCESS; @@ -1593,13 +1631,13 @@ int32 CFE_ES_GetTaskInfoInternal(CFE_ES_TaskRecord_t *TaskRecPtr, CFE_ES_TaskInf else { /* task ID was OK but parent app ID is bad */ - ReturnCode = CFE_ES_ERR_APPID; + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } } else { /* task ID is bad */ - ReturnCode = CFE_ES_ERR_TASKID; + ReturnCode = CFE_ES_ERR_RESOURCEID_NOT_VALID; } CFE_ES_UnlockSharedData(__func__,__LINE__); diff --git a/fsw/cfe-core/src/es/cfe_es_apps.h b/fsw/cfe-core/src/es/cfe_es_apps.h index f4a0fbdb2..fa29774b4 100644 --- a/fsw/cfe-core/src/es/cfe_es_apps.h +++ b/fsw/cfe-core/src/es/cfe_es_apps.h @@ -83,18 +83,6 @@ typedef struct } CFE_ES_AppStartParams_t; -/* -** CFE_ES_MainTaskInfo_t is a structure of information about the main -** task and child tasks in a cFE application. This structure is just used in the -** cFE_ES_AppRecord_t structure. -*/ -typedef struct -{ - CFE_ES_ResourceID_t MainTaskId; /* The Application's Main Task ID */ - char MainTaskName[OS_MAX_API_NAME]; /* The Application's Main Task ID */ -} CFE_ES_MainTaskInfo_t; - - /* ** CFE_ES_AppRecord_t is an internal structure used to keep track of ** CFE Applications that are active in the system. @@ -106,7 +94,7 @@ typedef struct 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 */ - CFE_ES_MainTaskInfo_t TaskInfo; /* Information about the Tasks */ + CFE_ES_ResourceID_t MainTaskId; /* The Application's Main Task ID */ } CFE_ES_AppRecord_t; diff --git a/fsw/cfe-core/src/es/cfe_es_cds.c b/fsw/cfe-core/src/es/cfe_es_cds.c index 43861dda6..be9efc862 100644 --- a/fsw/cfe-core/src/es/cfe_es_cds.c +++ b/fsw/cfe-core/src/es/cfe_es_cds.c @@ -42,6 +42,7 @@ #include "cfe_es_apps.h" #include "cfe_es_cds.h" #include "cfe_es_global.h" +#include "cfe_es_resource.h" #include "cfe_es_log.h" #include "cfe_psp.h" #include "cfe_es_cds_mempool.h" @@ -74,6 +75,8 @@ int32 CFE_ES_CDS_EarlyInit(void) return CFE_STATUS_EXTERNAL_RESOURCE_FAIL; } + CDS->LastCDSBlockId = CFE_ES_ResourceID_FromInteger(CFE_ES_CDSBLOCKID_BASE); + /* Get CDS size from OS BSP */ Status = CFE_PSP_GetCDSSize(&CDS->TotalSize); if (Status != CFE_PSP_SUCCESS) @@ -305,14 +308,20 @@ int32 CFE_ES_CDS_CachePreload(CFE_ES_CDS_AccessCache_t *Cache, const void *Sourc int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t UserBlockSize, const char *Name, bool CriticalTbl) { CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars; - int32 Status = CFE_SUCCESS; - int32 RegUpdateStatus = CFE_SUCCESS; + int32 Status; + int32 RegUpdateStatus; CFE_ES_CDS_RegRec_t *RegRecPtr; CFE_ES_MemOffset_t BlockOffset; CFE_ES_MemOffset_t OldBlockSize; CFE_ES_MemOffset_t NewBlockSize; - bool IsNewEntry = false; - bool IsNewOffset = false; + CFE_ES_ResourceID_t PendingBlockId; + bool IsNewEntry; + bool IsNewOffset; + + Status = CFE_SUCCESS; + RegUpdateStatus = CFE_SUCCESS; + IsNewEntry = false; + IsNewOffset = false; if (UserBlockSize == 0 || UserBlockSize > CDS_ABS_MAX_BLOCK_SIZE) { @@ -324,21 +333,38 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t Us /* trying to register CDSs at the same location at the same time */ CFE_ES_LockCDS(); - /* Check for duplicate CDS name */ - RegRecPtr = CFE_ES_FindCDSInRegistry(Name); - - /* If not found then make a new entry */ - if (RegRecPtr == NULL) + /* + * Check for an existing entry with the same name. + */ + RegRecPtr = CFE_ES_LocateCDSBlockRecordByName(Name); + if (RegRecPtr != NULL) { - RegRecPtr = CFE_ES_AllocateNewCDSRegistryEntry(); - IsNewEntry = true; + /* in CDS a duplicate name is not necessarily an error, we + * may reuse/resize the existing entry */ + PendingBlockId = CFE_ES_CDSBlockRecordGetID(RegRecPtr); } - - if (RegRecPtr == NULL) + else { - Status = CFE_ES_CDS_REGISTRY_FULL; + /* scan for a free slot */ + PendingBlockId = CFE_ES_FindNextAvailableId(CDS->LastCDSBlockId, CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES); + RegRecPtr = CFE_ES_LocateCDSBlockRecordByID(PendingBlockId); + + if (RegRecPtr != NULL) + { + /* Fully clear the entry, just in case of stale data */ + memset(RegRecPtr, 0, sizeof(*RegRecPtr)); + CDS->LastCDSBlockId = PendingBlockId; + IsNewEntry = true; + Status = CFE_SUCCESS; + } + else + { + Status = CFE_ES_NO_RESOURCE_IDS_AVAILABLE; + PendingBlockId = CFE_ES_RESOURCEID_UNDEFINED; + } } - else + + if (RegRecPtr != NULL) { /* Account for the extra header which will be added */ NewBlockSize = UserBlockSize; @@ -378,43 +404,24 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t Us } } - if (IsNewEntry) + if (Status == CFE_SUCCESS && IsNewEntry) { - if (Status == CFE_SUCCESS) - { - /* Save flag indicating whether it is a Critical Table or not */ - RegRecPtr->Table = CriticalTbl; + /* Save flag indicating whether it is a Critical Table or not */ + RegRecPtr->Table = CriticalTbl; - /* Save CDS Name in Registry */ - strncpy(RegRecPtr->Name, Name, sizeof(RegRecPtr->Name)-1); - RegRecPtr->Name[sizeof(RegRecPtr->Name)-1] = 0; - } - else - { - /* On failure set it free */ - CFE_ES_CDSBlockRecordSetFree(RegRecPtr); - } + /* Save CDS Name in Registry */ + strncpy(RegRecPtr->Name, Name, sizeof(RegRecPtr->Name)-1); + RegRecPtr->Name[sizeof(RegRecPtr->Name)-1] = 0; + CFE_ES_CDSBlockRecordSetUsed(RegRecPtr, PendingBlockId); } - if (IsNewOffset || IsNewEntry) + if (Status == CFE_SUCCESS && (IsNewOffset || IsNewEntry)) { /* If we succeeded at creating a CDS, save updated registry in the CDS */ RegUpdateStatus = CFE_ES_UpdateCDSRegistry(); } } - /* - * Export handle to caller before unlock - */ - if (Status == CFE_SUCCESS) - { - *HandlePtr = CFE_ES_CDSBlockRecordGetID(RegRecPtr); - } - else - { - *HandlePtr = CFE_ES_RESOURCEID_UNDEFINED; - } - /* Unlock Registry for update */ CFE_ES_UnlockCDS(); @@ -446,6 +453,7 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t Us Status = CFE_ES_CDS_ALREADY_EXISTS; } + *HandlePtr = PendingBlockId; return (Status); @@ -732,12 +740,12 @@ int32 CFE_ES_UnlockCDS(void) /******************************************************************* ** -** CFE_ES_FindCDSInRegistry +** CFE_ES_LocateCDSBlockRecordByName ** ** NOTE: For complete prolog information, see 'cfe_es_cds.h' ********************************************************************/ -CFE_ES_CDS_RegRec_t *CFE_ES_FindCDSInRegistry(const char *CDSName) +CFE_ES_CDS_RegRec_t *CFE_ES_LocateCDSBlockRecordByName(const char *CDSName) { CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars; CFE_ES_CDS_RegRec_t *CDSRegRecPtr; @@ -768,51 +776,7 @@ CFE_ES_CDS_RegRec_t *CFE_ES_FindCDSInRegistry(const char *CDSName) } return CDSRegRecPtr; -} /* End of CFE_ES_FindCDSInRegistry() */ - - -/******************************************************************* -** -** CFE_ES_FindFreeCDSRegistryEntry -** -** NOTE: For complete prolog information, see 'cfe_es_cds.h' -********************************************************************/ - -CFE_ES_CDS_RegRec_t *CFE_ES_AllocateNewCDSRegistryEntry() -{ - CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars; - CFE_ES_CDS_RegRec_t *CDSRegRecPtr; - uint32 NumReg; - - CDSRegRecPtr = CDS->Registry; - NumReg = CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES; - while (true) - { - if (NumReg == 0) - { - CDSRegRecPtr = NULL; /* not found */ - break; - } - - if (!CFE_ES_CDSBlockRecordIsUsed(CDSRegRecPtr)) - { - /* Wipe it, just in case of stale data */ - memset(CDSRegRecPtr, 0, sizeof(*CDSRegRecPtr)); - - /* Set the ID which marks it as used */ - CFE_ES_CDSBlockRecordSetUsed(CDSRegRecPtr, - CFE_ES_ResourceID_FromInteger( - (CDSRegRecPtr - CDS->Registry) - + CFE_ES_CDSBLOCKID_BASE)); - break; - } - - ++CDSRegRecPtr; - --NumReg; - } - - return CDSRegRecPtr; -} /* End of CFE_ES_FindFreeCDSRegistryEntry() */ +} /* End of CFE_ES_LocateCDSBlockRecordByName() */ /******************************************************************* @@ -889,7 +853,7 @@ int32 CFE_ES_DeleteCDS(const char *CDSName, bool CalledByTblServices) CFE_ES_LockCDS(); /* Find CDS name in registry */ - RegRecPtr = CFE_ES_FindCDSInRegistry(CDSName); + RegRecPtr = CFE_ES_LocateCDSBlockRecordByName(CDSName); /* Check to see if CDS is already in the registry */ if (RegRecPtr != NULL) @@ -952,7 +916,7 @@ int32 CFE_ES_DeleteCDS(const char *CDSName, bool CalledByTblServices) } else /* Error - CDS not in registry */ { - Status = CFE_ES_CDS_NOT_FOUND_ERR; + Status = CFE_ES_ERR_NAME_NOT_FOUND; } /* Unlock Registry for future updates */ diff --git a/fsw/cfe-core/src/es/cfe_es_cds.h b/fsw/cfe-core/src/es/cfe_es_cds.h index 192df3594..926135a27 100644 --- a/fsw/cfe-core/src/es/cfe_es_cds.h +++ b/fsw/cfe-core/src/es/cfe_es_cds.h @@ -170,6 +170,7 @@ typedef struct osal_id_t GenMutex; /**< \brief Mutex that controls access to CDS and registry */ CFE_ES_CDS_Offset_t TotalSize; /**< \brief Total size of the CDS as reported by BSP */ CFE_ES_CDS_Offset_t DataSize; /**< \brief Size of actual user data pool */ + CFE_ES_ResourceID_t LastCDSBlockId; /**< \brief Last issued CDS block ID */ CFE_ES_CDS_RegRec_t Registry[CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES]; /**< \brief CDS Registry (Local Copy) */ } CFE_ES_CDS_Instance_t; @@ -274,7 +275,7 @@ int32 CFE_ES_CDS_CachePreload(CFE_ES_CDS_AccessCache_t *Cache, const void *Sourc * @param[in] BlockID the ID/handle of the CDS block to retrieve * @param[out] Idx Output buffer to store the index * @returns #CFE_SUCCESS if conversion successful. @copydoc CFE_SUCCESS - * #CFE_ES_RESOURCE_ID_INVALID if block ID is outside valid range + * #CFE_ES_ERR_RESOURCEID_NOT_VALID if block ID is outside valid range */ int32 CFE_ES_CDSBlockID_ToIndex(CFE_ES_ResourceID_t BlockID, uint32 *Idx); @@ -505,7 +506,7 @@ void CFE_ES_FormCDSName(char *FullCDSName, const char *CDSName, CFE_ES_ResourceI /*****************************************************************************/ /** -** \brief Returns the Registry Index for the specified CDS Name +** \brief Returns the Registry Record for the specified CDS Name ** ** \par Description ** Locates given CDS Name in the CDS Registry and @@ -520,22 +521,7 @@ void CFE_ES_FormCDSName(char *FullCDSName, const char *CDSName, CFE_ES_ResourceI ** \retval NULL if not found, Non null entry pointer on success ** ******************************************************************************/ -CFE_ES_CDS_RegRec_t *CFE_ES_FindCDSInRegistry(const char *CDSName); - -/*****************************************************************************/ -/** -** \brief Locates a free slot in the CDS Registry and configures it for new use. -** -** \par Description -** Locates a free slot in the CDS Registry, assigns an ID, -** and marks the entry as used. -** -** \par Assumptions, External Events, and Notes: -** Note: This function assumes the registry has been locked. -** -** \retval NULL if registry full, Non null entry pointer on success -******************************************************************************/ -CFE_ES_CDS_RegRec_t *CFE_ES_AllocateNewCDSRegistryEntry(void); +CFE_ES_CDS_RegRec_t *CFE_ES_LocateCDSBlockRecordByName(const char *CDSName); /*****************************************************************************/ /** diff --git a/fsw/cfe-core/src/es/cfe_es_cds_mempool.c b/fsw/cfe-core/src/es/cfe_es_cds_mempool.c index 81b68cf5a..53b9bf51c 100644 --- a/fsw/cfe-core/src/es/cfe_es_cds_mempool.c +++ b/fsw/cfe-core/src/es/cfe_es_cds_mempool.c @@ -283,7 +283,7 @@ int32 CFE_ES_CDSBlockWrite(CFE_ES_CDSHandle_t Handle, const void *DataToWrite) } else { - Status = CFE_ES_RESOURCE_ID_INVALID; + Status = CFE_ES_ERR_RESOURCEID_NOT_VALID; } CFE_ES_UnlockCDS(); @@ -379,7 +379,7 @@ int32 CFE_ES_CDSBlockRead(void *DataRead, CFE_ES_CDSHandle_t Handle) } else { - Status = CFE_ES_RESOURCE_ID_INVALID; + Status = CFE_ES_ERR_RESOURCEID_NOT_VALID; } CFE_ES_UnlockCDS(); diff --git a/fsw/cfe-core/src/es/cfe_es_erlog.c b/fsw/cfe-core/src/es/cfe_es_erlog.c index ef212102c..c7cafdf01 100644 --- a/fsw/cfe-core/src/es/cfe_es_erlog.c +++ b/fsw/cfe-core/src/es/cfe_es_erlog.c @@ -42,6 +42,7 @@ #include "cfe_es.h" #include "cfe_es_apps.h" #include "cfe_es_global.h" +#include "cfe_es_resource.h" #include "cfe_es_log.h" #include "cfe_es_task.h" #include "cfe_psp.h" diff --git a/fsw/cfe-core/src/es/cfe_es_global.h b/fsw/cfe-core/src/es/cfe_es_global.h index 6f8a451dc..d3dbcc9fe 100644 --- a/fsw/cfe-core/src/es/cfe_es_global.h +++ b/fsw/cfe-core/src/es/cfe_es_global.h @@ -53,31 +53,6 @@ #include "cfe_psp.h" -/* -** Defines -*/ - -/* - * Limits/definitions related to CFE_ES_ResourceID_t values. - * - * Defining based on OSAL ID values makes this object a superset of - * the OSAL ID type, such that OSAL IDs can be represented as ES resource IDs - * and not conflict with/alias each other. - * - * NOTE: This reflects a bit if "inside knowledge" about how OSAL IDs are - * constructed. The overlap between OSAL IDs and ES IDs may not always be - * consistent, and they can diverge in a future version. - */ -#define CFE_ES_RESOURCEID_SHIFT OS_OBJECT_TYPE_SHIFT -#define CFE_ES_RESOURCEID_MAX ((1 << CFE_ES_RESOURCEID_SHIFT)-1) -#define CFE_ES_RESOURCEID_MARK (0x02000000) - -#define CFE_ES_APPID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+1) << CFE_ES_RESOURCEID_SHIFT)) -#define CFE_ES_LIBID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+2) << CFE_ES_RESOURCEID_SHIFT)) -#define CFE_ES_COUNTID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+3) << CFE_ES_RESOURCEID_SHIFT)) -#define CFE_ES_POOLID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+4) << CFE_ES_RESOURCEID_SHIFT)) -#define CFE_ES_CDSBLOCKID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+5) << CFE_ES_RESOURCEID_SHIFT)) - /* ** Typedefs */ @@ -142,17 +117,20 @@ typedef struct */ uint32 RegisteredCoreApps; uint32 RegisteredExternalApps; + CFE_ES_ResourceID_t LastAppId; CFE_ES_AppRecord_t AppTable[CFE_PLATFORM_ES_MAX_APPLICATIONS]; /* ** ES Shared Library Table */ uint32 RegisteredLibs; + CFE_ES_ResourceID_t LastLibId; CFE_ES_LibRecord_t LibTable[CFE_PLATFORM_ES_MAX_LIBRARIES]; /* ** ES Generic Counters Table */ + CFE_ES_ResourceID_t LastCounterId; CFE_ES_GenCounterRecord_t CounterTable[CFE_PLATFORM_ES_MAX_GEN_COUNTERS]; /* @@ -170,6 +148,7 @@ typedef struct /* ** Memory Pools */ + CFE_ES_ResourceID_t LastMemPoolId; CFE_ES_MemPoolRecord_t MemPoolTable[CFE_PLATFORM_ES_MAX_MEMORY_POOLS]; } CFE_ES_Global_t; @@ -184,449 +163,9 @@ 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(CFE_ES_ResourceID_t AppID); - -/** - * @brief Locate the Library table entry correlating with a given Lib ID. - * - * This only returns a pointer to the table entry and does _not_ - * otherwise check/validate the entry. - * - * @param[in] LibID the Lib ID to locate - * @return pointer to Library Table entry for the given Lib ID - */ -extern CFE_ES_LibRecord_t* CFE_ES_LocateLibRecordByID(CFE_ES_ResourceID_t LibID); - -/** - * @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(CFE_ES_ResourceID_t TaskID); - -/** - * @brief Locate the Counter table entry correlating with a given Counter ID. - * - * This only returns a pointer to the table entry and does _not_ - * otherwise check/validate the entry. - * - * @param[in] CounterID the Counter ID to locate - * @return pointer to Counter Table entry for the given Counter ID - */ -extern CFE_ES_GenCounterRecord_t* CFE_ES_LocateCounterRecordByID(CFE_ES_ResourceID_t CounterID); - -/** - * @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 CFE_ES_ResourceID_IsDefined(AppRecPtr->AppId); -} - -/** - * @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 CFE_ES_ResourceID_t CFE_ES_AppRecordGetID(const CFE_ES_AppRecord_t *AppRecPtr) -{ - return AppRecPtr->AppId; -} - -/** - * @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, CFE_ES_ResourceID_t AppID) -{ - AppRecPtr->AppId = AppID; -} - -/** - * @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->AppId = CFE_ES_RESOURCEID_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, CFE_ES_ResourceID_t AppID) -{ - return (AppRecPtr != NULL && CFE_ES_ResourceID_Equal(AppRecPtr->AppId, AppID)); -} - -/** - * @brief Check if a Library record is in use or free/empty - * - * This routine checks if the Lib 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] LibRecPtr pointer to Lib table entry - * @returns true if the entry is in use/configured, or false if it is free/empty - */ -static inline bool CFE_ES_LibRecordIsUsed(const CFE_ES_LibRecord_t *LibRecPtr) -{ - return CFE_ES_ResourceID_IsDefined(LibRecPtr->LibId); -} - -/** - * @brief Get the ID value from a Library table entry - * - * This routine converts the table entry back to an abstract ID. - * - * @param[in] LibRecPtr pointer to Lib table entry - * @returns LibID of entry - */ -static inline CFE_ES_ResourceID_t CFE_ES_LibRecordGetID(const CFE_ES_LibRecord_t *LibRecPtr) -{ - /* - * The initial implementation does not store the ID in the entry; - * the ID is simply the zero-based index into the table. - */ - return (LibRecPtr->LibId); -} - -/** - * @brief Marks a Library table entry as used (not free) - * - * This sets the internal field(s) within this entry, and marks - * it as being associated with the given Lib ID. - * - * @param[in] LibRecPtr pointer to Lib table entry - * @param[in] LibID the Lib ID of this entry - */ -static inline void CFE_ES_LibRecordSetUsed(CFE_ES_LibRecord_t *LibRecPtr, CFE_ES_ResourceID_t LibID) -{ - LibRecPtr->LibId = LibID; -} - -/** - * @brief Set a Library 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. - * - * @param[in] LibRecPtr pointer to Lib table entry - */ -static inline void CFE_ES_LibRecordSetFree(CFE_ES_LibRecord_t *LibRecPtr) -{ - LibRecPtr->LibId = CFE_ES_RESOURCEID_UNDEFINED; -} - -/** - * @brief Check if a Library record is a match for the given LibID - * - * This routine confirms that the previously-located record is valid - * and matches the expected Lib ID. - * - * As this dereferences fields within the record, global data must be - * locked prior to invoking this function. - * - * @param[in] LibRecPtr pointer to Lib table entry - * @param[in] LibID expected Lib ID - * @returns true if the entry matches the given Lib ID - */ -static inline bool CFE_ES_LibRecordIsMatch(const CFE_ES_LibRecord_t *LibRecPtr, CFE_ES_ResourceID_t LibID) -{ - return (LibRecPtr != NULL && CFE_ES_ResourceID_Equal(LibRecPtr->LibId, LibID)); -} - -/** - * @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 CFE_ES_ResourceID_t 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 CFE_ES_ResourceID_IsDefined(TaskRecPtr->TaskId); -} - -/** - * @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, CFE_ES_ResourceID_t TaskID) -{ - TaskRecPtr->TaskId = TaskID; -} - -/** - * @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 = CFE_ES_RESOURCEID_UNDEFINED; -} - -/** - * @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 - * @param[in] TaskID The expected task ID to verify - * @returns true if the entry matches the given task ID - */ -static inline bool CFE_ES_TaskRecordIsMatch(const CFE_ES_TaskRecord_t *TaskRecPtr, CFE_ES_ResourceID_t TaskID) -{ - return (TaskRecPtr != NULL && CFE_ES_ResourceID_Equal(TaskRecPtr->TaskId, TaskID)); -} - -/** - * @brief Check if an Counter record is in use or free/empty - * - * This routine checks if the Counter 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] CounterRecPtr pointer to Counter table entry - * @returns true if the entry is in use/configured, or false if it is free/empty - */ -static inline bool CFE_ES_CounterRecordIsUsed(const CFE_ES_GenCounterRecord_t *CounterRecPtr) -{ - return CFE_ES_ResourceID_IsDefined(CounterRecPtr->CounterId); -} - -/** - * @brief Get the ID value from an Counter table entry - * - * This routine converts the table entry back to an abstract ID. - * - * @param[in] CounterRecPtr pointer to Counter table entry - * @returns CounterID of entry - */ -static inline CFE_ES_ResourceID_t CFE_ES_CounterRecordGetID(const CFE_ES_GenCounterRecord_t *CounterRecPtr) -{ - return CounterRecPtr->CounterId; -} - -/** - * @brief Marks an Counter table entry as used (not free) - * - * This sets the internal field(s) within this entry, and marks - * it as being associated with the given Counter ID. - * - * As this dereferences fields within the record, global data must be - * locked prior to invoking this function. - * - * @param[in] CounterRecPtr pointer to Counter table entry - * @param[in] CounterID the Counter ID of this entry - */ -static inline void CFE_ES_CounterRecordSetUsed(CFE_ES_GenCounterRecord_t *CounterRecPtr, CFE_ES_ResourceID_t CounterID) -{ - CounterRecPtr->CounterId = CounterID; -} - -/** - * @brief Set an Counter 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] CounterRecPtr pointer to Counter table entry - */ -static inline void CFE_ES_CounterRecordSetFree(CFE_ES_GenCounterRecord_t *CounterRecPtr) -{ - CounterRecPtr->CounterId = CFE_ES_RESOURCEID_UNDEFINED; -} - -/** - * @brief Check if an Counter record is a match for the given CounterID - * - * This routine confirms that the previously-located record is valid - * and matches the expected Counter ID. - * - * As this dereferences fields within the record, global data must be - * locked prior to invoking this function. - * - * @param[in] CounterRecPtr pointer to Counter table entry - * @param[in] CounterID expected Counter ID - * @returns true if the entry matches the given Counter ID - */ -static inline bool CFE_ES_CounterRecordIsMatch(const CFE_ES_GenCounterRecord_t *CounterRecPtr, CFE_ES_ResourceID_t CounterID) -{ - return (CounterRecPtr != NULL && CFE_ES_ResourceID_Equal(CounterRecPtr->CounterId, CounterID)); -} - -/** - * 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); - -/** - * @brief Convert an ES Task ID to an OSAL task ID - * - * Task IDs created via CFE ES are also OSAL task IDs, but technically - * do refer to a different scope and therefore have a different type - * to represent them. - * - * This function facilitates converting between the types. - * - * @note Currently the numeric values are the same and can be interchanged - * for backward compatibility, however they may diverge in a future version. - * New code should not assume equivalence between OSAL and ES task IDs. - * - * @sa CFE_ES_ResourceID_FromOSAL - * - * @param[in] id The ES task ID - * @returns The OSAL task ID - */ -osal_id_t CFE_ES_ResourceID_ToOSAL(CFE_ES_ResourceID_t id); - -/** - * @brief Convert an ES Task ID to an OSAL task ID - * - * Task IDs created via CFE ES are also OSAL task IDs, but technically - * do refer to a different scope and therefore have a different type - * to represent them. - * - * This function facilitates converting between the types. - * - * @note Currently the numeric values are the same and can be interchanged - * for backward compatibility, however they may diverge in a future version. - * New code should not assume equivalence between OSAL and ES task IDs. - * - * @sa CFE_ES_ResourceID_ToOSAL - * - * @param[in] id The OSAL task ID - * @returns The ES task ID - */ -CFE_ES_ResourceID_t CFE_ES_ResourceID_FromOSAL(osal_id_t id); - -/** - * @brief Internal routine to aid in converting an ES resource ID to an array index - - * @param[in] Serial The resource serial number (type info masked out) - * @param[in] TableSize The size of the internal table (MAX value) - * @param[out] Idx The output index - * @returns Status code, CFE_SUCCESS if successful. - */ -int32 CFE_ES_ResourceID_ToIndex_Internal(uint32 Serial, uint32 TableSize, uint32 *Idx); - /* ** Functions used to lock/unlock shared data */ -extern int32 CFE_ES_GetAppIDInternal(CFE_ES_ResourceID_t *AppIdPtr); extern void CFE_ES_LockSharedData(const char *FunctionName, int32 LineNumber); extern void CFE_ES_UnlockSharedData(const char *FunctionName, int32 LineNumber); diff --git a/fsw/cfe-core/src/es/cfe_es_mempool.c b/fsw/cfe-core/src/es/cfe_es_mempool.c index a4285a856..9c25d3ba7 100644 --- a/fsw/cfe-core/src/es/cfe_es_mempool.c +++ b/fsw/cfe-core/src/es/cfe_es_mempool.c @@ -43,6 +43,7 @@ #include "cfe_es.h" #include "cfe_es_task.h" #include "cfe_es_log.h" +#include "cfe_es_resource.h" /** * Macro that determines the native alignment requirement of a specific type @@ -161,7 +162,6 @@ int32 CFE_ES_PoolCreateEx(CFE_ES_MemHandle_t *PoolID, uint16 UseMutex ) { int32 Status; - uint32 Index; CFE_ES_MemHandle_t PendingID; CFE_ES_MemPoolRecord_t *PoolRecPtr; CFE_ES_MemOffset_t Alignment; @@ -215,25 +215,27 @@ int32 CFE_ES_PoolCreateEx(CFE_ES_MemHandle_t *PoolID, - /* - * Find an open slot in the Pool Table - */ - PendingID = CFE_ES_RESOURCEID_UNDEFINED; - PoolRecPtr = CFE_ES_Global.MemPoolTable; - CFE_ES_LockSharedData(__func__, __LINE__); - for (Index = 0; Index < CFE_PLATFORM_ES_MAX_MEMORY_POOLS; ++Index) + CFE_ES_LockSharedData(__func__,__LINE__); + + /* scan for a free slot */ + PendingID = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastMemPoolId, CFE_PLATFORM_ES_MAX_MEMORY_POOLS); + PoolRecPtr = CFE_ES_LocateMemPoolRecordByID(PendingID); + + if (PoolRecPtr == NULL) { - if (!CFE_ES_MemPoolRecordIsUsed(PoolRecPtr)) - { - /* reset/clear all contents */ - memset(PoolRecPtr, 0, sizeof(*PoolRecPtr)); - PendingID = CFE_ES_ResourceID_FromInteger(Index + CFE_ES_POOLID_BASE); - CFE_ES_MemPoolRecordSetUsed(PoolRecPtr, CFE_ES_RESOURCEID_RESERVED); - break; - } - ++PoolRecPtr; + CFE_ES_SysLogWrite_Unsync("ES Startup: No free MemPoolrary slots available\n"); + Status = CFE_ES_NO_RESOURCE_IDS_AVAILABLE; + } + else + { + /* Fully clear the entry, just in case of stale data */ + memset(PoolRecPtr, 0, sizeof(*PoolRecPtr)); + CFE_ES_MemPoolRecordSetUsed(PoolRecPtr, CFE_ES_RESOURCEID_RESERVED); + CFE_ES_Global.LastMemPoolId = PendingID; + Status = CFE_SUCCESS; } - CFE_ES_UnlockSharedData(__func__, __LINE__); + + CFE_ES_UnlockSharedData(__func__,__LINE__); /* * If no open resource ID was found, return now. @@ -242,14 +244,19 @@ int32 CFE_ES_PoolCreateEx(CFE_ES_MemHandle_t *PoolID, * must continue to the end of this function where the ID is freed * if not fully successful. */ - if (!CFE_ES_ResourceID_IsDefined(PendingID)) + if (Status != CFE_SUCCESS) { - return CFE_ES_NO_RESOURCE_IDS_AVAILABLE; + return Status; } Alignment = ALIGN_OF(CFE_ES_PoolAlign_t); /* memory mapped pools should be aligned */ if (Alignment < CFE_PLATFORM_ES_MEMPOOL_ALIGN_SIZE_MIN) { + /* + * Note about path coverage testing - depending on the + * system architecture and configuration this line may be + * unreachable. This is OK. + */ Alignment = CFE_PLATFORM_ES_MEMPOOL_ALIGN_SIZE_MIN; } @@ -356,7 +363,7 @@ int32 CFE_ES_PoolDelete(CFE_ES_MemHandle_t PoolID) else { MutexId = OS_OBJECT_ID_UNDEFINED; - Status = CFE_ES_ERR_MEM_HANDLE; + Status = CFE_ES_ERR_RESOURCEID_NOT_VALID; } CFE_ES_UnlockSharedData(__func__, __LINE__); @@ -408,7 +415,7 @@ int32 CFE_ES_GetPoolBuf(uint32 **BufPtr, CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:Bad handle(0x%08lX) AppId=%lu\n", CFE_ES_ResourceID_ToInteger(Handle), CFE_ES_ResourceID_ToInteger(AppId)); - return(CFE_ES_ERR_MEM_HANDLE); + return(CFE_ES_ERR_RESOURCEID_NOT_VALID); } /* @@ -467,7 +474,7 @@ int32 CFE_ES_GetPoolBufInfo(CFE_ES_MemHandle_t Handle, /* basic sanity check */ if (!CFE_ES_MemPoolRecordIsMatch(PoolRecPtr, Handle)) { - return(CFE_ES_ERR_MEM_HANDLE); + return(CFE_ES_ERR_RESOURCEID_NOT_VALID); } /* @@ -524,7 +531,7 @@ int32 CFE_ES_PutPoolBuf(CFE_ES_MemHandle_t Handle, CFE_ES_WriteToSysLog("CFE_ES:putPoolBuf err:Invalid Memory Handle (0x%08lX).\n", CFE_ES_ResourceID_ToInteger(Handle)); - return(CFE_ES_ERR_MEM_HANDLE); + return(CFE_ES_ERR_RESOURCEID_NOT_VALID); } /* @@ -602,7 +609,7 @@ int32 CFE_ES_GetMemPoolStats(CFE_ES_MemPoolStats_t *BufPtr, CFE_ES_GetAppID(&AppId); CFE_ES_WriteToSysLog("CFE_ES:getMemPoolStats err:Bad handle(0x%08lX) AppId=%lu\n", CFE_ES_ResourceID_ToInteger(Handle), CFE_ES_ResourceID_ToInteger(AppId)); - return(CFE_ES_ERR_MEM_HANDLE); + return(CFE_ES_ERR_RESOURCEID_NOT_VALID); } /* diff --git a/fsw/cfe-core/src/es/cfe_es_resource.c b/fsw/cfe-core/src/es/cfe_es_resource.c new file mode 100644 index 000000000..e51867277 --- /dev/null +++ b/fsw/cfe-core/src/es/cfe_es_resource.c @@ -0,0 +1,433 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +/* +** File: +** cfe_es_resource.c +** +** Purpose: +** Function definitions related to CFE resource management +** +** References: +** Flight Software Branch C Coding Standard Version 1.0a +** cFE Flight Software Application Developers Guide +*/ + +/* +** Includes +*/ +#include +#include +#include + +#include "cfe_platform_cfg.h" +#include "cfe_es_resource.h" + + +/*********************************************************************/ +/* + * CFE_ES_ResourceID_ToIndex_Internal + * + * For complete API information, see prototype in header + */ +int32 CFE_ES_ResourceID_ToIndex_Internal(uint32 Serial, uint32 TableSize, uint32 *Idx) +{ + if (Idx == NULL) + { + return CFE_ES_ERR_BUFFER; + } + + if (Serial > CFE_ES_RESOURCEID_MAX) + { + return CFE_ES_ERR_RESOURCEID_NOT_VALID; + } + + *Idx = Serial % TableSize; + return CFE_SUCCESS; +} + + +/*********************************************************************/ +/* + * CFE_ES_ResourceID_ToOSAL + * + * For complete API information, see prototype in header + */ +osal_id_t CFE_ES_ResourceID_ToOSAL(CFE_ES_ResourceID_t id) +{ + unsigned long val = CFE_ES_ResourceID_ToInteger(id); + return OS_ObjectIdFromInteger(val); +} + +/*********************************************************************/ +/* + * CFE_ES_ResourceID_FromOSAL + * + * For complete API information, see prototype in header + */ +CFE_ES_ResourceID_t CFE_ES_ResourceID_FromOSAL(osal_id_t id) +{ + unsigned long val = OS_ObjectIdToInteger(id); + return CFE_ES_ResourceID_FromInteger(val); +} + +/*********************************************************************/ +/* + * CFE_ES_FindNextAvailableId + * + * For complete API information, see prototype in header + */ +CFE_ES_ResourceID_t CFE_ES_FindNextAvailableId(CFE_ES_ResourceID_t StartId, uint32 TableSize) +{ + uint32 Serial; + uint32 Count; + uint32 ResourceType; + CFE_ES_ResourceID_t CheckId; + bool IsTaken; + + ResourceType = CFE_ES_ResourceID_ToInteger(StartId); + Serial = ResourceType & CFE_ES_RESOURCEID_MAX; + ResourceType -= Serial; + Count = TableSize; + IsTaken = true; + + do + { + if (Count == 0) + { + CheckId = CFE_ES_RESOURCEID_UNDEFINED; + break; + } + + --Count; + ++Serial; + if (Serial >= CFE_ES_RESOURCEID_MAX) + { + Serial %= TableSize; + } + CheckId = CFE_ES_ResourceID_FromInteger(ResourceType + Serial); + + switch (ResourceType) + { + case CFE_ES_APPID_BASE: + IsTaken = CFE_ES_AppRecordIsUsed(CFE_ES_LocateAppRecordByID(CheckId)); + break; + case CFE_ES_LIBID_BASE: + IsTaken = CFE_ES_LibRecordIsUsed(CFE_ES_LocateLibRecordByID(CheckId)); + break; + case CFE_ES_COUNTID_BASE: + IsTaken = CFE_ES_CounterRecordIsUsed(CFE_ES_LocateCounterRecordByID(CheckId)); + break; + case CFE_ES_POOLID_BASE: + IsTaken = CFE_ES_MemPoolRecordIsUsed(CFE_ES_LocateMemPoolRecordByID(CheckId)); + break; + case CFE_ES_CDSBLOCKID_BASE: + IsTaken = CFE_ES_CDSBlockRecordIsUsed(CFE_ES_LocateCDSBlockRecordByID(CheckId)); + break; + default: + /* do nothing, should never happen */ + break; + } + } + while (IsTaken); + + return CheckId; +} + +/*********************************************************************/ +/* + * CFE_ES_LocateAppRecordByName + * + * For complete API information, see prototype in header + */ +CFE_ES_AppRecord_t *CFE_ES_LocateAppRecordByName(const char *Name) +{ + CFE_ES_AppRecord_t *AppRecPtr; + uint32 Count; + + /* + ** Search the Application table for an app with a matching name. + */ + AppRecPtr = CFE_ES_Global.AppTable; + Count = CFE_PLATFORM_ES_MAX_APPLICATIONS; + while ( true ) + { + if ( Count == 0 ) + { + AppRecPtr = NULL; + break; + } + if ( CFE_ES_AppRecordIsUsed(AppRecPtr) && + strcmp(Name, CFE_ES_AppRecordGetName(AppRecPtr)) == 0 ) + { + break; + } + + ++AppRecPtr; + --Count; + } + + return AppRecPtr; + +} /* End of CFE_ES_LocateAppRecordByName() */ + +/*********************************************************************/ +/* + * CFE_ES_LocateLibRecordByName + * + * For complete API information, see prototype in header + */ +CFE_ES_LibRecord_t *CFE_ES_LocateLibRecordByName(const char *Name) +{ + CFE_ES_LibRecord_t *LibRecPtr; + uint32 Count; + + /* + ** Search the Library table for a library with a matching name. + */ + LibRecPtr = CFE_ES_Global.LibTable; + Count = CFE_PLATFORM_ES_MAX_LIBRARIES; + while ( true ) + { + if ( Count == 0 ) + { + LibRecPtr = NULL; + break; + } + if ( CFE_ES_LibRecordIsUsed(LibRecPtr) && + strcmp(Name, CFE_ES_LibRecordGetName(LibRecPtr)) == 0 ) + { + break; + } + + ++LibRecPtr; + --Count; + } + + return LibRecPtr; + +} /* End of CFE_ES_LocateLibRecordByName() */ + + +/*********************************************************************/ +/* + * CFE_ES_LocateCounterRecordByName + * + * For complete API information, see prototype in header + */ +CFE_ES_GenCounterRecord_t *CFE_ES_LocateCounterRecordByName(const char *Name) +{ + CFE_ES_GenCounterRecord_t *CounterRecPtr; + uint32 Count; + + /* + ** Search the Counter table for a matching name. + */ + CounterRecPtr = CFE_ES_Global.CounterTable; + Count = CFE_PLATFORM_ES_MAX_GEN_COUNTERS; + while ( true ) + { + if ( Count == 0 ) + { + CounterRecPtr = NULL; + break; + } + if ( CFE_ES_CounterRecordIsUsed(CounterRecPtr) && + strcmp(Name, CFE_ES_CounterRecordGetName(CounterRecPtr)) == 0 ) + { + break; + } + + ++CounterRecPtr; + --Count; + } + + return CounterRecPtr; +} + + +/*********************************************************************/ +/* + * CFE_ES_LocateAppRecordByID + * + * For complete API information, see prototype in header + */ +CFE_ES_AppRecord_t *CFE_ES_LocateAppRecordByID(CFE_ES_ResourceID_t 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; +} + +/*********************************************************************/ +/* + * CFE_ES_LocateLibRecordByID + * + * For complete API information, see prototype in header + */ +CFE_ES_LibRecord_t* CFE_ES_LocateLibRecordByID(CFE_ES_ResourceID_t LibID) +{ + CFE_ES_LibRecord_t *LibRecPtr; + uint32 Idx; + + if (CFE_ES_LibID_ToIndex(LibID, &Idx) == CFE_SUCCESS) + { + LibRecPtr = &CFE_ES_Global.LibTable[Idx]; + } + else + { + LibRecPtr = NULL; + } + + return LibRecPtr; +} + +/*********************************************************************/ +/* + * CFE_ES_LocateTaskRecordByID + * + * For complete API information, see prototype in header + */ +CFE_ES_TaskRecord_t *CFE_ES_LocateTaskRecordByID(CFE_ES_ResourceID_t 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; +} + +/*********************************************************************/ +/* + * CFE_ES_LocateCounterRecordByID + * + * For complete API information, see prototype in header + */ +CFE_ES_GenCounterRecord_t* CFE_ES_LocateCounterRecordByID(CFE_ES_ResourceID_t CounterID) +{ + CFE_ES_GenCounterRecord_t *CounterRecPtr; + uint32 Idx; + + if (CFE_ES_CounterID_ToIndex(CounterID, &Idx) == CFE_SUCCESS) + { + CounterRecPtr = &CFE_ES_Global.CounterTable[Idx]; + } + else + { + CounterRecPtr = NULL; + } + + return CounterRecPtr; +} + +/*********************************************************************/ +/* + * CFE_ES_GetTaskRecordByContext + * + * For complete API information, see prototype in header + * + * 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; + CFE_ES_ResourceID_t TaskID; + + /* + ** Use the OS task ID to get the ES task record + */ + TaskID = CFE_ES_ResourceID_FromOSAL(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_GetAppRecordByContext + * + * For complete API information, see prototype in header + */ +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; +} + + diff --git a/fsw/cfe-core/src/es/cfe_es_resource.h b/fsw/cfe-core/src/es/cfe_es_resource.h new file mode 100644 index 000000000..9ca10533f --- /dev/null +++ b/fsw/cfe-core/src/es/cfe_es_resource.h @@ -0,0 +1,593 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +/** + * \file cfe_es_resource.h + * + * Contains basic prototypes and definitions related to CFE ES resource + * management and related resource IDs. + * + * A CFE ES Resource ID is a common way to identify CFE-managed resources such + * as apps, tasks, counters, memory pools, CDS blocks, and other entities. + */ + +#ifndef CFE_ES_RESOURCE_H +#define CFE_ES_RESOURCE_H + +/* +** Include Files +*/ +#include "cfe_es_global.h" + +/* +** Defines +*/ + +/* + * Limits/definitions related to CFE_ES_ResourceID_t values. + * + * Defining based on OSAL ID values makes this object a superset of + * the OSAL ID type, such that OSAL IDs can be represented as ES resource IDs + * and not conflict with/alias each other. + * + * NOTE: This reflects a bit if "inside knowledge" about how OSAL IDs are + * constructed. The overlap between OSAL IDs and ES IDs may not always be + * consistent, and they can diverge in a future version. + */ +#define CFE_ES_RESOURCEID_SHIFT OS_OBJECT_TYPE_SHIFT +#define CFE_ES_RESOURCEID_MAX ((1 << CFE_ES_RESOURCEID_SHIFT)-1) +#define CFE_ES_RESOURCEID_MARK (0x02000000) + +#define CFE_ES_APPID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+1) << CFE_ES_RESOURCEID_SHIFT)) +#define CFE_ES_LIBID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+2) << CFE_ES_RESOURCEID_SHIFT)) +#define CFE_ES_COUNTID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+3) << CFE_ES_RESOURCEID_SHIFT)) +#define CFE_ES_POOLID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+4) << CFE_ES_RESOURCEID_SHIFT)) +#define CFE_ES_CDSBLOCKID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+5) << CFE_ES_RESOURCEID_SHIFT)) + + +/** + * @brief Locate the next resource ID which does not map to an in-use table entry + * + * This begins searching from StartId which should be the most recently issued ID + * for the resource category. This will then search for the next ID which does + * _not_ map to a table entry that is in use. That is, it does not alias any + * valid ID when converted to an array index. + * + * returns an undefined ID value if no open slots are available + * + * @param[in] StartId the last issued ID for the resource category (app, lib, etc). + * @returns Next ID value which does not map to a valid entry + * @retval #CFE_ES_RESOURCEID_UNDEFINED if no open slots. + * + */ +CFE_ES_ResourceID_t CFE_ES_FindNextAvailableId(CFE_ES_ResourceID_t StartId, uint32 TableSize); + + +/** + * @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(CFE_ES_ResourceID_t AppID); + +/** + * @brief Locate the Library table entry correlating with a given Lib ID. + * + * This only returns a pointer to the table entry and does _not_ + * otherwise check/validate the entry. + * + * @param[in] LibID the Lib ID to locate + * @return pointer to Library Table entry for the given Lib ID + */ +extern CFE_ES_LibRecord_t* CFE_ES_LocateLibRecordByID(CFE_ES_ResourceID_t LibID); + +/** + * @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(CFE_ES_ResourceID_t TaskID); + +/** + * @brief Locate the Counter table entry correlating with a given Counter ID. + * + * This only returns a pointer to the table entry and does _not_ + * otherwise check/validate the entry. + * + * @param[in] CounterID the Counter ID to locate + * @return pointer to Counter Table entry for the given Counter ID + */ +extern CFE_ES_GenCounterRecord_t* CFE_ES_LocateCounterRecordByID(CFE_ES_ResourceID_t CounterID); + +/** + * @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 CFE_ES_ResourceID_IsDefined(AppRecPtr->AppId); +} + +/** + * @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 CFE_ES_ResourceID_t CFE_ES_AppRecordGetID(const CFE_ES_AppRecord_t *AppRecPtr) +{ + return AppRecPtr->AppId; +} + +/** + * @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, CFE_ES_ResourceID_t AppID) +{ + AppRecPtr->AppId = AppID; +} + +/** + * @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->AppId = CFE_ES_RESOURCEID_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, CFE_ES_ResourceID_t AppID) +{ + return (AppRecPtr != NULL && CFE_ES_ResourceID_Equal(AppRecPtr->AppId, AppID)); +} + +/** + * @brief Obtain the name associated with the Application record + * + * Returns the name field from within the Application record + * + * @param[in] AppRecPtr pointer to App table entry + * @returns Pointer to Application name + */ +static inline const char* CFE_ES_AppRecordGetName(const CFE_ES_AppRecord_t *AppRecPtr) +{ + return AppRecPtr->StartParams.Name; +} + + + +/** + * @brief Check if a Library record is in use or free/empty + * + * This routine checks if the Lib 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] LibRecPtr pointer to Lib table entry + * @returns true if the entry is in use/configured, or false if it is free/empty + */ +static inline bool CFE_ES_LibRecordIsUsed(const CFE_ES_LibRecord_t *LibRecPtr) +{ + return CFE_ES_ResourceID_IsDefined(LibRecPtr->LibId); +} + +/** + * @brief Get the ID value from a Library table entry + * + * This routine converts the table entry back to an abstract ID. + * + * @param[in] LibRecPtr pointer to Lib table entry + * @returns LibID of entry + */ +static inline CFE_ES_ResourceID_t CFE_ES_LibRecordGetID(const CFE_ES_LibRecord_t *LibRecPtr) +{ + /* + * The initial implementation does not store the ID in the entry; + * the ID is simply the zero-based index into the table. + */ + return (LibRecPtr->LibId); +} + +/** + * @brief Marks a Library table entry as used (not free) + * + * This sets the internal field(s) within this entry, and marks + * it as being associated with the given Lib ID. + * + * @param[in] LibRecPtr pointer to Lib table entry + * @param[in] LibID the Lib ID of this entry + */ +static inline void CFE_ES_LibRecordSetUsed(CFE_ES_LibRecord_t *LibRecPtr, CFE_ES_ResourceID_t LibID) +{ + LibRecPtr->LibId = LibID; +} + +/** + * @brief Set a Library 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. + * + * @param[in] LibRecPtr pointer to Lib table entry + */ +static inline void CFE_ES_LibRecordSetFree(CFE_ES_LibRecord_t *LibRecPtr) +{ + LibRecPtr->LibId = CFE_ES_RESOURCEID_UNDEFINED; +} + +/** + * @brief Check if a Library record is a match for the given LibID + * + * This routine confirms that the previously-located record is valid + * and matches the expected Lib ID. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] LibRecPtr pointer to Lib table entry + * @param[in] LibID expected Lib ID + * @returns true if the entry matches the given Lib ID + */ +static inline bool CFE_ES_LibRecordIsMatch(const CFE_ES_LibRecord_t *LibRecPtr, CFE_ES_ResourceID_t LibID) +{ + return (LibRecPtr != NULL && CFE_ES_ResourceID_Equal(LibRecPtr->LibId, LibID)); +} + +/** + * @brief Obtain the name associated with the Library record + * + * Returns the name field from within the Library record + * + * @param[in] LibRecPtr pointer to Lib table entry + * @returns Pointer to Library name + */ +static inline const char* CFE_ES_LibRecordGetName(const CFE_ES_LibRecord_t *LibRecPtr) +{ + return LibRecPtr->LibName; +} + + + +/** + * @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 CFE_ES_ResourceID_t 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 CFE_ES_ResourceID_IsDefined(TaskRecPtr->TaskId); +} + +/** + * @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, CFE_ES_ResourceID_t TaskID) +{ + TaskRecPtr->TaskId = TaskID; +} + +/** + * @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 = CFE_ES_RESOURCEID_UNDEFINED; +} + +/** + * @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 + * @param[in] TaskID The expected task ID to verify + * @returns true if the entry matches the given task ID + */ +static inline bool CFE_ES_TaskRecordIsMatch(const CFE_ES_TaskRecord_t *TaskRecPtr, CFE_ES_ResourceID_t TaskID) +{ + return (TaskRecPtr != NULL && CFE_ES_ResourceID_Equal(TaskRecPtr->TaskId, TaskID)); +} + +/** + * @brief Obtain the name associated with the Task record + * + * Returns the name field from within the Task record + * + * @param[in] TaskRecPtr pointer to Task table entry + * @returns Pointer to Task name + */ +static inline const char* CFE_ES_TaskRecordGetName(const CFE_ES_TaskRecord_t *TaskRecPtr) +{ + return TaskRecPtr->TaskName; +} + + + +/** + * @brief Check if an Counter record is in use or free/empty + * + * This routine checks if the Counter 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] CounterRecPtr pointer to Counter table entry + * @returns true if the entry is in use/configured, or false if it is free/empty + */ +static inline bool CFE_ES_CounterRecordIsUsed(const CFE_ES_GenCounterRecord_t *CounterRecPtr) +{ + return CFE_ES_ResourceID_IsDefined(CounterRecPtr->CounterId); +} + +/** + * @brief Get the ID value from an Counter table entry + * + * This routine converts the table entry back to an abstract ID. + * + * @param[in] CounterRecPtr pointer to Counter table entry + * @returns CounterID of entry + */ +static inline CFE_ES_ResourceID_t CFE_ES_CounterRecordGetID(const CFE_ES_GenCounterRecord_t *CounterRecPtr) +{ + return CounterRecPtr->CounterId; +} + +/** + * @brief Marks an Counter table entry as used (not free) + * + * This sets the internal field(s) within this entry, and marks + * it as being associated with the given Counter ID. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] CounterRecPtr pointer to Counter table entry + * @param[in] CounterID the Counter ID of this entry + */ +static inline void CFE_ES_CounterRecordSetUsed(CFE_ES_GenCounterRecord_t *CounterRecPtr, CFE_ES_ResourceID_t CounterID) +{ + CounterRecPtr->CounterId = CounterID; +} + +/** + * @brief Set an Counter 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] CounterRecPtr pointer to Counter table entry + */ +static inline void CFE_ES_CounterRecordSetFree(CFE_ES_GenCounterRecord_t *CounterRecPtr) +{ + CounterRecPtr->CounterId = CFE_ES_RESOURCEID_UNDEFINED; +} + +/** + * @brief Check if an Counter record is a match for the given CounterID + * + * This routine confirms that the previously-located record is valid + * and matches the expected Counter ID. + * + * As this dereferences fields within the record, global data must be + * locked prior to invoking this function. + * + * @param[in] CounterRecPtr pointer to Counter table entry + * @param[in] CounterID expected Counter ID + * @returns true if the entry matches the given Counter ID + */ +static inline bool CFE_ES_CounterRecordIsMatch(const CFE_ES_GenCounterRecord_t *CounterRecPtr, CFE_ES_ResourceID_t CounterID) +{ + return (CounterRecPtr != NULL && CFE_ES_ResourceID_Equal(CounterRecPtr->CounterId, CounterID)); +} + +/** + * @brief Obtain the name associated with the counter record + * + * Returns the name field from within the counter record + * + * @param[in] CounterRecPtr pointer to Counter table entry + * @returns Pointer to counter name + */ +static inline const char* CFE_ES_CounterRecordGetName(const CFE_ES_GenCounterRecord_t *CounterRecPtr) +{ + return CounterRecPtr->CounterName; +} + + +/** + * 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); + +/** + * @brief Convert an ES Task ID to an OSAL task ID + * + * Task IDs created via CFE ES are also OSAL task IDs, but technically + * do refer to a different scope and therefore have a different type + * to represent them. + * + * This function facilitates converting between the types. + * + * @note Currently the numeric values are the same and can be interchanged + * for backward compatibility, however they may diverge in a future version. + * New code should not assume equivalence between OSAL and ES task IDs. + * + * @sa CFE_ES_ResourceID_FromOSAL + * + * @param[in] id The ES task ID + * @returns The OSAL task ID + */ +osal_id_t CFE_ES_ResourceID_ToOSAL(CFE_ES_ResourceID_t id); + +/** + * @brief Convert an ES Task ID to an OSAL task ID + * + * Task IDs created via CFE ES are also OSAL task IDs, but technically + * do refer to a different scope and therefore have a different type + * to represent them. + * + * This function facilitates converting between the types. + * + * @note Currently the numeric values are the same and can be interchanged + * for backward compatibility, however they may diverge in a future version. + * New code should not assume equivalence between OSAL and ES task IDs. + * + * @sa CFE_ES_ResourceID_ToOSAL + * + * @param[in] id The OSAL task ID + * @returns The ES task ID + */ +CFE_ES_ResourceID_t CFE_ES_ResourceID_FromOSAL(osal_id_t id); + +/** + * @brief Internal routine to aid in converting an ES resource ID to an array index + + * @param[in] Serial The resource serial number (type info masked out) + * @param[in] TableSize The size of the internal table (MAX value) + * @param[out] Idx The output index + * @returns Status code, CFE_SUCCESS if successful. + */ +int32 CFE_ES_ResourceID_ToIndex_Internal(uint32 Serial, uint32 TableSize, uint32 *Idx); + +/* + * Internal functions to perform name based resource lookups + * + * These functions do not lock, they must only be used internally by ES when + * the lock is already held. + */ +CFE_ES_AppRecord_t *CFE_ES_LocateAppRecordByName(const char *Name); +CFE_ES_LibRecord_t *CFE_ES_LocateLibRecordByName(const char *Name); +CFE_ES_TaskRecord_t *CFE_ES_LocateTaskRecordByName(const char *Name); +CFE_ES_GenCounterRecord_t *CFE_ES_LocateCounterRecordByName(const char *Name); + + +#endif /* CFE_ES_RESOURCE_H */ diff --git a/fsw/cfe-core/src/es/cfe_es_start.c b/fsw/cfe-core/src/es/cfe_es_start.c index d1025e163..9f8c8eb66 100644 --- a/fsw/cfe-core/src/es/cfe_es_start.c +++ b/fsw/cfe-core/src/es/cfe_es_start.c @@ -40,6 +40,7 @@ #include "private/cfe_private.h" #include "cfe_es.h" #include "cfe_es_global.h" +#include "cfe_es_resource.h" #include "cfe_es_start.h" #include "cfe_es_apps.h" #include "cfe_es_log.h" @@ -83,11 +84,14 @@ CFE_ES_ResetData_t *CFE_ES_ResetDataPtr; */ void CFE_ES_Main(uint32 StartType, uint32 StartSubtype, uint32 ModeId, const char *StartFilePath ) { - uint32 i; int32 ReturnCode; - CFE_ES_AppRecord_t *AppRecPtr; - CFE_ES_TaskRecord_t *TaskRecPtr; - CFE_ES_GenCounterRecord_t *CountRecPtr; + + /* + * Clear the entire global data structure. + * This also takes care of setting all resource IDs on all table entries + * to be "undefined" (not in use). + */ + memset(&CFE_ES_Global, 0, sizeof(CFE_ES_Global)); /* ** Indicate that the CFE is the earliest initialization state @@ -176,37 +180,12 @@ void CFE_ES_Main(uint32 StartType, uint32 StartSubtype, uint32 ModeId, const cha CFE_PSP_AttachExceptions(); /* - ** 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_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_TaskRecordSetFree(TaskRecPtr); - ++TaskRecPtr; - } - - /* - ** Initialize the ES Generic Counter Table - ** to mark all entries as unused. + ** Initialize the Last Id */ - CountRecPtr = CFE_ES_Global.CounterTable; - for ( i = 0; i < CFE_PLATFORM_ES_MAX_GEN_COUNTERS; i++ ) - { - CFE_ES_CounterRecordSetFree(CountRecPtr); - ++CountRecPtr; - } + CFE_ES_Global.LastAppId = CFE_ES_ResourceID_FromInteger(CFE_ES_APPID_BASE); + CFE_ES_Global.LastLibId = CFE_ES_ResourceID_FromInteger(CFE_ES_LIBID_BASE); + CFE_ES_Global.LastCounterId = CFE_ES_ResourceID_FromInteger(CFE_ES_COUNTID_BASE); + CFE_ES_Global.LastMemPoolId = CFE_ES_ResourceID_FromInteger(CFE_ES_POOLID_BASE); /* ** Indicate that the CFE core is now starting up / going multi-threaded @@ -773,12 +752,11 @@ void CFE_ES_InitializeFileSystems(uint32 StartType) void CFE_ES_CreateObjects(void) { int32 ReturnCode; - bool AppSlotFound; uint16 i; - uint16 j; osal_id_t OsalId; CFE_ES_AppRecord_t *AppRecPtr; CFE_ES_TaskRecord_t *TaskRecPtr; + CFE_ES_ResourceID_t PendingAppId; CFE_ES_WriteToSysLog("ES Startup: Starting Object Creation calls.\n"); @@ -792,36 +770,25 @@ 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++ ) + CFE_ES_LockSharedData(__func__,__LINE__); + + PendingAppId = CFE_ES_FindNextAvailableId(CFE_ES_Global.LastAppId, CFE_PLATFORM_ES_MAX_APPLICATIONS); + AppRecPtr = CFE_ES_LocateAppRecordByID(PendingAppId); + if (AppRecPtr != NULL) { - if ( !CFE_ES_AppRecordIsUsed(AppRecPtr) ) - { - AppSlotFound = true; - break; - } - ++AppRecPtr; + CFE_ES_AppRecordSetUsed(AppRecPtr, CFE_ES_RESOURCEID_RESERVED); } + CFE_ES_UnlockSharedData(__func__,__LINE__); + /* ** If a slot was found, create the application */ - if ( AppSlotFound == true ) + if (AppRecPtr != NULL) { CFE_ES_LockSharedData(__func__,__LINE__); - /* - ** Allocate and populate the ES_AppTable entry - */ - 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_AppRecordSetUsed(AppRecPtr, CFE_ES_ResourceID_FromInteger(j + CFE_ES_APPID_BASE)); - AppRecPtr->Type = CFE_ES_AppType_CORE; /* @@ -837,12 +804,6 @@ void CFE_ES_CreateObjects(void) AppRecPtr->StartParams.Priority = CFE_ES_ObjectTable[i].ObjectPriority; - /* - ** Fill out the Task Info - */ - 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 */ @@ -875,8 +836,8 @@ void CFE_ES_CreateObjects(void) } else { - AppRecPtr->TaskInfo.MainTaskId = CFE_ES_ResourceID_FromOSAL(OsalId); - TaskRecPtr = CFE_ES_LocateTaskRecordByID(AppRecPtr->TaskInfo.MainTaskId); + AppRecPtr->MainTaskId = CFE_ES_ResourceID_FromOSAL(OsalId); + TaskRecPtr = CFE_ES_LocateTaskRecordByID(AppRecPtr->MainTaskId); /* ** Allocate and populate the CFE_ES_Global.TaskTable entry @@ -886,14 +847,16 @@ void CFE_ES_CreateObjects(void) CFE_ES_SysLogWrite_Unsync("ES Startup: CFE_ES_Global.TaskTable record used error for App: %s, continuing.\n", CFE_ES_ObjectTable[i].ObjectName); } - 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_TaskRecordSetUsed(TaskRecPtr, AppRecPtr->MainTaskId); + TaskRecPtr->AppId = PendingAppId; + strncpy(TaskRecPtr->TaskName, CFE_ES_ObjectTable[i].ObjectName, sizeof(TaskRecPtr->TaskName)-1); + TaskRecPtr->TaskName[sizeof(TaskRecPtr->TaskName)-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))); + CFE_ES_ResourceID_ToInteger(PendingAppId)); + + CFE_ES_AppRecordSetUsed(AppRecPtr, PendingAppId); /* ** Increment the registered App and Registered External Task variables. diff --git a/fsw/cfe-core/src/es/cfe_es_task.c b/fsw/cfe-core/src/es/cfe_es_task.c index 3a1206274..3540b3f2a 100644 --- a/fsw/cfe-core/src/es/cfe_es_task.c +++ b/fsw/cfe-core/src/es/cfe_es_task.c @@ -1702,7 +1702,7 @@ int32 CFE_ES_DeleteCDSCmd(const CFE_ES_DeleteCDS_t *data) CFE_ES_TaskData.CommandErrorCounter++; } - else if (Status == CFE_ES_CDS_NOT_FOUND_ERR) + else if (Status == CFE_ES_ERR_NAME_NOT_FOUND) { CFE_EVS_SendEvent(CFE_ES_CDS_NAME_ERR_EID, CFE_EVS_EventType_ERROR, "Unable to locate '%s' in CDS Registry", LocalCdsName); diff --git a/fsw/cfe-core/src/inc/cfe_error.h b/fsw/cfe-core/src/inc/cfe_error.h index e5ca4179b..4a62d6ac0 100644 --- a/fsw/cfe-core/src/inc/cfe_error.h +++ b/fsw/cfe-core/src/inc/cfe_error.h @@ -284,20 +284,21 @@ typedef int32 CFE_Status_t; */ /** - * @brief Application ID Error + * @brief Resource ID is not valid * - * The given application ID does not reflect a currently active application. + * This error indicates that the passed in resource identifier + * (App ID, Lib ID, Counter ID, etc) did not validate. * */ -#define CFE_ES_ERR_APPID ((int32)0xc4000001) +#define CFE_ES_ERR_RESOURCEID_NOT_VALID ((int32)0xc4000001) /** - * @brief Application Name Error + * @brief Resource Name Error * - * There is no match for the given application name in the current application list. + * There is no match in the system for the given name. * */ -#define CFE_ES_ERR_APPNAME ((int32)0xc4000002) +#define CFE_ES_ERR_NAME_NOT_FOUND ((int32)0xc4000002) /** * @brief Invalid Pointer @@ -332,14 +333,6 @@ typedef int32 CFE_Status_t; */ #define CFE_ES_ERR_SYS_LOG_FULL ((int32)0xc4000006) -/** - * @brief Memory Handle Error - * - * The Memory Pool handle is invalid. - * - */ -#define CFE_ES_ERR_MEM_HANDLE ((int32)0xc4000007) - /** * @brief Memory Block Size Error * @@ -419,17 +412,6 @@ typedef int32 CFE_Status_t; #define CFE_ES_CDS_INVALID_SIZE ((int32)0xc4000010) -/** - * @brief CDS Registry Full - * - * The CDS Registry has as many entries in it as it can hold. The - * CDS Registry size can be adjusted with the #CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES - * macro defined in the cfe_platform_cfg.h file. - * - */ -#define CFE_ES_CDS_REGISTRY_FULL ((int32)0xc4000011) - - /** * @brief CDS Invalid * @@ -465,14 +447,6 @@ typedef int32 CFE_Status_t; */ #define CFE_ES_RST_ACCESS_ERR ((int32)0xc4000015) -/** - * @brief Task ID Error - * - * Occurs when the Task ID passed into a task-related API is invalid. - * - */ -#define CFE_ES_ERR_TASKID ((int32)0xc4000016) - /** * @brief Application Register Error * @@ -564,15 +538,6 @@ typedef int32 CFE_Status_t; */ #define CFE_ES_CDS_WRONG_TYPE_ERR ((int32)0xc4000020) -/** - * @brief CDS Not Found Error - * - * Occurs when a search of the Critical Data Store Registry does not find a - * critical data store with the specified name. - * - */ -#define CFE_ES_CDS_NOT_FOUND_ERR ((int32)0xc4000021) - /** * @brief CDS Owner Active Error * @@ -653,15 +618,6 @@ typedef int32 CFE_Status_t; #define CFE_ES_ERR_SYS_LOG_TRUNCATED ((int32)0x44000029) -/** - * @brief Resource ID is not valid - * - * This error indicates that the passed in resource identifier - * (App ID, Lib ID, Counter ID, etc) did not validate. - * - */ -#define CFE_ES_RESOURCE_ID_INVALID ((int32)0xc400002A) - /** * @brief Resource ID is not available * @@ -692,6 +648,14 @@ typedef int32 CFE_Status_t; #define CFE_ES_POOL_BOUNDS_ERROR ((int32)0xc400002D) +/** + * @brief Duplicate Name Error + * + * Resource creation failed due to the name already existing in the system. + * + */ +#define CFE_ES_ERR_DUPLICATE_NAME ((int32)0xc400002E) + /** * @brief Not Implemented * @@ -1439,4 +1403,16 @@ typedef int32 CFE_Status_t; #define CFE_TIME_CALLBACK_NOT_REGISTERED ((int32)0xce000004) /**@}*/ + +/* Compatibility for error names which have been updated */ +#ifndef CFE_OMIT_DEPRECATED_6_8 +#define CFE_ES_ERR_TASKID CFE_ES_ERR_RESOURCEID_NOT_VALID +#define CFE_ES_ERR_APPID CFE_ES_ERR_RESOURCEID_NOT_VALID +#define CFE_ES_ERR_MEM_HANDLE CFE_ES_ERR_RESOURCEID_NOT_VALID +#define CFE_ES_ERR_APPNAME CFE_ES_ERR_NAME_NOT_FOUND +#define CFE_ES_CDS_NOT_FOUND_ERR CFE_ES_ERR_NAME_NOT_FOUND +#define CFE_ES_CDS_REGISTRY_FULL CFE_ES_NO_RESOURCE_IDS_AVAILABLE +#endif + + #endif /* _cfe_error_ */ diff --git a/fsw/cfe-core/src/inc/cfe_es.h b/fsw/cfe-core/src/inc/cfe_es.h index 6c47987a6..ccf01e761 100644 --- a/fsw/cfe-core/src/inc/cfe_es.h +++ b/fsw/cfe-core/src/inc/cfe_es.h @@ -257,7 +257,8 @@ static inline bool CFE_ES_ResourceID_IsDefined(CFE_ES_ResourceID_t id) * @param[out] Idx Buffer where the calculated index will be stored * * @return Execution status, see @ref CFEReturnCodes - * @retval #CFE_SUCCESS @copybrief CFE_SUCCESS + * @retval #CFE_SUCCESS @copybrief CFE_SUCCESS + * @retval #CFE_ES_ERR_RESOURCEID_NOT_VALID @copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID */ CFE_Status_t CFE_ES_AppID_ToIndex(CFE_ES_ResourceID_t AppID, uint32 *Idx); @@ -281,7 +282,8 @@ CFE_Status_t CFE_ES_AppID_ToIndex(CFE_ES_ResourceID_t AppID, uint32 *Idx); * @param[out] Idx Buffer where the calculated index will be stored * * @return Execution status, see @ref CFEReturnCodes - * @retval #CFE_SUCCESS @copybrief CFE_SUCCESS + * @retval #CFE_SUCCESS @copybrief CFE_SUCCESS + * @retval #CFE_ES_ERR_RESOURCEID_NOT_VALID @copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID */ int32 CFE_ES_LibID_ToIndex(CFE_ES_ResourceID_t LibID, uint32 *Idx); @@ -305,10 +307,37 @@ int32 CFE_ES_LibID_ToIndex(CFE_ES_ResourceID_t LibID, uint32 *Idx); * @param[out] Idx Buffer where the calculated index will be stored * * @return Execution status, see @ref CFEReturnCodes - * @retval #CFE_SUCCESS @copybrief CFE_SUCCESS + * @retval #CFE_SUCCESS @copybrief CFE_SUCCESS + * @retval #CFE_ES_ERR_RESOURCEID_NOT_VALID @copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID */ CFE_Status_t CFE_ES_TaskID_ToIndex(CFE_ES_ResourceID_t TaskID, uint32 *Idx); +/** + * @brief Obtain an index value correlating to an ES Counter 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] Counter + * IDs will never overlap, but the index of an Counter 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 CounterID value. The caller should retain the original ID + * for future use. + * + * @param[in] CounterID Counter ID to convert + * @param[out] Idx Buffer where the calculated index will be stored + * + * @return Execution status, see @ref CFEReturnCodes + * @retval #CFE_SUCCESS @copybrief CFE_SUCCESS + * @retval #CFE_ES_ERR_RESOURCEID_NOT_VALID @copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID + */ +CFE_Status_t CFE_ES_CounterID_ToIndex(CFE_ES_ResourceID_t CounterID, uint32 *Idx); + + /** * \brief Application Information * @@ -801,9 +830,9 @@ int32 CFE_ES_GetResetType(uint32 *ResetSubtypePtr); ** ** ** \return Execution status, see \ref CFEReturnCodes -** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_APPID \copybrief CFE_ES_ERR_APPID -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID +** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** ** \sa #CFE_ES_GetResetType, #CFE_ES_GetAppIDByName, #CFE_ES_GetAppName, #CFE_ES_GetTaskInfo ** @@ -826,8 +855,9 @@ CFE_Status_t CFE_ES_GetAppID(CFE_ES_ResourceID_t *AppIdPtr); ** 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 +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID +** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** ******************************************************************************/ CFE_Status_t CFE_ES_GetTaskID(CFE_ES_ResourceID_t *TaskIdPtr); @@ -848,15 +878,40 @@ CFE_Status_t CFE_ES_GetTaskID(CFE_ES_ResourceID_t *TaskIdPtr); ** ** ** \return Execution status, see \ref CFEReturnCodes -** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_NAME_NOT_FOUND \copybrief CFE_ES_ERR_NAME_NOT_FOUND +** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** -** \sa #CFE_ES_GetResetType, #CFE_ES_GetAppID, #CFE_ES_GetAppName, #CFE_ES_GetTaskInfo +** \sa #CFE_ES_GetAppID, #CFE_ES_GetAppName, #CFE_ES_GetAppInfo ** ******************************************************************************/ CFE_Status_t CFE_ES_GetAppIDByName(CFE_ES_ResourceID_t *AppIdPtr, const char *AppName); +/*****************************************************************************/ +/** +** \brief Get a Library ID associated with a specified Library name +** +** \par Description +** This routine retrieves the cFE Library ID associated with a +** specified Library name. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \param[out] LibIdPtr Pointer to variable that is to receive the Library's ID. +** \param[in] LibName Pointer to null terminated character string containing a Library name. +** +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_NAME_NOT_FOUND \copybrief CFE_ES_ERR_NAME_NOT_FOUND +** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER +** +** \sa #CFE_ES_GetLibName +** +******************************************************************************/ +CFE_Status_t CFE_ES_GetLibIDByName(CFE_ES_ResourceID_t *LibIdPtr, const char *LibName); + /*****************************************************************************/ /** ** \brief Get an Application name for a specified Application ID @@ -866,12 +921,10 @@ CFE_Status_t CFE_ES_GetAppIDByName(CFE_ES_ResourceID_t *AppIdPtr, const char *Ap ** specified Application ID. ** ** \par Assumptions, External Events, and Notes: -** In the case of a failure (#CFE_ES_ERR_APPID), an empty string is returned. #CFE_ES_ERR_APPID -** will be returned if the specified Application ID (AppId) is invalid or not in use. +** In the case of a failure (#CFE_ES_ERR_RESOURCEID_NOT_VALID), an empty string is returned. ** -** \param[in, out] AppName Pointer to a character array of at least \c BufferLength in size that will -** be filled with the appropriate Application name. *AppName is the null terminated Application name of the Application associated with the -** specified Application ID +** \param[out] AppName Pointer to a character array of at least \c BufferLength in size that will +** be filled with the appropriate Application name. ** ** \param[in] AppId Application ID of Application whose name is being requested. ** @@ -881,14 +934,44 @@ CFE_Status_t CFE_ES_GetAppIDByName(CFE_ES_ResourceID_t *AppIdPtr, const char *Ap ** ** ** \return Execution status, see \ref CFEReturnCodes -** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_APPID \copybrief CFE_ES_ERR_APPID +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID ** -** \sa #CFE_ES_GetResetType, #CFE_ES_GetAppID, #CFE_ES_GetAppIDByName, #CFE_ES_GetTaskInfo +** \sa #CFE_ES_GetAppID, #CFE_ES_GetAppIDByName, #CFE_ES_GetAppInfo ** ******************************************************************************/ CFE_Status_t CFE_ES_GetAppName(char *AppName, CFE_ES_ResourceID_t AppId, uint32 BufferLength); +/*****************************************************************************/ +/** +** \brief Get a Library name for a specified Library ID +** +** \par Description +** This routine retrieves the cFE Library name associated with a +** specified Library ID. +** +** \par Assumptions, External Events, and Notes: +** In the case of a failure (#CFE_ES_ERR_RESOURCEID_NOT_VALID), an empty string is returned. +** +** \param[out] LibName Pointer to a character array of at least \c BufferLength in size that will +** be filled with the Library name. +** +** \param[in] LibId Library ID of Library whose name is being requested. +** +** \param[in] BufferLength The maximum number of characters, including the null terminator, that can be put +** into the \c LibName buffer. This routine will truncate the name to this length, +** if necessary. +** +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID +** +** \sa #CFE_ES_GetLibIDByName +** +******************************************************************************/ +CFE_Status_t CFE_ES_GetLibName(char *LibName, CFE_ES_ResourceID_t LibId, uint32 BufferLength); + /*****************************************************************************/ /** ** \brief Get Application Information given a specified App ID @@ -909,11 +992,11 @@ CFE_Status_t CFE_ES_GetAppName(char *AppName, CFE_ES_ResourceID_t AppId, uint32 ** ** ** \return Execution status, see \ref CFEReturnCodes -** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_APPID \copybrief CFE_ES_ERR_APPID -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID +** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** -** \sa #CFE_ES_GetResetType, #CFE_ES_GetAppID, #CFE_ES_GetAppIDByName, #CFE_ES_GetAppName +** \sa #CFE_ES_GetAppID, #CFE_ES_GetAppIDByName, #CFE_ES_GetAppName ** ******************************************************************************/ CFE_Status_t CFE_ES_GetAppInfo(CFE_ES_AppInfo_t *AppInfo, CFE_ES_ResourceID_t AppId); @@ -930,7 +1013,7 @@ CFE_Status_t CFE_ES_GetAppInfo(CFE_ES_AppInfo_t *AppInfo, CFE_ES_ResourceID_t Ap ** \par Assumptions, External Events, and Notes: ** None ** -** \param[in, out] TaskInfo Pointer to a \c CFE_ES_TaskInfo_t structure that holds the specific +** \param[out] TaskInfo Pointer to a \c CFE_ES_TaskInfo_t structure that holds the specific ** task information. *TaskInfo is the filled out \c CFE_ES_TaskInfo_t structure containing the ** Task Name, Parent App Name, Parent App ID among other fields. ** @@ -938,11 +1021,11 @@ CFE_Status_t CFE_ES_GetAppInfo(CFE_ES_AppInfo_t *AppInfo, CFE_ES_ResourceID_t Ap ** ** ** \return Execution status, see \ref CFEReturnCodes -** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_TASKID \copybrief CFE_ES_ERR_TASKID -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID +** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** -** \sa #CFE_ES_GetResetType, #CFE_ES_GetAppID, #CFE_ES_GetAppIDByName, #CFE_ES_GetAppName +** \sa #CFE_ES_GetTaskID, #CFE_ES_GetTaskIDByName, #CFE_ES_GetTaskName ** ******************************************************************************/ CFE_Status_t CFE_ES_GetTaskInfo(CFE_ES_TaskInfo_t *TaskInfo, CFE_ES_ResourceID_t TaskId); @@ -1017,6 +1100,61 @@ CFE_Status_t CFE_ES_CreateChildTask(CFE_ES_ResourceID_t *TaskIdPtr, uint32 Priority, uint32 Flags); +/*****************************************************************************/ +/** +** \brief Get a Task ID associated with a specified Task name +** +** \par Description +** This routine retrieves the cFE Task ID associated with a +** specified Task name. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \param[out] TaskIdPtr Pointer to variable that is to receive the Task's ID. +** \param[in] TaskName Pointer to null terminated character string containing an Task name. +** +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_NAME_NOT_FOUND \copybrief CFE_ES_ERR_NAME_NOT_FOUND +** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER +** +** \sa #CFE_ES_GetTaskName +** +******************************************************************************/ +CFE_Status_t CFE_ES_GetTaskIDByName(CFE_ES_ResourceID_t *TaskIdPtr, const char *TaskName); + +/*****************************************************************************/ +/** +** \brief Get a Task name for a specified Task ID +** +** \par Description +** This routine retrieves the cFE Task name associated with a +** specified Task ID. +** +** \par Assumptions, External Events, and Notes: +** In the case of a failure (#CFE_ES_ERR_RESOURCEID_NOT_VALID), an empty string is returned. +** +** \param[out] TaskName Pointer to a character array of at least \c BufferLength in size that will +** be filled with the Task name. +** +** \param[in] TaskId Task ID of Task whose name is being requested. +** +** \param[in] BufferLength The maximum number of characters, including the null terminator, that can be put +** into the \c TaskName buffer. This routine will truncate the name to this length, +** if necessary. +** +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID +** +** \sa #CFE_ES_GetTaskIDByName +** +******************************************************************************/ +CFE_Status_t CFE_ES_GetTaskName(char *TaskName, CFE_ES_ResourceID_t TaskId, uint32 BufferLength); + /*****************************************************************************/ /** ** \brief Deletes a task under an existing Application @@ -1174,6 +1312,62 @@ void CFE_ES_ProcessAsyncEvent(void); ******************************************************************************/ CFE_Status_t CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t BlockSize, const char *Name); +/*****************************************************************************/ +/** +** \brief Get a CDS Block ID associated with a specified CDS Block name +** +** \par Description +** This routine retrieves the CDS Block ID associated with a +** specified CDS Block name. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \param[out] BlockIdPtr Pointer to variable that is to receive the CDS Block ID. +** \param[in] BlockName Pointer to null terminated character string containing a CDS Block name. +** +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_NAME_NOT_FOUND \copybrief CFE_ES_ERR_NAME_NOT_FOUND +** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER +** +** \sa #CFE_ES_GetCDSBlockName +** +******************************************************************************/ +CFE_Status_t CFE_ES_GetCDSBlockIDByName(CFE_ES_ResourceID_t *BlockIdPtr, const char *BlockName); + +/*****************************************************************************/ +/** +** \brief Get a Block name for a specified Block ID +** +** \par Description +** This routine retrieves the cFE Block name associated with a +** specified Block ID. +** +** \par Assumptions, External Events, and Notes: +** In the case of a failure (#CFE_ES_ERR_RESOURCEID_NOT_VALID), an empty string is returned. +** +** \param[out] BlockName Pointer to a character array of at least \c BufferLength in size that will +** be filled with the CDS Block name. +** +** \param[in] BlockId Block ID/Handle of CDS registry entry whose name is being requested. +** +** \param[in] BufferLength The maximum number of characters, including the null terminator, that can be put +** into the \c BlockName buffer. This routine will truncate the name to this length, +** if necessary. +** +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID +** +** \sa #CFE_ES_GetCDSBlockIDByName +** +******************************************************************************/ +CFE_Status_t CFE_ES_GetCDSBlockName(char *BlockName, CFE_ES_ResourceID_t BlockId, uint32 BufferLength); + + /*****************************************************************************/ /** ** \brief Save a block of data in the Critical Data Store (CDS) @@ -1191,9 +1385,8 @@ CFE_Status_t CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset ** \param[in] DataToCopy A Pointer to the block of memory to be copied into the CDS. ** ** \return Execution status, see \ref CFEReturnCodes -** \retval #OS_SUCCESS \copybrief OS_SUCCESS -** \retval #CFE_ES_ERR_MEM_HANDLE \copybrief CFE_ES_ERR_MEM_HANDLE -** \retval #OS_ERROR Problem with handle or a size mismatch +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID ** ** \sa #CFE_ES_RegisterCDS, #CFE_ES_RestoreFromCDS ** @@ -1221,8 +1414,8 @@ CFE_Status_t CFE_ES_CopyToCDS(CFE_ES_CDSHandle_t Handle, void *DataToCopy); ** ** \return Execution status, see \ref CFEReturnCodes ** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID ** \retval #CFE_ES_CDS_BLOCK_CRC_ERR \copybrief CFE_ES_CDS_BLOCK_CRC_ERR -** \retval #OS_ERROR Problem with handle or a size mismatch ** ** \sa #CFE_ES_RegisterCDS, #CFE_ES_CopyToCDS ** @@ -1352,8 +1545,8 @@ CFE_Status_t CFE_ES_PoolCreateEx(CFE_ES_MemHandle_t *PoolID, ** \param[in] PoolID The ID of the pool to delete ** ** \return Execution status, see \ref CFEReturnCodes -** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_MEM_HANDLE \copybrief CFE_ES_ERR_MEM_HANDLE +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID ** ** \sa #CFE_ES_PoolCreate, #CFE_ES_PoolCreateNoSem, #CFE_ES_GetPoolBuf, #CFE_ES_PutPoolBuf, #CFE_ES_GetMemPoolStats ** @@ -1378,8 +1571,8 @@ int32 CFE_ES_PoolDelete(CFE_ES_MemHandle_t PoolID); ** \param[in] Size The size of the buffer requested. NOTE: The size allocated may be larger. ** ** \return Bytes Allocated, or error code \ref CFEReturnCodes -** \retval #CFE_ES_ERR_MEM_HANDLE \copybrief CFE_ES_ERR_MEM_HANDLE -** \retval #CFE_ES_ERR_MEM_BLOCK_SIZE \copybrief CFE_ES_ERR_MEM_BLOCK_SIZE +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID +** \retval #CFE_ES_ERR_MEM_BLOCK_SIZE \copybrief CFE_ES_ERR_MEM_BLOCK_SIZE ** ** \sa #CFE_ES_PoolCreate, #CFE_ES_PoolCreateNoSem, #CFE_ES_PoolCreateEx, #CFE_ES_PutPoolBuf, #CFE_ES_GetMemPoolStats, #CFE_ES_GetPoolBufInfo ** @@ -1401,9 +1594,9 @@ int32 CFE_ES_GetPoolBuf(uint32 **BufPtr, CFE_ES_MemHandle_t PoolID, CFE_ES_MemOf ** \param[in] BufPtr A pointer to the memory buffer to provide status for. ** ** \return Execution status, see \ref CFEReturnCodes -** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_MEM_HANDLE \copybrief CFE_ES_ERR_MEM_HANDLE -** \retval #CFE_ES_BUFFER_NOT_IN_POOL \copybrief CFE_ES_BUFFER_NOT_IN_POOL +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID +** \retval #CFE_ES_BUFFER_NOT_IN_POOL \copybrief CFE_ES_BUFFER_NOT_IN_POOL ** ** \sa #CFE_ES_PoolCreate, #CFE_ES_PoolCreateNoSem, #CFE_ES_PoolCreateEx, #CFE_ES_GetPoolBuf, #CFE_ES_GetMemPoolStats, #CFE_ES_PutPoolBuf ** @@ -1425,7 +1618,7 @@ CFE_Status_t CFE_ES_GetPoolBufInfo(CFE_ES_MemHandle_t PoolID, uint32 *BufPtr); ** \param[in] BufPtr A pointer to the memory buffer to be released. ** ** \return Bytes released, or error code \ref CFEReturnCodes -** \retval #CFE_ES_ERR_MEM_HANDLE \copybrief CFE_ES_ERR_MEM_HANDLE +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID ** ** \sa #CFE_ES_PoolCreate, #CFE_ES_PoolCreateNoSem, #CFE_ES_PoolCreateEx, #CFE_ES_GetPoolBuf, #CFE_ES_GetMemPoolStats, #CFE_ES_GetPoolBufInfo ** @@ -1451,8 +1644,8 @@ int32 CFE_ES_PutPoolBuf(CFE_ES_MemHandle_t PoolID, uint32 *BufPtr); ** ** ** \return Execution status, see \ref CFEReturnCodes -** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_MEM_HANDLE \copybrief CFE_ES_ERR_MEM_HANDLE +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID ** ** \sa #CFE_ES_PoolCreate, #CFE_ES_PoolCreateNoSem, #CFE_ES_PoolCreateEx, #CFE_ES_GetPoolBuf, #CFE_ES_PutPoolBuf ** @@ -1650,17 +1843,49 @@ CFE_Status_t CFE_ES_GetGenCount(CFE_ES_ResourceID_t CounterId, uint32 *Count); ** \par Assumptions, External Events, and Notes: ** None. ** -** \param[in] *CounterName The name of the Counter. -** -** \param[out] *CounterIdPtr The Counter Id for the given name. +** \param[out] CounterIdPtr Pointer to variable that is to receive the Counter's ID. +** \param[in] CounterName Pointer to null terminated character string containing a Counter name. ** ** \return Execution status, see \ref CFEReturnCodes -** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_BAD_ARGUMENT \copybrief CFE_ES_BAD_ARGUMENT +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_NAME_NOT_FOUND \copybrief CFE_ES_ERR_NAME_NOT_FOUND +** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER +** +** \sa #CFE_ES_GetGenCounterName ** -** \sa #CFE_ES_RegisterGenCounter, #CFE_ES_DeleteGenCounter, #CFE_ES_SetGenCount, #CFE_ES_IncrementGenCounter, #CFE_ES_GetGenCount ******************************************************************************/ CFE_Status_t CFE_ES_GetGenCounterIDByName(CFE_ES_ResourceID_t *CounterIdPtr, const char *CounterName); + +/*****************************************************************************/ +/** +** \brief Get a Counter name for a specified Counter ID +** +** \par Description +** This routine retrieves the cFE Counter name associated with a +** specified Counter ID. +** +** \par Assumptions, External Events, and Notes: +** In the case of a failure (#CFE_ES_ERR_RESOURCEID_NOT_VALID), an empty string is returned. +** +** \param[out] CounterName Pointer to a character array of at least \c BufferLength in size that will +** be filled with the Counter name. +** +** \param[in] CounterId ID of Counter whose name is being requested. +** +** \param[in] BufferLength The maximum number of characters, including the null terminator, that can be put +** into the \c CounterName buffer. This routine will truncate the name to this length, +** if necessary. +** +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_ES_ERR_RESOURCEID_NOT_VALID \copybrief CFE_ES_ERR_RESOURCEID_NOT_VALID +** +** \sa #CFE_ES_GetGenCounterIDByName +** +******************************************************************************/ +CFE_Status_t CFE_ES_GetGenCounterName(char *CounterName, CFE_ES_ResourceID_t CounterId, uint32 BufferLength); + /**@}*/ #endif /* _cfe_es_ */ diff --git a/fsw/cfe-core/src/inc/cfe_tbl.h b/fsw/cfe-core/src/inc/cfe_tbl.h index 92d303613..4e29481d2 100644 --- a/fsw/cfe-core/src/inc/cfe_tbl.h +++ b/fsw/cfe-core/src/inc/cfe_tbl.h @@ -260,8 +260,6 @@ typedef struct CFE_TBL_Info ** \retval #CFE_TBL_ERR_INVALID_SIZE \copybrief CFE_TBL_ERR_INVALID_SIZE ** \retval #CFE_TBL_ERR_INVALID_NAME \copybrief CFE_TBL_ERR_INVALID_NAME ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** ** \sa #CFE_TBL_Unregister, #CFE_TBL_Share **/ @@ -303,8 +301,6 @@ CFE_Status_t CFE_TBL_Register(CFE_TBL_Handle_t *TblHandlePtr, / ** \retval #CFE_TBL_ERR_HANDLES_FULL \copybrief CFE_TBL_ERR_HANDLES_FULL ** \retval #CFE_TBL_ERR_INVALID_NAME \copybrief CFE_TBL_ERR_INVALID_NAME ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** ** \sa #CFE_TBL_Unregister, #CFE_TBL_Register ** @@ -333,8 +329,6 @@ CFE_Status_t CFE_TBL_Share(CFE_TBL_Handle_t *TblHandlePtr, const char *TblName); ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** ** \sa #CFE_TBL_Share, #CFE_TBL_Register ** @@ -382,8 +376,6 @@ CFE_Status_t CFE_TBL_Unregister (CFE_TBL_Handle_t TblHandle); ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_DUMP_ONLY \copybrief CFE_TBL_ERR_DUMP_ONLY ** \retval #CFE_TBL_ERR_ILLEGAL_SRC_TYPE \copybrief CFE_TBL_ERR_ILLEGAL_SRC_TYPE ** \retval #CFE_TBL_ERR_LOAD_IN_PROGRESS \copybrief CFE_TBL_ERR_LOAD_IN_PROGRESS @@ -423,8 +415,6 @@ CFE_Status_t CFE_TBL_Load(CFE_TBL_Handle_t TblHandle, CFE_TBL_SrcEnum_t SrcType, ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** ** \sa #CFE_TBL_Load, #CFE_TBL_Validate, #CFE_TBL_Manage ** @@ -453,8 +443,6 @@ CFE_Status_t CFE_TBL_Update(CFE_TBL_Handle_t TblHandle); ** \return Execution status, see \ref CFEReturnCodes ** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS ** \retval #CFE_TBL_INFO_NO_VALIDATION_PENDING \copybrief CFE_TBL_INFO_NO_VALIDATION_PENDING -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE @@ -485,8 +473,6 @@ CFE_Status_t CFE_TBL_Validate(CFE_TBL_Handle_t TblHandle); ** \return Execution status, see \ref CFEReturnCodes ** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS ** \retval #CFE_TBL_INFO_UPDATED \copybrief CFE_TBL_INFO_UPDATED -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE @@ -514,8 +500,6 @@ CFE_Status_t CFE_TBL_Manage(CFE_TBL_Handle_t TblHandle); ** ** \return Execution status, see \ref CFEReturnCodes ** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE @@ -542,8 +526,6 @@ CFE_Status_t CFE_TBL_DumpToBuffer(CFE_TBL_Handle_t TblHandle); ** ** \return Execution status, see \ref CFEReturnCodes ** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE @@ -598,8 +580,6 @@ CFE_Status_t CFE_TBL_Modified(CFE_TBL_Handle_t TblHandle); ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_UNREGISTERED \copybrief CFE_TBL_ERR_UNREGISTERED ** \retval #CFE_TBL_ERR_NEVER_LOADED \copybrief CFE_TBL_ERR_NEVER_LOADED ** @@ -631,8 +611,6 @@ CFE_Status_t CFE_TBL_GetAddress(void **TblPtr, CFE_TBL_Handle_t TblHandle); ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_NEVER_LOADED \copybrief CFE_TBL_ERR_NEVER_LOADED ** ** \sa #CFE_TBL_GetAddress, #CFE_TBL_GetAddresses, #CFE_TBL_ReleaseAddresses @@ -682,8 +660,6 @@ CFE_Status_t CFE_TBL_ReleaseAddress(CFE_TBL_Handle_t TblHandle); ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_UNREGISTERED \copybrief CFE_TBL_ERR_UNREGISTERED ** \retval #CFE_TBL_ERR_NEVER_LOADED \copybrief CFE_TBL_ERR_NEVER_LOADED ** @@ -717,8 +693,6 @@ CFE_Status_t CFE_TBL_GetAddresses(void **TblPtrs[], uint16 NumTables, const CFE_ ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_NEVER_LOADED \copybrief CFE_TBL_ERR_NEVER_LOADED ** ** \sa #CFE_TBL_GetAddress, #CFE_TBL_ReleaseAddress, #CFE_TBL_GetAddresses @@ -754,8 +728,6 @@ CFE_Status_t CFE_TBL_ReleaseAddresses(uint16 NumTables, const CFE_TBL_Handle_t T ** \retval #CFE_TBL_INFO_UPDATE_PENDING \copybrief CFE_TBL_INFO_UPDATE_PENDING ** \retval #CFE_TBL_INFO_VALIDATION_PENDING \copybrief CFE_TBL_INFO_VALIDATION_PENDING ** \retval #CFE_TBL_INFO_DUMP_PENDING \copybrief CFE_TBL_INFO_DUMP_PENDING -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE @@ -833,8 +805,6 @@ CFE_Status_t CFE_TBL_GetInfo(CFE_TBL_Info_t *TblInfoPtr, const char *TblName); ** ** \return Execution status, see \ref CFEReturnCodes ** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS -** \retval #CFE_ES_ERR_APPNAME \copybrief CFE_ES_ERR_APPNAME -** \retval #CFE_ES_ERR_BUFFER \copybrief CFE_ES_ERR_BUFFER ** \retval #CFE_TBL_ERR_BAD_APP_ID \copybrief CFE_TBL_ERR_BAD_APP_ID ** \retval #CFE_TBL_ERR_NO_ACCESS \copybrief CFE_TBL_ERR_NO_ACCESS ** \retval #CFE_TBL_ERR_INVALID_HANDLE \copybrief CFE_TBL_ERR_INVALID_HANDLE diff --git a/fsw/cfe-core/src/inc/cfe_time.h b/fsw/cfe-core/src/inc/cfe_time.h index 2f586a309..71ddc162f 100644 --- a/fsw/cfe-core/src/inc/cfe_time.h +++ b/fsw/cfe-core/src/inc/cfe_time.h @@ -709,7 +709,6 @@ void CFE_TIME_ExternalTime(CFE_TIME_SysTime_t NewTime); ** \return Execution status, see \ref CFEReturnCodes ** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS ** \retval #CFE_TIME_TOO_MANY_SYNCH_CALLBACKS \copybrief CFE_TIME_TOO_MANY_SYNCH_CALLBACKS -** \retval #CFE_ES_ERR_APPID \copybrief CFE_ES_ERR_APPID ** ** \sa #CFE_TIME_UnregisterSynchCallback ** @@ -733,7 +732,6 @@ CFE_Status_t CFE_TIME_RegisterSynchCallback(CFE_TIME_SynchCallbackPtr_t Callbac ** \return Execution status, see \ref CFEReturnCodes ** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS ** \retval #CFE_TIME_CALLBACK_NOT_REGISTERED \copybrief CFE_TIME_CALLBACK_NOT_REGISTERED -** \retval #CFE_ES_ERR_APPID \copybrief CFE_ES_ERR_APPID ** ** \sa #CFE_TIME_RegisterSynchCallback ** diff --git a/fsw/cfe-core/src/inc/cfe_version.h b/fsw/cfe-core/src/inc/cfe_version.h index ca00f673a..64bb3c4a1 100644 --- a/fsw/cfe-core/src/inc/cfe_version.h +++ b/fsw/cfe-core/src/inc/cfe_version.h @@ -35,7 +35,7 @@ /* Development Build Macro Definitions */ -#define CFE_BUILD_NUMBER 129 /*!< Development Build: Number of commits since baseline */ +#define CFE_BUILD_NUMBER 139 /*!< Development Build: Number of commits since baseline */ #define CFE_BUILD_BASELINE "v6.8.0-rc1" /*!< Development Build: git tag that is the base for the current development */ /* Version Macro Definitions */ diff --git a/fsw/cfe-core/src/inc/private/cfe_private.h b/fsw/cfe-core/src/inc/private/cfe_private.h index cc16cd2ee..727c9f62b 100644 --- a/fsw/cfe-core/src/inc/private/cfe_private.h +++ b/fsw/cfe-core/src/inc/private/cfe_private.h @@ -325,7 +325,7 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t Us ** \return #CFE_SUCCESS \copydoc CFE_SUCCESS ** \return #CFE_ES_CDS_WRONG_TYPE_ERR \copydoc CFE_ES_CDS_WRONG_TYPE_ERR ** \return #CFE_ES_CDS_OWNER_ACTIVE_ERR \copydoc CFE_ES_CDS_OWNER_ACTIVE_ERR -** \return #CFE_ES_CDS_NOT_FOUND_ERR \copydoc CFE_ES_CDS_NOT_FOUND_ERR +** \return #CFE_ES_ERR_NAME_NOT_FOUND \copydoc CFE_ES_ERR_NAME_NOT_FOUND ** \return Any of the return values from #CFE_ES_UpdateCDSRegistry ** \return Any of the return values from #CFE_ES_PutCDSBlock ** diff --git a/fsw/cfe-core/src/tbl/cfe_tbl_task_cmds.c b/fsw/cfe-core/src/tbl/cfe_tbl_task_cmds.c index 9010c4d67..39048e696 100644 --- a/fsw/cfe-core/src/tbl/cfe_tbl_task_cmds.c +++ b/fsw/cfe-core/src/tbl/cfe_tbl_task_cmds.c @@ -1396,7 +1396,7 @@ int32 CFE_TBL_DeleteCDSCmd(const CFE_TBL_DeleteCDS_t *data) "CDS '%s' owning app is still active", TableName); } - else if (Status == CFE_ES_CDS_NOT_FOUND_ERR) + else if (Status == CFE_ES_ERR_NAME_NOT_FOUND) { CFE_EVS_SendEvent(CFE_TBL_CDS_NOT_FOUND_ERR_EID, CFE_EVS_EventType_ERROR, "Unable to locate '%s' in CDS Registry", TableName); diff --git a/fsw/cfe-core/unit-test/es_UT.c b/fsw/cfe-core/unit-test/es_UT.c index c733fb3c0..fe99f690e 100644 --- a/fsw/cfe-core/unit-test/es_UT.c +++ b/fsw/cfe-core/unit-test/es_UT.c @@ -74,11 +74,6 @@ CFE_ES_GMP_IndirectBuffer_t UT_MemPoolIndirectBuffer; /* Create a startup script buffer for a maximum of 5 lines * 80 chars/line */ char StartupScript[MAX_STARTUP_SCRIPT]; -/* Number of apps instantiated */ -uint32 ES_UT_NumApps; -uint32 ES_UT_NumPools; -uint32 ES_UT_NumCDS; - static const UT_TaskPipeDispatchId_t UT_TPID_CFE_ES_CMD_NOOP_CC = { .MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_ES_CMD_MID), @@ -268,15 +263,16 @@ void ES_UT_SetupSingleAppId(CFE_ES_AppType_Enum_t AppType, CFE_ES_AppState_Enum_ OS_TaskCreate(&UtOsalId, "UT", NULL, NULL, 0, 0, 0); UtTaskId = CFE_ES_ResourceID_FromOSAL(UtOsalId); - UtAppId = ES_UT_MakeAppIdForIndex(ES_UT_NumApps); - ++ES_UT_NumApps; + UtAppId = CFE_ES_Global.LastAppId; + CFE_ES_Global.LastAppId = CFE_ES_ResourceID_FromInteger( + CFE_ES_ResourceID_ToInteger(UtAppId) + 1); 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->MainTaskId = UtTaskId; LocalAppPtr->AppState = AppState; LocalAppPtr->Type = AppType; @@ -346,6 +342,37 @@ void ES_UT_SetupChildTaskId(const CFE_ES_AppRecord_t *ParentApp, const char *Tas ++CFE_ES_Global.RegisteredTasks; } +/* + * Helper function to setup a single Lib ID. A pointer to the Lib + * record is output so the record can be modified + */ +void ES_UT_SetupSingleLibId(const char *LibName, CFE_ES_LibRecord_t **OutLibRec) +{ + CFE_ES_ResourceID_t UtLibId; + CFE_ES_LibRecord_t *LocalLibPtr; + + UtLibId = CFE_ES_Global.LastLibId; + CFE_ES_Global.LastLibId = CFE_ES_ResourceID_FromInteger( + CFE_ES_ResourceID_ToInteger(UtLibId) + 1); + + LocalLibPtr = CFE_ES_LocateLibRecordByID(UtLibId); + CFE_ES_LibRecordSetUsed(LocalLibPtr, UtLibId); + + if (LibName) + { + strncpy(LocalLibPtr->LibName, LibName, + sizeof(LocalLibPtr->LibName)-1); + LocalLibPtr->LibName[sizeof(LocalLibPtr->LibName)-1] = 0; + } + + if (OutLibRec) + { + *OutLibRec = LocalLibPtr; + } + + ++CFE_ES_Global.RegisteredLibs; +} + int32 ES_UT_PoolDirectRetrieve(CFE_ES_GenPoolRecord_t *PoolRecPtr, CFE_ES_MemOffset_t Offset, CFE_ES_GenPoolBD_t **BdPtr) { @@ -394,8 +421,10 @@ void ES_UT_SetupMemPoolId(CFE_ES_MemPoolRecord_t **OutPoolRecPtr) CFE_ES_MemHandle_t UtPoolID; CFE_ES_MemPoolRecord_t *LocalPoolRecPtr; - UtPoolID = ES_UT_MakePoolIdForIndex(ES_UT_NumPools); - ++ES_UT_NumPools; + UtPoolID = CFE_ES_Global.LastMemPoolId; + CFE_ES_Global.LastMemPoolId = CFE_ES_ResourceID_FromInteger( + CFE_ES_ResourceID_ToInteger(UtPoolID) + 1); + LocalPoolRecPtr = CFE_ES_LocateMemPoolRecordByID(UtPoolID); @@ -449,7 +478,7 @@ void ES_UT_SetupSingleCDSRegistry(const char *CDSName, CFE_ES_MemOffset_t BlockS /* first time this is done, set up the global */ - if (ES_UT_NumCDS == 0 && CFE_ES_Global.CDSVars.Pool.TailPosition == 0) + if (!CFE_ES_Global.CDSIsAvailable) { UT_GetDataBuffer(UT_KEY(CFE_PSP_GetCDSSize), NULL, &UT_CDS_BufferSize, NULL); if (UT_CDS_BufferSize > (2*CFE_ES_CDS_SIGNATURE_LEN)) @@ -471,10 +500,13 @@ void ES_UT_SetupSingleCDSRegistry(const char *CDSName, CFE_ES_MemOffset_t BlockS CFE_ES_Global.CDSVars.Pool.TailPosition = CFE_ES_CDS_SIGNATURE_LEN; CFE_ES_Global.CDSVars.Pool.PoolTotalSize = CFE_ES_Global.CDSVars.Pool.PoolMaxOffset - CFE_ES_Global.CDSVars.Pool.TailPosition; + + CFE_ES_Global.CDSIsAvailable = true; } - UtCDSID = ES_UT_MakeCDSIdForIndex(ES_UT_NumCDS); - ++ES_UT_NumCDS; + UtCDSID = CFE_ES_Global.CDSVars.LastCDSBlockId; + CFE_ES_Global.CDSVars.LastCDSBlockId = CFE_ES_ResourceID_FromInteger( + CFE_ES_ResourceID_ToInteger(UtCDSID) + 1); LocalRegRecPtr = CFE_ES_LocateCDSBlockRecordByID(UtCDSID); if (CDSName != NULL) @@ -589,6 +621,7 @@ void UtTest_Setup(void) UT_ADD_TEST(TestInit); UT_ADD_TEST(TestStartupErrorPaths); + UT_ADD_TEST(TestResourceID); UT_ADD_TEST(TestApps); UT_ADD_TEST(TestLibs); UT_ADD_TEST(TestERLog); @@ -612,9 +645,17 @@ void ES_ResetUnitTest(void) UT_InitData(); memset(&CFE_ES_Global, 0, sizeof(CFE_ES_Global)); - ES_UT_NumApps = 0; - ES_UT_NumPools = 0; - ES_UT_NumCDS = 0; + + /* + ** Initialize the Last Id + */ + CFE_ES_Global.LastAppId = CFE_ES_ResourceID_FromInteger(CFE_ES_APPID_BASE); + CFE_ES_Global.LastLibId = CFE_ES_ResourceID_FromInteger(CFE_ES_LIBID_BASE); + CFE_ES_Global.LastCounterId = CFE_ES_ResourceID_FromInteger(CFE_ES_COUNTID_BASE); + CFE_ES_Global.LastMemPoolId = CFE_ES_ResourceID_FromInteger(CFE_ES_POOLID_BASE); + CFE_ES_Global.CDSVars.LastCDSBlockId = CFE_ES_ResourceID_FromInteger(CFE_ES_CDSBLOCKID_BASE); + + } /* end ES_ResetUnitTest() */ void TestInit(void) @@ -1114,6 +1155,8 @@ void TestApps(void) CFE_ES_ResourceID_t Id; CFE_ES_TaskRecord_t *UtTaskRecPtr; CFE_ES_AppRecord_t *UtAppRecPtr; + CFE_ES_MemPoolRecord_t *UtPoolRecPtr; + char NameBuffer[OS_MAX_API_NAME+5]; UtPrintf("Begin Test Apps"); @@ -1250,10 +1293,26 @@ void TestApps(void) 4096, 1); UT_Report(__FILE__, __LINE__, - Return == CFE_ES_ERR_APP_CREATE, + Return == CFE_ES_BAD_ARGUMENT, "CFE_ES_AppCreate", "NULL file name"); + /* Test application creation with name too long */ + memset(NameBuffer, 'x', sizeof(NameBuffer)-1); + NameBuffer[sizeof(NameBuffer)-1] = 0; + Return = CFE_ES_AppCreate(&Id, + "ut/filename.x", + "EntryPoint", + NameBuffer, + 170, + 4096, + 1); + UT_Report(__FILE__, __LINE__, + Return == CFE_ES_BAD_ARGUMENT, + "CFE_ES_AppCreate", + "Name too long"); + + /* Test successful application loading and creation */ ES_ResetUnitTest(); Return = CFE_ES_AppCreate(&Id, @@ -1268,13 +1327,26 @@ void TestApps(void) "CFE_ES_AppCreate", "Application load/create; successful"); + /* Test application loading of the same name again */ + Return = CFE_ES_AppCreate(&Id, + "ut/filename.x", + "EntryPoint", + "AppName", + 170, + 8192, + 1); + UT_Report(__FILE__, __LINE__, + Return == CFE_ES_ERR_DUPLICATE_NAME, + "CFE_ES_AppCreate", + "Duplicate name"); + /* Test application loading and creation where the file cannot be loaded */ UT_InitData(); UT_SetDeferredRetcode(UT_KEY(OS_ModuleLoad), 1, -1); Return = CFE_ES_AppCreate(&Id, "ut/filename.x", "EntryPoint", - "AppName", + "AppName2", 170, 8192, 1); @@ -1301,7 +1373,7 @@ void TestApps(void) 8192, 1); UT_Report(__FILE__, __LINE__, - Return == CFE_ES_ERR_APP_CREATE && + Return == CFE_ES_NO_RESOURCE_IDS_AVAILABLE && UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_NO_FREE_APP_SLOTS]), "CFE_ES_AppCreate", "No free application slots available"); @@ -1345,6 +1417,15 @@ void TestApps(void) "CFE_ES_AppCreate", "Module unload failure after entry point lookup failure"); + /* + * Set up a situation where attempting to get appID by context, + * but the task record does not match the app record. + */ + ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, &UtTaskRecPtr); + UtTaskRecPtr->AppId = CFE_ES_RESOURCEID_UNDEFINED; + UtAssert_NULL(CFE_ES_GetAppRecordByContext()); + /* Test scanning and acting on the application table where the timer * expires for a waiting application */ @@ -1683,7 +1764,7 @@ void TestApps(void) 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(&AppInfo, Id) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetAppInfo", "Application ID not active"); @@ -1693,7 +1774,7 @@ void TestApps(void) ES_ResetUnitTest(); Id = ES_UT_MakeAppIdForIndex(99999); UT_Report(__FILE__, __LINE__, - CFE_ES_GetAppInfo(&AppInfo, Id) == CFE_ES_ERR_APPID, + CFE_ES_GetAppInfo(&AppInfo, Id) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetAppInfo", "Application ID exceeds maximum"); @@ -1929,6 +2010,8 @@ void TestApps(void) 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); + ES_UT_SetupMemPoolId(&UtPoolRecPtr); + UtPoolRecPtr->OwnerAppID = CFE_ES_AppRecordGetID(UtAppRecPtr); OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); /* Associate a child task with the app to be deleted */ ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, NULL); @@ -1940,6 +2023,29 @@ void TestApps(void) CFE_ES_TaskRecordIsUsed(UtTaskRecPtr), "CFE_ES_CleanUpApp", "Main task ID matches task ID, other task unaffected"); + UT_Report(__FILE__, __LINE__, + !CFE_ES_MemPoolRecordIsUsed(UtPoolRecPtr), + "CFE_ES_CleanUpApp", + "Main task ID matches task ID, memory pool deleted"); + + /* Test deleting an application and cleaning up its resources where the + * memory pool deletion fails + */ + ES_ResetUnitTest(); + /* 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); + ES_UT_SetupMemPoolId(&UtPoolRecPtr); + UtPoolRecPtr->OwnerAppID = CFE_ES_AppRecordGetID(UtAppRecPtr); + UtPoolRecPtr->PoolID = CFE_ES_ResourceID_FromInteger(99999); /* Mismatch */ + UT_Report(__FILE__, __LINE__, + CFE_ES_CleanUpApp(UtAppRecPtr) == CFE_ES_APP_CLEANUP_ERR, + "CFE_ES_CleanUpApp", + "Mem Pool delete error"); + UT_Report(__FILE__, __LINE__, + CFE_ES_MemPoolRecordIsUsed(UtPoolRecPtr), + "CFE_ES_CleanUpApp", + "Mem Pool not freed"); /* Test deleting an application and cleaning up its resources where the * application ID doesn't match the main task ID @@ -1956,7 +2062,7 @@ void TestApps(void) ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, NULL); /* switch the main task association (makes it wrong) */ - UtAppRecPtr->TaskInfo.MainTaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + UtAppRecPtr->MainTaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); UT_SetForceFail(UT_KEY(OS_TaskDelete), OS_ERROR); UT_Report(__FILE__, __LINE__, @@ -1980,7 +2086,7 @@ void TestApps(void) ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, NULL); /* switch the main task association (makes it wrong) */ - UtAppRecPtr->TaskInfo.MainTaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + UtAppRecPtr->MainTaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); UT_Report(__FILE__, __LINE__, CFE_ES_CleanUpApp(UtAppRecPtr) == CFE_SUCCESS, @@ -2031,6 +2137,45 @@ void TestApps(void) CFE_ES_CleanupTaskResources(Id) == CFE_SUCCESS, "CFE_ES_CleanupTaskResources", "Get OS information failures"); + +} + +void TestResourceID(void) +{ + /* + * Test cases for generic resource ID functions which are + * not sufficiently covered by other app/lib tests. + */ + CFE_ES_ResourceID_t Id; + CFE_ES_ResourceID_t LastId; + uint32 Count; + + /* Call CFE_ES_FindNextAvailableId() using an invalid resource type */ + ES_ResetUnitTest(); + Id = CFE_ES_FindNextAvailableId(CFE_ES_RESOURCEID_UNDEFINED, 5); + UtAssert_True(!CFE_ES_ResourceID_IsDefined(Id), "CFE_ES_FindNextAvailableId() on undefined resource type"); + + /* Verify that CFE_ES_FindNextAvailableId() does not repeat until CFE_ES_RESOURCEID_MAX is reached */ + LastId = CFE_ES_Global.LastAppId; + Count = CFE_ES_RESOURCEID_MAX-1; + while (Count > 0) + { + Id = CFE_ES_FindNextAvailableId(LastId, CFE_PLATFORM_ES_MAX_APPLICATIONS); + if (CFE_ES_ResourceID_ToInteger(Id) - CFE_ES_ResourceID_ToInteger(LastId) != 1) + { + /* Numbers should be incrementing by 1 each time, never decreasing */ + break; + } + + LastId = Id; + --Count; + } + UtAssert_True(Count == 0, "CFE_ES_FindNextAvailableId() allocate all resource ID space"); + + /* Now verify that CFE_ES_FindNextAvailableId() recycles the first item again */ + Id = CFE_ES_FindNextAvailableId(LastId, CFE_PLATFORM_ES_MAX_APPLICATIONS); + UtAssert_True(CFE_ES_ResourceID_IsDefined(Id), "CFE_ES_FindNextAvailableId() after wrap"); + UtAssert_True(CFE_ES_ResourceID_ToInteger(Id) < (CFE_ES_APPID_BASE + CFE_PLATFORM_ES_MAX_APPLICATIONS), "CFE_ES_FindNextAvailableId() wrap ID"); } void TestLibs(void) @@ -2056,6 +2201,24 @@ void TestLibs(void) "CFE_ES_LoadLibrary", "Load shared library initialization failure"); + /* Test Load library returning an error on a null pointer argument */ + Return = CFE_ES_LoadLibrary(&Id, + NULL, + "EntryPoint", + "LibName"); + UT_Report(__FILE__, __LINE__, + Return == CFE_ES_BAD_ARGUMENT, + "CFE_ES_LoadLibrary", + "Load shared library bad argument (NULL filename)"); + + Return = CFE_ES_LoadLibrary(&Id, + "filename", + "EntryPoint", + NULL); + UT_Report(__FILE__, __LINE__, + Return == CFE_ES_BAD_ARGUMENT, + "CFE_ES_LoadLibrary", + "Load shared library bad argument (NULL library name)"); /* Test Load library returning an error on a too long library name */ memset(&LongLibraryName[0], 'a', sizeof(UtLibRecPtr->LibName)); @@ -2091,7 +2254,7 @@ void TestLibs(void) "TST_LIB_Init", "TST_LIB"); UT_Report(__FILE__, __LINE__, - Return == CFE_ES_LIB_ALREADY_LOADED, + Return == CFE_ES_ERR_DUPLICATE_NAME, "CFE_ES_LoadLibrary", "Duplicate"); UtAssert_True(CFE_ES_ResourceID_Equal(Id, CFE_ES_LibRecordGetID(UtLibRecPtr)), @@ -2157,11 +2320,24 @@ void TestLibs(void) "EntryPoint", "LibName"); UT_Report(__FILE__, __LINE__, - Return == CFE_ES_ERR_LOAD_LIB && + Return == CFE_ES_NO_RESOURCE_IDS_AVAILABLE && UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_LIBRARY_SLOTS]), "CFE_ES_LoadLibrary", "No free library slots"); + /* + * Test public Name+ID query/lookup API + */ + ES_ResetUnitTest(); + ES_UT_SetupSingleLibId("UT", &UtLibRecPtr); + Id = CFE_ES_LibRecordGetID(UtLibRecPtr); + UtAssert_INT32_EQ(CFE_ES_GetLibName(LongLibraryName, Id, sizeof(LongLibraryName)), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_ES_GetLibIDByName(&Id, "Nonexistent"), CFE_ES_ERR_NAME_NOT_FOUND); + UtAssert_INT32_EQ(CFE_ES_GetLibIDByName(&Id, LongLibraryName), CFE_SUCCESS); + UtAssert_True(CFE_ES_ResourceID_Equal(Id, CFE_ES_LibRecordGetID(UtLibRecPtr)), "Library IDs Match"); + UtAssert_INT32_EQ(CFE_ES_GetLibName(LongLibraryName, CFE_ES_RESOURCEID_UNDEFINED, sizeof(LongLibraryName)), CFE_ES_ERR_RESOURCEID_NOT_VALID); + UtAssert_INT32_EQ(CFE_ES_GetLibName(NULL, Id, sizeof(LongLibraryName)), CFE_ES_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_ES_GetLibIDByName(&Id, NULL), CFE_ES_BAD_ARGUMENT); } void TestERLog(void) @@ -4287,7 +4463,7 @@ void TestPerf(void) void TestAPI(void) { osal_id_t TestObjId; - char AppName[32]; + char AppName[OS_MAX_API_NAME + 12]; uint32 StackBuf[8]; int32 Return; uint8 Data[12]; @@ -4351,9 +4527,9 @@ void TestAPI(void) /* Test restarting an app that doesn't exist */ ES_ResetUnitTest(); 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 */ + AppId = ES_UT_MakeAppIdForIndex(CFE_PLATFORM_ES_MAX_APPLICATIONS-1); /* Should be within range, but not used */ UT_Report(__FILE__, __LINE__, - CFE_ES_RestartApp(AppId) == CFE_ES_ERR_APPID, + CFE_ES_RestartApp(AppId) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_RestartApp", "Bad application ID"); @@ -4361,7 +4537,7 @@ void TestAPI(void) ES_ResetUnitTest(); AppId = ES_UT_MakeAppIdForIndex(99999); UT_Report(__FILE__, __LINE__, - CFE_ES_RestartApp(AppId) == CFE_ES_ERR_APPID, + CFE_ES_RestartApp(AppId) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_RestartApp", "Application ID too large"); @@ -4370,7 +4546,7 @@ void TestAPI(void) ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_STOPPED, NULL, &UtAppRecPtr, NULL); AppId = CFE_ES_AppRecordGetID(UtAppRecPtr); UT_Report(__FILE__, __LINE__, - CFE_ES_ReloadApp(AppId, "filename") == CFE_ES_ERR_APPID, + CFE_ES_ReloadApp(AppId, "filename") == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_ReloadApp", "Bad application ID"); @@ -4379,7 +4555,7 @@ void TestAPI(void) 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(AppId) == CFE_ES_ERR_APPID, + CFE_ES_DeleteApp(AppId) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_DeleteApp", "Bad application ID"); @@ -4521,19 +4697,23 @@ void TestAPI(void) "CFE_ES_RegisterApp", "Application registration successful"); - /* Test getting the cFE application ID by its name */ + /* Test getting the cFE application and task ID by context */ ES_ResetUnitTest(); 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"); + "Get application ID by context successful"); + UT_Report(__FILE__, __LINE__, + CFE_ES_GetTaskID(&TaskId) == CFE_SUCCESS, + "CFE_ES_GetTaskID", + "Get task ID by context successful"); /* Test getting the app name with a bad app ID */ ES_ResetUnitTest(); AppId = ES_UT_MakeAppIdForIndex(99999); UT_Report(__FILE__, __LINE__, - CFE_ES_GetAppName(AppName, AppId, 32) == CFE_ES_ERR_APPID, + CFE_ES_GetAppName(AppName, AppId, 32) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetAppName", "Get application name by ID; bad application ID"); @@ -4544,7 +4724,7 @@ void TestAPI(void) UT_Report(__FILE__, __LINE__, CFE_ES_GetAppName(AppName, AppId, - 32) == CFE_ES_ERR_APPID, + 32) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetAppName", "Get application name by ID; ID out of range"); @@ -4569,7 +4749,7 @@ void TestAPI(void) /* Test getting task information using the task ID - bad task ID */ UT_SetForceFail(UT_KEY(OS_ObjectIdToArrayIndex), OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_TASKID, + CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetTaskInfo", "Get task info by ID; bad task ID"); @@ -4589,7 +4769,7 @@ void TestAPI(void) TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); CFE_ES_AppRecordSetFree(UtAppRecPtr); UT_Report(__FILE__, __LINE__, - CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_APPID, + CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetTaskInfo", "Get task info by ID; parent application not active"); @@ -4599,7 +4779,7 @@ void TestAPI(void) TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); CFE_ES_TaskRecordSetFree(UtTaskRecPtr); UT_Report(__FILE__, __LINE__, - CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_TASKID, + CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetTaskInfo", "Get task info by ID; task not active"); @@ -4607,7 +4787,7 @@ void TestAPI(void) ES_ResetUnitTest(); TaskId = CFE_ES_RESOURCEID_UNDEFINED; UT_Report(__FILE__, __LINE__, - CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_TASKID, + CFE_ES_GetTaskInfo(&TaskInfo, TaskId) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetTaskInfo", "Get task info by ID; invalid task ID"); @@ -4621,7 +4801,7 @@ void TestAPI(void) 400, 0); UT_Report(__FILE__, __LINE__, - Return == CFE_ES_ERR_APPID, + Return == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_ChildTaskCreate", "Bad application ID"); @@ -4742,7 +4922,7 @@ void TestAPI(void) /* Test deleting a child task with an invalid task ID */ UT_SetForceFail(UT_KEY(OS_ObjectIdToArrayIndex), OS_ERROR); UT_Report(__FILE__, __LINE__, - CFE_ES_DeleteChildTask(TaskId) == CFE_ES_ERR_TASKID, + CFE_ES_DeleteChildTask(TaskId) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_DeleteChildTask", "Task ID invalid"); @@ -4782,7 +4962,7 @@ void TestAPI(void) ES_ResetUnitTest(); TaskId = CFE_ES_RESOURCEID_UNDEFINED; UT_Report(__FILE__, __LINE__, - CFE_ES_DeleteChildTask(TaskId) == CFE_ES_ERR_TASKID, + CFE_ES_DeleteChildTask(TaskId) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_DeleteChildTask", "Task ID too large"); @@ -4997,12 +5177,30 @@ void TestAPI(void) "CFE_ES_RunLoop", "Application error run status"); + /* + * Test public Name+ID query/lookup API for tasks + * This just uses OSAL routines to implement, but need to cover error paths. + */ + ES_ResetUnitTest(); + ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, "UT", &UtAppRecPtr, &UtTaskRecPtr); + TaskId = CFE_ES_TaskRecordGetID(UtTaskRecPtr); + UtAssert_INT32_EQ(CFE_ES_GetTaskName(AppName, CFE_ES_RESOURCEID_UNDEFINED, sizeof(AppName)), CFE_ES_ERR_RESOURCEID_NOT_VALID); + UtAssert_INT32_EQ(CFE_ES_GetTaskName(NULL, TaskId, sizeof(AppName)), CFE_ES_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_ES_GetTaskName(AppName, TaskId, sizeof(AppName)), CFE_SUCCESS); + UT_SetDeferredRetcode(UT_KEY(OS_GetResourceName), 1, OS_ERROR); + UtAssert_INT32_EQ(CFE_ES_GetTaskName(AppName, TaskId, sizeof(AppName)), CFE_ES_ERR_RESOURCEID_NOT_VALID); + + UtAssert_INT32_EQ(CFE_ES_GetTaskIDByName(&TaskId, NULL), CFE_ES_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_ES_GetTaskIDByName(&TaskId, AppName), CFE_SUCCESS); + UT_SetDeferredRetcode(UT_KEY(OS_TaskGetIdByName), 1, OS_ERROR); + UtAssert_INT32_EQ(CFE_ES_GetTaskIDByName(&TaskId, "Nonexistent"), CFE_ES_ERR_NAME_NOT_FOUND); } void TestGenericCounterAPI(void) { char CounterName[11]; CFE_ES_ResourceID_t CounterId; + CFE_ES_ResourceID_t CounterId2; uint32 CounterCount; int i; @@ -5016,7 +5214,7 @@ void TestGenericCounterAPI(void) /* Test registering a generic counter that is already registered */ UT_Report(__FILE__, __LINE__, CFE_ES_RegisterGenCounter(&CounterId, - "Counter1") == CFE_ES_BAD_ARGUMENT, + "Counter1") == CFE_ES_ERR_DUPLICATE_NAME, "CFE_ES_RegisterGenCounter", "Attempt to register an existing counter"); @@ -5039,15 +5237,14 @@ void TestGenericCounterAPI(void) /* Test registering a generic counter after the maximum are registered */ UT_Report(__FILE__, __LINE__, CFE_ES_RegisterGenCounter(&CounterId, - "Counter999") == CFE_ES_BAD_ARGUMENT, + "Counter999") == CFE_ES_NO_RESOURCE_IDS_AVAILABLE, "CFE_ES_RegisterGenCounter", "Maximum number of counters exceeded"); /* Test getting a registered generic counter that doesn't exist */ UT_Report(__FILE__, __LINE__, CFE_ES_GetGenCounterIDByName(&CounterId, - "Counter999") == - CFE_ES_BAD_ARGUMENT, + "Counter999") == CFE_ES_ERR_NAME_NOT_FOUND, "CFE_ES_GetGenCounterIDByName", "Cannot get counter that does not exist"); @@ -5178,6 +5375,19 @@ void TestGenericCounterAPI(void) "CounterX") == CFE_ES_BAD_ARGUMENT, "CFE_ES_GetGenCounterIDByName", "Null name"); + + /* + * Test Name-ID query/conversion API + */ + ES_ResetUnitTest(); + UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(&CounterId, "Counter1"), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(CounterName, CounterId, sizeof(CounterName)), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(&CounterId2, "Nonexistent"), CFE_ES_ERR_NAME_NOT_FOUND); + UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(&CounterId2, CounterName), CFE_SUCCESS); + UtAssert_True(CFE_ES_ResourceID_Equal(CounterId, CounterId2), "Counter IDs Match"); + UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(CounterName, CFE_ES_RESOURCEID_UNDEFINED, sizeof(CounterName)), CFE_ES_ERR_RESOURCEID_NOT_VALID); + UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(NULL, CounterId, sizeof(CounterName)), CFE_ES_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(&CounterId, NULL), CFE_ES_BAD_ARGUMENT); } void TestCDS() @@ -5328,26 +5538,26 @@ void TestCDS() } UT_Report(__FILE__, __LINE__, - CFE_ES_RegisterCDS(&CDSHandle, 4, "Name2") == CFE_ES_CDS_REGISTRY_FULL, + CFE_ES_RegisterCDS(&CDSHandle, 4, "Name2") == CFE_ES_NO_RESOURCE_IDS_AVAILABLE, "CFE_ES_RegisterCDS", "No available entries"); /* 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(&CDSHandle, 4, "Name2") == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_RegisterCDS", "Bad application ID"); /* Test copying to CDS with bad handle */ CDSHandle = CFE_ES_RESOURCEID_UNDEFINED; UT_Report(__FILE__, __LINE__, - CFE_ES_CopyToCDS(CDSHandle, &TempSize) == CFE_ES_RESOURCE_ID_INVALID, + CFE_ES_CopyToCDS(CDSHandle, &TempSize) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_CopyToCDS", "Copy to CDS bad handle"); /* Test restoring from a CDS with bad handle */ UT_Report(__FILE__, __LINE__, - CFE_ES_RestoreFromCDS(&TempSize, CDSHandle) == CFE_ES_RESOURCE_ID_INVALID, + CFE_ES_RestoreFromCDS(&TempSize, CDSHandle) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_RestoreFromCDS", "Restore from CDS bad handle"); @@ -5638,10 +5848,24 @@ void TestCDS() CDSName[sizeof(CDSName) - 1] = '\0'; ES_UT_SetupSingleCDSRegistry(CDSName, ES_UT_CDS_BLOCK_SIZE, true, NULL); UT_Report(__FILE__, __LINE__, - CFE_ES_DeleteCDS(CDSName, - true) == CFE_ES_CDS_NOT_FOUND_ERR, + CFE_ES_DeleteCDS(CDSName, true) == CFE_ES_ERR_NAME_NOT_FOUND, "CFE_ES_DeleteCDS", "CDS name too long"); + + /* + * Test Name-ID query/conversion API + */ + ES_ResetUnitTest(); + ES_UT_SetupSingleCDSRegistry("CDS1", ES_UT_CDS_BLOCK_SIZE, false, &UtCDSRegRecPtr); + CDSHandle = CFE_ES_CDSBlockRecordGetID(UtCDSRegRecPtr); + UtAssert_INT32_EQ(CFE_ES_GetCDSBlockName(CDSName, CDSHandle, sizeof(CDSName)), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_ES_GetCDSBlockIDByName(&CDSHandle, "Nonexistent"), CFE_ES_ERR_NAME_NOT_FOUND); + UtAssert_INT32_EQ(CFE_ES_GetCDSBlockIDByName(&CDSHandle, CDSName), CFE_SUCCESS); + UtAssert_True(CFE_ES_ResourceID_Equal(CDSHandle, CFE_ES_CDSBlockRecordGetID(UtCDSRegRecPtr)), "CDS Handle IDs Match"); + UtAssert_INT32_EQ(CFE_ES_GetCDSBlockName(CDSName, CFE_ES_RESOURCEID_UNDEFINED, sizeof(CDSName)), CFE_ES_ERR_RESOURCEID_NOT_VALID); + UtAssert_INT32_EQ(CFE_ES_GetCDSBlockName(NULL, CDSHandle, sizeof(CDSName)), CFE_ES_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_ES_GetCDSBlockIDByName(&CDSHandle, NULL), CFE_ES_BAD_ARGUMENT); + } /* End TestCDS */ void TestCDSMempool(void) @@ -5707,11 +5931,11 @@ void TestCDSMempool(void) ES_ResetUnitTest(); BlockHandle = CFE_ES_ResourceID_FromInteger(7); UT_Report(__FILE__, __LINE__, - CFE_ES_CDSBlockWrite(BlockHandle, &Data) == CFE_ES_RESOURCE_ID_INVALID, + CFE_ES_CDSBlockWrite(BlockHandle, &Data) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_CDSBlockWrite", "Invalid memory handle"); UT_Report(__FILE__, __LINE__, - CFE_ES_CDSBlockRead(&Data, BlockHandle) == CFE_ES_RESOURCE_ID_INVALID, + CFE_ES_CDSBlockRead(&Data, BlockHandle) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_CDSBlockRead", "Invalid memory handle"); @@ -5938,7 +6162,7 @@ void TestESMempool(void) UT_Report(__FILE__, __LINE__, CFE_ES_GetPoolBuf(&addressp2, PoolID2, - 256) == CFE_ES_ERR_MEM_HANDLE, + 256) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetPoolBuf", "Invalid handle; not pool start address"); @@ -5947,7 +6171,7 @@ void TestESMempool(void) */ UT_Report(__FILE__, __LINE__, CFE_ES_GetMemPoolStats(&Stats, - CFE_ES_RESOURCEID_UNDEFINED) == CFE_ES_ERR_MEM_HANDLE, + CFE_ES_RESOURCEID_UNDEFINED) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetMemPoolStats", "Invalid handle; not pool start address"); @@ -5966,7 +6190,7 @@ void TestESMempool(void) */ UT_Report(__FILE__, __LINE__, CFE_ES_GetPoolBufInfo(PoolID2, addressp2) == - CFE_ES_ERR_MEM_HANDLE, + CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetPoolBufInfo", "Invalid memory pool handle"); @@ -6007,6 +6231,28 @@ void TestESMempool(void) "CFE_ES_PoolCreateEx", "Memory pool size too small (default block size)"); + /* Test calling CFE_ES_PoolCreateEx() with NULL pointer arguments + */ + UT_Report(__FILE__, __LINE__, + CFE_ES_PoolCreateEx(NULL, + Buffer1, + sizeof(Buffer1), + CFE_ES_DEFAULT_MEMPOOL_BLOCK_SIZES, + BlockSizes, + CFE_ES_USE_MUTEX) == CFE_ES_BAD_ARGUMENT, + "CFE_ES_PoolCreateEx", + "Memory pool bad arguments (NULL handle pointer)"); + + UT_Report(__FILE__, __LINE__, + CFE_ES_PoolCreateEx(&PoolID1, + NULL, + sizeof(Buffer1), + CFE_ES_DEFAULT_MEMPOOL_BLOCK_SIZES, + BlockSizes, + CFE_ES_USE_MUTEX) == CFE_ES_BAD_ARGUMENT, + "CFE_ES_PoolCreateEx", + "Memory pool bad arguments (NULL mem pointer)"); + /* * Test to use default block sizes if none are given @@ -6032,6 +6278,54 @@ void TestESMempool(void) "CFE_ES_PoolCreateEx", "Invalid mutex option"); + /* + * Test creating a memory pool after the limit reached (no slots) + */ + ES_ResetUnitTest(); + PoolPtr = CFE_ES_Global.MemPoolTable; + for (i = 0; i < CFE_PLATFORM_ES_MAX_MEMORY_POOLS; ++i) + { + CFE_ES_MemPoolRecordSetUsed(PoolPtr, CFE_ES_ResourceID_FromInteger(i + CFE_ES_POOLID_BASE)); + ++PoolPtr; + } + UT_Report(__FILE__, __LINE__, + CFE_ES_PoolCreateEx(&PoolID1, + Buffer1, + sizeof(Buffer1), + CFE_ES_DEFAULT_MEMPOOL_BLOCK_SIZES, + BlockSizes, + CFE_ES_USE_MUTEX) == CFE_ES_NO_RESOURCE_IDS_AVAILABLE, + "CFE_ES_PoolCreateEx", + "Memory pool limit reached"); + + /* + * Test creating a memory pool with a semaphore error + */ + ES_ResetUnitTest(); + UT_SetDeferredRetcode(UT_KEY(OS_MutSemCreate), 1, OS_ERROR); + UT_Report(__FILE__, __LINE__, + CFE_ES_PoolCreate(&PoolID1, + Buffer1, + sizeof(Buffer1)) == CFE_STATUS_EXTERNAL_RESOURCE_FAIL, + "CFE_ES_PoolCreateEx", + "Memory pool mutex create error"); + + /* + * Test creating a memory pool with a semaphore error + * This still returns success as there is no recourse, but there + * should be a syslog about it. + */ + ES_UT_SetupMemPoolId(&PoolPtr); + OS_MutSemCreate(&PoolPtr->MutexId, "UT", 0); + UT_SetDeferredRetcode(UT_KEY(OS_MutSemDelete), 1, OS_ERROR); + PoolID1 = CFE_ES_MemPoolRecordGetID(PoolPtr); + UT_Report(__FILE__, __LINE__, + CFE_ES_PoolDelete(PoolID1) == CFE_SUCCESS, + "CFE_ES_PoolDelete", + "Memory pool delete with semaphore delete error"); + + + /* Test initializing a pre-allocated pool specifying * the block size with one block size set to zero */ @@ -6250,7 +6544,7 @@ void TestESMempool(void) /* Test returning a pool buffer using a null handle */ UT_Report(__FILE__, __LINE__, - CFE_ES_PutPoolBuf(CFE_ES_RESOURCEID_UNDEFINED, addressp2) == CFE_ES_ERR_MEM_HANDLE, + CFE_ES_PutPoolBuf(CFE_ES_RESOURCEID_UNDEFINED, addressp2) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_PutPoolBuf", "NULL memory handle"); @@ -6259,14 +6553,14 @@ void TestESMempool(void) UT_Report(__FILE__, __LINE__, CFE_ES_GetPoolBuf(&addressp2, CFE_ES_RESOURCEID_UNDEFINED, - 256) == CFE_ES_ERR_MEM_HANDLE, + 256) == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetPoolBuf", "NULL memory handle"); /* Test getting the size of an existing pool buffer using a null handle */ UT_Report(__FILE__, __LINE__, CFE_ES_GetPoolBufInfo(CFE_ES_RESOURCEID_UNDEFINED, addressp1) == - CFE_ES_ERR_MEM_HANDLE, + CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_GetPoolBufInfo", "NULL memory handle"); @@ -6333,7 +6627,7 @@ void TestESMempool(void) UT_Report(__FILE__, __LINE__, CFE_ES_PutPoolBuf(CFE_ES_RESOURCEID_UNDEFINED, addressp1) == - CFE_ES_ERR_MEM_HANDLE, + CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_PutPoolBuf", "Invalid memory handle"); } @@ -6438,7 +6732,7 @@ void TestBackground(void) */ ES_ResetUnitTest(); status = CFE_ES_BackgroundInit(); - UtAssert_True(status == CFE_ES_ERR_APPID, "CFE_ES_BackgroundInit - CFE_ES_CreateChildTask failure (%08x)", (unsigned int)status); + UtAssert_True(status == CFE_ES_ERR_RESOURCEID_NOT_VALID, "CFE_ES_BackgroundInit - CFE_ES_CreateChildTask failure (%08x)", (unsigned int)status); /* The CFE_ES_BackgroundCleanup() function has no conditionals - * it just needs to be executed as part of this routine, diff --git a/fsw/cfe-core/unit-test/es_UT.h b/fsw/cfe-core/unit-test/es_UT.h index 6d9ebe4ed..c33b5546c 100644 --- a/fsw/cfe-core/unit-test/es_UT.h +++ b/fsw/cfe-core/unit-test/es_UT.h @@ -57,6 +57,7 @@ #include "cfe_es_cds_mempool.h" #include "cfe_es_generic_pool.h" #include "cfe_es_global.h" +#include "cfe_es_resource.h" #include "cfe_es_log.h" #include "cfe_es_perf.h" #include "cfe_es_task.h" @@ -332,6 +333,7 @@ void TestCDSMempool(void); void TestESMempool(void); void TestSysLog(void); +void TestResourceID(void); void TestGenericCounterAPI(void); void TestGenericPool(void); void TestLibs(void); diff --git a/fsw/cfe-core/unit-test/evs_UT.c b/fsw/cfe-core/unit-test/evs_UT.c index d63fb3691..052fffc1f 100644 --- a/fsw/cfe-core/unit-test/evs_UT.c +++ b/fsw/cfe-core/unit-test/evs_UT.c @@ -494,7 +494,7 @@ void Test_IllegalAppID(void) /* Set test up with illegal application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID); /* Test registering an event using an illegal application ID */ UT_Report(__FILE__, __LINE__, @@ -504,7 +504,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_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_Report(__FILE__, __LINE__, CFE_EVS_Unregister() == CFE_EVS_APP_ILLEGAL_APP_ID, "CFE_EVS_Unregister", @@ -512,7 +512,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_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_Report(__FILE__, __LINE__, CFE_EVS_SendEvent(0, 0, "NULL") == CFE_EVS_APP_ILLEGAL_APP_ID, "CFE_EVS_SendEvent", @@ -520,7 +520,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_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_Report(__FILE__, __LINE__, EVS_SendEvent(0, 0, "NULL") == CFE_SUCCESS, "EVS_SendEvent", @@ -528,7 +528,7 @@ void Test_IllegalAppID(void) /* 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_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_Report(__FILE__, __LINE__, CFE_EVS_SendTimedEvent(time, 0, @@ -539,7 +539,7 @@ 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_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_Report(__FILE__, __LINE__, CFE_EVS_SendEventWithAppID(0, 0, @@ -550,7 +550,7 @@ void Test_IllegalAppID(void) /* Test resetting a filter using an illegal application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_APPID); + UT_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_Report(__FILE__, __LINE__, CFE_EVS_ResetFilter(0) == CFE_EVS_APP_ILLEGAL_APP_ID, "CFE_EVS_ResetFilter", @@ -558,7 +558,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_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_Report(__FILE__, __LINE__, CFE_EVS_ResetAllFilters() == CFE_EVS_APP_ILLEGAL_APP_ID, "CFE_EVS_ResetAllFilters", @@ -566,7 +566,7 @@ 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_SetForceFail(UT_KEY(CFE_ES_AppID_ToIndex), CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_Report(__FILE__, __LINE__, CFE_EVS_CleanUpApp(CFE_ES_RESOURCEID_UNDEFINED) == CFE_EVS_APP_ILLEGAL_APP_ID, @@ -1541,7 +1541,7 @@ void Test_BadAppCmd(void) sizeof(appcmdcmd.Payload.AppName)); /* Test disabling application event types with an unknown application ID */ - UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_APPNAME); + UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_NAME_NOT_FOUND); UT_EVS_DoDispatchCheckEvents(&appbitcmd, sizeof(appbitcmd), UT_TPID_CFE_EVS_CMD_DISABLE_APP_EVENT_TYPE_CC, &UT_EVS_EventBuf); @@ -1552,7 +1552,7 @@ void Test_BadAppCmd(void) /* Test enabling application event types with an unknown application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_APPNAME); + UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_NAME_NOT_FOUND); UT_EVS_DoDispatchCheckEvents(&appbitcmd, sizeof(appbitcmd), UT_TPID_CFE_EVS_CMD_ENABLE_APP_EVENT_TYPE_CC, &UT_EVS_EventBuf); @@ -1563,7 +1563,7 @@ void Test_BadAppCmd(void) /* Test disabling application events with an unknown application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_APPNAME); + UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_NAME_NOT_FOUND); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_DISABLE_APP_EVENTS_CC, &UT_EVS_EventBuf); @@ -1574,7 +1574,7 @@ void Test_BadAppCmd(void) /* Test enabling application events with an unknown application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_APPNAME); + UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_NAME_NOT_FOUND); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_ENABLE_APP_EVENTS_CC, &UT_EVS_EventBuf); @@ -1587,7 +1587,7 @@ void Test_BadAppCmd(void) * application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_APPNAME); + UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_NAME_NOT_FOUND); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_RESET_APP_COUNTER_CC, &UT_EVS_EventBuf); @@ -1598,7 +1598,7 @@ void Test_BadAppCmd(void) /* Test modifying event filters with an unknown application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_APPNAME); + UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_NAME_NOT_FOUND); UT_EVS_DoDispatchCheckEvents(&appmaskcmd, sizeof(appmaskcmd), UT_TPID_CFE_EVS_CMD_ADD_EVENT_FILTER_CC, &UT_EVS_EventBuf); @@ -1610,7 +1610,7 @@ void Test_BadAppCmd(void) /* Test deleting event filters with an unknown application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_APPNAME); + UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_NAME_NOT_FOUND); UT_EVS_DoDispatchCheckEvents(&appcmdcmd, sizeof(appcmdcmd), UT_TPID_CFE_EVS_CMD_DELETE_EVENT_FILTER_CC, &UT_EVS_EventBuf); @@ -1622,7 +1622,7 @@ void Test_BadAppCmd(void) /* Test setting the event filter mask with an unknown application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_APPNAME); + UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_NAME_NOT_FOUND); UT_EVS_DoDispatchCheckEvents(&appmaskcmd, sizeof(appmaskcmd), UT_TPID_CFE_EVS_CMD_SET_FILTER_CC, &UT_EVS_EventBuf); @@ -1634,7 +1634,7 @@ void Test_BadAppCmd(void) /* Test resetting the filter with an unknown application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_APPNAME); + UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_NAME_NOT_FOUND); UT_EVS_DoDispatchCheckEvents(&appcmdcmd, sizeof(appcmdcmd), UT_TPID_CFE_EVS_CMD_RESET_FILTER_CC, &UT_EVS_EventBuf); @@ -1645,7 +1645,7 @@ void Test_BadAppCmd(void) /* Test resetting all filters with an unknown application ID */ UT_InitData(); - UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_APPNAME); + UT_SetForceFail(UT_KEY(CFE_ES_GetAppIDByName), CFE_ES_ERR_NAME_NOT_FOUND); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_RESET_ALL_FILTERS_CC, &UT_EVS_EventBuf); @@ -1669,7 +1669,7 @@ void Test_BadAppCmd(void) * 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_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_EVS_DoDispatchCheckEvents(&appbitcmd, sizeof(appbitcmd), UT_TPID_CFE_EVS_CMD_DISABLE_APP_EVENT_TYPE_CC, &UT_EVS_EventBuf); @@ -1681,7 +1681,7 @@ void Test_BadAppCmd(void) /* Test enabling application event types with an illegal application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_EVS_DoDispatchCheckEvents(&appbitcmd, sizeof(appbitcmd), UT_TPID_CFE_EVS_CMD_ENABLE_APP_EVENT_TYPE_CC, &UT_EVS_EventBuf); @@ -1692,7 +1692,7 @@ void Test_BadAppCmd(void) /* Test disabling application events with an illegal application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_DISABLE_APP_EVENTS_CC, &UT_EVS_EventBuf); @@ -1703,7 +1703,7 @@ void Test_BadAppCmd(void) /* Test enabling application events with an illegal application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_ENABLE_APP_EVENTS_CC, &UT_EVS_EventBuf); @@ -1716,7 +1716,7 @@ void Test_BadAppCmd(void) * application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_RESET_APP_COUNTER_CC, &UT_EVS_EventBuf); @@ -1728,7 +1728,7 @@ void Test_BadAppCmd(void) /* Test adding the event filter with an illegal application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_EVS_DoDispatchCheckEvents(&appmaskcmd, sizeof(appmaskcmd), UT_TPID_CFE_EVS_CMD_ADD_EVENT_FILTER_CC, &UT_EVS_EventBuf); @@ -1739,7 +1739,7 @@ void Test_BadAppCmd(void) /* Test deleting the event filter with an illegal application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_EVS_DoDispatchCheckEvents(&appcmdcmd, sizeof(appcmdcmd), UT_TPID_CFE_EVS_CMD_DELETE_EVENT_FILTER_CC, &UT_EVS_EventBuf); @@ -1750,7 +1750,7 @@ void Test_BadAppCmd(void) /* Test setting the filter mask with an illegal application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_EVS_DoDispatchCheckEvents(&appmaskcmd, sizeof(appmaskcmd), UT_TPID_CFE_EVS_CMD_SET_FILTER_CC, &UT_EVS_EventBuf); @@ -1761,7 +1761,7 @@ void Test_BadAppCmd(void) /* Test resetting the filter with an illegal application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_EVS_DoDispatchCheckEvents(&appcmdcmd, sizeof(appcmdcmd), UT_TPID_CFE_EVS_CMD_RESET_FILTER_CC, &UT_EVS_EventBuf); @@ -1772,7 +1772,7 @@ void Test_BadAppCmd(void) /* Test resetting all filters with an illegal application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_AppID_ToIndex), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_EVS_DoDispatchCheckEvents(&appnamecmd, sizeof(appnamecmd), UT_TPID_CFE_EVS_CMD_RESET_ALL_FILTERS_CC, &UT_EVS_EventBuf); diff --git a/fsw/cfe-core/unit-test/sb_UT.c b/fsw/cfe-core/unit-test/sb_UT.c index 820957f0f..76e45c0d9 100644 --- a/fsw/cfe-core/unit-test/sb_UT.c +++ b/fsw/cfe-core/unit-test/sb_UT.c @@ -1531,7 +1531,7 @@ void Test_CreatePipe_NullPtr(void) uint16 PipeDepth = 10; /* This provides completion of code coverage in CFE_SB_GetAppTskName() */ - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetTaskInfo), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetTaskInfo), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); UT_SetDeferredRetcode(UT_KEY(OS_QueueCreate), 1, OS_SUCCESS); /* Avoids creating socket */ ASSERT_EQ(CFE_SB_CreatePipe(NULL, PipeDepth, "TestPipe"), CFE_SB_BAD_ARGUMENT); diff --git a/fsw/cfe-core/unit-test/tbl_UT.c b/fsw/cfe-core/unit-test/tbl_UT.c index 0ab972b68..e395262f4 100644 --- a/fsw/cfe-core/unit-test/tbl_UT.c +++ b/fsw/cfe-core/unit-test/tbl_UT.c @@ -499,7 +499,7 @@ void Test_CFE_TBL_DeleteCDSCmd(void) /* Test deletion where the table cannot be located in the CDS registry */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_DeleteCDS), 1, CFE_ES_CDS_NOT_FOUND_ERR); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_DeleteCDS), 1, CFE_ES_ERR_NAME_NOT_FOUND); UT_Report(__FILE__, __LINE__, CFE_TBL_DeleteCDSCmd(&DelCDSCmd) == CFE_TBL_INC_ERR_CTR, @@ -1783,14 +1783,14 @@ void Test_CFE_TBL_Register(void) /* Test response to an invalid application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); 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_ES_ERR_APPID && EventsCorrect, + RtnCode == CFE_ES_ERR_RESOURCEID_NOT_VALID && EventsCorrect, "CFE_TBL_Register", "Invalid application ID"); @@ -1930,14 +1930,14 @@ void Test_CFE_TBL_Register(void) /* Test response to a memory handle error */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetPoolBuf), 1, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetPoolBuf), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); 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_ES_ERR_MEM_HANDLE && EventsCorrect, + RtnCode == CFE_ES_ERR_RESOURCEID_NOT_VALID && EventsCorrect, "CFE_TBL_Register", "Memory handle error"); @@ -2191,7 +2191,7 @@ void Test_CFE_TBL_Register(void) /* a. Perform test */ UT_InitData(); UT_SetDeferredRetcode(UT_KEY(CFE_ES_RegisterCDSEx), 1, CFE_ES_CDS_ALREADY_EXISTS); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_RestoreFromCDS), 1, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_RestoreFromCDS), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_Register(&TblHandle1, "UT_Table1", sizeof(UT_Table1_t), CFE_TBL_OPT_CRITICAL, NULL); @@ -2285,7 +2285,7 @@ void Test_CFE_TBL_Register(void) * is full */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_RegisterCDSEx), 1, CFE_ES_CDS_REGISTRY_FULL); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_RegisterCDSEx), 1, CFE_ES_NO_RESOURCE_IDS_AVAILABLE); RtnCode = CFE_TBL_Register(&TblHandle1, "UT_Table1", sizeof(UT_Table1_t), CFE_TBL_OPT_CRITICAL, NULL); @@ -2490,12 +2490,12 @@ void Test_CFE_TBL_Share(void) /* Test response to an invalid application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); 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_ES_ERR_APPID && EventsCorrect, + RtnCode == CFE_ES_ERR_RESOURCEID_NOT_VALID && EventsCorrect, "CFE_TBL_Share", "Invalid application ID"); @@ -2531,7 +2531,7 @@ void Test_CFE_TBL_Share(void) /* Test unregister response to a PutPoolBuf error */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_PutPoolBuf), 1, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_PutPoolBuf), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_Unregister(CFE_PLATFORM_TBL_MAX_NUM_HANDLES / 2 + 1); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, @@ -2681,11 +2681,11 @@ void Test_CFE_TBL_NotifyByMessage(void) /* Test response to notification request when the application ID is bad */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); EventsCorrect = (UT_GetNumEventsSent() == 0); RtnCode = CFE_TBL_NotifyByMessage(App1TblHandle1, CFE_SB_ValueToMsgId(1), 1, 1); UT_Report(__FILE__, __LINE__, - RtnCode == CFE_ES_ERR_APPID && EventsCorrect, + RtnCode == CFE_ES_ERR_RESOURCEID_NOT_VALID && EventsCorrect, "CFE_TBL_NotifyByMessage", "Notify - bad application ID"); } @@ -3057,11 +3057,11 @@ void Test_CFE_TBL_GetAddress(void) /* Test attempt to get the address with an invalid application ID */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_GetAddress((void **) &App3TblPtr, App2TblHandle1); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, - RtnCode == CFE_ES_ERR_APPID && EventsCorrect, + RtnCode == CFE_ES_ERR_RESOURCEID_NOT_VALID && EventsCorrect, "CFE_TBL_GetAddress", "Invalid application ID"); @@ -3126,11 +3126,11 @@ void Test_CFE_TBL_ReleaseAddress(void) /* b. Perform test */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_APPID); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetAppID), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_ReleaseAddress(App1TblHandle1); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, - RtnCode == CFE_ES_ERR_APPID && EventsCorrect, + RtnCode == CFE_ES_ERR_RESOURCEID_NOT_VALID && EventsCorrect, "CFE_TBL_GetAddress", "Attempt to release address with invalid application ID"); } @@ -4372,11 +4372,11 @@ void Test_CFE_TBL_Internal(void) * memory buffer for a double buffered table */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_PutPoolBuf), 2, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_PutPoolBuf), 2, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_RemoveAccessLink(App1TblHandle2); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, - RtnCode == CFE_ES_ERR_MEM_HANDLE && EventsCorrect, + RtnCode == CFE_ES_ERR_RESOURCEID_NOT_VALID && EventsCorrect, "CFE_TBL_RemoveAccessLink", "Fail to put back memory buffer for double buffered table"); @@ -4412,11 +4412,11 @@ void Test_CFE_TBL_Internal(void) /* Test CFE_TBL_EarlyInit reponse to a get pool buffer failure */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetPoolBuf), 1, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetPoolBuf), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_EarlyInit(); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, - RtnCode == CFE_ES_ERR_MEM_HANDLE && EventsCorrect, + RtnCode == CFE_ES_ERR_RESOURCEID_NOT_VALID && EventsCorrect, "CFE_TBL_EarlyInit", "Get pool buffer failure"); @@ -4447,7 +4447,7 @@ void Test_CFE_TBL_Internal(void) * registry to the CDS */ UT_InitData(); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 1, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_EarlyInit(); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, @@ -4667,7 +4667,7 @@ void Test_CFE_TBL_Internal(void) UT_SetReadBuffer(&TblFileHeader, sizeof(TblFileHeader)); UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader)); UT_SetDeferredRetcode(UT_KEY(OS_read), 3, 0); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 1, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_Load(App1TblHandle2, CFE_TBL_SRC_FILE, "TblSrcFileName.dat"); EventsCorrect = @@ -4715,7 +4715,7 @@ void Test_CFE_TBL_Internal(void) UT_SetReadBuffer(&TblFileHeader, sizeof(TblFileHeader)); UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader)); UT_SetDeferredRetcode(UT_KEY(OS_read), 3, 0); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 2, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 2, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_Load(App1TblHandle2, CFE_TBL_SRC_FILE, "TblSrcFileName.dat"); EventsCorrect = @@ -4765,7 +4765,7 @@ void Test_CFE_TBL_Internal(void) UT_SetReadBuffer(&TblFileHeader, sizeof(TblFileHeader)); UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader)); UT_SetDeferredRetcode(UT_KEY(OS_read), 3, 0); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 2, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 2, CFE_ES_ERR_RESOURCEID_NOT_VALID); AccessDescPtr = &CFE_TBL_TaskData.Handles[App1TblHandle2]; RegRecPtr = &CFE_TBL_TaskData.Registry[AccessDescPtr->RegIndex]; @@ -4846,7 +4846,7 @@ void Test_CFE_TBL_Internal(void) UT_SetReadBuffer(&TblFileHeader, sizeof(TblFileHeader)); UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader)); UT_SetDeferredRetcode(UT_KEY(OS_read), 3, 0); - UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 2, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 2, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_Load(App1TblHandle2, CFE_TBL_SRC_FILE, "TblSrcFileName.dat"); EventsCorrect = (UT_EventIsInHistory(CFE_TBL_HANDLE_ACCESS_ERR_EID) == true && @@ -4951,7 +4951,7 @@ void Test_CFE_TBL_Internal(void) RegRecPtr->LoadInProgress = CFE_TBL_NO_LOAD_IN_PROGRESS + 1; RegRecPtr->CriticalTable = false; RegRecPtr->DoubleBuffered = true; - UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 1, CFE_ES_ERR_MEM_HANDLE); + UT_SetDeferredRetcode(UT_KEY(CFE_ES_CopyToCDS), 1, CFE_ES_ERR_RESOURCEID_NOT_VALID); RtnCode = CFE_TBL_UpdateInternal(App1TblHandle2, RegRecPtr, AccessDescPtr); EventsCorrect = (UT_GetNumEventsSent() == 0); UT_Report(__FILE__, __LINE__, diff --git a/fsw/cfe-core/unit-test/ut_osprintf_stubs.c b/fsw/cfe-core/unit-test/ut_osprintf_stubs.c index 34005daea..6face1351 100644 --- a/fsw/cfe-core/unit-test/ut_osprintf_stubs.c +++ b/fsw/cfe-core/unit-test/ut_osprintf_stubs.c @@ -67,7 +67,7 @@ const char *UT_OSP_MESSAGES[] = /* PROCESSOR RESET called from CFE_ES_ResetCFE (Commanded). */ [UT_OSP_PROC_RESET_COMMANDED] = "PROCESSOR RESET called from CFE_ES_ResetCFE (Commanded).\n", /* ES SharedData Mutex Take Err Stat=0x~,App=1,Func=TestAPI,Line=12345 */ - [UT_OSP_MUTEX_TAKE] = "ES SharedData Mutex Take Err Stat=0x%x,App=%d,Func=%s,Line=%d\n", + [UT_OSP_MUTEX_TAKE] = "ES SharedData Mutex Take Err Stat=0x%x,Func=%s,Line=%d\n", /* ES Startup: Startup Sync failed - Applications may not have all started */ [UT_OSP_STARTUP_SYNC_FAIL_1] = "ES Startup: Startup Sync failed - Applications may not have all started\n", /* Warning: System Log full, log entry discarded. */ @@ -101,7 +101,7 @@ const char *UT_OSP_MESSAGES[] = /* ES Startup: Unable to extract filename from path: ut57/ */ [UT_OSP_EXTRACT_FILENAME_UT57] = "ES Startup: Unable to extract filename from path: %s.\n", /* ES SharedData Mutex Give Err Stat=0x~,App=1,Func=TestAPI,Line=98765 */ - [UT_OSP_MUTEX_GIVE] = "ES SharedData Mutex Give Err Stat=0x%x,App=%d,Func=%s,Line=%d\n", + [UT_OSP_MUTEX_GIVE] = "ES SharedData Mutex Give Err Stat=0x%x,Func=%s,Line=%d\n", /* ES Startup: Could not find symbol:EntryPoint. EC = 0x~ */ [UT_OSP_CANNOT_FIND_SYMBOL] = "ES Startup: Could not find symbol:%s. EC = 0x%08X\n", /* ES Startup: Error Initializing Volatile(RAM) Volume. EC = 0x~ */ diff --git a/fsw/cfe-core/ut-stubs/ut_es_stubs.c b/fsw/cfe-core/ut-stubs/ut_es_stubs.c index 528cab1ca..f9c26c407 100644 --- a/fsw/cfe-core/ut-stubs/ut_es_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_es_stubs.c @@ -232,7 +232,7 @@ int32 CFE_ES_GetTaskID(CFE_ES_ResourceID_t *TaskIdPtr) ** None ** ** \returns -** Returns either CFE_ES_ERR_APPNAME or CFE_SUCCESS. +** Returns either CFE_ES_ERR_NAME_NOT_FOUND or CFE_SUCCESS. ** ******************************************************************************/ int32 CFE_ES_GetAppIDByName(CFE_ES_ResourceID_t *AppIdPtr, const char *AppName)