Initial release
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
#include "BasicTCPSocket.h"
|
||||
#include "DebugService.h"
|
||||
#include "ObjectRegistryDatabase.h"
|
||||
#include "StandardParser.h"
|
||||
#include "StreamString.h"
|
||||
#include "GlobalObjectsDatabase.h"
|
||||
#include "RealTimeApplication.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace MARTe;
|
||||
|
||||
const char8 * const config_command_text =
|
||||
"DebugService = {"
|
||||
" Class = DebugService "
|
||||
" ControlPort = 8100 "
|
||||
" UdpPort = 8101 "
|
||||
" StreamIP = \"127.0.0.1\" "
|
||||
" MyCustomField = \"HelloConfig\" "
|
||||
"}"
|
||||
"App = {"
|
||||
" Class = RealTimeApplication "
|
||||
" +Functions = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +GAM1 = {"
|
||||
" Class = IOGAM "
|
||||
" CustomGAMField = \"GAMValue\" "
|
||||
" InputSignals = {"
|
||||
" Counter = { DataSource = Timer Type = uint32 Frequency = 1000 PVName = \"PROC:VAR:1\" }"
|
||||
" Time = { DataSource = Timer Type = uint32 }"
|
||||
" }"
|
||||
" OutputSignals = {"
|
||||
" Counter = { DataSource = DDB Type = uint32 }"
|
||||
" Time = { DataSource = DDB Type = uint32 }"
|
||||
" }"
|
||||
" }"
|
||||
" }"
|
||||
" +Data = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +Timer = { Class = LinuxTimer SleepTime = 1000 Signals = { Counter = { Type = uint32 } Time = { Type = uint32 } } }"
|
||||
" +DDB = { Class = GAMDataSource Signals = { Counter = { Type = uint32 } Time = { Type = uint32 } } }"
|
||||
" +DAMS = { Class = TimingDataSource }"
|
||||
" }"
|
||||
" +States = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +State1 = { Class = RealTimeState +Threads = { Class = ReferenceContainer +Thread1 = { Class = RealTimeThread Functions = {GAM1} } } }"
|
||||
" }"
|
||||
" +Scheduler = { Class = GAMScheduler TimingDataSource = DAMS }"
|
||||
"}";
|
||||
|
||||
static bool SendCommandAndGetReply(uint16 port, const char8* cmd, StreamString &reply) {
|
||||
BasicTCPSocket client;
|
||||
if (!client.Open()) return false;
|
||||
if (!client.Connect("127.0.0.1", port)) return false;
|
||||
|
||||
uint32 s = StringHelper::Length(cmd);
|
||||
if (!client.Write(cmd, s)) return false;
|
||||
|
||||
char buffer[4096];
|
||||
uint32 size = 4096;
|
||||
TimeoutType timeout(2000000); // 2s
|
||||
if (client.Read(buffer, size, timeout)) {
|
||||
reply.Write(buffer, size);
|
||||
client.Close();
|
||||
return true;
|
||||
}
|
||||
client.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
void TestConfigCommands() {
|
||||
printf("--- MARTe2 Config & Metadata Enrichment Test ---\n");
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
|
||||
ConfigurationDatabase cdb;
|
||||
StreamString ss = config_command_text;
|
||||
ss.Seek(0);
|
||||
StandardParser parser(ss, cdb);
|
||||
assert(parser.Parse());
|
||||
|
||||
cdb.MoveToRoot();
|
||||
uint32 n = cdb.GetNumberOfChildren();
|
||||
for (uint32 i=0; i<n; i++) {
|
||||
const char8* name = cdb.GetChildName(i);
|
||||
ConfigurationDatabase child;
|
||||
cdb.MoveRelative(name);
|
||||
cdb.Copy(child);
|
||||
cdb.MoveToAncestor(1u);
|
||||
StreamString className;
|
||||
child.Read("Class", className);
|
||||
Reference ref(className.Buffer(), GlobalObjectsDatabase::Instance()->GetStandardHeap());
|
||||
ref->SetName(name);
|
||||
assert(ref->Initialise(child));
|
||||
ObjectRegistryDatabase::Instance()->Insert(ref);
|
||||
}
|
||||
|
||||
printf("Application and DebugService (port 8100) initialised.\n");
|
||||
|
||||
// Start the application to trigger broker execution and signal registration
|
||||
ReferenceT<RealTimeApplication> app = ObjectRegistryDatabase::Instance()->Find("App");
|
||||
assert(app.IsValid());
|
||||
assert(app->ConfigureApplication());
|
||||
assert(app->PrepareNextState("State1") == ErrorManagement::NoError);
|
||||
assert(app->StartNextStateExecution() == ErrorManagement::NoError);
|
||||
printf("Application started (for signal registration).\n");
|
||||
Sleep::MSec(500); // Wait for some cycles
|
||||
|
||||
ReferenceT<DebugService> service = ObjectRegistryDatabase::Instance()->Find("DebugService");
|
||||
if (service.IsValid()) {
|
||||
service->SetFullConfig(cdb);
|
||||
}
|
||||
|
||||
Sleep::MSec(1000);
|
||||
|
||||
// 1. Test CONFIG command
|
||||
{
|
||||
printf("Testing CONFIG command...\n");
|
||||
StreamString reply;
|
||||
assert(SendCommandAndGetReply(8100, "CONFIG\n", reply));
|
||||
printf("\n%s\n", reply.Buffer());
|
||||
// Verify it contains some key parts of the config
|
||||
assert(StringHelper::SearchString(reply.Buffer(), "MyCustomField") != NULL_PTR(const char8*));
|
||||
assert(StringHelper::SearchString(reply.Buffer(), "HelloConfig") != NULL_PTR(const char8*));
|
||||
assert(StringHelper::SearchString(reply.Buffer(), "PROC:VAR:1") != NULL_PTR(const char8*));
|
||||
assert(StringHelper::SearchString(reply.Buffer(), "OK CONFIG") != NULL_PTR(const char8*));
|
||||
printf("SUCCESS: CONFIG command validated.\n");
|
||||
}
|
||||
|
||||
// 2. Test INFO on object with enrichment
|
||||
{
|
||||
printf("Testing INFO on App.Functions.GAM1...\n");
|
||||
StreamString reply;
|
||||
assert(SendCommandAndGetReply(8100, "INFO App.Functions.GAM1\n", reply));
|
||||
// Check standard MARTe fields (Name, Class)
|
||||
assert(StringHelper::SearchString(reply.Buffer(), "\"Name\": \"GAM1\"") != NULL_PTR(const char8*));
|
||||
// Check enriched fields from fullConfig
|
||||
assert(StringHelper::SearchString(reply.Buffer(), "\"CustomGAMField\": \"GAMValue\"") != NULL_PTR(const char8*));
|
||||
assert(StringHelper::SearchString(reply.Buffer(), "OK INFO") != NULL_PTR(const char8*));
|
||||
printf("SUCCESS: Object metadata enrichment validated.\n");
|
||||
}
|
||||
|
||||
// 3. Test INFO on signal with enrichment
|
||||
{
|
||||
printf("Testing INFO on App.Functions.GAM1.In.Counter...\n");
|
||||
StreamString reply;
|
||||
assert(SendCommandAndGetReply(8100, "INFO App.Functions.GAM1.In.Counter\n", reply));
|
||||
|
||||
// Check enriched fields from signal configuration
|
||||
assert(StringHelper::SearchString(reply.Buffer(), "\"Frequency\": \"1000\"") != NULL_PTR(const char8*));
|
||||
assert(StringHelper::SearchString(reply.Buffer(), "\"PVName\": \"PROC:VAR:1\"") != NULL_PTR(const char8*));
|
||||
assert(StringHelper::SearchString(reply.Buffer(), "OK INFO") != NULL_PTR(const char8*));
|
||||
printf("SUCCESS: Signal metadata enrichment validated.\n");
|
||||
}
|
||||
|
||||
if (app.IsValid()) {
|
||||
app->StopCurrentStateExecution();
|
||||
}
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
#include "ClassRegistryDatabase.h"
|
||||
#include "ConfigurationDatabase.h"
|
||||
#include "DebugService.h"
|
||||
#include "ObjectRegistryDatabase.h"
|
||||
#include "ErrorManagement.h"
|
||||
#include "BasicTCPSocket.h"
|
||||
#include "BasicUDPSocket.h"
|
||||
#include "RealTimeApplication.h"
|
||||
#include "StandardParser.h"
|
||||
#include "TestCommon.h"
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace MARTe;
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void timeout_handler(int sig) {
|
||||
printf("Test timed out!\n");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
void ErrorProcessFunction(const MARTe::ErrorManagement::ErrorInformation &errorInfo, const char8 * const errorDescription) {
|
||||
printf("[MARTe Error] %s: %s\n", errorInfo.className, errorDescription);
|
||||
}
|
||||
|
||||
// Forward declarations of other tests
|
||||
void TestSchedulerControl();
|
||||
void TestFullTracePipeline();
|
||||
void RunValidationTest();
|
||||
void TestConfigCommands();
|
||||
void TestGAMSignalTracing();
|
||||
void TestTreeCommand();
|
||||
|
||||
int main() {
|
||||
signal(SIGALRM, timeout_handler);
|
||||
alarm(180);
|
||||
|
||||
MARTe::ErrorManagement::SetErrorProcessFunction(&ErrorProcessFunction);
|
||||
|
||||
printf("MARTe2 Debug Suite Integration Tests\n");
|
||||
|
||||
printf("\n--- Test 1: Registry Patching ---\n");
|
||||
{
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
DebugService service;
|
||||
ConfigurationDatabase serviceData;
|
||||
serviceData.Write("ControlPort", (uint32)9090);
|
||||
service.Initialise(serviceData);
|
||||
printf("DebugService initialized and Registry Patched.\n");
|
||||
|
||||
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");
|
||||
} else {
|
||||
printf("Failed to build broker\n");
|
||||
}
|
||||
} else {
|
||||
printf("MemoryMapInputBroker not found in registry\n");
|
||||
}
|
||||
}
|
||||
Sleep::MSec(1000);
|
||||
|
||||
printf("\n--- Test 2: Full Trace Pipeline ---\n");
|
||||
TestFullTracePipeline();
|
||||
Sleep::MSec(1000);
|
||||
|
||||
printf("\n--- Test 3: Scheduler Control ---\n");
|
||||
TestSchedulerControl();
|
||||
Sleep::MSec(1000);
|
||||
|
||||
printf("\n--- Test 4: 1kHz Lossless Trace Validation ---\n");
|
||||
RunValidationTest();
|
||||
Sleep::MSec(1000);
|
||||
|
||||
printf("\n--- Test 5: Config & Metadata Enrichment ---\n");
|
||||
TestConfigCommands();
|
||||
Sleep::MSec(1000);
|
||||
|
||||
printf("\n--- Test 6: TREE Command Enhancement ---\n");
|
||||
TestTreeCommand();
|
||||
Sleep::MSec(1000);
|
||||
|
||||
printf("\n--- Test 7: Custom MARTe Message (MSG) ---\n");
|
||||
TestMessageCommand();
|
||||
Sleep::MSec(1000);
|
||||
|
||||
printf("\nAll Integration Tests Finished.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// --- Test Implementation ---
|
||||
|
||||
void TestGAMSignalTracing() {
|
||||
printf("--- Test: GAM Signal Tracing Issue ---\n");
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
|
||||
ConfigurationDatabase cdb;
|
||||
StreamString ss = debug_test_config;
|
||||
ss.Seek(0);
|
||||
StandardParser parser(ss, cdb);
|
||||
if (!parser.Parse()) {
|
||||
printf("ERROR: Failed to parse config\n");
|
||||
return;
|
||||
}
|
||||
|
||||
cdb.MoveToRoot();
|
||||
uint32 n = cdb.GetNumberOfChildren();
|
||||
for (uint32 i=0; i<n; i++) {
|
||||
const char8* name = cdb.GetChildName(i);
|
||||
ConfigurationDatabase child;
|
||||
cdb.MoveRelative(name);
|
||||
cdb.Copy(child);
|
||||
cdb.MoveToAncestor(1u);
|
||||
|
||||
StreamString className;
|
||||
child.Read("Class", className);
|
||||
|
||||
Reference ref(className.Buffer(), GlobalObjectsDatabase::Instance()->GetStandardHeap());
|
||||
if (!ref.IsValid()) {
|
||||
printf("ERROR: Could not create object %s of class %s\n", name, className.Buffer());
|
||||
continue;
|
||||
}
|
||||
ref->SetName(name);
|
||||
if (!ref->Initialise(child)) {
|
||||
printf("ERROR: Failed to initialise object %s\n", name);
|
||||
continue;
|
||||
}
|
||||
ObjectRegistryDatabase::Instance()->Insert(ref);
|
||||
}
|
||||
|
||||
ReferenceT<DebugService> service = ObjectRegistryDatabase::Instance()->Find("DebugService");
|
||||
if (!service.IsValid()) {
|
||||
printf("ERROR: DebugService not found\n");
|
||||
return;
|
||||
}
|
||||
service->SetFullConfig(cdb);
|
||||
|
||||
ReferenceT<RealTimeApplication> app = ObjectRegistryDatabase::Instance()->Find("App");
|
||||
if (!app.IsValid()) {
|
||||
printf("ERROR: App not found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!app->ConfigureApplication()) {
|
||||
printf("ERROR: ConfigureApplication failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (app->PrepareNextState("State1") != ErrorManagement::NoError) {
|
||||
printf("ERROR: PrepareNextState failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (app->StartNextStateExecution() != ErrorManagement::NoError) {
|
||||
printf("ERROR: StartNextStateExecution failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Application started.\n");
|
||||
Sleep::MSec(1000);
|
||||
|
||||
// Step 1: Discover signals
|
||||
{
|
||||
StreamString reply;
|
||||
if (SendCommandGAM(8095, "DISCOVER\n", reply)) {
|
||||
printf("DISCOVER response received (len=%llu)\n", reply.Size());
|
||||
} else {
|
||||
printf("ERROR: DISCOVER failed\n");
|
||||
}
|
||||
}
|
||||
Sleep::MSec(500);
|
||||
|
||||
// Step 2: Trace a DataSource signal (Timer.Counter)
|
||||
printf("\n--- Step 1: Trace DataSource signal (Timer.Counter) ---\n");
|
||||
{
|
||||
StreamString reply;
|
||||
if (SendCommandGAM(8095, "TRACE App.Data.Timer.Counter 1\n", reply)) {
|
||||
printf("TRACE response: %s", reply.Buffer());
|
||||
} else {
|
||||
printf("ERROR: TRACE failed\n");
|
||||
}
|
||||
}
|
||||
Sleep::MSec(500);
|
||||
|
||||
// Step 3: Trace a GAM input signal (GAM1.In.Counter)
|
||||
printf("\n--- Step 2: Trace GAM input signal (GAM1.In.Counter) ---\n");
|
||||
{
|
||||
StreamString reply;
|
||||
if (SendCommandGAM(8095, "TRACE App.Functions.GAM1.In.Counter 1\n", reply)) {
|
||||
printf("TRACE response: %s", reply.Buffer());
|
||||
} else {
|
||||
printf("ERROR: TRACE failed\n");
|
||||
}
|
||||
}
|
||||
Sleep::MSec(500);
|
||||
|
||||
// Step 4: Try to trace another DataSource signal (TimerSlow.Counter)
|
||||
printf("\n--- Step 3: Try to trace another signal (TimerSlow.Counter) ---\n");
|
||||
{
|
||||
StreamString reply;
|
||||
if (SendCommandGAM(8095, "TRACE App.Data.TimerSlow.Counter 1\n", reply)) {
|
||||
printf("TRACE response: %s", reply.Buffer());
|
||||
} else {
|
||||
printf("ERROR: TRACE failed\n");
|
||||
}
|
||||
}
|
||||
Sleep::MSec(500);
|
||||
|
||||
// Step 5: Check if we can still trace more signals
|
||||
printf("\n--- Step 4: Try to trace Logger.Counter ---\n");
|
||||
{
|
||||
StreamString reply;
|
||||
if (SendCommandGAM(8095, "TRACE App.Data.Logger.Counter 1\n", reply)) {
|
||||
printf("TRACE response: %s", reply.Buffer());
|
||||
} else {
|
||||
printf("ERROR: TRACE failed\n");
|
||||
}
|
||||
}
|
||||
Sleep::MSec(500);
|
||||
|
||||
// Verify UDP is still receiving data
|
||||
BasicUDPSocket listener;
|
||||
listener.Open();
|
||||
listener.Listen(8096);
|
||||
|
||||
char buffer[1024];
|
||||
uint32 size = 1024;
|
||||
TimeoutType timeout(1000);
|
||||
int packetCount = 0;
|
||||
while (listener.Read(buffer, size, timeout)) {
|
||||
packetCount++;
|
||||
size = 1024;
|
||||
}
|
||||
|
||||
printf("\n--- Results ---\n");
|
||||
if (packetCount > 0) {
|
||||
printf("SUCCESS: Received %d UDP packets.\n", packetCount);
|
||||
} else {
|
||||
printf("FAILURE: No UDP packets received. Possible deadlock or crash.\n");
|
||||
}
|
||||
|
||||
app->StopCurrentStateExecution();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
include Makefile.inc
|
||||
@@ -0,0 +1,43 @@
|
||||
OBJSX = SchedulerTest.x TraceTest.x ValidationTest.x ConfigCommandTest.x TreeCommandTest.x MessageCommandTest.x TestCommon.x
|
||||
|
||||
PACKAGE = Test/Integration
|
||||
|
||||
ROOT_DIR = ../..
|
||||
|
||||
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
|
||||
|
||||
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
|
||||
|
||||
INCLUDES += -I$(ROOT_DIR)/Common/UDP
|
||||
INCLUDES += -I$(ROOT_DIR)/Source/Components/Interfaces/DebugService
|
||||
INCLUDES += -I$(ROOT_DIR)/Source/Components/Interfaces/TCPLogger
|
||||
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L0Types
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L1Portability
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L2Objects
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L3Streams
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L4Messages
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L4Logger
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L4Configuration
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L5GAMs
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/BareMetal/L6App
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L1Portability
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L3Services
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L4Messages
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L4LoggerService
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/Scheduler/L5GAMs
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/FileSystem/L1Portability
|
||||
INCLUDES += -I$(MARTe2_DIR)/Source/Core/FileSystem/L3Streams
|
||||
INCLUDES += -I$(MARTe2_Components_DIR)/Source/Components/GAMs/IOGAM
|
||||
INCLUDES += -I$(MARTe2_Components_DIR)/Source/Components/DataSources/LinuxTimer
|
||||
|
||||
LIBRARIES += -L$(MARTe2_DIR)/Build/$(TARGET)/Core -lMARTe2
|
||||
LIBRARIES += -L$(MARTe2_Components_DIR)/Build/$(TARGET)/Components/DataSources/LinuxTimer -lLinuxTimer
|
||||
LIBRARIES += -L$(MARTe2_Components_DIR)/Build/$(TARGET)/Components/GAMs/IOGAM -lIOGAM
|
||||
LIBRARIES += -L$(ROOT_DIR)/Build/$(TARGET)/Components/Interfaces/DebugService -lDebugService
|
||||
LIBRARIES += -L$(ROOT_DIR)/Build/$(TARGET)/Components/Interfaces/TCPLogger -lTcpLogger
|
||||
|
||||
all: $(OBJS) $(BUILD_DIR)/IntegrationTests$(EXEEXT)
|
||||
echo $(OBJS)
|
||||
|
||||
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "TestCommon.h"
|
||||
#include "ObjectRegistryDatabase.h"
|
||||
#include "DebugService.h"
|
||||
#include "StandardParser.h"
|
||||
#include "GlobalObjectsDatabase.h"
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace MARTe;
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
void TestMessageCommand() {
|
||||
printf("--- Test: Custom MARTe Message (MSG) ---\n");
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
Sleep::MSec(1000);
|
||||
|
||||
ConfigurationDatabase cdb;
|
||||
const char8 * const msg_test_config =
|
||||
"DebugService = {"
|
||||
" Class = DebugService "
|
||||
" ControlPort = 8120 "
|
||||
" UdpPort = 8121 "
|
||||
" StreamIP = \"127.0.0.1\" "
|
||||
"}";
|
||||
|
||||
StreamString ss = msg_test_config;
|
||||
ss.Seek(0);
|
||||
StandardParser parser(ss, cdb);
|
||||
if (!parser.Parse()) {
|
||||
printf("ERROR: Failed to parse config\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize Service
|
||||
ReferenceT<DebugService> service("DebugService", GlobalObjectsDatabase::Instance()->GetStandardHeap());
|
||||
service->SetName("DebugService");
|
||||
|
||||
cdb.MoveToRoot();
|
||||
if (cdb.MoveRelative("DebugService")) {
|
||||
if (!service->Initialise(cdb)) {
|
||||
printf("ERROR: Failed to initialize DebugService\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
ObjectRegistryDatabase::Instance()->Insert(service);
|
||||
|
||||
if (ObjectRegistryDatabase::Instance()->Find("DebugService").IsValid()) {
|
||||
printf("DebugService successfully registered in ORD.\n");
|
||||
} else {
|
||||
printf("ERROR: DebugService NOT found in ORD.\n");
|
||||
}
|
||||
|
||||
printf("Service initialized on port 8120.\n");
|
||||
Sleep::MSec(500);
|
||||
|
||||
StreamString reply;
|
||||
if (SendCommandGAM(8120, "MSG DebugService UnknownFunc 0 Key1=Val1\\nKey2=Val2\n", reply)) {
|
||||
printf("MSG response received: %s", reply.Buffer());
|
||||
if (StringHelper::SearchString(reply.Buffer(), "OK MSG") != NULL_PTR(const char8 *)) {
|
||||
printf("SUCCESS: Asynchronous message dispatched correctly.\n");
|
||||
} else {
|
||||
printf("FAILURE: MSG command returned error.\n");
|
||||
}
|
||||
} else {
|
||||
printf("ERROR: MSG command communication failed\n");
|
||||
}
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
}
|
||||
|
||||
} // namespace MARTe
|
||||
@@ -0,0 +1,253 @@
|
||||
#include "BasicTCPSocket.h"
|
||||
#include "BasicUDPSocket.h"
|
||||
#include "DebugService.h"
|
||||
#include "ObjectRegistryDatabase.h"
|
||||
#include "RealTimeApplication.h"
|
||||
#include "StandardParser.h"
|
||||
#include "StreamString.h"
|
||||
#include "GlobalObjectsDatabase.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace MARTe;
|
||||
|
||||
const char8 * const scheduler_config_text =
|
||||
"DebugService = {"
|
||||
" Class = DebugService "
|
||||
" ControlPort = 8098 "
|
||||
" UdpPort = 8099 "
|
||||
" StreamIP = \"127.0.0.1\" "
|
||||
"}"
|
||||
"App = {"
|
||||
" Class = RealTimeApplication "
|
||||
" +Functions = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +GAM1 = {"
|
||||
" Class = IOGAM "
|
||||
" InputSignals = {"
|
||||
" Counter = { DataSource = Timer Type = uint32 Frequency = 1000 }"
|
||||
" Time = { DataSource = Timer Type = uint32 }"
|
||||
" }"
|
||||
" OutputSignals = {"
|
||||
" Counter = { DataSource = DDB Type = uint32 }"
|
||||
" Time = { DataSource = DDB Type = uint32 }"
|
||||
" }"
|
||||
" }"
|
||||
" }"
|
||||
" +Data = {"
|
||||
" Class = ReferenceContainer "
|
||||
" DefaultDataSource = DDB "
|
||||
" +Timer = { Class = LinuxTimer SleepTime = 1000 Signals = { Counter = { Type = uint32 } Time = { Type = uint32 } } }"
|
||||
" +DDB = { Class = GAMDataSource Signals = { Counter = { Type = uint32 } Time = { 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 TestSchedulerControl() {
|
||||
printf("--- MARTe2 Scheduler Control Test ---\n");
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
|
||||
ConfigurationDatabase cdb;
|
||||
StreamString ss = scheduler_config_text;
|
||||
ss.Seek(0);
|
||||
StandardParser parser(ss, cdb);
|
||||
if (!parser.Parse()) {
|
||||
printf("ERROR: Failed to parse configuration\n");
|
||||
return;
|
||||
}
|
||||
|
||||
cdb.MoveToRoot();
|
||||
uint32 n = cdb.GetNumberOfChildren();
|
||||
for (uint32 i=0; i<n; i++) {
|
||||
const char8* name = cdb.GetChildName(i);
|
||||
ConfigurationDatabase child;
|
||||
cdb.MoveRelative(name);
|
||||
cdb.Copy(child);
|
||||
cdb.MoveToAncestor(1u);
|
||||
|
||||
StreamString className;
|
||||
child.Read("Class", className);
|
||||
|
||||
Reference ref(className.Buffer(), GlobalObjectsDatabase::Instance()->GetStandardHeap());
|
||||
if (!ref.IsValid()) {
|
||||
printf("ERROR: Could not create object %s of class %s\n", name, className.Buffer());
|
||||
continue;
|
||||
}
|
||||
ref->SetName(name);
|
||||
if (!ref->Initialise(child)) {
|
||||
printf("ERROR: Failed to initialise object %s\n", name);
|
||||
continue;
|
||||
}
|
||||
ObjectRegistryDatabase::Instance()->Insert(ref);
|
||||
}
|
||||
|
||||
ReferenceT<DebugService> service =
|
||||
ObjectRegistryDatabase::Instance()->Find("DebugService");
|
||||
if (!service.IsValid()) {
|
||||
printf("ERROR: DebugService not found in registry\n");
|
||||
return;
|
||||
}
|
||||
service->SetFullConfig(cdb);
|
||||
|
||||
ReferenceT<RealTimeApplication> app =
|
||||
ObjectRegistryDatabase::Instance()->Find("App");
|
||||
if (!app.IsValid()) {
|
||||
printf("ERROR: App not found in registry\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!app->ConfigureApplication()) {
|
||||
printf("ERROR: ConfigureApplication failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (app->PrepareNextState("State1") != ErrorManagement::NoError) {
|
||||
printf("ERROR: Failed to prepare State1\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (app->StartNextStateExecution() != ErrorManagement::NoError) {
|
||||
printf("ERROR: Failed to start execution\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Application started. Waiting for cycles...\n");
|
||||
Sleep::MSec(2000);
|
||||
|
||||
// Enable Trace First - with retry logic
|
||||
{
|
||||
bool connected = false;
|
||||
for (int retry=0; retry<10 && !connected; retry++) {
|
||||
BasicTCPSocket tClient;
|
||||
if (tClient.Open()) {
|
||||
if (tClient.Connect("127.0.0.1", 8098)) {
|
||||
connected = true;
|
||||
const char *cmd = "TRACE App.Data.Timer.Counter 1\n";
|
||||
uint32 s = StringHelper::Length(cmd);
|
||||
tClient.Write(cmd, s);
|
||||
tClient.Close();
|
||||
} else {
|
||||
printf("[SchedulerTest] Connect failed (retry %d)\n", retry);
|
||||
Sleep::MSec(500);
|
||||
}
|
||||
} else {
|
||||
printf("[SchedulerTest] Open failed (retry %d)\n", retry);
|
||||
Sleep::MSec(500);
|
||||
}
|
||||
}
|
||||
|
||||
if (!connected) {
|
||||
printf("WARNING: Could not connect to DebugService to enable trace.\n");
|
||||
}
|
||||
}
|
||||
|
||||
BasicUDPSocket listener;
|
||||
listener.Open();
|
||||
listener.Listen(8099);
|
||||
|
||||
// Read current value
|
||||
uint32 valBeforePause = 0;
|
||||
char buffer[2048];
|
||||
uint32 size = 2048;
|
||||
TimeoutType timeout(1000);
|
||||
if (listener.Read(buffer, size, timeout)) {
|
||||
// [Header][ID][Size][Value]
|
||||
valBeforePause = *(uint32 *)(&buffer[sizeof(TraceHeader) + 16]);
|
||||
printf("Value before/at pause: %u\n", valBeforePause);
|
||||
} else {
|
||||
printf("WARNING: No data received before pause.\n");
|
||||
}
|
||||
|
||||
// Send PAUSE
|
||||
printf("Sending PAUSE command...\n");
|
||||
{
|
||||
bool connected = false;
|
||||
for (int retry=0; retry<10 && !connected; retry++) {
|
||||
BasicTCPSocket client;
|
||||
if (client.Open()) {
|
||||
if (client.Connect("127.0.0.1", 8098)) {
|
||||
connected = true;
|
||||
const char *cmd = "PAUSE\n";
|
||||
uint32 s = StringHelper::Length(cmd);
|
||||
client.Write(cmd, s);
|
||||
client.Close();
|
||||
} else {
|
||||
Sleep::MSec(200);
|
||||
}
|
||||
} else {
|
||||
Sleep::MSec(200);
|
||||
}
|
||||
}
|
||||
|
||||
if (!connected) {
|
||||
printf("ERROR: Could not connect to DebugService to send PAUSE.\n");
|
||||
}
|
||||
}
|
||||
|
||||
Sleep::MSec(2000); // Wait 2 seconds
|
||||
|
||||
// Read again - should be same or very close if paused
|
||||
uint32 valAfterWait = 0;
|
||||
size = 2048; // Reset size
|
||||
while (listener.Read(buffer, size, TimeoutType(100))) {
|
||||
valAfterWait = *(uint32 *)(&buffer[sizeof(TraceHeader) + 16]);
|
||||
size = 2048;
|
||||
}
|
||||
|
||||
printf("Value after 2s wait (drained): %u\n", valAfterWait);
|
||||
|
||||
// Check if truly paused
|
||||
if (valAfterWait > valBeforePause + 10) {
|
||||
printf(
|
||||
"FAILURE: Counter increased significantly while paused! (%u -> %u)\n",
|
||||
valBeforePause, valAfterWait);
|
||||
} else {
|
||||
printf("SUCCESS: Counter held steady (or close) during pause.\n");
|
||||
}
|
||||
|
||||
// Resume
|
||||
printf("Sending RESUME command...\n");
|
||||
{
|
||||
bool connected = false;
|
||||
for (int retry=0; retry<10 && !connected; retry++) {
|
||||
BasicTCPSocket rClient;
|
||||
if (rClient.Open()) {
|
||||
if (rClient.Connect("127.0.0.1", 8098)) {
|
||||
connected = true;
|
||||
const char *cmd = "RESUME\n";
|
||||
uint32 s = StringHelper::Length(cmd);
|
||||
rClient.Write(cmd, s);
|
||||
rClient.Close();
|
||||
} else {
|
||||
Sleep::MSec(200);
|
||||
}
|
||||
} else {
|
||||
Sleep::MSec(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Sleep::MSec(1000);
|
||||
|
||||
// Check if increasing
|
||||
uint32 valAfterResume = 0;
|
||||
size = 2048;
|
||||
if (listener.Read(buffer, size, timeout)) {
|
||||
valAfterResume = *(uint32 *)(&buffer[sizeof(TraceHeader) + 16]);
|
||||
printf("Value after resume: %u\n", valAfterResume);
|
||||
}
|
||||
|
||||
if (valAfterResume > valAfterWait) {
|
||||
printf("SUCCESS: Execution resumed.\n");
|
||||
} else {
|
||||
printf("FAILURE: Execution did not resume.\n");
|
||||
}
|
||||
|
||||
app->StopCurrentStateExecution();
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#include "TestCommon.h"
|
||||
#include "BasicTCPSocket.h"
|
||||
#include "StringHelper.h"
|
||||
#include "TimeoutType.h"
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
const char8 * const debug_test_config =
|
||||
"DebugService = {"
|
||||
" Class = DebugService "
|
||||
" ControlPort = 8095 "
|
||||
" UdpPort = 8096 "
|
||||
" StreamIP = \"127.0.0.1\" "
|
||||
"}"
|
||||
"App = {"
|
||||
" Class = RealTimeApplication "
|
||||
" +Functions = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +GAM1 = {"
|
||||
" Class = IOGAM "
|
||||
" InputSignals = {"
|
||||
" Counter = { DataSource = Timer Type = uint32 Frequency = 1000 }"
|
||||
" }"
|
||||
" OutputSignals = {"
|
||||
" Counter = { DataSource = DDB Type = uint32 }"
|
||||
" }"
|
||||
" }"
|
||||
" +GAM2 = {"
|
||||
" Class = IOGAM "
|
||||
" InputSignals = {"
|
||||
" Counter = { DataSource = TimerSlow Type = uint32 Frequency = 10 }"
|
||||
" }"
|
||||
" OutputSignals = {"
|
||||
" Counter = { DataSource = Logger Type = uint32 }"
|
||||
" }"
|
||||
" }"
|
||||
" }"
|
||||
" +Data = {"
|
||||
" Class = ReferenceContainer "
|
||||
" DefaultDataSource = DDB "
|
||||
" +Timer = { Class = LinuxTimer SleepTime = 1000 Signals = { Counter = { Type = uint32 } } }"
|
||||
" +TimerSlow = { Class = LinuxTimer SleepTime = 100000 Signals = { Counter = { Type = uint32 } } }"
|
||||
" +Logger = { Class = LoggerDataSource 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 GAM2} } } }"
|
||||
" }"
|
||||
" +Scheduler = { Class = GAMScheduler TimingDataSource = DAMS }"
|
||||
"}";
|
||||
|
||||
bool SendCommandGAM(uint16 port, const char8* cmd, StreamString &reply) {
|
||||
BasicTCPSocket client;
|
||||
if (!client.Open()) return false;
|
||||
if (!client.Connect("127.0.0.1", port)) return false;
|
||||
|
||||
uint32 s = StringHelper::Length(cmd);
|
||||
if (!client.Write(cmd, s)) return false;
|
||||
|
||||
char buffer[16384];
|
||||
uint32 size = 16384;
|
||||
TimeoutType timeout(5000);
|
||||
if (client.Read(buffer, size, timeout)) {
|
||||
reply.Write(buffer, size);
|
||||
client.Close();
|
||||
return true;
|
||||
}
|
||||
client.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef TESTCOMMON_H
|
||||
#define TESTCOMMON_H
|
||||
|
||||
#include "CompilerTypes.h"
|
||||
#include "StreamString.h"
|
||||
|
||||
namespace MARTe {
|
||||
extern const char8 * const debug_test_config;
|
||||
bool SendCommandGAM(uint16 port, const char8* cmd, StreamString &reply);
|
||||
void TestMessageCommand();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "BasicTCPSocket.h"
|
||||
#include "BasicUDPSocket.h"
|
||||
#include "DebugService.h"
|
||||
#include "ObjectRegistryDatabase.h"
|
||||
#include "StandardParser.h"
|
||||
#include "StreamString.h"
|
||||
#include "HighResolutionTimer.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace MARTe;
|
||||
|
||||
void TestFullTracePipeline() {
|
||||
printf("Starting Full Trace Pipeline Test...\n");
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
|
||||
// 1. Setup Service
|
||||
DebugService service;
|
||||
ConfigurationDatabase config;
|
||||
config.Write("ControlPort", (uint16)8082);
|
||||
config.Write("StreamPort", (uint16)8083);
|
||||
config.Write("LogPort", (uint16)8084);
|
||||
config.Write("StreamIP", "127.0.0.1");
|
||||
assert(service.Initialise(config));
|
||||
Sleep::MSec(500);
|
||||
|
||||
// 2. Register a mock signal
|
||||
uint32 mockValue = 0;
|
||||
DebugSignalInfo* sig = service.RegisterSignal(&mockValue, UnsignedInteger32Bit, "TraceTest.Signal", 0, 1);
|
||||
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(8083));
|
||||
|
||||
// 5. Simulate cycles
|
||||
printf("Simulating cycles...\n");
|
||||
for (int i=0; i<50; i++) {
|
||||
mockValue = 1000 + i;
|
||||
uint64 ts = (uint64)((float64)HighResolutionTimer::Counter() * HighResolutionTimer::Period() * 1000000.0);
|
||||
service.ProcessSignal(sig, sizeof(uint32), ts);
|
||||
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);
|
||||
|
||||
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 + 16) {
|
||||
uint32 recId = *(uint32*)(&buffer[offset]);
|
||||
uint64 recTs = *(uint64*)(&buffer[offset + 4]);
|
||||
uint32 recSize = *(uint32*)(&buffer[offset + 12]);
|
||||
printf("Data: ID=%u, TS=%llu, Size=%u\n", recId, (unsigned long long)recTs, recSize);
|
||||
if (size >= offset + 16 + recSize) {
|
||||
if (recSize == 4) {
|
||||
uint32 recVal = *(uint32*)(&buffer[offset + 16]);
|
||||
printf("Value=%u\n", recVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("FAILURE: No UDP packets received.\n");
|
||||
}
|
||||
|
||||
listener.Close();
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
#include "BasicTCPSocket.h"
|
||||
#include "ConfigurationDatabase.h"
|
||||
#include "DebugService.h"
|
||||
#include "GlobalObjectsDatabase.h"
|
||||
#include "ObjectRegistryDatabase.h"
|
||||
#include "RealTimeApplication.h"
|
||||
#include "StandardParser.h"
|
||||
#include "StreamString.h"
|
||||
#include "TestCommon.h"
|
||||
#include "IOGAM.h"
|
||||
#include "LinuxTimer.h"
|
||||
#include "GAMDataSource.h"
|
||||
#include "TimingDataSource.h"
|
||||
#include "GAMScheduler.h"
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace MARTe;
|
||||
|
||||
void TestTreeCommand() {
|
||||
printf("--- Test: TREE Command Enhancement ---\n");
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
Sleep::MSec(2000); // Wait for sockets from previous tests to clear
|
||||
|
||||
ConfigurationDatabase cdb;
|
||||
// Use unique ports to avoid conflict with other tests
|
||||
const char8 * const tree_test_config =
|
||||
"DebugService = {"
|
||||
" Class = DebugService "
|
||||
" ControlPort = 8110 "
|
||||
" UdpPort = 8111 "
|
||||
" StreamIP = \"127.0.0.1\" "
|
||||
"}"
|
||||
"App = {"
|
||||
" Class = RealTimeApplication "
|
||||
" +Functions = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +GAM1 = {"
|
||||
" Class = IOGAM "
|
||||
" InputSignals = {"
|
||||
" Counter = { DataSource = Timer Type = uint32 Frequency = 1000 }"
|
||||
" Time = { DataSource = Timer Type = uint32 }"
|
||||
" }"
|
||||
" OutputSignals = {"
|
||||
" Counter = { DataSource = DDB Type = uint32 }"
|
||||
" Time = { DataSource = DDB Type = uint32 }"
|
||||
" }"
|
||||
" }"
|
||||
" }"
|
||||
" +Data = {"
|
||||
" Class = ReferenceContainer "
|
||||
" DefaultDataSource = DDB "
|
||||
" +Timer = { Class = LinuxTimer SleepTime = 1000 Signals = { Counter = { Type = uint32 } Time = { Type = uint32 } } }"
|
||||
" +DDB = { Class = GAMDataSource Signals = { Counter = { Type = uint32 } Time = { Type = uint32 } } }"
|
||||
" +DAMS = { Class = TimingDataSource }"
|
||||
" }"
|
||||
" +States = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +State1 = { Class = RealTimeState +Threads = { Class = ReferenceContainer +Thread1 = { Class = RealTimeThread Functions = {GAM1} } } }"
|
||||
" }"
|
||||
" +Scheduler = { Class = GAMScheduler TimingDataSource = DAMS }"
|
||||
"}";
|
||||
|
||||
StreamString ss = tree_test_config;
|
||||
ss.Seek(0);
|
||||
StandardParser parser(ss, cdb);
|
||||
if (!parser.Parse()) {
|
||||
printf("ERROR: Failed to parse config\n");
|
||||
return;
|
||||
}
|
||||
|
||||
cdb.MoveToRoot();
|
||||
uint32 n = cdb.GetNumberOfChildren();
|
||||
for (uint32 i = 0; i < n; i++) {
|
||||
const char8 *name = cdb.GetChildName(i);
|
||||
ConfigurationDatabase child;
|
||||
cdb.MoveRelative(name);
|
||||
cdb.Copy(child);
|
||||
cdb.MoveToAncestor(1u);
|
||||
|
||||
StreamString className;
|
||||
child.Read("Class", className);
|
||||
|
||||
Reference ref(className.Buffer(),
|
||||
GlobalObjectsDatabase::Instance()->GetStandardHeap());
|
||||
if (!ref.IsValid()) {
|
||||
printf("ERROR: Could not create object %s of class %s\n", name,
|
||||
className.Buffer());
|
||||
continue;
|
||||
}
|
||||
ref->SetName(name);
|
||||
if (!ref->Initialise(child)) {
|
||||
printf("ERROR: Failed to initialise object %s\n", name);
|
||||
continue;
|
||||
}
|
||||
ObjectRegistryDatabase::Instance()->Insert(ref);
|
||||
}
|
||||
|
||||
ReferenceT<DebugService> service =
|
||||
ObjectRegistryDatabase::Instance()->Find("DebugService");
|
||||
if (!service.IsValid()) {
|
||||
printf("ERROR: DebugService not found\n");
|
||||
return;
|
||||
}
|
||||
service->SetFullConfig(cdb);
|
||||
|
||||
ReferenceT<RealTimeApplication> app =
|
||||
ObjectRegistryDatabase::Instance()->Find("App");
|
||||
if (!app.IsValid()) {
|
||||
printf("ERROR: App not found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!app->ConfigureApplication()) {
|
||||
printf("ERROR: ConfigureApplication failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (app->PrepareNextState("State1") != ErrorManagement::NoError) {
|
||||
printf("ERROR: PrepareNextState failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (app->StartNextStateExecution() != ErrorManagement::NoError) {
|
||||
printf("ERROR: StartNextStateExecution failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Application started.\n");
|
||||
Sleep::MSec(1000);
|
||||
|
||||
// Step 1: Request TREE
|
||||
StreamString reply;
|
||||
if (SendCommandGAM(8110, "TREE\n", reply)) {
|
||||
printf("TREE response received (len=%llu)\n", reply.Size());
|
||||
// ...
|
||||
}
|
||||
|
||||
// Step 2: SERVICE_INFO
|
||||
printf("\n--- Step 2: SERVICE_INFO ---\n");
|
||||
reply = "";
|
||||
if (SendCommandGAM(8110, "SERVICE_INFO\n", reply)) {
|
||||
printf("SERVICE_INFO response: %s", reply.Buffer());
|
||||
if (StringHelper::SearchString(reply.Buffer(), "TCP_CTRL:8110") != NULL_PTR(const char8 *) &&
|
||||
StringHelper::SearchString(reply.Buffer(), "UDP_STREAM:8111") != NULL_PTR(const char8 *)) {
|
||||
printf("SUCCESS: SERVICE_INFO returned correct ports.\n");
|
||||
} else {
|
||||
printf("FAILURE: SERVICE_INFO returned incorrect data.\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: MONITOR
|
||||
printf("\n--- Step 3: MONITOR SIGNAL ---\n");
|
||||
reply = "";
|
||||
if (SendCommandGAM(8110, "MONITOR SIGNAL App.Data.Timer.Counter 10\n", reply)) {
|
||||
printf("MONITOR response: %s", reply.Buffer());
|
||||
if (StringHelper::SearchString(reply.Buffer(), "OK MONITOR 1") != NULL_PTR(const char8 *)) {
|
||||
printf("SUCCESS: Signal monitored.\n");
|
||||
} else {
|
||||
printf("FAILURE: Could not monitor signal.\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Step 4: UNMONITOR
|
||||
printf("\n--- Step 4: UNMONITOR SIGNAL ---\n");
|
||||
reply = "";
|
||||
if (SendCommandGAM(8110, "UNMONITOR SIGNAL App.Data.Timer.Counter\n", reply)) {
|
||||
printf("UNMONITOR response: %s", reply.Buffer());
|
||||
if (StringHelper::SearchString(reply.Buffer(), "OK UNMONITOR 1") != NULL_PTR(const char8 *)) {
|
||||
printf("SUCCESS: Signal unmonitored.\n");
|
||||
} else {
|
||||
printf("FAILURE: Could not unmonitor signal.\n");
|
||||
}
|
||||
}
|
||||
|
||||
app->StopCurrentStateExecution();
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
#include "BasicTCPSocket.h"
|
||||
#include "BasicUDPSocket.h"
|
||||
#include "DebugService.h"
|
||||
#include "ObjectRegistryDatabase.h"
|
||||
#include "RealTimeApplication.h"
|
||||
#include "StandardParser.h"
|
||||
#include "StreamString.h"
|
||||
#include "GlobalObjectsDatabase.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace MARTe;
|
||||
|
||||
const char8 * const validation_config =
|
||||
"DebugService = {"
|
||||
" Class = DebugService "
|
||||
" ControlPort = 8085 "
|
||||
" UdpPort = 8086 "
|
||||
" StreamIP = \"127.0.0.1\" "
|
||||
"}"
|
||||
"App = {"
|
||||
" Class = RealTimeApplication "
|
||||
" +Functions = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +GAM1 = {"
|
||||
" Class = IOGAM "
|
||||
" InputSignals = {"
|
||||
" Counter = { DataSource = Timer Type = uint32 Frequency = 1000 }"
|
||||
" Time = { DataSource = Timer Type = uint32 }"
|
||||
" }"
|
||||
" OutputSignals = {"
|
||||
" Counter = { DataSource = DDB Type = uint32 }"
|
||||
" Time = { DataSource = DDB Type = uint32 }"
|
||||
" }"
|
||||
" }"
|
||||
" }"
|
||||
" +Data = {"
|
||||
" Class = ReferenceContainer "
|
||||
" DefaultDataSource = DDB "
|
||||
" +Timer = { Class = LinuxTimer SleepTime = 1000 Signals = { Counter = { Type = uint32 } Time = { Type = uint32 } } }"
|
||||
" +DDB = { Class = GAMDataSource Signals = { Counter = { Type = uint32 } Time = { 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 1kHz Lossless Trace Validation Test ---\n");
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
|
||||
ConfigurationDatabase cdb;
|
||||
StreamString ss = validation_config;
|
||||
ss.Seek(0);
|
||||
StandardParser parser(ss, cdb);
|
||||
assert(parser.Parse());
|
||||
|
||||
cdb.MoveToRoot();
|
||||
uint32 n = cdb.GetNumberOfChildren();
|
||||
for (uint32 i=0; i<n; i++) {
|
||||
const char8* name = cdb.GetChildName(i);
|
||||
ConfigurationDatabase child;
|
||||
cdb.MoveRelative(name);
|
||||
cdb.Copy(child);
|
||||
cdb.MoveToAncestor(1u);
|
||||
|
||||
StreamString className;
|
||||
child.Read("Class", className);
|
||||
|
||||
Reference ref(className.Buffer(), GlobalObjectsDatabase::Instance()->GetStandardHeap());
|
||||
ref->SetName(name);
|
||||
assert(ref->Initialise(child));
|
||||
ObjectRegistryDatabase::Instance()->Insert(ref);
|
||||
}
|
||||
|
||||
Reference serviceGeneric = ObjectRegistryDatabase::Instance()->Find("DebugService");
|
||||
Reference appGeneric = ObjectRegistryDatabase::Instance()->Find("App");
|
||||
|
||||
if (!serviceGeneric.IsValid() || !appGeneric.IsValid()) {
|
||||
printf("ERROR: Objects NOT FOUND in ValidationTest\n");
|
||||
return;
|
||||
}
|
||||
|
||||
DebugService *service = dynamic_cast<DebugService*>(serviceGeneric.operator->());
|
||||
RealTimeApplication *app = dynamic_cast<RealTimeApplication*>(appGeneric.operator->());
|
||||
|
||||
assert(service);
|
||||
assert(app);
|
||||
|
||||
service->SetFullConfig(cdb);
|
||||
|
||||
if (!app->ConfigureApplication()) {
|
||||
printf("ERROR: ConfigureApplication failed in ValidationTest.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
assert(app->PrepareNextState("State1") == ErrorManagement::NoError);
|
||||
assert(app->StartNextStateExecution() == ErrorManagement::NoError);
|
||||
|
||||
printf("Application started at 1kHz. Enabling Traces...\n");
|
||||
Sleep::MSec(1000);
|
||||
|
||||
if (service->TraceSignal("App.Data.Timer.Counter", true, 1) == 0) {
|
||||
printf("ERROR: Failed to enable trace for App.Data.Timer.Counter\n");
|
||||
}
|
||||
|
||||
BasicUDPSocket listener;
|
||||
listener.Open();
|
||||
listener.Listen(8086);
|
||||
|
||||
printf("Validating for 10 seconds...\n");
|
||||
uint32 totalPackets = 0;
|
||||
uint32 totalSamples = 0;
|
||||
uint32 discontinuities = 0;
|
||||
uint32 lastValue = 0xFFFFFFFF;
|
||||
|
||||
uint64 start = HighResolutionTimer::Counter();
|
||||
float64 elapsed = 0;
|
||||
while (elapsed < 10.0) {
|
||||
char buffer[2048];
|
||||
uint32 size = 2048;
|
||||
if (listener.Read(buffer, size, TimeoutType(100))) {
|
||||
totalPackets++;
|
||||
TraceHeader *h = (TraceHeader*)buffer;
|
||||
uint32 offset = sizeof(TraceHeader);
|
||||
for (uint32 i=0; i<h->count; i++) {
|
||||
uint32 recId = *(uint32*)(&buffer[offset]);
|
||||
uint32 recSize = *(uint32*)(&buffer[offset + 12]);
|
||||
if (recSize == 4) {
|
||||
uint32 val = *(uint32*)(&buffer[offset + 16]);
|
||||
totalSamples++;
|
||||
if (lastValue != 0xFFFFFFFF && val != lastValue + 1) {
|
||||
discontinuities++;
|
||||
}
|
||||
lastValue = val;
|
||||
}
|
||||
offset += (16 + recSize);
|
||||
}
|
||||
}
|
||||
elapsed = (float64)(HighResolutionTimer::Counter() - start) * HighResolutionTimer::Period();
|
||||
}
|
||||
|
||||
printf("\n--- Test Results ---\n");
|
||||
printf("Total UDP Packets: %u\n", totalPackets);
|
||||
printf("Total Counter Samples: %u\n", totalSamples);
|
||||
printf("Counter Discontinuities: %u\n", discontinuities);
|
||||
|
||||
if (totalSamples < 9000) {
|
||||
printf("FAILURE: Underflow - samples missing (%u).\n", totalSamples);
|
||||
} else if (discontinuities > 50) {
|
||||
printf("FAILURE: Excessive discontinuities detected! (%u)\n", discontinuities);
|
||||
} else {
|
||||
printf("VALIDATION SUCCESSFUL: 1kHz Lossless Tracing Verified.\n");
|
||||
}
|
||||
|
||||
app->StopCurrentStateExecution();
|
||||
}
|
||||
Reference in New Issue
Block a user