2024-11-04 17:32:21 +01:00
|
|
|
#include <mock/HkReceiverMock.h>
|
|
|
|
#include <mock/MessageQueueMock.h>
|
|
|
|
|
2022-07-18 08:59:40 +02:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
2022-07-18 11:58:55 +02:00
|
|
|
#include "DeviceHandlerCommander.h"
|
2024-11-04 17:32:21 +01:00
|
|
|
#include "mock/ComIFMock.h"
|
|
|
|
#include "mock/CookieIFMock.h"
|
|
|
|
#include "mock/DeviceFdirMock.h"
|
|
|
|
#include "mock/DeviceHandlerMock.h"
|
2022-07-18 11:58:55 +02:00
|
|
|
#include "objects/systemObjectList.h"
|
2022-07-18 08:59:40 +02:00
|
|
|
|
|
|
|
TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
|
|
|
|
// Will be deleted with DHB destructor
|
2022-07-18 11:58:55 +02:00
|
|
|
auto* cookieIFMock = new CookieIFMock;
|
2022-07-18 08:59:40 +02:00
|
|
|
ComIFMock comIF(objects::COM_IF_MOCK);
|
2024-11-04 17:32:21 +01:00
|
|
|
MessageQueueMock mqMock(1, MessageQueueIF::NO_QUEUE);
|
|
|
|
HkReceiverMock hkReceiver(1);
|
2022-07-18 08:59:40 +02:00
|
|
|
DeviceFdirMock deviceFdirMock(objects::DEVICE_HANDLER_MOCK, objects::NO_OBJECT);
|
|
|
|
DeviceHandlerMock deviceHandlerMock(objects::DEVICE_HANDLER_MOCK, objects::COM_IF_MOCK,
|
|
|
|
cookieIFMock, &deviceFdirMock);
|
2024-11-04 17:32:21 +01:00
|
|
|
auto& hkHelper = deviceHandlerMock.getHkHelper();
|
|
|
|
hkHelper.setHkDestinationId(1);
|
2022-07-18 08:59:40 +02:00
|
|
|
ReturnValue_t result = deviceHandlerMock.initialize();
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-07-18 08:59:40 +02:00
|
|
|
DeviceHandlerCommander deviceHandlerCommander(objects::DEVICE_HANDLER_COMMANDER);
|
|
|
|
result = deviceHandlerCommander.initialize();
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-07-18 08:59:40 +02:00
|
|
|
|
|
|
|
SECTION("Commanding nominal") {
|
|
|
|
comIF.setTestCase(ComIFMock::TestCase::SIMPLE_COMMAND_NOMINAL);
|
|
|
|
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
|
|
|
|
DeviceHandlerMock::SIMPLE_COMMAND);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-07-18 08:59:40 +02:00
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_READ);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_READ);
|
|
|
|
deviceHandlerCommander.performOperation();
|
|
|
|
result = deviceHandlerCommander.getReplyReturnCode();
|
|
|
|
uint32_t missedReplies = deviceFdirMock.getMissedReplyCount();
|
|
|
|
REQUIRE(missedReplies == 0);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-07-18 08:59:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Commanding missed reply") {
|
|
|
|
comIF.setTestCase(ComIFMock::TestCase::MISSED_REPLY);
|
|
|
|
deviceHandlerCommander.resetReplyReturnCode();
|
|
|
|
// Set the timeout to 0 to immediately timeout the reply
|
|
|
|
deviceHandlerMock.changeSimpleCommandReplyCountdown(0);
|
|
|
|
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
|
|
|
|
DeviceHandlerMock::SIMPLE_COMMAND);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-07-18 08:59:40 +02:00
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_READ);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_READ);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
|
|
|
deviceHandlerCommander.performOperation();
|
|
|
|
result = deviceHandlerCommander.getReplyReturnCode();
|
|
|
|
REQUIRE(result == DeviceHandlerIF::TIMEOUT);
|
|
|
|
uint32_t missedReplies = deviceFdirMock.getMissedReplyCount();
|
|
|
|
REQUIRE(missedReplies == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Periodic reply nominal") {
|
|
|
|
comIF.setTestCase(ComIFMock::TestCase::PERIODIC_REPLY_NOMINAL);
|
|
|
|
deviceHandlerMock.enablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_READ);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_READ);
|
|
|
|
REQUIRE(deviceHandlerMock.getPeriodicReplyReceived() == true);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Missed periodic reply") {
|
|
|
|
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.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_READ);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_READ);
|
|
|
|
uint32_t missedReplies = deviceFdirMock.getMissedReplyCount();
|
|
|
|
REQUIRE(missedReplies == 1);
|
|
|
|
// Test if disabling of periodic reply
|
|
|
|
deviceHandlerMock.disablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_READ);
|
|
|
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_READ);
|
|
|
|
missedReplies = deviceFdirMock.getMissedReplyCount();
|
|
|
|
// Should still be 1 because periodic reply is now disabled
|
|
|
|
REQUIRE(missedReplies == 1);
|
|
|
|
}
|
|
|
|
}
|