Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1843, Add Time Clock Test #1860

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions modules/cfe_testcase/src/time_current_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/

#include "cfe_test.h"
#include "cfe_time_msg.h"

bool TimeInRange(CFE_TIME_SysTime_t Time, CFE_TIME_SysTime_t Target, OS_time_t difference)
{
Expand All @@ -51,6 +52,18 @@ bool TimeInRange(CFE_TIME_SysTime_t Time, CFE_TIME_SysTime_t Target, OS_time_t d
}
}

bool ClockFlagCheck(uint16 info, int flag)
{
if ((info & flag) == flag)
{
return true;
}
else
{
return false;
}
}

void TestGetTime(void)
{
UtPrintf("Testing: CFE_TIME_GetTime, CFE_TIME_GetTAI, CFE_TIME_GetUTC, CFE_TIME_GetMET, CFE_TIME_GetSTCF, "
Expand Down Expand Up @@ -120,7 +133,39 @@ void TestGetTime(void)
UtAssert_True(TimeInRange(MET, Buf, difference), "MET (%s) = METSubSeconds (%s)", timeBuf1, timeBuf2);
}

void TestClock(void)
{
UtPrintf("Testing: CFE_TIME_GetClockState, CFE_TIME_GetClockInfo");

CFE_TIME_ClockState_Enum_t state = CFE_TIME_GetClockState();
uint16 ClockInfo = CFE_TIME_GetClockInfo();

if (state >= 0)
{
UtAssert_BOOL_TRUE(ClockFlagCheck(ClockInfo, CFE_TIME_FLAG_CLKSET));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the "ClockFlagCheck" helper here. This seems to be hiding info, or at least will result in the log file having less detail than it could.

What about doing something like:

UtAssert_UINT32_EQ(ClockInfo, ClockInfo | CFE_TIME_FLAG_CLKSET);

The reason I like this is that it will show the raw value for ClockInfo value. In comparison, calling the ClockFlagCheck function will only display the result (true or false) and neither the raw value nor the bit being tested will be shown in the log.

(FWIW, I acknowledge that this does not show the bit being tested either, could also do UtAssert_UINT32_EQ(ClockInfo & CFE_TIME_FLAG_CLKSET, CFE_TIME_FLAG_CLKSET) but then this only shows the flag, not the raw value - depends on which is more interesting).

At the end of the day, could also introduce a new macro to test a bit field, that logs both the raw value and the bit being tested (not a bad idea, really).


if (state == 0)
{
UtAssert_BOOL_FALSE(ClockFlagCheck(ClockInfo, CFE_TIME_FLAG_FLYING));
}
else
{
UtAssert_BOOL_TRUE(ClockFlagCheck(ClockInfo, CFE_TIME_FLAG_FLYING));
}
}
else
{
UtAssert_BOOL_FALSE(ClockFlagCheck(ClockInfo, CFE_TIME_FLAG_CLKSET));
}

UtAssert_BOOL_TRUE(ClockFlagCheck(ClockInfo, CFE_TIME_FLAG_SRCINT));
UtAssert_BOOL_TRUE(ClockFlagCheck(ClockInfo, CFE_TIME_FLAG_SIGPRI));
UtAssert_BOOL_FALSE(ClockFlagCheck(ClockInfo, CFE_TIME_FLAG_REFERR));
UtAssert_BOOL_FALSE(ClockFlagCheck(ClockInfo, CFE_TIME_FLAG_UNUSED));
}

void TimeCurrentTestSetup(void)
{
UtTest_Add(TestGetTime, NULL, NULL, "Test Current Time");
UtTest_Add(TestClock, NULL, NULL, "Test Clock");
}