Skip to content

Commit

Permalink
Merge pull request #1962 from skliper/fix1961-testgettime
Browse files Browse the repository at this point in the history
Fix #1961, Single time domain in functional time tests
  • Loading branch information
astrogeco authored Sep 21, 2021
2 parents 25426ed + 828ee58 commit 5f5be83
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 101 deletions.
2 changes: 1 addition & 1 deletion modules/cfe_testcase/src/cfe_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extern CFE_FT_Global_t CFE_FT_Global;
*/
#define CFE_ASSERT_LOG_FILE_NAME "/cf/cfe_test.log"

bool TimeInRange(CFE_TIME_SysTime_t Time, CFE_TIME_SysTime_t Target, OS_time_t difference);
void TimeInRange(CFE_TIME_SysTime_t Start, CFE_TIME_SysTime_t Time, CFE_TIME_SysTime_t Range, const char *Str);

void CFE_TestMain(void);
void ESApplicationControlTestSetup(void);
Expand Down
57 changes: 10 additions & 47 deletions modules/cfe_testcase/src/time_conversion_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,62 +34,25 @@ void TestConvertMET2SCTime(void)
{
UtPrintf("Testing: CFE_TIME_MET2SCTime");

/* Mission Elapsed Time */
CFE_TIME_SysTime_t MET;
/* MET + SCTF */
CFE_TIME_SysTime_t TAI;
/* MET + SCTF - Leap Seconds */
CFE_TIME_SysTime_t UTC;
/* Spacecraft Time */
CFE_TIME_SysTime_t METStart;
CFE_TIME_SysTime_t METEnd;
CFE_TIME_SysTime_t Time;
CFE_TIME_SysTime_t SCTime;

OS_time_t start;
OS_time_t end;
OS_time_t difference;

/* Print buffers */
char timeBuf1[sizeof("yyyy-ddd-hh:mm:ss.xxxxx_")];
char timeBuf2[sizeof("yyyy-ddd-hh:mm:ss.xxxxx_")];

OS_GetLocalTime(&start);
CFE_TIME_SysTime_t Range;

/* Get Times */
MET = CFE_TIME_GetMET();
TAI = CFE_TIME_GetTAI();
UTC = CFE_TIME_GetUTC();
METStart = CFE_TIME_GetMET();
Time = CFE_TIME_GetTime();
METEnd = CFE_TIME_GetMET();

OS_GetLocalTime(&end);
Range = CFE_TIME_Subtract(METEnd, METStart);

/* Convert - should produce a TAI or UTC at the moment of GetMET() */
SCTime = CFE_TIME_MET2SCTime(MET);

/* write Spacecraft Time into second buffer */
CFE_TIME_Print(timeBuf2, SCTime);

difference = OS_TimeSubtract(end, start);
SCTime = CFE_TIME_MET2SCTime(METStart);

/* Check conversion */
#if (CFE_MISSION_TIME_CFG_DEFAULT_TAI == true)
/* SCTime is TAI format */

/* avoid unused compiler warning */
(void)UTC;

/* write TAI into first buffer */
CFE_TIME_Print(timeBuf1, TAI);

UtAssert_True(TimeInRange(SCTime, TAI, difference), "TAI (%s) = MET2SCTime (%s)", timeBuf1, timeBuf2);
#else
/* SCTime is UTC format */

/* avoid unused compiler warning */
(void)TAI;

/* write UTC into first buffer */
CFE_TIME_Print(timeBuf1, UTC);

UtAssert_True(TimeInRange(SCTime, UTC, difference), "UTC (%s) = MET2SCTime (%s)", timeBuf1, timeBuf2);
#endif
TimeInRange(SCTime, Time, Range, "MET to SC Time vs default time");
}

void TestConvertSubSeconds2MicroSeconds(void)
Expand Down
96 changes: 43 additions & 53 deletions modules/cfe_testcase/src/time_current_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,91 +34,81 @@
#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)
void TimeInRange(CFE_TIME_SysTime_t Start, CFE_TIME_SysTime_t Time, CFE_TIME_SysTime_t Range, const char *Str)
{
OS_time_t Max;
OS_time_t TimeT = OS_TimeAssembleFromSubseconds(Time.Seconds, Time.Subseconds);
OS_time_t TargetT = OS_TimeAssembleFromSubseconds(Target.Seconds, Target.Subseconds);

Max = OS_TimeAdd(TimeT, difference);

if (TargetT.ticks >= TimeT.ticks && TargetT.ticks <= Max.ticks)
{
return true;
}
else
{
return false;
}
char StartStr[sizeof("yyyy-ddd-hh:mm:ss.xxxxx_")];
char TimeStr[sizeof("yyyy-ddd-hh:mm:ss.xxxxx_")];
CFE_TIME_Compare_t Compare;
CFE_TIME_SysTime_t Delta;

CFE_TIME_Print(StartStr, Start);
CFE_TIME_Print(TimeStr, Time);

Compare = CFE_TIME_Compare(Start, Time);
UtAssert_True((Compare == CFE_TIME_EQUAL) || (Compare == CFE_TIME_A_LT_B), "%s: %lu %lu (%s) <= %lu %lu (%s)", Str,
(long unsigned)Start.Seconds, (long unsigned)Start.Subseconds, StartStr, (long unsigned)Time.Seconds,
(long unsigned)Time.Subseconds, TimeStr);

Delta = CFE_TIME_Subtract(Time, Start);
Compare = CFE_TIME_Compare(Delta, Range);
UtAssert_True((Compare == CFE_TIME_EQUAL) || (Compare == CFE_TIME_A_LT_B), "%s: Delta %lu %lu <= Range %lu %lu",
Str, (long unsigned)Delta.Seconds, (long unsigned)Delta.Subseconds, (long unsigned)Range.Seconds,
(long unsigned)Range.Subseconds);
}

