Skip to content

Commit ce97f45

Browse files
authored
Merge pull request #1711 from pepepr08/fix1659-time-ut
Fix #1659, Add custom epoch support to TIME UT
2 parents ea754b6 + 17861ce commit ce97f45

File tree

1 file changed

+93
-44
lines changed

1 file changed

+93
-44
lines changed

modules/time/ut-coverage/time_UT.c

+93-44
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,17 @@ void Test_Init(void)
388388
*/
389389
void Test_GetTime(void)
390390
{
391-
int result;
392-
uint16 StateFlags;
393-
char timeBuf[sizeof("yyyy-ddd-hh:mm:ss.xxxxx_")];
394-
/* Note: Time is in seconds + microseconds since 1980-001-00:00:00:00000 */
395-
/* The time below equals 2013-001-02:03:04.56789 */
396-
int seconds = 1041472984;
397-
int microsecs = 567890;
398-
const char * expectedMET = "2013-001-02:03:14.56789";
399-
const char * expectedTAI = "2013-001-03:03:14.56789";
400-
const char * expectedUTC = "2013-001-03:02:42.56789";
401-
const char * expectedSTCF = "1980-001-01:00:00.00000";
391+
unsigned int result;
392+
uint16 StateFlags;
393+
/* Note: Time is in seconds + microseconds since epoch */
394+
unsigned int seconds = 1041472984;
395+
unsigned int microsecs = 567890;
402396
volatile CFE_TIME_ReferenceState_t *RefState;
397+
CFE_TIME_SysTime_t time;
398+
CFE_TIME_SysTime_t expectedMET = {.Seconds = 1041472994, .Subseconds = 2439068978};
399+
CFE_TIME_SysTime_t expectedTAI = {.Seconds = 1041476594, .Subseconds = 2439068978};
400+
CFE_TIME_SysTime_t expectedUTC = {.Seconds = 1041476562, .Subseconds = 2439068978};
401+
CFE_TIME_SysTime_t expectedSTCF = {.Seconds = 3600, .Subseconds = 0};
403402

404403
UtPrintf("Begin Test Get Time");
405404

@@ -420,8 +419,9 @@ void Test_GetTime(void)
420419
RefState->AtToneLatch.Subseconds = 0;
421420
RefState->ClockSetState = CFE_TIME_SetState_NOT_SET; /* Force invalid time */
422421
CFE_TIME_FinishReferenceUpdate(RefState);
423-
CFE_TIME_Print(timeBuf, CFE_TIME_GetMET());
424-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedMET, strlen(expectedMET));
422+
time = CFE_TIME_GetMET();
423+
UtAssert_UINT32_EQ(time.Seconds, expectedMET.Seconds);
424+
UtAssert_UINT32_EQ(time.Subseconds, expectedMET.Subseconds);
425425

426426
/* Test successfully retrieving the mission elapsed time (seconds
427427
* portion)
@@ -446,33 +446,38 @@ void Test_GetTime(void)
446446
/* Test successfully retrieving the international atomic time (TAI) */
447447
UT_InitData();
448448
UT_SetBSP_Time(seconds, microsecs);
449-
CFE_TIME_Print(timeBuf, CFE_TIME_GetTAI());
450-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedTAI, strlen(expectedTAI));
449+
time = CFE_TIME_GetTAI();
450+
UtAssert_UINT32_EQ(time.Seconds, expectedTAI.Seconds);
451+
UtAssert_UINT32_EQ(time.Subseconds, expectedTAI.Subseconds);
451452

452453
/* Test successfully retrieving the coordinated universal time (UTC) */
453454
UT_InitData();
454455
UT_SetBSP_Time(seconds, microsecs);
455-
CFE_TIME_Print(timeBuf, CFE_TIME_GetUTC());
456-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedUTC, strlen(expectedUTC));
456+
time = CFE_TIME_GetUTC();
457+
UtAssert_UINT32_EQ(time.Seconds, expectedUTC.Seconds);
458+
UtAssert_UINT32_EQ(time.Subseconds, expectedUTC.Subseconds);
457459

458460
/* Test successfully retrieving the default time (UTC or TAI) */
459461
UT_InitData();
460462
UT_SetBSP_Time(seconds, microsecs);
461-
CFE_TIME_Print(timeBuf, CFE_TIME_GetTime());
463+
time = CFE_TIME_GetTime();
462464

