Skip to content

Commit

Permalink
Fix nasa#502, remove extra copy of task name
Browse files Browse the repository at this point in the history
There is no need to store the main task name a second time in
the app record, as it is already stored in the task record.
  • Loading branch information
jphickey committed Oct 14, 2020
1 parent 787f3a8 commit 9a31c26
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 47 deletions.
6 changes: 3 additions & 3 deletions fsw/cfe-core/src/es/cfe_es_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,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) )
{
/*
Expand Down Expand Up @@ -1279,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
Expand Down Expand Up @@ -1381,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
Expand Down
29 changes: 12 additions & 17 deletions fsw/cfe-core/src/es/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,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
*/
Expand Down Expand Up @@ -552,18 +546,19 @@ 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);
CFE_ES_TaskRecordSetUsed(TaskRecPtr,AppRecPtr->MainTaskId);
TaskRecPtr->AppId = PendingAppId;
strncpy((char *)TaskRecPtr->TaskName,
(char *)AppRecPtr->TaskInfo.MainTaskName,OS_MAX_API_NAME );
TaskRecPtr->TaskName[OS_MAX_API_NAME - 1]='\0';
/* 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;
Expand Down Expand Up @@ -1174,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
Expand Down Expand Up @@ -1517,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
Expand All @@ -1545,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((char *)AppInfoPtr->MainTaskName, TaskRecPtr->TaskName,
sizeof(AppInfoPtr->MainTaskName) - 1);
AppInfoPtr->MainTaskName[sizeof(AppInfoPtr->MainTaskName) - 1] = '\0';
}

/*
Expand Down
14 changes: 1 addition & 13 deletions fsw/cfe-core/src/es/cfe_es_apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

Expand Down
16 changes: 5 additions & 11 deletions fsw/cfe-core/src/es/cfe_es_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,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
*/
Expand Down Expand Up @@ -842,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
Expand All @@ -853,10 +847,10 @@ 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);
CFE_ES_TaskRecordSetUsed(TaskRecPtr, AppRecPtr->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';
strncpy(TaskRecPtr->TaskName, CFE_ES_ObjectTable[i].ObjectName, sizeof(TaskRecPtr->TaskName)-1);
TaskRecPtr->TaskName[sizeof(TaskRecPtr->TaskName)-1 - 1] = '\0';

CFE_ES_SysLogWrite_Unsync("ES Startup: Core App: %s created. App ID: %lu\n",
CFE_ES_ObjectTable[i].ObjectName,
Expand Down
6 changes: 3 additions & 3 deletions fsw/cfe-core/unit-test/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void ES_UT_SetupSingleAppId(CFE_ES_AppType_Enum_t AppType, CFE_ES_AppState_Enum_
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;

Expand Down Expand Up @@ -2062,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__,
Expand All @@ -2086,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,
Expand Down

0 comments on commit 9a31c26

Please sign in to comment.