Initial commit

This commit is contained in:
Martino Ferrari
2026-02-21 00:58:56 +01:00
commit 5ef0efe7d6
26 changed files with 7999 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
add_executable(IntegrationTest main.cpp)
target_link_libraries(IntegrationTest marte_dev ${MARTe2_LIB})
add_executable(TraceTest TraceTest.cpp)
target_link_libraries(TraceTest marte_dev ${MARTe2_LIB})
add_executable(ValidationTest ValidationTest.cpp)
target_link_libraries(ValidationTest marte_dev ${MARTe2_LIB} ${IOGAM_LIB} ${LinuxTimer_LIB})

View File

@@ -0,0 +1,86 @@
#include "DebugService.h"
#include "DebugCore.h"
#include "ObjectRegistryDatabase.h"
#include "StandardParser.h"
#include "StreamString.h"
#include "BasicUDPSocket.h"
#include <assert.h>
#include <stdio.h>
using namespace MARTe;
void TestFullTracePipeline() {
printf("Starting Full Trace Pipeline Test...\n");
printf("sizeof(TraceHeader) = %lu\n", sizeof(TraceHeader));
// 1. Setup Service
DebugService service;
ConfigurationDatabase config;
config.Write("ControlPort", (uint16)8080);
config.Write("StreamPort", (uint16)8081);
config.Write("LogPort", (uint16)8082);
config.Write("StreamIP", "127.0.0.1");
assert(service.Initialise(config));
// 2. Register a mock signal
uint32 mockValue = 0;
DebugSignalInfo* sig = service.RegisterSignal(&mockValue, UnsignedInteger32Bit, "Test.Signal");
assert(sig != NULL_PTR(DebugSignalInfo*));
printf("Signal registered with ID: %u\n", sig->internalID);
// 3. Enable Trace manually
sig->isTracing = true;
sig->decimationFactor = 1;
// 4. Setup a local UDP listener
BasicUDPSocket listener;
assert(listener.Open());
assert(listener.Listen(8081));
// 5. Simulate cycles
printf("Simulating cycles...\n");
for (int i=0; i<50; i++) {
mockValue = 1000 + i;
service.ProcessSignal(sig, sizeof(uint32));
Sleep::MSec(10);
}
// 6. Try to read from UDP
char buffer[2048];
uint32 size = 2048;
TimeoutType timeout(1000); // 1s
if (listener.Read(buffer, size, timeout)) {
printf("SUCCESS: Received %u bytes over UDP!\n", size);
for(uint32 i=0; i<size; i++) {
printf("%02X ", (uint8)buffer[i]);
if((i+1)%4 == 0) printf("| ");
if((i+1)%16 == 0) printf("\n");
}
printf("\n");
TraceHeader *h = (TraceHeader*)buffer;
printf("Header: Magic=0x%X, Count=%u, Seq=%u\n", h->magic, h->count, h->seq);
uint32 offset = sizeof(TraceHeader);
if (size >= offset + 8) {
uint32 recId = *(uint32*)(&buffer[offset]);
uint32 recSize = *(uint32*)(&buffer[offset + 4]);
printf("Data: ID=%u, Size=%u\n", recId, recSize);
if (size >= offset + 8 + recSize) {
if (recSize == 4) {
uint32 recVal = *(uint32*)(&buffer[offset + 8]);
printf("Value=%u\n", recVal);
}
}
}
} else {
printf("FAILURE: No UDP packets received.\n");
}
listener.Close();
}
int main() {
TestFullTracePipeline();
return 0;
}

View File