void TestGetTime(void)
{
UtPrintf("Testing: CFE_TIME_GetTime, CFE_TIME_GetTAI, CFE_TIME_GetUTC, CFE_TIME_GetMET, CFE_TIME_GetSTCF, "
"CFE_TIME_GetLeapSeconds");
OS_time_t start;
OS_time_t end;
OS_time_t difference;
CFE_TIME_SysTime_t Time;
CFE_TIME_SysTime_t Start;
CFE_TIME_SysTime_t End;
CFE_TIME_SysTime_t TAI;
CFE_TIME_SysTime_t UTC;
CFE_TIME_SysTime_t MET;
CFE_TIME_SysTime_t STCF;
CFE_TIME_SysTime_t Range;
uint32 METSeconds;
uint32 METSubSeconds;

int16 LeapSeconds;
CFE_TIME_SysTime_t Buf;

char timeBuf1[sizeof("yyyy-ddd-hh:mm:ss.xxxxx_")];
char timeBuf2[sizeof("yyyy-ddd-hh:mm:ss.xxxxx_")];

OS_GetLocalTime(&start);

Time = CFE_TIME_GetTime();
Start = CFE_TIME_GetTime();
TAI = CFE_TIME_GetTAI();
UTC = CFE_TIME_GetUTC();
MET = CFE_TIME_GetMET();
METSeconds = CFE_TIME_GetMETseconds();
METSubSeconds = CFE_TIME_GetMETsubsecs();
STCF = CFE_TIME_GetSTCF();
LeapSeconds = CFE_TIME_GetLeapSeconds();
End = CFE_TIME_GetTime();

OS_GetLocalTime(&end);

CFE_TIME_Print(timeBuf1, Time);
UtPrintf("The current time is (%ld) %s", (long)Time.Seconds, timeBuf1);

difference = OS_TimeSubtract(end, start);
Range = CFE_TIME_Subtract(End, Start);

#if (CFE_MISSION_TIME_CFG_DEFAULT_TAI == true)
CFE_TIME_Print(timeBuf2, TAI);
UtAssert_True(TimeInRange(Time, TAI, difference), "Get Time (%s) = TAI (%s)", timeBuf1, timeBuf2);
TimeInRange(Start, TAI, Range, "default time vs TAI");
#else
CFE_TIME_Print(timeBuf2, UTC);
UtAssert_True(TimeInRange(Time, UTC, difference), "Get Time (%s) = UTC(%s)", timeBuf1, timeBuf2);
TimeInRange(Start, UTC, Range, "default time vs UTC");
#endif

CFE_TIME_Print(timeBuf1, TAI);
Buf = CFE_TIME_Add(MET, STCF);
CFE_TIME_Print(timeBuf2, Buf);
UtAssert_True(TimeInRange(TAI, Buf, difference), "TAI (%s) = MET + STCF (%s)", timeBuf1, timeBuf2);
TimeInRange(TAI, Buf, Range, "TAI vs MET + STCF");

CFE_TIME_Print(timeBuf1, UTC);
Buf.Seconds = Buf.Seconds - LeapSeconds;
CFE_TIME_Print(timeBuf2, Buf);
UtAssert_True(TimeInRange(UTC, Buf, difference), "UTC (%s) = MET + STCF - Leap Seconds (%s)", timeBuf1, timeBuf2);

CFE_TIME_Print(timeBuf1, MET);
Buf.Seconds = METSeconds;
Buf.Subseconds = MET.Subseconds;
CFE_TIME_Print(timeBuf2, Buf);
UtAssert_True(TimeInRange(MET, Buf, difference), "MET (%s) = METSeconds (%s)", timeBuf1, timeBuf2);

Buf.Seconds = MET.Seconds;
Buf.Subseconds = METSubSeconds;
CFE_TIME_Print(timeBuf2, Buf);
UtAssert_True(TimeInRange(MET, Buf, difference), "MET (%s) = METSubSeconds (%s)", timeBuf1, timeBuf2);
TimeInRange(UTC, Buf, Range, "UTC vs MET + STCF - Leap Seconds");

/* Handle rollover */
if (METSubSeconds < MET.Subseconds)
{
UtAssert_UINT32_EQ(MET.Seconds + 1, METSeconds);
}
else
{
UtAssert_UINT32_EQ(MET.Seconds, METSeconds);
}
UtAssert_UINT32_LTEQ(METSubSeconds - MET.Subseconds, Range.Subseconds);
UtPrintf("MET = %lu, %lu, METSeconds = %lu, METSubSeconds = %lu, Range.Subseconds = %lu",
(long unsigned)MET.Seconds, (long unsigned)MET.Subseconds, (long unsigned)METSeconds,
(long unsigned)METSubSeconds, (long unsigned)Range.Subseconds);
}

void TestClock(void)
Expand Down

0 comments on commit 5f5be83

Please sign in to comment.