added more unittests
This commit is contained in:
@ -1,10 +1,16 @@
|
||||
#include "LocalPoolOwnerBase.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
|
||||
#include <fsfw/datapool/PoolReadHelper.h>
|
||||
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/housekeeping/HousekeepingSnapshot.h>
|
||||
#include <fsfw/ipc/CommandMessageCleaner.h>
|
||||
#include <fsfw/timemanager/CCSDSTime.h>
|
||||
#include <unittest/core/CatchDefinitions.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
||||
@ -14,7 +20,7 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
||||
REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK);
|
||||
REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation()
|
||||
== retval::CATCH_OK);
|
||||
REQUIRE(poolOwner->dataset.assignPointers() == retval::CATCH_OK);
|
||||
//REQUIRE(poolOwner->dataset.assignPointers() == retval::CATCH_OK);
|
||||
MessageQueueMockBase* mqMock = poolOwner->getMockQueueHandle();
|
||||
REQUIRE(mqMock != nullptr);
|
||||
CommandMessage messageSent;
|
||||
@ -63,29 +69,76 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
||||
HousekeepingMessage::HK_REPORT));
|
||||
/* Clear message to avoid memory leak, our mock won't do it for us (yet) */
|
||||
CommandMessageCleaner::clearCommandMessage(&messageSent);
|
||||
/* we need to reset the subscription list because the pool owner
|
||||
is a global object. */
|
||||
poolOwner->resetSubscriptionList();
|
||||
|
||||
}
|
||||
|
||||
SECTION("SnapshotUpdateTests") {
|
||||
/* we need to reset the subscription list because the pool owner
|
||||
is a global object. */
|
||||
poolOwner->resetSubscriptionList();
|
||||
/* Set the variables in the set to certain values. These are checked later. */
|
||||
{
|
||||
PoolReadHelper readHelper(&poolOwner->dataset);
|
||||
REQUIRE(readHelper.getReadResult() == retval::CATCH_OK);
|
||||
poolOwner->dataset.localPoolVarUint8.value = 5;
|
||||
poolOwner->dataset.localPoolVarFloat.value = -12.242;
|
||||
poolOwner->dataset.localPoolUint16Vec.value[0] = 2;
|
||||
poolOwner->dataset.localPoolUint16Vec.value[1] = 32;
|
||||
poolOwner->dataset.localPoolUint16Vec.value[2] = 42932;
|
||||
}
|
||||
|
||||
/* Subscribe for snapshot generation on update. */
|
||||
REQUIRE(poolOwner->subscribeWrapperSetUpdateSnapshot() == retval::CATCH_OK);
|
||||
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);
|
||||
REQUIRE(mqMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||
/* Check that snapshot was generated */
|
||||
CHECK(messageSent.getCommand() == static_cast<int>(
|
||||
HousekeepingMessage::UPDATE_SNAPSHOT_SET));
|
||||
/* Now we deserialize the snapshot into a new dataset instance */
|
||||
CCSDSTime::CDS_short cdsShort;
|
||||
LocalPoolTestDataSet newSet;
|
||||
HousekeepingSnapshot snapshot(&cdsShort, &newSet);
|
||||
store_address_t storeId;
|
||||
HousekeepingMessage::getUpdateSnapshotSetCommand(&messageSent, &storeId);
|
||||
ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId);
|
||||
REQUIRE(accessorPair.first == retval::CATCH_OK);
|
||||
const uint8_t* readOnlyPtr = accessorPair.second.data();
|
||||
size_t sizeToDeserialize = accessorPair.second.size();
|
||||
CHECK(newSet.localPoolVarFloat.value == 0);
|
||||
CHECK(newSet.localPoolVarUint8 == 0);
|
||||
CHECK(newSet.localPoolUint16Vec.value[0] == 0);
|
||||
CHECK(newSet.localPoolUint16Vec.value[1] == 0);
|
||||
CHECK(newSet.localPoolUint16Vec.value[2] == 0);
|
||||
/* Fill the dataset and timestamp */
|
||||
REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize,
|
||||
SerializeIF::Endianness::MACHINE) == retval::CATCH_OK);
|
||||
/* Now we check that the snapshot is actually correct */
|
||||
CHECK(newSet.localPoolVarFloat.value == Catch::Approx(-12.242));
|
||||
CHECK(newSet.localPoolVarUint8 == 5);
|
||||
CHECK(newSet.localPoolUint16Vec.value[0] == 2);
|
||||
CHECK(newSet.localPoolUint16Vec.value[1] == 32);
|
||||
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(1));
|
||||
}
|
||||
|
||||
SECTION("AdvancedTests") {
|
||||
|
||||
/* Subscribe for variable update as well */
|
||||
REQUIRE(not poolOwner->dataset.hasChanged());
|
||||
/* Subscribe for variable update */
|
||||
REQUIRE(poolOwner->subscribeWrapperVariableUpdate(lpool::uint8VarId) ==
|
||||
retval::CATCH_OK);
|
||||
lp_var_t<uint8_t>* poolVar = dynamic_cast<lp_var_t<uint8_t>*>(
|
||||
@ -102,7 +155,6 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
||||
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||
CHECK(messageSent.getCommand() == static_cast<int>(
|
||||
HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
|
||||
|
||||
/* Now subscribe for the dataset update (HK and update) again */
|
||||
REQUIRE(poolOwner->subscribeWrapperSetUpdate() == retval::CATCH_OK);
|
||||
REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK);
|
||||
@ -133,5 +185,10 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
||||
REQUIRE(mqMock->receiveMessage(&messageSent) ==
|
||||
static_cast<int>(MessageQueueIF::EMPTY));
|
||||
}
|
||||
|
||||
/* we need to reset the subscription list because the pool owner
|
||||
is a global object. */
|
||||
poolOwner->resetSubscriptionList();
|
||||
mqMock->clearMessages(true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user