fsfw/tests/src/fsfw_tests/unit/devicehandler/TestDeviceHandlerBase.cpp

62 lines
3.0 KiB
C++
Raw Normal View History

2022-05-16 11:10:35 +02:00
#include <catch2/catch_test_macros.hpp>
2022-06-05 12:52:55 +02:00
#include "ComIFMock.h"
#include "DeviceFdirMock.h"
2022-05-16 11:10:35 +02:00
#include "fsfw_tests/unit/devicehandler/CookieIFMock.h"
2022-06-05 12:52:55 +02:00
#include "fsfw_tests/unit/devicehandler/DeviceHandlerCommander.h"
#include "fsfw_tests/unit/devicehandler/DeviceHandlerMock.h"
2022-05-16 11:10:35 +02:00
#include "fsfw_tests/unit/testcfg/objects/systemObjectList.h"
TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
2022-06-05 12:52:55 +02:00
// Will be deleted with DHB destructor
CookieIFMock* cookieIFMock = new CookieIFMock;
ComIFMock comIF(objects::COM_IF_MOCK);
DeviceFdirMock deviceFdirMock(objects::DEVICE_HANDLER_MOCK, objects::NO_OBJECT);
DeviceHandlerMock deviceHandlerMock(objects::DEVICE_HANDLER_MOCK, objects::COM_IF_MOCK,
cookieIFMock, &deviceFdirMock);
ReturnValue_t result = deviceHandlerMock.initialize();
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
DeviceHandlerCommander deviceHandlerCommander(objects::DEVICE_HANDLER_COMMANDER);
result = deviceHandlerCommander.initialize();
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
SECTION("Commanding") {
comIF.setTestCase(ComIFMock::TestCase::SIMPLE_COMMAND_NOMINAL);
2022-05-16 11:10:35 +02:00
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
2022-06-05 12:52:55 +02:00
DeviceHandlerMock::SIMPLE_COMMAND);
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
2022-05-16 11:10:35 +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);
2022-06-05 12:52:55 +02:00
deviceHandlerCommander.performOperation();
2022-05-16 11:10:35 +02:00
result = deviceHandlerCommander.getReplyReturnCode();
2022-06-05 12:52:55 +02:00
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
}
SECTION("Periodic reply") {
comIF.setTestCase(ComIFMock::TestCase::PERIODIC_REPLY_NOMINAL);
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.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);
2022-05-16 11:10:35 +02:00
}
}