From 157edb489d51a7d310d3a3f2e9a6871fb143792a Mon Sep 17 00:00:00 2001
From: kongr45gpen <electrovesta@gmail.com>
Date: Thu, 14 Mar 2019 16:57:31 +0200
Subject: [PATCH] Replace all Service instances with calls to the ServicePool

---
 inc/ErrorHandler.hpp                         |  3 +-
 inc/Service.hpp                              | 40 ++++++++++++++++++++
 inc/Services/RequestVerificationService.hpp  |  6 ---
 inc/Services/TestService.hpp                 |  6 ---
 src/ErrorHandler.cpp                         | 14 +++----
 src/MessageParser.cpp                        |  7 ++--
 src/main.cpp                                 | 13 ++++---
 test/Services/EventActionService.cpp         | 12 ++----
 test/Services/EventReportService.cpp         | 11 +-----
 test/Services/MemoryManagementService.cpp    |  4 +-
 test/Services/ParameterService.cpp           |  6 +--
 test/Services/RequestVerificationService.cpp | 20 +---------
 test/Services/ServiceTests.hpp               |  5 ++-
 test/Services/TestService.cpp                |  6 +--
 test/Services/TimeManagementService.cpp      |  4 +-
 15 files changed, 76 insertions(+), 81 deletions(-)

diff --git a/inc/ErrorHandler.hpp b/inc/ErrorHandler.hpp
index 25c65960..2f3c067e 100644
--- a/inc/ErrorHandler.hpp
+++ b/inc/ErrorHandler.hpp
@@ -165,7 +165,7 @@ public:
 	/**
  	 * Report a failure about the progress of the execution of a request
  	 *
- 	 * Note:This function is different from reportError, because we need one more /p(stepID)
+ 	 * @note This function is different from reportError, because we need one more \p stepID
  	 * to call the proper function for reporting the progress of the execution of a request
  	 *
  	 * @param message The incoming message that prompted the failure
@@ -183,6 +183,7 @@ public:
 	 *
 	 * Note that these errors correspond to bugs or faults in the software, and should be treated
 	 * differently. Such an error may prompt a task or software reset.
+	 *
 	 */
 	static void reportInternalError(InternalErrorType errorCode);
 
diff --git a/inc/Service.hpp b/inc/Service.hpp
index 0aab624d..09937508 100644
--- a/inc/Service.hpp
+++ b/inc/Service.hpp
@@ -5,6 +5,8 @@
 #include "Message.hpp"
 #include <iostream> // This file should be removed
 
+class ServicePool;
+
 /**
  * A spacecraft service, as defined in ECSS-E-ST-70-41C
  *
@@ -17,6 +19,10 @@ class Service {
 private:
 	uint16_t messageTypeCounter = 0;
 protected:
+	/**
+	 * The service type of this Service. For example, ST[12]'s serviceType is `12`.
+	 * Specify this value in the constructor of your service.
+	 */
 	uint8_t serviceType{};
 
 	/**
@@ -45,6 +51,40 @@ protected:
 	 * this, but this particular function does actually nothing.
 	 */
 	void execute(Message &message);
+
+	/**
+	 * Default protected constructor for this Service
+	 */
+	Service() = default;
+public:
+	/**
+	 * @brief Unimplemented copy constructor
+	 *
+	 * Does not allow Services should be copied. There should be only one instance for each Service.
+	 */
+	Service (Service const&) = delete;
+
+	/**
+	 * Unimplemented assignment operation
+	 *
+	 * Does not allow changing the instances of Services, as Services are singletons.
+	 */
+	void operator=(Service const&) = delete;
+
+	/**
+	 * Default destructor
+	 */
+	~Service() = default;
+
+	/**
+	 * Default move constructor
+	 */
+	Service(Service && service) noexcept = default;
+
+	/**
+	 * Default move assignment operator
+	 */
+	Service & operator=(Service && service) noexcept = default;
 };
 
 
