include fixes

This commit is contained in:
Robin Müller 2020-10-28 22:34:41 +01:00
parent 6325eb7647
commit b860d8bce7
16 changed files with 465 additions and 466 deletions

View File

@ -1,4 +1,4 @@
#include <fsfw/unittest/config/cdatapool/dataPoolInit.h>
#include "dataPoolInit.h"
void datapool::dataPoolInit(std::map<uint32_t, PoolEntryIF*> * poolMap) {
uint8_t UINT8T_INIT[1] = {0};

View File

@ -1,7 +1,7 @@
#ifndef HOSTED_CONFIG_CDATAPOOL_DATAPOOLINIT_H_
#define HOSTED_CONFIG_CDATAPOOL_DATAPOOLINIT_H_
#include <fsfw/datapool/DataPool.h>
#include <fsfw/datapoolglob/GlobalDataPool.h>
#include <fsfw/datapool/PoolEntryIF.h>
#include <map>
#include <cstdint>

View File

@ -23,10 +23,7 @@ void Factory::produce(void) {
setStaticFrameworkObjectIds();
new EventManager(objects::EVENT_MANAGER);
new HealthTable(objects::HEALTH_TABLE);
new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER,
datapool::INTERNAL_ERROR_FULL_MSG_QUEUES,
datapool::INTERNAL_ERROR_MISSED_LIVE_TM,
datapool::INTERNAL_ERROR_STORE_FULL);
new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER);
}

View File

