Merge pull request 'Fixed test issue with overflow of times' (#574) from gaisser/fsfw:gaisser_ccsds_time_tests into development
Reviewed-on: fsfw/fsfw#574
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#include <fsfw/datapool/PoolReadGuard.h>
|
||||
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/globalfunctions/timevalOperations.h>
|
||||
#include <fsfw/housekeeping/HousekeepingSnapshot.h>
|
||||
#include <fsfw/ipc/CommandMessageCleaner.h>
|
||||
#include <fsfw/objectmanager/ObjectManager.h>
|
||||
@ -93,10 +94,8 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") {
|
||||
poolOwner->dataset.setChanged(true);
|
||||
|
||||
/* Store current time, we are going to check the (approximate) time equality later */
|
||||
CCSDSTime::CDS_short timeCdsNow;
|
||||
timeval now;
|
||||
Clock::getClock_timeval(&now);
|
||||
CCSDSTime::convertToCcsds(&timeCdsNow, &now);
|
||||
|
||||
/* Trigger generation of snapshot */
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
@ -131,13 +130,11 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") {
|
||||
CHECK(newSet.localPoolUint16Vec.value[2] == 42932);
|
||||
|
||||
/* Now we check that both times are equal */
|
||||
CHECK(cdsShort.pField == timeCdsNow.pField);
|
||||
CHECK(cdsShort.dayLSB == Catch::Approx(timeCdsNow.dayLSB).margin(1));
|
||||
CHECK(cdsShort.dayMSB == Catch::Approx(timeCdsNow.dayMSB).margin(1));
|
||||
CHECK(cdsShort.msDay_h == Catch::Approx(timeCdsNow.msDay_h).margin(1));
|
||||
CHECK(cdsShort.msDay_hh == Catch::Approx(timeCdsNow.msDay_hh).margin(1));
|
||||
CHECK(cdsShort.msDay_l == Catch::Approx(timeCdsNow.msDay_l).margin(1));
|
||||
CHECK(cdsShort.msDay_ll == Catch::Approx(timeCdsNow.msDay_ll).margin(5));
|
||||
timeval timeFromHK;
|
||||
auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort);
|
||||
CHECK(result == HasReturnvaluesIF::RETURN_OK);
|
||||
timeval difference = timeFromHK - now;
|
||||
CHECK(timevalOperations::toDouble(difference) < 1.0);
|
||||
}
|
||||
|
||||
SECTION("VariableSnapshotTest") {
|
||||
@ -158,13 +155,10 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") {
|
||||
}
|
||||
|
||||
poolVar->setChanged(true);
|
||||
|
||||
/* Store current time, we are going to check the (approximate) time equality later */
|
||||
CCSDSTime::CDS_short timeCdsNow;
|
||||
timeval now;
|
||||
Clock::getClock_timeval(&now);
|
||||
CCSDSTime::convertToCcsds(&timeCdsNow, &now);
|
||||
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
|
||||
/* Check update snapshot was sent. */
|
||||
@ -193,13 +187,11 @@ TEST_CASE("LocalPoolManagerTest", "[LocManTest]") {
|
||||
CHECK(varCopy.value == 25);
|
||||
|
||||
/* Now we check that both times are equal */
|
||||
CHECK(cdsShort.pField == timeCdsNow.pField);
|
||||
CHECK(cdsShort.dayLSB == Catch::Approx(timeCdsNow.dayLSB).margin(1));
|
||||
CHECK(cdsShort.dayMSB == Catch::Approx(timeCdsNow.dayMSB).margin(1));
|
||||
CHECK(cdsShort.msDay_h == Catch::Approx(timeCdsNow.msDay_h).margin(1));
|
||||
CHECK(cdsShort.msDay_hh == Catch::Approx(timeCdsNow.msDay_hh).margin(1));
|
||||
CHECK(cdsShort.msDay_l == Catch::Approx(timeCdsNow.msDay_l).margin(1));
|
||||
CHECK(cdsShort.msDay_ll == Catch::Approx(timeCdsNow.msDay_ll).margin(5));
|
||||
timeval timeFromHK;
|
||||
auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort);
|
||||
CHECK(result == HasReturnvaluesIF::RETURN_OK);
|
||||
timeval difference = timeFromHK - now;
|
||||
CHECK(timevalOperations::toDouble(difference) < 1.0);
|
||||
}
|
||||
|
||||
SECTION("VariableNotificationTest") {
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <fsfw/globalfunctions/timevalOperations.h>
|
||||
#include <fsfw/timemanager/CCSDSTime.h>
|
||||
|
||||
#include <array>
|
||||
@ -89,4 +90,43 @@ TEST_CASE("CCSDSTime Tests", "[TestCCSDSTime]") {
|
||||
REQUIRE(timeTo.second == 59);
|
||||
REQUIRE(timeTo.usecond == Catch::Approx(123000));
|
||||
}
|
||||
|
||||
SECTION("CDS Conversions") {
|
||||
// Preperation
|
||||
Clock::TimeOfDay_t time;
|
||||
time.year = 2020;
|
||||
time.month = 2;
|
||||
time.day = 29;
|
||||
time.hour = 13;
|
||||
time.minute = 24;
|
||||
time.second = 45;
|
||||
time.usecond = 123456;
|
||||
timeval timeAsTimeval;
|
||||
auto result = Clock::convertTimeOfDayToTimeval(&time, &timeAsTimeval);
|
||||
CHECK(result == HasReturnvaluesIF::RETURN_OK);
|
||||
CHECK(timeAsTimeval.tv_sec == 1582982685);
|
||||
CHECK(timeAsTimeval.tv_usec == 123456);
|
||||
|
||||
// Conversion to CDS Short
|
||||
CCSDSTime::CDS_short cdsTime;
|
||||
result = CCSDSTime::convertToCcsds(&cdsTime, &timeAsTimeval);
|
||||
CHECK(result == HasReturnvaluesIF::RETURN_OK);
|
||||
// Days in CCSDS Epoch 22704 (0x58B0)
|
||||
CHECK(cdsTime.dayMSB == 0x58);
|
||||
CHECK(cdsTime.dayLSB == 0xB0);
|
||||
// MS of day 48285123.456 (floored here)
|
||||
CHECK(cdsTime.msDay_hh == 0x2);
|
||||
CHECK(cdsTime.msDay_h == 0xE0);
|
||||
CHECK(cdsTime.msDay_l == 0xC5);
|
||||
CHECK(cdsTime.msDay_ll == 0xC3);
|
||||
|
||||
// Conversion back to timeval
|
||||
timeval timeReturnAsTimeval;
|
||||
result = CCSDSTime::convertFromCDS(&timeReturnAsTimeval, &cdsTime);
|
||||
CHECK(result == HasReturnvaluesIF::RETURN_OK);
|
||||
// micro seconds precision is lost
|
||||
timeval difference = timeAsTimeval - timeReturnAsTimeval;
|
||||
CHECK(difference.tv_usec == 456);
|
||||
CHECK(difference.tv_sec == 0);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user