Skip to content

Commit

Permalink
Fix #1691, Verify Callback functions are run.
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed Aug 12, 2021
1 parent ddba337 commit 2fb070a
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions modules/cfe_testcase/src/time_external_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,39 @@

int32 TestCallbackFunction(void)
{
CFE_FT_Global.Count += 1;
return CFE_SUCCESS;
}

int32 TestCallbackFunction2(void)
{
CFE_FT_Global.Count = 0;
return CFE_SUCCESS;
}

void TestCallback(void)
{
CFE_FT_Global.Count = 1;

UtPrintf("Testing: CFE_TIME_RegisterSynchCallback, CFE_TIME_UnregisterSynchCallback");

UtAssert_INT32_EQ(CFE_TIME_RegisterSynchCallback(&TestCallbackFunction), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_TIME_RegisterSynchCallback(&TestCallbackFunction2), CFE_TIME_TOO_MANY_SYNCH_CALLBACKS);

OS_TaskDelay(2000);
UtAssert_INT32_GTEQ(CFE_FT_Global.Count, 2);

CFE_FT_Global.Count = 1;
UtAssert_INT32_EQ(CFE_TIME_UnregisterSynchCallback(&TestCallbackFunction), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_TIME_UnregisterSynchCallback(&TestCallbackFunction), CFE_TIME_CALLBACK_NOT_REGISTERED);

OS_TaskDelay(2000);
UtAssert_INT32_LTEQ(CFE_FT_Global.Count, 2);

UtAssert_INT32_EQ(CFE_TIME_UnregisterSynchCallback(NULL), CFE_TIME_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_TIME_RegisterSynchCallback(NULL), CFE_TIME_BAD_ARGUMENT);
}

void TestExternal(void)
{
#if ((CFE_PLATFORM_TIME_CFG_SRC_MET == true) || (CFE_PLATFORM_TIME_CFG_SRC_GPS == true) || \
Expand All @@ -51,7 +76,8 @@ void TestExternal(void)
#endif

UtPrintf("Testing: CFE_TIME_ExternalTone, CFE_TIME_ExternalMET, CFE_TIME_ExternalGPS, CFE_TIME_ExternalTime");

/* These time calls could impact the system timekeeping. Likely impact is incorrect time for one update cycle, a
* rejected external time update, multiple tone's or external updates detected, or similar. */
UtAssert_VOIDCALL(CFE_TIME_ExternalTone());

#if (CFE_PLATFORM_TIME_CFG_SRC_MET == true)
Expand All @@ -67,22 +93,8 @@ void TestExternal(void)
#endif
}

void TestCallback(void)
{
UtPrintf("Testing: CFE_TIME_RegisterSynchCallback, CFE_TIME_UnregisterSynchCallback");

UtAssert_INT32_EQ(CFE_TIME_RegisterSynchCallback(&TestCallbackFunction), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_TIME_RegisterSynchCallback(&TestCallbackFunction2), CFE_TIME_TOO_MANY_SYNCH_CALLBACKS);

UtAssert_INT32_EQ(CFE_TIME_UnregisterSynchCallback(&TestCallbackFunction), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_TIME_UnregisterSynchCallback(&TestCallbackFunction), CFE_TIME_CALLBACK_NOT_REGISTERED);

UtAssert_INT32_EQ(CFE_TIME_UnregisterSynchCallback(NULL), CFE_TIME_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_TIME_RegisterSynchCallback(NULL), CFE_TIME_BAD_ARGUMENT);
}

void TimeExternalTestSetup(void)
{
UtTest_Add(TestExternal, NULL, NULL, "Test External Sources");
UtTest_Add(TestCallback, NULL, NULL, "Test Time Synch Callbacks");
UtTest_Add(TestExternal, NULL, NULL, "Test External Sources");
}

0 comments on commit 2fb070a

Please sign in to comment.