diff --git a/inc/Services/RequestVerificationService.hpp b/inc/Services/RequestVerificationService.hpp
index 3f78f83b..683b74d2 100644
--- a/inc/Services/RequestVerificationService.hpp
+++ b/inc/Services/RequestVerificationService.hpp
@@ -132,12 +132,6 @@ public:
 	 * subservices. More arguments are needed.
 	 */
 	void execute(const Message &message);
-
-	/**
-	 * The purpose of this instance is to access the execute function of this service when a
-	 * MessageParser object is created
-	 */
-	static RequestVerificationService instance;
 };
 
 
diff --git a/inc/Services/TestService.hpp b/inc/Services/TestService.hpp
index f06be969..937c1b97 100644
--- a/inc/Services/TestService.hpp
+++ b/inc/Services/TestService.hpp
@@ -32,12 +32,6 @@ public:
 	 * @todo Error handling for the switch() in the implementation of this execute function
 	 */
 	void execute(Message &message);
-
-	/**
-	 *  The purpose of this instance is to access the execute function of this service when a
-	 *  MessageParser object is created
-	 */
-	static TestService instance;
 };
 
 
diff --git a/src/ErrorHandler.cpp b/src/ErrorHandler.cpp
index d62eadd5..854ea79e 100644
--- a/src/ErrorHandler.cpp
+++ b/src/ErrorHandler.cpp
@@ -1,43 +1,41 @@
 #include <iostream>
 #include <cxxabi.h>
 #include <ErrorHandler.hpp>
+#include <ServicePool.hpp>
 #include "Services/RequestVerificationService.hpp"
 
 
-// TODO: Use service singleton, as soon as singletons are ready
-static RequestVerificationService requestVerificationService;
-
 template<>
 void ErrorHandler::reportError(const Message &message, AcceptanceErrorType errorCode) {
-	requestVerificationService.failAcceptanceVerification(message, errorCode);
+	Services.requestVerification.failAcceptanceVerification(message, errorCode);
 
 	logError(message, errorCode);
 }
 
 template<>
 void ErrorHandler::reportError(const Message &message, ExecutionStartErrorType errorCode) {
-	requestVerificationService.failStartExecutionVerification(message, errorCode);
+	Services.requestVerification.failStartExecutionVerification(message, errorCode);
 
 	logError(message, errorCode);
 }
 
 void ErrorHandler::reportProgressError(const Message &message, ExecutionProgressErrorType
 errorCode, uint8_t stepID) {
-	requestVerificationService.failProgressExecutionVerification(message, errorCode, stepID);
+	Services.requestVerification.failProgressExecutionVerification(message, errorCode, stepID);
 
 	logError(message, errorCode);
 }
 
 template<>
 void ErrorHandler::reportError(const Message &message, ExecutionCompletionErrorType errorCode) {
-	requestVerificationService.failCompletionExecutionVerification(message, errorCode);
+	Services.requestVerification.failCompletionExecutionVerification(message, errorCode);
 
 	logError(message, errorCode);
 }
 
 template<>
 void ErrorHandler::reportError(const Message &message, RoutingErrorType errorCode) {
-	requestVerificationService.failRoutingVerification(message, errorCode);
+	Services.requestVerification.failRoutingVerification(message, errorCode);
 
 	logError(message, errorCode);
 }
diff --git a/src/MessageParser.cpp b/src/MessageParser.cpp
index 6472871e..6e7ca4ea 100644
--- a/src/MessageParser.cpp
+++ b/src/MessageParser.cpp
@@ -1,21 +1,20 @@
 #include <cstring>
 #include <Services/EventActionService.hpp>
+#include <ServicePool.hpp>
 #include "ErrorHandler.hpp"
 #include "MessageParser.hpp"
 #include "macros.hpp"
 #include "Services/TestService.hpp"
 #include "Services/RequestVerificationService.hpp"
 
