unit test for detection of missed reply when commanded externally

This commit is contained in:
Jakob Meier 2022-06-06 10:53:08 +02:00
parent 161dbde0d7
commit 4fba2704aa
4 changed files with 31 additions and 4 deletions

View File

@ -6,7 +6,8 @@
/**
* @brief The ComIFMock supports the simulation of various device communication error cases
* like incomplete or wrong replies and can be used to test the DeviceHandlerBase.
* like incomplete or wrong replies and can be used to test the
* DeviceHandlerBase.
*/
class ComIFMock : public DeviceCommunicationIF, public SystemObject {
public:

View File

@ -83,7 +83,11 @@ void DeviceHandlerMock::fillCommandAndReplyMap() {
uint32_t DeviceHandlerMock::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }
void DeviceHandlerMock::changePeriodicReplyCountdown(uint32_t timeout) {
periodicReplyCountdown.setTimeout(0);
periodicReplyCountdown.setTimeout(timeout);
}
void DeviceHandlerMock::changeSimpleCommandReplyCountdown(uint32_t timeout) {
simpleCommandReplyTimeout.setTimeout(timeout);
}
void DeviceHandlerMock::resetPeriodicReplyState() {

View File

@ -16,6 +16,7 @@ public:
CookieIF *comCookie, FailureIsolationBase* fdirInstance);
virtual ~DeviceHandlerMock();
void changePeriodicReplyCountdown(uint32_t timeout);
void changeSimpleCommandReplyCountdown(uint32_t timeout);
void resetPeriodicReplyState();
bool getPeriodicReplyReceived();

View File

@ -21,7 +21,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
result = deviceHandlerCommander.initialize();
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
SECTION("Commanding") {
SECTION("Commanding nominal") {
comIF.setTestCase(ComIFMock::TestCase::SIMPLE_COMMAND_NOMINAL);
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
DeviceHandlerMock::SIMPLE_COMMAND);
@ -36,7 +36,28 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
}
SECTION("Periodic reply") {
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);
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
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.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);