@ -1,105 +1,106 @@
#include <fsfw/action/ActionHelper.h>
#include <fsfw/ipc/CommandMessage.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <fsfw/unittest/tests/action/TestActionHelper.h>
TEST_CASE( "Action Helper" , "[ActionHelper]") {
ActionHelperOwnerMockBase testDhMock;
MessageQueueMockBase testMqMock;
ActionHelper actionHelper = ActionHelper(
&testDhMock, dynamic_cast<MessageQueueIF*>(&testMqMock));
CommandMessage actionMessage;
ActionId_t testActionId = 777;
std::array <uint8_t, 3> testParams {1, 2, 3};
store_address_t paramAddress;
StorageManagerIF *ipcStore = tglob::getIpcStoreHandle();
ipcStore->addData(&paramAddress, testParams.data(), 3);
REQUIRE(actionHelper.initialize() == retval::CATCH_OK);
SECTION ("Simple tests") {
ActionMessage::setCommand(&actionMessage, testActionId, paramAddress);
CHECK(not testDhMock.executeActionCalled);
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK);
CHECK(testDhMock.executeActionCalled);
// No message is sent if everything is alright.
CHECK(not testMqMock.wasMessageSent());
store_address_t invalidAddress;
ActionMessage::setCommand(&actionMessage, testActionId, invalidAddress);
actionHelper.handleActionMessage(&actionMessage);
CHECK(testMqMock.wasMessageSent());
const uint8_t* ptr = nullptr;
size_t size = 0;
REQUIRE(ipcStore->getData(paramAddress, &ptr, &size) == static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST));
REQUIRE(ptr == nullptr);
REQUIRE(size == 0);
testDhMock.getBuffer(&ptr, &size);
REQUIRE(size == 3);
for(uint8_t i = 0; i<3;i++){
REQUIRE(ptr[i] == (i+1));
}
testDhMock.clearBuffer();
}
SECTION("Handle failures"){
actionMessage.setCommand(1234);
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == static_cast<uint32_t>(CommandMessage::UNKNOWN_COMMAND));
CHECK(not testMqMock.wasMessageSent());
uint16_t step = 5;
ReturnValue_t status = 0x1234;
actionHelper.step(step, testMqMock.getId(), testActionId, status);
step += 1;
CHECK(testMqMock.wasMessageSent());
CommandMessage testMessage;
REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast<uint32_t>(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;
REQUIRE(testMessage.getParameter2() == parameter2);
REQUIRE(ActionMessage::getStep(&testMessage) == step);
}
SECTION("Handle finish"){
CHECK(not testMqMock.wasMessageSent());
ReturnValue_t status = 0x9876;
actionHelper.finish(testMqMock.getId(), testActionId, status);
CHECK(testMqMock.wasMessageSent());
CommandMessage testMessage;
REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast<uint32_t>(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;
std::array<uint8_t, 5> toLongData = {5, 4, 3, 2, 1};
REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == retval::CATCH_OK);
ActionMessage::setCommand(&actionMessage, testActionId, toLongParamAddress);
CHECK(not testDhMock.executeActionCalled);
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_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(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
REQUIRE(ActionMessage::getReturnCode(&testMessage) == 0xAFFE);
REQUIRE(ActionMessage::getStep(&testMessage) == 0);
REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId);
}
SECTION("Missing IPC Data"){
ActionMessage::setCommand(&actionMessage, testActionId, StorageManagerIF::INVALID_ADDRESS);
CHECK(not testDhMock.executeActionCalled);
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK);
CommandMessage testMessage;
REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast<uint32_t>(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));
REQUIRE(ActionMessage::getStep(&testMessage) == 0);
}
SECTION("Data Reply"){
}
}
//#include "TestActionHelper.h"
//#include <fsfw/action/ActionHelper.h>
//#include <fsfw/ipc/CommandMessage.h>
//#include <catch2/catch.hpp>
//#include "../../core/CatchDefinitions.h"
//
//
//TEST_CASE( "Action Helper" , "[ActionHelper]") {
// ActionHelperOwnerMockBase testDhMock;
// MessageQueueMockBase testMqMock;
// ActionHelper actionHelper = ActionHelper(
// &testDhMock, dynamic_cast<MessageQueueIF*>(&testMqMock));
// CommandMessage actionMessage;
// ActionId_t testActionId = 777;
// std::array <uint8_t, 3> testParams {1, 2, 3};
// store_address_t paramAddress;
// StorageManagerIF *ipcStore = tglob::getIpcStoreHandle();
// ipcStore->addData(&paramAddress, testParams.data(), 3);
// REQUIRE(actionHelper.initialize() == retval::CATCH_OK);
//
// SECTION ("Simple tests") {
// ActionMessage::setCommand(&actionMessage, testActionId, paramAddress);
// CHECK(not testDhMock.executeActionCalled);
// REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK);
// CHECK(testDhMock.executeActionCalled);
// // No message is sent if everything is alright.
// CHECK(not testMqMock.wasMessageSent());
// store_address_t invalidAddress;
// ActionMessage::setCommand(&actionMessage, testActionId, invalidAddress);
// actionHelper.handleActionMessage(&actionMessage);
// CHECK(testMqMock.wasMessageSent());
// const uint8_t* ptr = nullptr;
// size_t size = 0;
// REQUIRE(ipcStore->getData(paramAddress, &ptr, &size) == static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST));
// REQUIRE(ptr == nullptr);
// REQUIRE(size == 0);
// testDhMock.getBuffer(&ptr, &size);
// REQUIRE(size == 3);
// for(uint8_t i = 0; i<3;i++){
// REQUIRE(ptr[i] == (i+1));
// }
// testDhMock.clearBuffer();
// }
//
// SECTION("Handle failures"){
// actionMessage.setCommand(1234);
// REQUIRE(actionHelper.handleActionMessage(&actionMessage) == static_cast<uint32_t>(CommandMessage::UNKNOWN_COMMAND));
// CHECK(not testMqMock.wasMessageSent());
// uint16_t step = 5;
// ReturnValue_t status = 0x1234;
// actionHelper.step(step, testMqMock.getId(), testActionId, status);
// step += 1;
// CHECK(testMqMock.wasMessageSent());
// CommandMessage testMessage;
// REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast<uint32_t>(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;
// REQUIRE(testMessage.getParameter2() == parameter2);
// REQUIRE(ActionMessage::getStep(&testMessage) == step);
// }
//
// SECTION("Handle finish"){
// CHECK(not testMqMock.wasMessageSent());
// ReturnValue_t status = 0x9876;
// actionHelper.finish(testMqMock.getId(), testActionId, status);
// CHECK(testMqMock.wasMessageSent());
// CommandMessage testMessage;
// REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast<uint32_t>(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;
// std::array<uint8_t, 5> toLongData = {5, 4, 3, 2, 1};
// REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == retval::CATCH_OK);
// ActionMessage::setCommand(&actionMessage, testActionId, toLongParamAddress);
// CHECK(not testDhMock.executeActionCalled);
// REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_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(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
// REQUIRE(ActionMessage::getReturnCode(&testMessage) == 0xAFFE);
// REQUIRE(ActionMessage::getStep(&testMessage) == 0);
// REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId);
// }
//
// SECTION("Missing IPC Data"){
// ActionMessage::setCommand(&actionMessage, testActionId, StorageManagerIF::INVALID_ADDRESS);
// CHECK(not testDhMock.executeActionCalled);
// REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK);
// CommandMessage testMessage;
// REQUIRE(testMqMock.receiveMessage(&testMessage) == static_cast<uint32_t>(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));
// REQUIRE(ActionMessage::getStep(&testMessage) == 0);
// }
//
//
// SECTION("Data Reply"){
//
// }
//}