463465
#if (CFE_MISSION_TIME_CFG_DEFAULT_TAI == true)
464-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedTAI, strlen(expectedTAI));
466+
UtAssert_UINT32_EQ(time.Seconds, expectedTAI.Seconds);
467+
UtAssert_UINT32_EQ(time.Subseconds, expectedTAI.Subseconds);
465468
#else
466-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedUTC, strlen(expectedUTC));
469+
UtAssert_UINT32_EQ(time.Seconds, expectedUTC.Seconds);
470+
UtAssert_UINT32_EQ(time.Subseconds, expectedUTC.Subseconds);
467471
#endif
468472

469473
/* Test successfully retrieving the spacecraft time correlation
470474
* factor (SCTF)
471475
*/
472476
UT_InitData();
473477
UT_SetBSP_Time(seconds, microsecs);
474-
CFE_TIME_Print(timeBuf, CFE_TIME_GetSTCF());
475-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedSTCF, strlen(expectedSTCF));
478+
time = CFE_TIME_GetSTCF();
479+
UtAssert_UINT32_EQ(time.Seconds, expectedSTCF.Seconds);
480+
UtAssert_UINT32_EQ(time.Subseconds, expectedSTCF.Subseconds);
476481

477482
/* Test retrieving the time status (invalid time is expected) */
478483
UT_InitData();
@@ -752,18 +757,11 @@ void Test_TimeOp(void)
752757
*/
753758
void Test_ConvertTime(void)
754759
{
755-
char timeBuf[sizeof("yyyy-ddd-hh:mm:ss.xxxxx_")];
756760
CFE_TIME_SysTime_t METTime;
761+
CFE_TIME_SysTime_t resultTime;
762+
CFE_TIME_SysTime_t expectedMET2SCTime;
757763
volatile CFE_TIME_ReferenceState_t *RefState;
758764

759-
#if (CFE_MISSION_TIME_CFG_DEFAULT_TAI == true)
760-
/* TAI time derived = MET + STCF */
761-
const char *expectedSCTime = "1980-001-02:00:40.00000";
762-
#else
763-
/* UTC time derived = MET + STCF - Leaps */
764-
const char *expectedSCTime = "1980-001-02:00:08.00000";
765-
#endif
766-
767765
UtPrintf("Begin Test Convert Time");
768766
UT_InitData();
769767

@@ -772,13 +770,20 @@ void Test_ConvertTime(void)
772770
METTime.Subseconds = 0;
773771
RefState = CFE_TIME_StartReferenceUpdate();
774772
RefState->AtToneSTCF.Seconds = 7240; /* 01:00:00.00000 */
775-
RefState->AtToneSTCF.Subseconds = 0;
773+
RefState->AtToneSTCF.Subseconds = 45;
776774
RefState->AtToneLeapSeconds = 32;
775+
#if (CFE_MISSION_TIME_CFG_DEFAULT_TAI == true)
776+
/* TAI time derived = MET + STCF */
777+
expectedMET2SCTime.Seconds = 7240;
778+
#else
779+
/* UTC time derived = MET + STCF - Leaps */
780+
expectedMET2SCTime.Seconds = 7208;
781+
#endif
782+
expectedMET2SCTime.Subseconds = 45;
777783
CFE_TIME_FinishReferenceUpdate(RefState);
778-
CFE_TIME_Print(timeBuf, CFE_TIME_MET2SCTime(METTime));
779-
780-
/* SC = MET + SCTF [- Leaps for UTC] */
781-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedSCTime, strlen(expectedSCTime));
784+
resultTime = CFE_TIME_MET2SCTime(METTime);
785+
UtAssert_UINT32_EQ(resultTime.Seconds, expectedMET2SCTime.Seconds);
786+
UtAssert_UINT32_EQ(resultTime.Subseconds, expectedMET2SCTime.Subseconds);
782787

