Skip to content

Commit

Permalink
Fix nasa#1595, provide CFE assert lock/unlock
Browse files Browse the repository at this point in the history
Provide the UT_BSP_Lock/Unlock function to be compatible with
nasa/osal#1065.  The library no longer needs to be locked the
entire time a test runs. This also allows test programs to be
multi threaded.
  • Loading branch information
jphickey committed Jun 1, 2021
1 parent 176e3df commit 445e922
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 21 deletions.
22 changes: 22 additions & 0 deletions modules/cfe_assert/src/cfe_assert_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@

CFE_Assert_Global_t CFE_Assert_Global;

void UT_BSP_Lock(void)
{
int32 rc;

rc = OS_MutSemTake(CFE_Assert_Global.AccessMutex);
if (rc != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s(): Error from OS_MutSemTake(): %d\n", __func__, (int)rc);
}
}

void UT_BSP_Unlock(void)
{
int32 rc;

rc = OS_MutSemGive(CFE_Assert_Global.AccessMutex);
if (rc != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s(): Error from OS_MutSemTake(): %d\n", __func__, (int)rc);
}
}

void UT_BSP_Setup(void)
{
CFE_Assert_Global.CurrVerbosity = (2 << UTASSERT_CASETYPE_PASS) - 1;
Expand Down
47 changes: 26 additions & 21 deletions modules/cfe_assert/src/cfe_assert_runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ void CFE_Assert_StatusReport(uint8 MessageType, const char *Prefix, const char *

int32 CFE_Assert_RegisterTest(const char *TestName)
{
int32 rc;
char SetupSegmentName[64];
int32 rc;
char SetupSegmentName[64];
CFE_ES_AppId_t SelfId;

rc = CFE_EVS_Register(CFE_TR_EventFilters, sizeof(CFE_TR_EventFilters) / sizeof(CFE_EVS_BinFilter_t),
CFE_EVS_EventFilter_BINARY);
Expand All @@ -127,28 +128,36 @@ int32 CFE_Assert_RegisterTest(const char *TestName)
return rc;
}

rc = CFE_ES_GetAppID(&SelfId);
if (rc != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s(): Error from CFE_ES_GetAppId(): %08x\n", __func__, (unsigned int)rc);
return rc;
}

/*
* Acquire the mutex. This is needed because UtAssert and its data structures are not thread-safe.
* Only one test app should use UtAssert facilities at a given time.
*/
rc = OS_MutSemTake(CFE_Assert_Global.AccessMutex);
if (rc != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s(): Error from OS_MutSemTake(): %d\n", __func__, (int)rc);
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
}
UT_BSP_Lock();

/*
* After acquiring mutex, record the fact that this app now "owns" the assert functions
* Wait here until "OwnerAppId" is available/undefined
*/
rc = CFE_ES_GetAppID(&CFE_Assert_Global.OwnerAppId);
if (rc != CFE_SUCCESS)
while (CFE_RESOURCEID_TEST_DEFINED(CFE_Assert_Global.OwnerAppId))
{
CFE_ES_WriteToSysLog("%s(): Error from CFE_ES_GetAppId(): %08x\n", __func__, (unsigned int)rc);
OS_MutSemGive(CFE_Assert_Global.AccessMutex);
return rc;
UT_BSP_Unlock();
OS_TaskDelay(100);
UT_BSP_Lock();
}

/*
* After acquiring mutex, record the fact that this app now owns the assert functions
*/
CFE_Assert_Global.OwnerAppId = SelfId;

UT_BSP_Unlock();

/*
* This means the system is operational and at least one app needs to run tests.
* Update library state accordingly. The first test app that gets to this point
Expand Down Expand Up @@ -211,12 +220,8 @@ void CFE_Assert_ExecuteTest(void)
UtTest_Run();

/* unregister the callback and unset the appid */
UT_BSP_Lock();
CFE_Assert_RegisterCallback(NULL);

/* Release the access mutex so the next test program can run */
rc = OS_MutSemGive(CFE_Assert_Global.AccessMutex);
if (rc != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("%s(): Error from OS_MutSemGive(): %d\n", __func__, (int)rc);
}
CFE_Assert_Global.OwnerAppId = CFE_ES_APPID_UNDEFINED;
UT_BSP_Unlock();
}

0 comments on commit 445e922

Please sign in to comment.