View File

@ -1,131 +1,131 @@
#ifndef UNITTEST_HOSTED_TESTACTIONHELPER_H_
#define UNITTEST_HOSTED_TESTACTIONHELPER_H_
#include <fsfw/action/HasActionsIF.h>
#include <fsfw/ipc/MessageQueueIF.h>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <cstring>
class ActionHelperOwnerMockBase: public HasActionsIF {
public:
bool getCommandQueueCalled = false;
bool executeActionCalled = false;
static const size_t MAX_SIZE = 3;
uint8_t buffer[MAX_SIZE] = {0, 0, 0};
size_t size = 0;
MessageQueueId_t getCommandQueue() const override {
return tconst::testQueueId;
}
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) override {
executeActionCalled = true;
if(size > MAX_SIZE){
return 0xAFFE;
}
this->size = size;
memcpy(buffer, data, size);
return HasReturnvaluesIF::RETURN_OK;
}
void clearBuffer(){
this->size = 0;
for(size_t i = 0; i<MAX_SIZE; i++){
buffer[i] = 0;
}
}
void getBuffer(const uint8_t** ptr, size_t* size){
if(size != nullptr){
*size = this->size;
}
if(ptr != nullptr){
*ptr = buffer;
}
}
};
class MessageQueueMockBase: public MessageQueueIF {
public:
MessageQueueId_t myQueueId = 0;
bool defaultDestSet = false;
bool messageSent = false;
bool wasMessageSent() {
bool tempMessageSent = messageSent;
messageSent = false;
return tempMessageSent;
}
virtual ReturnValue_t reply( MessageQueueMessage* message ) {
messageSent = true;
lastMessage = (*message);
return HasReturnvaluesIF::RETURN_OK;
};
virtual ReturnValue_t receiveMessage(MessageQueueMessage* message,
MessageQueueId_t *receivedFrom) {
(*message) = lastMessage;
lastMessage.clear();
return HasReturnvaluesIF::RETURN_OK;
}
virtual ReturnValue_t receiveMessage(MessageQueueMessage* message) {
(*message) = lastMessage;
lastMessage.clear();
return HasReturnvaluesIF::RETURN_OK;
}
virtual ReturnValue_t flush(uint32_t* count) {
return HasReturnvaluesIF::RETURN_OK;
}
virtual MessageQueueId_t getLastPartner() const {
return tconst::testQueueId;
}
virtual MessageQueueId_t getId() const {
return tconst::testQueueId;
}
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom,
bool ignoreFault = false ) {
messageSent = true;
lastMessage = (*message);
return HasReturnvaluesIF::RETURN_OK;
}
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo,
MessageQueueMessage* message, bool ignoreFault = false ) override {
messageSent = true;
lastMessage = (*message);
return HasReturnvaluesIF::RETURN_OK;
}
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message,
MessageQueueId_t sentFrom, bool ignoreFault = false ) {
messageSent = true;
lastMessage = (*message);
return HasReturnvaluesIF::RETURN_OK;
}
virtual ReturnValue_t sendToDefault( MessageQueueMessage* message ) {
messageSent = true;
lastMessage = (*message);
return HasReturnvaluesIF::RETURN_OK;
}
virtual void setDefaultDestination(MessageQueueId_t defaultDestination) {
myQueueId = defaultDestination;
defaultDestSet = true;
}
virtual MessageQueueId_t getDefaultDestination() const {
return myQueueId;
}
virtual bool isDefaultDestinationSet() const {
return defaultDestSet;
}
private:
MessageQueueMessage lastMessage;
};
#endif /* UNITTEST_TESTFW_NEWTESTS_TESTACTIONHELPER_H_ */
//#ifndef UNITTEST_HOSTED_TESTACTIONHELPER_H_
//#define UNITTEST_HOSTED_TESTACTIONHELPER_H_
//
//#include <fsfw/action/HasActionsIF.h>
//#include <fsfw/ipc/MessageQueueIF.h>
//#include <fsfw/unittest/core/CatchDefinitions.h>
//#include <cstring>
//
//
//class ActionHelperOwnerMockBase: public HasActionsIF {
//public:
// bool getCommandQueueCalled = false;
// bool executeActionCalled = false;
// static const size_t MAX_SIZE = 3;
// uint8_t buffer[MAX_SIZE] = {0, 0, 0};
// size_t size = 0;
//
// MessageQueueId_t getCommandQueue() const override {
// return tconst::testQueueId;
// }
//
// ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
// const uint8_t* data, size_t size) override {
// executeActionCalled = true;
// if(size > MAX_SIZE){
// return 0xAFFE;
// }
// this->size = size;
// memcpy(buffer, data, size);
// return HasReturnvaluesIF::RETURN_OK;
// }
//
// void clearBuffer(){
// this->size = 0;
// for(size_t i = 0; i<MAX_SIZE; i++){
// buffer[i] = 0;
// }
// }
//
// void getBuffer(const uint8_t** ptr, size_t* size){
// if(size != nullptr){
// *size = this->size;
// }
// if(ptr != nullptr){
// *ptr = buffer;
// }
// }
//};
//
//
//class MessageQueueMockBase: public MessageQueueIF {
//public:
// MessageQueueId_t myQueueId = 0;
// bool defaultDestSet = false;
// bool messageSent = false;
//
//
//
// bool wasMessageSent() {
// bool tempMessageSent = messageSent;
// messageSent = false;
// return tempMessageSent;
// }
//
// virtual ReturnValue_t reply( MessageQueueMessage* message ) {
// messageSent = true;
// lastMessage = (*message);
// return HasReturnvaluesIF::RETURN_OK;
// };
// virtual ReturnValue_t receiveMessage(MessageQueueMessage* message,
// MessageQueueId_t *receivedFrom) {
// (*message) = lastMessage;
// lastMessage.clear();
// return HasReturnvaluesIF::RETURN_OK;
// }
// virtual ReturnValue_t receiveMessage(MessageQueueMessage* message) {
// (*message) = lastMessage;
// lastMessage.clear();
// return HasReturnvaluesIF::RETURN_OK;
// }
// virtual ReturnValue_t flush(uint32_t* count) {
// return HasReturnvaluesIF::RETURN_OK;
// }
// virtual MessageQueueId_t getLastPartner() const {
// return tconst::testQueueId;
// }
// virtual MessageQueueId_t getId() const {
// return tconst::testQueueId;
// }
// virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
// MessageQueueMessage* message, MessageQueueId_t sentFrom,
// bool ignoreFault = false ) {
// messageSent = true;
// lastMessage = (*message);
// return HasReturnvaluesIF::RETURN_OK;
// }
// virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo,
// MessageQueueMessage* message, bool ignoreFault = false ) override {
// messageSent = true;
// lastMessage = (*message);
// return HasReturnvaluesIF::RETURN_OK;
// }
// virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message,
// MessageQueueId_t sentFrom, bool ignoreFault = false ) {
// messageSent = true;
// lastMessage = (*message);
// return HasReturnvaluesIF::RETURN_OK;
// }
// virtual ReturnValue_t sendToDefault( MessageQueueMessage* message ) {
// messageSent = true;
// lastMessage = (*message);
// return HasReturnvaluesIF::RETURN_OK;
// }
// virtual void setDefaultDestination(MessageQueueId_t defaultDestination) {
// myQueueId = defaultDestination;
// defaultDestSet = true;
// }
//
// virtual MessageQueueId_t getDefaultDestination() const {
// return myQueueId;
// }
// virtual bool isDefaultDestinationSet() const {
// return defaultDestSet;
// }
//private:
// MessageQueueMessage lastMessage;
//
//};
//
//
//#endif /* UNITTEST_TESTFW_NEWTESTS_TESTACTIONHELPER_H_ */

