more tests added
This commit is contained in:
parent
918200e88c
commit
b570da6467
@ -4,6 +4,7 @@
|
|||||||
#include "locPoolDefinitions.h"
|
#include "locPoolDefinitions.h"
|
||||||
|
|
||||||
#include "../datapool/PoolEntryIF.h"
|
#include "../datapool/PoolEntryIF.h"
|
||||||
|
#include "../serviceinterface/ServiceInterface.h"
|
||||||
#include "../ipc/MessageQueueSenderIF.h"
|
#include "../ipc/MessageQueueSenderIF.h"
|
||||||
#include "../housekeeping/HousekeepingMessage.h"
|
#include "../housekeeping/HousekeepingMessage.h"
|
||||||
|
|
||||||
@ -92,6 +93,9 @@ public:
|
|||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::warning << "HasLocalDataPoolIF::getPoolObjectHandle: Not overriden"
|
sif::warning << "HasLocalDataPoolIF::getPoolObjectHandle: Not overriden"
|
||||||
<< ". Returning nullptr!" << std::endl;
|
<< ". Returning nullptr!" << std::endl;
|
||||||
|
#else
|
||||||
|
fsfw::printWarning("HasLocalDataPoolIF::getPoolObjectHandle: "
|
||||||
|
"Not overriden. Returning nullptr!\n");
|
||||||
#endif
|
#endif
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
#include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
|
||||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||||
|
#include <fsfw/ipc/CommandMessageCleaner.h>
|
||||||
#include <unittest/core/CatchDefinitions.h>
|
#include <unittest/core/CatchDefinitions.h>
|
||||||
|
|
||||||
|
|
||||||
@ -17,12 +18,49 @@ TEST_CASE("LocalPoolManagerTest" , "[LocManTest]") {
|
|||||||
MessageQueueMockBase* mqMock = poolOwner->getMockQueueHandle();
|
MessageQueueMockBase* mqMock = poolOwner->getMockQueueHandle();
|
||||||
REQUIRE(mqMock != nullptr);
|
REQUIRE(mqMock != nullptr);
|
||||||
|
|
||||||
poolOwner->subscribeWrapperSetUpdate();
|
|
||||||
SECTION("BasicTest") {
|
SECTION("BasicTest") {
|
||||||
|
// Subscribe for message generation on update.
|
||||||
|
REQUIRE(poolOwner->subscribeWrapperSetUpdate() == retval::CATCH_OK);
|
||||||
|
// Subscribe for an update message.
|
||||||
poolOwner->dataset.setChanged(true);
|
poolOwner->dataset.setChanged(true);
|
||||||
|
// Now the update message should be generated.
|
||||||
REQUIRE(poolOwner->hkManager.performHkOperation() == retval::CATCH_OK);
|
REQUIRE(poolOwner->hkManager.performHkOperation() == retval::CATCH_OK);
|
||||||
REQUIRE(mqMock->wasMessageSent() == true);
|
REQUIRE(mqMock->wasMessageSent() == true);
|
||||||
|
CommandMessage messageSent;
|
||||||
|
uint8_t messagesSent = 0;
|
||||||
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||||
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
||||||
|
HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||||
|
|
||||||
|
// Should have been reset.
|
||||||
|
CHECK(poolOwner->dataset.hasChanged() == false);
|
||||||
|
// Set changed again, result should be the same.
|
||||||
|
poolOwner->dataset.setChanged(true);
|
||||||
|
REQUIRE(poolOwner->hkManager.performHkOperation() == retval::CATCH_OK);
|
||||||
|
|
||||||
|
REQUIRE(mqMock->wasMessageSent(&messagesSent) == true);
|
||||||
|
CHECK(messagesSent == 1);
|
||||||
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||||
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
||||||
|
HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||||
|
|
||||||
|
// now subscribe for set update HK as well.
|
||||||
|
REQUIRE(poolOwner->subscribeWrapperSetUpdateHk() == retval::CATCH_OK);
|
||||||
|
poolOwner->dataset.setChanged(true);
|
||||||
|
REQUIRE(poolOwner->hkManager.performHkOperation() == retval::CATCH_OK);
|
||||||
|
REQUIRE(mqMock->wasMessageSent(&messagesSent) == true);
|
||||||
|
CHECK(messagesSent == 2);
|
||||||
|
// first message sent should be the update notification, considering
|
||||||
|
// the internal list is a vector checked in insertion order.
|
||||||
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||||
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
||||||
|
HousekeepingMessage::UPDATE_NOTIFICATION_SET));
|
||||||
|
|
||||||
|
REQUIRE(mqMock->receiveMessage(&messageSent) == retval::CATCH_OK);
|
||||||
|
CHECK(messageSent.getCommand() == static_cast<int>(
|
||||||
|
HousekeepingMessage::HK_REPORT));
|
||||||
|
CommandMessageCleaner::clearCommandMessage(&messageSent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ static constexpr lp_id_t uint16Vec3Id = 3;
|
|||||||
static constexpr lp_id_t int64Vec2Id = 4;
|
static constexpr lp_id_t int64Vec2Id = 4;
|
||||||
|
|
||||||
static constexpr uint32_t testSetId = 0;
|
static constexpr uint32_t testSetId = 0;
|
||||||
|
static const sid_t testSid = sid_t(objects::TEST_LOCAL_POOL_OWNER_BASE,
|
||||||
|
testSetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -123,12 +125,27 @@ public:
|
|||||||
return &dataset;
|
return &dataset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual LocalPoolObjectBase* getPoolObjectHandle(
|
||||||
|
lp_id_t localPoolId) override {
|
||||||
|
return &testUint8;
|
||||||
|
}
|
||||||
|
|
||||||
MessageQueueMockBase* getMockQueueHandle() const {
|
MessageQueueMockBase* getMockQueueHandle() const {
|
||||||
return dynamic_cast<MessageQueueMockBase*>(messageQueue);
|
return dynamic_cast<MessageQueueMockBase*>(messageQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void subscribeWrapperSetUpdate() {
|
ReturnValue_t subscribeWrapperSetUpdate() {
|
||||||
hkManager.subscribeForSetUpdateMessages(lpool::testSetId,
|
return hkManager.subscribeForSetUpdateMessages(lpool::testSetId,
|
||||||
|
objects::NO_OBJECT, MessageQueueIF::NO_QUEUE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t subscribeWrapperSetUpdateHk(bool diagnostics = false) {
|
||||||
|
return hkManager.subscribeForUpdatePackets(lpool::testSid, diagnostics,
|
||||||
|
false, objects::HK_RECEIVER_MOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t subscribeWrapperVariableUpdate() {
|
||||||
|
return hkManager.subscribeForSetUpdateMessages(lpool::testSetId,
|
||||||
objects::NO_OBJECT, MessageQueueIF::NO_QUEUE, false);
|
objects::NO_OBJECT, MessageQueueIF::NO_QUEUE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
unittest/tests/mocks/HkReceiverMock.h
Normal file
20
unittest/tests/mocks/HkReceiverMock.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef FSFW_UNITTEST_TESTS_MOCKS_HKRECEIVERMOCK_H_
|
||||||
|
#define FSFW_UNITTEST_TESTS_MOCKS_HKRECEIVERMOCK_H_
|
||||||
|
|
||||||
|
#include <fsfw/housekeeping/AcceptsHkPacketsIF.h>
|
||||||
|
#include <fsfw/objectmanager/SystemObject.h>
|
||||||
|
|
||||||
|
class HkReceiverMock: public SystemObject, public AcceptsHkPacketsIF {
|
||||||
|
public:
|
||||||
|
HkReceiverMock(object_id_t objectId): SystemObject(objectId) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageQueueId_t getHkQueue() const {
|
||||||
|
return MessageQueueIF::NO_QUEUE;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* FSFW_UNITTEST_TESTS_MOCKS_HKRECEIVERMOCK_H_ */
|
@ -6,68 +6,81 @@
|
|||||||
#include <unittest/core/CatchDefinitions.h>
|
#include <unittest/core/CatchDefinitions.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
class MessageQueueMockBase: public MessageQueueIF {
|
class MessageQueueMockBase: public MessageQueueIF {
|
||||||
public:
|
public:
|
||||||
MessageQueueId_t myQueueId = 0;
|
MessageQueueId_t myQueueId = tconst::testQueueId;
|
||||||
|
uint8_t messageSentCounter = 0;
|
||||||
bool defaultDestSet = false;
|
bool defaultDestSet = false;
|
||||||
bool messageSent = false;
|
bool messageSent = false;
|
||||||
|
|
||||||
|
|
||||||
bool wasMessageSent() {
|
bool wasMessageSent(uint8_t* messageSentCounter = nullptr,
|
||||||
|
bool resetCounter = true) {
|
||||||
bool tempMessageSent = messageSent;
|
bool tempMessageSent = messageSent;
|
||||||
messageSent = false;
|
messageSent = false;
|
||||||
|
if(messageSentCounter != nullptr) {
|
||||||
|
*messageSentCounter = this->messageSentCounter;
|
||||||
|
}
|
||||||
|
if(resetCounter) {
|
||||||
|
this->messageSentCounter = 0;
|
||||||
|
}
|
||||||
return tempMessageSent;
|
return tempMessageSent;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ReturnValue_t reply( MessageQueueMessageIF* message ) {
|
virtual ReturnValue_t reply( MessageQueueMessageIF* message ) {
|
||||||
messageSent = true;
|
//messageSent = true;
|
||||||
lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
||||||
|
return sendMessage(myQueueId, message);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
};
|
};
|
||||||
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
|
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
|
||||||
MessageQueueId_t *receivedFrom) {
|
MessageQueueId_t *receivedFrom) {
|
||||||
(*message) = lastMessage;
|
return receiveMessage(message);
|
||||||
lastMessage.clear();
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
}
|
||||||
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) {
|
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) {
|
||||||
std::memcpy(message->getBuffer(), lastMessage.getBuffer(),
|
std::memcpy(message->getBuffer(), messagesSentQueue.front().getBuffer(),
|
||||||
message->getMessageSize());
|
message->getMessageSize());
|
||||||
lastMessage.clear();
|
messagesSentQueue.pop();
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
virtual ReturnValue_t flush(uint32_t* count) {
|
virtual ReturnValue_t flush(uint32_t* count) {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
virtual MessageQueueId_t getLastPartner() const {
|
virtual MessageQueueId_t getLastPartner() const {
|
||||||
return tconst::testQueueId;
|
return myQueueId;
|
||||||
}
|
}
|
||||||
virtual MessageQueueId_t getId() const {
|
virtual MessageQueueId_t getId() const {
|
||||||
return tconst::testQueueId;
|
return myQueueId;
|
||||||
}
|
}
|
||||||
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
|
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
|
||||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
||||||
bool ignoreFault = false ) {
|
bool ignoreFault = false ) {
|
||||||
messageSent = true;
|
//messageSent = true;
|
||||||
lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
//return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
return sendMessage(sendTo, message);
|
||||||
|
}
|
||||||
|
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
|
||||||
|
MessageQueueId_t sentFrom, bool ignoreFault = false ) {
|
||||||
|
//messageSent = true;
|
||||||
|
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
||||||
|
//return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
return sendMessage(myQueueId, message);
|
||||||
|
}
|
||||||
|
virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message ) {
|
||||||
|
//messageSent = true;
|
||||||
|
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
||||||
|
return sendMessage(myQueueId, message);
|
||||||
}
|
}
|
||||||
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo,
|
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo,
|
||||||
MessageQueueMessageIF* message, bool ignoreFault = false ) override {
|
MessageQueueMessageIF* message, bool ignoreFault = false ) override {
|
||||||
messageSent = true;
|
messageSent = true;
|
||||||
lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
messageSentCounter++;
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
MessageQueueMessage& messageRef = *(
|
||||||
}
|
dynamic_cast<MessageQueueMessage*>(message));
|
||||||
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
|
messagesSentQueue.push(messageRef);
|
||||||
MessageQueueId_t sentFrom, bool ignoreFault = false ) {
|
|
||||||
messageSent = true;
|
|
||||||
lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message ) {
|
|
||||||
messageSent = true;
|
|
||||||
lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
virtual void setDefaultDestination(MessageQueueId_t defaultDestination) {
|
virtual void setDefaultDestination(MessageQueueId_t defaultDestination) {
|
||||||
@ -81,9 +94,16 @@ public:
|
|||||||
virtual bool isDefaultDestinationSet() const {
|
virtual bool isDefaultDestinationSet() const {
|
||||||
return defaultDestSet;
|
return defaultDestSet;
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
MessageQueueMessage lastMessage;
|
|
||||||
|
|
||||||
|
void clearMessages() {
|
||||||
|
while(not messagesSentQueue.empty()) {
|
||||||
|
messagesSentQueue.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::queue<MessageQueueMessage> messagesSentQueue;
|
||||||
|
//MessageQueueMessage lastMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ namespace objects {
|
|||||||
TEST_ECHO_COM_IF = 20,
|
TEST_ECHO_COM_IF = 20,
|
||||||
TEST_DEVICE = 21,
|
TEST_DEVICE = 21,
|
||||||
|
|
||||||
|
HK_RECEIVER_MOCK = 22,
|
||||||
TEST_LOCAL_POOL_OWNER_BASE = 25
|
TEST_LOCAL_POOL_OWNER_BASE = 25
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user