diff --git a/fsw/cfe-core/src/es/cfe_es_api.c b/fsw/cfe-core/src/es/cfe_es_api.c index 480955071..d93851e19 100644 --- a/fsw/cfe-core/src/es/cfe_es_api.c +++ b/fsw/cfe-core/src/es/cfe_es_api.c @@ -1181,7 +1181,8 @@ int32 CFE_ES_DeleteChildTask(uint32 OSTaskId) bool TaskIsMain = false; int32 ReturnCode = CFE_SUCCESS; int32 OSReturnCode; - + int32 Result = CFE_SUCCESS; + uint32 AppId= 0xFFFFFFFF; /* ** Make sure the task ID is within range @@ -1224,16 +1225,34 @@ int32 CFE_ES_DeleteChildTask(uint32 OSTaskId) if ( OSReturnCode == OS_SUCCESS ) { /* + ** Get the AppID of the calling Application + */ + Result = CFE_ES_GetAppIDInternal(&AppId); + if (Result != CFE_SUCCESS) + { + CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteChildTask: Error calling CFE_ES_GetAppIDInternal for Task '%d'. RC = 0x%08X\n",(int)TaskId,(unsigned int)Result); + ReturnCode = CFE_ES_ERR_CHILD_TASK_DELETE; + } + else /* else AppId is valid */ + { + /* + ** Decrement the "Registered" child task count for the App + */ + if (CFE_ES_Global.AppTable[AppId].TaskInfo.NumOfChildTasks != 0 ) + { + CFE_ES_Global.AppTable[AppId].TaskInfo.NumOfChildTasks --; + } + ReturnCode = CFE_SUCCESS; + } + /* ** Invalidate the task table entry */ CFE_ES_Global.TaskTable[TaskId].RecordUsed = false; CFE_ES_Global.RegisteredTasks--; - /* ** Report the task delete */ CFE_ES_SysLogWrite_Unsync("CFE_ES_DeleteChildTask Task %u Deleted\n",(unsigned int)OSTaskId ); - ReturnCode = CFE_SUCCESS; } else { @@ -1275,7 +1294,8 @@ int32 CFE_ES_DeleteChildTask(uint32 OSTaskId) } return(ReturnCode); -} /* End of CFE_ES_DeleteTask() */ +} /* End of CFE_ES_DeleteChildTask() */ + /* ** Function: CFE_ES_ExitChildTask diff --git a/fsw/cfe-core/unit-test/es_UT.c b/fsw/cfe-core/unit-test/es_UT.c index 1668a0a35..1e245bb38 100644 --- a/fsw/cfe-core/unit-test/es_UT.c +++ b/fsw/cfe-core/unit-test/es_UT.c @@ -4798,9 +4798,17 @@ void TestAPI(void) CFE_ES_Global.AppTable[0].TaskInfo.MainTaskId = 15; OS_TaskCreate(&CFE_ES_Global.TaskTable[1].TaskId, NULL, NULL, NULL, 0, 0, 0); + uint32 NumOchildTasks = CFE_ES_Global.AppTable[0].TaskInfo.NumOfChildTasks; + uint32 NumORegTasks = CFE_ES_Global.RegisteredTasks; + int32 DeleteChildResult = CFE_ES_DeleteChildTask(CFE_ES_Global.TaskTable[1].TaskId); + int32 DeleteChildTestResult = 0xFFFFFFFF; + if( DeleteChildResult == CFE_SUCCESS && CFE_ES_Global.AppTable[0].TaskInfo.NumOfChildTasks == + NumOchildTasks - 1 && CFE_ES_Global.RegisteredTasks == NumORegTasks - 1 ) + { + DeleteChildTestResult = CFE_SUCCESS; + } UT_Report(__FILE__, __LINE__, - CFE_ES_DeleteChildTask(CFE_ES_Global.TaskTable[1].TaskId) == - CFE_SUCCESS, + DeleteChildTestResult == CFE_SUCCESS, "CFE_ES_DeleteChildTask", "Delete child task successful");