diff --git a/modules/cfe_assert/src/cfe_assert_io.c b/modules/cfe_assert/src/cfe_assert_io.c index a9561222b..2d36d7099 100644 --- a/modules/cfe_assert/src/cfe_assert_io.c +++ b/modules/cfe_assert/src/cfe_assert_io.c @@ -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; diff --git a/modules/cfe_assert/src/cfe_assert_runner.c b/modules/cfe_assert/src/cfe_assert_runner.c index 2d58daf46..5d060672b 100644 --- a/modules/cfe_assert/src/cfe_assert_runner.c +++ b/modules/cfe_assert/src/cfe_assert_runner.c @@ -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); @@ -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 @@ -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(); }