-TestService TestService::instance;
-RequestVerificationService RequestVerificationService::instance;
 
 void MessageParser::execute(Message &message) {
 	switch (message.serviceType) {
 		case 1:
-			RequestVerificationService::instance.execute(message);
+			Services.requestVerification.execute(message);
 			break;
 		case 17:
-			TestService::instance.execute(message);
+			Services.testService.execute(message);
 			break;
 		default:
 			ErrorHandler::reportInternalError(ErrorHandler::UnknownMessageType);
diff --git a/src/main.cpp b/src/main.cpp
index c62b1681..875276b7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,4 +1,5 @@
 #include <iostream>
+#include <ServicePool.hpp>
 #include "Helpers/CRCHelper.hpp"
 #include "Helpers/TimeHelper.hpp"
 #include "Services/TestService.hpp"
@@ -35,7 +36,7 @@ int main() {
 	std::cout << packet.readFloat() << " " << std::dec << packet.readSint32() << std::endl;
 
 	// ST[17] test
-	TestService testService;
+	TestService & testService = Services.testService;
 	Message receivedPacket = Message(17, 1, Message::TC, 1);
 	testService.areYouAlive(receivedPacket);
 	receivedPacket = Message(17, 3, Message::TC, 1);
@@ -44,7 +45,7 @@ int main() {
 
 
 	// ST[20] test
-	ParameterService paramService;
+	ParameterService & paramService = Services.parameterManagement;
 
 	// Test code for reportParameter
 	Message sentPacket = Message(20, 1, Message::TC, 1);  //application id is a dummy number (1)
@@ -72,7 +73,7 @@ int main() {
 	*(pStr + 1) = 'G';
 	*(pStr + 2) = '\0';
 
-	MemoryManagementService memMangService;
+	MemoryManagementService & memMangService = Services.memoryManagement;
 	Message rcvPack = Message(6, 5, Message::TC, 1);
 	rcvPack.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID
 	rcvPack.appendUint16(3); // Iteration count
@@ -112,7 +113,7 @@ int main() {
 
 	// ST[01] test
 
-	RequestVerificationService reqVerifService;
+	RequestVerificationService & reqVerifService = Services.requestVerification;
 
 	Message receivedMessage = Message(1, 1, Message::TC, 3);
 	reqVerifService.successAcceptanceVerification(receivedMessage);
@@ -202,7 +203,7 @@ int main() {
 	std::cout << "\n" << test << "\n";
 
 	// ST[09] test
-	TimeManagementService timeReport;
+	TimeManagementService & timeReport = Services.timeManagement;
 	timeReport.cucTimeReport();
 
 	// ST[05] (5,5 to 5,8) test [works]
@@ -226,7 +227,7 @@ int main() {
 
 	// ST[19] test
 
-	EventActionService eventActionService;
+	EventActionService & eventActionService = Services.eventAction;
 	Message eventActionDefinition(19, 1, Message::TC, 1);
 	eventActionDefinition.appendEnum16(0);
 	eventActionDefinition.appendEnum16(2);
diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp
index f40de3fd..964e8826 100644
--- a/test/Services/EventActionService.cpp
+++ b/test/Services/EventActionService.cpp
@@ -5,9 +5,11 @@
 #include <etl/String.hpp>
 #include <cstring>
 #include <iostream>
+#include <ServicePool.hpp>
+
+EventActionService & eventActionService = Services.eventAction;
 
 TEST_CASE("Add event-action definitions TC[19,1]", "[service][st09]") {
-	EventActionService eventActionService;
 	char checkstring[256];
 	Message message(19, 1, Message::TC, 0);
 	message.appendEnum16(0);
@@ -43,7 +45,6 @@ TEST_CASE("Add event-action definitions TC[19,1]", "[service][st09]") {
 }
 
 TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") {
-	EventActionService eventActionService;
 	Message message0(19, 1, Message::TC, 0);
 	message0.appendEnum16(1);
 	message0.appendEnum16(0);
@@ -116,7 +117,6 @@ TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") {
 }
 
 TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st09]") {
-	EventActionService eventActionService;
 	Message message0(19, 1, Message::TC, 0);
 	message0.appendEnum16(1);
 	message0.appendEnum16(0);
@@ -160,7 +160,6 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st09]") {
 }
 
 TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st09]") {
-	EventActionService eventActionService;
 	Message message0(19, 1, Message::TC, 0);
 	message0.appendEnum16(1);
 	message0.appendEnum16(0);
@@ -186,7 +185,6 @@ TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st09]") {
 }
 
 TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st09]") {
-	EventActionService eventActionService;
 	Message message0(19, 1, Message::TC, 0);
 	message0.appendEnum16(1);
 	message0.appendEnum16(0);
@@ -209,7 +207,6 @@ TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st09]") {
 }
 
 TEST_CASE("Request event-action definition status TC[19,6]", "[service][st09]") {
-	EventActionService eventActionService;
 	Message message(19, 6, Message::TC, 0);
 	eventActionService.requestEventActionDefinitionStatus(message);
 	REQUIRE(ServiceTests::hasOneMessage());
@@ -219,7 +216,6 @@ TEST_CASE("Request event-action definition status TC[19,6]", "[service][st09]")
 }
 
 TEST_CASE("Event-action status report TM[19,7]", "[service][st09]") {
-	EventActionService eventActionService;
 	Message message0(19, 1, Message::TC, 0);
 	message0.appendEnum16(1);
 	message0.appendEnum16(0);
@@ -251,14 +247,12 @@ TEST_CASE("Event-action status report TM[19,7]", "[service][st09]") {
 }
 
 TEST_CASE("Enable event-action function TC[19,8]", "[service][st09]") {
-	EventActionService eventActionService;
 	Message message(19, 8, Message::TC, 0);
 	eventActionService.enableEventActionFunction(message);
 	CHECK(eventActionService.getEventActionFunctionStatus() == true);
 }
 
 TEST_CASE("Disable event-action function TC[19,9]", "[service][st09]") {
-	EventActionService eventActionService;
 	Message message(19, 9, Message::TC, 0);
 	eventActionService.disableEventActionFunction(message);
 	CHECK(eventActionService.getEventActionFunctionStatus() == false);
diff --git a/test/Services/EventReportService.cpp b/test/Services/EventReportService.cpp
index ca90bee5..2d76b5cc 100644
--- a/test/Services/EventReportService.cpp
+++ b/test/Services/EventReportService.cpp
@@ -4,11 +4,12 @@
 #include "ServiceTests.hpp"
 #include <cstring>
 
+EventReportService & eventReportService = Services.eventReport;
+
 /*
  * @todo: Change the reinterpret_cast
  */
 TEST_CASE("Informative Event Report TM[5,1]", "[service][st05]") {
-	EventReportService eventReportService;
 	const char eventReportData[] = "HelloWorld";
 	char checkString[255];
 	eventReportService.informativeEventReport(EventReportService::InformativeUnknownEvent,
@@ -28,7 +29,6 @@ TEST_CASE("Informative Event Report TM[5,1]", "[service][st05]") {
 }
 
 TEST_CASE("Low Severity Anomaly Report TM[5,2]", "[service][st05]") {
-	EventReportService eventReportService;
 	const char eventReportData[] = "HelloWorld";
 	char checkString[255];
 	eventReportService.lowSeverityAnomalyReport(EventReportService::LowSeverityUnknownEvent,
@@ -48,7 +48,6 @@ TEST_CASE("Low Severity Anomaly Report TM[5,2]", "[service][st05]") {
 }
 
 TEST_CASE("Medium Severity Anomaly Report TM[5,3]", "[service][st05]") {
-	EventReportService eventReportService;
 	const char eventReportData[] = "HelloWorld";
 	char checkString[255];
 	eventReportService.mediumSeverityAnomalyReport
@@ -68,7 +67,6 @@ TEST_CASE("Medium Severity Anomaly Report TM[5,3]", "[service][st05]") {
 }
 
 TEST_CASE("High Severity Anomaly Report TM[5,4]", "[service][st05]") {
-	EventReportService eventReportService;
 	const char eventReportData[] = "HelloWorld";
 	char checkString[255];
 	eventReportService.highSeverityAnomalyReport(EventReportService::HighSeverityUnknownEvent,
@@ -88,7 +86,6 @@ TEST_CASE("High Severity Anomaly Report TM[5,4]", "[service][st05]") {
 }
 
 TEST_CASE("Enable Report Generation TC[5,5]", "[service][st05]") {
-	EventReportService eventReportService;
 	eventReportService.getStateOfEvents().reset();
 	EventReportService::Event eventID[] = {EventReportService::AssertionFail,
 	                                       EventReportService::LowSeverityUnknownEvent};
@@ -102,7 +99,6 @@ TEST_CASE("Enable Report Generation TC[5,5]", "[service][st05]") {
 }
 
 TEST_CASE("Disable Report Generation TC[5,6]", "[service][st05]") {
-	EventReportService eventReportService;
 	EventReportService::Event eventID[] = {EventReportService::InformativeUnknownEvent,
 	                                       EventReportService::MediumSeverityUnknownEvent};
 	Message message(5, 6, Message::TC, 1);
@@ -120,7 +116,6 @@ TEST_CASE("Disable Report Generation TC[5,6]", "[service][st05]") {
 }
 
 TEST_CASE("Request list of disabled events TC[5,7]", "[service][st05]") {
-	EventReportService eventReportService;
 	Message message(5, 7, Message::TC, 1);
 	eventReportService.requestListOfDisabledEvents(message);
 	REQUIRE(ServiceTests::hasOneMessage());
@@ -131,7 +126,6 @@ TEST_CASE("Request list of disabled events TC[5,7]", "[service][st05]") {
 }
 
 TEST_CASE("List of Disabled Events Report TM[5,8]", "[service][st05]") {
-	EventReportService eventReportService;
 	EventReportService::Event eventID[] = {EventReportService::MCUStart,
 	                                       EventReportService::HighSeverityUnknownEvent};
 	Message message(5, 6, Message::TC, 1);
@@ -156,7 +150,6 @@ TEST_CASE("List of Disabled Events Report TM[5,8]", "[service][st05]") {
 }
 
 TEST_CASE("List of observables 6.5.6", "[service][st05]") {
-	EventReportService eventReportService;
 	EventReportService::Event eventID[] = {EventReportService::HighSeverityUnknownEvent};
 	Message message(5, 6, Message::TC, 1);
 	message.appendUint16(1);
diff --git a/test/Services/MemoryManagementService.cpp b/test/Services/MemoryManagementService.cpp
index 64b0181f..ec1ef2d5 100644
--- a/test/Services/MemoryManagementService.cpp
+++ b/test/Services/MemoryManagementService.cpp
@@ -4,6 +4,8 @@
 #include "ServiceTests.hpp"
 #include "Helpers/CRCHelper.hpp"
 
+MemoryManagementService & memMangService = Services.memoryManagement;
+
 TEST_CASE("TM[6,2]", "[service][st06]") {
 	// Required test variables
 	char *pStr = static_cast<char *>(malloc(4));
@@ -12,8 +14,6 @@ TEST_CASE("TM[6,2]", "[service][st06]") {
 	*(pStr + 2) = '\0';
 	uint8_t data[2] = {'h', 'R'};
 
-	MemoryManagementService memMangService;
-
 	Message receivedPacket = Message(6, 2, Message::TC, 1);
 	receivedPacket.appendEnum8(MemoryManagementService::MemoryID::EXTERNAL); // Memory ID
 	receivedPacket.appendUint16(2); // Iteration count
diff --git a/test/Services/ParameterService.cpp b/test/Services/ParameterService.cpp
index dbf1820b..28f59a40 100644
--- a/test/Services/ParameterService.cpp
+++ b/test/Services/ParameterService.cpp
@@ -3,11 +3,9 @@
 #include "Message.hpp"
 #include "ServiceTests.hpp"
 
-#define CATCH_CONFIG_MAIN
+ParameterService & pserv = Services.parameterManagement;
 
 TEST_CASE("Parameter Report Subservice") {
-	ParameterService pserv;
-
 	SECTION("Faulty Instruction Handling Test") {
 		Message request(20, 1, Message::TC, 1);
 		Message report(20, 2, Message::TM, 1);
@@ -42,8 +40,6 @@ TEST_CASE("Parameter Report Subservice") {
 }
 
 TEST_CASE("Parameter Setting Subservice") {
-	ParameterService pserv;
-
 	SECTION("Faulty Instruction Handling Test") {
 		Message setRequest(20, 3, Message::TC, 1);
 		Message reportRequest(20, 1, Message::TC, 1);
diff --git a/test/Services/RequestVerificationService.cpp b/test/Services/RequestVerificationService.cpp
index 3e804404..8464dc5b 100644
--- a/test/Services/RequestVerificationService.cpp
+++ b/test/Services/RequestVerificationService.cpp
@@ -3,9 +3,9 @@
 #include <Message.hpp>
 #include "ServiceTests.hpp"
 
-TEST_CASE("TM[1,1]", "[service][st01]") {
-	RequestVerificationService reqVerifService;
+RequestVerificationService & reqVerifService = Services.requestVerification;
 
+TEST_CASE("TM[1,1]", "[service][st01]") {
 	Message receivedMessage = Message(1, 1, Message::TC, 3);
 	reqVerifService.successAcceptanceVerification(receivedMessage);
 	REQUIRE(ServiceTests::hasOneMessage());
@@ -27,8 +27,6 @@ TEST_CASE("TM[1,1]", "[service][st01]") {
 }
 
 TEST_CASE("TM[1,2]", "[service][st01]") {
-	RequestVerificationService reqVerifService;
-
 	Message receivedMessage = Message(1, 2, Message::TC, 3);
 	reqVerifService.failAcceptanceVerification(receivedMessage,
 	                                           ErrorHandler::UnknownAcceptanceError);
@@ -52,8 +50,6 @@ TEST_CASE("TM[1,2]", "[service][st01]") {
 }
 
 TEST_CASE("TM[1,3]", "[service][st01]") {
-	RequestVerificationService reqVerifService;
-
 	Message receivedMessage = Message(1, 3, Message::TC, 3);
 	reqVerifService.successStartExecutionVerification(receivedMessage);
 	REQUIRE(ServiceTests::hasOneMessage());
@@ -75,8 +71,6 @@ TEST_CASE("TM[1,3]", "[service][st01]") {
 }
 
 TEST_CASE("TM[1,4]", "[service][st01]") {
-	RequestVerificationService reqVerifService;
-
 	Message receivedMessage = Message(1, 2, Message::TC, 3);
 	reqVerifService.failStartExecutionVerification(receivedMessage,
 	                                               ErrorHandler::UnknownExecutionStartError);
@@ -100,8 +94,6 @@ TEST_CASE("TM[1,4]", "[service][st01]") {
 }
 
 TEST_CASE("TM[1,5]", "[service][st01]") {
-	RequestVerificationService reqVerifService;
-
 	Message receivedMessage = Message(1, 5, Message::TC, 3);
 	reqVerifService.successProgressExecutionVerification(receivedMessage, 0);
 	REQUIRE(ServiceTests::hasOneMessage());
@@ -124,8 +116,6 @@ TEST_CASE("TM[1,5]", "[service][st01]") {
 }
 
 TEST_CASE("TM[1,6]", "[service][st01]") {
-	RequestVerificationService reqVerifService;
-
 	Message receivedMessage = Message(1, 5, Message::TC, 3);
 	reqVerifService.failProgressExecutionVerification(receivedMessage,
 	                                                  ErrorHandler::UnknownExecutionProgressError,
@@ -151,8 +141,6 @@ TEST_CASE("TM[1,6]", "[service][st01]") {
 }
 
 TEST_CASE("TM[1,7]", "[service][st01]") {
-	RequestVerificationService reqVerifService;
-
 	Message receivedMessage = Message(1, 7, Message::TC, 3);
 	reqVerifService.successCompletionExecutionVerification(receivedMessage);
 	REQUIRE(ServiceTests::hasOneMessage());
@@ -174,8 +162,6 @@ TEST_CASE("TM[1,7]", "[service][st01]") {
 }
 
 TEST_CASE("TM[1,8]", "[service][st01]") {
-	RequestVerificationService reqVerifService;
-
 	Message receivedMessage = Message(1, 8, Message::TC, 3);
 	reqVerifService.failCompletionExecutionVerification(receivedMessage,
 		ErrorHandler::UnknownExecutionCompletionError);
@@ -198,8 +184,6 @@ TEST_CASE("TM[1,8]", "[service][st01]") {
 }
 
 TEST_CASE("TM[1,10]", "[service][st01]") {
-	RequestVerificationService reqVerifService;
-
 	Message receivedMessage = Message(1, 10, Message::TC, 3);
 	reqVerifService.failRoutingVerification(receivedMessage, ErrorHandler::UnknownRoutingError);
 	REQUIRE(ServiceTests::hasOneMessage());
diff --git a/test/Services/ServiceTests.hpp b/test/Services/ServiceTests.hpp
index a160558a..740cc9ff 100644
--- a/test/Services/ServiceTests.hpp
+++ b/test/Services/ServiceTests.hpp
@@ -3,6 +3,7 @@
 
 #include <vector>
 #include <Message.hpp>
+#include <ServicePool.hpp>
 
 /**
  * Supporting class for tests against ECSS services
@@ -43,10 +44,12 @@ public:
 	}
 
 	/**
-	 * Remove all the queued messages from the list, starting over from 0 items again
+	 * Reset the testing environment, starting from zero for all parameters
 	 */
 	static void reset() {
 		queuedMessages.clear();
+
+		Services.reset();
 	}
 };
 
diff --git a/test/Services/TestService.cpp b/test/Services/TestService.cpp
index a94934ad..700c0b9d 100644
--- a/test/Services/TestService.cpp
+++ b/test/Services/TestService.cpp
@@ -3,9 +3,9 @@
 #include <Message.hpp>
 #include "ServiceTests.hpp"
 
-TEST_CASE("TM[17,1]", "[service][st17]") {
-	TestService testService;
+TestService & testService = Services.testService;
 
+TEST_CASE("TM[17,1]", "[service][st17]") {
 	Message receivedPacket = Message(17, 1, Message::TC, 1);
 	testService.areYouAlive(receivedPacket);
 	REQUIRE(ServiceTests::hasOneMessage());
@@ -17,8 +17,6 @@ TEST_CASE("TM[17,1]", "[service][st17]") {
 }
 
 TEST_CASE("TM[17,3]", "[service][st17]") {
-	TestService testService;
-
 	Message receivedPacket = Message(17, 3, Message::TC, 1);
 	receivedPacket.appendEnum16(40);
 	testService.onBoardConnection(receivedPacket);
diff --git a/test/Services/TimeManagementService.cpp b/test/Services/TimeManagementService.cpp
index 714c99e1..f9ca5953 100644
--- a/test/Services/TimeManagementService.cpp
+++ b/test/Services/TimeManagementService.cpp
@@ -2,9 +2,9 @@
 #include <Services/TimeManagementService.hpp>
 #include "ServiceTests.hpp"
 
-TEST_CASE("TM[9,2]", "[service][st09]") {
-	TimeManagementService timeFormat;
+TimeManagementService & timeFormat = Services.timeManagement;
 
+TEST_CASE("TM[9,2]", "[service][st09]") {
 	uint32_t seconds;
 	seconds = time(nullptr);
 
-- 
GitLab