783788
/* NOTE: Microseconds <-> Subseconds conversion routines are implemented
784789
* as part of OS_time_t in OSAL, and are coverage tested there. CFE time
@@ -820,16 +825,33 @@ void Test_Print(void)
820825
char timeBuf[CFE_TIME_PRINTED_STRING_SIZE];
821826
char expectedBuf[CFE_TIME_PRINTED_STRING_SIZE];
822827
CFE_TIME_SysTime_t time;
828+
bool usingDefaultEpoch = true;
823829

824830
UtPrintf("Begin Test Print");
825831

832+
if (CFE_MISSION_TIME_EPOCH_YEAR != 1980 || CFE_MISSION_TIME_EPOCH_DAY != 1 || CFE_MISSION_TIME_EPOCH_HOUR != 0 ||
833+
CFE_MISSION_TIME_EPOCH_MINUTE != 0 || CFE_MISSION_TIME_EPOCH_SECOND != 0)
834+
{
835+
UtPrintf("Custom epoch time requires manual inspection for CFE_TIME_Print");
836+
usingDefaultEpoch = false;
837+
}
838+
826839
/* Test with zero time value */
827840
time.Subseconds = 0;
828841
time.Seconds = 0;
829842

830843
CFE_TIME_Print(timeBuf, time);
831-
strcpy(expectedBuf, "1980-001-00:00:00.00000");
832-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedBuf, sizeof(expectedBuf));
844+
if (usingDefaultEpoch)
845+
{
846+
strcpy(expectedBuf, "1980-001-00:00:00.00000");
847+
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedBuf, sizeof(expectedBuf));
848+
}
849+
else
850+
{
851+
UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__,
852+
"Confirm adding seconds = %u, subseconds = %u to configured EPOCH results in time %s", time.Seconds,
853+
time.Subseconds, timeBuf);
854+
}
833855

834856
/* Test with a time value that causes seconds >= 60 when
835857
* CFE_MISSION_TIME_EPOCH_SECOND > 0
@@ -838,24 +860,51 @@ void Test_Print(void)
838860
time.Seconds = 59;
839861

840862
CFE_TIME_Print(timeBuf, time);
841-
strcpy(expectedBuf, "1980-001-00:00:59.00000");
842-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedBuf, sizeof(expectedBuf));
863+
if (usingDefaultEpoch)
864+
{
865+
strcpy(expectedBuf, "1980-001-00:00:59.00000");
866+
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedBuf, sizeof(expectedBuf));
867+
}
868+
else
869+
{
870+
UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__,
871+
"Confirm adding seconds = %u, subseconds = %u to configured EPOCH results in time %s", time.Seconds,
872+
time.Subseconds, timeBuf);
873+
}
843874

844875
/* Test with mission representative time values */
845876
time.Subseconds = 215000;
846877
time.Seconds = 1041472984;
847878

848879
CFE_TIME_Print(timeBuf, time);
849-
strcpy(expectedBuf, "2013-001-02:03:04.00005");
850-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedBuf, sizeof(expectedBuf));
880+
if (usingDefaultEpoch)
881+
{
882+
strcpy(expectedBuf, "2013-001-02:03:04.00005");
883+
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedBuf, sizeof(expectedBuf));
884+
}
885+
else
886+
{
887+
UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__,
888+
"Confirm adding seconds = %u, subseconds = %u to configured EPOCH results in time %s", time.Seconds,
889+
time.Subseconds, timeBuf);
890+
}
851891

852892
/* Test with maximum seconds and subseconds values */
853893
time.Subseconds = 0xffffffff;
854894
time.Seconds = 0xffffffff;
855895

856896
CFE_TIME_Print(timeBuf, time);
857-
strcpy(expectedBuf, "2116-038-06:28:15.99999");
858-
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedBuf, sizeof(expectedBuf));
897+
if (usingDefaultEpoch)
898+
{
899+
strcpy(expectedBuf, "2116-038-06:28:15.99999");
900+
CFE_UtAssert_STRINGBUF_EQ(timeBuf, sizeof(timeBuf), expectedBuf, sizeof(expectedBuf));
901+
}
902+
else
903+
{
904+
UtAssertEx(false, UTASSERT_CASETYPE_MIR, __FILE__, __LINE__,
905+
"Confirm adding seconds = %u, subseconds = %u to configured EPOCH results in time %s", time.Seconds,
906+
time.Subseconds, timeBuf);
907+
}
859908
}
860909

861910
/*

0 commit comments

Comments
 (0)