View File

@ -1,6 +1,6 @@
#include <fsfw/container/SimpleRingBuffer.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <catch2/catch.hpp>
#include "../../core/CatchDefinitions.h"
#include <cstring>

View File

@ -1,7 +1,7 @@
#include <fsfw/container/ArrayList.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <catch2/catch.hpp>
#include "../../core/CatchDefinitions.h"
/**
* @brief Array List test

View File

@ -3,8 +3,8 @@
#include <fsfw/container/FIFO.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <catch2/catch.hpp>
#include "../../core/CatchDefinitions.h"
TEST_CASE( "Static Fifo Tests", "[TestFifo]") {
INFO("Fifo Tests");

View File

@ -1,8 +1,9 @@
#include "../../core/CatchDefinitions.h"
#include <fsfw/container/FixedArrayList.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <catch2/catch.hpp>
TEST_CASE( "FixedArrayList Tests", "[TestFixedArrayList]") {

View File

@ -1,8 +1,8 @@
#include <fsfw/container/FixedMap.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <catch2/catch.hpp>
#include "../../core/CatchDefinitions.h"
template class FixedMap<unsigned int, unsigned short>;

View File

@ -1,8 +1,8 @@
#include <fsfw/container/FixedOrderedMultimap.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <catch2/catch.hpp>
#include "../../core/CatchDefinitions.h"
TEST_CASE( "FixedOrderedMultimap Tests", "[TestFixedOrderedMultimap]") {
INFO("FixedOrderedMultimap Tests");

View File

@ -1,45 +1,45 @@
#include <fsfw/container/PlacementFactory.h>
#include <fsfw/storagemanager/LocalPool.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/container/ArrayList.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
TEST_CASE( "PlacementFactory Tests", "[TestPlacementFactory]") {
INFO("PlacementFactory Tests");
const uint16_t element_sizes[3] = {sizeof(uint16_t), sizeof(uint32_t), sizeof(uint64_t)};
const uint16_t n_elements[3] = {1, 1, 1};
LocalPool<3> storagePool(0x1, element_sizes, n_elements, false, true);
PlacementFactory factory(&storagePool);
SECTION("Pool overload"){
store_address_t address;
uint8_t* ptr = nullptr;
REQUIRE(storagePool.getFreeElement(&address, sizeof(ArrayList<uint32_t, uint16_t>), &ptr)
== static_cast<int>(StorageManagerIF::DATA_TOO_LARGE));
ArrayList<uint32_t, uint16_t>* list2 = factory.generate<ArrayList<uint32_t, uint16_t> >(80);
REQUIRE(list2 == nullptr);
}
SECTION("Test generate and destroy"){
uint64_t* number = factory.generate<uint64_t>(32000);
REQUIRE(number != nullptr);
REQUIRE(*number == 32000);
store_address_t address;
uint8_t* ptr = nullptr;
REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr)
== static_cast<int>(StorageManagerIF::DATA_TOO_LARGE));
uint64_t* number2 = factory.generate<uint64_t>(12345);
REQUIRE(number2 == nullptr);
REQUIRE(factory.destroy(number) == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr)
== static_cast<int>(HasReturnvaluesIF::RETURN_OK));
REQUIRE(storagePool.deleteData(address) == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
//Check that PlacementFactory checks for nullptr
ptr = nullptr;
REQUIRE(factory.destroy(ptr) == static_cast<int>(HasReturnvaluesIF::RETURN_FAILED));
}
}
//#include <fsfw/container/PlacementFactory.h>
//#include <fsfw/storagemanager/LocalPool.h>
//#include <fsfw/returnvalues/HasReturnvaluesIF.h>
//#include <fsfw/container/ArrayList.h>
//
//#include <catch2/catch.hpp>
//#include "../../core/CatchDefinitions.h"
//
//TEST_CASE( "PlacementFactory Tests", "[TestPlacementFactory]") {
// INFO("PlacementFactory Tests");
//
// const uint16_t element_sizes[3] = {sizeof(uint16_t), sizeof(uint32_t), sizeof(uint64_t)};
// const uint16_t n_elements[3] = {1, 1, 1};
// LocalPool<3> storagePool(0x1, element_sizes, n_elements, false, true);
// PlacementFactory factory(&storagePool);
//
// SECTION("Pool overload"){
// store_address_t address;
// uint8_t* ptr = nullptr;
// REQUIRE(storagePool.getFreeElement(&address, sizeof(ArrayList<uint32_t, uint16_t>), &ptr)
// == static_cast<int>(StorageManagerIF::DATA_TOO_LARGE));
// ArrayList<uint32_t, uint16_t>* list2 = factory.generate<ArrayList<uint32_t, uint16_t> >(80);
// REQUIRE(list2 == nullptr);
// }
//
// SECTION("Test generate and destroy"){
// uint64_t* number = factory.generate<uint64_t>(32000);
// REQUIRE(number != nullptr);
// REQUIRE(*number == 32000);
// store_address_t address;
// uint8_t* ptr = nullptr;
// REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr)
// == static_cast<int>(StorageManagerIF::DATA_TOO_LARGE));
// uint64_t* number2 = factory.generate<uint64_t>(12345);
// REQUIRE(number2 == nullptr);
// REQUIRE(factory.destroy(number) == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
// REQUIRE(storagePool.getFreeElement(&address, sizeof(uint64_t), &ptr)
// == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
// REQUIRE(storagePool.deleteData(address) == static_cast<int>(HasReturnvaluesIF::RETURN_OK));
//
// //Check that PlacementFactory checks for nullptr
// ptr = nullptr;
// REQUIRE(factory.destroy(ptr) == static_cast<int>(HasReturnvaluesIF::RETURN_FAILED));
// }
//}

View File

@ -1,7 +1,7 @@
#include <fsfw/serialize/SerialBufferAdapter.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <catch2/catch.hpp>
#include "../../core/CatchDefinitions.h"
static bool test_value_bool = true;

View File

@ -1,8 +1,8 @@
#include <fsfw/globalfunctions/arrayprinter.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <fsfw/unittest/tests/serialize/TestSerialLinkedPacket.h>
#include <catch2/catch.hpp>
#include "../../core/CatchDefinitions.h"
#include "TestSerialLinkedPacket.h"
TEST_CASE("Serial Linked Packet" , "[SerLinkPacket]") {

View File

@ -2,7 +2,7 @@
#include "catch.hpp"
#include <array>
#include "core/CatchDefinitions.h"
#include "../../core/CatchDefinitions.h"
static bool test_value_bool = true;
static uint8_t tv_uint8 {5};

View File

@ -1,161 +1,161 @@
#include <fsfw/storagemanager/LocalPool.h>
#include <fsfw/unittest/catch2/catch.hpp>
#include <fsfw/unittest/core/CatchDefinitions.h>
#include <array>
TEST_CASE( "New Accessor" , "[NewAccessor]") {
uint16_t numberOfElements[1] = {1};
uint16_t sizeofElements[1] = {10};
LocalPool<1> SimplePool = LocalPool<1>(0, sizeofElements, numberOfElements);
std::array<uint8_t, 20> testDataArray;
std::array<uint8_t, 20> receptionArray;
store_address_t testStoreId;
ReturnValue_t result = retval::CATCH_FAILED;
for(size_t i = 0; i < testDataArray.size(); i++) {
testDataArray[i] = i;
}
size_t size = 10;
SECTION ("Simple tests getter functions") {
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
REQUIRE(result == retval::CATCH_OK);
auto resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
resultPair.second.getDataCopy(receptionArray.data(), 20);
CHECK(resultPair.second.getId() == testStoreId);
CHECK(resultPair.second.size() == 10);
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
std::copy(resultPair.second.data(), resultPair.second.data() +
resultPair.second.size(), receptionArray.data());
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
{
auto resultPairLoc = SimplePool.getData(testStoreId);
REQUIRE(resultPairLoc.first == retval::CATCH_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);
{
ConstStorageAccessor constAccessor(testStoreId);
result = SimplePool.getData(testStoreId, constAccessor);
REQUIRE(result == retval::CATCH_OK);
constAccessor.getDataCopy(receptionArray.data(), 20);
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
// likewise, data should be deleted when accessor gets out of scope.
}
resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == (int) StorageManagerIF::DATA_DOES_NOT_EXIST);
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
{
resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
resultPair.second.release();
// now data should not be deleted anymore
}
resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
resultPair.second.getDataCopy(receptionArray.data(), 20);
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
}
SECTION("Simple tests modify functions") {
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
REQUIRE(result == retval::CATCH_OK);
{
StorageAccessor accessor(testStoreId);
result = SimplePool.modifyData(testStoreId, accessor);
REQUIRE(result == retval::CATCH_OK);
CHECK(accessor.getId() == testStoreId);
CHECK(accessor.size() == 10);
accessor.getDataCopy(receptionArray.data(), 20);
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
std::copy(accessor.data(), accessor.data() +
accessor.size(), receptionArray.data());
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
// data should be deleted when accessor goes out of scope
}
auto 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);
{
auto resultPairLoc = SimplePool.modifyData(testStoreId);
REQUIRE(resultPairLoc.first == retval::CATCH_OK);
CHECK(resultPairLoc.second.getId() == testStoreId);
CHECK(resultPairLoc.second.size() == 10);
resultPairLoc.second.getDataCopy(receptionArray.data(), 20);
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
std::copy(resultPairLoc.second.data(), resultPairLoc.second.data() +
resultPairLoc.second.size(), receptionArray.data());
for(size_t i = 0; i < size; i++) {
CHECK(receptionArray[i] == i );
}
resultPairLoc.second.release();
// data should not be deleted when accessor goes out of scope
}
resultPair = SimplePool.getData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
}
SECTION("Write tests") {
result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
REQUIRE(result == retval::CATCH_OK);
{
auto resultPair = SimplePool.modifyData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_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);
resultConstPair.second.getDataCopy(receptionArray.data(), 10);
for(size_t i = 0; i < size-1; i++) {
CHECK(receptionArray[i] == i );
}
CHECK(receptionArray[9] == 42 );
auto resultPair = SimplePool.modifyData(testStoreId);
REQUIRE(resultPair.first == retval::CATCH_OK);
result = resultPair.second.write(testDataArray.data(), 20, 0);
REQUIRE(result == retval::CATCH_FAILED);
result = resultPair.second.write(testDataArray.data(), 10, 5);
REQUIRE(result == retval::CATCH_FAILED);
memset(testDataArray.data(), 42, 5);
result = resultPair.second.write(testDataArray.data(), 5, 5);
REQUIRE(result == retval::CATCH_OK);
resultConstPair = SimplePool.getData(testStoreId);
resultPair.second.getDataCopy(receptionArray.data(), 20);
for(size_t i = 5; i < 10; i++) {
CHECK(receptionArray[i] == 42 );
}
}
}
//#include <fsfw/storagemanager/LocalPool.h>
//#include <catch2/catch.hpp>
//#include "../../core/CatchDefinitions.h"
//#include <array>
//
//TEST_CASE( "New Accessor" , "[NewAccessor]") {
// uint16_t numberOfElements[1] = {1};
// uint16_t sizeofElements[1] = {10};
// LocalPool<1> SimplePool = LocalPool<1>(0, sizeofElements, numberOfElements);
// std::array<uint8_t, 20> testDataArray;
// std::array<uint8_t, 20> receptionArray;
// store_address_t testStoreId;
// ReturnValue_t result = retval::CATCH_FAILED;
//
// for(size_t i = 0; i < testDataArray.size(); i++) {
// testDataArray[i] = i;
// }
// size_t size = 10;
//
// SECTION ("Simple tests getter functions") {
// result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
// REQUIRE(result == retval::CATCH_OK);
// auto resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// resultPair.second.getDataCopy(receptionArray.data(), 20);
// CHECK(resultPair.second.getId() == testStoreId);
// CHECK(resultPair.second.size() == 10);
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
//
// std::copy(resultPair.second.data(), resultPair.second.data() +
// resultPair.second.size(), receptionArray.data());
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
//
// {
// auto resultPairLoc = SimplePool.getData(testStoreId);
// REQUIRE(resultPairLoc.first == retval::CATCH_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);
// {
// ConstStorageAccessor constAccessor(testStoreId);
// result = SimplePool.getData(testStoreId, constAccessor);
// REQUIRE(result == retval::CATCH_OK);
// constAccessor.getDataCopy(receptionArray.data(), 20);
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// // likewise, data should be deleted when accessor gets out of scope.
// }
// resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == (int) StorageManagerIF::DATA_DOES_NOT_EXIST);
//
// result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
// {
// resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// resultPair.second.release();
// // now data should not be deleted anymore
// }
// resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// resultPair.second.getDataCopy(receptionArray.data(), 20);
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// }
//
//
// SECTION("Simple tests modify functions") {
// result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
// REQUIRE(result == retval::CATCH_OK);
// {
// StorageAccessor accessor(testStoreId);
// result = SimplePool.modifyData(testStoreId, accessor);
// REQUIRE(result == retval::CATCH_OK);
// CHECK(accessor.getId() == testStoreId);
// CHECK(accessor.size() == 10);
// accessor.getDataCopy(receptionArray.data(), 20);
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// std::copy(accessor.data(), accessor.data() +
// accessor.size(), receptionArray.data());
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// // data should be deleted when accessor goes out of scope
// }
// auto 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);
// {
// auto resultPairLoc = SimplePool.modifyData(testStoreId);
// REQUIRE(resultPairLoc.first == retval::CATCH_OK);
// CHECK(resultPairLoc.second.getId() == testStoreId);
// CHECK(resultPairLoc.second.size() == 10);
// resultPairLoc.second.getDataCopy(receptionArray.data(), 20);
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// std::copy(resultPairLoc.second.data(), resultPairLoc.second.data() +
// resultPairLoc.second.size(), receptionArray.data());
// for(size_t i = 0; i < size; i++) {
// CHECK(receptionArray[i] == i );
// }
// resultPairLoc.second.release();
// // data should not be deleted when accessor goes out of scope
// }
// resultPair = SimplePool.getData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// }
//
//
// SECTION("Write tests") {
// result = SimplePool.addData(&testStoreId, testDataArray.data(), size);
// REQUIRE(result == retval::CATCH_OK);
// {
// auto resultPair = SimplePool.modifyData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_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);
//
// resultConstPair.second.getDataCopy(receptionArray.data(), 10);
// for(size_t i = 0; i < size-1; i++) {
// CHECK(receptionArray[i] == i );
// }
// CHECK(receptionArray[9] == 42 );
//
// auto resultPair = SimplePool.modifyData(testStoreId);
// REQUIRE(resultPair.first == retval::CATCH_OK);
// result = resultPair.second.write(testDataArray.data(), 20, 0);
// REQUIRE(result == retval::CATCH_FAILED);
// result = resultPair.second.write(testDataArray.data(), 10, 5);
// REQUIRE(result == retval::CATCH_FAILED);
//
// memset(testDataArray.data(), 42, 5);
// result = resultPair.second.write(testDataArray.data(), 5, 5);
// REQUIRE(result == retval::CATCH_OK);
// resultConstPair = SimplePool.getData(testStoreId);
// resultPair.second.getDataCopy(receptionArray.data(), 20);
// for(size_t i = 5; i < 10; i++) {
// CHECK(receptionArray[i] == 42 );
// }
//
// }
//}