#include #include #include #include #include #include "DebugCore.h" #include "DebugService.h" #include "DebugBrokerWrapper.h" #include "TcpLogger.h" #include "ConfigurationDatabase.h" #include "ObjectRegistryDatabase.h" #include "GlobalObjectsDatabase.h" namespace MARTe { void TestTcpLogger() { printf("Stability Logger Tests...\n"); TcpLogger logger; ConfigurationDatabase config; config.Write("Port", (uint32)0); // Random port assert(logger.Initialise(config)); } class DebugServiceTest { public: static void TestAll() { printf("Stability Logic Tests...\n"); ObjectRegistryDatabase::Instance()->Purge(); DebugService service; assert(service.traceBuffer.Init(1024 * 1024)); ConfigurationDatabase cfg; cfg.Write("ControlPort", (uint32)0); cfg.Write("StreamPort", (uint32)0); cfg.Write("SuppressTimeoutLogs", (uint32)1); assert(service.Initialise(cfg)); // 1. Signal logic uint32 val = 0; service.RegisterSignal(&val, UnsignedInteger32Bit, "X.Y.Z", 0, 1); assert(service.TraceSignal("Z", true) == 1); assert(service.ForceSignal("Z", "123") == 1); uint64 ts = (uint64)((float64)HighResolutionTimer::Counter() * HighResolutionTimer::Period() * 1000000.0); service.ProcessSignal(service.signals[0], 4, ts); assert(val == 123); service.UnforceSignal("Z"); // 2. Commands service.HandleCommand("TREE", NULL_PTR(BasicTCPSocket*)); service.HandleCommand("DISCOVER", NULL_PTR(BasicTCPSocket*)); service.HandleCommand("CONFIG", NULL_PTR(BasicTCPSocket*)); service.HandleCommand("PAUSE", NULL_PTR(BasicTCPSocket*)); service.HandleCommand("RESUME", NULL_PTR(BasicTCPSocket*)); service.HandleCommand("LS /", NULL_PTR(BasicTCPSocket*)); service.HandleCommand("INFO X.Y.Z", NULL_PTR(BasicTCPSocket*)); // 3. Broker Active Status volatile bool active = false; Vec indices; Vec sizes; FastPollingMutexSem mutex; DebugSignalInfo* ptrs[1] = { service.signals[0] }; service.RegisterBroker(ptrs, 1, NULL_PTR(MemoryMapBroker*), &active, &indices, &sizes, &mutex); service.UpdateBrokersActiveStatus(); assert(active == true); assert(indices.Size() == 1); assert(indices[0] == 0); // Helper Process DebugBrokerHelper::Process(&service, ptrs, indices, sizes, mutex); } }; } #include void timeout_handler(int sig) { printf("Test timed out!\n"); _exit(1); } int main() { signal(SIGALRM, timeout_handler); alarm(10); printf("--- MARTe2 Debug Suite COVERAGE V29 ---\n"); MARTe::TestTcpLogger(); MARTe::DebugServiceTest::TestAll(); printf("\nCOVERAGE V29 PASSED!\n"); return 0; }