added EventManagerMock, to be extended and moved into fsfw some day
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
Ulrich Mohr 2022-02-16 18:15:06 +01:00
parent e95647c572
commit 3400c538b3
10 changed files with 98 additions and 52 deletions

View File

@ -11,6 +11,9 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
target_sources(${OBSW_NAME} PRIVATE
objects/translateObjects.cpp
)
target_sources(${UNITTEST_NAME} PRIVATE
objects/translateObjects.cpp
)
endif()
# If a special translation file for events exists, compile it.
@ -18,4 +21,7 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
target_sources(${OBSW_NAME} PRIVATE
events/translateEvents.cpp
)
target_sources(${UNITTEST_NAME} PRIVATE
events/translateEvents.cpp
)
endif()

View File

@ -12,6 +12,9 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
target_sources(${OBSW_NAME} PRIVATE
objects/translateObjects.cpp
)
target_sources(${UNITTEST_NAME} PRIVATE
objects/translateObjects.cpp
)
endif()
# If a special translation file for events exists, compile it.
@ -19,4 +22,7 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp")
target_sources(${OBSW_NAME} PRIVATE
events/translateEvents.cpp
)
target_sources(${UNITTEST_NAME} PRIVATE
events/translateEvents.cpp
)
endif()

View File

@ -1,5 +1,5 @@
add_subdirectory(controller)
add_subdirectory(mocks)
target_sources(${UNITTEST_NAME} PRIVATE
main.cpp

View File

@ -3,45 +3,17 @@
#include <fsfw/housekeeping/AcceptsHkPacketsIF.h>
#include <fsfw/internalerror/InternalErrorReporter.h>
#include <fsfw/ipc/QueueFactory.h>
#include <fsfw/objectmanager.h>
#include <fsfw/storagemanager/PoolManager.h>
#include <fsfw/timemanager/TimeStamper.h>
#include <mission/controller/ThermalController.h>
#include <catch2/catch_test_macros.hpp>
class HkDummy : public SystemObject, public AcceptsHkPacketsIF {
public:
HkDummy() : SystemObject(objects::PUS_SERVICE_3_HOUSEKEEPING) {}
virtual MessageQueueId_t getHkQueue() const { return MessageQueueIF::NO_QUEUE; }
};
void factory(void* args) {
new HkDummy();
new HealthTable(objects::HEALTH_TABLE);
new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER);
new TimeStamper(objects::TIME_STAMPER);
{
PoolManager::LocalPoolConfig poolCfg = {{300, 16}, {200, 32}, {150, 64}, {150, 128},
{100, 256}, {50, 512}, {50, 1024}, {10, 2048}};
new PoolManager(objects::IPC_STORE, poolCfg);
}
}
TEST_CASE("Thermal Controller", "[ThermalController]") {
const object_id_t THERMAL_CONTROLLER_ID = 0x123;
ThermalController controller(THERMAL_CONTROLLER_ID, objects::NO_OBJECT);
ObjectManager::instance()->setObjectFactoryFunction(factory, nullptr);
ObjectManager::instance()->initialize();
ObjectManager::instance()->printList();
controller.initializeAfterTaskCreation();
MessageQueueId_t controllerQueue = controller.getCommandQueue();
@ -65,5 +37,9 @@ TEST_CASE("Thermal Controller", "[ThermalController]") {
componentTemperatures.commit();
ExecutableObjectIF *eventmanager = ObjectManager::instance()->get<ExecutableObjectIF>(objects::EVENT_MANAGER);
eventmanager->performOperation();
QueueFactory::instance()->deleteMessageQueue(commandQueue);
}

View File

@ -1,6 +1,33 @@
#include <fsfw/events/EventManager.h>
#include <fsfw/health/HealthTable.h>
#include <fsfw/housekeeping/AcceptsHkPacketsIF.h>
#include <fsfw/internalerror/InternalErrorReporter.h>
#include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/storagemanager/PoolManager.h>
#include <fsfw/timemanager/TimeStamper.h>
#include <catch2/catch_session.hpp>
#include "mocks/EventManagerMock.h"
#include "mocks/HouseKeepingMock.h"
void factory(void* args) {
new HouseKeepingMock();
new EventManagerMock();
new HealthTable(objects::HEALTH_TABLE);
new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER);
new TimeStamper(objects::TIME_STAMPER);
{
PoolManager::LocalPoolConfig poolCfg = {{300, 16}, {200, 32}, {150, 64}, {150, 128},
{100, 256}, {50, 512}, {50, 1024}, {10, 2048}};
new PoolManager(objects::IPC_STORE, poolCfg);
}
}
int main(int argc, char* argv[]) {
ObjectManager::instance()->setObjectFactoryFunction(factory, nullptr);
ObjectManager::instance()->initialize();
// Catch internal function call
int result = Catch::Session().run(argc, argv);
@ -8,4 +35,3 @@ int main(int argc, char* argv[]) {
// global clean-up
return result;
}

View File

@ -0,0 +1,4 @@
target_sources(${UNITTEST_NAME} PRIVATE
EventManagerMock.cpp
HouseKeepingMock.cpp
)

View File

@ -0,0 +1,18 @@
#include "EventManagerMock.h"
#include <fsfw/ipc/QueueFactory.h>
EventManagerMock::EventManagerMock() : EventManager(objects::EVENT_MANAGER) {}
ReturnValue_t EventManagerMock::performOperation(uint8_t opCode) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
while (result == HasReturnvaluesIF::RETURN_OK) {
EventMessage message;
result = eventReportQueue->receiveMessage(&message);
if (result == HasReturnvaluesIF::RETURN_OK) {
notifyListeners(&message);
}
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,27 +1,13 @@
#ifndef EVENTMANAGERMOCK_H_
#define EVENTMANAGERMOCK_H_
#include <fsfw/events/EventManagerIF.h>
#include <fsfw/events/EventManager.h>
class EventManagerMock {
class EventManagerMock : public EventManager {
public:
virtual MessageQueueId_t getEventReportQueue() override;
EventManagerMock();
virtual ReturnValue_t registerListener(MessageQueueId_t listener,
bool forwardAllButSelected = false) override;
virtual ReturnValue_t subscribeToEvent(MessageQueueId_t listener, EventId_t event) override;
virtual ReturnValue_t subscribeToAllEventsFrom(MessageQueueId_t listener,
object_id_t object) override;
virtual ReturnValue_t subscribeToEventRange(MessageQueueId_t listener, EventId_t idFrom = 0,
EventId_t idTo = 0, bool idInverted = false,
object_id_t reporterFrom = 0,
object_id_t reporterTo = 0,
bool reporterInverted = false) override;
virtual ReturnValue_t unsubscribeFromEventRange(MessageQueueId_t listener, EventId_t idFrom = 0,
EventId_t idTo = 0, bool idInverted = false,
object_id_t reporterFrom = 0,
object_id_t reporterTo = 0,
bool reporterInverted = false) override;
virtual ReturnValue_t performOperation(uint8_t opCode) override;
};
#endif /* EVENTMANAGERMOCK_H_ */

View File

@ -0,0 +1,8 @@
#include "HouseKeepingMock.h"
#include <fsfw/objectmanager/frameworkObjects.h>
HouseKeepingMock::HouseKeepingMock() : SystemObject(objects::PUS_SERVICE_3_HOUSEKEEPING) {}
MessageQueueId_t HouseKeepingMock::getHkQueue() const { return MessageQueueIF::NO_QUEUE; }

View File

@ -0,0 +1,16 @@
#ifndef HOUSEKEEPINGMOCK_H_
#define HOUSEKEEPINGMOCK_H_
#include <fsfw/housekeeping/AcceptsHkPacketsIF.h>
#include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/ipc/MessageQueueIF.h>
class HouseKeepingMock : public SystemObject, public AcceptsHkPacketsIF {
public:
HouseKeepingMock();
virtual MessageQueueId_t getHkQueue() const;
};
#endif /*HOUSEKEEPINGMOCK_H_*/