Merge remote-tracking branch 'sidestream/mohr_introspection' into mohr_other_introspection
This commit is contained in:
@ -9,37 +9,35 @@
|
||||
#include "fsfw_tests/unit/mocks/MessageQueueMockBase.h"
|
||||
|
||||
TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||
ActionHelperOwnerMockBase testDhMock;
|
||||
|
||||
MessageQueueMockBase testMqMock;
|
||||
ActionHelper actionHelper = ActionHelper(&testDhMock, dynamic_cast<MessageQueueIF*>(&testMqMock));
|
||||
ActionHelperOwnerMockBase testDhMock(&testMqMock);
|
||||
CommandMessage actionMessage;
|
||||
ActionId_t testActionId = 777;
|
||||
ActionId_t testActionId = (ActionId_t) TestActions::TEST_ACTION;
|
||||
std::array<uint8_t, 3> testParams{1, 2, 3};
|
||||
store_address_t paramAddress;
|
||||
StorageManagerIF* ipcStore = tglob::getIpcStoreHandle();
|
||||
REQUIRE(ipcStore != nullptr);
|
||||
ipcStore->addData(¶mAddress, testParams.data(), 3);
|
||||
REQUIRE(actionHelper.initialize() == retval::CATCH_OK);
|
||||
REQUIRE(testDhMock.getActionHelper()->initialize() == retval::CATCH_OK);
|
||||
|
||||
SECTION("Simple tests") {
|
||||
ActionMessage::setCommand(&actionMessage, testActionId, paramAddress);
|
||||
CHECK(not testDhMock.executeActionCalled);
|
||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK);
|
||||
REQUIRE(testDhMock.getActionHelper()->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);
|
||||
testDhMock.getActionHelper()->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);
|
||||
testDhMock.getBuffer(&ptr);
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
REQUIRE(ptr[i] == (i + 1));
|
||||
}
|
||||
@ -48,12 +46,12 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||
|
||||
SECTION("Handle failures") {
|
||||
actionMessage.setCommand(1234);
|
||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) ==
|
||||
REQUIRE(testDhMock.getActionHelper()->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);
|
||||
testDhMock.getActionHelper()->step(step, testMqMock.getId(), testActionId, status);
|
||||
step += 1;
|
||||
CHECK(testMqMock.wasMessageSent());
|
||||
CommandMessage testMessage;
|
||||
@ -69,7 +67,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||
SECTION("Handle finish") {
|
||||
CHECK(not testMqMock.wasMessageSent());
|
||||
ReturnValue_t status = 0x9876;
|
||||
actionHelper.finish(false, testMqMock.getId(), testActionId, status);
|
||||
testDhMock.getActionHelper()->finish(false, testMqMock.getId(), testActionId, status);
|
||||
CHECK(testMqMock.wasMessageSent());
|
||||
CommandMessage testMessage;
|
||||
REQUIRE(testMqMock.receiveMessage(&testMessage) ==
|
||||
@ -85,14 +83,14 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||
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(testDhMock.getActionHelper()->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::getReturnCode(&testMessage) == HasActionsIF::INVALID_PARAMETERS);
|
||||
REQUIRE(ActionMessage::getStep(&testMessage) == 0);
|
||||
REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId);
|
||||
}
|
||||
@ -100,7 +98,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||
SECTION("Missing IPC Data") {
|
||||
ActionMessage::setCommand(&actionMessage, testActionId, StorageManagerIF::INVALID_ADDRESS);
|
||||
CHECK(not testDhMock.executeActionCalled);
|
||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == retval::CATCH_OK);
|
||||
REQUIRE(testDhMock.getActionHelper()->handleActionMessage(&actionMessage) == retval::CATCH_OK);
|
||||
CommandMessage testMessage;
|
||||
REQUIRE(testMqMock.receiveMessage(&testMessage) ==
|
||||
static_cast<uint32_t>(HasReturnvaluesIF::RETURN_OK));
|
||||
|
@ -2,12 +2,27 @@
|
||||
#define UNITTEST_HOSTED_TESTACTIONHELPER_H_
|
||||
|
||||
#include <fsfw/action/HasActionsIF.h>
|
||||
#include <fsfw/action/Parameter.h>
|
||||
#include <fsfw/action/TemplateAction.h>
|
||||
#include <fsfw/introspection/Enum.h>
|
||||
#include <fsfw/ipc/MessageQueueIF.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "fsfw_tests/unit/CatchDefinitions.h"
|
||||
|
||||
class ActionHelperOwnerMockBase;
|
||||
|
||||
FSFW_ENUM(TestActions, ActionId_t, ((TEST_ACTION, "Test Action")))
|
||||
|
||||
class TestAction : public TemplateAction < ActionHelperOwnerMockBase, TestAction, TestActions> {
|
||||
public:
|
||||
TestAction(ActionHelperOwnerMockBase* owner) : TemplateAction(owner, TestActions::TEST_ACTION) {}
|
||||
Parameter<uint8_t> p1 = Parameter<uint8_t>::createParameter(this, "An uint8_t");
|
||||
Parameter<uint8_t> p2 = Parameter<uint8_t>::createParameter(this, "An uint8_t");
|
||||
Parameter<uint8_t> p3 = Parameter<uint8_t>::createParameter(this, "An uint8_t");
|
||||
};
|
||||
|
||||
class ActionHelperOwnerMockBase : public HasActionsIF {
|
||||
public:
|
||||
bool getCommandQueueCalled = false;
|
||||
@ -16,16 +31,26 @@ class ActionHelperOwnerMockBase : public HasActionsIF {
|
||||
uint8_t buffer[MAX_SIZE] = {0, 0, 0};
|
||||
size_t size = 0;
|
||||
|
||||
ActionHelperOwnerMockBase(MessageQueueIF* useThisQueue) : actionHelper(this, useThisQueue) {}
|
||||
|
||||
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 {
|
||||
ActionHelper* getActionHelper() override { return &actionHelper; }
|
||||
|
||||
ReturnValue_t executeAction(Action* action, MessageQueueId_t commandedBy) override {
|
||||
executeActionCalled = true;
|
||||
if (size > MAX_SIZE) {
|
||||
return 0xAFFE;
|
||||
}
|
||||
this->size = size;
|
||||
memcpy(buffer, data, size);
|
||||
return action->handle();
|
||||
}
|
||||
|
||||
ReturnValue_t handleAction(TestAction *action){
|
||||
executeActionCalled = true;
|
||||
buffer[0] = action->p1;
|
||||
buffer[1] = action->p2;
|
||||
buffer[2] = action->p3;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -36,14 +61,15 @@ class ActionHelperOwnerMockBase : public HasActionsIF {
|
||||
}
|
||||
}
|
||||
|
||||
void getBuffer(const uint8_t** ptr, size_t* size) {
|
||||
if (size != nullptr) {
|
||||
*size = this->size;
|
||||
}
|
||||
void getBuffer(const uint8_t** ptr) {
|
||||
if (ptr != nullptr) {
|
||||
*ptr = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
ActionHelper actionHelper;
|
||||
TestAction testAction = TestAction(this);
|
||||
};
|
||||
|
||||
#endif /* UNITTEST_TESTFW_NEWTESTS_TESTACTIONHELPER_H_ */
|
||||
|
Reference in New Issue
Block a user