Merge remote-tracking branch 'upstream/mueller/refactor-tmtc-stack' into mueller/tmtc-stack-refactoring
This commit is contained in:
@ -27,5 +27,6 @@ add_subdirectory(cfdp)
|
||||
add_subdirectory(hal)
|
||||
add_subdirectory(internalerror)
|
||||
add_subdirectory(devicehandler)
|
||||
add_subdirectory(tmtcservices)
|
||||
|
||||
target_include_directories(${FSFW_TEST_TGT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
@ -5,11 +5,6 @@
|
||||
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <fsfw/storagemanager/StorageManagerIF.h>
|
||||
|
||||
namespace retval {
|
||||
static constexpr int CATCH_OK = static_cast<int>(HasReturnvaluesIF::RETURN_OK);
|
||||
static constexpr int CATCH_FAILED = static_cast<int>(HasReturnvaluesIF::RETURN_FAILED);
|
||||
} // namespace retval
|
||||
|
||||
namespace tconst {
|
||||
static constexpr MessageQueueId_t testQueueId = 42;
|
||||
}
|
||||
|
@ -7,11 +7,9 @@
|
||||
#include <fsfw/internalerror/InternalErrorReporter.h>
|
||||
#include <fsfw/objectmanager/frameworkObjects.h>
|
||||
#include <fsfw/storagemanager/PoolManager.h>
|
||||
#include <fsfw/tmtcpacket/pus/tm/TmPacketStored.h>
|
||||
#include <fsfw/tmtcservices/CommandingServiceBase.h>
|
||||
#include <fsfw/tmtcservices/PusServiceBase.h>
|
||||
|
||||
#include "datapoollocal/LocalPoolOwnerBase.h"
|
||||
#include "mocks/HkReceiverMock.h"
|
||||
#include "tests/TestsConfig.h"
|
||||
|
||||
@ -36,14 +34,6 @@ void Factory::produceFrameworkObjects(void* args) {
|
||||
new HealthTable(objects::HEALTH_TABLE);
|
||||
new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER);
|
||||
|
||||
new LocalPoolOwnerBase(objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
new HkReceiverMock(objects::HK_RECEIVER_MOCK);
|
||||
|
||||
{
|
||||
PoolManager::LocalPoolConfig poolCfg = {{100, 16}, {50, 32}, {25, 64}, {15, 128}, {5, 1024}};
|
||||
new PoolManager(objects::TC_STORE, poolCfg);
|
||||
}
|
||||
|
||||
{
|
||||
PoolManager::LocalPoolConfig poolCfg = {{100, 16}, {50, 32}, {25, 64}, {15, 128}, {5, 1024}};
|
||||
new PoolManager(objects::TM_STORE, poolCfg);
|
||||
@ -55,23 +45,20 @@ void Factory::produceFrameworkObjects(void* args) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Our tests, and the code base in general should really not depend on some arbitrary function
|
||||
// like this. Instead, this should be more like a general struct containing all important
|
||||
// object IDs which are then explicitely passed in the object constructor
|
||||
void Factory::setStaticFrameworkObjectIds() {
|
||||
PusServiceBase::packetSource = objects::NO_OBJECT;
|
||||
PusServiceBase::packetDestination = objects::NO_OBJECT;
|
||||
PusServiceBase::PACKET_DESTINATION = objects::NO_OBJECT;
|
||||
|
||||
CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT;
|
||||
CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT;
|
||||
|
||||
VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION;
|
||||
|
||||
DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT;
|
||||
DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT;
|
||||
|
||||
LocalDataPoolManager::defaultHkDestination = objects::HK_RECEIVER_MOCK;
|
||||
|
||||
LocalDataPoolManager::defaultHkDestination = objects::NO_OBJECT;
|
||||
DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT;
|
||||
|
||||
TmPacketBase::timeStamperId = objects::NO_OBJECT;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <catch2/catch_session.hpp>
|
||||
|
||||
extern int customSetup();
|
||||
extern int customTeardown();
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
customSetup();
|
||||
@ -21,5 +22,6 @@ int main(int argc, char* argv[]) {
|
||||
int result = Catch::Session().run(argc, argv);
|
||||
|
||||
// global clean-up
|
||||
customTeardown();
|
||||
return result;
|
||||
}
|
||||
|
@ -29,3 +29,5 @@ int customSetup() {
|
||||
objMan->initialize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int customTeardown() { return 0; }
|
||||
|
@ -6,11 +6,12 @@
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "mocks/MessageQueueMockBase.h"
|
||||
#include "mocks/MessageQueueMock.h"
|
||||
|
||||
TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||
ActionHelperOwnerMockBase testDhMock;
|
||||
MessageQueueMockBase testMqMock;
|
||||
// TODO: Setting another number here breaks the test. Find out why
|
||||
MessageQueueMock testMqMock(MessageQueueIF::NO_QUEUE);
|
||||
ActionHelper actionHelper = ActionHelper(&testDhMock, dynamic_cast<MessageQueueIF*>(&testMqMock));
|
||||
CommandMessage actionMessage;
|
||||
ActionId_t testActionId = 777;
|
||||
@ -19,12 +20,12 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||
StorageManagerIF* ipcStore = tglob::getIpcStoreHandle();
|
||||
REQUIRE(ipcStore != nullptr);
|
||||
ipcStore->addData(¶mAddress, testParams.data(), 3);
|
||||
REQUIRE(actionHelper.initialize() == retval::CATCH_OK);
|
||||
REQUIRE(actionHelper.initialize() == result::OK);
|
||||
|
||||
SECTION("Simple tests") {
|
||||
ActionMessage::setCommand(&actionMessage, testActionId, paramAddress);
|
||||
CHECK(not testDhMock.executeActionCalled);
|
||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK);
|
||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == result::OK);
|
||||
CHECK(testDhMock.executeActionCalled);
|
||||
// No message is sent if everything is alright.
|
||||
CHECK(not testMqMock.wasMessageSent());
|
||||
@ -57,8 +58,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||
step += 1;
|
||||
CHECK(testMqMock.wasMessageSent());
|
||||
CommandMessage testMessage;
|
||||
REQUIRE(testMqMock.receiveMessage(&testMessage) ==
|
||||
static_cast<uint32_t>(HasReturnvaluesIF::RETURN_OK));
|
||||
REQUIRE(testMqMock.getNextSentMessage(testMessage) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
|
||||
REQUIRE(testMessage.getParameter() == static_cast<uint32_t>(testActionId));
|
||||
uint32_t parameter2 = ((uint32_t)step << 16) | (uint32_t)status;
|
||||
@ -72,25 +72,23 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||
actionHelper.finish(false, testMqMock.getId(), testActionId, status);
|
||||
CHECK(testMqMock.wasMessageSent());
|
||||
CommandMessage testMessage;
|
||||
REQUIRE(testMqMock.receiveMessage(&testMessage) ==
|
||||
static_cast<uint32_t>(HasReturnvaluesIF::RETURN_OK));
|
||||
REQUIRE(testMqMock.getNextSentMessage(testMessage) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::COMPLETION_FAILED));
|
||||
REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId);
|
||||
REQUIRE(ActionMessage::getReturnCode(&testMessage) == static_cast<uint32_t>(status));
|
||||
}
|
||||
|
||||
SECTION("Handle failed") {
|
||||
store_address_t toLongParamAddress = StorageManagerIF::INVALID_ADDRESS;
|
||||
store_address_t toLongParamAddress = store_address_t::invalid();
|
||||
std::array<uint8_t, 5> toLongData = {5, 4, 3, 2, 1};
|
||||
REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == retval::CATCH_OK);
|
||||
REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == result::OK);
|
||||
ActionMessage::setCommand(&actionMessage, testActionId, toLongParamAddress);
|
||||
CHECK(not testDhMock.executeActionCalled);
|
||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK);
|
||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == result::OK);
|
||||
REQUIRE(ipcStore->getData(toLongParamAddress).first ==
|
||||
static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST));
|
||||
CommandMessage testMessage;
|
||||
REQUIRE(testMqMock.receiveMessage(&testMessage) ==
|
||||
static_cast<uint32_t>(HasReturnvaluesIF::RETURN_OK));
|
||||
REQUIRE(testMqMock.getNextSentMessage(testMessage) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
|
||||
REQUIRE(ActionMessage::getReturnCode(&testMessage) == 0xAFFE);
|
||||
REQUIRE(ActionMessage::getStep(&testMessage) == 0);
|
||||
@ -98,12 +96,11 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||
}
|
||||
|
||||
SECTION("Missing IPC Data") {
|
||||
ActionMessage::setCommand(&actionMessage, testActionId, StorageManagerIF::INVALID_ADDRESS);
|
||||
ActionMessage::setCommand(&actionMessage, testActionId, store_address_t::invalid());
|
||||
CHECK(not testDhMock.executeActionCalled);
|
||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK);
|
||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == result::OK);
|
||||
CommandMessage testMessage;
|
||||
REQUIRE(testMqMock.receiveMessage(&testMessage) ==
|
||||
static_cast<uint32_t>(HasReturnvaluesIF::RETURN_OK));
|
||||
REQUIRE(testMqMock.getNextSentMessage(testMessage) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
|
||||
REQUIRE(ActionMessage::getReturnCode(&testMessage) ==
|
||||
static_cast<uint32_t>(StorageManagerIF::ILLEGAL_STORAGE_ID));
|
||||
|
@ -29,10 +29,10 @@ TEST_CASE("CFDP Base", "[CfdpBase]") {
|
||||
const uint8_t** dummyPtr = nullptr;
|
||||
ReturnValue_t deserResult =
|
||||
headerSerializer.deSerialize(dummyPtr, &serSize, SerializeIF::Endianness::NETWORK);
|
||||
REQUIRE(deserResult == retval::CATCH_FAILED);
|
||||
REQUIRE(deserResult == result::FAILED);
|
||||
deserResult = headerSerializer.serialize(nullptr, &serSize, serBuf.size(),
|
||||
SerializeIF::Endianness::NETWORK);
|
||||
REQUIRE(deserResult == retval::CATCH_FAILED);
|
||||
REQUIRE(deserResult == result::FAILED);
|
||||
REQUIRE(seqNum.getSerializedSize() == 1);
|
||||
|
||||
REQUIRE(headerSerializer.getPduDataFieldLen() == 0);
|
||||
@ -62,7 +62,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") {
|
||||
|
||||
result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(),
|
||||
SerializeIF::Endianness::BIG);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
REQUIRE(serSize == 7);
|
||||
// Only version bits are set
|
||||
REQUIRE(serBuf[0] == 0b00100000);
|
||||
@ -155,11 +155,11 @@ TEST_CASE("CFDP Base", "[CfdpBase]") {
|
||||
REQUIRE(entityId == 0x00ff00ff);
|
||||
|
||||
result = pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 0xfff);
|
||||
REQUIRE(result == retval::CATCH_FAILED);
|
||||
REQUIRE(result == result::FAILED);
|
||||
result = pduConf.sourceId.setValue(cfdp::WidthInBytes::TWO_BYTES, 0xfffff);
|
||||
REQUIRE(result == retval::CATCH_FAILED);
|
||||
REQUIRE(result == result::FAILED);
|
||||
result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xfffffffff);
|
||||
REQUIRE(result == retval::CATCH_FAILED);
|
||||
REQUIRE(result == result::FAILED);
|
||||
uint8_t oneByteSourceId = 32;
|
||||
serTarget = &oneByteSourceId;
|
||||
size_t deserLen = 1;
|
||||
@ -197,7 +197,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") {
|
||||
auto headerSerializer = HeaderSerializer(pduConf, cfdp::PduType::FILE_DIRECTIVE, 0);
|
||||
ReturnValue_t result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(),
|
||||
SerializeIF::Endianness::BIG);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
REQUIRE(serBuf[1] == 0);
|
||||
REQUIRE(serBuf[2] == 0);
|
||||
// Entity and Transaction Sequence number are 1 byte large
|
||||
@ -207,7 +207,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") {
|
||||
auto headerDeser = HeaderDeserializer(serBuf.data(), serBuf.size());
|
||||
|
||||
ReturnValue_t serResult = headerDeser.parseData();
|
||||
REQUIRE(serResult == retval::CATCH_OK);
|
||||
REQUIRE(serResult == result::OK);
|
||||
REQUIRE(headerDeser.getPduDataFieldLen() == 0);
|
||||
REQUIRE(headerDeser.getHeaderSize() == 7);
|
||||
REQUIRE(headerDeser.getWholePduSize() == 7);
|
||||
@ -230,11 +230,11 @@ TEST_CASE("CFDP Base", "[CfdpBase]") {
|
||||
headerSerializer.setPduType(cfdp::PduType::FILE_DATA);
|
||||
headerSerializer.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT);
|
||||
result = pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
result = pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
serTarget = serBuf.data();
|
||||
serSize = 0;
|
||||
result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(),
|
||||
@ -242,7 +242,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") {
|
||||
headerDeser = HeaderDeserializer(serBuf.data(), serBuf.size());
|
||||
|
||||
result = headerDeser.parseData();
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
// Everything except version bit flipped to one now
|
||||
REQUIRE(serBuf[0] == 0x3f);
|
||||
REQUIRE(serBuf[3] == 0b11001010);
|
||||
@ -274,7 +274,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") {
|
||||
serTarget = serBuf.data();
|
||||
const uint8_t** serTargetConst = const_cast<const uint8_t**>(&serTarget);
|
||||
result = headerDeser.parseData();
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
|
||||
headerDeser.setData(nullptr, -1);
|
||||
REQUIRE(headerDeser.getHeaderSize() == 0);
|
||||
@ -286,7 +286,7 @@ TEST_CASE("CFDP Base", "[CfdpBase]") {
|
||||
pduConf.destId.setValue(cfdp::WidthInBytes::ONE_BYTE, 48);
|
||||
result = headerSerializer.serialize(&serTarget, &serSize, serBuf.size(),
|
||||
SerializeIF::Endianness::BIG);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
REQUIRE(headerDeser.getWholePduSize() == 8);
|
||||
headerDeser.setData(serBuf.data(), serBuf.size());
|
||||
|
||||
|
@ -12,42 +12,42 @@ TEST_CASE("Ring Buffer Test", "[RingBufferTest]") {
|
||||
|
||||
SECTION("Simple Test") {
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == result::OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == result::FAILED);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 5; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 5);
|
||||
ringBuffer.clear();
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 4) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 4, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 4) == result::OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 4, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 9, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == result::OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 9, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 9; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
REQUIRE(ringBuffer.writeData(testData, 1024) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.writeData(nullptr, 5) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.writeData(testData, 1024) == result::FAILED);
|
||||
REQUIRE(ringBuffer.writeData(nullptr, 5) == result::FAILED);
|
||||
}
|
||||
|
||||
SECTION("Get Free Element Test") {
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 8) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 8) == result::OK);
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 1);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 8, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 8, true) == result::OK);
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
uint8_t *testPtr = nullptr;
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == result::FAILED);
|
||||
|
||||
REQUIRE(ringBuffer.writeTillWrap() == 2);
|
||||
// too many excess bytes.
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == result::FAILED);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == result::OK);
|
||||
REQUIRE(ringBuffer.getExcessBytes() == 3);
|
||||
std::memcpy(testPtr, testData, 5);
|
||||
ringBuffer.confirmBytesWritten(5);
|
||||
@ -59,19 +59,19 @@ TEST_CASE("Ring Buffer Test", "[RingBufferTest]") {
|
||||
}
|
||||
|
||||
SECTION("Read Remaining Test") {
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == result::OK);
|
||||
REQUIRE(ringBuffer.getAvailableReadData() == 3);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == result::FAILED);
|
||||
size_t trueSize = 0;
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == result::OK);
|
||||
REQUIRE(trueSize == 3);
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
trueSize = 0;
|
||||
REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == result::FAILED);
|
||||
REQUIRE(trueSize == 0);
|
||||
REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == result::OK);
|
||||
REQUIRE(trueSize == 3);
|
||||
}
|
||||
}
|
||||
@ -84,21 +84,21 @@ TEST_CASE("Ring Buffer Test2", "[RingBufferTest2]") {
|
||||
|
||||
SECTION("Simple Test") {
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == result::OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 5; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 5);
|
||||
ringBuffer.clear();
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 4) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 4, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 4) == result::OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 4, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 9, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == result::OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 9, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 9; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
@ -106,17 +106,17 @@ TEST_CASE("Ring Buffer Test2", "[RingBufferTest2]") {
|
||||
|
||||
SECTION("Get Free Element Test") {
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 8) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 8) == result::OK);
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 1);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 8, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 8, true) == result::OK);
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
uint8_t *testPtr = nullptr;
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == result::FAILED);
|
||||
|
||||
REQUIRE(ringBuffer.writeTillWrap() == 2);
|
||||
// too many excess bytes.
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == result::FAILED);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == result::OK);
|
||||
REQUIRE(ringBuffer.getExcessBytes() == 3);
|
||||
std::memcpy(testPtr, testData, 5);
|
||||
ringBuffer.confirmBytesWritten(5);
|
||||
@ -128,19 +128,19 @@ TEST_CASE("Ring Buffer Test2", "[RingBufferTest2]") {
|
||||
}
|
||||
|
||||
SECTION("Read Remaining Test") {
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == result::OK);
|
||||
REQUIRE(ringBuffer.getAvailableReadData() == 3);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == result::FAILED);
|
||||
size_t trueSize = 0;
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == result::OK);
|
||||
REQUIRE(trueSize == 3);
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
trueSize = 0;
|
||||
REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == result::FAILED);
|
||||
REQUIRE(trueSize == 0);
|
||||
REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == result::OK);
|
||||
REQUIRE(trueSize == 3);
|
||||
}
|
||||
|
||||
@ -148,17 +148,17 @@ TEST_CASE("Ring Buffer Test2", "[RingBufferTest2]") {
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
// We don't allow writing of Data that is larger than the ring buffer in total
|
||||
REQUIRE(ringBuffer.getMaxSize() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 13) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.writeData(testData, 13) == result::FAILED);
|
||||
REQUIRE(ringBuffer.getAvailableReadData() == 0);
|
||||
ringBuffer.clear();
|
||||
uint8_t *ptr = nullptr;
|
||||
// With excess Bytes 13 Bytes can be written to this Buffer
|
||||
REQUIRE(ringBuffer.getFreeElement(&ptr, 13) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.getFreeElement(&ptr, 13) == result::OK);
|
||||
REQUIRE(ptr != nullptr);
|
||||
memcpy(ptr, testData, 13);
|
||||
ringBuffer.confirmBytesWritten(13);
|
||||
REQUIRE(ringBuffer.getAvailableReadData() == 3);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 3, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 3, true) == result::OK);
|
||||
for (auto i = 0; i < 3; i++) {
|
||||
REQUIRE(readBuffer[i] == testData[i + 10]);
|
||||
}
|
||||
@ -173,21 +173,21 @@ TEST_CASE("Ring Buffer Test3", "[RingBufferTest3]") {
|
||||
|
||||
SECTION("Simple Test") {
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == result::OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 5; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 5);
|
||||
ringBuffer.clear();
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 4) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 4, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 4) == result::OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 4, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 9, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == result::OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 9, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 9; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
@ -195,19 +195,19 @@ TEST_CASE("Ring Buffer Test3", "[RingBufferTest3]") {
|
||||
|
||||
SECTION("Get Free Element Test") {
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 8) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 8) == result::OK);
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 1);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 8, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 8, true) == result::OK);
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
uint8_t *testPtr = nullptr;
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == result::OK);
|
||||
REQUIRE(ringBuffer.getExcessBytes() == 8);
|
||||
|
||||
REQUIRE(ringBuffer.writeTillWrap() == 2);
|
||||
// too many excess bytes.
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == result::FAILED);
|
||||
// Less Execss bytes overwrites before
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 3) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 3) == result::OK);
|
||||
REQUIRE(ringBuffer.getExcessBytes() == 1);
|
||||
std::memcpy(testPtr, testData, 3);
|
||||
ringBuffer.confirmBytesWritten(3);
|
||||
@ -219,19 +219,19 @@ TEST_CASE("Ring Buffer Test3", "[RingBufferTest3]") {
|
||||
}
|
||||
|
||||
SECTION("Read Remaining Test") {
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == result::OK);
|
||||
REQUIRE(ringBuffer.getAvailableReadData() == 3);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == result::FAILED);
|
||||
size_t trueSize = 0;
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == result::OK);
|
||||
REQUIRE(trueSize == 3);
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
trueSize = 0;
|
||||
REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == result::FAILED);
|
||||
REQUIRE(trueSize == 0);
|
||||
REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == result::OK);
|
||||
REQUIRE(trueSize == 3);
|
||||
}
|
||||
|
||||
@ -239,18 +239,18 @@ TEST_CASE("Ring Buffer Test3", "[RingBufferTest3]") {
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
// Writing more than the buffer is large.
|
||||
// This write will be rejected and is seen as a configuration mistake
|
||||
REQUIRE(ringBuffer.writeData(testData, 13) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.writeData(testData, 13) == result::FAILED);
|
||||
REQUIRE(ringBuffer.getAvailableReadData() == 0);
|
||||
ringBuffer.clear();
|
||||
// Using FreeElement allows the usage of excessBytes but
|
||||
// should be used with caution
|
||||
uint8_t *ptr = nullptr;
|
||||
REQUIRE(ringBuffer.getFreeElement(&ptr, 13) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.getFreeElement(&ptr, 13) == result::OK);
|
||||
REQUIRE(ptr != nullptr);
|
||||
memcpy(ptr, testData, 13);
|
||||
ringBuffer.confirmBytesWritten(13);
|
||||
REQUIRE(ringBuffer.getAvailableReadData() == 3);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 3, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 3, true) == result::OK);
|
||||
for (auto i = 0; i < 3; i++) {
|
||||
REQUIRE(readBuffer[i] == testData[i + 10]);
|
||||
}
|
||||
@ -264,22 +264,22 @@ TEST_CASE("Ring Buffer Test4", "[RingBufferTest4]") {
|
||||
|
||||
SECTION("Simple Test") {
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == result::OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == result::FAILED);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 5; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 5);
|
||||
ringBuffer.clear();
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 4) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 4, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 4) == result::OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 4, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 9, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 9) == result::OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 9, true) == result::OK);
|
||||
for (uint8_t i = 0; i < 9; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
@ -287,16 +287,16 @@ TEST_CASE("Ring Buffer Test4", "[RingBufferTest4]") {
|
||||
|
||||
SECTION("Get Free Element Test") {
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
REQUIRE(ringBuffer.writeData(testData, 8) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 8) == result::OK);
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 1);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 8, true) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 8, true) == result::OK);
|
||||
REQUIRE(ringBuffer.availableWriteSpace() == 9);
|
||||
uint8_t *testPtr = nullptr;
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 10) == result::FAILED);
|
||||
|
||||
REQUIRE(ringBuffer.writeTillWrap() == 2);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 8) == result::OK);
|
||||
REQUIRE(ringBuffer.getFreeElement(&testPtr, 5) == result::OK);
|
||||
REQUIRE(ringBuffer.getExcessBytes() == 3);
|
||||
std::memcpy(testPtr, testData, 5);
|
||||
ringBuffer.confirmBytesWritten(5);
|
||||
@ -308,19 +308,19 @@ TEST_CASE("Ring Buffer Test4", "[RingBufferTest4]") {
|
||||
}
|
||||
|
||||
SECTION("Read Remaining Test") {
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.writeData(testData, 3) == result::OK);
|
||||
REQUIRE(ringBuffer.getAvailableReadData() == 3);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, false, nullptr) == result::FAILED);
|
||||
size_t trueSize = 0;
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.readData(readBuffer, 5, false, true, &trueSize) == result::OK);
|
||||
REQUIRE(trueSize == 3);
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
CHECK(readBuffer[i] == i);
|
||||
}
|
||||
trueSize = 0;
|
||||
REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == retval::CATCH_FAILED);
|
||||
REQUIRE(ringBuffer.deleteData(5, false, &trueSize) == result::FAILED);
|
||||
REQUIRE(trueSize == 0);
|
||||
REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == retval::CATCH_OK);
|
||||
REQUIRE(ringBuffer.deleteData(5, true, &trueSize) == result::OK);
|
||||
REQUIRE(trueSize == 3);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
LocalPoolVariableTest.cpp
|
||||
LocalPoolVectorTest.cpp
|
||||
DataSetTest.cpp
|
||||
LocalPoolManagerTest.cpp
|
||||
LocalPoolOwnerBase.cpp
|
||||
testLocalPoolVariable.cpp
|
||||
testLocalPoolVector.cpp
|
||||
testDataSet.cpp
|
||||
testLocalPoolManager.cpp
|
||||
)
|
||||
|
@ -1,413 +0,0 @@
|
||||
#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>
|
||||
#include <fsfw/timemanager/CCSDSTime.h>
|
||||
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "CatchDefinitions.h"
|
||||
#include "LocalPoolOwnerBase.h"
|
||||
|
||||
TEST_CASE("LocalPoolManagerTest", "[LocManTest]") {
|
||||
LocalPoolOwnerBase* poolOwner =
|
||||
ObjectManager::instance()->get<LocalPoolOwnerBase>(objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
REQUIRE(poolOwner != nullptr);
|
||||
REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK);
|
||||
REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK);
|
||||
|
||||
MessageQueueMockBase* poolOwnerMock = poolOwner->getMockQueueHandle();
|
||||
REQUIRE(poolOwnerMock != nullptr);
|
||||
|
||||
// MessageQueueIF* hkCommander = QueueFactory::instance()->createMessageQueue();
|
||||
CommandMessage messageSent;
|
||||
uint8_t messagesSent = 0;
|
||||
|
||||
SECTION("BasicTest") {
|
||||
{
|
||||
/* For code coverage, should not crash */
|
||||
LocalDataPoolManager manager(nullptr, nullptr);
|
||||
}
|
||||
auto owner = poolOwner->poolManager.getOwner();
|
||||
REQUIRE(owner != nullptr);
|
||||
CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
|
||||
/* Subscribe for message generation on update. */
|
||||
REQUIRE(poolOwner->subscribeWrapperSetUpdate() == retval::CATCH_OK);
|
||||
/* Subscribe for an update message. */
|
||||
poolOwner->dataset.setChanged(true);
|
||||
/* Now the update message should be generated. */
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent() == true);
|
||||
|
||||
REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||
|
||||
/* Should have been reset. */
|
||||
CHECK(poolOwner->dataset.hasChanged() == false);
|
||||
/* Set changed again, result should be the same. */
|
||||
poolOwner->dataset.setChanged(true);
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||
|
||||
/* Now subscribe for set update HK as well. */
|
||||
REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK);
|
||||
poolOwner->dataset.setChanged(true);
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 2);
|
||||
/* first message sent should be the update notification, considering
|
||||
the internal list is a vector checked in insertion order. */
|
||||
REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||
|
||||
REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
|
||||
/* Clear message to avoid memory leak, our mock won't do it for us (yet) */
|
||||
CommandMessageCleaner::clearCommandMessage(&messageSent);
|
||||
}
|
||||
|
||||
SECTION("SetSnapshotUpdateTest") {
|
||||
/* Set the variables in the set to certain values. These are checked later. */
|
||||
{
|
||||
PoolReadGuard 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 */
|
||||
timeval now;
|
||||
Clock::getClock_timeval(&now);
|
||||
|
||||
/* Trigger generation of snapshot */
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
REQUIRE(poolOwnerMock->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 */
|
||||
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") {
|
||||
/* Acquire subscription interface */
|
||||
ProvidesDataPoolSubscriptionIF* subscriptionIF = poolOwner->getSubscriptionInterface();
|
||||
REQUIRE(subscriptionIF != nullptr);
|
||||
|
||||
/* Subscribe for variable snapshot */
|
||||
REQUIRE(poolOwner->subscribeWrapperVariableSnapshot(lpool::uint8VarId) == retval::CATCH_OK);
|
||||
auto poolVar =
|
||||
dynamic_cast<lp_var_t<uint8_t>*>(poolOwner->getPoolObjectHandle(lpool::uint8VarId));
|
||||
REQUIRE(poolVar != nullptr);
|
||||
|
||||
{
|
||||
PoolReadGuard rg(poolVar);
|
||||
CHECK(rg.getReadResult() == retval::CATCH_OK);
|
||||
poolVar->value = 25;
|
||||
}
|
||||
|
||||
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);
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
|
||||
/* Check update snapshot was sent. */
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
|
||||
/* Should have been reset. */
|
||||
CHECK(poolVar->hasChanged() == false);
|
||||
REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE));
|
||||
/* Now we deserialize the snapshot into a new dataset instance */
|
||||
CCSDSTime::CDS_short cdsShort;
|
||||
lp_var_t<uint8_t> varCopy = lp_var_t<uint8_t>(lpool::uint8VarGpid);
|
||||
HousekeepingSnapshot snapshot(&cdsShort, &varCopy);
|
||||
store_address_t storeId;
|
||||
HousekeepingMessage::getUpdateSnapshotVariableCommand(&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(varCopy.value == 0);
|
||||
/* Fill the dataset and timestamp */
|
||||
REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize,
|
||||
SerializeIF::Endianness::MACHINE) == retval::CATCH_OK);
|
||||
CHECK(varCopy.value == 25);
|
||||
|
||||
/* Now we check that both times are equal */
|
||||
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") {
|
||||
/* Acquire subscription interface */
|
||||
ProvidesDataPoolSubscriptionIF* subscriptionIF = poolOwner->getSubscriptionInterface();
|
||||
REQUIRE(subscriptionIF != nullptr);
|
||||
|
||||
/* 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>*>(poolOwner->getPoolObjectHandle(lpool::uint8VarId));
|
||||
REQUIRE(poolVar != nullptr);
|
||||
poolVar->setChanged(true);
|
||||
REQUIRE(poolVar->hasChanged() == true);
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
|
||||
/* Check update notification was sent. */
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
/* Should have been reset. */
|
||||
CHECK(poolVar->hasChanged() == false);
|
||||
REQUIRE(poolOwnerMock->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 with subscription interface */
|
||||
REQUIRE(subscriptionIF->subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT,
|
||||
objects::HK_RECEIVER_MOCK,
|
||||
false) == retval::CATCH_OK);
|
||||
REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK);
|
||||
|
||||
poolOwner->dataset.setChanged(true);
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
/* Now two messages should be sent. */
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 2);
|
||||
poolOwnerMock->clearMessages(true);
|
||||
|
||||
poolOwner->dataset.setChanged(true);
|
||||
poolVar->setChanged(true);
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
/* Now three messages should be sent. */
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 3);
|
||||
REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
|
||||
REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||
REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
|
||||
CommandMessageCleaner::clearCommandMessage(&messageSent);
|
||||
REQUIRE(poolOwnerMock->receiveMessage(&messageSent) == static_cast<int>(MessageQueueIF::EMPTY));
|
||||
}
|
||||
|
||||
SECTION("PeriodicHKAndMessaging") {
|
||||
/* Now we subcribe for a HK periodic generation. Even when it's difficult to simulate
|
||||
the temporal behaviour correctly the HK manager should generate a HK packet
|
||||
immediately and the periodic helper depends on HK op function calls anyway instead of
|
||||
using the clock, so we could also just call performHkOperation multiple times */
|
||||
REQUIRE(poolOwner->subscribePeriodicHk(true) == retval::CATCH_OK);
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
/* Now HK packet should be sent as message immediately. */
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
LocalPoolDataSetBase* setHandle = poolOwner->getDataSetHandle(lpool::testSid);
|
||||
REQUIRE(setHandle != nullptr);
|
||||
CHECK(poolOwner->poolManager.generateHousekeepingPacket(lpool::testSid, setHandle, false) ==
|
||||
retval::CATCH_OK);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
CHECK(setHandle->getReportingEnabled() == true);
|
||||
CommandMessage hkCmd;
|
||||
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
CHECK(setHandle->getReportingEnabled() == false);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, false);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
CHECK(setHandle->getReportingEnabled() == true);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
CHECK(setHandle->getReportingEnabled() == false);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4,
|
||||
false);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
/* For non-diagnostics and a specified minimum frequency of 0.2 seconds, the
|
||||
resulting collection interval should be 1.0 second */
|
||||
CHECK(poolOwner->dataset.getCollectionInterval() == 1.0);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false);
|
||||
REQUIRE(poolOwner->poolManager.performHkOperation() == retval::CATCH_OK);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
/* Now HK packet should be sent as message. */
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setUpdateNotificationSetCommand(&hkCmd, lpool::testSid);
|
||||
sid_t sidToCheck;
|
||||
store_address_t storeId;
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
CHECK(poolOwner->changedDataSetCallbackWasCalled(sidToCheck, storeId) == true);
|
||||
CHECK(sidToCheck == lpool::testSid);
|
||||
|
||||
/* Now we test the handling is the dataset is set to diagnostic */
|
||||
poolOwner->dataset.setDiagnostic(true);
|
||||
|
||||
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) ==
|
||||
static_cast<int>(LocalDataPoolManager::WRONG_HK_PACKET_TYPE));
|
||||
/* We still expect a failure message being sent */
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4,
|
||||
false);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) ==
|
||||
static_cast<int>(LocalDataPoolManager::WRONG_HK_PACKET_TYPE));
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) ==
|
||||
static_cast<int>(LocalDataPoolManager::WRONG_HK_PACKET_TYPE));
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, true);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4,
|
||||
true);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, true);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, true);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) ==
|
||||
static_cast<int>(LocalDataPoolManager::WRONG_HK_PACKET_TYPE));
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, true);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
REQUIRE(poolOwnerMock->wasMessageSent(&messagesSent) == true);
|
||||
CHECK(messagesSent == 1);
|
||||
CHECK(poolOwnerMock->popMessage() == retval::CATCH_OK);
|
||||
|
||||
HousekeepingMessage::setUpdateNotificationVariableCommand(&hkCmd, lpool::uint8VarGpid);
|
||||
gp_id_t gpidToCheck;
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
CHECK(poolOwner->changedVariableCallbackWasCalled(gpidToCheck, storeId) == true);
|
||||
CHECK(gpidToCheck == lpool::uint8VarGpid);
|
||||
|
||||
HousekeepingMessage::setUpdateSnapshotSetCommand(&hkCmd, lpool::testSid,
|
||||
storeId::INVALID_STORE_ADDRESS);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
CHECK(poolOwner->changedDataSetCallbackWasCalled(sidToCheck, storeId) == true);
|
||||
CHECK(sidToCheck == lpool::testSid);
|
||||
|
||||
HousekeepingMessage::setUpdateSnapshotVariableCommand(&hkCmd, lpool::uint8VarGpid,
|
||||
storeId::INVALID_STORE_ADDRESS);
|
||||
CHECK(poolOwner->poolManager.handleHousekeepingMessage(&hkCmd) == retval::CATCH_OK);
|
||||
CHECK(poolOwner->changedVariableCallbackWasCalled(gpidToCheck, storeId) == true);
|
||||
CHECK(gpidToCheck == lpool::uint8VarGpid);
|
||||
|
||||
poolOwner->poolManager.printPoolEntry(lpool::uint8VarId);
|
||||
}
|
||||
|
||||
/* we need to reset the subscription list because the pool owner
|
||||
is a global object. */
|
||||
CHECK(poolOwner->reset() == retval::CATCH_OK);
|
||||
poolOwnerMock->clearMessages(true);
|
||||
}
|
@ -9,15 +9,15 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "CatchDefinitions.h"
|
||||
#include "LocalPoolOwnerBase.h"
|
||||
#include "mocks/LocalPoolOwnerBase.h"
|
||||
#include "mocks/MessageQueueMock.h"
|
||||
#include "tests/TestsConfig.h"
|
||||
|
||||
TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
LocalPoolOwnerBase* poolOwner =
|
||||
ObjectManager::instance()->get<LocalPoolOwnerBase>(objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
REQUIRE(poolOwner != nullptr);
|
||||
REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK);
|
||||
REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK);
|
||||
auto queue = MessageQueueMock(1);
|
||||
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
REQUIRE(poolOwner.initializeHkManager() == result::OK);
|
||||
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK);
|
||||
LocalPoolStaticTestDataSet localSet;
|
||||
|
||||
SECTION("BasicTest") {
|
||||
@ -30,13 +30,13 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
size_t maxSize = localSet.getLocalPoolIdsSerializedSize(true);
|
||||
uint8_t localPoolIdBuff[maxSize];
|
||||
/* Skip size field */
|
||||
lp_id_t* lpIds = reinterpret_cast<lp_id_t*>(localPoolIdBuff + 1);
|
||||
auto* lpIds = reinterpret_cast<lp_id_t*>(localPoolIdBuff + 1);
|
||||
size_t serSize = 0;
|
||||
uint8_t* localPoolIdBuffPtr = reinterpret_cast<uint8_t*>(localPoolIdBuff);
|
||||
auto* localPoolIdBuffPtr = reinterpret_cast<uint8_t*>(localPoolIdBuff);
|
||||
|
||||
/* Test local pool ID serialization */
|
||||
CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize,
|
||||
SerializeIF::Endianness::MACHINE) == retval::CATCH_OK);
|
||||
SerializeIF::Endianness::MACHINE) == result::OK);
|
||||
CHECK(serSize == maxSize);
|
||||
CHECK(localPoolIdBuff[0] == 3);
|
||||
CHECK(lpIds[0] == localSet.localPoolVarUint8.getDataPoolId());
|
||||
@ -47,8 +47,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
localPoolIdBuffPtr = localPoolIdBuff;
|
||||
serSize = 0;
|
||||
CHECK(localSet.serializeLocalPoolIds(&localPoolIdBuffPtr, &serSize, maxSize,
|
||||
SerializeIF::Endianness::MACHINE,
|
||||
false) == retval::CATCH_OK);
|
||||
SerializeIF::Endianness::MACHINE, false) == result::OK);
|
||||
CHECK(serSize == maxSize - sizeof(uint8_t));
|
||||
CHECK(lpIds[0] == localSet.localPoolVarUint8.getDataPoolId());
|
||||
CHECK(lpIds[1] == localSet.localPoolVarFloat.getDataPoolId());
|
||||
@ -57,7 +56,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
{
|
||||
/* Test read operation. Values should be all zeros */
|
||||
PoolReadGuard readHelper(&localSet);
|
||||
REQUIRE(readHelper.getReadResult() == retval::CATCH_OK);
|
||||
REQUIRE(readHelper.getReadResult() == result::OK);
|
||||
CHECK(not localSet.isValid());
|
||||
CHECK(localSet.localPoolVarUint8.value == 0);
|
||||
CHECK(not localSet.localPoolVarUint8.isValid());
|
||||
@ -90,7 +89,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
/* Now we read again and check whether our zeroed values were overwritten with
|
||||
the values in the pool */
|
||||
PoolReadGuard readHelper(&localSet);
|
||||
REQUIRE(readHelper.getReadResult() == retval::CATCH_OK);
|
||||
REQUIRE(readHelper.getReadResult() == result::OK);
|
||||
CHECK(localSet.isValid());
|
||||
CHECK(localSet.localPoolVarUint8.value == 232);
|
||||
CHECK(localSet.localPoolVarUint8.isValid());
|
||||
@ -110,7 +109,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
uint8_t buffer[maxSize + 1];
|
||||
uint8_t* buffPtr = buffer;
|
||||
CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
|
||||
retval::CATCH_OK);
|
||||
result::OK);
|
||||
uint8_t rawUint8 = buffer[0];
|
||||
CHECK(rawUint8 == 232);
|
||||
float rawFloat = 0.0;
|
||||
@ -128,7 +127,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
std::memset(buffer, 0, sizeof(buffer));
|
||||
const uint8_t* constBuffPtr = buffer;
|
||||
CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize,
|
||||
SerializeIF::Endianness::MACHINE) == retval::CATCH_OK);
|
||||
SerializeIF::Endianness::MACHINE) == result::OK);
|
||||
/* Check whether deserialization was successfull */
|
||||
CHECK(localSet.localPoolVarUint8.value == 0);
|
||||
CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0));
|
||||
@ -156,7 +155,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
serSize = 0;
|
||||
buffPtr = buffer;
|
||||
CHECK(localSet.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
|
||||
retval::CATCH_OK);
|
||||
result::OK);
|
||||
CHECK(rawUint8 == 232);
|
||||
std::memcpy(&rawFloat, buffer + sizeof(uint8_t), sizeof(float));
|
||||
CHECK(rawFloat == Catch::Approx(-2324.322));
|
||||
@ -186,7 +185,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
sizeToDeserialize = maxSize;
|
||||
constBuffPtr = buffer;
|
||||
CHECK(localSet.deSerialize(&constBuffPtr, &sizeToDeserialize,
|
||||
SerializeIF::Endianness::MACHINE) == retval::CATCH_OK);
|
||||
SerializeIF::Endianness::MACHINE) == result::OK);
|
||||
/* Check whether deserialization was successfull */
|
||||
CHECK(localSet.localPoolVarUint8.value == 0);
|
||||
CHECK(localSet.localPoolVarFloat.value == Catch::Approx(0.0));
|
||||
@ -200,7 +199,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
}
|
||||
|
||||
/* Common fault test cases */
|
||||
LocalPoolObjectBase* variableHandle = poolOwner->getPoolObjectHandle(lpool::uint32VarId);
|
||||
LocalPoolObjectBase* variableHandle = poolOwner.getPoolObjectHandle(lpool::uint32VarId);
|
||||
CHECK(variableHandle != nullptr);
|
||||
CHECK(localSet.registerVariable(variableHandle) == static_cast<int>(DataSetIF::DATA_SET_FULL));
|
||||
variableHandle = nullptr;
|
||||
@ -209,14 +208,14 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
}
|
||||
|
||||
SECTION("MorePoolVariables") {
|
||||
LocalDataSet set(poolOwner, 2, 10);
|
||||
LocalDataSet set(&poolOwner, 2, 10);
|
||||
|
||||
/* Register same variables again to get more than 8 registered variables */
|
||||
for (uint8_t idx = 0; idx < 8; idx++) {
|
||||
REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == retval::CATCH_OK);
|
||||
REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == result::OK);
|
||||
}
|
||||
REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == retval::CATCH_OK);
|
||||
REQUIRE(set.registerVariable(&localSet.localPoolUint16Vec) == retval::CATCH_OK);
|
||||
REQUIRE(set.registerVariable(&localSet.localPoolVarUint8) == result::OK);
|
||||
REQUIRE(set.registerVariable(&localSet.localPoolUint16Vec) == result::OK);
|
||||
|
||||
set.setValidityBufferGeneration(true);
|
||||
{
|
||||
@ -233,8 +232,8 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
uint8_t buffer[maxSize + 1];
|
||||
uint8_t* buffPtr = buffer;
|
||||
CHECK(set.serialize(&buffPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
|
||||
retval::CATCH_OK);
|
||||
std::array<uint8_t, 2> validityBuffer;
|
||||
result::OK);
|
||||
std::array<uint8_t, 2> validityBuffer{};
|
||||
std::memcpy(validityBuffer.data(), buffer + 9 + sizeof(uint16_t) * 3, 2);
|
||||
/* The first 9 variables should be valid */
|
||||
CHECK(validityBuffer[0] == 0xff);
|
||||
@ -251,36 +250,32 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
|
||||
const uint8_t* constBuffPtr = buffer;
|
||||
size_t sizeToDeSerialize = serSize;
|
||||
CHECK(set.deSerialize(&constBuffPtr, &sizeToDeSerialize, SerializeIF::Endianness::MACHINE) ==
|
||||
retval::CATCH_OK);
|
||||
result::OK);
|
||||
CHECK(localSet.localPoolVarUint8.isValid() == false);
|
||||
CHECK(localSet.localPoolUint16Vec.isValid() == true);
|
||||
}
|
||||
|
||||
SECTION("SharedDataSet") {
|
||||
object_id_t sharedSetId = objects::SHARED_SET_ID;
|
||||
SharedLocalDataSet sharedSet(sharedSetId, poolOwner, lpool::testSetId, 5);
|
||||
SharedLocalDataSet sharedSet(sharedSetId, &poolOwner, lpool::testSetId, 5);
|
||||
localSet.localPoolVarUint8.setReadWriteMode(pool_rwm_t::VAR_WRITE);
|
||||
localSet.localPoolUint16Vec.setReadWriteMode(pool_rwm_t::VAR_WRITE);
|
||||
CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == retval::CATCH_OK);
|
||||
CHECK(sharedSet.registerVariable(&localSet.localPoolUint16Vec) == retval::CATCH_OK);
|
||||
CHECK(sharedSet.initialize() == retval::CATCH_OK);
|
||||
CHECK(sharedSet.lockDataset() == retval::CATCH_OK);
|
||||
CHECK(sharedSet.unlockDataset() == retval::CATCH_OK);
|
||||
CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == result::OK);
|
||||
CHECK(sharedSet.registerVariable(&localSet.localPoolUint16Vec) == result::OK);
|
||||
CHECK(sharedSet.initialize() == result::OK);
|
||||
CHECK(sharedSet.lockDataset() == result::OK);
|
||||
CHECK(sharedSet.unlockDataset() == result::OK);
|
||||
|
||||
{
|
||||
// PoolReadGuard rg(&sharedSet);
|
||||
// CHECK(rg.getReadResult() == retval::CATCH_OK);
|
||||
// CHECK(rg.getReadResult() == result::OK);
|
||||
localSet.localPoolVarUint8.value = 5;
|
||||
localSet.localPoolUint16Vec.value[0] = 1;
|
||||
localSet.localPoolUint16Vec.value[1] = 2;
|
||||
localSet.localPoolUint16Vec.value[2] = 3;
|
||||
CHECK(sharedSet.commit() == retval::CATCH_OK);
|
||||
CHECK(sharedSet.commit() == result::OK);
|
||||
}
|
||||
|
||||
sharedSet.setReadCommitProtectionBehaviour(true);
|
||||
}
|
||||
|
||||
/* we need to reset the subscription list because the pool owner
|
||||
is a global object. */
|
||||
CHECK(poolOwner->reset() == retval::CATCH_OK);
|
||||
}
|
430
unittests/datapoollocal/testLocalPoolManager.cpp
Normal file
430
unittests/datapoollocal/testLocalPoolManager.cpp
Normal file
@ -0,0 +1,430 @@
|
||||
#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>
|
||||
#include <fsfw/timemanager/CCSDSTime.h>
|
||||
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "CatchDefinitions.h"
|
||||
#include "mocks/HkReceiverMock.h"
|
||||
#include "mocks/LocalPoolOwnerBase.h"
|
||||
|
||||
TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
|
||||
const MessageQueueId_t defaultDestId = 1;
|
||||
const MessageQueueId_t hkDest = defaultDestId;
|
||||
const MessageQueueId_t subscriberId = 2;
|
||||
auto hkReceiver = HkReceiverMock(hkDest);
|
||||
auto queue = MessageQueueMock(3);
|
||||
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
REQUIRE(poolOwner.initializeHkManager() == result::OK);
|
||||
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK);
|
||||
|
||||
MessageQueueMock& poolOwnerMock = poolOwner.getMockQueueHandle();
|
||||
|
||||
// TODO: This is ugly. This should be an arbitrary ctor argument. Fix this in the pool
|
||||
// manager
|
||||
poolOwnerMock.setDefaultDestination(defaultDestId);
|
||||
poolOwner.setHkDestId(hkDest);
|
||||
|
||||
auto* hkMan = poolOwner.getHkManagerHandle();
|
||||
|
||||
CommandMessage messageSent;
|
||||
|
||||
SECTION("Basic Test") {
|
||||
{
|
||||
/* For code coverage, should not crash */
|
||||
LocalDataPoolManager manager(nullptr, nullptr);
|
||||
}
|
||||
auto owner = poolOwner.poolManager.getOwner();
|
||||
REQUIRE(owner != nullptr);
|
||||
CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
|
||||
/* Subscribe for message generation on update. */
|
||||
REQUIRE(poolOwner.subscribeWrapperSetUpdate(subscriberId) == result::OK);
|
||||
/* Subscribe for an update message. */
|
||||
poolOwner.dataset.setChanged(true);
|
||||
/* Now the update message should be generated. */
|
||||
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||
|
||||
/* Should have been reset. */
|
||||
CHECK(poolOwner.dataset.hasChanged() == false);
|
||||
poolOwnerMock.clearMessages(true);
|
||||
/* Set changed again, result should be the same. */
|
||||
poolOwner.dataset.setChanged(true);
|
||||
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
|
||||
|
||||
REQUIRE(poolOwnerMock.wasMessageSent() == true);
|
||||
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||
|
||||
poolOwnerMock.clearMessages(true);
|
||||
/* Now subscribe for set update HK as well. */
|
||||
REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == result::OK);
|
||||
poolOwner.dataset.setChanged(true);
|
||||
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent() == true);
|
||||
CHECK(poolOwnerMock.numberOfSentMessages() == 2);
|
||||
// first message sent should be the update notification
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == result::OK);
|
||||
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
|
||||
/* Clear message to avoid memory leak, our mock won't do it for us (yet) */
|
||||
CommandMessageCleaner::clearCommandMessage(&messageSent);
|
||||
}
|
||||
|
||||
SECTION("SetSnapshotUpdateTest") {
|
||||
/* Set the variables in the set to certain values. These are checked later. */
|
||||
{
|
||||
PoolReadGuard readHelper(&poolOwner.dataset);
|
||||
REQUIRE(readHelper.getReadResult() == result::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(subscriberId) == result::OK);
|
||||
poolOwner.dataset.setChanged(true);
|
||||
|
||||
/* Store current time, we are going to check the (approximate) time equality later */
|
||||
timeval now{};
|
||||
Clock::getClock_timeval(&now);
|
||||
|
||||
/* Trigger generation of snapshot */
|
||||
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::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 == result::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) == result::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 */
|
||||
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") {
|
||||
/* Acquire subscription interface */
|
||||
ProvidesDataPoolSubscriptionIF* subscriptionIF = poolOwner.getSubscriptionInterface();
|
||||
REQUIRE(subscriptionIF != nullptr);
|
||||
|
||||
/* Subscribe for variable snapshot */
|
||||
REQUIRE(poolOwner.subscribeWrapperVariableSnapshot(subscriberId, lpool::uint8VarId) ==
|
||||
result::OK);
|
||||
auto poolVar =
|
||||
dynamic_cast<lp_var_t<uint8_t>*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId));
|
||||
REQUIRE(poolVar != nullptr);
|
||||
|
||||
{
|
||||
PoolReadGuard rg(poolVar);
|
||||
CHECK(rg.getReadResult() == result::OK);
|
||||
poolVar->value = 25;
|
||||
}
|
||||
|
||||
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);
|
||||
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
|
||||
|
||||
/* Check update snapshot was sent. */
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
|
||||
/* Should have been reset. */
|
||||
CHECK(poolVar->hasChanged() == false);
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE));
|
||||
/* Now we deserialize the snapshot into a new dataset instance */
|
||||
CCSDSTime::CDS_short cdsShort{};
|
||||
lp_var_t<uint8_t> varCopy = lp_var_t<uint8_t>(lpool::uint8VarGpid);
|
||||
HousekeepingSnapshot snapshot(&cdsShort, &varCopy);
|
||||
store_address_t storeId;
|
||||
HousekeepingMessage::getUpdateSnapshotVariableCommand(&messageSent, &storeId);
|
||||
ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId);
|
||||
REQUIRE(accessorPair.first == result::OK);
|
||||
const uint8_t* readOnlyPtr = accessorPair.second.data();
|
||||
size_t sizeToDeserialize = accessorPair.second.size();
|
||||
CHECK(varCopy.value == 0);
|
||||
/* Fill the dataset and timestamp */
|
||||
REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize,
|
||||
SerializeIF::Endianness::MACHINE) == result::OK);
|
||||
CHECK(varCopy.value == 25);
|
||||
|
||||
/* Now we check that both times are equal */
|
||||
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") {
|
||||
/* Acquire subscription interface */
|
||||
ProvidesDataPoolSubscriptionIF* subscriptionIF = poolOwner.getSubscriptionInterface();
|
||||
REQUIRE(subscriptionIF != nullptr);
|
||||
|
||||
/* Subscribe for variable update */
|
||||
REQUIRE(poolOwner.subscribeWrapperVariableUpdate(subscriberId, lpool::uint8VarId) ==
|
||||
result::OK);
|
||||
auto* poolVar =
|
||||
dynamic_cast<lp_var_t<uint8_t>*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId));
|
||||
REQUIRE(poolVar != nullptr);
|
||||
poolVar->setChanged(true);
|
||||
REQUIRE(poolVar->hasChanged() == true);
|
||||
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
|
||||
|
||||
/* Check update notification was sent. */
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
/* Should have been reset. */
|
||||
CHECK(poolVar->hasChanged() == false);
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
|
||||
/* Now subscribe for the dataset update (HK and update) again with subscription interface */
|
||||
REQUIRE(subscriptionIF->subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT,
|
||||
subscriberId, false) == result::OK);
|
||||
REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == result::OK);
|
||||
|
||||
poolOwner.dataset.setChanged(true);
|
||||
poolOwnerMock.clearMessages();
|
||||
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
|
||||
/* Now two messages should be sent. */
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
CHECK(poolOwnerMock.numberOfSentMessages() == 2);
|
||||
poolOwnerMock.clearMessages(true);
|
||||
|
||||
poolOwner.dataset.setChanged(true);
|
||||
poolOwnerMock.clearMessages(true);
|
||||
poolVar->setChanged(true);
|
||||
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
|
||||
/* Now three messages should be sent. */
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
CHECK(poolOwnerMock.numberOfSentMessages() == 3);
|
||||
CHECK(poolOwnerMock.numberOfSentMessagesToDest(subscriberId) == 2);
|
||||
CHECK(poolOwnerMock.numberOfSentMessagesToDest(hkDest) == 1);
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == result::OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
|
||||
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
CHECK(messageSent.getCommand() ==
|
||||
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == result::OK);
|
||||
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
|
||||
REQUIRE(poolOwnerMock.clearLastSentMessage() == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == MessageQueueIF::EMPTY);
|
||||
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == MessageQueueIF::EMPTY);
|
||||
}
|
||||
|
||||
SECTION("PeriodicHKAndMessaging") {
|
||||
/* Now we subcribe for a HK periodic generation. Even when it's difficult to simulate
|
||||
the temporal behaviour correctly the HK manager should generate a HK packet
|
||||
immediately and the periodic helper depends on HK op function calls anyway instead of
|
||||
using the clock, so we could also just call performHkOperation multiple times */
|
||||
REQUIRE(poolOwner.subscribePeriodicHk(true) == result::OK);
|
||||
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
|
||||
/* Now HK packet should be sent as message immediately. */
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
|
||||
|
||||
LocalPoolDataSetBase* setHandle = poolOwner.getDataSetHandle(lpool::testSid);
|
||||
REQUIRE(setHandle != nullptr);
|
||||
CHECK(poolOwner.poolManager.generateHousekeepingPacket(lpool::testSid, setHandle, false) ==
|
||||
result::OK);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
|
||||
|
||||
CHECK(setHandle->getReportingEnabled() == true);
|
||||
CommandMessage hkCmd;
|
||||
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
CHECK(setHandle->getReportingEnabled() == false);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
|
||||
|
||||
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, false);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
CHECK(setHandle->getReportingEnabled() == true);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
|
||||
|
||||
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, false);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
CHECK(setHandle->getReportingEnabled() == false);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
|
||||
|
||||
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4,
|
||||
false);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
/* For non-diagnostics and a specified minimum frequency of 0.2 seconds, the
|
||||
resulting collection interval should be 1.0 second */
|
||||
CHECK(poolOwner.dataset.getCollectionInterval() == 1.0);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
|
||||
|
||||
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false);
|
||||
REQUIRE(poolOwner.poolManager.performHkOperation() == result::OK);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
/* Now HK packet should be sent as message. */
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
poolOwnerMock.clearMessages();
|
||||
|
||||
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
poolOwnerMock.clearMessages();
|
||||
|
||||
HousekeepingMessage::setUpdateNotificationSetCommand(&hkCmd, lpool::testSid);
|
||||
sid_t sidToCheck;
|
||||
store_address_t storeId;
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true);
|
||||
CHECK(sidToCheck == lpool::testSid);
|
||||
|
||||
/* Now we test the handling is the dataset is set to diagnostic */
|
||||
poolOwner.dataset.setDiagnostic(true);
|
||||
|
||||
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) ==
|
||||
static_cast<int>(LocalDataPoolManager::WRONG_HK_PACKET_TYPE));
|
||||
/* We still expect a failure message being sent */
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
|
||||
|
||||
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4,
|
||||
false);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) ==
|
||||
static_cast<int>(LocalDataPoolManager::WRONG_HK_PACKET_TYPE));
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
|
||||
|
||||
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, false);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) ==
|
||||
static_cast<int>(LocalDataPoolManager::WRONG_HK_PACKET_TYPE));
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
CHECK(poolOwnerMock.clearLastSentMessage() == result::OK);
|
||||
|
||||
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid, true);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
poolOwnerMock.clearMessages();
|
||||
|
||||
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4,
|
||||
true);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
poolOwnerMock.clearMessages();
|
||||
|
||||
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true, true);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
poolOwnerMock.clearMessages();
|
||||
|
||||
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false, true);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
poolOwnerMock.clearMessages();
|
||||
|
||||
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, false);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) ==
|
||||
static_cast<int>(LocalDataPoolManager::WRONG_HK_PACKET_TYPE));
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
poolOwnerMock.clearMessages();
|
||||
|
||||
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid, true);
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
REQUIRE(poolOwnerMock.wasMessageSent());
|
||||
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
|
||||
poolOwnerMock.clearMessages();
|
||||
|
||||
HousekeepingMessage::setUpdateNotificationVariableCommand(&hkCmd, lpool::uint8VarGpid);
|
||||
gp_id_t gpidToCheck;
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true);
|
||||
CHECK(gpidToCheck == lpool::uint8VarGpid);
|
||||
|
||||
HousekeepingMessage::setUpdateSnapshotSetCommand(&hkCmd, lpool::testSid,
|
||||
store_address_t::invalid());
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true);
|
||||
CHECK(sidToCheck == lpool::testSid);
|
||||
|
||||
HousekeepingMessage::setUpdateSnapshotVariableCommand(&hkCmd, lpool::uint8VarGpid,
|
||||
store_address_t::invalid());
|
||||
CHECK(poolOwner.poolManager.handleHousekeepingMessage(&hkCmd) == result::OK);
|
||||
CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true);
|
||||
CHECK(gpidToCheck == lpool::uint8VarGpid);
|
||||
|
||||
poolOwner.poolManager.printPoolEntry(lpool::uint8VarId);
|
||||
}
|
||||
|
||||
/* we need to reset the subscription list because the pool owner
|
||||
is a global object. */
|
||||
CHECK(poolOwner.reset() == result::OK);
|
||||
poolOwnerMock.clearMessages(true);
|
||||
}
|
@ -4,30 +4,29 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "CatchDefinitions.h"
|
||||
#include "LocalPoolOwnerBase.h"
|
||||
#include "mocks/LocalPoolOwnerBase.h"
|
||||
#include "tests/TestsConfig.h"
|
||||
|
||||
TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") {
|
||||
auto* poolOwner =
|
||||
ObjectManager::instance()->get<LocalPoolOwnerBase>(objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
REQUIRE(poolOwner != nullptr);
|
||||
REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK);
|
||||
REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK);
|
||||
auto queue = MessageQueueMock(1);
|
||||
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
REQUIRE(poolOwner.initializeHkManager() == result::OK);
|
||||
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK);
|
||||
|
||||
SECTION("Basic Tests") {
|
||||
/* very basic test. */
|
||||
lp_var_t<uint8_t> testVariable =
|
||||
lp_var_t<uint8_t>(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId);
|
||||
REQUIRE(testVariable.read() == retval::CATCH_OK);
|
||||
REQUIRE(testVariable.read() == result::OK);
|
||||
CHECK(testVariable.value == 0);
|
||||
testVariable.value = 5;
|
||||
REQUIRE(testVariable.commit() == retval::CATCH_OK);
|
||||
REQUIRE(testVariable.read() == retval::CATCH_OK);
|
||||
REQUIRE(testVariable.commit() == result::OK);
|
||||
REQUIRE(testVariable.read() == result::OK);
|
||||
REQUIRE(testVariable.value == 5);
|
||||
CHECK(not testVariable.isValid());
|
||||
testVariable.setValid(true);
|
||||
CHECK(testVariable.isValid());
|
||||
CHECK(testVariable.commit(true) == retval::CATCH_OK);
|
||||
CHECK(testVariable.commit(true) == result::OK);
|
||||
|
||||
testVariable.setReadWriteMode(pool_rwm_t::VAR_READ);
|
||||
CHECK(testVariable.getReadWriteMode() == pool_rwm_t::VAR_READ);
|
||||
@ -43,7 +42,7 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") {
|
||||
|
||||
gp_id_t globPoolId(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint8VarId);
|
||||
lp_var_t<uint8_t> testVariable2 = lp_var_t<uint8_t>(globPoolId);
|
||||
REQUIRE(testVariable2.read() == retval::CATCH_OK);
|
||||
REQUIRE(testVariable2.read() == result::OK);
|
||||
CHECK(testVariable2 == 5);
|
||||
CHECK(testVariable == testVariable2);
|
||||
testVariable = 10;
|
||||
@ -55,12 +54,12 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") {
|
||||
CHECK(maxSize == 1);
|
||||
size_t serSize = 0;
|
||||
CHECK(testVariable.serialize(&varPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
|
||||
retval::CATCH_OK);
|
||||
result::OK);
|
||||
CHECK(variableRaw == 10);
|
||||
const uint8_t* varConstPtr = &variableRaw;
|
||||
testVariable = 5;
|
||||
CHECK(testVariable.deSerialize(&varConstPtr, &serSize, SerializeIF::Endianness::MACHINE) ==
|
||||
retval::CATCH_OK);
|
||||
result::OK);
|
||||
CHECK(testVariable == 10);
|
||||
CHECK(testVariable != testVariable2);
|
||||
CHECK(testVariable2 < testVariable);
|
||||
@ -106,6 +105,4 @@ TEST_CASE("LocalPoolVariable", "[LocPoolVarTest]") {
|
||||
lp_var_t<uint8_t> invalidObjectVar2 = lp_var_t<uint8_t>(globPoolId);
|
||||
lp_var_t<uint8_t> invalidObjectVar3 = lp_var_t<uint8_t>(nullptr, lpool::uint8VarId);
|
||||
}
|
||||
|
||||
CHECK(poolOwner->reset() == retval::CATCH_OK);
|
||||
}
|
@ -4,33 +4,32 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "CatchDefinitions.h"
|
||||
#include "LocalPoolOwnerBase.h"
|
||||
#include "mocks/LocalPoolOwnerBase.h"
|
||||
#include "tests/TestsConfig.h"
|
||||
|
||||
TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
|
||||
LocalPoolOwnerBase* poolOwner =
|
||||
ObjectManager::instance()->get<LocalPoolOwnerBase>(objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
REQUIRE(poolOwner != nullptr);
|
||||
REQUIRE(poolOwner->initializeHkManager() == retval::CATCH_OK);
|
||||
REQUIRE(poolOwner->initializeHkManagerAfterTaskCreation() == retval::CATCH_OK);
|
||||
auto queue = MessageQueueMock(1);
|
||||
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
REQUIRE(poolOwner.initializeHkManager() == result::OK);
|
||||
REQUIRE(poolOwner.initializeHkManagerAfterTaskCreation() == result::OK);
|
||||
|
||||
SECTION("BasicTest") {
|
||||
// very basic test.
|
||||
lp_vec_t<uint16_t, 3> testVector =
|
||||
lp_vec_t<uint16_t, 3>(objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id);
|
||||
REQUIRE(testVector.read() == retval::CATCH_OK);
|
||||
REQUIRE(testVector.read() == result::OK);
|
||||
testVector.value[0] = 5;
|
||||
testVector.value[1] = 232;
|
||||
testVector.value[2] = 32023;
|
||||
|
||||
REQUIRE(testVector.commit(true) == retval::CATCH_OK);
|
||||
REQUIRE(testVector.commit(true) == result::OK);
|
||||
CHECK(testVector.isValid());
|
||||
|
||||
testVector.value[0] = 0;
|
||||
testVector.value[1] = 0;
|
||||
testVector.value[2] = 0;
|
||||
|
||||
CHECK(testVector.read() == retval::CATCH_OK);
|
||||
CHECK(testVector.read() == result::OK);
|
||||
CHECK(testVector.value[0] == 5);
|
||||
CHECK(testVector.value[1] == 232);
|
||||
CHECK(testVector.value[2] == 32023);
|
||||
@ -41,7 +40,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
|
||||
(we can't throw exceptions) */
|
||||
testVector[4] = 12;
|
||||
CHECK(testVector[2] == 12);
|
||||
CHECK(testVector.commit() == retval::CATCH_OK);
|
||||
CHECK(testVector.commit() == result::OK);
|
||||
|
||||
/* Use read-only reference. */
|
||||
const lp_vec_t<uint16_t, 3>& roTestVec = testVector;
|
||||
@ -58,7 +57,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
|
||||
uint8_t* vecPtr = reinterpret_cast<uint8_t*>(serializedVector);
|
||||
size_t serSize = 0;
|
||||
REQUIRE(testVector.serialize(&vecPtr, &serSize, maxSize, SerializeIF::Endianness::MACHINE) ==
|
||||
retval::CATCH_OK);
|
||||
result::OK);
|
||||
|
||||
CHECK(serSize == 6);
|
||||
CHECK(serializedVector[0] == 5);
|
||||
@ -75,7 +74,7 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
|
||||
|
||||
const uint8_t* constVecPtr = reinterpret_cast<const uint8_t*>(serializedVector);
|
||||
REQUIRE(testVector.deSerialize(&constVecPtr, &serSize, SerializeIF::Endianness::MACHINE) ==
|
||||
retval::CATCH_OK);
|
||||
result::OK);
|
||||
CHECK(testVector[0] == 16);
|
||||
CHECK(testVector[1] == 7832);
|
||||
CHECK(testVector[2] == 39232);
|
||||
@ -106,5 +105,4 @@ TEST_CASE("LocalPoolVector", "[LocPoolVecTest]") {
|
||||
objects::TEST_LOCAL_POOL_OWNER_BASE, lpool::uint16Vec3Id, nullptr, pool_rwm_t::VAR_READ);
|
||||
REQUIRE(readOnlyVec.commit() == static_cast<int>(PoolVariableIF::INVALID_READ_WRITE_MODE));
|
||||
}
|
||||
poolOwner->reset();
|
||||
}
|
@ -1,8 +1,4 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
CookieIFMock.cpp
|
||||
ComIFMock.cpp
|
||||
DeviceHandlerCommander.cpp
|
||||
DeviceHandlerMock.cpp
|
||||
DeviceFdirMock.cpp
|
||||
TestDeviceHandlerBase.cpp
|
||||
)
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "ComIFMock.h"
|
||||
#include "DeviceFdirMock.h"
|
||||
#include "DeviceHandlerCommander.h"
|
||||
#include "DeviceHandlerMock.h"
|
||||
#include "devicehandler/CookieIFMock.h"
|
||||
#include "mocks/ComIFMock.h"
|
||||
#include "mocks/CookieIFMock.h"
|
||||
#include "mocks/DeviceFdirMock.h"
|
||||
#include "mocks/DeviceHandlerMock.h"
|
||||
#include "objects/systemObjectList.h"
|
||||
|
||||
TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
|
||||
|
@ -60,7 +60,7 @@ TEST_CASE("DleEncoder", "[DleEncoder]") {
|
||||
const std::vector<uint8_t>& expectedVec) {
|
||||
result = encoder.encode(vecToEncode.data(), vecToEncode.size(), buffer.data(), buffer.size(),
|
||||
&encodedLen);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
for (size_t idx = 0; idx < expectedVec.size(); idx++) {
|
||||
REQUIRE(buffer[idx] == expectedVec[idx]);
|
||||
}
|
||||
@ -71,7 +71,7 @@ TEST_CASE("DleEncoder", "[DleEncoder]") {
|
||||
const std::vector<uint8_t>& expectedVec) {
|
||||
result = encoder.decode(testVecEncoded.data(), testVecEncoded.size(), &readLen, buffer.data(),
|
||||
buffer.size(), &decodedLen);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
REQUIRE(readLen == testVecEncoded.size());
|
||||
REQUIRE(decodedLen == expectedVec.size());
|
||||
for (size_t idx = 0; idx < decodedLen; idx++) {
|
||||
|
@ -33,12 +33,12 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") {
|
||||
MessageQueueIF* hkQueue = QueueFactory::instance()->createMessageQueue(1);
|
||||
internalErrorReporter->getSubscriptionInterface()->subscribeForSetUpdateMessage(
|
||||
InternalErrorDataset::ERROR_SET_ID, objects::NO_OBJECT, hkQueue->getId(), true);
|
||||
StorageManagerIF* ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
auto* ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
|
||||
SECTION("MessageQueueFull") {
|
||||
CommandMessage message;
|
||||
ActionMessage::setCompletionReply(&message, 10, true);
|
||||
auto result = hkQueue->sendMessage(testQueue->getId(), &message);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
uint32_t queueHits = 0;
|
||||
uint32_t lostTm = 0;
|
||||
uint32_t storeHits = 0;
|
||||
@ -57,7 +57,7 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") {
|
||||
REQUIRE(gpid.objectId == objects::INTERNAL_ERROR_REPORTER);
|
||||
// We need the object ID of the reporter here (NO_OBJECT)
|
||||
InternalErrorDataset dataset(objects::INTERNAL_ERROR_REPORTER);
|
||||
CCSDSTime::CDS_short time;
|
||||
CCSDSTime::CDS_short time{};
|
||||
ConstAccessorPair data = ipcStore->getData(storeAddress);
|
||||
REQUIRE(data.first == HasReturnvaluesIF::RETURN_OK);
|
||||
HousekeepingSnapshot hkSnapshot(&time, &dataset);
|
||||
@ -87,7 +87,7 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") {
|
||||
|
||||
ConstAccessorPair data = ipcStore->getData(storeAddress);
|
||||
REQUIRE(data.first == HasReturnvaluesIF::RETURN_OK);
|
||||
CCSDSTime::CDS_short time;
|
||||
CCSDSTime::CDS_short time{};
|
||||
// We need the object ID of the reporter here (NO_OBJECT)
|
||||
InternalErrorDataset dataset(objects::INTERNAL_ERROR_REPORTER);
|
||||
HousekeepingSnapshot hkSnapshot(&time, &dataset);
|
||||
@ -107,10 +107,10 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") {
|
||||
// Message Queue Id
|
||||
MessageQueueId_t id = internalErrorReporter->getCommandQueue();
|
||||
REQUIRE(id != MessageQueueIF::NO_QUEUE);
|
||||
CommandMessage message;
|
||||
CommandMessage message2;
|
||||
sid_t sid(objects::INTERNAL_ERROR_REPORTER, InternalErrorDataset::ERROR_SET_ID);
|
||||
HousekeepingMessage::setToggleReportingCommand(&message, sid, true, false);
|
||||
result = hkQueue->sendMessage(id, &message);
|
||||
HousekeepingMessage::setToggleReportingCommand(&message2, sid, true, false);
|
||||
result = hkQueue->sendMessage(id, &message2);
|
||||
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
||||
internalErrorReporter->performOperation(0);
|
||||
}
|
||||
|
11
unittests/mocks/AcceptsTmMock.cpp
Normal file
11
unittests/mocks/AcceptsTmMock.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "AcceptsTmMock.h"
|
||||
|
||||
AcceptsTmMock::AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn)
|
||||
: SystemObject(registeredId), returnedQueue(queueToReturn) {}
|
||||
|
||||
AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn)
|
||||
: SystemObject(objects::NO_OBJECT, false), returnedQueue(queueToReturn) {}
|
||||
|
||||
MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) {
|
||||
return returnedQueue;
|
||||
}
|
16
unittests/mocks/AcceptsTmMock.h
Normal file
16
unittests/mocks/AcceptsTmMock.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef FSFW_TESTS_ACCEPTSTMMOCK_H
|
||||
#define FSFW_TESTS_ACCEPTSTMMOCK_H
|
||||
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
|
||||
|
||||
class AcceptsTmMock : public SystemObject, public AcceptsTelemetryIF {
|
||||
public:
|
||||
AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn);
|
||||
explicit AcceptsTmMock(MessageQueueId_t queueToReturn);
|
||||
|
||||
MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override;
|
||||
|
||||
MessageQueueId_t returnedQueue;
|
||||
};
|
||||
#endif // FSFW_TESTS_ACCEPTSTMMOCK_H
|
@ -1,3 +1,14 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
PowerSwitcherMock.cpp
|
||||
DeviceHandlerMock.cpp
|
||||
DeviceFdirMock.cpp
|
||||
CookieIFMock.cpp
|
||||
ComIFMock.cpp
|
||||
MessageQueueMock.cpp
|
||||
InternalErrorReporterMock.cpp
|
||||
LocalPoolOwnerBase.cpp
|
||||
PusVerificationReporterMock.cpp
|
||||
PusServiceBaseMock.cpp
|
||||
AcceptsTmMock.cpp
|
||||
PusDistributorMock.cpp
|
||||
)
|
||||
|
86
unittests/mocks/CdsShortTimestamperMock.h
Normal file
86
unittests/mocks/CdsShortTimestamperMock.h
Normal file
@ -0,0 +1,86 @@
|
||||
#ifndef FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
|
||||
#define FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "fsfw/timemanager/TimeReaderIF.h"
|
||||
#include "fsfw/timemanager/TimeStamperIF.h"
|
||||
|
||||
class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF {
|
||||
public:
|
||||
unsigned int serializeCallCount = 0;
|
||||
unsigned int deserializeCallCount = 0;
|
||||
ReturnValue_t lastDeserializeResult = HasReturnvaluesIF::RETURN_OK;
|
||||
ReturnValue_t lastSerializeResult = HasReturnvaluesIF::RETURN_OK;
|
||||
unsigned int getSizeCallCount = 0;
|
||||
bool nextSerFails = false;
|
||||
ReturnValue_t serFailRetval = HasReturnvaluesIF::RETURN_FAILED;
|
||||
bool nextDeserFails = false;
|
||||
ReturnValue_t deserFailRetval = HasReturnvaluesIF::RETURN_FAILED;
|
||||
std::array<uint8_t, 7> valueToStamp{};
|
||||
|
||||
CdsShortTimestamperMock() = default;
|
||||
|
||||
explicit CdsShortTimestamperMock(std::array<uint8_t, 7> valueToStamp)
|
||||
: valueToStamp(valueToStamp) {}
|
||||
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const override {
|
||||
auto &thisNonConst = const_cast<CdsShortTimestamperMock &>(*this);
|
||||
thisNonConst.serializeCallCount += 1;
|
||||
if (nextSerFails) {
|
||||
return serFailRetval;
|
||||
}
|
||||
if (*size + getSerializedSize() > maxSize) {
|
||||
thisNonConst.lastSerializeResult = SerializeIF::BUFFER_TOO_SHORT;
|
||||
return lastSerializeResult;
|
||||
}
|
||||
std::copy(valueToStamp.begin(), valueToStamp.end(), *buffer);
|
||||
thisNonConst.lastSerializeResult = HasReturnvaluesIF::RETURN_OK;
|
||||
*buffer += getSerializedSize();
|
||||
*size += getSerializedSize();
|
||||
return lastSerializeResult;
|
||||
}
|
||||
[[nodiscard]] size_t getSerializedSize() const override {
|
||||
auto &thisNonConst = const_cast<CdsShortTimestamperMock &>(*this);
|
||||
thisNonConst.getSizeCallCount += 1;
|
||||
return valueToStamp.size();
|
||||
}
|
||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override {
|
||||
deserializeCallCount += 1;
|
||||
if (nextDeserFails) {
|
||||
return deserFailRetval;
|
||||
}
|
||||
if (*size < 7) {
|
||||
lastDeserializeResult = SerializeIF::STREAM_TOO_SHORT;
|
||||
return lastDeserializeResult;
|
||||
}
|
||||
std::copy(*buffer, *buffer + getSerializedSize(), valueToStamp.begin());
|
||||
return lastDeserializeResult;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t getTimestampSize() const override { return getSerializedSize(); }
|
||||
ReturnValue_t addTimeStamp(uint8_t *buffer, uint8_t maxSize) override { return 0; }
|
||||
|
||||
void reset() {
|
||||
serializeCallCount = 0;
|
||||
getSizeCallCount = 0;
|
||||
deserializeCallCount = 0;
|
||||
nextSerFails = false;
|
||||
nextDeserFails = false;
|
||||
lastSerializeResult = HasReturnvaluesIF::RETURN_OK;
|
||||
lastDeserializeResult = HasReturnvaluesIF::RETURN_OK;
|
||||
deserFailRetval = HasReturnvaluesIF::RETURN_FAILED;
|
||||
serFailRetval = HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override {
|
||||
return deSerialize(&buffer, &maxSize, SerializeIF::Endianness::NETWORK);
|
||||
}
|
||||
timeval &getTime() override { return dummyTime; }
|
||||
|
||||
private:
|
||||
timeval dummyTime{};
|
||||
};
|
||||
#endif // FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
|
@ -1,11 +1,9 @@
|
||||
#include "DeviceFdirMock.h"
|
||||
|
||||
#include "devicehandler/DeviceFdirMock.h"
|
||||
|
||||
DeviceFdirMock::DeviceFdirMock(object_id_t owner, object_id_t parent)
|
||||
: DeviceHandlerFailureIsolation(owner, parent) {}
|
||||
|
||||
DeviceFdirMock::~DeviceFdirMock() {}
|
||||
DeviceFdirMock::~DeviceFdirMock() = default;
|
||||
|
||||
uint32_t DeviceFdirMock::getMissedReplyCount() {
|
||||
ParameterWrapper parameterWrapper;
|
@ -8,7 +8,7 @@ DeviceHandlerMock::DeviceHandlerMock(object_id_t objectId, object_id_t deviceCom
|
||||
mode = MODE_ON;
|
||||
}
|
||||
|
||||
DeviceHandlerMock::~DeviceHandlerMock() {}
|
||||
DeviceHandlerMock::~DeviceHandlerMock() = default;
|
||||
|
||||
void DeviceHandlerMock::doStartUp() { setMode(_MODE_TO_ON); }
|
||||
|
@ -2,13 +2,15 @@
|
||||
#define FSFW_UNITTEST_TESTS_MOCKS_HKRECEIVERMOCK_H_
|
||||
|
||||
#include <fsfw/housekeeping/AcceptsHkPacketsIF.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
|
||||
class HkReceiverMock : public SystemObject, public AcceptsHkPacketsIF {
|
||||
class HkReceiverMock : public AcceptsHkPacketsIF {
|
||||
public:
|
||||
HkReceiverMock(object_id_t objectId) : SystemObject(objectId) {}
|
||||
explicit HkReceiverMock(MessageQueueId_t queueId) : queueId(queueId) {}
|
||||
|
||||
MessageQueueId_t getHkQueue() const { return MessageQueueIF::NO_QUEUE; }
|
||||
[[nodiscard]] MessageQueueId_t getHkQueue() const override { return queueId; }
|
||||
|
||||
private:
|
||||
MessageQueueId_t queueId;
|
||||
};
|
||||
|
||||
#endif /* FSFW_UNITTEST_TESTS_MOCKS_HKRECEIVERMOCK_H_ */
|
||||
|
13
unittests/mocks/InternalErrorReporterMock.cpp
Normal file
13
unittests/mocks/InternalErrorReporterMock.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "InternalErrorReporterMock.h"
|
||||
|
||||
InternalErrorReporterMock::InternalErrorReporterMock() = default;
|
||||
|
||||
void InternalErrorReporterMock::queueMessageNotSent() { queueMsgNotSentCallCnt++; }
|
||||
void InternalErrorReporterMock::lostTm() { lostTmCallCnt++; }
|
||||
void InternalErrorReporterMock::storeFull() { storeFullCallCnt++; }
|
||||
|
||||
void InternalErrorReporterMock::reset() {
|
||||
queueMsgNotSentCallCnt = 0;
|
||||
lostTmCallCnt = 0;
|
||||
storeFullCallCnt = 0;
|
||||
}
|
19
unittests/mocks/InternalErrorReporterMock.h
Normal file
19
unittests/mocks/InternalErrorReporterMock.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef FSFW_TESTS_INTERNALERRORREPORTERMOCK_H
|
||||
#define FSFW_TESTS_INTERNALERRORREPORTERMOCK_H
|
||||
|
||||
#include "fsfw/internalerror/InternalErrorReporterIF.h"
|
||||
|
||||
class InternalErrorReporterMock : public InternalErrorReporterIF {
|
||||
public:
|
||||
unsigned int queueMsgNotSentCallCnt = 0;
|
||||
unsigned int lostTmCallCnt = 0;
|
||||
unsigned int storeFullCallCnt = 0;
|
||||
InternalErrorReporterMock();
|
||||
void reset();
|
||||
|
||||
private:
|
||||
void queueMessageNotSent() override;
|
||||
void lostTm() override;
|
||||
void storeFull() override;
|
||||
};
|
||||
#endif // FSFW_TESTS_INTERNALERRORREPORTERMOCK_H
|
@ -1,18 +1,17 @@
|
||||
#include "LocalPoolOwnerBase.h"
|
||||
|
||||
LocalPoolOwnerBase::LocalPoolOwnerBase(object_id_t objectId)
|
||||
: SystemObject(objectId), poolManager(this, messageQueue), dataset(this, lpool::testSetId) {
|
||||
messageQueue = new MessageQueueMockBase();
|
||||
}
|
||||
LocalPoolOwnerBase::LocalPoolOwnerBase(MessageQueueIF &queue, object_id_t objectId)
|
||||
: SystemObject(objectId),
|
||||
queue(queue),
|
||||
poolManager(this, &queue),
|
||||
dataset(this, lpool::testSetId) {}
|
||||
|
||||
LocalPoolOwnerBase::~LocalPoolOwnerBase() {
|
||||
QueueFactory::instance()->deleteMessageQueue(messageQueue);
|
||||
}
|
||||
LocalPoolOwnerBase::~LocalPoolOwnerBase() = default;
|
||||
|
||||
ReturnValue_t LocalPoolOwnerBase::initializeHkManager() {
|
||||
if (not initialized) {
|
||||
initialized = true;
|
||||
return poolManager.initialize(messageQueue);
|
||||
return poolManager.initialize(&queue);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
@ -20,12 +19,12 @@ ReturnValue_t LocalPoolOwnerBase::initializeHkManager() {
|
||||
ReturnValue_t LocalPoolOwnerBase::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
|
||||
LocalDataPoolManager &poolManager) {
|
||||
// Default initialization empty for now.
|
||||
localDataPoolMap.emplace(lpool::uint8VarId, new PoolEntry<uint8_t>({0}));
|
||||
localDataPoolMap.emplace(lpool::floatVarId, new PoolEntry<float>({0}));
|
||||
localDataPoolMap.emplace(lpool::uint32VarId, new PoolEntry<uint32_t>({0}));
|
||||
localDataPoolMap.emplace(lpool::uint8VarId, &u8PoolEntry);
|
||||
localDataPoolMap.emplace(lpool::floatVarId, &floatPoolEntry);
|
||||
localDataPoolMap.emplace(lpool::uint32VarId, &u32PoolEntry);
|
||||
|
||||
localDataPoolMap.emplace(lpool::uint16Vec3Id, new PoolEntry<uint16_t>({0, 0, 0}));
|
||||
localDataPoolMap.emplace(lpool::int64Vec2Id, new PoolEntry<int64_t>({0, 0}));
|
||||
localDataPoolMap.emplace(lpool::uint16Vec3Id, &u16VecPoolEntry);
|
||||
localDataPoolMap.emplace(lpool::int64Vec2Id, &i64VecPoolEntry);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -90,7 +89,7 @@ bool LocalPoolOwnerBase::changedDataSetCallbackWasCalled(sid_t &sid, store_addre
|
||||
sid = changedDatasetSid;
|
||||
storeId = storeIdForChangedSet;
|
||||
this->changedDatasetSid.raw = sid_t::INVALID_SID;
|
||||
this->storeIdForChangedSet = storeId::INVALID_STORE_ADDRESS;
|
||||
this->storeIdForChangedSet = store_address_t::invalid();
|
||||
return condition;
|
||||
}
|
||||
|
||||
@ -108,7 +107,7 @@ bool LocalPoolOwnerBase::changedVariableCallbackWasCalled(gp_id_t &gpid, store_a
|
||||
gpid = changedPoolVariableGpid;
|
||||
storeId = storeIdForChangedVariable;
|
||||
this->changedPoolVariableGpid.raw = gp_id_t::INVALID_GPID;
|
||||
this->storeIdForChangedVariable = storeId::INVALID_STORE_ADDRESS;
|
||||
this->storeIdForChangedVariable = store_address_t::invalid();
|
||||
return condition;
|
||||
}
|
||||
|
||||
@ -125,3 +124,5 @@ void LocalPoolOwnerBase::handleChangedPoolVariable(gp_id_t globPoolId, store_add
|
||||
this->changedPoolVariableGpid = globPoolId;
|
||||
this->storeIdForChangedVariable = storeId;
|
||||
}
|
||||
|
||||
void LocalPoolOwnerBase::setHkDestId(MessageQueueId_t id) { poolManager.setHkDestinationId(id); }
|
@ -10,7 +10,8 @@
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
|
||||
#include "../mocks/MessageQueueMockBase.h"
|
||||
#include "fsfw/datapool/PoolEntry.h"
|
||||
#include "mocks/MessageQueueMock.h"
|
||||
#include "tests/TestsConfig.h"
|
||||
|
||||
namespace lpool {
|
||||
@ -64,26 +65,29 @@ class LocalPoolTestDataSet : public LocalDataSet {
|
||||
|
||||
class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF {
|
||||
public:
|
||||
LocalPoolOwnerBase(object_id_t objectId = objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
explicit LocalPoolOwnerBase(MessageQueueIF& queue,
|
||||
object_id_t objectId = objects::TEST_LOCAL_POOL_OWNER_BASE);
|
||||
|
||||
~LocalPoolOwnerBase();
|
||||
~LocalPoolOwnerBase() override;
|
||||
|
||||
object_id_t getObjectId() const override { return SystemObject::getObjectId(); }
|
||||
[[nodiscard]] object_id_t getObjectId() const override { return SystemObject::getObjectId(); }
|
||||
|
||||
ReturnValue_t initializeHkManager();
|
||||
|
||||
void setHkDestId(MessageQueueId_t id);
|
||||
|
||||
ReturnValue_t initializeHkManagerAfterTaskCreation();
|
||||
|
||||
/** Command queue for housekeeping messages. */
|
||||
MessageQueueId_t getCommandQueue() const override { return messageQueue->getId(); }
|
||||
[[nodiscard]] MessageQueueId_t getCommandQueue() const override { return queue.getId(); }
|
||||
|
||||
// This is called by initializeAfterTaskCreation of the HK manager.
|
||||
virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
|
||||
LocalDataPoolManager* getHkManagerHandle() override { return &poolManager; }
|
||||
|
||||
dur_millis_t getPeriodicOperationFrequency() const override { return 200; }
|
||||
[[nodiscard]] dur_millis_t getPeriodicOperationFrequency() const override { return 200; }
|
||||
|
||||
/**
|
||||
* This function is used by the pool manager to get a valid dataset
|
||||
@ -91,41 +95,54 @@ class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF {
|
||||
* @param sid Corresponding structure ID
|
||||
* @return
|
||||
*/
|
||||
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override { return &dataset; }
|
||||
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override { return &dataset; }
|
||||
|
||||
virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) override;
|
||||
LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) override;
|
||||
|
||||
MessageQueueMockBase* getMockQueueHandle() const {
|
||||
return dynamic_cast<MessageQueueMockBase*>(messageQueue);
|
||||
[[nodiscard]] MessageQueueMock& getMockQueueHandle() const {
|
||||
return dynamic_cast<MessageQueueMock&>(queue);
|
||||
}
|
||||
|
||||
ReturnValue_t subscribePeriodicHk(bool enableReporting) {
|
||||
return poolManager.subscribeForPeriodicPacket(lpool::testSid, enableReporting, 0.2, false);
|
||||
return poolManager.subscribeForRegularPeriodicPacket(
|
||||
subdp::RegularHkPeriodicParams(lpool::testSid, enableReporting, 0.2));
|
||||
}
|
||||
|
||||
ReturnValue_t subscribeWrapperSetUpdate() {
|
||||
ReturnValue_t subscribeWrapperSetUpdate(MessageQueueId_t receiverId) {
|
||||
return poolManager.subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT,
|
||||
objects::HK_RECEIVER_MOCK, false);
|
||||
receiverId, false);
|
||||
}
|
||||
|
||||
ReturnValue_t subscribeWrapperSetUpdateSnapshot() {
|
||||
ReturnValue_t subscribeWrapperSetUpdateSnapshot(MessageQueueId_t receiverId) {
|
||||
return poolManager.subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT,
|
||||
objects::HK_RECEIVER_MOCK, true);
|
||||
receiverId, true);
|
||||
}
|
||||
|
||||
ReturnValue_t subscribeWrapperSetUpdateHk(bool diagnostics = false) {
|
||||
return poolManager.subscribeForUpdatePacket(lpool::testSid, diagnostics, false,
|
||||
objects::HK_RECEIVER_MOCK);
|
||||
ReturnValue_t subscribeWrapperSetUpdateHk(bool diagnostics = false,
|
||||
AcceptsHkPacketsIF* receiver = nullptr) {
|
||||
if (diagnostics) {
|
||||
auto params = subdp::DiagnosticsHkUpdateParams(lpool::testSid, true);
|
||||
if (receiver != nullptr) {
|
||||
params.receiver = receiver->getHkQueue();
|
||||
}
|
||||
return poolManager.subscribeForDiagUpdatePacket(params);
|
||||
} else {
|
||||
auto params = subdp::RegularHkUpdateParams(lpool::testSid, true);
|
||||
if (receiver != nullptr) {
|
||||
params.receiver = receiver->getHkQueue();
|
||||
}
|
||||
return poolManager.subscribeForRegularUpdatePacket(params);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t subscribeWrapperVariableUpdate(lp_id_t localPoolId) {
|
||||
ReturnValue_t subscribeWrapperVariableUpdate(MessageQueueId_t receiverId, lp_id_t localPoolId) {
|
||||
return poolManager.subscribeForVariableUpdateMessage(localPoolId, MessageQueueIF::NO_QUEUE,
|
||||
objects::HK_RECEIVER_MOCK, false);
|
||||
receiverId, false);
|
||||
}
|
||||
|
||||
ReturnValue_t subscribeWrapperVariableSnapshot(lp_id_t localPoolId) {
|
||||
ReturnValue_t subscribeWrapperVariableSnapshot(MessageQueueId_t receiverId, lp_id_t localPoolId) {
|
||||
return poolManager.subscribeForVariableUpdateMessage(localPoolId, MessageQueueIF::NO_QUEUE,
|
||||
objects::HK_RECEIVER_MOCK, true);
|
||||
receiverId, true);
|
||||
}
|
||||
|
||||
ReturnValue_t reset();
|
||||
@ -148,14 +165,19 @@ class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF {
|
||||
gp_id_t changedPoolVariableGpid;
|
||||
store_address_t storeIdForChangedVariable;
|
||||
|
||||
PoolEntry<uint8_t> u8PoolEntry = PoolEntry<uint8_t>({0});
|
||||
PoolEntry<float> floatPoolEntry = PoolEntry<float>({0});
|
||||
PoolEntry<uint32_t> u32PoolEntry = PoolEntry<uint32_t>({0});
|
||||
PoolEntry<uint16_t> u16VecPoolEntry = PoolEntry<uint16_t>({0, 0, 0});
|
||||
PoolEntry<int64_t> i64VecPoolEntry = PoolEntry<int64_t>({0, 0});
|
||||
|
||||
lp_var_t<uint8_t> testUint8 = lp_var_t<uint8_t>(this, lpool::uint8VarId);
|
||||
lp_var_t<float> testFloat = lp_var_t<float>(this, lpool::floatVarId);
|
||||
lp_var_t<uint32_t> testUint32 = lp_var_t<uint32_t>(this, lpool::uint32VarId);
|
||||
|
||||
lp_vec_t<uint16_t, 3> testUint16Vec = lp_vec_t<uint16_t, 3>(this, lpool::uint16Vec3Id);
|
||||
lp_vec_t<int64_t, 2> testInt64Vec = lp_vec_t<int64_t, 2>(this, lpool::int64Vec2Id);
|
||||
|
||||
MessageQueueIF* messageQueue = nullptr;
|
||||
MessageQueueIF& queue;
|
||||
|
||||
bool initialized = false;
|
||||
bool initializedAfterTaskCreation = false;
|
173
unittests/mocks/MessageQueueMock.cpp
Normal file
173
unittests/mocks/MessageQueueMock.cpp
Normal file
@ -0,0 +1,173 @@
|
||||
#include "MessageQueueMock.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
MessageQueueMock::MessageQueueMock(MessageQueueId_t queueId)
|
||||
: MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {}
|
||||
|
||||
bool MessageQueueMock::wasMessageSent() const {
|
||||
return std::any_of(
|
||||
sendMap.begin(), sendMap.end(),
|
||||
[](const std::pair<MessageQueueId_t, SendInfo>& pair) { return pair.second.callCount > 0; });
|
||||
}
|
||||
|
||||
size_t MessageQueueMock::numberOfSentMessages() const {
|
||||
size_t callCount = 0;
|
||||
for (auto& destInfo : sendMap) {
|
||||
callCount += destInfo.second.callCount;
|
||||
}
|
||||
return callCount;
|
||||
}
|
||||
|
||||
size_t MessageQueueMock::numberOfSentMessagesToDest(MessageQueueId_t id) const {
|
||||
auto iter = sendMap.find(id);
|
||||
if (iter == sendMap.end()) {
|
||||
return 0;
|
||||
}
|
||||
return iter->second.callCount;
|
||||
}
|
||||
|
||||
size_t MessageQueueMock::numberOfSentMessagesToDefault() const {
|
||||
return numberOfSentMessagesToDest(MessageQueueBase::getDefaultDestination());
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::clearLastReceivedMessage(bool clearCmdMsg) {
|
||||
if (receivedMsgs.empty()) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
if (clearCmdMsg) {
|
||||
CommandMessage message;
|
||||
std::memcpy(message.getBuffer(), receivedMsgs.front().getBuffer(), message.getMessageSize());
|
||||
message.clearCommandMessage();
|
||||
}
|
||||
receivedMsgs.pop();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::receiveMessage(MessageQueueMessageIF* message) {
|
||||
if (receivedMsgs.empty()) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
std::memcpy(message->getBuffer(), receivedMsgs.front().getBuffer(), message->getMessageSize());
|
||||
receivedMsgs.pop();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::flush(uint32_t* count) { return HasReturnvaluesIF::RETURN_FAILED; }
|
||||
|
||||
ReturnValue_t MessageQueueMock::sendMessageFrom(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault) {
|
||||
if (message == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if (nextSendFailsPair.first) {
|
||||
nextSendFailsPair.first = false;
|
||||
return nextSendFailsPair.second;
|
||||
}
|
||||
auto iter = sendMap.find(sendTo);
|
||||
MessageQueueMessage messageCopy;
|
||||
if (iter == sendMap.end()) {
|
||||
createMsgCopy(messageCopy, *message);
|
||||
sendMap.emplace(sendTo, SendInfo(messageCopy, 1));
|
||||
} else {
|
||||
iter->second.callCount += 1;
|
||||
createMsgCopy(messageCopy, *message);
|
||||
iter->second.msgs.push(messageCopy);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::reply(MessageQueueMessageIF* message) {
|
||||
return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false);
|
||||
}
|
||||
|
||||
void MessageQueueMock::clearMessages(bool clearCommandMessages) {
|
||||
if (not clearCommandMessages) {
|
||||
sendMap.clear();
|
||||
return;
|
||||
}
|
||||
for (auto& destInfo : sendMap) {
|
||||
while (!destInfo.second.msgs.empty()) {
|
||||
CommandMessage message;
|
||||
std::memcpy(message.getBuffer(), destInfo.second.msgs.front().getBuffer(),
|
||||
message.getMessageSize());
|
||||
message.clear();
|
||||
destInfo.second.msgs.pop();
|
||||
destInfo.second.callCount--;
|
||||
}
|
||||
}
|
||||
sendMap.clear();
|
||||
}
|
||||
|
||||
void MessageQueueMock::addReceivedMessage(MessageQueueMessageIF& msg) {
|
||||
MessageQueueMessage messageCopy;
|
||||
createMsgCopy(messageCopy, msg);
|
||||
receivedMsgs.push(messageCopy);
|
||||
}
|
||||
|
||||
void MessageQueueMock::createMsgCopy(MessageQueueMessageIF& into, MessageQueueMessageIF& from) {
|
||||
if (from.getMessageSize() > into.getMaximumDataSize()) {
|
||||
throw std::invalid_argument("Passed message does not fit into message copy");
|
||||
}
|
||||
std::memcpy(into.getBuffer(), from.getBuffer(), from.getMaximumDataSize());
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::getNextSentMessage(MessageQueueId_t id,
|
||||
MessageQueueMessageIF& message) {
|
||||
auto iter = sendMap.find(id);
|
||||
if (iter == sendMap.end() or iter->second.callCount == 0) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
createMsgCopy(message, iter->second.msgs.front());
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::getNextSentMessage(MessageQueueMessageIF& message) {
|
||||
return getNextSentMessage(MessageQueueBase::getDefaultDestination(), message);
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::clearLastSentMessage(MessageQueueId_t destId, bool clearCmdMsg) {
|
||||
auto iter = sendMap.find(destId);
|
||||
if (iter == sendMap.end()) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
return clearLastSentMessage(iter, clearCmdMsg);
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::clearLastSentMessage(bool clearCmdMsg) {
|
||||
auto iter = sendMap.find(getDefaultDestination());
|
||||
if (iter == sendMap.end()) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
ReturnValue_t result = clearLastSentMessage(iter, clearCmdMsg);
|
||||
clearEmptyEntries();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueueMock::clearLastSentMessage(
|
||||
std::map<MessageQueueId_t, SendInfo>::iterator& iter, bool clearCmdMsg) {
|
||||
if (clearCmdMsg) {
|
||||
CommandMessage message;
|
||||
std::memcpy(message.getBuffer(), iter->second.msgs.front().getBuffer(),
|
||||
message.getMessageSize());
|
||||
message.clear();
|
||||
}
|
||||
iter->second.msgs.pop();
|
||||
iter->second.callCount--;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
void MessageQueueMock::clearEmptyEntries() {
|
||||
for (auto it = sendMap.cbegin(); it != sendMap.cend();) {
|
||||
if (it->second.callCount == 0) {
|
||||
sendMap.erase(it++);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
void MessageQueueMock::makeNextSendFail(ReturnValue_t retval) {
|
||||
nextSendFailsPair.first = true;
|
||||
nextSendFailsPair.second = retval;
|
||||
}
|
64
unittests/mocks/MessageQueueMock.h
Normal file
64
unittests/mocks/MessageQueueMock.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_
|
||||
#define FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_
|
||||
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
|
||||
#include "CatchDefinitions.h"
|
||||
#include "fsfw/ipc/CommandMessage.h"
|
||||
#include "fsfw/ipc/MessageQueueBase.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
#include "fsfw/ipc/MessageQueueMessage.h"
|
||||
|
||||
struct SendInfo {
|
||||
explicit SendInfo(MessageQueueMessage& initMsg, unsigned int initCallCnt = 1)
|
||||
: callCount(initCallCnt) {
|
||||
msgs.push(initMsg);
|
||||
}
|
||||
unsigned int callCount = 0;
|
||||
std::queue<MessageQueueMessage> msgs;
|
||||
};
|
||||
|
||||
class MessageQueueMock : public MessageQueueBase {
|
||||
public:
|
||||
void addReceivedMessage(MessageQueueMessageIF& msg);
|
||||
explicit MessageQueueMock(MessageQueueId_t queueId);
|
||||
|
||||
//! Get next message which was sent to the default destination
|
||||
ReturnValue_t getNextSentMessage(MessageQueueMessageIF& message);
|
||||
//! Get message which was sent to a specific ID
|
||||
ReturnValue_t getNextSentMessage(MessageQueueId_t id, MessageQueueMessageIF& message);
|
||||
[[nodiscard]] bool wasMessageSent() const;
|
||||
void makeNextSendFail(ReturnValue_t retval);
|
||||
[[nodiscard]] size_t numberOfSentMessages() const;
|
||||
[[nodiscard]] size_t numberOfSentMessagesToDefault() const;
|
||||
[[nodiscard]] size_t numberOfSentMessagesToDest(MessageQueueId_t id) const;
|
||||
/**
|
||||
* Pop a message, clearing it in the process.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t clearLastReceivedMessage(bool clearCmdMsg = true);
|
||||
|
||||
ReturnValue_t flush(uint32_t* count) override;
|
||||
ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault = false) override;
|
||||
ReturnValue_t reply(MessageQueueMessageIF* message) override;
|
||||
|
||||
ReturnValue_t clearLastSentMessage(MessageQueueId_t destId, bool clearCmdMsg = true);
|
||||
ReturnValue_t clearLastSentMessage(bool clearCmdMsg = true);
|
||||
void clearMessages(bool clearCmdMsg = true);
|
||||
|
||||
private:
|
||||
using SendMap = std::map<MessageQueueId_t, SendInfo>;
|
||||
SendMap sendMap;
|
||||
std::queue<MessageQueueMessage> receivedMsgs;
|
||||
std::pair<bool, ReturnValue_t> nextSendFailsPair;
|
||||
|
||||
void clearEmptyEntries();
|
||||
ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override;
|
||||
static ReturnValue_t clearLastSentMessage(SendMap::iterator& iter, bool clearCmdMsg = true);
|
||||
static void createMsgCopy(MessageQueueMessageIF& into, MessageQueueMessageIF& from);
|
||||
};
|
||||
|
||||
#endif /* FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ */
|
@ -1,84 +0,0 @@
|
||||
#ifndef FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_
|
||||
#define FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_
|
||||
|
||||
#include <cstring>
|
||||
#include <queue>
|
||||
|
||||
#include "CatchDefinitions.h"
|
||||
#include "fsfw/ipc/CommandMessage.h"
|
||||
#include "fsfw/ipc/MessageQueueBase.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
#include "fsfw/ipc/MessageQueueMessage.h"
|
||||
|
||||
class MessageQueueMockBase : public MessageQueueBase {
|
||||
public:
|
||||
MessageQueueMockBase()
|
||||
: MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {}
|
||||
|
||||
uint8_t messageSentCounter = 0;
|
||||
bool messageSent = false;
|
||||
|
||||
bool wasMessageSent(uint8_t* messageSentCounter = nullptr, bool resetCounter = true) {
|
||||
bool tempMessageSent = messageSent;
|
||||
messageSent = false;
|
||||
if (messageSentCounter != nullptr) {
|
||||
*messageSentCounter = this->messageSentCounter;
|
||||
}
|
||||
if (resetCounter) {
|
||||
this->messageSentCounter = 0;
|
||||
}
|
||||
return tempMessageSent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop a message, clearing it in the process.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t popMessage() {
|
||||
CommandMessage message;
|
||||
message.clear();
|
||||
return receiveMessage(&message);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override {
|
||||
if (messagesSentQueue.empty()) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
this->last = message->getSender();
|
||||
std::memcpy(message->getBuffer(), messagesSentQueue.front().getBuffer(),
|
||||
message->getMessageSize());
|
||||
messagesSentQueue.pop();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
virtual ReturnValue_t flush(uint32_t* count) { return HasReturnvaluesIF::RETURN_OK; }
|
||||
virtual ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom,
|
||||
bool ignoreFault = false) override {
|
||||
messageSent = true;
|
||||
messageSentCounter++;
|
||||
MessageQueueMessage& messageRef = *(dynamic_cast<MessageQueueMessage*>(message));
|
||||
messagesSentQueue.push(messageRef);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
virtual ReturnValue_t reply(MessageQueueMessageIF* message) override {
|
||||
return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false);
|
||||
}
|
||||
|
||||
void clearMessages(bool clearCommandMessages = true) {
|
||||
while (not messagesSentQueue.empty()) {
|
||||
if (clearCommandMessages) {
|
||||
CommandMessage message;
|
||||
std::memcpy(message.getBuffer(), messagesSentQueue.front().getBuffer(),
|
||||
message.getMessageSize());
|
||||
message.clear();
|
||||
}
|
||||
messagesSentQueue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::queue<MessageQueueMessage> messagesSentQueue;
|
||||
};
|
||||
|
||||
#endif /* FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ */
|
12
unittests/mocks/PusDistributorMock.cpp
Normal file
12
unittests/mocks/PusDistributorMock.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "PusDistributorMock.h"
|
||||
|
||||
PusDistributorMock::PusDistributorMock() : SystemObject(objects::NO_OBJECT, false) {}
|
||||
|
||||
PusDistributorMock::PusDistributorMock(object_id_t registeredId)
|
||||
: SystemObject(registeredId, true) {}
|
||||
|
||||
ReturnValue_t PusDistributorMock::registerService(AcceptsTelecommandsIF *service) {
|
||||
registerCallCount++;
|
||||
lastServiceArg = service;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
16
unittests/mocks/PusDistributorMock.h
Normal file
16
unittests/mocks/PusDistributorMock.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef FSFW_TESTS_PUSDISTRIBUTORMOCK_H
|
||||
#define FSFW_TESTS_PUSDISTRIBUTORMOCK_H
|
||||
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/tcdistribution/PUSDistributorIF.h"
|
||||
|
||||
class PusDistributorMock : public SystemObject, public PUSDistributorIF {
|
||||
public:
|
||||
PusDistributorMock();
|
||||
explicit PusDistributorMock(object_id_t registeredId);
|
||||
unsigned int registerCallCount = 0;
|
||||
AcceptsTelecommandsIF* lastServiceArg = nullptr;
|
||||
ReturnValue_t registerService(AcceptsTelecommandsIF* service) override;
|
||||
};
|
||||
|
||||
#endif // FSFW_TESTS_PUSDISTRIBUTORMOCK_H
|
53
unittests/mocks/PusServiceBaseMock.cpp
Normal file
53
unittests/mocks/PusServiceBaseMock.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "PusServiceBaseMock.h"
|
||||
|
||||
PsbMock::PsbMock(PsbParams params) : PusServiceBase(params) {}
|
||||
|
||||
ReturnValue_t PsbMock::handleRequest(uint8_t subservice) {
|
||||
handleRequestCallCnt++;
|
||||
subserviceQueue.push(subservice);
|
||||
if (handleReqFailPair.first) {
|
||||
handleReqFailPair.first = false;
|
||||
return handleReqFailPair.second;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PsbMock::performService() {
|
||||
performServiceCallCnt++;
|
||||
if (performServiceFailPair.first) {
|
||||
performServiceFailPair.first = false;
|
||||
return performServiceFailPair.second;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void PsbMock::reset() {
|
||||
handleRequestCallCnt = 0;
|
||||
performServiceCallCnt = 0;
|
||||
std::queue<uint8_t>().swap(subserviceQueue);
|
||||
}
|
||||
|
||||
void PsbMock::makeNextHandleReqCallFail(ReturnValue_t retval) {
|
||||
handleReqFailPair.first = true;
|
||||
handleReqFailPair.second = retval;
|
||||
}
|
||||
bool PsbMock::getAndPopNextSubservice(uint8_t& subservice) {
|
||||
if (subserviceQueue.empty()) {
|
||||
return false;
|
||||
}
|
||||
subservice = subserviceQueue.front();
|
||||
subserviceQueue.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
PsbParams& PsbMock::getParams() { return psbParams; }
|
||||
|
||||
void PsbMock::setStaticPusDistributor(object_id_t pusDistributor) {
|
||||
PUS_DISTRIBUTOR = pusDistributor;
|
||||
}
|
||||
|
||||
object_id_t PsbMock::getStaticPusDistributor() { return PUS_DISTRIBUTOR; }
|
||||
|
||||
void PsbMock::setStaticTmDest(object_id_t tmDest) { PACKET_DESTINATION = tmDest; }
|
||||
|
||||
object_id_t PsbMock::getStaticTmDest() { return PACKET_DESTINATION; }
|
32
unittests/mocks/PusServiceBaseMock.h
Normal file
32
unittests/mocks/PusServiceBaseMock.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef FSFW_TESTS_PUSSERVICEBASEMOCK_H
|
||||
#define FSFW_TESTS_PUSSERVICEBASEMOCK_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "fsfw/tmtcservices/PusServiceBase.h"
|
||||
|
||||
class PsbMock : public PusServiceBase {
|
||||
public:
|
||||
explicit PsbMock(PsbParams params);
|
||||
unsigned int handleRequestCallCnt = 0;
|
||||
std::queue<uint8_t> subserviceQueue;
|
||||
unsigned int performServiceCallCnt = 0;
|
||||
|
||||
static void setStaticPusDistributor(object_id_t pusDistributor);
|
||||
static object_id_t getStaticPusDistributor();
|
||||
static void setStaticTmDest(object_id_t tmDest);
|
||||
static object_id_t getStaticTmDest();
|
||||
|
||||
PsbParams& getParams();
|
||||
|
||||
std::pair<bool, ReturnValue_t> handleReqFailPair;
|
||||
std::pair<bool, ReturnValue_t> performServiceFailPair;
|
||||
ReturnValue_t handleRequest(uint8_t subservice) override;
|
||||
ReturnValue_t performService() override;
|
||||
|
||||
void makeNextHandleReqCallFail(ReturnValue_t retval);
|
||||
bool getAndPopNextSubservice(uint8_t& subservice);
|
||||
void reset();
|
||||
};
|
||||
|
||||
#endif // FSFW_TESTS_PUSSERVICEBASEMOCK_H
|
42
unittests/mocks/PusVerificationReporterMock.cpp
Normal file
42
unittests/mocks/PusVerificationReporterMock.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "PusVerificationReporterMock.h"
|
||||
|
||||
#include "fsfw/objectmanager/frameworkObjects.h"
|
||||
|
||||
PusVerificationReporterMock::PusVerificationReporterMock()
|
||||
: SystemObject(objects::NO_OBJECT, false) {}
|
||||
|
||||
PusVerificationReporterMock::PusVerificationReporterMock(object_id_t registeredId)
|
||||
: SystemObject(registeredId) {}
|
||||
|
||||
size_t PusVerificationReporterMock::successCallCount() const { return successParams.size(); }
|
||||
size_t PusVerificationReporterMock::failCallCount() const { return failParams.size(); }
|
||||
|
||||
VerifSuccessParams& PusVerificationReporterMock::getNextSuccessCallParams() {
|
||||
return successParams.front();
|
||||
}
|
||||
|
||||
void PusVerificationReporterMock::popNextFailParams() {
|
||||
if (not failParams.empty()) {
|
||||
failParams.pop();
|
||||
}
|
||||
}
|
||||
|
||||
VerifFailureParams& PusVerificationReporterMock::getNextFailCallParams() {
|
||||
return failParams.front();
|
||||
}
|
||||
|
||||
void PusVerificationReporterMock::popNextSuccessParams() {
|
||||
if (not successParams.empty()) {
|
||||
successParams.pop();
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PusVerificationReporterMock::sendSuccessReport(VerifSuccessParams params) {
|
||||
successParams.push(params);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PusVerificationReporterMock::sendFailureReport(VerifFailureParams params) {
|
||||
failParams.push(params);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
25
unittests/mocks/PusVerificationReporterMock.h
Normal file
25
unittests/mocks/PusVerificationReporterMock.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef FSFW_TESTS_PUSVERIFICATIONREPORTERMOCK_H
|
||||
#define FSFW_TESTS_PUSVERIFICATIONREPORTERMOCK_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/tmtcservices/VerificationReporterIF.h"
|
||||
|
||||
class PusVerificationReporterMock : public SystemObject, public VerificationReporterIF {
|
||||
public:
|
||||
std::queue<VerifSuccessParams> successParams;
|
||||
std::queue<VerifFailureParams> failParams;
|
||||
PusVerificationReporterMock();
|
||||
explicit PusVerificationReporterMock(object_id_t registeredId);
|
||||
[[nodiscard]] size_t successCallCount() const;
|
||||
VerifSuccessParams& getNextSuccessCallParams();
|
||||
void popNextSuccessParams();
|
||||
[[nodiscard]] size_t failCallCount() const;
|
||||
VerifFailureParams& getNextFailCallParams();
|
||||
void popNextFailParams();
|
||||
|
||||
ReturnValue_t sendSuccessReport(VerifSuccessParams params) override;
|
||||
ReturnValue_t sendFailureReport(VerifFailureParams params) override;
|
||||
};
|
||||
#endif // FSFW_TESTS_PUSVERIFICATIONREPORTERMOCK_H
|
@ -1,8 +1,8 @@
|
||||
#ifndef FSFW_TESTS_SIMPLESERIALIZABLE_H
|
||||
#define FSFW_TESTS_SIMPLESERIALIZABLE_H
|
||||
|
||||
#include "fsfw/serialize.h"
|
||||
#include "fsfw/osal/Endiness.h"
|
||||
#include "fsfw/serialize.h"
|
||||
|
||||
class SimpleSerializable : public SerializeIF {
|
||||
public:
|
||||
|
@ -1,5 +1,5 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
TestMessageQueue.cpp
|
||||
testMq.cpp
|
||||
TestSemaphore.cpp
|
||||
TestClock.cpp
|
||||
)
|
||||
|
@ -19,7 +19,7 @@ TEST_CASE("Binary Semaphore Test" , "[BinSemaphore]") {
|
||||
REQUIRE(binSemaph->release() ==
|
||||
static_cast<int>(SemaphoreIF::SEMAPHORE_NOT_OWNED));
|
||||
REQUIRE(binSemaph->acquire(SemaphoreIF::POLLING) ==
|
||||
retval::CATCH_OK);
|
||||
result::OK);
|
||||
{
|
||||
// not precise enough on linux.. should use clock instead..
|
||||
//Stopwatch stopwatch(false);
|
||||
@ -29,7 +29,7 @@ TEST_CASE("Binary Semaphore Test" , "[BinSemaphore]") {
|
||||
//CHECK(time == 5);
|
||||
}
|
||||
REQUIRE(binSemaph->getSemaphoreCounter() == 0);
|
||||
REQUIRE(binSemaph->release() == retval::CATCH_OK);
|
||||
REQUIRE(binSemaph->release() == result::OK);
|
||||
}
|
||||
SemaphoreFactory::instance()->deleteSemaphore(binSemaph);
|
||||
// perform tear-down here
|
||||
|
@ -19,17 +19,17 @@ TEST_CASE("MessageQueue Basic Test", "[TestMq]") {
|
||||
|
||||
SECTION("Simple Tests") {
|
||||
auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
MessageQueueMessage recvMessage;
|
||||
result = testReceiverMq->receiveMessage(&recvMessage);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(recvMessage.getData()[0] == 42);
|
||||
|
||||
result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
MessageQueueId_t senderId = 0;
|
||||
result = testReceiverMq->receiveMessage(&recvMessage, &senderId);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(recvMessage.getData()[0] == 42);
|
||||
CHECK(senderId == testSenderMqId);
|
||||
senderId = testReceiverMq->getLastPartner();
|
||||
@ -37,7 +37,7 @@ TEST_CASE("MessageQueue Basic Test", "[TestMq]") {
|
||||
}
|
||||
SECTION("Test Full") {
|
||||
auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
||||
REQUIRE(result == MessageQueueIF::FULL);
|
||||
// We try another message
|
||||
@ -45,12 +45,12 @@ TEST_CASE("MessageQueue Basic Test", "[TestMq]") {
|
||||
REQUIRE(result == MessageQueueIF::FULL);
|
||||
MessageQueueMessage recvMessage;
|
||||
result = testReceiverMq->receiveMessage(&recvMessage);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(recvMessage.getData()[0] == 42);
|
||||
result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
result = testReceiverMq->receiveMessage(&recvMessage);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(recvMessage.getData()[0] == 42);
|
||||
}
|
||||
// We have to clear MQs ourself ATM
|
@ -102,7 +102,7 @@ TEST_CASE("Serial Buffer Adapter", "[single-file]") {
|
||||
size_t size = 6;
|
||||
auto result = tv_serial_buffer_adapter3.deSerialize(const_cast<const uint8_t**>(&arrayPtr),
|
||||
&size, SerializeIF::Endianness::MACHINE);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(test_recv_array[0] == 1);
|
||||
CHECK(test_recv_array[1] == 1);
|
||||
CHECK(test_recv_array[2] == 1);
|
||||
|
@ -40,7 +40,7 @@ TEST_CASE("Serial Linked Packet", "[SerLinkPacket]") {
|
||||
// Deserialize big endian packet by setting bigEndian to true.
|
||||
ReturnValue_t result =
|
||||
testClass.deSerialize(&readOnlyPointer, &packetLen, SerializeIF::Endianness::BIG);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(testClass.getHeader() == 42);
|
||||
// Equivalent check.
|
||||
// CHECK(testClass.getBuffer()[0] == 1);
|
||||
@ -59,7 +59,7 @@ TEST_CASE("Serial Linked Packet", "[SerLinkPacket]") {
|
||||
// serialize for ground: bigEndian = true.
|
||||
ReturnValue_t result = testClass.serialize(&packetPointer, &serializedSize, packetMaxSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
// Result should be big endian now.
|
||||
CHECK(packet[3] == 42);
|
||||
CHECK(packet[4] == 1);
|
||||
|
@ -1,4 +1,4 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
TestNewAccessor.cpp
|
||||
TestPool.cpp
|
||||
testAccessor.cpp
|
||||
testPool.cpp
|
||||
)
|
||||
|
@ -6,13 +6,13 @@
|
||||
|
||||
#include "CatchDefinitions.h"
|
||||
|
||||
TEST_CASE("New Accessor", "[NewAccessor]") {
|
||||
TEST_CASE("Pool Accessor", "[pool-accessor]") {
|
||||
LocalPool::LocalPoolConfig poolCfg = {{1, 10}};
|
||||
LocalPool SimplePool = LocalPool(0, poolCfg);
|
||||
std::array<uint8_t, 20> testDataArray;
|
||||
std::array<uint8_t, 20> receptionArray;
|
||||
std::array<uint8_t, 20> testDataArray{};
|
||||
std::array<uint8_t, 20> receptionArray{};
|
||||
store_address_t testStoreId;
|
||||
ReturnValue_t result = retval::CATCH_FAILED;
|
||||
ReturnValue_t result = result::FAILED;
|
||||
|
||||
for (size_t i = 0; i < testDataArray.size(); i++) {
|
||||
testDataArray[i] = i;
|
||||
@ -21,9 +21,9 @@ TEST_CASE("New Accessor", "[NewAccessor]") {
|
||||
|
||||
SECTION("Simple tests getter functions") {
|
||||
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
auto resultPair = SimplePool.getData(testStoreId);
|
||||
REQUIRE(resultPair.first == retval::CATCH_OK);
|
||||
REQUIRE(resultPair.first == result::OK);
|
||||
resultPair.second.getDataCopy(receptionArray.data(), 20);
|
||||
CHECK(resultPair.second.getId() == testStoreId);
|
||||
CHECK(resultPair.second.size() == 10);
|
||||
@ -39,18 +39,18 @@ TEST_CASE("New Accessor", "[NewAccessor]") {
|
||||
|
||||
{
|
||||
auto resultPairLoc = SimplePool.getData(testStoreId);
|
||||
REQUIRE(resultPairLoc.first == retval::CATCH_OK);
|
||||
REQUIRE(resultPairLoc.first == result::OK);
|
||||
// data should be deleted when accessor goes out of scope.
|
||||
}
|
||||
resultPair = SimplePool.getData(testStoreId);
|
||||
REQUIRE(resultPair.first == (int)StorageManagerIF::DATA_DOES_NOT_EXIST);
|
||||
|
||||
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
{
|
||||
ConstStorageAccessor constAccessor(testStoreId);
|
||||
result = SimplePool.getData(testStoreId, constAccessor);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
constAccessor.getDataCopy(receptionArray.data(), 20);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
CHECK(receptionArray[i] == i);
|
||||
@ -63,12 +63,12 @@ TEST_CASE("New Accessor", "[NewAccessor]") {
|
||||
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
{
|
||||
resultPair = SimplePool.getData(testStoreId);
|
||||
REQUIRE(resultPair.first == retval::CATCH_OK);
|
||||
REQUIRE(resultPair.first == result::OK);
|
||||
resultPair.second.release();
|
||||
// now data should not be deleted anymore
|
||||
}
|
||||
resultPair = SimplePool.getData(testStoreId);
|
||||
REQUIRE(resultPair.first == retval::CATCH_OK);
|
||||
REQUIRE(resultPair.first == result::OK);
|
||||
resultPair.second.getDataCopy(receptionArray.data(), 20);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
CHECK(receptionArray[i] == i);
|
||||
@ -77,11 +77,11 @@ TEST_CASE("New Accessor", "[NewAccessor]") {
|
||||
|
||||
SECTION("Simple tests modify functions") {
|
||||
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
{
|
||||
StorageAccessor accessor(testStoreId);
|
||||
result = SimplePool.modifyData(testStoreId, accessor);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(accessor.getId() == testStoreId);
|
||||
CHECK(accessor.size() == 10);
|
||||
accessor.getDataCopy(receptionArray.data(), 20);
|
||||
@ -98,10 +98,10 @@ TEST_CASE("New Accessor", "[NewAccessor]") {
|
||||
REQUIRE(resultPair.first == (int)StorageManagerIF::DATA_DOES_NOT_EXIST);
|
||||
|
||||
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
{
|
||||
auto resultPairLoc = SimplePool.modifyData(testStoreId);
|
||||
REQUIRE(resultPairLoc.first == retval::CATCH_OK);
|
||||
REQUIRE(resultPairLoc.first == result::OK);
|
||||
CHECK(resultPairLoc.second.getId() == testStoreId);
|
||||
CHECK(resultPairLoc.second.size() == 10);
|
||||
resultPairLoc.second.getDataCopy(receptionArray.data(), 20);
|
||||
@ -117,22 +117,22 @@ TEST_CASE("New Accessor", "[NewAccessor]") {
|
||||
// data should not be deleted when accessor goes out of scope
|
||||
}
|
||||
resultPair = SimplePool.getData(testStoreId);
|
||||
REQUIRE(resultPair.first == retval::CATCH_OK);
|
||||
REQUIRE(resultPair.first == result::OK);
|
||||
}
|
||||
|
||||
SECTION("Write tests") {
|
||||
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
{
|
||||
auto resultPair = SimplePool.modifyData(testStoreId);
|
||||
REQUIRE(resultPair.first == retval::CATCH_OK);
|
||||
REQUIRE(resultPair.first == result::OK);
|
||||
testDataArray[9] = 42;
|
||||
resultPair.second.write(testDataArray.data(), 10, 0);
|
||||
// now data should not be deleted
|
||||
resultPair.second.release();
|
||||
}
|
||||
auto resultConstPair = SimplePool.getData(testStoreId);
|
||||
REQUIRE(resultConstPair.first == retval::CATCH_OK);
|
||||
REQUIRE(resultConstPair.first == result::OK);
|
||||
|
||||
resultConstPair.second.getDataCopy(receptionArray.data(), 10);
|
||||
for (size_t i = 0; i < size - 1; i++) {
|
||||
@ -141,15 +141,15 @@ TEST_CASE("New Accessor", "[NewAccessor]") {
|
||||
CHECK(receptionArray[9] == 42);
|
||||
|
||||
auto resultPair = SimplePool.modifyData(testStoreId);
|
||||
REQUIRE(resultPair.first == retval::CATCH_OK);
|
||||
REQUIRE(resultPair.first == result::OK);
|
||||
result = resultPair.second.write(testDataArray.data(), 20, 0);
|
||||
REQUIRE(result == retval::CATCH_FAILED);
|
||||
REQUIRE(result == result::FAILED);
|
||||
result = resultPair.second.write(testDataArray.data(), 10, 5);
|
||||
REQUIRE(result == retval::CATCH_FAILED);
|
||||
REQUIRE(result == result::FAILED);
|
||||
|
||||
std::memset(testDataArray.data(), 42, 5);
|
||||
result = resultPair.second.write(testDataArray.data(), 5, 5);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
resultConstPair = SimplePool.getData(testStoreId);
|
||||
resultPair.second.getDataCopy(receptionArray.data(), 20);
|
||||
for (size_t i = 5; i < 10; i++) {
|
||||
@ -159,10 +159,10 @@ TEST_CASE("New Accessor", "[NewAccessor]") {
|
||||
|
||||
SECTION("Operators") {
|
||||
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
{
|
||||
StorageAccessor accessor(testStoreId);
|
||||
StorageAccessor accessor2(0);
|
||||
StorageAccessor accessor2(store_address_t::invalid());
|
||||
accessor2 = std::move(accessor);
|
||||
REQUIRE(accessor.data() == nullptr);
|
||||
std::array<uint8_t, 6> data;
|
@ -10,10 +10,10 @@
|
||||
TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") {
|
||||
LocalPool::LocalPoolConfig config = {{1, 10}};
|
||||
LocalPool simplePool(0, config);
|
||||
std::array<uint8_t, 20> testDataArray;
|
||||
std::array<uint8_t, 20> receptionArray;
|
||||
std::array<uint8_t, 20> testDataArray{};
|
||||
std::array<uint8_t, 20> receptionArray{};
|
||||
store_address_t testStoreId;
|
||||
ReturnValue_t result = retval::CATCH_FAILED;
|
||||
ReturnValue_t result;
|
||||
uint8_t* pointer = nullptr;
|
||||
const uint8_t* constPointer = nullptr;
|
||||
|
||||
@ -23,10 +23,12 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") {
|
||||
size_t size = 10;
|
||||
|
||||
SECTION("Basic tests") {
|
||||
REQUIRE(not simplePool.hasDataAtId(testStoreId));
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
REQUIRE(simplePool.hasDataAtId(testStoreId));
|
||||
result = simplePool.getData(testStoreId, &constPointer, &size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
memcpy(receptionArray.data(), constPointer, size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
CHECK(receptionArray[i] == i);
|
||||
@ -34,12 +36,13 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") {
|
||||
memset(receptionArray.data(), 0, size);
|
||||
result = simplePool.modifyData(testStoreId, &pointer, &size);
|
||||
memcpy(receptionArray.data(), pointer, size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
CHECK(receptionArray[i] == i);
|
||||
}
|
||||
result = simplePool.deleteData(testStoreId);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
REQUIRE(not simplePool.hasDataAtId(testStoreId));
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), 15);
|
||||
CHECK(result == (int)StorageManagerIF::DATA_TOO_LARGE);
|
||||
}
|
||||
@ -47,12 +50,12 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") {
|
||||
SECTION("Reservation Tests ") {
|
||||
pointer = nullptr;
|
||||
result = simplePool.getFreeElement(&testStoreId, size, &pointer);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
memcpy(pointer, testDataArray.data(), size);
|
||||
constPointer = nullptr;
|
||||
result = simplePool.getData(testStoreId, &constPointer, &size);
|
||||
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
memcpy(receptionArray.data(), constPointer, size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
CHECK(receptionArray[i] == i);
|
||||
@ -61,21 +64,21 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") {
|
||||
|
||||
SECTION("Add, delete, add, add when full") {
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
result = simplePool.getData(testStoreId, &constPointer, &size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
memcpy(receptionArray.data(), constPointer, size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
CHECK(receptionArray[i] == i);
|
||||
}
|
||||
|
||||
result = simplePool.deleteData(testStoreId);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
result = simplePool.getData(testStoreId, &constPointer, &size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
memcpy(receptionArray.data(), constPointer, size);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
CHECK(receptionArray[i] == i);
|
||||
@ -102,20 +105,20 @@ TEST_CASE("Local Pool Simple Tests [1 Pool]", "[TestPool]") {
|
||||
|
||||
SECTION("Initialize and clear store, delete with pointer") {
|
||||
result = simplePool.initialize();
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
simplePool.clearStore();
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
result = simplePool.modifyData(testStoreId, &pointer, &size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
store_address_t newId;
|
||||
result = simplePool.deleteData(pointer, size, &testStoreId);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
REQUIRE(testStoreId.raw != (uint32_t)StorageManagerIF::INVALID_ADDRESS);
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,10 +141,10 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") {
|
||||
runIdx++;
|
||||
|
||||
LocalPool simplePool(0, *config);
|
||||
std::array<uint8_t, 20> testDataArray;
|
||||
std::array<uint8_t, 20> receptionArray;
|
||||
std::array<uint8_t, 20> testDataArray{};
|
||||
std::array<uint8_t, 20> receptionArray{};
|
||||
store_address_t testStoreId;
|
||||
ReturnValue_t result = retval::CATCH_FAILED;
|
||||
ReturnValue_t result = result::FAILED;
|
||||
for (size_t i = 0; i < testDataArray.size(); i++) {
|
||||
testDataArray[i] = i;
|
||||
}
|
||||
@ -150,20 +153,20 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") {
|
||||
SECTION("Basic tests") {
|
||||
size = 8;
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
// Should be on second page of the pool now for 8 bytes
|
||||
CHECK(testStoreId.poolIndex == 1);
|
||||
CHECK(testStoreId.packetIndex == 0);
|
||||
|
||||
size = 15;
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
// Should be on third page of the pool now for 15 bytes
|
||||
CHECK(testStoreId.poolIndex == 2);
|
||||
CHECK(testStoreId.packetIndex == 0);
|
||||
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
// Should be on third page of the pool now for 15 bytes
|
||||
CHECK(testStoreId.poolIndex == 2);
|
||||
CHECK(testStoreId.packetIndex == 1);
|
||||
@ -174,7 +177,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") {
|
||||
|
||||
size = 8;
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
// Should still work
|
||||
CHECK(testStoreId.poolIndex == 1);
|
||||
CHECK(testStoreId.packetIndex == 1);
|
||||
@ -182,7 +185,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") {
|
||||
// fill the rest of the pool
|
||||
for (uint8_t idx = 2; idx < 5; idx++) {
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(testStoreId.poolIndex == 1);
|
||||
CHECK(testStoreId.packetIndex == idx);
|
||||
}
|
||||
@ -203,21 +206,21 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") {
|
||||
size = 5;
|
||||
for (uint8_t idx = 0; idx < 10; idx++) {
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(testStoreId.poolIndex == 0);
|
||||
CHECK(testStoreId.packetIndex == idx);
|
||||
}
|
||||
size = 10;
|
||||
for (uint8_t idx = 0; idx < 5; idx++) {
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(testStoreId.poolIndex == 1);
|
||||
CHECK(testStoreId.packetIndex == idx);
|
||||
}
|
||||
size = 20;
|
||||
for (uint8_t idx = 0; idx < 2; idx++) {
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(testStoreId.poolIndex == 2);
|
||||
CHECK(testStoreId.packetIndex == idx);
|
||||
}
|
||||
@ -244,7 +247,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") {
|
||||
size = 5;
|
||||
for (uint8_t idx = 0; idx < 10; idx++) {
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(testStoreId.poolIndex == 0);
|
||||
CHECK(testStoreId.packetIndex == idx);
|
||||
}
|
||||
@ -261,7 +264,7 @@ TEST_CASE("Local Pool Extended Tests [3 Pools]", "[TestPool2]") {
|
||||
size = 10;
|
||||
for (uint8_t idx = 0; idx < 5; idx++) {
|
||||
result = simplePool.addData(&testStoreId, testDataArray.data(), size);
|
||||
REQUIRE(result == retval::CATCH_OK);
|
||||
REQUIRE(result == result::OK);
|
||||
CHECK(testStoreId.poolIndex == 1);
|
||||
CHECK(testStoreId.packetIndex == idx);
|
||||
}
|
@ -31,4 +31,4 @@ enum sourceObjects : uint32_t {
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* BSP_CONFIG_OBJECTS_SYSTEMOBJECTLIST_H_ */
|
||||
#endif /* HOSTED_CONFIG_OBJECTS_SYSTEMOBJECTLIST_H_ */
|
||||
|
@ -1,3 +1,10 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
testCcsds.cpp
|
||||
testCcsdsCreator.cpp
|
||||
testCcsdsReader.cpp
|
||||
testPusTcCreator.cpp
|
||||
testPusTcReader.cpp
|
||||
testPusTmCreator.cpp
|
||||
testPusTmReader.cpp
|
||||
testCcsds.cpp
|
||||
testZcTmWriter.cpp
|
||||
)
|
||||
|
@ -1 +0,0 @@
|
||||
|
@ -1,11 +1,134 @@
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <cmath>
|
||||
|
||||
#include "fsfw/tmtcpacket/SpacePacket.h"
|
||||
#include "fsfw/tmtcpacket/ccsds/PacketId.h"
|
||||
#include "fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h"
|
||||
#include "fsfw/tmtcpacket/ccsds/header.h"
|
||||
|
||||
TEST_CASE("CCSDS Test", "[ccsds]") {
|
||||
REQUIRE(spacepacket::getTcSpacePacketIdFromApid(0x22) == 0x1822);
|
||||
REQUIRE(spacepacket::getTmSpacePacketIdFromApid(0x22) == 0x0822);
|
||||
TEST_CASE("CCSDS Low Level", "[ccsds-ll]") {
|
||||
SECTION("Lowlevel Header Packet ID test") {
|
||||
ccsds::PrimaryHeader header{};
|
||||
uint16_t packetIdRaw = 0x3ff;
|
||||
ccsds::setPacketId(header, packetIdRaw);
|
||||
REQUIRE(header.packetIdHAndVersion == 3);
|
||||
REQUIRE(header.packetIdL == 0xff);
|
||||
REQUIRE(ccsds::getPacketId(header) == 0x3ff);
|
||||
header.packetIdHAndVersion |= 0b00100000;
|
||||
REQUIRE(ccsds::getPacketId(header) == 0x3ff);
|
||||
REQUIRE(ccsds::getVersion(header) == 0b001);
|
||||
}
|
||||
|
||||
REQUIRE(spacepacket::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff);
|
||||
REQUIRE(spacepacket::getTmSpacePacketIdFromApid(0x7ff) == 0xfff);
|
||||
SECTION("Lowlevel Header APID Test") {
|
||||
ccsds::PrimaryHeader header{};
|
||||
uint16_t packetIdRaw = 0x3ff;
|
||||
ccsds::setPacketId(header, packetIdRaw);
|
||||
ccsds::setApid(header, 0x1ff);
|
||||
REQUIRE(ccsds::getPacketId(header) == 0x3ff);
|
||||
}
|
||||
|
||||
SECTION("Lowlevel Packet Length Test") {
|
||||
ccsds::PrimaryHeader header{};
|
||||
header.packetLenH = 0x02;
|
||||
header.packetLenL = 0x03;
|
||||
REQUIRE(ccsds::getPacketLen(header) == 0x0203);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") {
|
||||
PacketId packetId;
|
||||
std::array<uint8_t, 3> buf{};
|
||||
SECTION("Basic") {
|
||||
packetId.apid = 0x1ff;
|
||||
packetId.secHeaderFlag = false;
|
||||
packetId.packetType = ccsds::PacketType::TM;
|
||||
size_t serLen = 0;
|
||||
REQUIRE(packetId.raw() == 0x1ff);
|
||||
REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), serLen, buf.size()) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
CHECK(buf[0] == 0x1);
|
||||
CHECK(buf[1] == 0xff);
|
||||
}
|
||||
|
||||
SECTION("Invalid Ser") {
|
||||
size_t serLen = 0;
|
||||
REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), serLen, 0) ==
|
||||
SerializeIF::BUFFER_TOO_SHORT);
|
||||
REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), serLen, 1) ==
|
||||
SerializeIF::BUFFER_TOO_SHORT);
|
||||
}
|
||||
|
||||
SECTION("Invalid Deser") {
|
||||
size_t deserLen = 0;
|
||||
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, 1) ==
|
||||
SerializeIF::STREAM_TOO_SHORT);
|
||||
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, 0) ==
|
||||
SerializeIF::STREAM_TOO_SHORT);
|
||||
}
|
||||
|
||||
SECTION("From Raw") {
|
||||
auto newId = PacketId(ccsds::PacketType::TC, true, 0x2ff);
|
||||
uint16_t rawId = newId.raw();
|
||||
CHECK(rawId == 0x1aff);
|
||||
CHECK(PacketId::fromRaw(rawId) == newId);
|
||||
}
|
||||
|
||||
SECTION("Deserialize") {
|
||||
buf[0] = 0x1a;
|
||||
buf[1] = 0xff;
|
||||
size_t deserLen = 0xff;
|
||||
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
CHECK(packetId.apid == 0x2ff);
|
||||
CHECK(deserLen == 2);
|
||||
CHECK(packetId.packetType == ccsds::PacketType::TC);
|
||||
CHECK(packetId.secHeaderFlag == true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {
|
||||
PacketSeqCtrl psc;
|
||||
std::array<uint8_t, 3> buf{};
|
||||
SECTION("Basic") {
|
||||
size_t serLen = 0xff;
|
||||
psc.seqFlags = ccsds::SequenceFlags::FIRST_SEGMENT;
|
||||
psc.seqCount = static_cast<uint16_t>(std::round(std::pow(2, 14) - 1));
|
||||
REQUIRE(psc.raw() == 0x7fff);
|
||||
REQUIRE(psc.SerializeIF::serializeBe(buf.data(), serLen, buf.size()) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
CHECK(buf[0] == 0x7f);
|
||||
CHECK(buf[1] == 0xff);
|
||||
CHECK(serLen == 2);
|
||||
}
|
||||
|
||||
SECTION("From Raw") {
|
||||
auto newId = PacketSeqCtrl(ccsds::SequenceFlags::LAST_SEGMENT,
|
||||
static_cast<uint16_t>(std::round(std::pow(2, 14) - 2)));
|
||||
uint16_t rawId = newId.raw();
|
||||
REQUIRE(rawId == 0xbffe);
|
||||
CHECK(PacketSeqCtrl::fromRaw(rawId) == newId);
|
||||
}
|
||||
|
||||
SECTION("Deserialize") {
|
||||
buf[0] = 0xbf;
|
||||
buf[1] = 0xfe;
|
||||
size_t deserLen = 0xff;
|
||||
REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
CHECK(psc.seqFlags == ccsds::SequenceFlags::LAST_SEGMENT);
|
||||
CHECK(deserLen == 2);
|
||||
CHECK(psc.seqCount == static_cast<uint16_t>(std::round(std::pow(2, 14) - 2)));
|
||||
}
|
||||
|
||||
SECTION("Invalid Ser") {
|
||||
size_t deserLen = 0;
|
||||
REQUIRE(psc.SerializeIF::serializeBe(buf.data(), deserLen, 0) == SerializeIF::BUFFER_TOO_SHORT);
|
||||
REQUIRE(psc.SerializeIF::serializeBe(buf.data(), deserLen, 1) == SerializeIF::BUFFER_TOO_SHORT);
|
||||
}
|
||||
|
||||
SECTION("Invalid Deser") {
|
||||
size_t deserLen = 0;
|
||||
REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, 1) == SerializeIF::STREAM_TOO_SHORT);
|
||||
REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, 0) == SerializeIF::STREAM_TOO_SHORT);
|
||||
}
|
||||
}
|
||||
|
107
unittests/tmtcpacket/testCcsdsCreator.cpp
Normal file
107
unittests/tmtcpacket/testCcsdsCreator.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <cmath>
|
||||
|
||||
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
|
||||
|
||||
TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
|
||||
auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02);
|
||||
auto psc = PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34);
|
||||
auto params = SpacePacketParams(packetId, psc, 0x16);
|
||||
SpacePacketCreator base = SpacePacketCreator(params);
|
||||
std::array<uint8_t, 6> buf{};
|
||||
uint8_t* bufPtr = buf.data();
|
||||
size_t serLen = 0;
|
||||
|
||||
SECTION("Constexpr Helpers") {
|
||||
REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822);
|
||||
REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822);
|
||||
|
||||
REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff);
|
||||
REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff);
|
||||
}
|
||||
|
||||
SECTION("Basic Test") {
|
||||
CHECK(base.isValid());
|
||||
CHECK(base);
|
||||
CHECK(base.getApid() == 0x02);
|
||||
CHECK(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT);
|
||||
CHECK(base.getVersion() == 0b000);
|
||||
CHECK(base.getSequenceCount() == 0x34);
|
||||
CHECK(base.getPacketDataLen() == 0x16);
|
||||
CHECK(base.getPacketType() == ccsds::PacketType::TC);
|
||||
CHECK(base.getPacketIdRaw() == 0x1802);
|
||||
CHECK(base.getSerializedSize() == 6);
|
||||
CHECK(base.getPacketSeqCtrl() == psc);
|
||||
CHECK(base.getPacketId() == packetId);
|
||||
}
|
||||
|
||||
SECTION("Deserialization Fails") {
|
||||
serLen = 6;
|
||||
const uint8_t* readOnlyPtr = buf.data();
|
||||
REQUIRE(base.deSerialize(&readOnlyPtr, &serLen, SerializeIF::Endianness::BIG) ==
|
||||
HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
|
||||
SECTION("Raw Output") {
|
||||
REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
// TC, and secondary header flag is set -> 0b0001100 -> 0x18
|
||||
CHECK(buf[0] == 0x18);
|
||||
// APID 0x02
|
||||
CHECK(buf[1] == 0x02);
|
||||
// Sequence count is one byte value, so the only set bit here is the bit
|
||||
// from the Sequence flag argument, which is the second bit for
|
||||
// SequenceFlags.FIRST_SEGMENT
|
||||
CHECK(buf[2] == 0x40);
|
||||
// Sequence Count specified above
|
||||
CHECK(buf[3] == 0x34);
|
||||
// This byte and the next byte should be 22 big endian (packet length)
|
||||
CHECK(buf[4] == 0x00);
|
||||
CHECK(buf[5] == 0x16);
|
||||
}
|
||||
|
||||
SECTION("All Ones Output") {
|
||||
base.setApid(static_cast<int>(std::pow(2, 11)) - 1);
|
||||
base.setSeqCount(static_cast<int>(std::pow(2, 14)) - 1);
|
||||
base.setSeqFlags(ccsds::SequenceFlags::UNSEGMENTED);
|
||||
base.setDataLen(static_cast<int>(std::pow(2, 16)) - 1);
|
||||
REQUIRE(base.isValid());
|
||||
REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
CHECK(buf[0] == 0x1F);
|
||||
CHECK(buf[1] == 0xFF);
|
||||
CHECK(buf[2] == 0xFF);
|
||||
CHECK(buf[3] == 0xFF);
|
||||
CHECK(buf[4] == 0xFF);
|
||||
CHECK(buf[5] == 0xFF);
|
||||
}
|
||||
|
||||
SECTION("Invalid APID") {
|
||||
SpacePacketCreator creator = SpacePacketCreator(
|
||||
ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16);
|
||||
REQUIRE(not creator.isValid());
|
||||
REQUIRE(not creator);
|
||||
REQUIRE(creator.serializeBe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
|
||||
SECTION("Invalid Seq Count") {
|
||||
SpacePacketCreator invalid = SpacePacketCreator(
|
||||
ccsds::PacketType::TC, true, 0x02, ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF, 0x16);
|
||||
REQUIRE(not invalid.isValid());
|
||||
REQUIRE(invalid.serializeBe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
|
||||
SECTION("Invalid Buf Size 1") {
|
||||
serLen = 2;
|
||||
REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT);
|
||||
}
|
||||
|
||||
SECTION("Invalid Buf Size 2") {
|
||||
serLen = 4;
|
||||
REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT);
|
||||
}
|
||||
|
||||
SECTION("Invalid Buf Size 3") {
|
||||
serLen = 6;
|
||||
REQUIRE(base.serializeBe(&bufPtr, &serLen, buf.size()) == SerializeIF::BUFFER_TOO_SHORT);
|
||||
}
|
||||
}
|
71
unittests/tmtcpacket/testCcsdsReader.cpp
Normal file
71
unittests/tmtcpacket/testCcsdsReader.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
|
||||
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
|
||||
|
||||
#define FULL_PACKET_LEN 29
|
||||
|
||||
TEST_CASE("CCSDS Reader", "[ccsds-reader]") {
|
||||
auto params = SpacePacketParams(PacketId(ccsds::PacketType::TC, true, 0x02),
|
||||
PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16);
|
||||
SpacePacketCreator base = SpacePacketCreator(params);
|
||||
// This is enough to hold 0x16 (22) bytes + 6 (SP header length) + 1 as defined as the full packet
|
||||
// length derived from the length field
|
||||
std::array<uint8_t, FULL_PACKET_LEN> buf{};
|
||||
uint8_t* bufPtr = buf.data();
|
||||
size_t serLen = 0;
|
||||
SpacePacketReader reader;
|
||||
|
||||
auto checkReader = [&](SpacePacketReader& reader) {
|
||||
REQUIRE(reader.getPacketDataLen() == 0x16);
|
||||
REQUIRE(reader.getBufSize() == SpacePacketIF::getHeaderLen());
|
||||
REQUIRE(reader.getFullData() == buf.data());
|
||||
REQUIRE(reader.getFullPacketLen() == 0x16 + SpacePacketReader::getHeaderLen() + 1);
|
||||
REQUIRE(reader.getPacketIdRaw() == 0x1802);
|
||||
REQUIRE(reader.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT);
|
||||
REQUIRE(reader.getSequenceCount() == 0x34);
|
||||
REQUIRE(reader.getPacketSeqCtrlRaw() == 0x4034);
|
||||
REQUIRE(reader.hasSecHeader());
|
||||
REQUIRE(reader.getApid() == 0x02);
|
||||
REQUIRE(not reader.isNull());
|
||||
// We only serialized the 6 bytes of the header, so the packer data should be invalid
|
||||
REQUIRE(reader.getPacketData() == nullptr);
|
||||
};
|
||||
|
||||
SECTION("Empty Reader") {
|
||||
REQUIRE(SpacePacketIF::getHeaderLen() == 6);
|
||||
REQUIRE(reader.isNull());
|
||||
REQUIRE(reader.checkSize() == HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
|
||||
SECTION("Basic Read") {
|
||||
REQUIRE(base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
SECTION("Setter") {
|
||||
reader.setReadOnlyData(buf.data(), SpacePacketIF::getHeaderLen());
|
||||
checkReader(reader);
|
||||
}
|
||||
SECTION("Direct Construction") {
|
||||
SpacePacketReader secondReader(buf.data(), serLen);
|
||||
checkReader(secondReader);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Read with additional data") {
|
||||
REQUIRE(base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.getBufSize() == buf.size());
|
||||
REQUIRE(reader.getFullPacketLen() == FULL_PACKET_LEN);
|
||||
REQUIRE(reader.getPacketData() == buf.data() + SpacePacketIF::getHeaderLen());
|
||||
}
|
||||
|
||||
SECTION("Invalid Size") {
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), i) == SerializeIF::STREAM_TOO_SHORT);
|
||||
REQUIRE(not reader.isNull());
|
||||
REQUIRE(reader.getPacketData() == nullptr);
|
||||
}
|
||||
}
|
||||
}
|
132
unittests/tmtcpacket/testPusTcCreator.cpp
Normal file
132
unittests/tmtcpacket/testPusTcCreator.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/globalfunctions/CRC.h"
|
||||
#include "fsfw/tmtcpacket/pus/tc.h"
|
||||
#include "mocks/SimpleSerializable.h"
|
||||
|
||||
TEST_CASE("PUS TC Creator", "[pus-tc-creator]") {
|
||||
auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02);
|
||||
auto spParams =
|
||||
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 0x34), 0x00);
|
||||
auto pusParams = PusTcParams(17, 1);
|
||||
PusTcCreator creator(spParams, pusParams);
|
||||
std::array<uint8_t, 32> buf{};
|
||||
uint8_t* dataPtr = buf.data();
|
||||
size_t serLen = 0;
|
||||
|
||||
SECTION("State") {
|
||||
CHECK(creator.isTc());
|
||||
CHECK(creator.hasSecHeader());
|
||||
CHECK(creator.getService() == 17);
|
||||
CHECK(creator.getSubService() == 1);
|
||||
CHECK(creator.getApid() == 0x02);
|
||||
CHECK(creator.getPusVersion() == 2);
|
||||
CHECK(creator.getAcknowledgeFlags() == 0b1111);
|
||||
CHECK(creator.getSourceId() == 0x00);
|
||||
CHECK(creator.getPacketSeqCtrlRaw() == 0xc034);
|
||||
// bytes CCSDS header, 5 bytes secondary header, 2 bytes CRC, 3 bytes app data
|
||||
CHECK(creator.getFullPacketLen() == 13);
|
||||
// The data length field is the full packet length minus the primary header minus 1
|
||||
CHECK(creator.getPacketDataLen() == 6);
|
||||
auto& paramsLocal = creator.getSpParams();
|
||||
CHECK(paramsLocal.packetId == packetId);
|
||||
}
|
||||
|
||||
SECTION("Serialized") {
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(serLen == 13);
|
||||
REQUIRE(buf[0] == 0x18);
|
||||
REQUIRE(buf[1] == 0x02);
|
||||
// Unsegmented, first 2 bits 11
|
||||
REQUIRE(buf[2] == 0xc0);
|
||||
// Packet Sequence count only occupies lower byte of packet sequence control
|
||||
REQUIRE(buf[3] == 0x34);
|
||||
// Data length packed big endian
|
||||
REQUIRE(buf[4] == 0x00);
|
||||
REQUIRE(buf[5] == 0x06);
|
||||
// PUS Version C (2)
|
||||
REQUIRE(((buf[6] >> 4) & 0b1111) == 2);
|
||||
// All Ack Fields is default
|
||||
REQUIRE((buf[6] & 0b1111) == 0b1111);
|
||||
// Service and subservice
|
||||
REQUIRE(buf[7] == 17);
|
||||
REQUIRE(buf[8] == 1);
|
||||
// Source ID is 0
|
||||
REQUIRE(((buf[9] << 8) | buf[10]) == 0);
|
||||
// CRC16 check
|
||||
REQUIRE(CRC::crc16ccitt(buf.data(), serLen) == 0);
|
||||
REQUIRE(buf[11] == 0xee);
|
||||
REQUIRE(buf[12] == 0x63);
|
||||
}
|
||||
|
||||
SECTION("Custom Source ID") {
|
||||
auto& params = creator.getPusParams();
|
||||
params.sourceId = 0x5ff;
|
||||
REQUIRE(creator.getSourceId() == 0x5ff);
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(((buf[9] << 8) | buf[10]) == 0x5ff);
|
||||
}
|
||||
|
||||
SECTION("Test with Application Data Raw") {
|
||||
auto& params = creator.getPusParams();
|
||||
std::array<uint8_t, 3> data{1, 2, 3};
|
||||
params.dataWrapper.setRawData({data.data(), data.size()});
|
||||
// To get correct size information, the SP length field needs to be updated automatically
|
||||
REQUIRE(creator.getSerializedSize() == 13);
|
||||
creator.updateSpLengthField();
|
||||
REQUIRE(creator.getSerializedSize() == 16);
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(serLen == 16);
|
||||
REQUIRE(buf[11] == 1);
|
||||
REQUIRE(buf[12] == 2);
|
||||
REQUIRE(buf[13] == 3);
|
||||
}
|
||||
|
||||
SECTION("Test with Application Data Serializable") {
|
||||
auto& params = creator.getPusParams();
|
||||
auto simpleSer = SimpleSerializable();
|
||||
creator.setSerializableUserData(simpleSer);
|
||||
REQUIRE(creator.getSerializedSize() == 16);
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(serLen == 16);
|
||||
REQUIRE(buf[11] == 1);
|
||||
REQUIRE(buf[12] == 2);
|
||||
REQUIRE(buf[13] == 3);
|
||||
}
|
||||
|
||||
SECTION("Test with Application Data Serializable Simple Ser API") {
|
||||
auto& params = creator.getPusParams();
|
||||
auto simpleSer = SimpleSerializable();
|
||||
creator.setSerializableUserData(simpleSer);
|
||||
REQUIRE(creator.getSerializedSize() == 16);
|
||||
REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(serLen == 16);
|
||||
REQUIRE(buf[11] == 1);
|
||||
REQUIRE(buf[12] == 2);
|
||||
REQUIRE(buf[13] == 3);
|
||||
}
|
||||
|
||||
SECTION("Deserialization Fails") {
|
||||
SerializeIF& deser = creator;
|
||||
size_t deserLen = buf.size();
|
||||
const uint8_t* roPtr = buf.data();
|
||||
REQUIRE(deser.deSerialize(&roPtr, &deserLen, SerializeIF::Endianness::NETWORK) ==
|
||||
HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
|
||||
SECTION("Serialize with invalid buffer length") {
|
||||
size_t reqSize = creator.getSerializedSize();
|
||||
for (size_t maxSize = 0; maxSize < reqSize; maxSize++) {
|
||||
dataPtr = buf.data();
|
||||
serLen = 0;
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, maxSize) == SerializeIF::BUFFER_TOO_SHORT);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Invalid PUS Version") {
|
||||
auto& params = creator.getPusParams();
|
||||
params.pusVersion = 0;
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == PusIF::INVALID_PUS_VERSION);
|
||||
}
|
||||
}
|
85
unittests/tmtcpacket/testPusTcReader.cpp
Normal file
85
unittests/tmtcpacket/testPusTcReader.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/tmtcpacket/pus/tc/PusTcCreator.h"
|
||||
#include "fsfw/tmtcpacket/pus/tc/PusTcReader.h"
|
||||
|
||||
TEST_CASE("PUS TC Reader", "[pus-tc-reader]") {
|
||||
auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02);
|
||||
auto spParams =
|
||||
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 0x34), 0x00);
|
||||
auto pusParams = PusTcParams(17, 1);
|
||||
PusTcCreator creator(spParams, pusParams);
|
||||
std::array<uint8_t, 32> buf{};
|
||||
uint8_t* dataPtr = buf.data();
|
||||
size_t serLen = 0;
|
||||
PusTcReader reader;
|
||||
|
||||
SECTION("State") {
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.isNull());
|
||||
REQUIRE(not reader);
|
||||
PusTcReader* readerPtr = nullptr;
|
||||
bool callDelete = false;
|
||||
SECTION("Setter") {
|
||||
readerPtr = &reader;
|
||||
REQUIRE(readerPtr->setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
|
||||
}
|
||||
SECTION("Directly Constructed") {
|
||||
callDelete = true;
|
||||
readerPtr = new PusTcReader(buf.data(), serLen);
|
||||
REQUIRE(not readerPtr->isNull());
|
||||
REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
|
||||
}
|
||||
REQUIRE(not readerPtr->isNull());
|
||||
REQUIRE(*readerPtr);
|
||||
REQUIRE(readerPtr->getPacketType() == ccsds::PacketType::TC);
|
||||
REQUIRE(readerPtr->getApid() == 0x02);
|
||||
REQUIRE(readerPtr->getService() == 17);
|
||||
REQUIRE(readerPtr->getSubService() == 1);
|
||||
REQUIRE(readerPtr->getFullPacketLen() == 13);
|
||||
REQUIRE(readerPtr->getPacketDataLen() == 6);
|
||||
REQUIRE(readerPtr->getPusVersion() == 2);
|
||||
REQUIRE(readerPtr->getSequenceCount() == 0x34);
|
||||
REQUIRE(readerPtr->getUserData() == nullptr);
|
||||
REQUIRE(readerPtr->getUserDataLen() == 0);
|
||||
REQUIRE(readerPtr->getFullData() == buf.data());
|
||||
REQUIRE(readerPtr->getSourceId() == 0x00);
|
||||
REQUIRE(readerPtr->getAcknowledgeFlags() == 0b1111);
|
||||
// This value was verified to be correct
|
||||
REQUIRE(readerPtr->getErrorControl() == 0xee63);
|
||||
if (callDelete) {
|
||||
delete readerPtr;
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Invalid CRC") {
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
|
||||
buf[11] = 0x00;
|
||||
REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16);
|
||||
}
|
||||
|
||||
SECTION("Invalid CRC but no check") {
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
|
||||
buf[11] = 0x00;
|
||||
REQUIRE(reader.parseDataWithoutCrcCheck() == HasReturnvaluesIF::RETURN_OK);
|
||||
}
|
||||
|
||||
SECTION("With application data") {
|
||||
auto& params = creator.getPusParams();
|
||||
std::array<uint8_t, 3> data{1, 2, 3};
|
||||
creator.setRawUserData(data.data(), data.size());
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
|
||||
const uint8_t* userDataPtr = reader.getUserData();
|
||||
REQUIRE(userDataPtr != nullptr);
|
||||
REQUIRE(reader.getUserDataLen() == 3);
|
||||
REQUIRE(userDataPtr[0] == 1);
|
||||
REQUIRE(userDataPtr[1] == 2);
|
||||
REQUIRE(userDataPtr[2] == 3);
|
||||
}
|
||||
}
|
159
unittests/tmtcpacket/testPusTmCreator.cpp
Normal file
159
unittests/tmtcpacket/testPusTmCreator.cpp
Normal file
@ -0,0 +1,159 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/globalfunctions/CRC.h"
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
#include "fsfw/tmtcpacket/pus/tm.h"
|
||||
#include "mocks/CdsShortTimestamperMock.h"
|
||||
#include "mocks/SimpleSerializable.h"
|
||||
|
||||
TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {
|
||||
auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef);
|
||||
auto spParams =
|
||||
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00);
|
||||
auto timeStamper = CdsShortTimestamperMock();
|
||||
auto pusTmParams = PusTmParams(17, 2, &timeStamper);
|
||||
timeStamper.valueToStamp = {1, 2, 3, 4, 5, 6, 7};
|
||||
PusTmCreator creator(spParams, pusTmParams);
|
||||
std::array<uint8_t, 32> buf{};
|
||||
uint8_t* dataPtr = buf.data();
|
||||
size_t serLen = 0;
|
||||
|
||||
SECTION("State") {
|
||||
CHECK(creator.isTm());
|
||||
CHECK(creator.hasSecHeader());
|
||||
CHECK(creator.getApid() == 0xef);
|
||||
CHECK(creator.getPusVersion() == 2);
|
||||
CHECK(creator.getScTimeRefStatus() == 0);
|
||||
CHECK(creator.getService() == 17);
|
||||
CHECK(creator.getSubService() == 2);
|
||||
CHECK(creator.getTimestamper() == &timeStamper);
|
||||
CHECK(creator.getSequenceFlags() == ccsds::SequenceFlags::UNSEGMENTED);
|
||||
CHECK(creator.getSequenceCount() == 22);
|
||||
// 6 bytes CCSDS header, 7 bytes secondary header, 7 bytes CDS short timestamp,
|
||||
// 0 bytes application data, 2 bytes CRC
|
||||
CHECK(creator.getFullPacketLen() == 22);
|
||||
// As specified in standard, the data length fields is the total size of the packet without
|
||||
// the primary header minus 1
|
||||
CHECK(creator.getPacketDataLen() == 15);
|
||||
CHECK(timeStamper.getSizeCallCount == 1);
|
||||
}
|
||||
|
||||
SECTION("SP Params") {
|
||||
auto& spParamsRef = creator.getSpParams();
|
||||
REQUIRE(spParamsRef.dataLen == 15);
|
||||
REQUIRE(spParamsRef.packetId.apid == 0xef);
|
||||
}
|
||||
|
||||
SECTION("Serialization") {
|
||||
REQUIRE(creator.SerializeIF::serializeBe(&dataPtr, &serLen, buf.size()) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(buf[0] == 0x08);
|
||||
REQUIRE(buf[1] == 0xef);
|
||||
// Unsegmented is the default
|
||||
REQUIRE(buf[2] == 0xc0);
|
||||
REQUIRE(buf[3] == 22);
|
||||
REQUIRE(buf[4] == 0);
|
||||
REQUIRE(buf[5] == 15);
|
||||
REQUIRE(((buf[6] >> 4) & 0b1111) == ecss::PusVersion::PUS_C);
|
||||
// SC time reference field
|
||||
REQUIRE((buf[6] & 0b1111) == 0);
|
||||
// Service and subservice field
|
||||
REQUIRE(buf[7] == 17);
|
||||
REQUIRE(buf[8] == 2);
|
||||
// Message Sequence Count
|
||||
REQUIRE(((buf[9] << 8) | buf[10]) == 0);
|
||||
// Destination ID
|
||||
REQUIRE(((buf[11] << 8) | buf[12]) == 0);
|
||||
// Custom timestamp
|
||||
for (size_t i = 1; i < 8; i++) {
|
||||
REQUIRE(buf[12 + i] == i);
|
||||
}
|
||||
REQUIRE(serLen == 22);
|
||||
REQUIRE(CRC::crc16ccitt(buf.data(), serLen) == 0);
|
||||
REQUIRE(buf[20] == 0x03);
|
||||
REQUIRE(buf[21] == 0x79);
|
||||
REQUIRE(timeStamper.serializeCallCount == 1);
|
||||
}
|
||||
|
||||
SECTION("Custom Fields") {
|
||||
creator.setApid(0x3ff);
|
||||
SECTION("Using Params") {
|
||||
auto& pusParams = creator.getParams();
|
||||
pusParams.secHeader.destId = 0xfff;
|
||||
pusParams.secHeader.messageTypeCounter = 0x313;
|
||||
}
|
||||
SECTION("Using Setters") {
|
||||
auto& pusParams = creator.getParams();
|
||||
creator.setDestId(0xfff);
|
||||
creator.setMessageTypeCounter(0x313);
|
||||
}
|
||||
REQUIRE(creator.getApid() == 0x3ff);
|
||||
REQUIRE(creator.getDestId() == 0xfff);
|
||||
REQUIRE(creator.getMessageTypeCounter() == 0x313);
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
// Message Sequence Count
|
||||
REQUIRE(((buf[9] << 8) | buf[10]) == 0x313);
|
||||
// Destination ID
|
||||
REQUIRE(((buf[11] << 8) | buf[12]) == 0xfff);
|
||||
}
|
||||
|
||||
SECTION("Deserialization fails") {
|
||||
SerializeIF& deser = creator;
|
||||
const uint8_t* roDataPtr = nullptr;
|
||||
REQUIRE(deser.deSerialize(&roDataPtr, &serLen, SerializeIF::Endianness::NETWORK) ==
|
||||
HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
|
||||
SECTION("Serialize with Raw Data") {
|
||||
std::array<uint8_t, 3> data{1, 2, 3};
|
||||
creator.setRawUserData(data.data(), data.size());
|
||||
REQUIRE(creator.getFullPacketLen() == 25);
|
||||
REQUIRE(creator.SerializeIF::serialize(&dataPtr, &serLen, buf.size()) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(buf[20] == 1);
|
||||
REQUIRE(buf[21] == 2);
|
||||
REQUIRE(buf[22] == 3);
|
||||
}
|
||||
|
||||
SECTION("Serialize with Serializable") {
|
||||
auto simpleSer = SimpleSerializable();
|
||||
creator.setSerializableUserData(simpleSer);
|
||||
REQUIRE(creator.getFullPacketLen() == 25);
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(buf[20] == 1);
|
||||
REQUIRE(buf[21] == 2);
|
||||
REQUIRE(buf[22] == 3);
|
||||
}
|
||||
|
||||
SECTION("Empty Ctor") {
|
||||
PusTmCreator creatorFromEmptyCtor;
|
||||
// 6 bytes CCSDS header, 7 bytes secondary header, no timestamp (IF is null),
|
||||
// 0 bytes application data, 2 bytes CRC
|
||||
REQUIRE(creatorFromEmptyCtor.getFullPacketLen() == 15);
|
||||
// As specified in standard, the data length fields is the total size of the packet without
|
||||
// the primary header minus 1
|
||||
REQUIRE(creatorFromEmptyCtor.getPacketDataLen() == 8);
|
||||
creatorFromEmptyCtor.setTimeStamper(timeStamper);
|
||||
REQUIRE(creatorFromEmptyCtor.getFullPacketLen() == 22);
|
||||
REQUIRE(creatorFromEmptyCtor.getPacketDataLen() == 15);
|
||||
}
|
||||
|
||||
SECTION("Invalid Buffer Sizes") {
|
||||
size_t reqSize = creator.getSerializedSize();
|
||||
for (size_t maxSize = 0; maxSize < reqSize; maxSize++) {
|
||||
dataPtr = buf.data();
|
||||
serLen = 0;
|
||||
REQUIRE(creator.SerializeIF::serialize(&dataPtr, &serLen, maxSize) ==
|
||||
SerializeIF::BUFFER_TOO_SHORT);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("No CRC Generation") {
|
||||
creator.disableCrcCalculation();
|
||||
REQUIRE(not creator.crcCalculationEnabled());
|
||||
REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(serLen == 22);
|
||||
REQUIRE(buf[20] == 0x00);
|
||||
REQUIRE(buf[21] == 0x00);
|
||||
}
|
||||
}
|
109
unittests/tmtcpacket/testPusTmReader.cpp
Normal file
109
unittests/tmtcpacket/testPusTmReader.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h"
|
||||
#include "fsfw/tmtcpacket/pus/tm/PusTmReader.h"
|
||||
#include "mocks/CdsShortTimestamperMock.h"
|
||||
|
||||
TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {
|
||||
auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef);
|
||||
auto spParams =
|
||||
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00);
|
||||
auto timeStamperAndReader = CdsShortTimestamperMock();
|
||||
auto pusTmParams = PusTmParams(17, 2, &timeStamperAndReader);
|
||||
timeStamperAndReader.valueToStamp = {1, 2, 3, 4, 5, 6, 7};
|
||||
PusTmCreator creator(spParams, pusTmParams);
|
||||
PusTmReader reader(&timeStamperAndReader);
|
||||
std::array<uint8_t, 32> buf{};
|
||||
uint8_t* dataPtr = buf.data();
|
||||
size_t serLen = 0;
|
||||
|
||||
SECTION("Basic") {
|
||||
PusTmReader* readerPtr = &reader;
|
||||
bool deleteReader = false;
|
||||
dataPtr = buf.data();
|
||||
serLen = 0;
|
||||
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(not(*readerPtr));
|
||||
REQUIRE(readerPtr->isNull());
|
||||
|
||||
SECTION("Setter") {
|
||||
REQUIRE(readerPtr->setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
|
||||
}
|
||||
SECTION("Full Construction") {
|
||||
readerPtr = new PusTmReader(&timeStamperAndReader, buf.data(), serLen);
|
||||
deleteReader = true;
|
||||
}
|
||||
SECTION("Time Stamper set manually") {
|
||||
readerPtr = new PusTmReader(buf.data(), serLen);
|
||||
readerPtr->setTimeReader(&timeStamperAndReader);
|
||||
deleteReader = true;
|
||||
}
|
||||
REQUIRE(not *readerPtr);
|
||||
REQUIRE(readerPtr->isNull());
|
||||
REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(not readerPtr->isNull());
|
||||
REQUIRE(readerPtr->getService() == 17);
|
||||
REQUIRE(readerPtr->getSubService() == 2);
|
||||
REQUIRE(readerPtr->getApid() == 0xef);
|
||||
REQUIRE(readerPtr->getSequenceFlags() == ccsds::SequenceFlags::UNSEGMENTED);
|
||||
REQUIRE(readerPtr->getScTimeRefStatus() == 0);
|
||||
REQUIRE(readerPtr->getDestId() == 0);
|
||||
REQUIRE(readerPtr->getMessageTypeCounter() == 0);
|
||||
REQUIRE(readerPtr->getTimeReader() == &timeStamperAndReader);
|
||||
REQUIRE(readerPtr->getPusVersion() == 2);
|
||||
REQUIRE(readerPtr->getPacketDataLen() == 15);
|
||||
REQUIRE(readerPtr->getFullPacketLen() == 22);
|
||||
REQUIRE(readerPtr->getUserDataLen() == 0);
|
||||
REQUIRE(readerPtr->getUserData() == nullptr);
|
||||
REQUIRE(readerPtr->getFullData() == buf.data());
|
||||
if (deleteReader) {
|
||||
delete readerPtr;
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Invalid CRC") {
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
buf[20] = 0;
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16);
|
||||
}
|
||||
|
||||
SECTION("Set Time Reader") {
|
||||
reader.setTimeReader(nullptr);
|
||||
REQUIRE(reader.getTimeReader() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("Invalid CRC ignored") {
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
buf[20] = 0;
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.parseDataWithoutCrcCheck() == HasReturnvaluesIF::RETURN_OK);
|
||||
}
|
||||
|
||||
SECTION("Read with source data") {
|
||||
std::array<uint8_t, 3> data{1, 2, 3};
|
||||
creator.setRawUserData(data.data(), data.size());
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.getUserDataLen() == 3);
|
||||
const uint8_t* roData = reader.getUserData();
|
||||
REQUIRE(roData[0] == 1);
|
||||
REQUIRE(roData[1] == 2);
|
||||
REQUIRE(roData[2] == 3);
|
||||
}
|
||||
|
||||
SECTION("Invalid stream lengths") {
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
for (size_t i = 0; i < serLen - 1; i++) {
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), i) == SerializeIF::STREAM_TOO_SHORT);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Reading timestamp fails") {
|
||||
timeStamperAndReader.nextDeserFails = true;
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
}
|
42
unittests/tmtcpacket/testZcTmWriter.cpp
Normal file
42
unittests/tmtcpacket/testZcTmWriter.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/globalfunctions/CRC.h"
|
||||
#include "fsfw/tmtcpacket/pus/tm.h"
|
||||
#include "fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h"
|
||||
#include "mocks/CdsShortTimestamperMock.h"
|
||||
|
||||
TEST_CASE("TM ZC Helper", "[tm-zc-helper]") {
|
||||
auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef);
|
||||
auto spParams =
|
||||
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00);
|
||||
auto timeStamper = CdsShortTimestamperMock();
|
||||
auto pusTmParams = PusTmParams(17, 2, &timeStamper);
|
||||
timeStamper.valueToStamp = {1, 2, 3, 4, 5, 6, 7};
|
||||
PusTmCreator creator(spParams, pusTmParams);
|
||||
std::array<uint8_t, 32> buf{};
|
||||
uint8_t* dataPtr = buf.data();
|
||||
size_t serLen = 0;
|
||||
|
||||
SECTION("No Crash For Uninitialized Object") {
|
||||
REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK);
|
||||
PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen);
|
||||
REQUIRE(writer.getSequenceCount() == 22);
|
||||
writer.setSequenceCount(23);
|
||||
// Can't set anything, parse function was not called
|
||||
REQUIRE(writer.getSequenceCount() == 22);
|
||||
writer.updateErrorControl();
|
||||
}
|
||||
|
||||
SECTION("Basic") {
|
||||
REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK);
|
||||
PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen);
|
||||
REQUIRE(writer.parseDataWithoutCrcCheck() == result::OK);
|
||||
REQUIRE(writer.getSequenceCount() == 22);
|
||||
writer.setSequenceCount(23);
|
||||
REQUIRE(writer.getSequenceCount() == 23);
|
||||
// CRC is invalid now
|
||||
REQUIRE(CRC::crc16ccitt(dataPtr, serLen) != 0);
|
||||
writer.updateErrorControl();
|
||||
REQUIRE(CRC::crc16ccitt(dataPtr, serLen) == 0);
|
||||
}
|
||||
}
|
6
unittests/tmtcservices/CMakeLists.txt
Normal file
6
unittests/tmtcservices/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
testStoreHelper.cpp
|
||||
testSendHelper.cpp
|
||||
testStoreAndSendHelper.cpp
|
||||
testPsb.cpp
|
||||
)
|
245
unittests/tmtcservices/testPsb.cpp
Normal file
245
unittests/tmtcservices/testPsb.cpp
Normal file
@ -0,0 +1,245 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/ipc/QueueFactory.h"
|
||||
#include "fsfw/storagemanager/LocalPool.h"
|
||||
#include "fsfw/storagemanager/PoolManager.h"
|
||||
#include "mocks/AcceptsTmMock.h"
|
||||
#include "mocks/CdsShortTimestamperMock.h"
|
||||
#include "mocks/InternalErrorReporterMock.h"
|
||||
#include "mocks/MessageQueueMock.h"
|
||||
#include "mocks/PusDistributorMock.h"
|
||||
#include "mocks/PusServiceBaseMock.h"
|
||||
#include "mocks/PusVerificationReporterMock.h"
|
||||
|
||||
TEST_CASE("Pus Service Base", "[pus-service-base]") {
|
||||
uint16_t apid = 2;
|
||||
auto verificationReporter = PusVerificationReporterMock();
|
||||
auto msgQueue = MessageQueueMock(1);
|
||||
auto tmReceiver = AcceptsTmMock(2);
|
||||
auto psbParams = PsbParams(0, apid, 17);
|
||||
|
||||
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
|
||||
LocalPool pool(objects::NO_OBJECT, cfg);
|
||||
|
||||
psbParams.verifReporter = &verificationReporter;
|
||||
psbParams.reqQueue = &msgQueue;
|
||||
psbParams.tmReceiver = &tmReceiver;
|
||||
psbParams.tcPool = &pool;
|
||||
auto psb = PsbMock(psbParams);
|
||||
|
||||
store_address_t storeId;
|
||||
TmTcMessage tmtcMsg;
|
||||
|
||||
// Components to create valid PUS packets
|
||||
auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02);
|
||||
auto spParams =
|
||||
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 0x34), 0x00);
|
||||
auto pusParams = PusTcParams(17, 1);
|
||||
PusTcCreator creator(spParams, pusParams);
|
||||
|
||||
REQUIRE(psb.initialize() == HasReturnvaluesIF::RETURN_OK);
|
||||
|
||||
SECTION("State") {
|
||||
REQUIRE(psb.getIdentifier() == 17);
|
||||
REQUIRE(psb.getObjectId() == 0);
|
||||
REQUIRE(psb.getRequestQueue() == msgQueue.getId());
|
||||
auto psbParamsLocal = psb.getParams();
|
||||
REQUIRE(psbParamsLocal.errReporter == nullptr);
|
||||
}
|
||||
|
||||
SECTION("Perform Service") {
|
||||
REQUIRE(psb.performServiceCallCnt == 0);
|
||||
REQUIRE(psb.performOperation(0) == result::OK);
|
||||
REQUIRE(psb.performServiceCallCnt == 1);
|
||||
}
|
||||
|
||||
SECTION("Send Request with Successful Handling") {
|
||||
REQUIRE(psb.performServiceCallCnt == 0);
|
||||
uint8_t* dataPtr;
|
||||
REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == result::OK);
|
||||
size_t serLen = 0;
|
||||
REQUIRE(creator.serializeBe(dataPtr, serLen, creator.getSerializedSize()) == result::OK);
|
||||
tmtcMsg.setStorageId(storeId);
|
||||
msgQueue.addReceivedMessage(tmtcMsg);
|
||||
REQUIRE(psb.performOperation(0) == result::OK);
|
||||
uint8_t subservice = 0;
|
||||
REQUIRE(psb.getAndPopNextSubservice(subservice));
|
||||
REQUIRE(subservice == 1);
|
||||
REQUIRE(psb.performServiceCallCnt == 1);
|
||||
// PSB should take care of freeing the pool slot
|
||||
REQUIRE(not pool.hasDataAtId(storeId));
|
||||
REQUIRE(verificationReporter.successCallCount() == 1);
|
||||
REQUIRE(verificationReporter.failCallCount() == 0);
|
||||
auto verifParams = verificationReporter.getNextSuccessCallParams();
|
||||
REQUIRE(verifParams.tcPacketId == creator.getPacketIdRaw());
|
||||
REQUIRE(verifParams.tcPsc == creator.getPacketSeqCtrlRaw());
|
||||
}
|
||||
|
||||
SECTION("Send Request with Failed Handling") {
|
||||
uint8_t* dataPtr;
|
||||
REQUIRE(pool.getFreeElement(&storeId, creator.getSerializedSize(), &dataPtr) == result::OK);
|
||||
size_t serLen = 0;
|
||||
REQUIRE(creator.serializeBe(dataPtr, serLen, creator.getSerializedSize()) == result::OK);
|
||||
tmtcMsg.setStorageId(storeId);
|
||||
msgQueue.addReceivedMessage(tmtcMsg);
|
||||
psb.makeNextHandleReqCallFail(3);
|
||||
REQUIRE(psb.performOperation(0) == result::OK);
|
||||
uint8_t subservice = 0;
|
||||
REQUIRE(psb.getAndPopNextSubservice(subservice));
|
||||
REQUIRE(subservice == 1);
|
||||
REQUIRE(psb.performServiceCallCnt == 1);
|
||||
// PSB should take care of freeing the pool slot
|
||||
REQUIRE(not pool.hasDataAtId(storeId));
|
||||
REQUIRE(verificationReporter.successCallCount() == 0);
|
||||
REQUIRE(verificationReporter.failCallCount() == 1);
|
||||
auto verifParams = verificationReporter.getNextFailCallParams();
|
||||
REQUIRE(verifParams.tcPacketId == creator.getPacketIdRaw());
|
||||
REQUIRE(verifParams.tcPsc == creator.getPacketSeqCtrlRaw());
|
||||
}
|
||||
|
||||
SECTION("Invalid Packet Sent") {
|
||||
tmtcMsg.setStorageId(store_address_t::invalid());
|
||||
msgQueue.addReceivedMessage(tmtcMsg);
|
||||
REQUIRE(psb.performOperation(0) == result::OK);
|
||||
REQUIRE(verificationReporter.failCallCount() == 1);
|
||||
auto verifParams = verificationReporter.getNextFailCallParams();
|
||||
REQUIRE(verifParams.tcPacketId == 0);
|
||||
REQUIRE(verifParams.tcPsc == 0);
|
||||
}
|
||||
|
||||
SECTION("Set Verif Reporter") {
|
||||
auto verificationReporter2 = PusVerificationReporterMock();
|
||||
psb.setVerificationReporter(verificationReporter2);
|
||||
auto& p = psb.getParams();
|
||||
REQUIRE(p.verifReporter == &verificationReporter2);
|
||||
}
|
||||
|
||||
SECTION("Set Request Queue") {
|
||||
auto msgQueueMock = MessageQueueMock(2);
|
||||
psb.setRequestQueue(msgQueueMock);
|
||||
auto& p = psb.getParams();
|
||||
REQUIRE(p.reqQueue == &msgQueueMock);
|
||||
}
|
||||
|
||||
SECTION("Set TM Receiver") {
|
||||
auto tmReceiver2 = AcceptsTmMock(3);
|
||||
psb.setTmReceiver(tmReceiver2);
|
||||
auto& p = psb.getParams();
|
||||
REQUIRE(p.tmReceiver == &tmReceiver2);
|
||||
}
|
||||
|
||||
SECTION("Set TC Store") {
|
||||
LocalPool tcStore2(5, cfg);
|
||||
psb.setTcPool(tcStore2);
|
||||
auto& p = psb.getParams();
|
||||
REQUIRE(p.tcPool == &tcStore2);
|
||||
}
|
||||
|
||||
SECTION("Set error reporter") {
|
||||
auto errReporter = InternalErrorReporterMock();
|
||||
psb.setErrorReporter(errReporter);
|
||||
auto& p = psb.getParams();
|
||||
REQUIRE(p.errReporter == &errReporter);
|
||||
}
|
||||
SECTION("Owner Queue") {
|
||||
// This will cause the initialize function to create a new owner queue
|
||||
psbParams.reqQueue = nullptr;
|
||||
psbParams.objectId = 1;
|
||||
auto mockWithOwnerQueue = PsbMock(psbParams);
|
||||
REQUIRE(mockWithOwnerQueue.getRequestQueue() == MessageQueueIF::NO_QUEUE);
|
||||
REQUIRE(mockWithOwnerQueue.initialize() == result::OK);
|
||||
REQUIRE(mockWithOwnerQueue.getRequestQueue() != MessageQueueIF::NO_QUEUE);
|
||||
}
|
||||
|
||||
SECTION("TM Store Helper Initializer") {
|
||||
TmStoreHelper storeHelper(0);
|
||||
psb.initializeTmStoreHelper(storeHelper);
|
||||
REQUIRE(storeHelper.getApid() == apid);
|
||||
}
|
||||
|
||||
SECTION("TM Send Helper Initializer") {
|
||||
TmSendHelper sendHelper;
|
||||
psb.initializeTmSendHelper(sendHelper);
|
||||
REQUIRE(sendHelper.getMsgQueue() == &msgQueue);
|
||||
REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination());
|
||||
}
|
||||
|
||||
SECTION("TM Store And Send Helper Initializer") {
|
||||
TmStoreHelper storeHelper(0);
|
||||
TmSendHelper sendHelper;
|
||||
psb.initializeTmHelpers(sendHelper, storeHelper);
|
||||
REQUIRE(sendHelper.getMsgQueue() == &msgQueue);
|
||||
REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination());
|
||||
REQUIRE(storeHelper.getApid() == apid);
|
||||
}
|
||||
|
||||
SECTION("TM Send Helper Initializer With Error Reporter") {
|
||||
TmSendHelper sendHelper;
|
||||
auto errReporter = InternalErrorReporterMock();
|
||||
psb.setErrorReporter(errReporter);
|
||||
psb.initializeTmSendHelper(sendHelper);
|
||||
REQUIRE(sendHelper.getMsgQueue() == &msgQueue);
|
||||
REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination());
|
||||
REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter);
|
||||
}
|
||||
|
||||
SECTION("Auto Initialize PUS Distributor") {
|
||||
psbParams.objectId = 1;
|
||||
object_id_t distributorId = 3;
|
||||
auto psb2 = PsbMock(psbParams);
|
||||
auto pusDistrib = PusDistributorMock(distributorId);
|
||||
PsbMock::setStaticPusDistributor(distributorId);
|
||||
REQUIRE(PsbMock::getStaticPusDistributor() == distributorId);
|
||||
REQUIRE(psb2.initialize() == result::OK);
|
||||
REQUIRE(pusDistrib.registerCallCount == 1);
|
||||
REQUIRE(pusDistrib.lastServiceArg == &psb2);
|
||||
}
|
||||
|
||||
SECTION("Auto Initialize Packet Destination") {
|
||||
psbParams.tmReceiver = nullptr;
|
||||
psbParams.objectId = 1;
|
||||
object_id_t destId = 3;
|
||||
auto psb2 = PsbMock(psbParams);
|
||||
auto packetDest = AcceptsTmMock(destId, 2);
|
||||
PsbMock::setStaticTmDest(destId);
|
||||
REQUIRE(PsbMock::getStaticTmDest() == destId);
|
||||
REQUIRE(psb2.initialize() == result::OK);
|
||||
auto& p = psb2.getParams();
|
||||
REQUIRE(p.tmReceiver == &packetDest);
|
||||
}
|
||||
|
||||
SECTION("Auto Initialize Verification Reporter") {
|
||||
psbParams.verifReporter = nullptr;
|
||||
psbParams.objectId = 1;
|
||||
object_id_t reporterId = objects::TC_VERIFICATOR;
|
||||
PusVerificationReporterMock otherReporter(reporterId);
|
||||
auto psb2 = PsbMock(psbParams);
|
||||
REQUIRE(psb2.initialize() == result::OK);
|
||||
auto& p = psb2.getParams();
|
||||
REQUIRE(p.verifReporter == &otherReporter);
|
||||
}
|
||||
|
||||
SECTION("Auto Initialize TC Pool") {
|
||||
PoolManager tcStoreGlobal(objects::TC_STORE, cfg);
|
||||
psbParams.tcPool = nullptr;
|
||||
psbParams.objectId = 1;
|
||||
auto psb2 = PsbMock(psbParams);
|
||||
REQUIRE(psb2.initialize() == result::OK);
|
||||
auto& p = psb2.getParams();
|
||||
REQUIRE(p.tcPool == &tcStoreGlobal);
|
||||
}
|
||||
|
||||
SECTION("Invalid Verification Reporter") {
|
||||
psbParams.verifReporter = nullptr;
|
||||
psbParams.objectId = 1;
|
||||
auto psb2 = PsbMock(psbParams);
|
||||
REQUIRE(psb2.initialize() == ObjectManagerIF::CHILD_INIT_FAILED);
|
||||
}
|
||||
|
||||
SECTION("Invalid TC Store") {
|
||||
psbParams.tcPool = nullptr;
|
||||
psbParams.objectId = 1;
|
||||
auto psb2 = PsbMock(psbParams);
|
||||
REQUIRE(psb2.initialize() == ObjectManagerIF::CHILD_INIT_FAILED);
|
||||
}
|
||||
}
|
106
unittests/tmtcservices/testSendHelper.cpp
Normal file
106
unittests/tmtcservices/testSendHelper.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/storagemanager/LocalPool.h"
|
||||
#include "fsfw/tmtcservices/TmSendHelper.h"
|
||||
#include "fsfw/tmtcservices/TmStoreHelper.h"
|
||||
#include "mocks/CdsShortTimestamperMock.h"
|
||||
#include "mocks/InternalErrorReporterMock.h"
|
||||
#include "mocks/MessageQueueMock.h"
|
||||
|
||||
TEST_CASE("TM Send Helper", "[tm-send-helper]") {
|
||||
MessageQueueId_t destId = 2;
|
||||
auto errReporter = InternalErrorReporterMock();
|
||||
auto msgQueue = MessageQueueMock(1);
|
||||
msgQueue.setDefaultDestination(destId);
|
||||
TmSendHelper sendHelper(msgQueue, errReporter, destId);
|
||||
auto timeStamper = CdsShortTimestamperMock();
|
||||
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
|
||||
LocalPool pool(objects::NO_OBJECT, cfg);
|
||||
auto storeHelper = TmStoreHelper(2, pool, timeStamper);
|
||||
|
||||
SECTION("State and Setters") {
|
||||
REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter);
|
||||
REQUIRE(sendHelper.getDefaultDestination() == destId);
|
||||
REQUIRE(sendHelper.getMsgQueue() == &msgQueue);
|
||||
}
|
||||
|
||||
SECTION("Setters") {
|
||||
REQUIRE(not sendHelper.areFaultsIgnored());
|
||||
sendHelper.ignoreFaults();
|
||||
REQUIRE(sendHelper.areFaultsIgnored());
|
||||
sendHelper.dontIgnoreFaults();
|
||||
REQUIRE(not sendHelper.areFaultsIgnored());
|
||||
REQUIRE(sendHelper.getDefaultDestination() == destId);
|
||||
sendHelper.setDefaultDestination(destId + 1);
|
||||
REQUIRE(sendHelper.getDefaultDestination() == destId + 1);
|
||||
auto errReporter2 = InternalErrorReporterMock();
|
||||
sendHelper.setInternalErrorReporter(errReporter2);
|
||||
REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter2);
|
||||
}
|
||||
|
||||
SECTION("Default CTOR") {
|
||||
TmSendHelper emptyHelper;
|
||||
REQUIRE(emptyHelper.getInternalErrorReporter() == nullptr);
|
||||
REQUIRE(emptyHelper.getDefaultDestination() == MessageQueueIF::NO_QUEUE);
|
||||
store_address_t dummy;
|
||||
// basic robustness
|
||||
REQUIRE(emptyHelper.sendPacket(dummy) == HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
|
||||
SECTION("One Arg CTOR") {
|
||||
TmSendHelper helper(errReporter);
|
||||
REQUIRE(helper.getInternalErrorReporter() == &errReporter);
|
||||
REQUIRE(helper.getDefaultDestination() == MessageQueueIF::NO_QUEUE);
|
||||
REQUIRE(helper.getMsgQueue() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("Two Arg CTOR") {
|
||||
TmSendHelper helper(msgQueue, errReporter);
|
||||
REQUIRE(helper.getInternalErrorReporter() == &errReporter);
|
||||
REQUIRE(helper.getDefaultDestination() == 2);
|
||||
REQUIRE(helper.getMsgQueue() == &msgQueue);
|
||||
}
|
||||
SECTION("Send") {
|
||||
REQUIRE(storeHelper.preparePacket(17, 2, 0) == HasReturnvaluesIF::RETURN_OK);
|
||||
store_address_t storeId;
|
||||
SECTION("Separate Helpers") {
|
||||
REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK);
|
||||
storeId = storeHelper.getCurrentAddr();
|
||||
REQUIRE(sendHelper.sendPacket(storeId) == HasReturnvaluesIF::RETURN_OK);
|
||||
}
|
||||
REQUIRE(msgQueue.wasMessageSent());
|
||||
REQUIRE(msgQueue.numberOfSentMessagesToDefault() == 1);
|
||||
TmTcMessage msg;
|
||||
REQUIRE(msgQueue.getNextSentMessage(msg) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(msg.getStorageId() == storeId);
|
||||
REQUIRE(pool.hasDataAtId(msg.getStorageId()));
|
||||
}
|
||||
|
||||
SECTION("Send to Non-Default") {
|
||||
storeHelper.preparePacket(17, 2, 0);
|
||||
REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK);
|
||||
store_address_t storeId = storeHelper.getCurrentAddr();
|
||||
REQUIRE(sendHelper.sendPacket(destId + 1, storeId) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(msgQueue.wasMessageSent());
|
||||
REQUIRE(msgQueue.numberOfSentMessagesToDest(destId + 1) == 1);
|
||||
}
|
||||
|
||||
SECTION("Sending fails, errors not ignored") {
|
||||
msgQueue.makeNextSendFail(HasReturnvaluesIF::RETURN_FAILED);
|
||||
storeHelper.preparePacket(17, 2, 0);
|
||||
REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK);
|
||||
store_address_t storeId = storeHelper.getCurrentAddr();
|
||||
REQUIRE(sendHelper.sendPacket(destId + 1, storeId) == HasReturnvaluesIF::RETURN_FAILED);
|
||||
REQUIRE(errReporter.lostTmCallCnt == 1);
|
||||
}
|
||||
|
||||
SECTION("Sending fails, errors ignored") {
|
||||
msgQueue.makeNextSendFail(HasReturnvaluesIF::RETURN_FAILED);
|
||||
storeHelper.preparePacket(17, 2, 0);
|
||||
sendHelper.ignoreFaults();
|
||||
REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK);
|
||||
store_address_t storeId = storeHelper.getCurrentAddr();
|
||||
REQUIRE(sendHelper.sendPacket(destId + 1, storeId) == HasReturnvaluesIF::RETURN_FAILED);
|
||||
REQUIRE(errReporter.lostTmCallCnt == 0);
|
||||
}
|
||||
}
|
94
unittests/tmtcservices/testStoreAndSendHelper.cpp
Normal file
94
unittests/tmtcservices/testStoreAndSendHelper.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/storagemanager/LocalPool.h"
|
||||
#include "fsfw/tmtcservices/TmSendHelper.h"
|
||||
#include "fsfw/tmtcservices/TmStoreAndSendHelper.h"
|
||||
#include "fsfw/tmtcservices/TmStoreHelper.h"
|
||||
#include "mocks/CdsShortTimestamperMock.h"
|
||||
#include "mocks/InternalErrorReporterMock.h"
|
||||
#include "mocks/MessageQueueMock.h"
|
||||
#include "mocks/SimpleSerializable.h"
|
||||
|
||||
TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") {
|
||||
auto timeStamper = CdsShortTimestamperMock();
|
||||
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
|
||||
LocalPool pool(objects::NO_OBJECT, cfg);
|
||||
auto storeHelper = TmStoreHelper(2, pool, timeStamper);
|
||||
|
||||
MessageQueueId_t destId = 1;
|
||||
auto errReporter = InternalErrorReporterMock();
|
||||
auto msgQueue = MessageQueueMock(2);
|
||||
msgQueue.setDefaultDestination(destId);
|
||||
TmSendHelper sendHelper(msgQueue, errReporter, destId);
|
||||
TmStoreAndSendWrapper tmHelper(17, storeHelper, sendHelper);
|
||||
|
||||
SECTION("State") {
|
||||
CHECK(tmHelper.sendCounter == 0);
|
||||
CHECK(tmHelper.defaultService == 17);
|
||||
CHECK(tmHelper.delOnFailure);
|
||||
CHECK(tmHelper.incrementSendCounter);
|
||||
CHECK(&tmHelper.sendHelper == &sendHelper);
|
||||
CHECK(&tmHelper.storeHelper == &storeHelper);
|
||||
}
|
||||
|
||||
SECTION("Storage Fails") {
|
||||
// Too large to fit in store
|
||||
std::array<uint8_t, 80> data{};
|
||||
REQUIRE(storeHelper.setSourceDataRaw(data.data(), data.size()) == result::OK);
|
||||
REQUIRE(tmHelper.storeAndSendTmPacket() == StorageManagerIF::DATA_TOO_LARGE);
|
||||
}
|
||||
|
||||
SECTION("Base Test") {
|
||||
tmHelper.prepareTmPacket(2);
|
||||
auto& creator = storeHelper.getCreatorRef();
|
||||
REQUIRE(creator.getSubService() == 2);
|
||||
REQUIRE(creator.getService() == 17);
|
||||
auto& params = creator.getParams();
|
||||
REQUIRE(params.dataWrapper.type == ecss::DataTypes::RAW);
|
||||
REQUIRE(params.dataWrapper.dataUnion.raw.data == nullptr);
|
||||
REQUIRE(params.dataWrapper.dataUnion.raw.len == 0);
|
||||
REQUIRE(tmHelper.sendCounter == 0);
|
||||
REQUIRE(tmHelper.storeAndSendTmPacket() == result::OK);
|
||||
REQUIRE(tmHelper.sendCounter == 1);
|
||||
auto storeId = storeHelper.getCurrentAddr();
|
||||
REQUIRE(msgQueue.wasMessageSent());
|
||||
REQUIRE(msgQueue.numberOfSentMessagesToDefault() == 1);
|
||||
TmTcMessage msg;
|
||||
REQUIRE(msgQueue.getNextSentMessage(msg) == result::OK);
|
||||
REQUIRE(msg.getStorageId() == storeId);
|
||||
REQUIRE(pool.hasDataAtId(msg.getStorageId()));
|
||||
storeHelper.deletePacket();
|
||||
}
|
||||
|
||||
SECTION("Raw Data Helper") {
|
||||
std::array<uint8_t, 3> data = {1, 2, 3};
|
||||
REQUIRE(tmHelper.prepareTmPacket(2, data.data(), data.size()) == result::OK);
|
||||
auto& creator = storeHelper.getCreatorRef();
|
||||
auto& params = creator.getParams();
|
||||
REQUIRE(params.dataWrapper.type == ecss::DataTypes::RAW);
|
||||
REQUIRE(params.dataWrapper.dataUnion.raw.data == data.data());
|
||||
REQUIRE(params.dataWrapper.dataUnion.raw.len == data.size());
|
||||
}
|
||||
|
||||
SECTION("Serializable Helper") {
|
||||
auto simpleSer = SimpleSerializable();
|
||||
REQUIRE(tmHelper.prepareTmPacket(2, simpleSer) == result::OK);
|
||||
auto& creator = storeHelper.getCreatorRef();
|
||||
auto& params = creator.getParams();
|
||||
REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE);
|
||||
REQUIRE(params.dataWrapper.dataUnion.serializable == &simpleSer);
|
||||
}
|
||||
|
||||
SECTION("Object ID prefix Helper") {
|
||||
uint32_t objectId = 0x01020304;
|
||||
std::array<uint8_t, 3> data = {1, 2, 3};
|
||||
telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data.data(), data.size());
|
||||
REQUIRE(tmHelper.prepareTmPacket(2, dataWithObjId) == result::OK);
|
||||
auto& creator = storeHelper.getCreatorRef();
|
||||
auto& params = creator.getParams();
|
||||
REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE);
|
||||
REQUIRE(params.dataWrapper.dataUnion.serializable == &dataWithObjId);
|
||||
}
|
||||
|
||||
// TODO: Error handling
|
||||
}
|
110
unittests/tmtcservices/testStoreHelper.cpp
Normal file
110
unittests/tmtcservices/testStoreHelper.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/storagemanager/LocalPool.h"
|
||||
#include "fsfw/tmtcservices/TmStoreHelper.h"
|
||||
#include "fsfw/tmtcservices/tmHelpers.h"
|
||||
#include "mocks/CdsShortTimestamperMock.h"
|
||||
#include "mocks/SimpleSerializable.h"
|
||||
|
||||
TEST_CASE("TM Store Helper", "[tm-store-helper]") {
|
||||
auto timeStamper = CdsShortTimestamperMock();
|
||||
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
|
||||
LocalPool pool(objects::NO_OBJECT, cfg);
|
||||
auto storeHelper = TmStoreHelper(2, pool, timeStamper);
|
||||
|
||||
SECTION("State") {
|
||||
REQUIRE(storeHelper.getCurrentAddr() == store_address_t::invalid());
|
||||
REQUIRE(storeHelper.getTimeStamper() == &timeStamper);
|
||||
REQUIRE(storeHelper.getTmStore() == &pool);
|
||||
REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK);
|
||||
auto& creator = storeHelper.getCreatorRef();
|
||||
REQUIRE(creator.getApid() == 2);
|
||||
REQUIRE(creator.getService() == 17);
|
||||
REQUIRE(creator.getSubService() == 1);
|
||||
REQUIRE(creator.getSequenceCount() == 0);
|
||||
REQUIRE(creator.getMessageTypeCounter() == 1);
|
||||
}
|
||||
|
||||
SECTION("Timestamper Setter") {
|
||||
auto timeStamper2 = CdsShortTimestamperMock();
|
||||
storeHelper.setTimeStamper(timeStamper2);
|
||||
REQUIRE(storeHelper.getTimeStamper() == &timeStamper2);
|
||||
}
|
||||
|
||||
SECTION("Pool Setter") {
|
||||
LocalPool::LocalPoolConfig cfg2 = {{10, 32}, {5, 64}};
|
||||
LocalPool pool2(objects::NO_OBJECT, cfg);
|
||||
storeHelper.setTmStore(pool2);
|
||||
REQUIRE(storeHelper.getTmStore() == &pool2);
|
||||
}
|
||||
|
||||
SECTION("APID Setter") {
|
||||
storeHelper.setApid(3);
|
||||
auto& creator = storeHelper.getCreatorRef();
|
||||
REQUIRE(creator.getApid() == 3);
|
||||
}
|
||||
|
||||
SECTION("Basic") {
|
||||
REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid());
|
||||
auto accessor = pool.getData(storeHelper.getCurrentAddr());
|
||||
REQUIRE(accessor.first == HasReturnvaluesIF::RETURN_OK);
|
||||
// Not going to verify individual fields, the creator was unittested separately
|
||||
REQUIRE(accessor.second.size() == 22);
|
||||
}
|
||||
|
||||
SECTION("Deletion") {
|
||||
REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid());
|
||||
{
|
||||
auto accessor = pool.getData(storeHelper.getCurrentAddr());
|
||||
REQUIRE(accessor.first == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(accessor.second.size() == 22);
|
||||
accessor.second.release();
|
||||
}
|
||||
REQUIRE(storeHelper.deletePacket() == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(storeHelper.getCurrentAddr() == store_address_t::invalid());
|
||||
auto accessor = pool.getData(storeHelper.getCurrentAddr());
|
||||
REQUIRE(accessor.first != HasReturnvaluesIF::RETURN_OK);
|
||||
}
|
||||
|
||||
SECTION("With App Data Raw") {
|
||||
REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK);
|
||||
std::array<uint8_t, 3> data = {1, 2, 3};
|
||||
REQUIRE(storeHelper.setSourceDataRaw(data.data(), data.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid());
|
||||
auto accessor = pool.getData(storeHelper.getCurrentAddr());
|
||||
REQUIRE(accessor.first == HasReturnvaluesIF::RETURN_OK);
|
||||
// Not going to verify individual fields, the creator was unittested separately
|
||||
REQUIRE(accessor.second.size() == 25);
|
||||
}
|
||||
|
||||
SECTION("With App Data Serializable") {
|
||||
REQUIRE(storeHelper.preparePacket(17, 1, 1) == HasReturnvaluesIF::RETURN_OK);
|
||||
auto serializable = SimpleSerializable();
|
||||
REQUIRE(storeHelper.setSourceDataSerializable(serializable) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(storeHelper.addPacketToStore() == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(storeHelper.getCurrentAddr() != store_address_t::invalid());
|
||||
auto accessor = pool.getData(storeHelper.getCurrentAddr());
|
||||
REQUIRE(accessor.first == HasReturnvaluesIF::RETURN_OK);
|
||||
// Not going to verify individual fields, the creator was unittested separately
|
||||
REQUIRE(accessor.second.size() == 25);
|
||||
}
|
||||
|
||||
SECTION("APID Only CTOR") {
|
||||
auto storeHelperApidOnly = TmStoreHelper(2);
|
||||
REQUIRE(storeHelperApidOnly.getApid() == 2);
|
||||
REQUIRE(storeHelperApidOnly.getTmStore() == nullptr);
|
||||
REQUIRE(storeHelperApidOnly.getTimeStamper() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("APID and TM Store Only CTOR") {
|
||||
auto storeHelperApidOnly = TmStoreHelper(2, pool);
|
||||
REQUIRE(storeHelperApidOnly.getApid() == 2);
|
||||
REQUIRE(storeHelperApidOnly.getTmStore() == &pool);
|
||||
REQUIRE(storeHelperApidOnly.getTimeStamper() == nullptr);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user