-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nasa#1690, unit-tests for time conversion apis
- Loading branch information
pavll
committed
Jul 25, 2021
1 parent
33a4f19
commit 5263aed
Showing
4 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/************************************************************************* | ||
** | ||
** GSC-18128-1, "Core Flight Executive Version 6.7" | ||
** | ||
** Copyright (c) 2006-2021 United States Government as represented by | ||
** the Administrator of the National Aeronautics and Space Administration. | ||
** All Rights Reserved. | ||
** | ||
** Licensed under the Apache License, Version 2.0 (the "License"); | ||
** you may not use this file except in compliance with the License. | ||
** You may obtain a copy of the License at | ||
** | ||
** http://www.apache.org/licenses/LICENSE-2.0 | ||
** | ||
** Unless required by applicable law or agreed to in writing, software | ||
** distributed under the License is distributed on an "AS IS" BASIS, | ||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
** See the License for the specific language governing permissions and | ||
** limitations under the License. | ||
** | ||
** File: time_conversion_test.c | ||
** | ||
** Purpose: | ||
** Functional test of basic Time Conversion APIs | ||
** | ||
*************************************************************************/ | ||
|
||
/* | ||
* Includes | ||
*/ | ||
#include "cfe_test.h" | ||
|
||
// Check if its nearly possible that Time == Target | ||
// DUPLICATE! from time_current_test.c | ||
bool TimeInRange(CFE_TIME_SysTime_t Time, CFE_TIME_SysTime_t Target, OS_time_t difference) | ||
{ | ||
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; | ||
} | ||
} | ||
|
||
void TestConvertMET2SCTime(void) | ||
{ | ||
UtPrintf("Testing: CFE_TIME_MET2SCTime"); | ||
|
||
// std os time variables | ||
OS_time_t start; | ||
OS_time_t end; | ||
OS_time_t difference; | ||
|
||
// 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 SCTime; | ||
|
||
// Print buffers | ||
char timeBuf1[sizeof("yyyy-ddd-hh:mm:ss.xxxxx_")]; | ||
char timeBuf2[sizeof("yyyy-ddd-hh:mm:ss.xxxxx_")]; | ||
|
||
OS_GetLocalTime(&start); | ||
|
||
// Get Times | ||
MET = CFE_TIME_GetMET(); | ||
TAI = CFE_TIME_GetTAI(); | ||
UTC = CFE_TIME_GetUTC(); | ||
|
||
OS_GetLocalTime(&end); | ||
|
||
// Convert - should produce a TAI or UTC at the moment of GetMET() | ||
// with a minimal time shift between | ||
SCTime = CFE_TIME_MET2SCTime(MET); | ||
|
||
// write Spacecraft Time into second buffer | ||
CFE_TIME_Print(timeBuf2, SCTime); | ||
|
||
// Check conversion | ||
#if (CFE_MISSION_TIME_CFG_DEFAULT_TAI == true) | ||
// SCTime is TAI format | ||
|
||
// write TAI into first buffer | ||
CFE_TIME_Print(timeBuf1, TAI); | ||
|
||
// CFE_TIME_Compare not possible because of the | ||
// temporal diffrence between get GetMET and GetTAI | ||
UtAssert_True(TimeInRange(TAI, SCTime, difference), "TAI (%s) = MET2SCTime (%s)", timeBuf1, timeBuf2); | ||
|
||
// this would be ok but it would repeat a whats done in CFE_TIME_MET2SCTime | ||
// UtAssert_True(CFE_TIME_Compare(SCTime, CFE_TIME_Add(MET, STCF))); | ||
#else | ||
// SCTime is UTC format | ||
|
||
// write UTC into first buffer | ||
CFE_TIME_Print(timeBuf1, UTC); | ||
|
||
// CFE_TIME_Compare not possible because of the | ||
// temporal diffrence between get GetMET and GetUTC | ||
UtAssert_True(TimeInRange(UTC, SCTime, difference), "UTC (%s) = MET2SCTime (%s)", timeBuf1, timeBuf2); | ||
#endif | ||
} | ||
|
||
void TestConvertSubSeconds2MicroSeconds(void) | ||
{ | ||
UtPrintf("Testing: CFE_TIME_Sub2MicroSecs"); | ||
|
||
uint32 SUB; | ||
uint32 MS; | ||
OS_time_t TimeSUB; | ||
|
||
SUB = CFE_TIME_GetMETsubsecs(); | ||
MS = CFE_TIME_Sub2MicroSecs(SUB); | ||
|
||
TimeSUB = OS_TimeAssembleFromSubseconds(0, SUB); | ||
|
||
UtAssert_True(OS_TimeGetMicrosecondsPart(TimeSUB) == MS, "sub-seconds (%zu) = Sub2MicroSecs (%zu)", SUB, MS); | ||
} | ||
|
||
void TestConvertMicroSeconds2SubSeconds(void) | ||
{ | ||
UtPrintf("Testing: CFE_TIME_Micro2SubSecs"); | ||
|
||
// micro-seconds | ||
uint32 MS = 64512; | ||
// sub-seconds | ||
uint32 SUB; | ||
OS_time_t TimeMS; | ||
|
||
// convert | ||
SUB = CFE_TIME_Micro2SubSecs(MS); | ||
|
||
// manually convert example micro-seconds into OS_time_t | ||
TimeMS = OS_TimeAssembleFromNanoseconds(0, MS * 1000); | ||
|
||
// get sub-seconds form TimeMS and compare with SUB | ||
UtAssert_True(OS_TimeGetSubsecondsPart(TimeMS) == SUB, "micro-seconds (%zu) = Micro2SubSecs (%zu)", MS, SUB); | ||
} | ||
|
||
void TimeConversionTestSetup(void) | ||
{ | ||
UtTest_Add(TestConvertMET2SCTime, NULL, NULL, "Test convert MET into spacecraft time"); | ||
UtTest_Add(TestConvertSubSeconds2MicroSeconds, NULL, NULL, "Test Convert sub-seconds into micro-seconds"); | ||
UtTest_Add(TestConvertMicroSeconds2SubSeconds, NULL, NULL, "Test Convert micro-seconds into sub-seconds"); | ||
} |