fsfw/unittests/osal/TestMessageQueue.cpp

60 lines
2.4 KiB
C++
Raw Normal View History

2020-12-27 14:20:26 +01:00
#include <fsfw/ipc/MessageQueueIF.h>
#include <fsfw/ipc/QueueFactory.h>
2020-10-20 17:11:23 +02:00
#include <array>
2022-02-02 10:29:30 +01:00
#include <catch2/catch_test_macros.hpp>
2020-10-20 17:11:23 +02:00
2022-07-18 11:58:55 +02:00
#include "CatchDefinitions.h"
2020-10-20 17:11:23 +02:00
2022-02-02 10:29:30 +01:00
TEST_CASE("MessageQueue Basic Test", "[TestMq]") {
MessageQueueIF* testSenderMq = QueueFactory::instance()->createMessageQueue(1);
MessageQueueId_t testSenderMqId = testSenderMq->getId();
MessageQueueIF* testReceiverMq = QueueFactory::instance()->createMessageQueue(1);
MessageQueueId_t testReceiverMqId = testReceiverMq->getId();
std::array<uint8_t, 20> testData{0};
testData[0] = 42;
MessageQueueMessage testMessage(testData.data(), 1);
testSenderMq->setDefaultDestination(testReceiverMqId);
SECTION("Simple Tests") {
auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
2022-08-15 20:28:16 +02:00
REQUIRE(result == returnvalue::OK);
2022-02-02 10:29:30 +01:00
MessageQueueMessage recvMessage;
result = testReceiverMq->receiveMessage(&recvMessage);
2022-08-15 20:28:16 +02:00
REQUIRE(result == returnvalue::OK);
2022-02-02 10:29:30 +01:00
CHECK(recvMessage.getData()[0] == 42);
result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
2022-08-15 20:28:16 +02:00
REQUIRE(result == returnvalue::OK);
2022-02-02 10:29:30 +01:00
MessageQueueId_t senderId = 0;
result = testReceiverMq->receiveMessage(&recvMessage, &senderId);
2022-08-15 20:28:16 +02:00
REQUIRE(result == returnvalue::OK);
2022-02-02 10:29:30 +01:00
CHECK(recvMessage.getData()[0] == 42);
CHECK(senderId == testSenderMqId);
senderId = testReceiverMq->getLastPartner();
CHECK(senderId == testSenderMqId);
}
2022-02-18 19:08:06 +01:00
SECTION("Test Full") {
auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
2022-08-15 20:28:16 +02:00
REQUIRE(result == returnvalue::OK);
2022-02-18 19:08:06 +01:00
result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
REQUIRE(result == MessageQueueIF::FULL);
// We try another message
result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
REQUIRE(result == MessageQueueIF::FULL);
MessageQueueMessage recvMessage;
result = testReceiverMq->receiveMessage(&recvMessage);
2022-08-15 20:28:16 +02:00
REQUIRE(result == returnvalue::OK);
2022-02-18 19:08:06 +01:00
CHECK(recvMessage.getData()[0] == 42);
result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
2022-08-15 20:28:16 +02:00
REQUIRE(result == returnvalue::OK);
2022-02-18 19:08:06 +01:00
result = testReceiverMq->receiveMessage(&recvMessage);
2022-08-15 20:28:16 +02:00
REQUIRE(result == returnvalue::OK);
2022-02-18 19:08:06 +01:00
CHECK(recvMessage.getData()[0] == 42);
}
// We have to clear MQs ourself ATM
QueueFactory::instance()->deleteMessageQueue(testSenderMq);
QueueFactory::instance()->deleteMessageQueue(testReceiverMq);
2020-10-20 17:11:23 +02:00
}