Skip to content

Commit

Permalink
Fix nasa#797, Update TIME subsystem for abstract IDs
Browse files Browse the repository at this point in the history
Update the TIME subsystem to use the new ES-supplied ID
abstractions.  Do not use AppID directly as array index
when registering sync callbacks, use the ES-supplied
conversion to array index before accessing local table.

Also update logging to use ES-supplied conversion
  • Loading branch information
jphickey committed Sep 2, 2020
1 parent aa8d7a9 commit 7f0c08e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
22 changes: 16 additions & 6 deletions fsw/cfe-core/src/time/cfe_time_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,22 +819,27 @@ int32 CFE_TIME_RegisterSynchCallback(CFE_TIME_SynchCallbackPtr_t CallbackFuncPt
{
int32 Status;
uint32 AppId;
uint32 AppIndex;

Status = CFE_ES_GetAppID(&AppId);
if (Status == CFE_SUCCESS)
{
Status = CFE_ES_AppID_ToIndex(AppId, &AppIndex);
}
if (Status != CFE_SUCCESS)
{
/* Called from an invalid context */
return Status;
}

if (AppId >= (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0])) ||
CFE_TIME_TaskData.SynchCallback[AppId].Ptr != NULL)
if (AppIndex >= (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0])) ||
CFE_TIME_TaskData.SynchCallback[AppIndex].Ptr != NULL)
{
Status = CFE_TIME_TOO_MANY_SYNCH_CALLBACKS;
}
else
{
CFE_TIME_TaskData.SynchCallback[AppId].Ptr = CallbackFuncPtr;
CFE_TIME_TaskData.SynchCallback[AppIndex].Ptr = CallbackFuncPtr;
}

return Status;
Expand All @@ -848,22 +853,27 @@ int32 CFE_TIME_UnregisterSynchCallback(CFE_TIME_SynchCallbackPtr_t CallbackFunc
{
int32 Status;
uint32 AppId;
uint32 AppIndex;

Status = CFE_ES_GetAppID(&AppId);
if (Status == CFE_SUCCESS)
{
Status = CFE_ES_AppID_ToIndex(AppId, &AppIndex);
}
if (Status != CFE_SUCCESS)
{
/* Called from an invalid context */
return Status;
}

if (AppId >= (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0])) ||
CFE_TIME_TaskData.SynchCallback[AppId].Ptr != CallbackFuncPtr)
if (AppIndex >= (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0])) ||
CFE_TIME_TaskData.SynchCallback[AppIndex].Ptr != CallbackFuncPtr)
{
Status = CFE_TIME_CALLBACK_NOT_REGISTERED;
}
else
{
CFE_TIME_TaskData.SynchCallback[AppId].Ptr = NULL;
CFE_TIME_TaskData.SynchCallback[AppIndex].Ptr = NULL;
}

return Status;
Expand Down
11 changes: 8 additions & 3 deletions fsw/cfe-core/src/time/cfe_time_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,11 +1139,16 @@ void CFE_TIME_Set1HzAdj(CFE_TIME_SysTime_t NewAdjust, int16 Direction)
int32 CFE_TIME_CleanUpApp(uint32 AppId)
{
int32 Status;
uint32 AppIndex;

if (AppId < (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0])))
Status = CFE_ES_AppID_ToIndex(AppId, &AppIndex);
if (Status != CFE_SUCCESS)
{
CFE_TIME_TaskData.SynchCallback[AppId].Ptr = NULL;
Status = CFE_SUCCESS;
/* Do nothing */
}
else if (AppIndex < (sizeof(CFE_TIME_TaskData.SynchCallback) / sizeof(CFE_TIME_TaskData.SynchCallback[0])))
{
CFE_TIME_TaskData.SynchCallback[AppIndex].Ptr = NULL;
}
else
{
Expand Down
21 changes: 12 additions & 9 deletions fsw/cfe-core/unit-test/time_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -3297,6 +3297,7 @@ void Test_CleanUpApp(void)
uint16 i;
uint16 Count;
int32 Status = CFE_SUCCESS;
uint32 AppIndex;
uint32 TestAppId;

#ifdef UT_VERBOSE
Expand All @@ -3313,16 +3314,19 @@ void Test_CleanUpApp(void)
}

/* Add callbacks for 3 apps into callback registry table */
UT_SetAppID(1);
AppIndex = 1;
UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &AppIndex, sizeof(AppIndex), false);
CFE_TIME_RegisterSynchCallback(&ut_time_MyCallbackFunc);
UT_SetAppID(2);
AppIndex = 2;
UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &AppIndex, sizeof(AppIndex), false);
CFE_TIME_RegisterSynchCallback(&ut_time_MyCallbackFunc);
UT_SetAppID(3);
AppIndex = 3;
UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &AppIndex, sizeof(AppIndex), false);
CFE_TIME_RegisterSynchCallback(&ut_time_MyCallbackFunc);

/* Clean up an app which did not have a callback */
TestAppId = 4;
UT_SetAppID(TestAppId);
AppIndex = 4;
UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &AppIndex, sizeof(AppIndex), false);
Status = CFE_TIME_CleanUpApp(TestAppId);
UT_Report(__FILE__, __LINE__,
Status == CFE_SUCCESS,
Expand All @@ -3345,8 +3349,8 @@ void Test_CleanUpApp(void)
"No Sync Callback entry cleared");

/* Clean up an app which did have a callback */
TestAppId = 2;
UT_SetAppID(TestAppId);
AppIndex = 2;
UT_SetDataBuffer(UT_KEY(CFE_ES_AppID_ToIndex), &AppIndex, sizeof(AppIndex), false);
Status = CFE_TIME_CleanUpApp(TestAppId);
UT_Report(__FILE__, __LINE__,
Status == CFE_SUCCESS,
Expand All @@ -3370,8 +3374,7 @@ void Test_CleanUpApp(void)

/* Test response to a bad application ID -
* This is effectively a no-op but here for coverage */
UT_SetAppID(CFE_PLATFORM_ES_MAX_APPLICATIONS);
Status = CFE_TIME_CleanUpApp(CFE_PLATFORM_ES_MAX_APPLICATIONS);
Status = CFE_TIME_CleanUpApp(99999);
UT_Report(__FILE__, __LINE__,
Status == CFE_TIME_CALLBACK_NOT_REGISTERED,
"CFE_TIME_CleanUpApp",
Expand Down

0 comments on commit 7f0c08e

Please sign in to comment.