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 7c0d1b7
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 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,42 @@

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);
if (CFE_FT_Global.Count < 2)
{
UtAssert_MIR("Timing performance of this system is insufficient to test CFE_TIME_RegisterSynchCallback");
}

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 +79,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 +96,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 7c0d1b7

Please sign in to comment.