diff --git a/fsw/cfe-core/src/es/cfe_es_api.c b/fsw/cfe-core/src/es/cfe_es_api.c index 22cbbe1e5..78b2feb25 100644 --- a/fsw/cfe-core/src/es/cfe_es_api.c +++ b/fsw/cfe-core/src/es/cfe_es_api.c @@ -256,7 +256,7 @@ int32 CFE_ES_ReloadApp(CFE_ES_ResourceID_t AppID, const char *AppFileName) { CFE_ES_SysLogWrite_Unsync("CFE_ES_ReloadApp: Reload Application %s Initiated. New filename = %s\n", CFE_ES_AppRecordGetName(AppRecPtr), AppFileName); - strncpy((char *)AppRecPtr->StartParams.FileName, AppFileName, OS_MAX_PATH_LEN); + strncpy(AppRecPtr->StartParams.BasicInfo.FileName, AppFileName, OS_MAX_PATH_LEN); AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RELOAD; } else diff --git a/fsw/cfe-core/src/es/cfe_es_apps.c b/fsw/cfe-core/src/es/cfe_es_apps.c index 8cb13dd16..a20402195 100644 --- a/fsw/cfe-core/src/es/cfe_es_apps.c +++ b/fsw/cfe-core/src/es/cfe_es_apps.c @@ -343,6 +343,236 @@ int32 CFE_ES_ParseFileEntry(const char **TokenList, uint32 NumTokens) } +/* +**------------------------------------------------------------------------------------- +** Name: CFE_ES_LoadModule +** +** Helper function to load + configure (but not start) a new app/lib module +** +** Loads the module file via OSAL and stores all relevant info in the table entry as necessary. +** +**------------------------------------------------------------------------------------- +*/ +int32 CFE_ES_LoadModule(const CFE_ES_ModuleLoadParams_t* LoadParams, CFE_ES_ModuleLoadStatus_t *LoadStatus) +{ + osal_id_t ModuleId; + cpuaddr StartAddr; + int32 ReturnCode; + int32 StatusCode; + + StartAddr = 0; + ReturnCode = CFE_SUCCESS; + + if (LoadParams->FileName[0] != 0) + { + /* + ** Load the module via OSAL. + */ + StatusCode = OS_ModuleLoad ( &ModuleId, + LoadParams->Name, + LoadParams->FileName ); + + if (StatusCode != OS_SUCCESS) + { + CFE_ES_WriteToSysLog("ES Startup: Could not load file:%s. EC = 0x%08X\n", + LoadParams->FileName, (unsigned int)StatusCode); + ModuleId = OS_OBJECT_ID_UNDEFINED; + ReturnCode = CFE_STATUS_EXTERNAL_RESOURCE_FAIL; + } + } + else + { + ModuleId = OS_OBJECT_ID_UNDEFINED; + } + + /* + ** If the Load was OK, then lookup the address of the entry point + */ + if (ReturnCode == CFE_SUCCESS && LoadParams->EntryPoint[0] != 0) + { + StatusCode = OS_SymbolLookup(&StartAddr, LoadParams->EntryPoint); + if (StatusCode != OS_SUCCESS) + { + CFE_ES_WriteToSysLog("ES Startup: Could not find symbol:%s. EC = 0x%08X\n", + LoadParams->EntryPoint, (unsigned int)StatusCode); + ReturnCode = CFE_STATUS_EXTERNAL_RESOURCE_FAIL; + } + } + + if ( ReturnCode == CFE_SUCCESS ) + { + /* store the data in the app record after successful load+lookup */ + LoadStatus->ModuleId = ModuleId; + LoadStatus->EntryAddress = StartAddr; + } + else if (OS_ObjectIdDefined(ModuleId)) + { + /* If the module had been successfully loaded, then unload it, + * so that it does not consume resources */ + StatusCode = OS_ModuleUnload(ModuleId); + if ( StatusCode != OS_SUCCESS ) /* There's not much we can do except notify */ + { + CFE_ES_WriteToSysLog("ES Startup: Failed to unload: %s. EC = 0x%08X\n", + LoadParams->Name, (unsigned int)StatusCode); + } + } + + return ReturnCode; +} + +/* +**------------------------------------------------------------------------------------- +** Name: CFE_ES_GetAppEntryPoint +** +** Helper function to act as the intermediate entry point of an app +** This is to support starting apps before having a fully completed entry in the +** global app table. The app startup will delay until the app creation is completed +** and verified, then the actual entry point will be determined. +** +**------------------------------------------------------------------------------------- +*/ +int32 CFE_ES_GetAppEntryPoint(osal_task_entry *FuncPtr) +{ + CFE_ES_AppRecord_t *AppRecPtr; + int32 ReturnCode; + int32 Timeout; + + /* + * Use the same timeout as was used for the startup script itself. + */ + ReturnCode = CFE_ES_ERR_APP_REGISTER; + Timeout = CFE_PLATFORM_ES_STARTUP_SCRIPT_TIMEOUT_MSEC; + + while(true) + { + OS_TaskDelay(CFE_PLATFORM_ES_STARTUP_SYNC_POLL_MSEC); + + CFE_ES_LockSharedData(__func__,__LINE__); + AppRecPtr = CFE_ES_GetAppRecordByContext(); + if (AppRecPtr != NULL) + { + AppRecPtr->AppState = CFE_ES_AppState_EARLY_INIT; + *FuncPtr = (osal_task_entry)AppRecPtr->ModuleInfo.EntryAddress; + ReturnCode = CFE_SUCCESS; + } + CFE_ES_UnlockSharedData(__func__,__LINE__); + + if (ReturnCode == CFE_SUCCESS || Timeout <= 0) + { + /* end of loop condition */ + break; + } + + Timeout -= CFE_PLATFORM_ES_STARTUP_SYNC_POLL_MSEC; + } + + return (ReturnCode); +} + +/* +**------------------------------------------------------------------------------------- +** Name: CFE_ES_AppEntryPoint +** +** Helper function to act as the intermediate entry point of an app +** This is to support starting apps before having a fully completed entry in the +** global app table. The app startup will delay until the app creation is completed +** and verified, then the actual entry point will be determined. +** +**------------------------------------------------------------------------------------- +*/ +void CFE_ES_AppEntryPoint(void) +{ + osal_task_entry RealEntryFunc; + + if (CFE_ES_GetAppEntryPoint(&RealEntryFunc) == CFE_SUCCESS && + RealEntryFunc != NULL) + { + (*RealEntryFunc)(); + } +} + +/* +**------------------------------------------------------------------------------------- +** Name: CFE_ES_StartMainTask +** +** Helper function to start (but not load) a new app/lib module +** +** Note that OSAL does not separate the action of creating and start a task, providing +** only OS_TaskCreate which does both. But there is a potential race condition if +** the real task code starts and calls e.g. CFE_ES_RegisterApp() or any other function +** that depends on having an AppID context, before its fully registered in the global app table. +** +** Therefore this calls a dedicated CFE_ES_AppEntryPoint which then will wait until +** the task is fully registered in the global, before calling the actual app entry point. +** +**------------------------------------------------------------------------------------- +*/ +int32 CFE_ES_StartAppTask(const CFE_ES_AppStartParams_t* StartParams, CFE_ES_ResourceID_t RefAppId, CFE_ES_ResourceID_t *TaskIdPtr) +{ + CFE_ES_TaskRecord_t *TaskRecPtr; + osal_id_t OsalTaskId; + CFE_ES_ResourceID_t TaskId; + int32 StatusCode; + int32 ReturnCode; + + /* + ** Create the primary task for the newly loaded task + */ + StatusCode = OS_TaskCreate(&OsalTaskId, /* task id */ + StartParams->BasicInfo.Name, /* task name */ + CFE_ES_AppEntryPoint, /* task function pointer */ + NULL, /* stack pointer (allocate) */ + StartParams->StackSize, /* stack size */ + StartParams->Priority, /* task priority */ + OS_FP_ENABLED); /* task options */ + + CFE_ES_LockSharedData(__func__,__LINE__); + + if ( StatusCode == OS_SUCCESS ) + { + /* + * As this is a newly-created task, this shouldn't fail. + * The entry is not (yet) matching the task ID - it will be + * initialized here. + */ + TaskId = CFE_ES_ResourceID_FromOSAL(OsalTaskId); + TaskRecPtr = CFE_ES_LocateTaskRecordByID(TaskId); + if ( CFE_ES_TaskRecordIsUsed(TaskRecPtr) ) + { + CFE_ES_SysLogWrite_Unsync("ES Startup: Error: ES_TaskTable slot for ID %lx in use at task creation!\n", + OS_ObjectIdToInteger(OsalTaskId)); + } + + /* + * Clear any other/stale data that might be in the entry, + * and reset all fields to the correct value. + */ + memset(TaskRecPtr, 0, sizeof(*TaskRecPtr)); + + TaskRecPtr->AppId = RefAppId; + strncpy(TaskRecPtr->TaskName, StartParams->BasicInfo.Name, sizeof(TaskRecPtr->TaskName)-1); + CFE_ES_TaskRecordSetUsed(TaskRecPtr, TaskId); + + /* + ** Increment the registered Task count. + */ + CFE_ES_Global.RegisteredTasks++; + ReturnCode = CFE_SUCCESS; + *TaskIdPtr = TaskId; + } + else + { + CFE_ES_SysLogWrite_Unsync("ES Startup: AppCreate Error: TaskCreate %s Failed. EC = 0x%08X!\n", + StartParams->BasicInfo.Name,(unsigned int)StatusCode); + ReturnCode = CFE_STATUS_EXTERNAL_RESOURCE_FAIL; + *TaskIdPtr = CFE_ES_RESOURCEID_UNDEFINED; + } + + CFE_ES_UnlockSharedData(__func__,__LINE__); + + return ReturnCode; +} + /* **--------------------------------------------------------------------------------------- ** Name: ES_AppCreate @@ -356,19 +586,15 @@ int32 CFE_ES_ParseFileEntry(const char **TokenList, uint32 NumTokens) */ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, const char *FileName, - const void *EntryPointData, + const char *EntryPointName, const char *AppName, uint32 Priority, uint32 StackSize, uint32 ExceptionAction) { - cpuaddr StartAddr; - int32 ReturnCode; CFE_Status_t Status; - osal_id_t ModuleId; - osal_id_t MainTaskId; + CFE_ES_ResourceID_t MainTaskId; CFE_ES_AppRecord_t *AppRecPtr; - CFE_ES_TaskRecord_t *TaskRecPtr; CFE_ES_ResourceID_t PendingAppId; /* @@ -428,6 +654,31 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, { /* Fully clear the entry, just in case of stale data */ memset(AppRecPtr, 0, sizeof(*AppRecPtr)); + + /* + * Fill out the parameters in the StartParams sub-structure + */ + AppRecPtr->Type = CFE_ES_AppType_EXTERNAL; + strncpy(AppRecPtr->StartParams.BasicInfo.Name, AppName, + sizeof(AppRecPtr->StartParams.BasicInfo.Name)-1); + strncpy(AppRecPtr->StartParams.BasicInfo.FileName, FileName, + sizeof(AppRecPtr->StartParams.BasicInfo.FileName)-1); + if (EntryPointName != NULL && strcmp(EntryPointName, "NULL") != 0) + { + strncpy(AppRecPtr->StartParams.BasicInfo.EntryPoint, EntryPointName, + sizeof(AppRecPtr->StartParams.BasicInfo.EntryPoint)-1); + } + + AppRecPtr->StartParams.StackSize = StackSize; + AppRecPtr->StartParams.ExceptionAction = ExceptionAction; + AppRecPtr->StartParams.Priority = Priority; + + /* + * Fill out the Task State info + */ + AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; + AppRecPtr->ControlReq.AppTimerMsec = 0; + CFE_ES_AppRecordSetUsed(AppRecPtr, CFE_ES_RESOURCEID_RESERVED); CFE_ES_Global.LastAppId = PendingAppId; Status = CFE_SUCCESS; @@ -437,142 +688,63 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, CFE_ES_UnlockSharedData(__func__,__LINE__); /* - ** If a slot was found, create the application - */ - if (Status == CFE_SUCCESS) + * If ID allocation was not successful, return now. + * A message regarding the issue should have already been logged + */ + if (Status != CFE_SUCCESS) { - /* - ** Load the module - */ - ReturnCode = OS_ModuleLoad ( &ModuleId, AppName, FileName ); - - /* - ** If the Load was OK, then lookup the address of the entry point - */ - if ( ReturnCode == OS_SUCCESS ) - { - ReturnCode = OS_SymbolLookup( &StartAddr, (const char*)EntryPointData ); - if ( ReturnCode != OS_SUCCESS ) - { - CFE_ES_WriteToSysLog("ES Startup: Could not find symbol:%s. EC = 0x%08X\n", - (const char*)EntryPointData, (unsigned int)ReturnCode); - - CFE_ES_LockSharedData(__func__,__LINE__); - CFE_ES_AppRecordSetFree(AppRecPtr); /* Release slot */ - CFE_ES_UnlockSharedData(__func__,__LINE__); - - /* Unload the module from memory, so that it does not consume resources */ - ReturnCode = OS_ModuleUnload(ModuleId); - if ( ReturnCode != OS_SUCCESS ) /* There's not much we can do except notify */ - { - CFE_ES_WriteToSysLog("ES Startup: Failed to unload APP: %s. EC = 0x%08X\n", - AppName, (unsigned int)ReturnCode); - } - - return(CFE_ES_ERR_APP_CREATE); - } - } - else /* load not successful */ - { - CFE_ES_WriteToSysLog("ES Startup: Could not load cFE application file:%s. EC = 0x%08X\n", - FileName, (unsigned int)ReturnCode); - - CFE_ES_LockSharedData(__func__,__LINE__); - CFE_ES_AppRecordSetFree(AppRecPtr); /* Release slot */ - CFE_ES_UnlockSharedData(__func__,__LINE__); - - return(CFE_ES_ERR_APP_CREATE); - } - - /* - ** If the EntryPoint symbol was found, then start creating the App - */ - CFE_ES_LockSharedData(__func__,__LINE__); - /* - ** Allocate and populate the ES_AppTable entry - */ - AppRecPtr->Type = CFE_ES_AppType_EXTERNAL; - - /* - ** Fill out the parameters in the AppStartParams sub-structure - */ - strncpy((char *)AppRecPtr->StartParams.Name, AppName, OS_MAX_API_NAME); - AppRecPtr->StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; - - strncpy((char *)AppRecPtr->StartParams.EntryPoint, (const char *)EntryPointData, OS_MAX_API_NAME); - AppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; - strncpy((char *)AppRecPtr->StartParams.FileName, FileName, OS_MAX_PATH_LEN); - AppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - - AppRecPtr->StartParams.StackSize = StackSize; - - AppRecPtr->StartParams.StartAddress = StartAddr; - AppRecPtr->StartParams.ModuleId = ModuleId; - - AppRecPtr->StartParams.ExceptionAction = ExceptionAction; - AppRecPtr->StartParams.Priority = Priority; - - /* - ** Fill out the Task State info - */ - AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; - AppRecPtr->ControlReq.AppTimerMsec = 0; - - /* - ** Create the primary task for the newly loaded task - */ - ReturnCode = OS_TaskCreate(&MainTaskId, /* task id */ - AppName, /* task name */ - (osal_task_entry)StartAddr, /* task function pointer */ - NULL, /* stack pointer */ - StackSize, /* stack size */ - Priority, /* task priority */ - OS_FP_ENABLED); /* task options */ - + return Status; + } - if(ReturnCode != OS_SUCCESS) - { - CFE_ES_SysLogWrite_Unsync("ES Startup: AppCreate Error: TaskCreate %s Failed. EC = 0x%08X!\n", - AppName,(unsigned int)ReturnCode); + /* + * Load the module based on StartParams configured above. + */ + Status = CFE_ES_LoadModule(&AppRecPtr->StartParams.BasicInfo, &AppRecPtr->ModuleInfo); - CFE_ES_AppRecordSetFree(AppRecPtr); /* Release slot */ - CFE_ES_UnlockSharedData(__func__,__LINE__); + /* + * If the Load was OK, then complete the initialization + */ + if (Status == CFE_SUCCESS) + { + Status = CFE_ES_StartAppTask(&AppRecPtr->StartParams, PendingAppId, &MainTaskId); + } + else + { + MainTaskId = CFE_ES_RESOURCEID_UNDEFINED; + } - Status = CFE_ES_ERR_APP_CREATE; - } - else - { + /* + * Finalize data in the app table entry, which must be done under lock. + * This transitions the entry from being RESERVED to the real ID. + */ + CFE_ES_LockSharedData(__func__,__LINE__); - /* - ** Record the ES_TaskTable entry - */ - AppRecPtr->MainTaskId = CFE_ES_ResourceID_FromOSAL(MainTaskId); - TaskRecPtr = CFE_ES_LocateTaskRecordByID(AppRecPtr->MainTaskId); + if ( Status == CFE_SUCCESS ) + { + /* + * important - set the ID to its proper value + * which turns this into a real/valid table entry + */ + AppRecPtr->MainTaskId = MainTaskId; + CFE_ES_AppRecordSetUsed(AppRecPtr, PendingAppId); - 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->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 = PendingAppId; - - /* - ** Increment the registered App and Registered External Task variables. - */ - CFE_ES_Global.RegisteredTasks++; - CFE_ES_Global.RegisteredExternalApps++; + /* + ** Increment the registered App counter. + */ + CFE_ES_Global.RegisteredExternalApps++; + } + else + { + /* + * Set the table entry back to free + */ + CFE_ES_AppRecordSetFree(AppRecPtr); + PendingAppId = CFE_ES_RESOURCEID_UNDEFINED; + } - CFE_ES_UnlockSharedData(__func__,__LINE__); + CFE_ES_UnlockSharedData(__func__,__LINE__); - } /* End If OS_TaskCreate */ - } + *ApplicationIdPtr = PendingAppId; return Status; @@ -587,15 +759,13 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, */ int32 CFE_ES_LoadLibrary(CFE_ES_ResourceID_t *LibraryIdPtr, const char *FileName, - const void *EntryPointData, + const char *EntryPointName, const char *LibName) { CFE_ES_LibraryEntryFuncPtr_t FunctionPointer; CFE_ES_LibRecord_t * LibSlotPtr; int32 Status; CFE_ES_ResourceID_t PendingLibId; - osal_id_t ModuleId; - bool IsModuleLoaded; /* * The FileName must not be NULL @@ -613,11 +783,8 @@ int32 CFE_ES_LoadLibrary(CFE_ES_ResourceID_t *LibraryIdPtr, /* ** Allocate an ES_LibTable entry */ - IsModuleLoaded = false; FunctionPointer = NULL; - 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 @@ -663,7 +830,20 @@ int32 CFE_ES_LoadLibrary(CFE_ES_ResourceID_t *LibraryIdPtr, { /* Fully clear the entry, just in case of stale data */ memset(LibSlotPtr, 0, sizeof(*LibSlotPtr)); - strcpy(LibSlotPtr->LibName, LibName); /* Size already checked */ + + /* + * Fill out the parameters in the AppStartParams sub-structure + */ + strncpy(LibSlotPtr->BasicInfo.Name, LibName, + sizeof(LibSlotPtr->BasicInfo.Name)-1); + strncpy(LibSlotPtr->BasicInfo.FileName, FileName, + sizeof(LibSlotPtr->BasicInfo.FileName)-1); + if (EntryPointName != NULL && strcmp(EntryPointName, "NULL") != 0) + { + strncpy(LibSlotPtr->BasicInfo.EntryPoint, EntryPointName, + sizeof(LibSlotPtr->BasicInfo.EntryPoint)-1); + } + CFE_ES_LibRecordSetUsed(LibSlotPtr, CFE_ES_RESOURCEID_RESERVED); CFE_ES_Global.LastLibId = PendingLibId; Status = CFE_SUCCESS; @@ -683,128 +863,51 @@ int32 CFE_ES_LoadLibrary(CFE_ES_ResourceID_t *LibraryIdPtr, } /* - * ------------------- - * IMPORTANT: - * - * there is now a reserved entry in the global library table, - * which must be freed if something goes wrong hereafter. - * - * Avoid any inline "return" statements - all paths must proceed to - * the end of this function where the cleanup will be done. - * - * Record sufficient breadcrumbs along the way, such that proper - * cleanup can be done in case it is necessary. - * ------------------- - */ - - /* - * STAGE 2: - * Do the OS_ModuleLoad() if is called for (i.e. ModuleLoadFile is NOT null) + * Load the module based on StartParams configured above. */ - if (Status == CFE_SUCCESS && FileName != NULL) + Status = CFE_ES_LoadModule(&LibSlotPtr->BasicInfo, &LibSlotPtr->ModuleInfo); + if (Status == CFE_SUCCESS) { - Status = OS_ModuleLoad( &ModuleId, LibName, FileName ); - if (Status == OS_SUCCESS) - { - Status = CFE_SUCCESS; /* just in case CFE_SUCCESS is different than OS_SUCCESS */ - IsModuleLoaded = true; - } - else - { - /* load not successful. Note OS errors are better displayed as decimal integers. */ - CFE_ES_WriteToSysLog("ES Startup: Could not load cFE Shared Library: %d\n", (int)Status); - Status = CFE_ES_ERR_LOAD_LIB; /* convert OS error to CFE error code */ - } + FunctionPointer = (CFE_ES_LibraryEntryFuncPtr_t)LibSlotPtr->ModuleInfo.EntryAddress; + if (FunctionPointer != NULL) + { + Status = (*FunctionPointer)(PendingLibId); + if (Status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("ES Startup: Load Shared Library Init Error = 0x%08x\n", + (unsigned int)Status); + } + } } /* - * STAGE 3: - * Figure out the Entry point / Initialization function. - * - * This depends on whether it is a dynamically loaded or a statically linked library, - * or it could be omitted altogether for libraries which do not require an init function. - * - * For dynamically loaded objects where FileName is non-NULL, the - * "EntryPointData" is a normal C string (const char *) with the name of the function. - * - * If the name of the function is the string "NULL" -- then treat this as no function - * needed and skip the lookup entirely (this is to support startup scripts where some - * string must be in the entry point field). + * Finalize data in the app table entry, which must be done under lock. + * This transitions the entry from being RESERVED to the real type, + * either MAIN_TASK (success) or returning to INVALID (failure). */ - if (Status == CFE_SUCCESS && EntryPointData != NULL) - { - if (strcmp(EntryPointData, "NULL") != 0) - { - /* - * If the entry point is explicitly set as NULL, - * this means the library has no init function - skip the lookup. - * Otherwise lookup the address of the entry point - */ - cpuaddr StartAddr; - - Status = OS_SymbolLookup( &StartAddr, EntryPointData ); - if (Status == OS_SUCCESS) - { - Status = CFE_SUCCESS; /* just in case CFE_SUCCESS is different than OS_SUCCESS */ - FunctionPointer = (CFE_ES_LibraryEntryFuncPtr_t)StartAddr; - } - else - { - /* could not find symbol. Note OS errors are better displayed as decimal integers */ - CFE_ES_WriteToSysLog("ES Startup: Could not find Library Init symbol:%s. EC = %d\n", - (const char *)EntryPointData, (int)Status); - Status = CFE_ES_ERR_LOAD_LIB; /* convert OS error to CFE error code */ - } - } - } + CFE_ES_LockSharedData(__func__,__LINE__); - /* - * STAGE 4: - * Call the Initialization function, if one was identified during the previous stage - */ - if (Status == CFE_SUCCESS && FunctionPointer != NULL) + if ( Status == CFE_SUCCESS ) { - /* - ** Call the library initialization routine + /* + * important - set the ID to its proper value + * which turns this into a real/valid table entry */ - Status = (*FunctionPointer)(*LibraryIdPtr); - if (Status != CFE_SUCCESS) - { - CFE_ES_WriteToSysLog("ES Startup: Load Shared Library Init Error = 0x%08x\n", (unsigned int)Status); - } - } + CFE_ES_LibRecordSetUsed(LibSlotPtr, PendingLibId); - /* - * LAST STAGE: - * Do final clean-up - * - * If fully successful, then increment the "RegisteredLibs" counter. - * Otherwise in case of an error, do clean up based on the breadcrumbs - */ - if(Status == CFE_SUCCESS) - { - /* Increment the counter, which needs to be done under lock */ - CFE_ES_LockSharedData(__func__,__LINE__); - CFE_ES_LibRecordSetUsed(LibSlotPtr, PendingLibId); - CFE_ES_Global.RegisteredLibs++; - CFE_ES_UnlockSharedData(__func__,__LINE__); + /* + * Increment the registered Lib counter. + */ + CFE_ES_Global.RegisteredLibs++; } else { - /* - * If the above code had loaded a module, then unload it - */ - if (IsModuleLoaded) - { - OS_ModuleUnload( ModuleId ); - } - - /* Release Slot - No need to lock as it is resetting just a single value */ - CFE_ES_LibRecordSetFree(LibSlotPtr); - - PendingLibId = CFE_ES_RESOURCEID_UNDEFINED; + CFE_ES_LibRecordSetFree(LibSlotPtr); + PendingLibId = CFE_ES_RESOURCEID_UNDEFINED; } + CFE_ES_UnlockSharedData(__func__,__LINE__); + *LibraryIdPtr = PendingLibId; return(Status); @@ -1014,9 +1117,9 @@ void CFE_ES_ProcessControlRequest(CFE_ES_ResourceID_t AppId) PendingControlReq == CFE_ES_RunStatus_SYS_RELOAD ) { StartupStatus = CFE_ES_AppCreate(&NewAppId, - OrigStartParams.FileName, - OrigStartParams.EntryPoint, - OrigStartParams.Name, + OrigStartParams.BasicInfo.FileName, + OrigStartParams.BasicInfo.EntryPoint, + OrigStartParams.BasicInfo.Name, OrigStartParams.Priority, OrigStartParams.StackSize, OrigStartParams.ExceptionAction); @@ -1167,7 +1270,7 @@ void CFE_ES_ProcessControlRequest(CFE_ES_ResourceID_t AppId) } CFE_EVS_SendEvent(EventID, EventType, "%s Application %s %s", - ReqName, OrigStartParams.Name, MessageDetail); + ReqName, OrigStartParams.BasicInfo.Name, MessageDetail); } } /* End Function */ @@ -1218,7 +1321,7 @@ int32 CFE_ES_CleanUpApp(CFE_ES_ResourceID_t AppId) * * (this will be OS_OBJECT_ID_UNDEFINED if it was not loaded dynamically) */ - ModuleId = AppRecPtr->StartParams.ModuleId; + ModuleId = AppRecPtr->ModuleInfo.ModuleId; } /* @@ -1645,18 +1748,17 @@ int32 CFE_ES_GetAppInfoInternal(CFE_ES_AppRecord_t *AppRecPtr, CFE_ES_AppInfo_t sizeof(AppInfoPtr->Name)-1); AppInfoPtr->Name[sizeof(AppInfoPtr->Name)-1] = '\0'; - strncpy((char *)AppInfoPtr->EntryPoint, - AppRecPtr->StartParams.EntryPoint, + strncpy(AppInfoPtr->EntryPoint, AppRecPtr->StartParams.BasicInfo.EntryPoint, sizeof(AppInfoPtr->EntryPoint) - 1); AppInfoPtr->EntryPoint[sizeof(AppInfoPtr->EntryPoint) - 1] = '\0'; - strncpy((char *)AppInfoPtr->FileName, (char *)AppRecPtr->StartParams.FileName, + strncpy(AppInfoPtr->FileName, AppRecPtr->StartParams.BasicInfo.FileName, sizeof(AppInfoPtr->FileName) - 1); AppInfoPtr->FileName[sizeof(AppInfoPtr->FileName) - 1] = '\0'; - AppInfoPtr->ModuleId = AppRecPtr->StartParams.ModuleId; + AppInfoPtr->ModuleId = AppRecPtr->ModuleInfo.ModuleId; AppInfoPtr->StackSize = AppRecPtr->StartParams.StackSize; - CFE_SB_SET_MEMADDR(AppInfoPtr->StartAddress, AppRecPtr->StartParams.StartAddress); + CFE_SB_SET_MEMADDR(AppInfoPtr->StartAddress, AppRecPtr->ModuleInfo.EntryAddress); AppInfoPtr->ExceptionAction = AppRecPtr->StartParams.ExceptionAction; AppInfoPtr->Priority = AppRecPtr->StartParams.Priority; diff --git a/fsw/cfe-core/src/es/cfe_es_apps.h b/fsw/cfe-core/src/es/cfe_es_apps.h index 4cf2c11bc..2c7540e50 100644 --- a/fsw/cfe-core/src/es/cfe_es_apps.h +++ b/fsw/cfe-core/src/es/cfe_es_apps.h @@ -65,21 +65,61 @@ typedef struct /* -** CFE_ES_AppStartParams_t is a structure of information used when an application is -** created in the system. It is stored in the cFE ES App Table +** CFE_ES_ModuleLoadParams_t contains the information used when a module +** (library or app) load request initially processed in the system. It captures +** the fundamental information - the name, the file to load, its entry point. +** It contains information directly provided by the user, not runtime status or +** other derived information. +** +** This information should remain fairly constant after initial allocation, even +** if the application is restarted for some reason. The major exception is the +** ReloadApp command, which can change the FileName. */ typedef struct { - char Name[OS_MAX_API_NAME]; - char EntryPoint[OS_MAX_API_NAME]; - char FileName[OS_MAX_PATH_LEN]; + char Name[OS_MAX_API_NAME]; + char EntryPoint[OS_MAX_API_NAME]; + char FileName[OS_MAX_PATH_LEN]; - uint32 StackSize; - cpuaddr StartAddress; - osal_id_t ModuleId; +} CFE_ES_ModuleLoadParams_t; + +/* +** CFE_ES_ModuleLoadStatus_t is a structure of information used when a module +** (library or app) is actually loaded in the system. It captures the +** runtime information - the module ID and starting address. +** +** This information may change if the module is reloaded. +*/ +typedef struct +{ + cpuaddr EntryAddress; + osal_id_t ModuleId; - uint16 ExceptionAction; - uint16 Priority; +} CFE_ES_ModuleLoadStatus_t; + + + +/* +** CFE_ES_AppStartParams_t is a structure of information used when an application is +** created in the system. +** +** This is an extension of the CFE_ES_ModuleLoadParams_t which adds information +** about the task stack size and priority. It is only used for apps, as libraries +** do not have a task associated. +*/ +typedef struct +{ + /* + * Basic (static) information about the module + */ + CFE_ES_ModuleLoadParams_t BasicInfo; + + /* + * Extra information the pertains to applications only, not libraries. + */ + cpusize StackSize; + uint16 Priority; + CFE_ES_ExceptionAction_Enum_t ExceptionAction; } CFE_ES_AppStartParams_t; @@ -89,12 +129,13 @@ typedef struct */ typedef struct { - CFE_ES_ResourceID_t AppId; /* The actual AppID of this entry, or undefined */ - CFE_ES_AppState_Enum_t AppState; /* Is the app running, or stopped, or waiting? */ - uint32 Type; /* The type of App: CORE or EXTERNAL */ - CFE_ES_AppStartParams_t StartParams; /* The start parameters for an App */ - CFE_ES_ControlReq_t ControlReq; /* The Control Request Record for External cFE Apps */ - CFE_ES_ResourceID_t MainTaskId; /* The Application's Main Task ID */ + CFE_ES_ResourceID_t AppId; /* The actual AppID of this entry, or undefined */ + CFE_ES_AppState_Enum_t AppState; /* Is the app running, or stopped, or waiting? */ + CFE_ES_AppType_Enum_t Type; /* The type of App: CORE or EXTERNAL */ + CFE_ES_AppStartParams_t StartParams; /* The start parameters for an App */ + CFE_ES_ModuleLoadStatus_t ModuleInfo; /* Runtime module information */ + CFE_ES_ControlReq_t ControlReq; /* The Control Request Record for External cFE Apps */ + CFE_ES_ResourceID_t MainTaskId; /* The Application's Main Task ID */ } CFE_ES_AppRecord_t; @@ -119,8 +160,9 @@ typedef struct */ typedef struct { - CFE_ES_ResourceID_t LibId; /* The actual LibID of this entry, or undefined */ - char LibName[OS_MAX_API_NAME]; /* Library Name */ + CFE_ES_ResourceID_t LibId; /* The actual LibID of this entry, or undefined */ + CFE_ES_ModuleLoadParams_t BasicInfo; /* Basic (static) information about the module */ + CFE_ES_ModuleLoadStatus_t ModuleInfo; /* Runtime information about the module */ } CFE_ES_LibRecord_t; /* @@ -151,13 +193,39 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath ); */ int32 CFE_ES_ParseFileEntry(const char **TokenList, uint32 NumTokens); +/* +** Internal function to load a module (app or library) +** This only loads the code and looks up relevent runtime information. +** It does not start any tasks. +*/ +int32 CFE_ES_LoadModule(const CFE_ES_ModuleLoadParams_t* LoadParams, CFE_ES_ModuleLoadStatus_t *LoadStatus); + +/* +** Internal function to determine the entry point of an app. +** If the app isn't fully registered in the global app table, +** then this delays until the app is completely configured and the entry point is +** confirmed to be valid. +*/ +int32 CFE_ES_GetAppEntryPoint(osal_task_entry *FuncPtr); + +/* +** Intermediate entry point of an app. Determines the actual +** entry point from the global data structures. +*/ +void CFE_ES_AppEntryPoint(void); + +/* +** Internal function to start the main task of an app. +*/ +int32 CFE_ES_StartAppTask(const CFE_ES_AppStartParams_t* StartParams, CFE_ES_ResourceID_t RefAppId, CFE_ES_ResourceID_t *TaskIdPtr); + /* ** Internal function to create/start a new cFE app ** based on the parameters passed in */ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, const char *FileName, - const void *EntryPointData, + const char *EntryPointName, const char *AppName, uint32 Priority, uint32 StackSize, @@ -167,7 +235,7 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr, */ int32 CFE_ES_LoadLibrary(CFE_ES_ResourceID_t *LibraryIdPtr, const char *FileName, - const void *EntryPointData, + const char *EntryPointName, const char *LibName); /* diff --git a/fsw/cfe-core/src/es/cfe_es_resource.h b/fsw/cfe-core/src/es/cfe_es_resource.h index 9ca10533f..82c936cd3 100644 --- a/fsw/cfe-core/src/es/cfe_es_resource.h +++ b/fsw/cfe-core/src/es/cfe_es_resource.h @@ -214,7 +214,7 @@ static inline bool CFE_ES_AppRecordIsMatch(const CFE_ES_AppRecord_t *AppRecPtr, */ static inline const char* CFE_ES_AppRecordGetName(const CFE_ES_AppRecord_t *AppRecPtr) { - return AppRecPtr->StartParams.Name; + return AppRecPtr->StartParams.BasicInfo.Name; } @@ -307,7 +307,7 @@ static inline bool CFE_ES_LibRecordIsMatch(const CFE_ES_LibRecord_t *LibRecPtr, */ static inline const char* CFE_ES_LibRecordGetName(const CFE_ES_LibRecord_t *LibRecPtr) { - return LibRecPtr->LibName; + return LibRecPtr->BasicInfo.Name; } diff --git a/fsw/cfe-core/src/es/cfe_es_start.c b/fsw/cfe-core/src/es/cfe_es_start.c index 5c701b4fc..2a883ef13 100644 --- a/fsw/cfe-core/src/es/cfe_es_start.c +++ b/fsw/cfe-core/src/es/cfe_es_start.c @@ -753,10 +753,9 @@ void CFE_ES_CreateObjects(void) { int32 ReturnCode; uint16 i; - osal_id_t OsalId; CFE_ES_AppRecord_t *AppRecPtr; - CFE_ES_TaskRecord_t *TaskRecPtr; CFE_ES_ResourceID_t PendingAppId; + CFE_ES_ResourceID_t PendingTaskId; CFE_ES_WriteToSysLog("ES Startup: Starting Object Creation calls.\n"); @@ -776,7 +775,27 @@ void CFE_ES_CreateObjects(void) AppRecPtr = CFE_ES_LocateAppRecordByID(PendingAppId); if (AppRecPtr != NULL) { + /* + ** Fill out the parameters in the AppStartParams sub-structure + */ + AppRecPtr->Type = CFE_ES_AppType_CORE; + strncpy(AppRecPtr->StartParams.BasicInfo.Name, CFE_ES_ObjectTable[i].ObjectName, + sizeof(AppRecPtr->StartParams.BasicInfo.Name)-1); + + /* FileName and EntryPoint is not valid for core apps */ + AppRecPtr->StartParams.StackSize = CFE_ES_ObjectTable[i].ObjectSize; + AppRecPtr->StartParams.ExceptionAction = CFE_ES_ExceptionAction_PROC_RESTART; + AppRecPtr->StartParams.Priority = CFE_ES_ObjectTable[i].ObjectPriority; + AppRecPtr->ModuleInfo.EntryAddress = (cpuaddr)CFE_ES_ObjectTable[i].FuncPtrUnion.VoidPtr; + + /* + ** Fill out the Task State info + */ + AppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_RUN; + AppRecPtr->ControlReq.AppTimerMsec = 0; + CFE_ES_AppRecordSetUsed(AppRecPtr, CFE_ES_RESOURCEID_RESERVED); + CFE_ES_Global.LastAppId = PendingAppId; } CFE_ES_UnlockSharedData(__func__,__LINE__); @@ -786,111 +805,60 @@ void CFE_ES_CreateObjects(void) */ if (AppRecPtr != NULL) { - - CFE_ES_LockSharedData(__func__,__LINE__); - - AppRecPtr->Type = CFE_ES_AppType_CORE; - - /* - ** Fill out the parameters in the AppStartParams sub-structure - */ - strncpy((char *)AppRecPtr->StartParams.Name, (char *)CFE_ES_ObjectTable[i].ObjectName, OS_MAX_API_NAME); - AppRecPtr->StartParams.Name[OS_MAX_API_NAME - 1] = '\0'; - /* EntryPoint field is not valid here for base apps */ - /* FileName is not valid for base apps, either */ - AppRecPtr->StartParams.StackSize = CFE_ES_ObjectTable[i].ObjectSize; - AppRecPtr->StartParams.StartAddress = (cpuaddr)CFE_ES_ObjectTable[i].FuncPtrUnion.VoidPtr; - AppRecPtr->StartParams.ExceptionAction = CFE_ES_ExceptionAction_PROC_RESTART; - AppRecPtr->StartParams.Priority = CFE_ES_ObjectTable[i].ObjectPriority; - - - /* - ** Create the task - */ - ReturnCode = OS_TaskCreate(&OsalId, /* task id */ - CFE_ES_ObjectTable[i].ObjectName, /* task name */ - CFE_ES_ObjectTable[i].FuncPtrUnion.MainAppPtr, /* task function pointer */ - NULL, /* stack pointer */ - CFE_ES_ObjectTable[i].ObjectSize, /* stack size */ - CFE_ES_ObjectTable[i].ObjectPriority, /* task priority */ - OS_FP_ENABLED); /* task options */ - - if(ReturnCode != OS_SUCCESS) - { - CFE_ES_AppRecordSetFree(AppRecPtr); - CFE_ES_UnlockSharedData(__func__,__LINE__); - - CFE_ES_WriteToSysLog("ES Startup: OS_TaskCreate error creating core App: %s: EC = 0x%08X\n", - CFE_ES_ObjectTable[i].ObjectName, (unsigned int)ReturnCode); - - /* - ** Delay to allow the message to be read - */ - OS_TaskDelay(CFE_ES_PANIC_DELAY); - - /* - ** cFE Cannot continue to start up. - */ - CFE_PSP_Panic(CFE_PSP_PANIC_CORE_APP); - - } - else - { - AppRecPtr->MainTaskId = CFE_ES_ResourceID_FromOSAL(OsalId); - TaskRecPtr = CFE_ES_LocateTaskRecordByID(AppRecPtr->MainTaskId); - - /* - ** Allocate and populate the CFE_ES_Global.TaskTable entry - */ - if ( CFE_ES_TaskRecordIsUsed(TaskRecPtr) ) - { - CFE_ES_SysLogWrite_Unsync("ES Startup: CFE_ES_Global.TaskTable record used error for App: %s, continuing.\n", - CFE_ES_ObjectTable[i].ObjectName); - } - CFE_ES_TaskRecordSetUsed(TaskRecPtr, AppRecPtr->MainTaskId); - TaskRecPtr->AppId = CFE_ES_AppRecordGetID(AppRecPtr); - 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))); + /* + ** Start the core app main task + ** (core apps are already in memory - no loading needed) + */ + ReturnCode = CFE_ES_StartAppTask(&AppRecPtr->StartParams, PendingAppId, &PendingTaskId); - CFE_ES_AppRecordSetUsed(AppRecPtr, PendingAppId); - - /* - ** Increment the registered App and Registered External Task variables. - */ - CFE_ES_Global.RegisteredTasks++; - CFE_ES_Global.RegisteredCoreApps++; - - CFE_ES_UnlockSharedData(__func__,__LINE__); - - } + /* + * Finalize data in the app table entry, which must be done under lock. + * This transitions the entry from being RESERVED to the real type, + * either MAIN_TASK (success) or returning to INVALID (failure). + */ + CFE_ES_LockSharedData(__func__,__LINE__); + + if ( ReturnCode == OS_SUCCESS ) + { + AppRecPtr->MainTaskId = PendingTaskId; + CFE_ES_AppRecordSetUsed(AppRecPtr, PendingAppId); + + /* + ** Increment the Core App counter. + */ + CFE_ES_Global.RegisteredCoreApps++; + ReturnCode = CFE_SUCCESS; + } + else + { + /* failure mode - just clear the whole app table entry. + * This will set the AppType back to CFE_ES_ResourceType_INVALID (0), + * as well as clearing any other data that had been written */ + memset(AppRecPtr, 0, sizeof(*AppRecPtr)); + } + + CFE_ES_UnlockSharedData(__func__,__LINE__); } - else /* appSlot not found -- This should never happen!*/ + else { - CFE_ES_WriteToSysLog("ES Startup: Error, No free application slots available for CORE App!\n"); - /* - ** Delay to allow the message to be read - */ - OS_TaskDelay(CFE_ES_PANIC_DELAY); - - /* - ** cFE Cannot continue to start up. - */ - CFE_PSP_Panic(CFE_PSP_PANIC_CORE_APP); - + /* appSlot not found -- This should never happen!*/ + CFE_ES_WriteToSysLog("ES Startup: Error, No free application slots available for CORE App!\n"); + ReturnCode = CFE_ES_ERR_APP_CREATE; } - /* - * CFE_ES_MainTaskSyncDelay() will delay this thread until the - * newly-started thread calls CFE_ES_WaitForSystemState() - */ - if (CFE_ES_MainTaskSyncDelay(CFE_ES_AppState_RUNNING, CFE_PLATFORM_CORE_MAX_STARTUP_MSEC) != CFE_SUCCESS) + if ( ReturnCode == CFE_SUCCESS ) + { + /* + * CFE_ES_MainTaskSyncDelay() will delay this thread until the + * newly-started thread calls CFE_ES_WaitForSystemState() + */ + ReturnCode = CFE_ES_MainTaskSyncDelay(CFE_ES_AppState_RUNNING, CFE_PLATFORM_CORE_MAX_STARTUP_MSEC*1000); + } + + if ( ReturnCode != CFE_SUCCESS ) { - CFE_ES_WriteToSysLog("ES Startup: Core App %s did not complete initialization\n", - CFE_ES_ObjectTable[i].ObjectName); + CFE_ES_WriteToSysLog("ES Startup: OS_TaskCreate error creating core App: %s: EC = 0x%08X\n", + CFE_ES_ObjectTable[i].ObjectName, (unsigned int)ReturnCode); /* ** Delay to allow the message to be read diff --git a/fsw/cfe-core/unit-test/es_UT.c b/fsw/cfe-core/unit-test/es_UT.c index 3a134cf50..951918a1b 100644 --- a/fsw/cfe-core/unit-test/es_UT.c +++ b/fsw/cfe-core/unit-test/es_UT.c @@ -278,9 +278,9 @@ void ES_UT_SetupSingleAppId(CFE_ES_AppType_Enum_t AppType, CFE_ES_AppState_Enum_ if (AppName) { - strncpy(LocalAppPtr->StartParams.Name, AppName, - sizeof(LocalAppPtr->StartParams.Name)-1); - LocalAppPtr->StartParams.Name[sizeof(LocalAppPtr->StartParams.Name)-1] = 0; + strncpy(LocalAppPtr->StartParams.BasicInfo.Name, AppName, + sizeof(LocalAppPtr->StartParams.BasicInfo.Name)-1); + LocalAppPtr->StartParams.BasicInfo.Name[sizeof(LocalAppPtr->StartParams.BasicInfo.Name)-1] = 0; strncpy(LocalTaskPtr->TaskName, AppName, sizeof(LocalTaskPtr->TaskName)-1); LocalTaskPtr->TaskName[sizeof(LocalTaskPtr->TaskName)-1] = 0; @@ -360,9 +360,9 @@ void ES_UT_SetupSingleLibId(const char *LibName, CFE_ES_LibRecord_t **OutLibRec) if (LibName) { - strncpy(LocalLibPtr->LibName, LibName, - sizeof(LocalLibPtr->LibName)-1); - LocalLibPtr->LibName[sizeof(LocalLibPtr->LibName)-1] = 0; + strncpy(LocalLibPtr->BasicInfo.Name, LibName, + sizeof(LocalLibPtr->BasicInfo.Name)-1); + LocalLibPtr->BasicInfo.Name[sizeof(LocalLibPtr->BasicInfo.Name)-1] = 0; } if (OutLibRec) @@ -986,10 +986,11 @@ void TestStartupErrorPaths(void) ++TaskRecPtr; } + UT_SetHookFunction(UT_KEY(OS_TaskCreate), ES_UT_SetAppStateHook, NULL); CFE_ES_CreateObjects(); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_RECORD_USED]) && - UT_GetStubCount(UT_KEY(OS_printf)) == 23, + UT_GetStubCount(UT_KEY(OS_printf)) == 13, "CFE_ES_CreateObjects", "Record used error"); @@ -1008,11 +1009,12 @@ void TestStartupErrorPaths(void) } UT_SetDeferredRetcode(UT_KEY(CFE_TBL_EarlyInit), 1, -1); + UT_SetHookFunction(UT_KEY(OS_TaskCreate), ES_UT_SetAppStateHook, NULL); CFE_ES_CreateObjects(); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_RECORD_USED]) && UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_EARLYINIT]) && - UT_GetStubCount(UT_KEY(OS_printf)) == 24, + UT_GetStubCount(UT_KEY(OS_printf)) == 14, "CFE_ES_CreateObjects", "Error returned when calling function"); @@ -1022,10 +1024,11 @@ void TestStartupErrorPaths(void) ES_ResetUnitTest(); UT_SetForceFail(UT_KEY(OS_TaskCreate), OS_ERROR); UT_SetForceFail(UT_KEY(OS_BinSemCreate), OS_ERROR); + UT_SetHookFunction(UT_KEY(OS_TaskCreate), ES_UT_SetAppStateHook, NULL); CFE_ES_CreateObjects(); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_CORE_APP_CREATE]) && - UT_GetStubCount(UT_KEY(OS_printf)) == 13, + UT_GetStubCount(UT_KEY(OS_printf)) == 18, "CFE_ES_CreateObjects", "Error creating core application"); @@ -1175,12 +1178,9 @@ void TestApps(void) UT_SetReadBuffer(StartupScript, NumBytes); CFE_ES_StartApplications(CFE_PSP_RST_TYPE_PROCESSOR, CFE_PLATFORM_ES_NONVOL_STARTUP_FILE); - UT_Report(__FILE__, __LINE__, - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_FILE_LINE_TOO_LONG]) && - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_ES_APP_STARTUP_OPEN]) && - UT_GetStubCount(UT_KEY(OS_printf)) == 8, - "CFE_ES_StartApplications", - "Line too long"); + UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_FILE_LINE_TOO_LONG])); + UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_ES_APP_STARTUP_OPEN])); + UtAssert_UINT32_EQ(UT_GetStubCount(UT_KEY(OS_printf)), 5); /* Create a valid startup script for subsequent tests */ strncpy(StartupScript, @@ -1232,13 +1232,11 @@ void TestApps(void) /* Test successfully starting an application */ ES_ResetUnitTest(); UT_SetReadBuffer(StartupScript, NumBytes); + UT_SetHookFunction(UT_KEY(OS_TaskCreate), ES_UT_SetAppStateHook, NULL); CFE_ES_StartApplications(CFE_PSP_RST_TYPE_PROCESSOR, CFE_PLATFORM_ES_NONVOL_STARTUP_FILE); - UT_Report(__FILE__, __LINE__, - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_ES_APP_STARTUP_OPEN]) && - UT_GetStubCount(UT_KEY(OS_printf)) == 8, - "CFE_ES_StartApplications", - "Start application; successful"); + UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_ES_APP_STARTUP_OPEN])); + UtAssert_UINT32_EQ(UT_GetStubCount(UT_KEY(OS_printf)), 5); /* Test parsing the startup script with an unknown entry type */ ES_ResetUnitTest(); @@ -1277,11 +1275,8 @@ void TestApps(void) 170, 4096, 1); - UT_Report(__FILE__, __LINE__, - Return == CFE_ES_ERR_APP_CREATE && - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_APP_CREATE]), - "CFE_ES_AppCreate", - "Task create failure"); + UtAssert_INT32_EQ(Return, CFE_STATUS_EXTERNAL_RESOURCE_FAIL); + UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_APP_CREATE])); /* Test application creation with NULL file name */ ES_ResetUnitTest(); @@ -1350,11 +1345,8 @@ void TestApps(void) 170, 8192, 1); - UT_Report(__FILE__, __LINE__, - Return == CFE_ES_ERR_APP_CREATE && - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_EXTRACT_FILENAME_UT55]), - "CFE_ES_AppCreate", - "File load failure"); + UtAssert_INT32_EQ(Return, CFE_STATUS_EXTERNAL_RESOURCE_FAIL); + UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_EXTRACT_FILENAME_UT55])); /* Test application loading and creation where all app slots are taken */ ES_ResetUnitTest(); @@ -1390,11 +1382,8 @@ void TestApps(void) 170, 8192, 1); - UT_Report(__FILE__, __LINE__, - Return == CFE_ES_ERR_APP_CREATE && - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_CANNOT_FIND_SYMBOL]), - "CFE_ES_AppCreate", - "Entry point symbol lookup failure"); + UtAssert_INT32_EQ(Return, CFE_STATUS_EXTERNAL_RESOURCE_FAIL); + UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_CANNOT_FIND_SYMBOL])); /* Test application loading and creation where the entry point symbol @@ -1410,12 +1399,9 @@ void TestApps(void) 170, 8192, 1); - UT_Report(__FILE__, __LINE__, - Return == CFE_ES_ERR_APP_CREATE && - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_CANNOT_FIND_SYMBOL]) && - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_MODULE_UNLOAD_FAILED]), - "CFE_ES_AppCreate", - "Module unload failure after entry point lookup failure"); + UtAssert_INT32_EQ(Return, CFE_STATUS_EXTERNAL_RESOURCE_FAIL); + UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_CANNOT_FIND_SYMBOL])); + UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_MODULE_UNLOAD_FAILED])); /* * Set up a situation where attempting to get appID by context, @@ -1498,17 +1484,17 @@ void TestApps(void) /* Test a successful control action request to exit an application */ ES_ResetUnitTest(); ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); - strncpy((char *) UtAppRecPtr->StartParams.FileName, + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.FileName, "/ram/Filename", OS_MAX_PATH_LEN); - UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, + UtAppRecPtr->StartParams.BasicInfo.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.EntryPoint, "NotNULL", OS_MAX_API_NAME); - UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.BasicInfo.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; UtAppRecPtr->StartParams.Priority = 255; UtAppRecPtr->StartParams.StackSize = 8192; UtAppRecPtr->StartParams.ExceptionAction = 0; - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_EXIT; Id = CFE_ES_AppRecordGetID(UtAppRecPtr); @@ -1525,7 +1511,7 @@ void TestApps(void) ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_EXIT; UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); UT_Report(__FILE__, __LINE__, @@ -1541,7 +1527,7 @@ void TestApps(void) UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); UT_Report(__FILE__, __LINE__, @@ -1557,7 +1543,7 @@ void TestApps(void) UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART; UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); UT_Report(__FILE__, __LINE__, @@ -1572,7 +1558,7 @@ void TestApps(void) ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART; - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); UT_SetForceFail(UT_KEY(OS_TaskCreate), OS_ERROR); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); @@ -1588,7 +1574,7 @@ void TestApps(void) ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RELOAD; - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); @@ -1604,7 +1590,7 @@ void TestApps(void) ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RELOAD; - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); UT_SetForceFail(UT_KEY(OS_TaskCreate), OS_ERROR); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); @@ -1618,17 +1604,17 @@ void TestApps(void) */ ES_ResetUnitTest(); ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); - strncpy((char *) UtAppRecPtr->StartParams.FileName, + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.FileName, "/ram/FileName", OS_MAX_PATH_LEN); - UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NULL", + UtAppRecPtr->StartParams.BasicInfo.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.EntryPoint, "NULL", OS_MAX_API_NAME); - UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.BasicInfo.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; UtAppRecPtr->StartParams.Priority = 255; UtAppRecPtr->StartParams.StackSize = 8192; UtAppRecPtr->StartParams.ExceptionAction = 0; - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_ERROR; Id = CFE_ES_AppRecordGetID(UtAppRecPtr); @@ -1646,7 +1632,7 @@ void TestApps(void) UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_APP_ERROR; - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); UT_Report(__FILE__, __LINE__, @@ -1657,19 +1643,19 @@ void TestApps(void) /* Test a successful control action request to stop an application */ ES_ResetUnitTest(); ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); - strncpy((char *) UtAppRecPtr->StartParams.FileName, + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.FileName, "/ram/FileName", OS_MAX_PATH_LEN); - UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NULL", + UtAppRecPtr->StartParams.BasicInfo.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.EntryPoint, "NULL", OS_MAX_API_NAME); - UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.BasicInfo.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; UtAppRecPtr->StartParams.Priority = 255; UtAppRecPtr->StartParams.StackSize = 8192; UtAppRecPtr->StartParams.ExceptionAction = 0; UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_DELETE; - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); UT_Report(__FILE__, __LINE__, @@ -1680,19 +1666,19 @@ void TestApps(void) /* Test a successful control action request to restart an application */ ES_ResetUnitTest(); ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); - strncpy((char *) UtAppRecPtr->StartParams.FileName, + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.FileName, "/ram/FileName", OS_MAX_PATH_LEN); - UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NULL", + UtAppRecPtr->StartParams.BasicInfo.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.EntryPoint, "NULL", OS_MAX_API_NAME); - UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.BasicInfo.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; UtAppRecPtr->StartParams.Priority = 255; UtAppRecPtr->StartParams.StackSize = 8192; UtAppRecPtr->StartParams.ExceptionAction = 0; UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RESTART; - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); UT_Report(__FILE__, __LINE__, @@ -1703,19 +1689,19 @@ void TestApps(void) /* Test a successful control action request to reload an application */ ES_ResetUnitTest(); ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); - strncpy((char *) UtAppRecPtr->StartParams.FileName, + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.FileName, "/ram/FileName", OS_MAX_PATH_LEN); - UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NULL", + UtAppRecPtr->StartParams.BasicInfo.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.EntryPoint, "NULL", OS_MAX_API_NAME); - UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.BasicInfo.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; UtAppRecPtr->StartParams.Priority = 255; UtAppRecPtr->StartParams.StackSize = 8192; UtAppRecPtr->StartParams.ExceptionAction = 0; UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_RELOAD; - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); UT_Report(__FILE__, __LINE__, @@ -1728,19 +1714,19 @@ void TestApps(void) */ ES_ResetUnitTest(); ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); - strncpy((char *) UtAppRecPtr->StartParams.FileName, + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.FileName, "/ram/FileName", OS_MAX_PATH_LEN); - UtAppRecPtr->StartParams.FileName[OS_MAX_PATH_LEN - 1] = '\0'; - strncpy((char *) UtAppRecPtr->StartParams.EntryPoint, "NULL", + UtAppRecPtr->StartParams.BasicInfo.FileName[OS_MAX_PATH_LEN - 1] = '\0'; + strncpy((char *) UtAppRecPtr->StartParams.BasicInfo.EntryPoint, "NULL", OS_MAX_API_NAME); - UtAppRecPtr->StartParams.EntryPoint[OS_MAX_API_NAME - 1] = + UtAppRecPtr->StartParams.BasicInfo.EntryPoint[OS_MAX_API_NAME - 1] = '\0'; UtAppRecPtr->StartParams.Priority = 255; UtAppRecPtr->StartParams.StackSize = 8192; UtAppRecPtr->StartParams.ExceptionAction = 0; UtAppRecPtr->ControlReq.AppControlRequest = CFE_ES_RunStatus_SYS_EXCEPTION; - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); CFE_ES_ProcessControlRequest(Id); UT_Report(__FILE__, __LINE__, @@ -1809,7 +1795,7 @@ void TestApps(void) ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); ES_UT_SetupForOSCleanup(); - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); UT_SetForceFail(UT_KEY(OS_TaskDelete), OS_ERROR); UT_SetForceFail(UT_KEY(OS_close), OS_ERROR); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); @@ -1823,7 +1809,7 @@ void TestApps(void) */ ES_ResetUnitTest(); ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, NULL); ES_UT_SetupForOSCleanup(); UT_SetDeferredRetcode(UT_KEY(OS_MutSemDelete), 1, OS_ERROR); @@ -1838,7 +1824,7 @@ void TestApps(void) */ ES_ResetUnitTest(); ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); UT_SetDeferredRetcode(UT_KEY(OS_ModuleUnload), 1, OS_ERROR); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); UT_Report(__FILE__, __LINE__, @@ -1851,7 +1837,7 @@ void TestApps(void) */ ES_ResetUnitTest(); ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, NULL); - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); UT_SetDeferredRetcode(UT_KEY(CFE_EVS_CleanUpApp), 1, -1); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); UT_Report(__FILE__, __LINE__, @@ -2023,12 +2009,12 @@ void TestApps(void) 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); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.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); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); /* Associate a child task with the app to be deleted */ ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, NULL); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); @@ -2051,7 +2037,7 @@ void TestApps(void) 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); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); ES_UT_SetupMemPoolId(&UtPoolRecPtr); UtPoolRecPtr->OwnerAppID = CFE_ES_AppRecordGetID(UtAppRecPtr); UtPoolRecPtr->PoolID = CFE_ES_ResourceID_FromInteger(99999); /* Mismatch */ @@ -2072,10 +2058,10 @@ void TestApps(void) /* 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); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); /* Setup a second entry which will NOT be deleted */ ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, NULL, &UtTaskRecPtr); - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, NULL, NULL); + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, NULL, NULL); /* Associate a child task with the app to be deleted */ ES_UT_SetupChildTaskId(UtAppRecPtr, NULL, NULL); @@ -2131,7 +2117,7 @@ void TestApps(void) /* Setup an entry which will be deleted */ ES_UT_SetupSingleAppId(CFE_ES_AppType_EXTERNAL, CFE_ES_AppState_RUNNING, NULL, &UtAppRecPtr, &UtTaskRecPtr); - OS_ModuleLoad(&UtAppRecPtr->StartParams.ModuleId, "UT", + OS_ModuleLoad(&UtAppRecPtr->ModuleInfo.ModuleId, "UT", "ut-module"); Id = CFE_ES_AppRecordGetID(UtAppRecPtr); UT_Report(__FILE__, __LINE__, @@ -2202,7 +2188,7 @@ void TestResourceID(void) void TestLibs(void) { CFE_ES_LibRecord_t *UtLibRecPtr; - char LongLibraryName[sizeof(UtLibRecPtr->LibName)+1]; + char LongLibraryName[sizeof(UtLibRecPtr->BasicInfo.Name)+1]; CFE_ES_ResourceID_t Id; uint32 j; int32 Return; @@ -2216,11 +2202,8 @@ void TestLibs(void) "filename", "EntryPoint", "LibName"); - UT_Report(__FILE__, __LINE__, - Return == -444 && - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_SHARED_LIBRARY_INIT]), - "CFE_ES_LoadLibrary", - "Load shared library initialization failure"); + UtAssert_INT32_EQ(Return, -444); + UtAssert_NONZERO(UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_SHARED_LIBRARY_INIT])); /* Test Load library returning an error on a null pointer argument */ Return = CFE_ES_LoadLibrary(&Id, @@ -2242,8 +2225,8 @@ void TestLibs(void) "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)); - LongLibraryName[sizeof(UtLibRecPtr->LibName)] = '\0'; + memset(&LongLibraryName[0], 'a', sizeof(LongLibraryName)-1); + LongLibraryName[sizeof(LongLibraryName)-1] = '\0'; Return = CFE_ES_LoadLibrary(&Id, "filename", "EntryPoint", @@ -2290,10 +2273,7 @@ void TestLibs(void) "/cf/apps/tst_lib.bundle", "TST_LIB_Init", "TST_LIB"); - UT_Report(__FILE__, __LINE__, - Return == CFE_ES_ERR_LOAD_LIB, - "CFE_ES_LoadLibrary", - "Load shared library failure"); + UtAssert_INT32_EQ(Return, CFE_STATUS_EXTERNAL_RESOURCE_FAIL); /* Test shared library loading and initialization where the library * entry point symbol cannot be found @@ -2304,10 +2284,7 @@ void TestLibs(void) "/cf/apps/tst_lib.bundle", "TST_LIB_Init", "TST_LIB"); - UT_Report(__FILE__, __LINE__, - Return == CFE_ES_ERR_LOAD_LIB, - "CFE_ES_LoadLibrary", - "Could not find library initialization symbol"); + UtAssert_INT32_EQ(Return, CFE_STATUS_EXTERNAL_RESOURCE_FAIL); /* Test shared library loading and initialization where the library * initialization function fails and then must be cleaned up diff --git a/fsw/cfe-core/unit-test/ut_osprintf_stubs.c b/fsw/cfe-core/unit-test/ut_osprintf_stubs.c index 6face1351..facd86a3c 100644 --- a/fsw/cfe-core/unit-test/ut_osprintf_stubs.c +++ b/fsw/cfe-core/unit-test/ut_osprintf_stubs.c @@ -93,7 +93,7 @@ const char *UT_OSP_MESSAGES[] = /* ES Startup: Error Re-Formating Volatile(RAM) Volume. EC = 0x~ */ [UT_OSP_REFORMAT_VOLATILE] = "ES Startup: Error Re-Formating Volatile(RAM) Volume. EC = 0x%08X\n", /* ES Startup: Could not load cFE application file:ut/filename.x. EC = 0x~ */ - [UT_OSP_EXTRACT_FILENAME_UT55] = "ES Startup: Could not load cFE application file:%s. EC = 0x%08X\n", + [UT_OSP_EXTRACT_FILENAME_UT55] = "ES Startup: Could not load file:%s. EC = 0x%08X\n", /* ES Startup: Unable to extract filename from path: ut46/ */ [UT_OSP_EXTRACT_FILENAME_UT46] = "ES Startup: Unable to extract filename from path: %s.\n", /* ES Startup: No free application slots available */ @@ -123,7 +123,7 @@ const char *UT_OSP_MESSAGES[] = /* ES Startup: Error Creating Volatile(RAM) Volume. EC = 0x~ */ [UT_OSP_CREATE_VOLATILE] = "ES Startup: Error Creating Volatile(RAM) Volume. EC = 0x%08X\n", /* ES Startup: Failed to unload APP: AppName. EC = 0x~ */ - [UT_OSP_MODULE_UNLOAD_FAILED] = "ES Startup: Failed to unload APP: %s. EC = 0x%08X\n", + [UT_OSP_MODULE_UNLOAD_FAILED] = "ES Startup: Failed to unload: %s. EC = 0x%08X\n", /* POWERON RESET called from CFE_ES_ResetCFE (Commanded). */ [UT_OSP_POR_COMMANDED] = "POWERON RESET called from CFE_ES_ResetCFE (Commanded).\n", /* ES Startup: Error Re-Mounting Volatile(RAM) Volume. EC = 0x~ */ @@ -159,7 +159,7 @@ const char *UT_OSP_MESSAGES[] = /* ES Startup: Error, No free application slots available for CORE App! */ [UT_OSP_NO_FREE_CORE_APP_SLOTS] = "ES Startup: Error, No free application slots available for CORE App!\n", /* ES Startup: CFE_ES_Global.TaskTable record used error for App: CFE_EVS, continuing. */ - [UT_OSP_RECORD_USED] = "ES Startup: CFE_ES_Global.TaskTable record used error for App: %s, continuing.\n", + [UT_OSP_RECORD_USED] = "ES Startup: Error: ES_TaskTable slot for ID %lx in use at task creation!\n", /* CFE_ES_ExitChildTask called from invalid task context */ [UT_OSP_TASKEXIT_BAD_CONTEXT] = "CFE_ES_ExitChildTask called from invalid task context\n", };