@@ -0,0 +1,202 @@
#include "DebugService.h"
#include "DebugCore.h"
#include "ObjectRegistryDatabase.h"
#include "StandardParser.h"
#include "StreamString.h"
#include "BasicUDPSocket.h"
#include "BasicTCPSocket.h"
#include "RealTimeApplication.h"
#include <assert.h>
#include <stdio.h>
using namespace MARTe;
const char8 * const config_text =
"+DebugService = {"
" Class = DebugService "
" ControlPort = 8080 "
" UdpPort = 8081 "
" StreamIP = \"127.0.0.1\" "
"}"
"+App = {"
" Class = RealTimeApplication "
" +Functions = {"
" Class = ReferenceContainer "
" +GAM1 = {"
" Class = IOGAM "
" InputSignals = {"
" Counter = {"
" DataSource = Timer "
" Type = uint32 "
" }"
" }"
" OutputSignals = {"
" Counter = {"
" DataSource = DDB "
" Type = uint32 "
" }"
" }"
" }"
" }"
" +Data = {"
" Class = ReferenceContainer "
" DefaultDataSource = DDB "
" +Timer = {"
" Class = LinuxTimer "
" SleepTime = 10000 "
" Signals = {"
" Counter = { Type = uint32 }"
" }"
" }"
" +DDB = {"
" Class = GAMDataSource "
" Signals = { Counter = { Type = uint32 } }"
" }"
" +DAMS = { Class = TimingDataSource }"
" }"
" +States = {"
" Class = ReferenceContainer "
" +State1 = {"
" Class = RealTimeState "
" +Threads = {"
" Class = ReferenceContainer "
" +Thread1 = {"
" Class = RealTimeThread "
" Functions = {GAM1} "
" }"
" }"
" }"
" }"
" +Scheduler = {"
" Class = GAMScheduler "
" TimingDataSource = DAMS "
" }"
"}";
void RunValidationTest() {
printf("--- MARTe2 100Hz Trace Validation Test ---\n");
// 1. Load Configuration
ConfigurationDatabase cdb;
StreamString ss = config_text;
ss.Seek(0);
StandardParser parser(ss, cdb);
if (!parser.Parse()) {
printf("ERROR: Failed to parse configuration\n");
return;
}
if (!ObjectRegistryDatabase::Instance()->Initialise(cdb)) {
printf("ERROR: Failed to initialise ObjectRegistryDatabase.\n");
return;
}
// 2. Start Application
ReferenceT<RealTimeApplication> app = ObjectRegistryDatabase::Instance()->Find("App");
if (!app.IsValid()) {
printf("ERROR: App not found\n");
return;
}
// We try to use State1 directly as many MARTe2 apps start in the first defined state if no transition is needed
if (app->PrepareNextState("State1") != ErrorManagement::NoError) {
printf("ERROR: Failed to prepare state State1\n");
// We will try to investigate why, but for now we continue
}
if (app->StartNextStateExecution() != ErrorManagement::NoError) {
printf("ERROR: Failed to start execution. Maybe it needs an explicit state?\n");
// return;
}
printf("Application started at 100Hz.\n");
Sleep::MSec(1000);
// 3. Enable Trace via TCP (Simulating GUI)
BasicTCPSocket client;
if (client.Connect("127.0.0.1", 8080)) {
const char* cmd = "TRACE Root.App.Data.Timer.Counter 1\n";
uint32 s = StringHelper::Length(cmd);
client.Write(cmd, s);
char resp[1024]; s = 1024;
TimeoutType timeout(1000);
if (client.Read(resp, s, timeout)) {
resp[s] = '\0';
printf("Server Response: %s", resp);
} else {
printf("WARNING: No response from server to TRACE command.\n");
}
client.Close();
} else {
printf("ERROR: Failed to connect to DebugService on 8080\n");
// continue anyway to see if it's already working
}
// 4. Setup UDP Listener
BasicUDPSocket listener;
if (!listener.Open()) { printf("ERROR: Failed to open UDP socket\n"); return; }
if (!listener.Listen(8081)) { printf("ERROR: Failed to listen on UDP 8081\n"); return; }
// 5. Validate for 30 seconds
printf("Validating telemetry for 30 seconds...\n");
uint32 lastVal = 0;
bool first = true;
uint32 packetCount = 0;
uint32 discontinuityCount = 0;
float64 startTime = HighResolutionTimer::Counter() * HighResolutionTimer::Period();
while ((HighResolutionTimer::Counter() * HighResolutionTimer::Period() - startTime) < 30.0) {
char buffer[2048];
uint32 size = 2048;
TimeoutType timeout(500);
if (listener.Read(buffer, size, timeout)) {
TraceHeader *h = (TraceHeader*)buffer;
if (h->magic == 0xDA7A57AD && h->count > 0) {
uint32 offset = sizeof(TraceHeader);
// Packet format: [Header][ID:4][Size:4][Value:N]
uint32 val = *(uint32*)(&buffer[offset + 8]);
if (!first) {
if (val != lastVal + 1) {
discontinuityCount++;
}
}
lastVal = val;
first = false;
packetCount++;
if (packetCount % 500 == 0) {
printf("Received %u packets... Current Value: %u\n", packetCount, val);
}
}
}
}
printf("Test Finished.\n");
printf("Total Packets Received: %u (Expected ~3000)\n", packetCount);
printf("Discontinuities: %u\n", discontinuityCount);
float64 actualFreq = (float64)packetCount / 30.0;
printf("Average Frequency: %.2f Hz\n", actualFreq);
if (packetCount < 100) {
printf("FAILURE: Almost no packets received. Telemetry is broken.\n");
} else if (packetCount < 2500) {
printf("WARNING: Too few packets received (Expected 3000, Got %u).\n", packetCount);
} else if (discontinuityCount > 100) {
printf("FAILURE: Too many discontinuities (%u).\n", discontinuityCount);
} else {
printf("VALIDATION SUCCESSFUL!\n");
}
app->StopCurrentStateExecution();
listener.Close();
}
int main() {
RunValidationTest();
return 0;
}

50
Test/Integration/main.cpp Normal file
View File

@@ -0,0 +1,50 @@
#include <stdio.h>
#include "DebugService.h"
#include "MemoryMapInputBroker.h"
#include "ConfigurationDatabase.h"
#include "ObjectRegistryDatabase.h"
#include "ClassRegistryDatabase.h"
using namespace MARTe;
#include <unistd.h>
#include <signal.h>
void timeout_handler(int sig) {
printf("Test timed out!\n");
_exit(1);
}
int main() {
signal(SIGALRM, timeout_handler);
alarm(5); // 5 seconds timeout
printf("MARTe2 Debug Suite Integration Test\n");
{
// 1. Manually trigger Registry Patching
DebugService service;
ConfigurationDatabase serviceData;
serviceData.Write("ControlPort", (uint16)9090);
service.Initialise(serviceData);
printf("DebugService initialized and Registry Patched.\n");
// 2. Try to create a MemoryMapInputBroker
ClassRegistryItem *item = ClassRegistryDatabase::Instance()->Find("MemoryMapInputBroker");
if (item != NULL_PTR(ClassRegistryItem *)) {
Object *obj = item->GetObjectBuilder()->Build(GlobalObjectsDatabase::Instance()->GetStandardHeap());
if (obj != NULL_PTR(Object *)) {
printf("Instantiated Broker Class: %s\n", obj->GetClassProperties()->GetName());
printf("Success: Broker patched and instantiated.\n");
// delete obj;
} else {
printf("Failed to build broker\n");
}
} else {
printf("MemoryMapInputBroker not found in registry\n");
}
}
printf("DebugService scope finished.\n");
return 0;
}