fixed DHB unittest for new Actions

This commit is contained in:
Ulrich Mohr 2022-09-14 17:04:17 +02:00
parent 6c711415c1
commit c42da5df86
3 changed files with 37 additions and 26 deletions

View File

@ -23,7 +23,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
SECTION("Commanding nominal") {
comIF.setTestCase(ComIFMock::TestCase::SIMPLE_COMMAND_NOMINAL);
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
DeviceHandlerMock::SIMPLE_COMMAND);
static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND));
REQUIRE(result == returnvalue::OK);
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
@ -43,7 +43,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
// Set the timeout to 0 to immediately timeout the reply
deviceHandlerMock.changeSimpleCommandReplyCountdown(0);
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
DeviceHandlerMock::SIMPLE_COMMAND);
static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND));
REQUIRE(result == returnvalue::OK);
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
@ -60,7 +60,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
SECTION("Periodic reply nominal") {
comIF.setTestCase(ComIFMock::TestCase::PERIODIC_REPLY_NOMINAL);
deviceHandlerMock.enablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY);
deviceHandlerMock.enablePeriodicReply(static_cast<uint32_t>(MockCommands::PERIODIC_REPLY));
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
@ -73,7 +73,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
comIF.setTestCase(ComIFMock::TestCase::MISSED_REPLY);
// Set the timeout to 0 to immediately timeout the reply
deviceHandlerMock.changePeriodicReplyCountdown(0);
deviceHandlerMock.enablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY);
deviceHandlerMock.enablePeriodicReply(static_cast<uint32_t>(MockCommands::PERIODIC_REPLY));
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
@ -82,7 +82,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
uint32_t missedReplies = deviceFdirMock.getMissedReplyCount();
REQUIRE(missedReplies == 1);
// Test if disabling of periodic reply
deviceHandlerMock.disablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY);
deviceHandlerMock.disablePeriodicReply(static_cast<uint32_t>(MockCommands::PERIODIC_REPLY));
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);

View File

@ -25,17 +25,13 @@ ReturnValue_t DeviceHandlerMock::buildTransitionDeviceCommand(DeviceCommandId_t
ReturnValue_t DeviceHandlerMock::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData,
size_t commandDataLen) {
switch (deviceCommand) {
case SIMPLE_COMMAND: {
commandBuffer[0] = SIMPLE_COMMAND_DATA;
rawPacket = commandBuffer;
rawPacketLen = sizeof(SIMPLE_COMMAND_DATA);
break;
}
default:
WARN("DeviceHandlerMock::buildCommandFromCommand: Invalid device command");
break;
}
return returnvalue::OK;
}
ReturnValue_t DeviceHandlerMock::handleAction(MockAction *action) {
commandBuffer[0] = SIMPLE_COMMAND_DATA;
rawPacket = commandBuffer;
rawPacketLen = sizeof(SIMPLE_COMMAND_DATA);
return returnvalue::OK;
}
@ -43,13 +39,13 @@ ReturnValue_t DeviceHandlerMock::scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) {
switch (*start) {
case SIMPLE_COMMAND_DATA: {
*foundId = SIMPLE_COMMAND;
*foundId = static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND);
*foundLen = sizeof(SIMPLE_COMMAND_DATA);
return returnvalue::OK;
break;
}
case PERIODIC_REPLY_DATA: {
*foundId = PERIODIC_REPLY;
*foundId = static_cast<uint32_t>(MockCommands::PERIODIC_REPLY);
*foundLen = sizeof(PERIODIC_REPLY_DATA);
return returnvalue::OK;
break;
@ -62,8 +58,8 @@ ReturnValue_t DeviceHandlerMock::scanForReply(const uint8_t *start, size_t len,
ReturnValue_t DeviceHandlerMock::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
switch (id) {
case SIMPLE_COMMAND:
case PERIODIC_REPLY: {
case static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND):
case static_cast<uint32_t>(MockCommands::PERIODIC_REPLY): {
periodicReplyReceived = true;
break;
}
@ -74,10 +70,10 @@ ReturnValue_t DeviceHandlerMock::interpretDeviceReply(DeviceCommandId_t id, cons
}
void DeviceHandlerMock::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(SIMPLE_COMMAND, 0, nullptr, 0, false, false, 0,
&simpleCommandReplyTimeout);
insertInCommandAndReplyMap(PERIODIC_REPLY, 0, nullptr, 0, true, false, 0,
&periodicReplyCountdown);
insertInCommandAndReplyMap(static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND), 0, nullptr, 0,
false, false, 0, &simpleCommandReplyTimeout);
insertInCommandAndReplyMap(static_cast<uint32_t>(MockCommands::PERIODIC_REPLY), 0, nullptr, 0,
true, false, 0, &periodicReplyCountdown);
}
uint32_t DeviceHandlerMock::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }

View File

@ -2,11 +2,22 @@
#define TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <fsfw/introspection/Enum.h>
#include <fsfw/action/TemplateAction.h>
FSFW_ENUM(MockCommands, ActionId_t, ((SIMPLE_COMMAND, 1, "Simple Command")) ((PERIODIC_REPLY, 2, "Periodic Reply")))
class DeviceHandlerMock;
class MockAction : public TemplateAction<DeviceHandlerMock, MockAction, MockCommands> {
public:
MockAction(DeviceHandlerMock *owner): TemplateAction(owner, MockCommands::SIMPLE_COMMAND) {
}
};
class DeviceHandlerMock : public DeviceHandlerBase {
public:
static const DeviceCommandId_t SIMPLE_COMMAND = 1;
static const DeviceCommandId_t PERIODIC_REPLY = 2;
static const uint8_t SIMPLE_COMMAND_DATA = 1;
static const uint8_t PERIODIC_REPLY_DATA = 2;
@ -21,6 +32,8 @@ class DeviceHandlerMock : public DeviceHandlerBase {
ReturnValue_t enablePeriodicReply(DeviceCommandId_t replyId);
ReturnValue_t disablePeriodicReply(DeviceCommandId_t replyId);
ReturnValue_t handleAction(MockAction * action);
protected:
void doStartUp() override;
void doShutDown() override;
@ -41,6 +54,8 @@ class DeviceHandlerMock : public DeviceHandlerBase {
uint8_t commandBuffer[1];
bool periodicReplyReceived = false;
MockAction mockAction = MockAction(this);
};
#endif /* TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_ */