17 Commits
main ... scope

Author SHA1 Message Date
Martino Ferrari
d3077e78ec implemented array support on client and server 2026-03-03 21:58:32 +01:00
Martino Ferrari
a941563749 Improved overall features 2026-03-03 21:41:59 +01:00
Martino Ferrari
e6102ba433 Project fixes and correct MARTe style makefile and source structure 2026-03-03 15:15:52 +01:00
Martino Ferrari
631417ef10 fixed remove forcing 2026-03-03 15:15:32 +01:00
Martino Ferrari
ad532419fb working again 2026-02-25 21:20:06 +01:00
Martino Ferrari
dfb399bbba better perf 2026-02-25 16:51:07 +01:00
Martino Ferrari
aaf69c0949 Added record to file 2026-02-24 22:59:37 +01:00
Martino Ferrari
ec29bd5148 Scope like ui start 2026-02-23 18:01:24 +01:00
Martino Ferrari
56bb3536fc Implemented all basic features 2026-02-23 13:17:16 +01:00
Martino Ferrari
6b1fc59fc0 Implemetned better buffering and high frequency tracing 2026-02-23 12:00:14 +01:00
Martino Ferrari
253a4989f9 Testing HF data 2026-02-23 11:24:32 +01:00
Martino Ferrari
04fb98bc74 Fixed ui for high frequency data 2026-02-23 11:17:11 +01:00
Martino Ferrari
3ad581d13b Removede scheduler 2026-02-23 10:25:58 +01:00
Martino Ferrari
38bb971bc4 cleaned up 2026-02-23 10:17:22 +01:00
Martino Ferrari
87b9ccebfd Implemented separate TCP logger service 2026-02-21 22:30:16 +01:00
Martino Ferrari
817d7276b7 Added tutorial and fixed issues on debugservice 2026-02-21 20:33:29 +01:00
Martino Ferrari
955eb02924 Updated with scheduler 2026-02-21 20:20:08 +01:00
63 changed files with 7128 additions and 2250 deletions

61
API.md Normal file
View File

@@ -0,0 +1,61 @@
# API Documentation
## 1. TCP Control Interface (Port 8080)
### 1.1 `TREE`
Retrieves the full object hierarchy.
- **Request:** `TREE
`
- **Response:** `JSON_OBJECT
OK TREE
`
### 1.2 `DISCOVER`
Lists all registrable signals and their metadata.
- **Request:** `DISCOVER
`
- **Response:** `{"Signals": [...]}
OK DISCOVER
`
### 1.3 `TRACE <path> <state>`
Enables/disables telemetry for a signal.
- **Example:** `TRACE App.Data.Timer.Counter 1
`
- **Response:** `OK TRACE <match_count>
`
### 1.4 `FORCE <path> <value>`
Overrides a signal value in memory.
- **Example:** `FORCE App.Data.DDB.Signal 123.4
`
- **Response:** `OK FORCE <match_count>
`
### 1.5 `PAUSE` / `RESUME`
Controls global execution state via the Scheduler.
- **Request:** `PAUSE
`
- **Response:** `OK
`
---
## 2. UDP Telemetry Format (Port 8081)
Telemetry packets are Little-Endian and use `#pragma pack(1)`.
### 2.1 TraceHeader (20 Bytes)
| Offset | Type | Name | Description |
| :--- | :--- | :--- | :--- |
| 0 | uint32 | magic | Always `0xDA7A57AD` |
| 4 | uint32 | seq | Incremental sequence number |
| 8 | uint64 | timestamp | High-resolution timestamp |
| 16 | uint32 | count | Number of samples in payload |
### 2.2 Sample Entry
| Offset | Type | Name | Description |
| :--- | :--- | :--- | :--- |
| 0 | uint32 | id | Internal Signal ID (from `DISCOVER`) |
| 4 | uint32 | size | Data size in bytes |
| 8 | Bytes | data | Raw signal memory |

44
ARCHITECTURE.md Normal file
View File

@@ -0,0 +1,44 @@
# System Architecture
## 1. Overview
The suite consists of a C++ server library (`libmarte_dev.so`) that instrument MARTe2 applications at runtime, and a native Rust client for visualization.
## 2. Core Mechanism: Registry Patching
The "Zero-Code-Change" requirement is met by intercepting the MARTe2 `ClassRegistryDatabase`. When the `DebugService` initializes, it replaces the standard object builders for critical classes:
1. **Broker Injection:** Standard Brokers (e.g., `MemoryMapInputBroker`) are replaced with `DebugBrokerWrapper`. This captures data every time a GAM reads or writes a signal.
2. **Scheduler Injection:** The `FastScheduler` is replaced with `DebugFastScheduler`. This provides hooks at the start/end of each real-time cycle for execution control (pausing).
## 3. Communication Layer
The system uses three distinct channels:
### 3.1 Command & Control (TCP Port 8080)
- **Protocol:** Text-based over TCP.
- **Role:** Object tree discovery (`TREE`), signal metadata (`DISCOVER`), and trace activation (`TRACE`).
- **Response Format:** JSON for complex data, `OK/ERROR` for status.
### 3.2 High-Speed Telemetry (UDP Port 8081)
- **Protocol:** Binary over UDP.
- **Format:** Packed C-structs.
- **Header:** `[Magic:4][Seq:4][TS:8][Count:4]` (Packed, 20 bytes).
- **Payload:** `[ID:4][Size:4][Data:N]` (Repeated for each traced signal).
### 3.3 Log Streaming (TCP Port 8082)
- **Protocol:** Real-time event streaming.
- **Service:** `TcpLogger` (Standalone component).
- **Role:** Forwards global `REPORT_ERROR` calls and `stdout` messages to the GUI client.
## 4. Component Diagram
```text
[ MARTe2 App ] <--- [ DebugFastScheduler ] (Registry Patch)
| |
+ <--- [ DebugBrokerWrapper ] (Registry Patch)
| |
+---------------------+
| |
[ DebugService ] [ TcpLogger ]
| |
+--- (TCP 8080) ------+-----> [ Rust GUI Client ]
+--- (UDP 8081) ------+-----> [ (Oscilloscope) ]
+--- (TCP 8082) ------+-----> [ (Log Terminal) ]
```

View File

@@ -1,59 +0,0 @@
cmake_minimum_required(VERSION 3.10)
project(marte_dev)
if(NOT DEFINED ENV{MARTe2_DIR})
message(FATAL_ERROR "MARTe2_DIR not set. Please source env.sh")
endif()
set(MARTe2_DIR $ENV{MARTe2_DIR})
set(MARTe2_Components_DIR $ENV{MARTe2_Components_DIR})
set(TARGET $ENV{TARGET})
# Define Architecture macros
add_definitions(-DARCHITECTURE=x86_gcc)
add_definitions(-DENVIRONMENT=Linux)
add_definitions(-DMARTe2_TEST_ENVIRONMENT=GTest) # Optional
add_definitions(-DUSE_PTHREAD)
# Add -pthread flag
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
include_directories(
${MARTe2_DIR}/Source/Core/BareMetal/L0Types
${MARTe2_DIR}/Source/Core/BareMetal/L1Portability
${MARTe2_DIR}/Source/Core/BareMetal/L2Objects
${MARTe2_DIR}/Source/Core/BareMetal/L3Streams
${MARTe2_DIR}/Source/Core/BareMetal/L4Configuration
${MARTe2_DIR}/Source/Core/BareMetal/L4Events
${MARTe2_DIR}/Source/Core/BareMetal/L4Logger
${MARTe2_DIR}/Source/Core/BareMetal/L4Messages
${MARTe2_DIR}/Source/Core/BareMetal/L5FILES
${MARTe2_DIR}/Source/Core/BareMetal/L5GAMs
${MARTe2_DIR}/Source/Core/BareMetal/L6App
${MARTe2_DIR}/Source/Core/Scheduler/L1Portability
${MARTe2_DIR}/Source/Core/Scheduler/L3Services
${MARTe2_DIR}/Source/Core/Scheduler/L4LoggerService
${MARTe2_DIR}/Source/Core/FileSystem/L1Portability
${MARTe2_DIR}/Source/Core/FileSystem/L3Streams
${MARTe2_Components_DIR}/Source/Components/DataSources/EpicsDataSource
${MARTe2_Components_DIR}/Source/Components/DataSources/FileDataSource
${MARTe2_Components_DIR}/Source/Components/GAMs/IOGAM
Source
Headers
)
file(GLOB_RECURSE SOURCES "Source/*.cpp")
add_library(${PROJECT_NAME} SHARED ${SOURCES})
# Target MARTe2 library
set(MARTe2_LIB ${MARTe2_DIR}/Build/${TARGET}/Core/libMARTe2.so)
set(IOGAM_LIB ${MARTe2_Components_DIR}/Build/${TARGET}/Components/GAMs/IOGAM/libIOGAM.so)
set(LinuxTimer_LIB ${MARTe2_Components_DIR}/Build/${TARGET}/Components/DataSources/LinuxTimer/libLinuxTimer.so)
target_link_libraries(${PROJECT_NAME}
${MARTe2_LIB}
)
add_subdirectory(Test/UnitTests)
add_subdirectory(Test/Integration)

32
DEMO.md Normal file
View File

@@ -0,0 +1,32 @@
# Demo Walkthrough: High-Speed Tracing
This demo demonstrates tracing a `Timer.Counter` signal at 100Hz and verifying its consistency.
### 1. Launch the Test Environment
Start the validation environment which simulates a real-time app:
```bash
./Build/Test/Integration/ValidationTest
```
*Note: The test will wait for a trace command before finishing.*
### 2. Connect the GUI
In another terminal:
```bash
cd Tools/gui_client
cargo run --release
```
### 3. Explore the Tree
1. On the left panel (**Application Tree**), expand `Root.App.Data.Timer`.
2. Click the ` Info` button on the `Timer` node to see its configuration (e.g., `SleepTime: 10000`).
### 4. Activate Trace
1. Locate the `Counter` signal under the `Timer` node.
2. Click the **📈 Trace** button.
3. The **Oscilloscope** in the center will immediately begin plotting the incremental counter.
4. Verify the **UDP Packets** counter in the top bar is increasing rapidly.
### 5. Test Execution Control
1. Click the **⏸ Pause** button in the top bar.
2. Observe that the plot stops updating and the counter value holds steady.
3. Click **▶ Resume** to continue execution.

View File

@@ -1,167 +0,0 @@
#ifndef DEBUGBROKERWRAPPER_H
#define DEBUGBROKERWRAPPER_H
#include "DebugService.h"
#include "BrokerI.h"
#include "MemoryMapBroker.h"
#include "ObjectRegistryDatabase.h"
#include "ReferenceT.h"
#include "ObjectBuilder.h"
#include "HighResolutionTimer.h"
// Original broker headers
#include "MemoryMapInputBroker.h"
#include "MemoryMapOutputBroker.h"
#include "MemoryMapSynchronisedInputBroker.h"
#include "MemoryMapSynchronisedOutputBroker.h"
#include "MemoryMapInterpolatedInputBroker.h"
#include "MemoryMapMultiBufferInputBroker.h"
#include "MemoryMapMultiBufferOutputBroker.h"
#include "MemoryMapSynchronisedMultiBufferInputBroker.h"
#include "MemoryMapSynchronisedMultiBufferOutputBroker.h"
namespace MARTe {
/**
* @brief Base implementation for all debug brokers.
*/
class DebugBrokerHelper {
public:
static void Process(BrokerI* broker, DebugService* service, DebugSignalInfo** signalInfoPointers, uint32 numSignals) {
if (service == NULL_PTR(DebugService*)) return;
while (service->IsPaused()) {
Sleep::MSec(10);
}
if (signalInfoPointers != NULL_PTR(DebugSignalInfo**)) {
for (uint32 i = 0; i < numSignals; i++) {
DebugSignalInfo *s = signalInfoPointers[i];
if (s != NULL_PTR(DebugSignalInfo*)) {
if (s->isTracing || s->isForcing) {
uint32 size = broker->GetCopyByteSize(i);
service->ProcessSignal(s, size);
}
}
}
}
}
static void InitSignals(MemoryMapBroker* broker, DataSourceI &dataSourceIn, DebugService* &service, DebugSignalInfo** &signalInfoPointers, uint32 &numSignals, MemoryMapBrokerCopyTableEntry* copyTable, const char8* functionName, SignalDirection direction) {
numSignals = broker->GetNumberOfCopies();
if (numSignals > 0) {
signalInfoPointers = new DebugSignalInfo*[numSignals];
for (uint32 i=0; i<numSignals; i++) signalInfoPointers[i] = NULL_PTR(DebugSignalInfo*);
}
ReferenceContainer *root = ObjectRegistryDatabase::Instance();
Reference serviceRef = root->Find("DebugService");
if (serviceRef.IsValid()) {
service = dynamic_cast<DebugService*>(serviceRef.operator->());
}
if (service && (copyTable != NULL_PTR(MemoryMapBrokerCopyTableEntry*))) {
StreamString dsPath;
DebugService::GetFullObjectName(dataSourceIn, dsPath);
for (uint32 i = 0; i < numSignals; i++) {
void *addr = copyTable[i].dataSourcePointer;
TypeDescriptor type = copyTable[i].type;
uint32 dsIdx = broker->GetDSCopySignalIndex(i);
StreamString signalName;
if (!dataSourceIn.GetSignalName(dsIdx, signalName)) signalName = "Unknown";
// 1. Register canonical DataSource name (Absolute)
StreamString dsFullName;
dsFullName.Printf("%s.%s", dsPath.Buffer(), signalName.Buffer());
service->RegisterSignal(addr, type, dsFullName.Buffer());
// 2. Also register absolute GAM alias
if (functionName != NULL_PTR(const char8*)) {
StreamString gamFullName;
const char8* dirStr = (direction == InputSignals) ? "In" : "Out";
Reference gamRef = ObjectRegistryDatabase::Instance()->Find(functionName);
if (gamRef.IsValid()) {
StreamString absGamPath;
DebugService::GetFullObjectName(*(gamRef.operator->()), absGamPath);
gamFullName.Printf("%s.%s.%s", absGamPath.Buffer(), dirStr, signalName.Buffer());
} else {
gamFullName.Printf("Root.%s.%s.%s", functionName, dirStr, signalName.Buffer());
}
signalInfoPointers[i] = service->RegisterSignal(addr, type, gamFullName.Buffer());
} else {
signalInfoPointers[i] = service->RegisterSignal(addr, type, dsFullName.Buffer());
}
}
}
}
};
#define DECLARE_DEBUG_BROKER_COMMON(BaseClass) \
Debug##BaseClass() : BaseClass() { \
service = NULL_PTR(DebugService*); \
signalInfoPointers = NULL_PTR(DebugSignalInfo**); \
numSignals = 0; \
} \
virtual ~Debug##BaseClass() { \
if (signalInfoPointers) delete[] signalInfoPointers; \
} \
virtual bool Execute() { \
bool ret = BaseClass::Execute(); \
if (ret) DebugBrokerHelper::Process(this, service, signalInfoPointers, numSignals); \
return ret; \
} \
private: \
DebugService *service; \
DebugSignalInfo **signalInfoPointers; \
uint32 numSignals;
#define DECLARE_DEBUG_BROKER(BaseClass) \
class Debug##BaseClass : public BaseClass { \
public: \
DECLARE_DEBUG_BROKER_COMMON(BaseClass) \
virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem) { \
bool ret = BaseClass::Init(direction, ds, name, gamMem); \
if (ret) DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers, numSignals, this->copyTable, name, direction); \
return ret; \
} \
virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem, const bool optim) { \
bool ret = BaseClass::Init(direction, ds, name, gamMem, optim); \
if (ret) DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers, numSignals, this->copyTable, name, direction); \
return ret; \
} \
}; \
class Debug##BaseClass##Builder : public ObjectBuilder { \
public: \
virtual Object *Build(HeapI* const heap) const { return new (heap) Debug##BaseClass(); } \
};
#define DECLARE_DEBUG_BROKER_NO_OPTIM(BaseClass) \
class Debug##BaseClass : public BaseClass { \
public: \
DECLARE_DEBUG_BROKER_COMMON(BaseClass) \
virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem) { \
bool ret = BaseClass::Init(direction, ds, name, gamMem); \
if (ret) DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers, numSignals, this->copyTable, name, direction); \
return ret; \
} \
}; \
class Debug##BaseClass##Builder : public ObjectBuilder { \
public: \
virtual Object *Build(HeapI* const heap) const { return new (heap) Debug##BaseClass(); } \
};
DECLARE_DEBUG_BROKER(MemoryMapInputBroker)
DECLARE_DEBUG_BROKER(MemoryMapOutputBroker)
DECLARE_DEBUG_BROKER(MemoryMapSynchronisedInputBroker)
DECLARE_DEBUG_BROKER(MemoryMapSynchronisedOutputBroker)
DECLARE_DEBUG_BROKER_NO_OPTIM(MemoryMapInterpolatedInputBroker)
DECLARE_DEBUG_BROKER(MemoryMapMultiBufferInputBroker)
DECLARE_DEBUG_BROKER(MemoryMapMultiBufferOutputBroker)
DECLARE_DEBUG_BROKER(MemoryMapSynchronisedMultiBufferInputBroker)
DECLARE_DEBUG_BROKER(MemoryMapSynchronisedMultiBufferOutputBroker)
}
#endif

View File

@@ -1,141 +0,0 @@
#ifndef DEBUGSERVICE_H
#define DEBUGSERVICE_H
#include "DataSourceI.h"
#include "GAM.h"
#include "MessageI.h"
#include "StreamString.h"
#include "BasicUDPSocket.h"
#include "BasicTCPSocket.h"
#include "ReferenceContainer.h"
#include "SingleThreadService.h"
#include "EmbeddedServiceMethodBinderI.h"
#include "FastMath.h"
#include "CompilerTypes.h"
#include "Object.h"
#include "DebugCore.h"
#include "ClassRegistryDatabase.h"
#include "ErrorManagement.h"
#include "AdvancedErrorManagement.h"
#include "LoggerConsumerI.h"
#include "Threads.h"
#include "EventSem.h"
namespace MARTe {
struct LogEntry {
ErrorManagement::ErrorInformation info;
char8 description[MAX_ERROR_MESSAGE_SIZE];
};
struct SignalAlias {
StreamString name;
uint32 signalIndex;
};
class DebugService : public ReferenceContainer, public MessageI, public EmbeddedServiceMethodBinderI, public LoggerConsumerI {
public:
CLASS_REGISTER_DECLARATION()
DebugService();
virtual ~DebugService();
virtual bool Initialise(StructuredDataI & data);
DebugSignalInfo* RegisterSignal(void* memoryAddress, TypeDescriptor type, const char8* name);
void ProcessSignal(DebugSignalInfo* signalInfo, uint32 size);
virtual ErrorManagement::ErrorType Execute(ExecutionInfo & info);
virtual void ConsumeLogMessage(LoggerPage *logPage);
static void LogCallback(const ErrorManagement::ErrorInformation &errorInfo, const char8 * const errorDescription);
void InsertLogIntoQueue(LoggerPage *logPage);
bool IsPaused() const { return isPaused; }
void SetPaused(bool paused) { isPaused = paused; }
static bool GetFullObjectName(const Object &obj, StreamString &fullPath);
private:
void HandleCommand(StreamString cmd, BasicTCPSocket *client);
uint32 ForceSignal(const char8* name, const char8* valueStr);
uint32 UnforceSignal(const char8* name);
uint32 TraceSignal(const char8* name, bool enable, uint32 decimation = 1);
void Discover(BasicTCPSocket *client);
void ListNodes(const char8* path, BasicTCPSocket *client);
void InfoNode(const char8* path, BasicTCPSocket *client);
uint32 ExportTree(ReferenceContainer *container, StreamString &json);
void PatchRegistry();
ErrorManagement::ErrorType Server(ExecutionInfo & info);
ErrorManagement::ErrorType Streamer(ExecutionInfo & info);
ErrorManagement::ErrorType LogStreamer(ExecutionInfo & info);
uint16 controlPort;
uint16 streamPort;
uint16 logPort;
StreamString streamIP;
bool isServer;
bool suppressTimeoutLogs;
volatile bool isPaused;
BasicTCPSocket tcpServer;
BasicUDPSocket udpSocket;
BasicTCPSocket logServer;
class ServiceBinder : public EmbeddedServiceMethodBinderI {
public:
enum ServiceType { ServerType, StreamerType, LogStreamerType };
ServiceBinder(DebugService *parent, ServiceType type) : parent(parent), type(type) {}
virtual ErrorManagement::ErrorType Execute(ExecutionInfo & info) {
if (type == StreamerType) return parent->Streamer(info);
if (type == LogStreamerType) return parent->LogStreamer(info);
return parent->Server(info);
}
private:
DebugService *parent;
ServiceType type;
};
ServiceBinder binderServer;
ServiceBinder binderStreamer;
ServiceBinder binderLogStreamer;
SingleThreadService threadService;
SingleThreadService streamerService;
SingleThreadService logStreamerService;
ThreadIdentifier serverThreadId;
ThreadIdentifier streamerThreadId;
ThreadIdentifier logStreamerThreadId;
static const uint32 MAX_SIGNALS = 4096;
DebugSignalInfo signals[MAX_SIGNALS];
uint32 numberOfSignals;
static const uint32 MAX_ALIASES = 8192;
SignalAlias aliases[MAX_ALIASES];
uint32 numberOfAliases;
FastPollingMutexSem mutex;
TraceRingBuffer traceBuffer;
static const uint32 MAX_CLIENTS = 16;
BasicTCPSocket* activeClients[MAX_CLIENTS];
FastPollingMutexSem clientsMutex;
BasicTCPSocket* activeLogClients[MAX_CLIENTS];
FastPollingMutexSem logClientsMutex;
static const uint32 LOG_QUEUE_SIZE = 1024;
LogEntry logQueue[LOG_QUEUE_SIZE];
volatile uint32 logQueueRead;
volatile uint32 logQueueWrite;
EventSem logEvent;
static DebugService* instance;
static ErrorManagement::ErrorProcessFunctionType originalLogCallback;
};
}
#endif

View File

@@ -1,10 +0,0 @@
all: build
build:
mkdir -p Build && cd Build && . ../env.sh && cmake -DCMAKE_BUILD_TYPE=Debug .. && make
ln -sf libmarte_dev.so Build/DebugService.so
clean:
rm -rf Build
.PHONY: all build clean

26
Makefile.gcc Normal file
View File

@@ -0,0 +1,26 @@
#############################################################
#
# Copyright 2015 F4E | European Joint Undertaking for ITER
# and the Development of Fusion Energy ('Fusion for Energy')
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://ec.europa.eu/idabc/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
#############################################################
export TARGET=x86-linux
include Makefile.inc

76
Makefile.inc Normal file
View File

@@ -0,0 +1,76 @@
#############################################################
#
# Copyright 2015 F4E | European Joint Undertaking for ITER
# and the Development of Fusion Energy ('Fusion for Energy')
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://ec.europa.eu/idabc/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
# $Id: Makefile.inc 3 2012-01-15 16:26:07Z aneto $
#
#############################################################
#Subprojects w.r.t. the main directory only (important to allow setting SPBM as an export variable).
#If SPB is directly exported as an environment variable it will also be evaluated as part of the subprojects SPB, thus
#potentially overriding its value
#Main target subprojects. May be overridden by shell definition.
SPBM?=Source/Components/Interfaces.x
SPBMT?=Test.x
#This really has to be defined locally.
SUBPROJMAIN=$(SPBM:%.x=%.spb)
SUBPROJMAINTEST=$(SPBMT:%.x=%.spb)
SUBPROJMAINCLEAN=$(SPBM:%.x=%.spc)
SUBPROJMAINTESTCLEAN=$(SPBMT:%.x=%.spc)
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
ROOT_DIR=.
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
all: $(OBJS) core test
echo $(OBJS)
compile_commands.json:
bear -- make -f Makefile.gcc
core: $(SUBPROJMAIN) check-env
echo $(SUBPROJMAIN)
test: $(SUBPROJMAINTEST)
echo $(SUBPROJMAINTEST)
clean:: $(SUBPROJMAINCLEAN) $(SUBPROJMAINTESTCLEAN) clean_wipe_old
#clean:: $(SUBPROJMAINCLEAN) $(SUBPROJMAINTESTCLEAN) clean_wipe_old
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)
check-marte:
ifndef MARTe2_DIR
$(error MARTe2_DIR is undefined)
endif
check-env:
ifndef MARTe2_DIR
$(error MARTe2_DIR is undefined)
endif

View File

@@ -1,48 +1,48 @@
# MARTe2 Universal Debugging & Observability Suite
# MARTe2 Debug Suite
A professional-grade, zero-code-change debugging suite for the MARTe2 real-time framework.
## Features
- **Runtime Registry Patching**: Instruments all MARTe2 Brokers automatically at startup.
- **Hierarchical Tree Explorer**: Recursive visualization of the `ObjectRegistryDatabase`, including GAMs, DataSources, and Signals.
- **Real-Time Execution Control**: Pause and Resume application logic globally to perform static inspection.
- **High-Speed Telemetry**: Visual oscilloscope with sub-millisecond precision via UDP.
- **Persistent Forcing**: Type-aware signal overrides (Last-Writer-Wins) with persistent re-application.
- **Isolated Log Streaming**: Dedicated TCP channel for real-time framework logs to ensure command responsiveness.
## Components
### 1. C++ Core (`libmarte_dev.so`)
The core service that handles registry patching, TCP/UDP communication, and real-time safe data capture.
### 2. Rust GUI Client (`marte_debug_gui`)
A native, multi-threaded dashboard built with `egui`.
- **Side Panel**: Collapsible application tree and signal navigator.
- **Bottom Panel**: Advanced log terminal with Regex filtering and priority levels.
- **Right Panel**: Active Trace and Force management.
- **Central Pane**: High-frequency oscilloscope.
An interactive observability and debugging suite for the MARTe2 real-time framework.
## Quick Start
### Build
### 1. Build the project
```bash
# Build C++ Core
cd Build && cmake .. && make -j$(nproc)
# Build GUI Client
cd Tools/gui_client
cargo build --release
. ./env.sh
make -f Makefile.gcc
```
### Run
1. Start your MARTe2 application with the `DebugService` enabled.
2. Launch the GUI:
```bash
./Tools/gui_client/target/release/marte_debug_gui
```
### 2. Run Integration Tests
```bash
./Build/x86-linux/Test/Integration/Integration/IntegrationTests.ex # Runs all tests
```
## Communication Ports
- **8080 (TCP)**: Commands (TREE, FORCE, TRACE, PAUSE).
- **8082 (TCP)**: Real-time framework logs.
- **8081 (UDP)**: Signal telemetry data.
### 3. Launch GUI
```bash
cd Tools/gui_client
cargo run --release
```
## Features
- **Live Tree:** Explore the MARTe2 object database in real-time.
- **Oscilloscope:** Trace any signal at high frequency (100Hz+) with automatic scaling.
- **Signal Forcing:** Inject values directly into the real-time memory map.
- **Log Forwarding:** Integrated framework log viewer with regex filtering.
- **Execution Control:** Global pause/resume via scheduler-level hooks.
## Usage
To enable debugging in your application, add the following to your `.cfg`:
```text
+DebugService = {
Class = DebugService
ControlPort = 8080
UdpPort = 8081
}
+LoggerService = {
Class = LoggerService
+DebugConsumer = {
Class = TcpLogger
Port = 8082
}
}
```
The suite automatically patches the registry to instrument your existing Brokers and Schedulers.

64
SPECS.md Normal file
View File

@@ -0,0 +1,64 @@
# MARTe2 Debug Suite Specifications
**Version:** 1.2
**Status:** Active / Implemented
## 1. Executive Summary
This project implements a "Zero-Code-Change" observability and debugging layer for the MARTe2 real-time framework. The system allows developers to Trace, Force, and Monitor any signal in a running MARTe2 application without modifying existing source code.
## 2. System Architecture
- **The Universal Debug Service (C++ Core):** A singleton MARTe2 Object that patches the registry and manages communication.
- **The Broker Injection Layer (C++ Templates):** Templated wrappers that intercept `Execute()` and `Init()` calls for tracing, forcing, and execution control.
- **The Remote Analyser (Rust/egui):** A high-performance, multi-threaded GUI for visualization and control.
- **Network Stack:**
- **Port 8080 (TCP):** Commands and Metadata.
- **Port 8081 (UDP):** High-Speed Telemetry for Oscilloscope.
- **Port 8082 (TCP):** Independent Real-Time Log Stream via `TcpLogger`.
## 3. Requirements
### 3.1 Functional Requirements (FR)
- **FR-01 (Discovery):** Discover the full MARTe2 object hierarchy at runtime. The GUI client SHALL request the full application tree upon connection and display it in a hierarchical tree view.
- **FR-02 (Telemetry):** Stream high-frequency signal data (verified up to 100Hz+) to a remote client via UDP.
- **FR-03 (Forcing):** Allow manual override of signal values in memory during execution.
- **FR-04 (Logs):** Stream global framework logs to a dedicated terminal/client via a standalone `TcpLogger` service.
- **FR-05 (Log Filtering):** The client must support filtering logs by type (Debug, Information, Warning, FatalError) and by content using regular expressions.
- **FR-06 (Execution Control):** Provide a mechanism to pause and resume the execution of all patched real-time threads (via Brokers), allowing for static inspection of the system state.
- **FR-07 (Session Management):** Support runtime re-configuration and "Apply & Reconnect" logic. The GUI provides a "Disconnect" button to close active network streams.
- **FR-08 (Decoupled Tracing):** Tracing activates telemetry; data is buffered and shown as a "Last Value" in the sidebar, but not plotted until manually assigned.
- **FR-09 (Advanced Plotting):**
- Support multiple plot panels with perfectly synchronized time (X) axes.
- Drag-and-drop signals from the traced list into specific plots.
- Plot modes: Standard (Time Series) and Logic Analyzer (Stacked rows).
- Signal transformations: Gain, offset, units, and custom labels.
- **FR-10 (Navigation & Scope):**
- Context menus for resetting zoom (X, Y, or both).
- "Fit to View" functionality that automatically scales both axes.
- High-performance oscilloscope mode with configurable time windows (10ms to 10s).
- Triggered acquisition (Single/Continuous, rising/falling edges).
- **FR-11 (Data Recording):** Record any traced signal to disk in Parquet format with a visual recording indicator in the GUI.
- **FR-12 (Configuration Awareness):** The DebugService SHALL store a complete copy of the application's configuration provided at initialization.
- **FR-13 (Metadata Enrichment):** Metadata returned by `INFO` and `DISCOVER` SHALL be enriched with additional fields from the stored configuration (e.g., Frequency, PVNames, Units).
- **FR-14 (Configuration Serving):** Provide a `CONFIG` command to serve the full stored configuration in JSON format to the client.
### 3.2 Technical Constraints (TC)
- **TC-01:** No modifications allowed to the MARTe2 core library or component source code.
- **TC-02:** Instrumentation must use Runtime Class Registry Patching.
- **TC-03:** Real-time threads must remain lock-free; use `FastPollingMutexSem` or atomic operations for synchronization.
- **TC-04:** Telemetry must be delivered via UDP to minimize impact on real-time jitter.
## 4. Performance Metrics
- **Latency:** Telemetry dispatch overhead < 5 microseconds per signal.
- **Throughput:** Support for 100Hz+ sampling rates with zero packet loss on local networks.
- **Scalability:** Handle up to 4096 unique signals and 16 simultaneous client connections.
- **Code Quality:** Maintain a minimum of **85% code coverage** across all core service and broker logic.
## 5. Communication Protocol (Port 8080)
- **LS [Path]:** List nodes at the specified path.
- **TREE:** Returns a full recursive JSON structure representing the entire application tree.
- **INFO [Path]:** Returns detailed metadata for a specific node or signal.
- **PAUSE / RESUME:** Global execution control.
- **TRACE <Signal> <1/0> [Decimation]:** Enable/disable telemetry for a signal.
- **FORCE <Signal> <Value>:** Persistent signal override.
- **UNFORCE <Signal>:** Remove override.
- **LOG <Level> <Msg>:** Streaming format used on Port 8082.

View File

@@ -0,0 +1,433 @@
#ifndef DEBUGBROKERWRAPPER_H
#define DEBUGBROKERWRAPPER_H
#include "BrokerI.h"
#include "DataSourceI.h"
#include "DebugService.h"
#include "FastPollingMutexSem.h"
#include "HighResolutionTimer.h"
#include "MemoryMapBroker.h"
#include "ObjectBuilder.h"
#include "ObjectRegistryDatabase.h"
#include "Vec.h"
// Original broker headers
#include "MemoryMapAsyncOutputBroker.h"
#include "MemoryMapAsyncTriggerOutputBroker.h"
#include "MemoryMapInputBroker.h"
#include "MemoryMapInterpolatedInputBroker.h"
#include "MemoryMapMultiBufferInputBroker.h"
#include "MemoryMapMultiBufferOutputBroker.h"
#include "MemoryMapOutputBroker.h"
#include "MemoryMapSynchronisedInputBroker.h"
#include "MemoryMapSynchronisedMultiBufferInputBroker.h"
#include "MemoryMapSynchronisedMultiBufferOutputBroker.h"
#include "MemoryMapSynchronisedOutputBroker.h"
namespace MARTe {
/**
* @brief Helper for optimized signal processing within brokers.
*/
class DebugBrokerHelper {
public:
static void Process(DebugService *service,
DebugSignalInfo **signalInfoPointers,
Vec<uint32> &activeIndices, Vec<uint32> &activeSizes,
FastPollingMutexSem &activeMutex) {
if (service == NULL_PTR(DebugService *))
return;
// Re-establish break logic
while (service->IsPaused()) {
Sleep::MSec(10);
}
activeMutex.FastLock();
uint32 n = activeIndices.Size();
if (n > 0 && signalInfoPointers != NULL_PTR(DebugSignalInfo **)) {
// Capture timestamp ONCE per broker cycle for lowest impact
uint64 ts = (uint64)((float64)HighResolutionTimer::Counter() *
HighResolutionTimer::Period() * 1000000.0);
for (uint32 i = 0; i < n; i++) {
uint32 idx = activeIndices[i];
uint32 size = activeSizes[i];
DebugSignalInfo *s = signalInfoPointers[idx];
if (s != NULL_PTR(DebugSignalInfo *)) {
service->ProcessSignal(s, size, ts);
}
}
}
activeMutex.FastUnLock();
}
// Pass numCopies explicitly so we can mock it
static void
InitSignals(BrokerI *broker, DataSourceI &dataSourceIn,
DebugService *&service, DebugSignalInfo **&signalInfoPointers,
uint32 numCopies, MemoryMapBrokerCopyTableEntry *copyTable,
const char8 *functionName, SignalDirection direction,
volatile bool *anyActiveFlag, Vec<uint32> *activeIndices,
Vec<uint32> *activeSizes, FastPollingMutexSem *activeMutex) {
if (numCopies > 0) {
signalInfoPointers = new DebugSignalInfo *[numCopies];
for (uint32 i = 0; i < numCopies; i++)
signalInfoPointers[i] = NULL_PTR(DebugSignalInfo *);
}
ReferenceContainer *root = ObjectRegistryDatabase::Instance();
Reference serviceRef = root->Find("DebugService");
if (serviceRef.IsValid()) {
service = dynamic_cast<DebugService *>(serviceRef.operator->());
}
if (service && (copyTable != NULL_PTR(MemoryMapBrokerCopyTableEntry *))) {
StreamString dsPath;
DebugService::GetFullObjectName(dataSourceIn, dsPath);
fprintf(stderr, ">> %s broker for %s [%d]\n",
direction == InputSignals ? "Input" : "Output", dsPath.Buffer(),
numCopies);
MemoryMapBroker *mmb = dynamic_cast<MemoryMapBroker *>(broker);
if (mmb == NULL_PTR(MemoryMapBroker *)) {
fprintf(stderr, ">> Impossible to get broker pointer!!\n");
}
for (uint32 i = 0; i < numCopies; i++) {
void *addr = copyTable[i].dataSourcePointer;
TypeDescriptor type = copyTable[i].type;
uint32 dsIdx = i;
if (mmb != NULL_PTR(MemoryMapBroker *)) {
dsIdx = mmb->GetDSCopySignalIndex(i);
}
StreamString signalName;
if (!dataSourceIn.GetSignalName(dsIdx, signalName))
signalName = "Unknown";
fprintf(stderr, ">> registering %s.%s [%p]\n", dsPath.Buffer(),
signalName.Buffer(), mmb);
uint8 dims = 0;
uint32 elems = 1;
(void)dataSourceIn.GetSignalNumberOfDimensions(dsIdx, dims);
(void)dataSourceIn.GetSignalNumberOfElements(dsIdx, elems);
// Register canonical name
StreamString dsFullName;
dsFullName.Printf("%s.%s", dsPath.Buffer(), signalName.Buffer());
service->RegisterSignal(addr, type, dsFullName.Buffer(), dims, elems);
// Register alias
if (functionName != NULL_PTR(const char8 *)) {
StreamString gamFullName;
const char8 *dirStr =
(direction == InputSignals) ? "InputSignals" : "OutputSignals";
const char8 *dirStrShort = (direction == InputSignals) ? "In" : "Out";
// Try to find the GAM with different path variations
Reference gamRef =
ObjectRegistryDatabase::Instance()->Find(functionName);
if (!gamRef.IsValid()) {
// Try with "App.Functions." prefix
StreamString tryPath;
tryPath.Printf("App.Functions.%s", functionName);
gamRef = ObjectRegistryDatabase::Instance()->Find(tryPath.Buffer());
}
if (!gamRef.IsValid()) {
// Try with "Functions." prefix
StreamString tryPath;
tryPath.Printf("Functions.%s", functionName);
gamRef = ObjectRegistryDatabase::Instance()->Find(tryPath.Buffer());
}
if (gamRef.IsValid()) {
StreamString absGamPath;
DebugService::GetFullObjectName(*(gamRef.operator->()), absGamPath);
// Register short path (In/Out) for GUI compatibility
gamFullName.Printf("%s.%s.%s", absGamPath.Buffer(), dirStrShort,
signalName.Buffer());
signalInfoPointers[i] =
service->RegisterSignal(addr, type, gamFullName.Buffer(), dims, elems);
} else {
// Fallback to short form
gamFullName.Printf("%s.%s.%s", functionName, dirStrShort,
signalName.Buffer());
signalInfoPointers[i] =
service->RegisterSignal(addr, type, gamFullName.Buffer(), dims, elems);
}
} else {
signalInfoPointers[i] =
service->RegisterSignal(addr, type, dsFullName.Buffer(), dims, elems);
}
}
// Register broker in DebugService for optimized control
service->RegisterBroker(signalInfoPointers, numCopies, mmb, anyActiveFlag,
activeIndices, activeSizes, activeMutex);
}
}
};
/**
* @brief Template class to instrument any MARTe2 Broker.
*/
template <typename BaseClass> class DebugBrokerWrapper : public BaseClass {
public:
DebugBrokerWrapper() : BaseClass() {
service = NULL_PTR(DebugService *);
signalInfoPointers = NULL_PTR(DebugSignalInfo **);
numSignals = 0;
anyActive = false;
}
virtual ~DebugBrokerWrapper() {
if (signalInfoPointers)
delete[] signalInfoPointers;
}
virtual bool Execute() {
bool ret = BaseClass::Execute();
if (ret && (anyActive || (service && service->IsPaused()))) {
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices,
activeSizes, activeMutex);
}
return ret;
}
virtual bool Init(SignalDirection direction, DataSourceI &ds,
const char8 *const name, void *gamMem) {
bool ret = BaseClass::Init(direction, ds, name, gamMem);
fprintf(stderr, ">> INIT BROKER %s %s\n", name,
direction == InputSignals ? "In" : "Out");
if (ret) {
numSignals = this->GetNumberOfCopies();
DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers,
numSignals, this->copyTable, name,
direction, &anyActive, &activeIndices,
&activeSizes, &activeMutex);
}
return ret;
}
virtual bool Init(SignalDirection direction, DataSourceI &ds,
const char8 *const name, void *gamMem, const bool optim) {
bool ret = BaseClass::Init(direction, ds, name, gamMem, false);
fprintf(stderr, ">> INIT optimized BROKER %s %s\n", name,
direction == InputSignals ? "In" : "Out");
if (ret) {
numSignals = this->GetNumberOfCopies();
DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers,
numSignals, this->copyTable, name,
direction, &anyActive, &activeIndices,
&activeSizes, &activeMutex);
}
return ret;
}
DebugService *service;
DebugSignalInfo **signalInfoPointers;
uint32 numSignals;
volatile bool anyActive;
Vec<uint32> activeIndices;
Vec<uint32> activeSizes;
FastPollingMutexSem activeMutex;
};
template <typename BaseClass>
class DebugBrokerWrapperNoOptim : public BaseClass {
public:
DebugBrokerWrapperNoOptim() : BaseClass() {
service = NULL_PTR(DebugService *);
signalInfoPointers = NULL_PTR(DebugSignalInfo **);
numSignals = 0;
anyActive = false;
}
virtual ~DebugBrokerWrapperNoOptim() {
if (signalInfoPointers)
delete[] signalInfoPointers;
}
virtual bool Execute() {
bool ret = BaseClass::Execute();
if (ret && (anyActive || (service && service->IsPaused()))) {
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices,
activeSizes, activeMutex);
}
return ret;
}
virtual bool Init(SignalDirection direction, DataSourceI &ds,
const char8 *const name, void *gamMem) {
bool ret = BaseClass::Init(direction, ds, name, gamMem);
if (ret) {
numSignals = this->GetNumberOfCopies();
DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers,
numSignals, this->copyTable, name,
direction, &anyActive, &activeIndices,
&activeSizes, &activeMutex);
}
return ret;
}
DebugService *service;
DebugSignalInfo **signalInfoPointers;
uint32 numSignals;
volatile bool anyActive;
Vec<uint32> activeIndices;
Vec<uint32> activeSizes;
FastPollingMutexSem activeMutex;
};
class DebugMemoryMapAsyncOutputBroker : public MemoryMapAsyncOutputBroker {
public:
DebugMemoryMapAsyncOutputBroker() : MemoryMapAsyncOutputBroker() {
service = NULL_PTR(DebugService *);
signalInfoPointers = NULL_PTR(DebugSignalInfo **);
numSignals = 0;
anyActive = false;
}
virtual ~DebugMemoryMapAsyncOutputBroker() {
if (signalInfoPointers)
delete[] signalInfoPointers;
}
virtual bool Execute() {
bool ret = MemoryMapAsyncOutputBroker::Execute();
if (ret && (anyActive || (service && service->IsPaused()))) {
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices,
activeSizes, activeMutex);
}
return ret;
}
virtual bool InitWithBufferParameters(const SignalDirection direction,
DataSourceI &dataSourceIn,
const char8 *const functionName,
void *const gamMemoryAddress,
const uint32 numberOfBuffersIn,
const ProcessorType &cpuMaskIn,
const uint32 stackSizeIn) {
bool ret = MemoryMapAsyncOutputBroker::InitWithBufferParameters(
direction, dataSourceIn, functionName, gamMemoryAddress,
numberOfBuffersIn, cpuMaskIn, stackSizeIn);
if (ret) {
numSignals = this->GetNumberOfCopies();
DebugBrokerHelper::InitSignals(
this, dataSourceIn, service, signalInfoPointers, numSignals,
this->copyTable, functionName, direction, &anyActive, &activeIndices,
&activeSizes, &activeMutex);
}
return ret;
}
DebugService *service;
DebugSignalInfo **signalInfoPointers;
uint32 numSignals;
volatile bool anyActive;
Vec<uint32> activeIndices;
Vec<uint32> activeSizes;
FastPollingMutexSem activeMutex;
};
class DebugMemoryMapAsyncTriggerOutputBroker
: public MemoryMapAsyncTriggerOutputBroker {
public:
DebugMemoryMapAsyncTriggerOutputBroker()
: MemoryMapAsyncTriggerOutputBroker() {
service = NULL_PTR(DebugService *);
signalInfoPointers = NULL_PTR(DebugSignalInfo **);
numSignals = 0;
anyActive = false;
}
virtual ~DebugMemoryMapAsyncTriggerOutputBroker() {
if (signalInfoPointers)
delete[] signalInfoPointers;
}
virtual bool Execute() {
bool ret = MemoryMapAsyncTriggerOutputBroker::Execute();
if (ret && (anyActive || (service && service->IsPaused()))) {
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices,
activeSizes, activeMutex);
}
return ret;
}
virtual bool InitWithTriggerParameters(
const SignalDirection direction, DataSourceI &dataSourceIn,
const char8 *const functionName, void *const gamMemoryAddress,
const uint32 numberOfBuffersIn, const uint32 preTriggerBuffersIn,
const uint32 postTriggerBuffersIn, const ProcessorType &cpuMaskIn,
const uint32 stackSizeIn) {
bool ret = MemoryMapAsyncTriggerOutputBroker::InitWithTriggerParameters(
direction, dataSourceIn, functionName, gamMemoryAddress,
numberOfBuffersIn, preTriggerBuffersIn, postTriggerBuffersIn, cpuMaskIn,
stackSizeIn);
if (ret) {
numSignals = this->GetNumberOfCopies();
DebugBrokerHelper::InitSignals(
this, dataSourceIn, service, signalInfoPointers, numSignals,
this->copyTable, functionName, direction, &anyActive, &activeIndices,
&activeSizes, &activeMutex);
}
return ret;
}
DebugService *service;
DebugSignalInfo **signalInfoPointers;
uint32 numSignals;
volatile bool anyActive;
Vec<uint32> activeIndices;
Vec<uint32> activeSizes;
FastPollingMutexSem activeMutex;
};
template <typename T> class DebugBrokerBuilder : public ObjectBuilder {
public:
virtual Object *Build(HeapI *const heap) const { return new (heap) T(); }
};
typedef DebugBrokerWrapper<MemoryMapInputBroker> DebugMemoryMapInputBroker;
// LCOV_EXCL_START
typedef DebugBrokerWrapper<MemoryMapOutputBroker> DebugMemoryMapOutputBroker;
typedef DebugBrokerWrapper<MemoryMapSynchronisedInputBroker>
DebugMemoryMapSynchronisedInputBroker;
typedef DebugBrokerWrapper<MemoryMapSynchronisedOutputBroker>
DebugMemoryMapSynchronisedOutputBroker;
typedef DebugBrokerWrapperNoOptim<MemoryMapInterpolatedInputBroker>
DebugMemoryMapInterpolatedInputBroker;
typedef DebugBrokerWrapper<MemoryMapMultiBufferInputBroker>
DebugMemoryMapMultiBufferInputBroker;
typedef DebugBrokerWrapper<MemoryMapMultiBufferOutputBroker>
DebugMemoryMapMultiBufferOutputBroker;
typedef DebugBrokerWrapper<MemoryMapSynchronisedMultiBufferInputBroker>
DebugMemoryMapSynchronisedMultiBufferInputBroker;
typedef DebugBrokerWrapper<MemoryMapSynchronisedMultiBufferOutputBroker>
DebugMemoryMapSynchronisedMultiBufferOutputBroker;
// LCOV_EXCL_STOP
typedef DebugBrokerBuilder<DebugMemoryMapInputBroker>
DebugMemoryMapInputBrokerBuilder;
// LCOV_EXCL_START
typedef DebugBrokerBuilder<DebugMemoryMapOutputBroker>
DebugMemoryMapOutputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedInputBroker>
DebugMemoryMapSynchronisedInputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedOutputBroker>
DebugMemoryMapSynchronisedOutputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapInterpolatedInputBroker>
DebugMemoryMapInterpolatedInputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapMultiBufferInputBroker>
DebugMemoryMapMultiBufferInputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapMultiBufferOutputBroker>
DebugMemoryMapMultiBufferOutputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedMultiBufferInputBroker>
DebugMemoryMapSynchronisedMultiBufferInputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedMultiBufferOutputBroker>
DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapAsyncOutputBroker>
DebugMemoryMapAsyncOutputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapAsyncTriggerOutputBroker>
DebugMemoryMapAsyncTriggerOutputBrokerBuilder;
// LCOV_EXCL_STOP
} // namespace MARTe
#endif

View File

@@ -4,7 +4,7 @@
#include "CompilerTypes.h"
#include "TypeDescriptor.h"
#include "StreamString.h"
#include "MemoryOperationsHelper.h"
#include <string.h>
namespace MARTe {
@@ -12,6 +12,8 @@ struct DebugSignalInfo {
void* memoryAddress;
TypeDescriptor type;
StreamString name;
uint8 numberOfDimensions;
uint32 numberOfElements;
volatile bool isTracing;
volatile bool isForcing;
uint8 forcedValue[1024];
@@ -29,6 +31,10 @@ struct TraceHeader {
};
#pragma pack(pop)
/**
* @brief Ring buffer for high-frequency signal tracing.
* @details New format per sample: [ID:4][Timestamp:8][Size:4][Data:N]
*/
class TraceRingBuffer {
public:
TraceRingBuffer() {
@@ -55,43 +61,53 @@ public:
return (buffer != NULL_PTR(uint8*));
}
bool Push(uint32 signalID, void* data, uint32 size) {
uint32 packetSize = 4 + 4 + size;
bool Push(uint32 signalID, uint64 timestamp, void* data, uint32 size) {
uint32 packetSize = 4 + 8 + 4 + size; // ID + TS + Size + Data
uint32 read = readIndex;
uint32 write = writeIndex;
uint32 available = (read <= write) ? (bufferSize - (write - read) - 1) : (read - write - 1);
uint32 available = 0;
if (read <= write) {
available = bufferSize - (write - read) - 1;
} else {
available = read - write - 1;
}
if (available < packetSize) return false;
// Use temporary write index to ensure atomic update
uint32 tempWrite = write;
WriteToBuffer(&tempWrite, &signalID, 4);
WriteToBuffer(&tempWrite, &timestamp, 8);
WriteToBuffer(&tempWrite, &size, 4);
WriteToBuffer(&tempWrite, data, size);
// Final atomic update
writeIndex = tempWrite;
return true;
}
bool Pop(uint32 &signalID, void* dataBuffer, uint32 &size, uint32 maxSize) {
bool Pop(uint32 &signalID, uint64 &timestamp, void* dataBuffer, uint32 &size, uint32 maxSize) {
uint32 read = readIndex;
uint32 write = writeIndex;
if (read == write) return false;
uint32 tempRead = read;
uint32 tempId, tempSize;
uint32 tempId = 0;
uint64 tempTs = 0;
uint32 tempSize = 0;
ReadFromBuffer(&tempRead, &tempId, 4);
ReadFromBuffer(&tempRead, &tempTs, 8);
ReadFromBuffer(&tempRead, &tempSize, 4);
if (tempSize > maxSize) {
// Error case: drop data up to writeIndex
readIndex = write;
return false;
}
ReadFromBuffer(&tempRead, dataBuffer, tempSize);
signalID = tempId;
timestamp = tempTs;
size = tempSize;
readIndex = tempRead;
@@ -107,18 +123,30 @@ public:
private:
void WriteToBuffer(uint32 *idx, void* src, uint32 count) {
uint8* s = (uint8*)src;
for (uint32 i=0; i<count; i++) {
buffer[*idx] = s[i];
*idx = (*idx + 1) % bufferSize;
uint32 current = *idx;
uint32 spaceToEnd = bufferSize - current;
if (count <= spaceToEnd) {
memcpy(&buffer[current], src, count);
*idx = (current + count) % bufferSize;
} else {
memcpy(&buffer[current], src, spaceToEnd);
uint32 remaining = count - spaceToEnd;
memcpy(&buffer[0], (uint8*)src + spaceToEnd, remaining);
*idx = remaining;
}
}
void ReadFromBuffer(uint32 *idx, void* dst, uint32 count) {
uint8* d = (uint8*)dst;
for (uint32 i=0; i<count; i++) {
d[i] = buffer[*idx];
*idx = (*idx + 1) % bufferSize;
uint32 current = *idx;
uint32 spaceToEnd = bufferSize - current;
if (count <= spaceToEnd) {
memcpy(dst, &buffer[current], count);
*idx = (current + count) % bufferSize;
} else {
memcpy(dst, &buffer[current], spaceToEnd);
uint32 remaining = count - spaceToEnd;
memcpy((uint8*)dst + spaceToEnd, &buffer[0], remaining);
*idx = remaining;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,157 @@
#ifndef DEBUGSERVICE_H
#define DEBUGSERVICE_H
#include "BasicTCPSocket.h"
#include "BasicUDPSocket.h"
#include "ConfigurationDatabase.h"
#include "DebugCore.h"
#include "EmbeddedServiceMethodBinderI.h"
#include "MessageI.h"
#include "Object.h"
#include "ReferenceContainer.h"
#include "SingleThreadService.h"
#include "StreamString.h"
#include "Vec.h"
namespace MARTe {
class MemoryMapBroker;
class DataSourceI;
struct SignalAlias {
StreamString name;
uint32 signalIndex;
};
struct BrokerInfo {
DebugSignalInfo **signalPointers;
uint32 numSignals;
MemoryMapBroker *broker;
volatile bool *anyActiveFlag;
Vec<uint32> *activeIndices;
Vec<uint32> *activeSizes;
FastPollingMutexSem *activeMutex;
};
class DebugService : public ReferenceContainer,
public MessageI,
public EmbeddedServiceMethodBinderI {
public:
friend class DebugServiceTest;
CLASS_REGISTER_DECLARATION()
DebugService();
virtual ~DebugService();
virtual bool Initialise(StructuredDataI &data);
DebugSignalInfo *RegisterSignal(void *memoryAddress, TypeDescriptor type,
const char8 *name, uint8 numberOfDimensions = 0,
uint32 numberOfElements = 1);
void ProcessSignal(DebugSignalInfo *signalInfo, uint32 size,
uint64 timestamp);
void RegisterBroker(DebugSignalInfo **signalPointers, uint32 numSignals,
MemoryMapBroker *broker, volatile bool *anyActiveFlag,
Vec<uint32> *activeIndices, Vec<uint32> *activeSizes,
FastPollingMutexSem *activeMutex);
virtual ErrorManagement::ErrorType Execute(ExecutionInfo &info);
bool IsPaused() const { return isPaused; }
void SetPaused(bool paused) { isPaused = paused; }
static bool GetFullObjectName(const Object &obj, StreamString &fullPath);
uint32 ForceSignal(const char8 *name, const char8 *valueStr);
uint32 UnforceSignal(const char8 *name);
uint32 TraceSignal(const char8 *name, bool enable, uint32 decimation = 1);
bool IsInstrumented(const char8 *fullPath, bool &traceable, bool &forcable);
void Discover(BasicTCPSocket *client);
void InfoNode(const char8 *path, BasicTCPSocket *client);
void ListNodes(const char8 *path, BasicTCPSocket *client);
void ServeConfig(BasicTCPSocket *client);
void SetFullConfig(ConfigurationDatabase &config);
struct MonitoredSignal {
ReferenceT<DataSourceI> dataSource;
uint32 signalIdx;
uint32 internalID;
uint32 periodMs;
uint64 lastPollTime;
uint32 size;
StreamString path;
};
uint32 RegisterMonitorSignal(const char8 *path, uint32 periodMs);
uint32 UnmonitorSignal(const char8 *path);
private:
void HandleCommand(StreamString cmd, BasicTCPSocket *client);
void UpdateBrokersActiveStatus();
uint32 ExportTree(ReferenceContainer *container, StreamString &json, const char8 *pathPrefix);
void PatchRegistry();
void EnrichWithConfig(const char8 *path, StreamString &json);
static void JsonifyDatabase(ConfigurationDatabase &db, StreamString &json);
ErrorManagement::ErrorType Server(ExecutionInfo &info);
ErrorManagement::ErrorType Streamer(ExecutionInfo &info);
uint16 controlPort;
uint16 streamPort;
uint16 logPort;
StreamString streamIP;
bool isServer;
bool suppressTimeoutLogs;
volatile bool isPaused;
BasicTCPSocket tcpServer;
BasicUDPSocket udpSocket;
class ServiceBinder : public EmbeddedServiceMethodBinderI {
public:
enum ServiceType { ServerType, StreamerType };
ServiceBinder(DebugService *parent, ServiceType type)
: parent(parent), type(type) {}
virtual ErrorManagement::ErrorType Execute(ExecutionInfo &info) {
if (type == StreamerType) {
return parent->Streamer(info);
}
printf("serve TCP\n");
return parent->Server(info);
}
private:
DebugService *parent;
ServiceType type;
};
ServiceBinder binderServer;
ServiceBinder binderStreamer;
SingleThreadService threadService;
SingleThreadService streamerService;
ThreadIdentifier serverThreadId;
ThreadIdentifier streamerThreadId;
Vec<DebugSignalInfo *> signals;
Vec<SignalAlias> aliases;
Vec<BrokerInfo> brokers;
Vec<MonitoredSignal> monitoredSignals;
FastPollingMutexSem mutex;
TraceRingBuffer traceBuffer;
BasicTCPSocket *activeClient;
ConfigurationDatabase fullConfig;
static DebugService *instance;
};
} // namespace MARTe
#endif

View File

@@ -0,0 +1,28 @@
#############################################################
#
# Copyright 2015 F4E | European Joint Undertaking for ITER
# and the Development of Fusion Energy ('Fusion for Energy')
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://ec.europa.eu/idabc/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
# $Id: Makefile.gcc 3 2015-01-15 16:26:07Z aneto $
#
#############################################################
include Makefile.inc

View File

@@ -0,0 +1,59 @@
#############################################################
#
# Copyright 2015 F4E | European Joint Undertaking for ITER
# and the Development of Fusion Energy ('Fusion for Energy')
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://ec.europa.eu/idabc/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
# $Id: Makefile.inc 3 2012-01-15 16:26:07Z aneto $
#
#############################################################
OBJSX=DebugService.x
PACKAGE=Components/Interfaces
ROOT_DIR=../../../../
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
INCLUDES += -I$(ROOT_DIR)/Source/Core/Types/Result
INCLUDES += -I$(ROOT_DIR)/Source/Core/Types/Vec
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/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
all: $(OBJS) $(SUBPROJ) \
$(BUILD_DIR)/DebugService$(LIBEXT) \
$(BUILD_DIR)/DebugService$(DLLEXT)
echo $(OBJS)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)

View File

@@ -0,0 +1,26 @@
#############################################################
#
# Copyright 2015 F4E | European Joint Undertaking for ITER
# and the Development of Fusion Energy ('Fusion for Energy')
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://ec.europa.eu/idabc/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
#############################################################
include Makefile.inc

View File

@@ -0,0 +1,43 @@
#############################################################
#
# Copyright 2015 F4E | European Joint Undertaking for ITER
# and the Development of Fusion Energy ('Fusion for Energy')
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://ec.europa.eu/idabc/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
#############################################################
OBJSX=
SPB = TCPLogger.x DebugService.x
ROOT_DIR=../../..
PACKAGE=Components
ROOT_DIR=../../..
ABS_ROOT_DIR=$(abspath $(ROOT_DIR))
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
all: $(OBJS) $(SUBPROJ)
echo $(OBJS)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)

View File

@@ -0,0 +1 @@
include Makefile.inc

View File

@@ -0,0 +1,31 @@
OBJSX=TcpLogger.x
PACKAGE=Components/Interfaces
ROOT_DIR=../../../../
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
INCLUDES += -I.
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/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
all: $(OBJS) $(SUBPROJ) \
$(BUILD_DIR)/TcpLogger$(LIBEXT) \
$(BUILD_DIR)/TcpLogger$(DLLEXT)
echo $(OBJS)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)

View File

@@ -0,0 +1,156 @@
#include "TcpLogger.h"
#include "Threads.h"
#include "StringHelper.h"
#include "ConfigurationDatabase.h"
namespace MARTe {
CLASS_REGISTER(TcpLogger, "1.0")
TcpLogger::TcpLogger() :
ReferenceContainer(), LoggerConsumerI(), EmbeddedServiceMethodBinderI(),
service(*this)
{
port = 8082;
readIdx = 0;
writeIdx = 0;
workerThreadId = InvalidThreadIdentifier;
for (uint32 i=0; i<MAX_CLIENTS; i++) {
activeClients[i] = NULL_PTR(BasicTCPSocket*);
}
}
TcpLogger::~TcpLogger() {
service.Stop();
server.Close();
clientsMutex.FastLock();
for (uint32 i=0; i<MAX_CLIENTS; i++) {
if (activeClients[i] != NULL_PTR(BasicTCPSocket*)) {
activeClients[i]->Close();
delete activeClients[i];
activeClients[i] = NULL_PTR(BasicTCPSocket*);
}
}
clientsMutex.FastUnLock();
}
bool TcpLogger::Initialise(StructuredDataI & data) {
if (!ReferenceContainer::Initialise(data)) return false;
if (!data.Read("Port", port)) {
(void)data.Read("TcpPort", port);
}
(void)eventSem.Create();
ConfigurationDatabase threadData;
threadData.Write("Timeout", (uint32)1000);
if (!service.Initialise(threadData)) return false;
if (!server.Open()) return false;
if (!server.Listen(port)) {
return false;
}
printf("[TcpLogger] Listening on port %u\n", port);
if (service.Start() != ErrorManagement::NoError) {
return false;
}
return true;
}
void TcpLogger::ConsumeLogMessage(LoggerPage *logPage) {
if (logPage == NULL_PTR(LoggerPage*)) return;
// 1. Mirror to stdout
StreamString levelStr;
ErrorManagement::ErrorCodeToStream(logPage->errorInfo.header.errorType, levelStr);
printf("[%s] %s\n", levelStr.Buffer(), logPage->errorStrBuffer);
fflush(stdout);
// 2. Queue for TCP
InsertLogIntoQueue(logPage->errorInfo, logPage->errorStrBuffer);
}
void TcpLogger::InsertLogIntoQueue(const ErrorManagement::ErrorInformation &info, const char8 * const description) {
uint32 next = (writeIdx + 1) % QUEUE_SIZE;
if (next != readIdx) {
TcpLogEntry &entry = queue[writeIdx % QUEUE_SIZE];
entry.info = info;
StringHelper::Copy(entry.description, description);
writeIdx = next;
(void)eventSem.Post();
}
}
ErrorManagement::ErrorType TcpLogger::Execute(ExecutionInfo & info) {
if (info.GetStage() == ExecutionInfo::TerminationStage) return ErrorManagement::NoError;
if (info.GetStage() == ExecutionInfo::StartupStage) {
workerThreadId = Threads::Id();
return ErrorManagement::NoError;
}
while (info.GetStage() == ExecutionInfo::MainStage) {
// 1. Check for new connections
BasicTCPSocket *newClient = server.WaitConnection(1);
if (newClient != NULL_PTR(BasicTCPSocket *)) {
clientsMutex.FastLock();
bool added = false;
for (uint32 i=0; i<MAX_CLIENTS; i++) {
if (activeClients[i] == NULL_PTR(BasicTCPSocket*)) {
activeClients[i] = newClient;
added = true;
break;
}
}
clientsMutex.FastUnLock();
if (!added) {
newClient->Close();
delete newClient;
} else {
(void)newClient->SetBlocking(false);
}
}
// 2. Stream data to clients
bool hadData = false;
while (readIdx != writeIdx) {
hadData = true;
uint32 idx = readIdx % QUEUE_SIZE;
TcpLogEntry &entry = queue[idx];
StreamString level;
ErrorManagement::ErrorCodeToStream(entry.info.header.errorType, level);
StreamString packet;
packet.Printf("LOG %s %s\n", level.Buffer(), entry.description);
uint32 size = packet.Size();
clientsMutex.FastLock();
for (uint32 j=0; j<MAX_CLIENTS; j++) {
if (activeClients[j] != NULL_PTR(BasicTCPSocket*)) {
uint32 s = size;
if (!activeClients[j]->Write(packet.Buffer(), s)) {
activeClients[j]->Close();
delete activeClients[j];
activeClients[j] = NULL_PTR(BasicTCPSocket*);
}
}
}
clientsMutex.FastUnLock();
readIdx = (readIdx + 1) % QUEUE_SIZE;
}
if (!hadData) {
(void)eventSem.Wait(TimeoutType(100));
eventSem.Reset();
} else {
Sleep::MSec(1);
}
}
return ErrorManagement::NoError;
}
}

View File

@@ -0,0 +1,65 @@
#ifndef TCPLOGGER_H
#define TCPLOGGER_H
#include "LoggerConsumerI.h"
#include "ReferenceContainer.h"
#include "EmbeddedServiceMethodBinderI.h"
#include "BasicTCPSocket.h"
#include "SingleThreadService.h"
#include "FastPollingMutexSem.h"
#include "EventSem.h"
namespace MARTe {
struct TcpLogEntry {
ErrorManagement::ErrorInformation info;
char8 description[MAX_ERROR_MESSAGE_SIZE];
};
/**
* @brief Logger consumer that publishes framework logs to TCP and stdout.
* @details Implements LoggerConsumerI to be used inside a LoggerService.
*/
class TcpLogger : public ReferenceContainer, public LoggerConsumerI, public EmbeddedServiceMethodBinderI {
public:
CLASS_REGISTER_DECLARATION()
TcpLogger();
virtual ~TcpLogger();
virtual bool Initialise(StructuredDataI & data);
/**
* @brief Implementation of LoggerConsumerI.
* Called by LoggerService.
*/
virtual void ConsumeLogMessage(LoggerPage *logPage);
/**
* @brief Worker thread method for TCP streaming.
*/
virtual ErrorManagement::ErrorType Execute(ExecutionInfo & info);
private:
void InsertLogIntoQueue(const ErrorManagement::ErrorInformation &info, const char8 * const description);
uint16 port;
BasicTCPSocket server;
static const uint32 MAX_CLIENTS = 8;
BasicTCPSocket* activeClients[MAX_CLIENTS];
FastPollingMutexSem clientsMutex;
SingleThreadService service;
ThreadIdentifier workerThreadId;
static const uint32 QUEUE_SIZE = 1024;
TcpLogEntry queue[QUEUE_SIZE];
volatile uint32 readIdx;
volatile uint32 writeIdx;
EventSem eventSem;
};
}
#endif

View File

@@ -0,0 +1 @@
include Makefile.inc

View File

@@ -0,0 +1,46 @@
#############################################################
#
# Copyright 2015 F4E | European Joint Undertaking for ITER
# and the Development of Fusion Energy ('Fusion for Energy')
#
# Licensed under the EUPL, Version 1.1 or - as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://ec.europa.eu/idabc/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
# $Id: Makefile.inc 3 2012-01-15 16:26:07Z aneto $
#
#############################################################
SPB =
ROOT_DIR=../../..
PACKAGE=Core
ROOT_DIR=../../..
ABS_ROOT_DIR=$(abspath $(ROOT_DIR))
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
all: $(OBJS) $(SUBPROJ)
echo $(OBJS)
include depends.$(TARGET)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)

View File

@@ -0,0 +1,75 @@
#ifndef __RESULT_H
#define __RESULT_H
#include <cassert>
namespace MARTe {
/**
* @brief Namespace for result error codes.
*/
namespace Errors {
enum ErrorT {
None = 0,
Generic = 1,
OutOfMemory = 2,
IndexOutOfBounds = 3,
ValueOutOfRange = 4,
WrongType = 5,
Empty = 6,
};
}
/**
* @brief A simple Result type for error handling.
* @details This implementation is header-only to ensure template linkage.
* Requirement: T and E must have default constructors and be copyable.
*/
template <typename T, typename E = Errors::ErrorT>
class Result {
public:
static Result Success(const T &t) {
return Result(t, true);
}
static Result Fail(const E &e) {
return Result(e, false);
}
Result() : state(false), val(T()), err(E()) {}
Result(const Result &r) : state(r.state), val(r.val), err(r.err) {}
Result& operator=(const Result &r) {
if (this != &r) {
state = r.state;
val = r.val;
err = r.err;
}
return *this;
}
bool Ok() const { return state; }
bool IsOk() const { return state; }
// Const accessors
const T &Val() const { assert(state); return val; }
const E &Err() const { assert(!state); return err; }
// Non-const accessors
T &Val() { assert(state); return val; }
E &Err() { assert(!state); return err; }
operator bool() const { return state; }
private:
Result(const T &v, bool s) : state(s), val(v), err(E()) {}
Result(const E &e, bool s) : state(s), val(T()), err(e) {}
bool state;
T val;
E err;
};
} // namespace MARTe
#endif

View File

@@ -0,0 +1 @@
Result.o: Result.cpp Result.h

143
Source/Core/Types/Vec/Vec.h Normal file
View File

@@ -0,0 +1,143 @@
#ifndef __VEC_H
#define __VEC_H
#include "Result.h"
#include <stddef.h>
#include <string.h>
#include <cassert>
#include <stdio.h>
namespace MARTe {
/**
* @brief Simple dynamic array (vector) implementation with fixed growth.
* @tparam T The type of elements.
* @tparam GROWTH The number of elements to add when the buffer is full.
*/
template <typename T, size_t GROWTH = 16>
class Vec {
public:
Vec() : size(0), mem_size(GROWTH), arr(NULL) {
arr = new T[mem_size];
}
Vec(const Vec<T, GROWTH> &other) : size(other.size), mem_size(other.mem_size), arr(NULL) {
arr = new T[mem_size];
for (size_t i = 0; i < size; ++i) {
arr[i] = other.arr[i];
}
}
Vec(const T *data, const size_t count) : size(count), mem_size(count + GROWTH), arr(NULL) {
arr = new T[mem_size];
for (size_t i = 0; i < size; ++i) {
arr[i] = data[i];
}
}
~Vec() {
if (arr != NULL) {
delete[] arr;
arr = NULL;
}
}
Vec& operator=(const Vec<T, GROWTH> &other) {
if (this != &other) {
T* new_arr = new T[other.mem_size];
for (size_t i = 0; i < other.size; ++i) {
new_arr[i] = other.arr[i];
}
if (arr != NULL) {
delete[] arr;
}
arr = new_arr;
size = other.size;
mem_size = other.mem_size;
}
return *this;
}
void Clear() {
size = 0;
}
size_t Size() const {
return size;
}
T* GetInternalBuffer() { return arr; }
bool Remove(size_t index) {
if (index >= size) return false;
for (size_t i = index; i < size - 1; ++i) {
arr[i] = arr[i + 1];
}
size--;
return true;
}
bool Insert(size_t index, const T& val) {
if (index > size) return false;
if (size == mem_size) extend();
for (size_t i = size; i > index; --i) {
arr[i] = arr[i - 1];
}
arr[index] = val;
size++;
return true;
}
Result<T> Get(size_t index) const {
if (index >= size) return Result<T>::Fail(Errors::IndexOutOfBounds);
return Result<T>::Success(arr[index]);
}
void Push(const T &val) {
if (size == mem_size) extend();
arr[size++] = val;
}
Result<T> Pop() {
if (size == 0) return Result<T>::Fail(Errors::Empty);
T last = arr[--size];
return Result<T>::Success(last);
}
const T &operator[](const size_t index) const {
assert(index < size);
return arr[index];
}
T &operator[](const size_t index) {
assert(index < size);
return arr[index];
}
protected:
const T *mem() const { return arr; }
size_t memSize() const { return mem_size; }
private:
size_t size;
size_t mem_size;
T *arr;
void extend() {
size_t new_mem_size = mem_size + GROWTH;
T *new_arr = new T[new_mem_size];
for (size_t i = 0; i < size; ++i) {
new_arr[i] = arr[i];
}
if (arr != NULL) {
delete[] arr;
}
arr = new_arr;
mem_size = new_mem_size;
}
};
} // namespace MARTe
#endif

View File

@@ -0,0 +1 @@
../../../..//Build/x86-linux/Core/Types/Vec/Vec.o: Vec.cpp

View File

@@ -0,0 +1 @@
Vec.o: Vec.cpp

View File

View File

@@ -1,910 +0,0 @@
#include "DebugService.h"
#include "StandardParser.h"
#include "StreamString.h"
#include "BasicSocket.h"
#include "DebugBrokerWrapper.h"
#include "ObjectRegistryDatabase.h"
#include "ClassRegistryItem.h"
#include "ObjectBuilder.h"
#include "TypeConversion.h"
#include "HighResolutionTimer.h"
#include "ConfigurationDatabase.h"
#include "GAM.h"
// Explicitly include target brokers for templating
#include "MemoryMapInputBroker.h"
#include "MemoryMapOutputBroker.h"
#include "MemoryMapSynchronisedInputBroker.h"
#include "MemoryMapSynchronisedOutputBroker.h"
#include "MemoryMapInterpolatedInputBroker.h"
#include "MemoryMapMultiBufferInputBroker.h"
#include "MemoryMapMultiBufferOutputBroker.h"
#include "MemoryMapSynchronisedMultiBufferInputBroker.h"
#include "MemoryMapSynchronisedMultiBufferOutputBroker.h"
namespace MARTe {
DebugService* DebugService::instance = NULL_PTR(DebugService*);
ErrorManagement::ErrorProcessFunctionType DebugService::originalLogCallback = NULL_PTR(ErrorManagement::ErrorProcessFunctionType);
static void EscapeJson(const char8* src, StreamString &dst) {
if (src == NULL_PTR(const char8*)) return;
while (*src != '\0') {
if (*src == '"') dst += "\\\"";
else if (*src == '\\') dst += "\\\\";
else if (*src == '\n') dst += "\\n";
else if (*src == '\r') dst += "\\r";
else if (*src == '\t') dst += "\\t";
else dst += *src;
src++;
}
}
CLASS_REGISTER(DebugService, "1.0")
DebugService::DebugService() :
ReferenceContainer(), EmbeddedServiceMethodBinderI(), LoggerConsumerI(),
binderServer(this, ServiceBinder::ServerType),
binderStreamer(this, ServiceBinder::StreamerType),
binderLogStreamer(this, ServiceBinder::LogStreamerType),
threadService(binderServer),
streamerService(binderStreamer),
logStreamerService(binderLogStreamer)
{
controlPort = 0;
streamPort = 8081;
logPort = 8082;
streamIP = "127.0.0.1";
numberOfSignals = 0;
numberOfAliases = 0;
isServer = false;
suppressTimeoutLogs = true;
isPaused = false;
for (uint32 i=0; i<MAX_CLIENTS; i++) {
activeClients[i] = NULL_PTR(BasicTCPSocket*);
activeLogClients[i] = NULL_PTR(BasicTCPSocket*);
}
logQueueRead = 0;
logQueueWrite = 0;
serverThreadId = InvalidThreadIdentifier;
streamerThreadId = InvalidThreadIdentifier;
logStreamerThreadId = InvalidThreadIdentifier;
}
DebugService::~DebugService() {
if (instance == this) {
if (ErrorManagement::errorMessageProcessFunction == &DebugService::LogCallback) {
ErrorManagement::SetErrorProcessFunction(originalLogCallback);
}
instance = NULL_PTR(DebugService*);
}
threadService.Stop();
streamerService.Stop();
logStreamerService.Stop();
tcpServer.Close();
udpSocket.Close();
logServer.Close();
for (uint32 i=0; i<MAX_CLIENTS; i++) {
if (activeClients[i] != NULL_PTR(BasicTCPSocket*)) {
activeClients[i]->Close();
delete activeClients[i];
}
if (activeLogClients[i] != NULL_PTR(BasicTCPSocket*)) {
activeLogClients[i]->Close();
delete activeLogClients[i];
}
}
}
bool DebugService::Initialise(StructuredDataI & data) {
if (!ReferenceContainer::Initialise(data)) return false;
if (!data.Read("ControlPort", controlPort)) {
(void)data.Read("TcpPort", controlPort);
}
if (controlPort > 0) {
isServer = true;
instance = this;
}
if (!data.Read("StreamPort", streamPort)) {
(void)data.Read("UdpPort", streamPort);
}
if (!data.Read("LogPort", logPort)) {
(void)data.Read("TcpLogPort", logPort);
}
(void)data.Read("StreamIP", streamIP);
uint32 suppress = 1;
if (data.Read("SuppressTimeoutLogs", suppress)) {
suppressTimeoutLogs = (suppress == 1);
}
if (isServer) {
if (ErrorManagement::errorMessageProcessFunction != &DebugService::LogCallback) {
originalLogCallback = ErrorManagement::errorMessageProcessFunction;
ErrorManagement::SetErrorProcessFunction(&DebugService::LogCallback);
}
if (!traceBuffer.Init(1024 * 1024)) return false;
(void)logEvent.Create();
PatchRegistry();
ConfigurationDatabase threadData;
threadData.Write("Timeout", (uint32)1000);
threadService.Initialise(threadData);
streamerService.Initialise(threadData);
logStreamerService.Initialise(threadData);
if (!tcpServer.Open()) {
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to open TCP Server Socket");
return false;
}
if (!udpSocket.Open()) {
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to open UDP Socket");
return false;
}
if (!logServer.Open()) {
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to open Log Server Socket");
return false;
}
if (threadService.Start() != ErrorManagement::NoError) {
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to start Server thread");
return false;
}
if (streamerService.Start() != ErrorManagement::NoError) {
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to start Streamer thread");
return false;
}
if (logStreamerService.Start() != ErrorManagement::NoError) {
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to start LogStreamer thread");
return false;
}
}
return true;
}
void PatchItemInternal(const char8* className, ObjectBuilder* builder) {
ClassRegistryDatabase *db = ClassRegistryDatabase::Instance();
ClassRegistryItem *item = (ClassRegistryItem*)db->Find(className);
if (item != NULL_PTR(ClassRegistryItem*)) {
item->SetObjectBuilder(builder);
}
}
void DebugService::PatchRegistry() {
static DebugMemoryMapInputBrokerBuilder b1;
PatchItemInternal("MemoryMapInputBroker", &b1);
static DebugMemoryMapOutputBrokerBuilder b2;
PatchItemInternal("MemoryMapOutputBroker", &b2);
static DebugMemoryMapSynchronisedInputBrokerBuilder b3;
PatchItemInternal("MemoryMapSynchronisedInputBroker", &b3);
static DebugMemoryMapSynchronisedOutputBrokerBuilder b4;
PatchItemInternal("MemoryMapSynchronisedOutputBroker", &b4);
static DebugMemoryMapInterpolatedInputBrokerBuilder b5;
PatchItemInternal("MemoryMapInterpolatedInputBroker", &b5);
static DebugMemoryMapMultiBufferInputBrokerBuilder b6;
PatchItemInternal("MemoryMapMultiBufferInputBroker", &b6);
static DebugMemoryMapMultiBufferOutputBrokerBuilder b7;
PatchItemInternal("MemoryMapMultiBufferOutputBroker", &b7);
static DebugMemoryMapSynchronisedMultiBufferInputBrokerBuilder b8;
PatchItemInternal("MemoryMapSynchronisedMultiBufferInputBroker", &b8);
static DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder b9;
PatchItemInternal("MemoryMapSynchronisedMultiBufferOutputBroker", &b9);
}
void DebugService::ProcessSignal(DebugSignalInfo* s, uint32 size) {
if (s != NULL_PTR(DebugSignalInfo*)) {
if (s->isForcing) {
MemoryOperationsHelper::Copy(s->memoryAddress, s->forcedValue, size);
}
if (s->isTracing) {
if (s->decimationFactor <= 1) {
(void)traceBuffer.Push(s->internalID, s->memoryAddress, size);
}
else {
if (s->decimationCounter == 0) {
(void)traceBuffer.Push(s->internalID, s->memoryAddress, size);
s->decimationCounter = s->decimationFactor - 1;
}
else {
s->decimationCounter--;
}
}
}
}
}
DebugSignalInfo* DebugService::RegisterSignal(void* memoryAddress, TypeDescriptor type, const char8* name) {
mutex.FastLock();
DebugSignalInfo* res = NULL_PTR(DebugSignalInfo*);
uint32 sigIdx = 0xFFFFFFFF;
for(uint32 i=0; i<numberOfSignals; i++) {
if(signals[i].memoryAddress == memoryAddress) {
res = &signals[i];
sigIdx = i;
break;
}
}
if (res == NULL_PTR(DebugSignalInfo*) && numberOfSignals < MAX_SIGNALS) {
sigIdx = numberOfSignals;
res = &signals[numberOfSignals];
res->memoryAddress = memoryAddress;
res->type = type;
res->name = name;
res->isTracing = false;
res->isForcing = false;
res->internalID = numberOfSignals;
res->decimationFactor = 1;
res->decimationCounter = 0;
numberOfSignals++;
}
if (sigIdx != 0xFFFFFFFF && numberOfAliases < MAX_ALIASES) {
bool foundAlias = false;
for (uint32 i=0; i<numberOfAliases; i++) {
if (aliases[i].name == name) { foundAlias = true; break; }
}
if (!foundAlias) {
aliases[numberOfAliases].name = name;
aliases[numberOfAliases].signalIndex = sigIdx;
numberOfAliases++;
}
}
mutex.FastUnLock();
return res;
}
static bool RecursiveGetFullObjectName(ReferenceContainer *container, const Object &obj, StreamString &path) {
uint32 size = container->Size();
for (uint32 i=0; i<size; i++) {
Reference child = container->Get(i);
if (child.IsValid()) {
if (child.operator->() == &obj) {
path = child->GetName();
return true;
}
ReferenceContainer *inner = dynamic_cast<ReferenceContainer*>(child.operator->());
if (inner) {
if (RecursiveGetFullObjectName(inner, obj, path)) {
StreamString prefix = child->GetName();
prefix += ".";
prefix += path;
path = prefix;
return true;
}
}
}
}
return false;
}
bool DebugService::GetFullObjectName(const Object &obj, StreamString &fullPath) {
fullPath = "";
if (RecursiveGetFullObjectName(ObjectRegistryDatabase::Instance(), obj, fullPath)) {
StreamString abs = "Root.";
abs += fullPath;
fullPath = abs;
return true;
}
return false;
}
ErrorManagement::ErrorType DebugService::Execute(ExecutionInfo & info) {
return ErrorManagement::FatalError;
}
ErrorManagement::ErrorType DebugService::Server(ExecutionInfo & info) {
if (info.GetStage() == ExecutionInfo::TerminationStage) return ErrorManagement::NoError;
if (info.GetStage() == ExecutionInfo::StartupStage) {
serverThreadId = Threads::Id();
if (!tcpServer.Listen(controlPort)) return ErrorManagement::FatalError;
return ErrorManagement::NoError;
}
while (info.GetStage() == ExecutionInfo::MainStage) {
if (ErrorManagement::errorMessageProcessFunction != &DebugService::LogCallback) {
originalLogCallback = ErrorManagement::errorMessageProcessFunction;
ErrorManagement::SetErrorProcessFunction(&DebugService::LogCallback);
}
BasicTCPSocket *newClient = tcpServer.WaitConnection(1);
if (newClient != NULL_PTR(BasicTCPSocket *)) {
clientsMutex.FastLock();
bool added = false;
for (uint32 i=0; i<MAX_CLIENTS; i++) {
if (activeClients[i] == NULL_PTR(BasicTCPSocket*)) {
activeClients[i] = newClient;
added = true;
break;
}
}
clientsMutex.FastUnLock();
if (!added) {
newClient->Close();
delete newClient;
}
}
for (uint32 i=0; i<MAX_CLIENTS; i++) {
BasicTCPSocket *client = NULL_PTR(BasicTCPSocket*);
clientsMutex.FastLock();
client = activeClients[i];
clientsMutex.FastUnLock();
if (client != NULL_PTR(BasicTCPSocket*)) {
char buffer[1024];
uint32 size = 1024;
TimeoutType timeout(0);
bool ok = client->Read(buffer, size, timeout);
if (ok && size > 0) {
StreamString command;
command.Write(buffer, size);
HandleCommand(command, client);
} else if (!ok) {
if (!client->IsValid()) {
clientsMutex.FastLock();
client->Close();
delete client;
activeClients[i] = NULL_PTR(BasicTCPSocket*);
clientsMutex.FastUnLock();
}
}
}
}
Sleep::MSec(10);
}
return ErrorManagement::NoError;
}
ErrorManagement::ErrorType DebugService::LogStreamer(ExecutionInfo & info) {
if (info.GetStage() == ExecutionInfo::TerminationStage) return ErrorManagement::NoError;
if (info.GetStage() == ExecutionInfo::StartupStage) {
logStreamerThreadId = Threads::Id();
if (!logServer.Listen(logPort)) return ErrorManagement::FatalError;
return ErrorManagement::NoError;
}
while (info.GetStage() == ExecutionInfo::MainStage) {
BasicTCPSocket *newClient = logServer.WaitConnection(1);
if (newClient != NULL_PTR(BasicTCPSocket *)) {
logClientsMutex.FastLock();
bool added = false;
for (uint32 i=0; i<MAX_CLIENTS; i++) {
if (activeLogClients[i] == NULL_PTR(BasicTCPSocket*)) {
activeLogClients[i] = newClient;
added = true;
break;
}
}
logClientsMutex.FastUnLock();
if (!added) {
newClient->Close();
delete newClient;
}
}
bool hadData = false;
for (uint32 b=0; b<50; b++) {
if (logQueueRead == logQueueWrite) break;
hadData = true;
uint32 idx = logQueueRead % LOG_QUEUE_SIZE;
LogEntry &entry = logQueue[idx];
StreamString level;
ErrorManagement::ErrorCodeToStream(entry.info.header.errorType, level);
StreamString packet;
packet.Printf("LOG %s %s\n", level.Buffer(), entry.description);
uint32 size = packet.Size();
logClientsMutex.FastLock();
for (uint32 j=0; j<MAX_CLIENTS; j++) {
if (activeLogClients[j] != NULL_PTR(BasicTCPSocket*)) {
uint32 s = size;
if (!activeLogClients[j]->Write(packet.Buffer(), s)) {
activeLogClients[j]->Close();
delete activeLogClients[j];
activeLogClients[j] = NULL_PTR(BasicTCPSocket*);
}
}
}
logClientsMutex.FastUnLock();
logQueueRead++;
}
if (!hadData) {
(void)logEvent.Wait(TimeoutType(100));
logEvent.Reset();
} else {
Sleep::MSec(1);
}
}
return ErrorManagement::NoError;
}
ErrorManagement::ErrorType DebugService::Streamer(ExecutionInfo & info) {
if (info.GetStage() == ExecutionInfo::TerminationStage) return ErrorManagement::NoError;
if (info.GetStage() == ExecutionInfo::StartupStage) {
streamerThreadId = Threads::Id();
return ErrorManagement::NoError;
}
InternetHost dest(streamPort, streamIP.Buffer());
udpSocket.SetDestination(dest);
uint8 packetBuffer[4096];
uint32 packetOffset = 0;
uint32 sequenceNumber = 0;
while (info.GetStage() == ExecutionInfo::MainStage) {
uint32 id;
uint32 size;
uint8 sampleData[1024];
bool hasData = false;
while ((info.GetStage() == ExecutionInfo::MainStage) && traceBuffer.Pop(id, sampleData, size, 1024)) {
hasData = true;
if (packetOffset == 0) {
TraceHeader header;
header.magic = 0xDA7A57AD;
header.seq = sequenceNumber++;
header.timestamp = HighResolutionTimer::Counter();
header.count = 0;
MemoryOperationsHelper::Copy(packetBuffer, &header, sizeof(TraceHeader));
packetOffset = sizeof(TraceHeader);
}
if (packetOffset + 8 + size > 1400) {
uint32 toWrite = packetOffset;
udpSocket.Write((char8*)packetBuffer, toWrite);
packetOffset = 0;
TraceHeader header;
header.magic = 0xDA7A57AD;
header.seq = sequenceNumber++;
header.timestamp = HighResolutionTimer::Counter();
header.count = 0;
MemoryOperationsHelper::Copy(packetBuffer, &header, sizeof(TraceHeader));
packetOffset = sizeof(TraceHeader);
}
MemoryOperationsHelper::Copy(&packetBuffer[packetOffset], &id, 4);
MemoryOperationsHelper::Copy(&packetBuffer[packetOffset + 4], &size, 4);
MemoryOperationsHelper::Copy(&packetBuffer[packetOffset + 8], sampleData, size);
packetOffset += (8 + size);
TraceHeader *h = (TraceHeader*)packetBuffer;
h->count++;
}
if (packetOffset > 0) {
uint32 toWrite = packetOffset;
udpSocket.Write((char8*)packetBuffer, toWrite);
packetOffset = 0;
}
if (!hasData) Sleep::MSec(1);
}
return ErrorManagement::NoError;
}
static bool SuffixMatch(const char8* target, const char8* pattern) {
uint32 tLen = StringHelper::Length(target);
uint32 pLen = StringHelper::Length(pattern);
if (pLen > tLen) return false;
const char8* suffix = target + (tLen - pLen);
if (StringHelper::Compare(suffix, pattern) == 0) {
if (tLen == pLen || *(suffix - 1) == '.') return true;
}
return false;
}
void DebugService::HandleCommand(StreamString cmd, BasicTCPSocket *client) {
StreamString token;
cmd.Seek(0);
char8 term;
const char8* delims = " \r\n";
if (cmd.GetToken(token, delims, term)) {
if (token == "FORCE") {
StreamString name, val;
if (cmd.GetToken(name, delims, term) && cmd.GetToken(val, delims, term)) {
uint32 count = ForceSignal(name.Buffer(), val.Buffer());
if (client) {
StreamString resp; resp.Printf("OK FORCE %u\n", count);
uint32 s = resp.Size(); client->Write(resp.Buffer(), s);
}
}
}
else if (token == "UNFORCE") {
StreamString name;
if (cmd.GetToken(name, delims, term)) {
uint32 count = UnforceSignal(name.Buffer());
if (client) {
StreamString resp; resp.Printf("OK UNFORCE %u\n", count);
uint32 s = resp.Size(); client->Write(resp.Buffer(), s);
}
}
}
else if (token == "TRACE") {
StreamString name, state, decim;
if (cmd.GetToken(name, delims, term) && cmd.GetToken(state, delims, term)) {
bool enable = (state == "1");
uint32 d = 1;
if (cmd.GetToken(decim, delims, term)) {
AnyType decimVal(UnsignedInteger32Bit, 0u, &d);
AnyType decimStr(CharString, 0u, decim.Buffer());
TypeConvert(decimVal, decimStr);
}
uint32 count = TraceSignal(name.Buffer(), enable, d);
if (client) {
StreamString resp; resp.Printf("OK TRACE %u\n", count);
uint32 s = resp.Size(); client->Write(resp.Buffer(), s);
}
}
}
else if (token == "DISCOVER") Discover(client);
else if (token == "PAUSE") {
SetPaused(true);
if (client) { uint32 s = 3; client->Write("OK\n", s); }
}
else if (token == "RESUME") {
SetPaused(false);
if (client) { uint32 s = 3; client->Write("OK\n", s); }
}
else if (token == "TREE") {
StreamString json;
json = "{\"Name\": \"Root\", \"Class\": \"ObjectRegistryDatabase\", \"Children\": [\n";
ExportTree(ObjectRegistryDatabase::Instance(), json);
json += "\n]}\nOK TREE\n";
uint32 s = json.Size();
client->Write(json.Buffer(), s);
}
else if (token == "INFO") {
StreamString path;
if (cmd.GetToken(path, delims, term)) InfoNode(path.Buffer(), client);
}
else if (token == "LS") {
StreamString path;
if (cmd.GetToken(path, delims, term)) ListNodes(path.Buffer(), client);
else ListNodes(NULL_PTR(const char8*), client);
}
else if (client) {
const char* msg = "ERROR: Unknown command\n";
uint32 s = StringHelper::Length(msg);
client->Write(msg, s);
}
}
}
void DebugService::InfoNode(const char8* path, BasicTCPSocket *client) {
if (!client) return;
Reference ref = ObjectRegistryDatabase::Instance()->Find(path);
StreamString json = "{";
if (ref.IsValid()) {
json += "\"Name\": \""; EscapeJson(ref->GetName(), json);
json += "\", \"Class\": \""; EscapeJson(ref->GetClassProperties()->GetName(), json); json += "\"";
ConfigurationDatabase db;
if (ref->ExportData(db)) {
json += ", \"Config\": {";
db.MoveToRoot();
uint32 nChildren = db.GetNumberOfChildren();
for (uint32 i=0; i<nChildren; i++) {
const char8* cname = db.GetChildName(i);
AnyType at = db.GetType(cname);
char8 valBuf[1024];
AnyType strType(CharString, 0u, valBuf);
strType.SetNumberOfElements(0, 1024);
if (TypeConvert(strType, at)) {
json += "\""; EscapeJson(cname, json); json += "\": \"";
EscapeJson(valBuf, json); json += "\"";
if (i < nChildren - 1) json += ", ";
}
}
json += "}";
}
} else {
mutex.FastLock();
bool found = false;
for (uint32 i=0; i<numberOfAliases; i++) {
if (aliases[i].name == path || SuffixMatch(aliases[i].name.Buffer(), path)) {
DebugSignalInfo &s = signals[aliases[i].signalIndex];
const char8* tname = TypeDescriptor::GetTypeNameFromTypeDescriptor(s.type);
json.Printf("\"Name\": \"%s\", \"Class\": \"Signal\", \"Type\": \"%s\", \"ID\": %d",
s.name.Buffer(), tname ? tname : "Unknown", s.internalID);
found = true;
break;
}
}
mutex.FastUnLock();
if (!found) json += "\"Error\": \"Object not found\"";
}
json += "}\nOK INFO\n";
uint32 s = json.Size();
client->Write(json.Buffer(), s);
}
uint32 DebugService::ExportTree(ReferenceContainer *container, StreamString &json) {
if (container == NULL_PTR(ReferenceContainer*)) return 0;
uint32 size = container->Size();
uint32 validCount = 0;
for (uint32 i = 0u; i < size; i++) {
Reference child = container->Get(i);
if (child.IsValid()) {
if (validCount > 0u) json += ",\n";
StreamString nodeJson;
const char8* cname = child->GetName();
if (cname == NULL_PTR(const char8*)) cname = "unnamed";
const char8* clsname = child->GetClassProperties()->GetName();
nodeJson += "{\"Name\": \""; EscapeJson(cname, nodeJson);
nodeJson += "\", \"Class\": \""; EscapeJson(clsname, nodeJson); nodeJson += "\"";
ReferenceContainer *inner = dynamic_cast<ReferenceContainer*>(child.operator->());
DataSourceI *ds = dynamic_cast<DataSourceI*>(child.operator->());
GAM *gam = dynamic_cast<GAM*>(child.operator->());
if ((inner != NULL_PTR(ReferenceContainer*)) || (ds != NULL_PTR(DataSourceI*)) || (gam != NULL_PTR(GAM*))) {
nodeJson += ", \"Children\": [\n";
uint32 subCount = 0u;
if (inner != NULL_PTR(ReferenceContainer*)) subCount += ExportTree(inner, nodeJson);
if (ds != NULL_PTR(DataSourceI*)) {
uint32 nSignals = ds->GetNumberOfSignals();
for (uint32 j = 0u; j < nSignals; j++) {
if (subCount > 0u) nodeJson += ",\n";
subCount++;
StreamString sname; (void)ds->GetSignalName(j, sname);
const char8* stype = TypeDescriptor::GetTypeNameFromTypeDescriptor(ds->GetSignalType(j));
uint8 dims = 0u; (void)ds->GetSignalNumberOfDimensions(j, dims);
uint32 elems = 0u; (void)ds->GetSignalNumberOfElements(j, elems);
nodeJson += "{\"Name\": \""; EscapeJson(sname.Buffer(), nodeJson);
nodeJson += "\", \"Class\": \"Signal\", \"Type\": \""; EscapeJson(stype ? stype : "Unknown", nodeJson);
nodeJson.Printf("\", \"Dimensions\": %d, \"Elements\": %u}", dims, elems);
}
}
if (gam != NULL_PTR(GAM*)) {
uint32 nIn = gam->GetNumberOfInputSignals();
for (uint32 j = 0u; j < nIn; j++) {
if (subCount > 0u) nodeJson += ",\n";
subCount++;
StreamString sname; (void)gam->GetSignalName(InputSignals, j, sname);
const char8* stype = TypeDescriptor::GetTypeNameFromTypeDescriptor(gam->GetSignalType(InputSignals, j));
uint32 dims = 0u; (void)gam->GetSignalNumberOfDimensions(InputSignals, j, dims);
uint32 elems = 0u; (void)gam->GetSignalNumberOfElements(InputSignals, j, elems);
nodeJson += "{\"Name\": \"In."; EscapeJson(sname.Buffer(), nodeJson);
nodeJson += "\", \"Class\": \"InputSignal\", \"Type\": \""; EscapeJson(stype ? stype : "Unknown", nodeJson);
nodeJson.Printf("\", \"Dimensions\": %u, \"Elements\": %u}", dims, elems);
}
uint32 nOut = gam->GetNumberOfOutputSignals();
for (uint32 j = 0u; j < nOut; j++) {
if (subCount > 0u) nodeJson += ",\n";
subCount++;
StreamString sname; (void)gam->GetSignalName(OutputSignals, j, sname);
const char8* stype = TypeDescriptor::GetTypeNameFromTypeDescriptor(gam->GetSignalType(OutputSignals, j));
uint32 dims = 0u; (void)gam->GetSignalNumberOfDimensions(OutputSignals, j, dims);
uint32 elems = 0u; (void)gam->GetSignalNumberOfElements(OutputSignals, j, elems);
nodeJson += "{\"Name\": \"Out."; EscapeJson(sname.Buffer(), nodeJson);
nodeJson += "\", \"Class\": \"OutputSignal\", \"Type\": \""; EscapeJson(stype ? stype : "Unknown", nodeJson);
nodeJson.Printf("\", \"Dimensions\": %u, \"Elements\": %u}", dims, elems);
}
}
nodeJson += "\n]";
}
nodeJson += "}";
json += nodeJson;
validCount++;
}
}
return validCount;
}
uint32 DebugService::ForceSignal(const char8* name, const char8* valueStr) {
mutex.FastLock();
uint32 count = 0;
for (uint32 i = 0; i < numberOfAliases; i++) {
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
DebugSignalInfo &s = signals[aliases[i].signalIndex];
s.isForcing = true;
AnyType dest(s.type, 0u, s.forcedValue);
AnyType source(CharString, 0u, valueStr);
(void)TypeConvert(dest, source);
count++;
}
}
mutex.FastUnLock();
return count;
}
uint32 DebugService::UnforceSignal(const char8* name) {
mutex.FastLock();
uint32 count = 0;
for (uint32 i = 0; i < numberOfAliases; i++) {
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
signals[aliases[i].signalIndex].isForcing = false;
count++;
}
}
mutex.FastUnLock();
return count;
}
uint32 DebugService::TraceSignal(const char8* name, bool enable, uint32 decimation) {
mutex.FastLock();
uint32 count = 0;
for (uint32 i = 0; i < numberOfAliases; i++) {
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
DebugSignalInfo &s = signals[aliases[i].signalIndex];
s.isTracing = enable;
s.decimationFactor = decimation;
s.decimationCounter = 0;
count++;
printf("[Debug] Tracing state for %s (ID: %u) set to %d\n", aliases[i].name.Buffer(), s.internalID, enable);
}
}
mutex.FastUnLock();
return count;
}
void DebugService::Discover(BasicTCPSocket *client) {
if (client) {
StreamString header = "{\n \"Signals\": [\n";
uint32 s = header.Size();
client->Write(header.Buffer(), s);
mutex.FastLock();
for (uint32 i = 0; i < numberOfAliases; i++) {
StreamString line;
DebugSignalInfo &sig = signals[aliases[i].signalIndex];
const char8* typeName = TypeDescriptor::GetTypeNameFromTypeDescriptor(sig.type);
if (typeName == NULL_PTR(const char8*)) typeName = "Unknown";
line.Printf(" {\"name\": \"%s\", \"id\": %d, \"type\": \"%s\"}", aliases[i].name.Buffer(), sig.internalID, typeName);
if (i < numberOfAliases - 1) line += ",";
line += "\n";
s = line.Size();
client->Write(line.Buffer(), s);
}
mutex.FastUnLock();
StreamString footer = " ]\n}\nOK DISCOVER\n";
s = footer.Size();
client->Write(footer.Buffer(), s);
}
}
void DebugService::ListNodes(const char8* path, BasicTCPSocket *client) {
if (!client) return;
Reference ref;
if (path == NULL_PTR(const char8*) || StringHelper::Length(path) == 0 || StringHelper::Compare(path, "/") == 0) {
ref = ObjectRegistryDatabase::Instance();
} else {
ref = ObjectRegistryDatabase::Instance()->Find(path);
}
if (ref.IsValid()) {
StreamString header;
header.Printf("Nodes under %s:\n", path ? path : "/");
uint32 s = header.Size();
client->Write(header.Buffer(), s);
ReferenceContainer *container = dynamic_cast<ReferenceContainer*>(ref.operator->());
if (container) {
uint32 size = container->Size();
for (uint32 i=0; i<size; i++) {
Reference child = container->Get(i);
if (child.IsValid()) {
StreamString line;
line.Printf(" %s [%s]\n", child->GetName(), child->GetClassProperties()->GetName());
s = line.Size();
client->Write(line.Buffer(), s);
}
}
}
DataSourceI *ds = dynamic_cast<DataSourceI*>(ref.operator->());
if (ds) {
StreamString dsHeader = " Signals:\n";
s = dsHeader.Size(); client->Write(dsHeader.Buffer(), s);
uint32 nSignals = ds->GetNumberOfSignals();
for (uint32 i=0; i<nSignals; i++) {
StreamString sname, line;
ds->GetSignalName(i, sname);
TypeDescriptor stype = ds->GetSignalType(i);
const char8* stypeName = TypeDescriptor::GetTypeNameFromTypeDescriptor(stype);
line.Printf(" %s [%s]\n", sname.Buffer(), stypeName ? stypeName : "Unknown");
s = line.Size(); client->Write(line.Buffer(), s);
}
}
GAM *gam = dynamic_cast<GAM*>(ref.operator->());
if (gam) {
uint32 nIn = gam->GetNumberOfInputSignals();
uint32 nOut = gam->GetNumberOfOutputSignals();
StreamString gamHeader;
gamHeader.Printf(" Input Signals (%d):\n", nIn);
s = gamHeader.Size(); client->Write(gamHeader.Buffer(), s);
for (uint32 i=0; i<nIn; i++) {
StreamString sname, line;
gam->GetSignalName(InputSignals, i, sname);
line.Printf(" %s\n", sname.Buffer());
s = line.Size(); client->Write(line.Buffer(), s);
}
gamHeader.SetSize(0);
gamHeader.Printf(" Output Signals (%d):\n", nOut);
s = gamHeader.Size(); client->Write(gamHeader.Buffer(), s);
for (uint32 i=0; i<nOut; i++) {
StreamString sname, line;
gam->GetSignalName(OutputSignals, i, sname);
line.Printf(" %s\n", sname.Buffer());
s = line.Size(); client->Write(line.Buffer(), s);
}
}
const char* okMsg = "OK LS\n";
s = StringHelper::Length(okMsg);
client->Write(okMsg, s);
} else {
const char* msg = "ERROR: Path not found\n";
uint32 s = StringHelper::Length(msg);
client->Write(msg, s);
}
}
void DebugService::ConsumeLogMessage(LoggerPage *logPage) {
}
void DebugService::LogCallback(const ErrorManagement::ErrorInformation &errorInfo, const char8 * const errorDescription) {
ThreadIdentifier current = Threads::Id();
if (instance != NULL_PTR(DebugService*)) {
StreamString levelStr;
ErrorManagement::ErrorCodeToStream(errorInfo.header.errorType, levelStr);
printf("[%s] %s\n", levelStr.Buffer(), errorDescription);
fflush(stdout);
bool isWorkerThread = false;
if (instance->serverThreadId != InvalidThreadIdentifier && current == instance->serverThreadId) isWorkerThread = true;
if (instance->streamerThreadId != InvalidThreadIdentifier && current == instance->streamerThreadId) isWorkerThread = true;
if (instance->logStreamerThreadId != InvalidThreadIdentifier && current == instance->logStreamerThreadId) isWorkerThread = true;
if (isWorkerThread) return;
if (instance->suppressTimeoutLogs && StringHelper::SearchString(errorDescription, "Timeout expired in recv()") != NULL_PTR(const char8*)) return;
LoggerPage tempPage;
tempPage.errorInfo = errorInfo;
StringHelper::Copy(tempPage.errorStrBuffer, errorDescription);
instance->InsertLogIntoQueue(&tempPage);
}
if (originalLogCallback) originalLogCallback(errorInfo, errorDescription);
}
void DebugService::InsertLogIntoQueue(LoggerPage *logPage) {
uint32 next = (logQueueWrite + 1) % LOG_QUEUE_SIZE;
if (next != logQueueRead) {
LogEntry &entry = logQueue[logQueueWrite % LOG_QUEUE_SIZE];
entry.info = logPage->errorInfo;
StringHelper::Copy(entry.description, logPage->errorStrBuffer);
logQueueWrite = next;
(void)logEvent.Post();
}
}
}

56
TUTORIAL.md Normal file
View File

@@ -0,0 +1,56 @@
# Tutorial: High-Speed Observability with MARTe2 Debug GUI
This guide will walk you through the process of tracing and forcing signals in a real-time MARTe2 application using the native Rust GUI client.
## 1. Environment Setup
### Launch the MARTe2 Application
First, start your application using the provided debug runner. This script launches the standard `MARTeApp.ex` while injecting the debugging layer:
```bash
./run_debug_app.sh
```
*Note: You should see logs indicating the `DebugService` has started on port 8080 and `TcpLogger` on port 8082.*
### Start the GUI Client
In a new terminal window, navigate to the client directory and run the GUI:
```bash
cd Tools/gui_client
cargo run --release
```
## 2. Exploring the Object Tree
Once connected, the left panel (**Application Tree**) displays the live hierarchy of your application.
1. **Navigate to Data:** Expand `Root` -> `App` -> `Data`.
2. **Inspect Nodes:** Click the ** Info** button next to any node (like `Timer` or `DDB`).
3. **View Metadata:** The bottom-left pane will display the full JSON configuration of that object, including its class, parameters, and signals.
## 3. Real-Time Signal Tracing (Oscilloscope)
Tracing allows you to see signal values exactly as they exist in the real-time memory map.
1. **Find a Signal:** In the tree, locate `Root.App.Data.Timer.Counter`.
2. **Activate Trace:** Click the **📈 Trace** button.
3. **Monitor the Scope:** The central **Oscilloscope** panel will begin plotting the signal.
4. **Verify Data Flow:** Check the **UDP Packets** counter in the top bar; it should be increasing rapidly, confirming high-speed data reception (Port 8081).
5. **Multi-Signal Trace:** You can click **📈 Trace** on other signals (like `Time`) to overlay multiple plots.
## 4. Signal Forcing (Manual Override)
Forcing allows you to bypass the framework logic and manually set a signal's value in memory.
1. **Locate Target:** Find a signal that is being written by a GAM, such as `Root.App.Data.DDB.Counter`.
2. **Open Force Dialog:** Click the **⚡ Force** button next to the signal.
3. **Inject Value:** In the popup dialog, enter a new value (e.g., `9999`) and click **Apply Force**.
4. **Observe Effect:** If you are tracing the same signal, the oscilloscope plot will immediately jump to and hold at `9999`.
5. **Release Control:** To stop forcing, click the **❌** button in the **Active Controls** (Right Panel) under "Forced Signals". The framework will resume writing its own values to that memory location.
## 5. Advanced Controls
### Global Pause
If you need to "freeze" the entire application to inspect a specific state:
- Click **⏸ Pause** in the top bar. The real-time threads will halt at the start of their next cycle.
- Click **▶ Resume** to restart the execution.
### Log Terminal
The bottom panel displays every `REPORT_ERROR` event from the C++ framework, powered by the standalone `TcpLogger` service.
- **Regex Filter:** Type a keyword like `Timer` in the filter box to isolate relevant events.
- **Pause Logs:** Toggle **⏸ Pause Logs** to stop the scrolling view while data continues to be captured in the background.

View File

@@ -1,18 +1,3 @@
+DebugService = {
Class = DebugService
ControlPort = 8080
StreamPort = 8081
StreamIP = "127.0.0.1"
}
+LoggerService = {
Class = LoggerService
CPUs = 0x1
+DebugConsumer = {
Class = DebugService
}
}
+App = {
Class = RealTimeApplication
+Functions = {
@@ -23,7 +8,7 @@
Counter = {
DataSource = Timer
Type = uint32
Frequency = 10
Frequency = 1000
}
Time = {
DataSource = Timer
@@ -32,22 +17,82 @@
}
OutputSignals = {
Counter = {
DataSource = DDB
DataSource = SyncDB
Type = uint32
}
Time = {
DataSource = Logger
DataSource = DDB
Type = uint32
}
}
}
+GAM2 = {
Class = IOGAM
InputSignals = {
Counter = {
DataSource = TimerSlow
Frequency = 1
}
Time = {
DataSource = TimerSlow
}
}
OutputSignals = {
Counter = {
Type = uint32
DataSource = Logger
}
Time = {
Type = uint32
DataSource = Logger
}
}
}
+GAM3 = {
Class = IOGAM
InputSignals = {
Counter = {
Frequency = 1
Samples = 100
Type = uint32
DataSource = SyncDB
}
}
OutputSignals = {
Counter = {
DataSource = DDB3
NumberOfElements = 100
Type = uint32
}
}
}
}
+Data = {
Class = ReferenceContainer
DefaultDataSource = DDB
+SyncDB = {
Class = RealTimeThreadSynchronisation
Timeout = 200
Signals = {
Counter = {
Type = uint32
}
}
}
+Timer = {
Class = LinuxTimer
SleepTime = 1000000 // 1 second
Signals = {
Counter = {
Type = uint32
}
Time = {
Type = uint32
}
}
}
+TimerSlow = {
Class = LinuxTimer
Signals = {
Counter = {
Type = uint32
@@ -77,6 +122,10 @@
}
}
}
+DDB3 = {
AllowNoProducer = 1
Class = GAMDataSource
}
+DAMS = {
Class = TimingDataSource
}
@@ -91,6 +140,14 @@
Class = RealTimeThread
Functions = {GAM1}
}
+Thread2 = {
Class = RealTimeThread
Functions = {GAM2}
}
+Thread3 = {
Class = RealTimeThread
Functions = {GAM3}
}
}
}
}
@@ -99,3 +156,11 @@
TimingDataSource = DAMS
}
}
+DebugService = {
Class = DebugService
ControlPort = 8080
UdpPort = 8081
LogPort = 8082
StreamIP = "127.0.0.1"
}

View File

@@ -1,8 +0,0 @@
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,163 @@
#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\" }"
" }"
" OutputSignals = {"
" Counter = { DataSource = DDB Type = uint32 }"
" }"
" }"
" }"
" +Data = {"
" Class = ReferenceContainer "
" +Timer = { Class = LinuxTimer SleepTime = 1000 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 }"
"}";
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");
if (app.IsValid()) {
if (app->ConfigureApplication()) {
if (app->PrepareNextState("State1") == ErrorManagement::NoError) {
if (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();
}

View File

@@ -0,0 +1,248 @@
#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(); // Skipping for now
Sleep::MSec(1000);
printf("\n--- Test 6: TREE Command Enhancement ---\n");
TestTreeCommand();
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();
}

View File

@@ -0,0 +1 @@
include Makefile.inc

View File

@@ -0,0 +1,44 @@
OBJSX = SchedulerTest.x TraceTest.x ValidationTest.x ConfigCommandTest.x TreeCommandTest.x TestCommon.x
PACKAGE = Test/Integration
ROOT_DIR = ../..
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
INCLUDES += -I$(ROOT_DIR)/Source/Core/Types/Result
INCLUDES += -I$(ROOT_DIR)/Source/Core/Types/Vec
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)

View File

@@ -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();
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,12 @@
#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);
}
#endif

View File

@@ -1,9 +1,10 @@
#include "BasicTCPSocket.h"
#include "BasicUDPSocket.h"
#include "DebugService.h"
#include "DebugCore.h"
#include "ObjectRegistryDatabase.h"
#include "StandardParser.h"
#include "StreamString.h"
#include "BasicUDPSocket.h"
#include "HighResolutionTimer.h"
#include <assert.h>
#include <stdio.h>
@@ -11,20 +12,22 @@ using namespace MARTe;
void TestFullTracePipeline() {
printf("Starting Full Trace Pipeline Test...\n");
printf("sizeof(TraceHeader) = %lu\n", sizeof(TraceHeader));
ObjectRegistryDatabase::Instance()->Purge();
// 1. Setup Service
DebugService service;
ConfigurationDatabase config;
config.Write("ControlPort", (uint16)8080);
config.Write("StreamPort", (uint16)8081);
config.Write("LogPort", (uint16)8082);
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, "Test.Signal");
DebugSignalInfo* sig = service.RegisterSignal(&mockValue, UnsignedInteger32Bit, "TraceTest.Signal", 0, 1);
assert(sig != NULL_PTR(DebugSignalInfo*));
printf("Signal registered with ID: %u\n", sig->internalID);
@@ -35,13 +38,14 @@ void TestFullTracePipeline() {
// 4. Setup a local UDP listener
BasicUDPSocket listener;
assert(listener.Open());
assert(listener.Listen(8081));
assert(listener.Listen(8083));
// 5. Simulate cycles
printf("Simulating cycles...\n");
for (int i=0; i<50; i++) {
mockValue = 1000 + i;
service.ProcessSignal(sig, sizeof(uint32));
uint64 ts = (uint64)((float64)HighResolutionTimer::Counter() * HighResolutionTimer::Period() * 1000000.0);
service.ProcessSignal(sig, sizeof(uint32), ts);
Sleep::MSec(10);
}
@@ -51,24 +55,19 @@ void TestFullTracePipeline() {
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) {
if (size >= offset + 16) {
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) {
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 + 8]);
uint32 recVal = *(uint32*)(&buffer[offset + 16]);
printf("Value=%u\n", recVal);
}
}
@@ -79,8 +78,3 @@ void TestFullTracePipeline() {
listener.Close();
}
int main() {
TestFullTracePipeline();
return 0;
}

View File

@@ -0,0 +1,176 @@
#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 }"
" }"
" OutputSignals = {"
" Counter = { DataSource = DDB Type = uint32 }"
" }"
" }"
" }"
" +Data = {"
" Class = ReferenceContainer "
" DefaultDataSource = DDB "
" +Timer = { Class = LinuxTimer SleepTime = 1000 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 }"
"}";
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();
}

View File

@@ -1,202 +1,161 @@
#include "BasicTCPSocket.h"
#include "BasicUDPSocket.h"
#include "DebugService.h"
#include "DebugCore.h"
#include "ObjectRegistryDatabase.h"
#include "RealTimeApplication.h"
#include "StandardParser.h"
#include "StreamString.h"
#include "BasicUDPSocket.h"
#include "BasicTCPSocket.h"
#include "RealTimeApplication.h"
#include "GlobalObjectsDatabase.h"
#include <assert.h>
#include <stdio.h>
using namespace MARTe;
const char8 * const config_text =
"+DebugService = {"
const char8 * const validation_config =
"DebugService = {"
" Class = DebugService "
" ControlPort = 8080 "
" UdpPort = 8081 "
" ControlPort = 8085 "
" UdpPort = 8086 "
" StreamIP = \"127.0.0.1\" "
"}"
"+App = {"
"App = {"
" Class = RealTimeApplication "
" +Functions = {"
" Class = ReferenceContainer "
" +GAM1 = {"
" Class = IOGAM "
" InputSignals = {"
" Counter = {"
" DataSource = Timer "
" Type = uint32 "
" }"
" Counter = { DataSource = Timer Type = uint32 Frequency = 1000 }"
" Time = { DataSource = Timer Type = uint32 }"
" }"
" OutputSignals = {"
" Counter = {"
" DataSource = DDB "
" Type = uint32 "
" }"
" Counter = { DataSource = DDB Type = uint32 }"
" Time = { 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 } }"
" }"
" +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 "
" +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");
printf("--- MARTe2 1kHz Lossless Trace Validation Test ---\n");
ObjectRegistryDatabase::Instance()->Purge();
// 1. Load Configuration
ConfigurationDatabase cdb;
StreamString ss = config_text;
StreamString ss = validation_config;
ss.Seek(0);
StandardParser parser(ss, cdb);
if (!parser.Parse()) {
printf("ERROR: Failed to parse configuration\n");
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;
}
if (!ObjectRegistryDatabase::Instance()->Initialise(cdb)) {
printf("ERROR: Failed to initialise ObjectRegistryDatabase.\n");
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;
}
// 2. Start Application
ReferenceT<RealTimeApplication> app = ObjectRegistryDatabase::Instance()->Find("App");
if (!app.IsValid()) {
printf("ERROR: App not found\n");
return;
}
assert(app->PrepareNextState("State1") == ErrorManagement::NoError);
assert(app->StartNextStateExecution() == ErrorManagement::NoError);
// 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");
printf("Application started at 1kHz. Enabling Traces...\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
if (service->TraceSignal("App.Data.Timer.Counter", true, 1) == 0) {
printf("ERROR: Failed to enable trace for App.Data.Timer.Counter\n");
}
// 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; }
listener.Open();
listener.Listen(8086);
// 5. Validate for 30 seconds
printf("Validating telemetry for 30 seconds...\n");
uint32 lastVal = 0;
bool first = true;
uint32 packetCount = 0;
uint32 discontinuityCount = 0;
printf("Validating for 10 seconds...\n");
uint32 totalPackets = 0;
uint32 totalSamples = 0;
uint32 discontinuities = 0;
uint32 lastValue = 0xFFFFFFFF;
float64 startTime = HighResolutionTimer::Counter() * HighResolutionTimer::Period();
while ((HighResolutionTimer::Counter() * HighResolutionTimer::Period() - startTime) < 30.0) {
uint64 start = HighResolutionTimer::Counter();
float64 elapsed = 0;
while (elapsed < 10.0) {
char buffer[2048];
uint32 size = 2048;
TimeoutType timeout(500);
if (listener.Read(buffer, size, timeout)) {
if (listener.Read(buffer, size, TimeoutType(100))) {
totalPackets++;
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);
}
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("Test Finished.\n");
printf("Total Packets Received: %u (Expected ~3000)\n", packetCount);
printf("Discontinuities: %u\n", discontinuityCount);
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);
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);
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!\n");
printf("VALIDATION SUCCESSFUL: 1kHz Lossless Tracing Verified.\n");
}
app->StopCurrentStateExecution();
listener.Close();
}
int main() {
RunValidationTest();
return 0;
}

View File

@@ -1,50 +0,0 @@
#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;
}

1
Test/Makefile.gcc Normal file
View File

@@ -0,0 +1 @@
include Makefile.inc

14
Test/Makefile.inc Normal file
View File

@@ -0,0 +1,14 @@
SPB = UnitTests.x Integration.x
PACKAGE = Test
ROOT_DIR = ..
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
all: $(SUBPROJ)
echo $(SUBPROJ)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)

View File

@@ -1,19 +0,0 @@
cmake_minimum_required(VERSION 3.10)
project(marte_dev_tests)
include_directories(
${MARTe2_DIR}/Source/Core/BareMetal/L0Types
${MARTe2_DIR}/Source/Core/BareMetal/L1Portability
# ... more ...
../../Source
../../Headers
)
file(GLOB SOURCES "*.cpp")
add_executable(UnitTests ${SOURCES})
target_link_libraries(UnitTests
marte_dev
${MARTe2_DIR}/Build/${TARGET}/Core/libMARTe2.so
)

View File

@@ -0,0 +1 @@
include Makefile.inc

View File

@@ -0,0 +1,39 @@
OBJSX =
PACKAGE = Test/UnitTests
ROOT_DIR = ../..
MAKEDEFAULTDIR=$(MARTe2_DIR)/MakeDefaults
include $(MAKEDEFAULTDIR)/MakeStdLibDefs.$(TARGET)
INCLUDES += -I$(ROOT_DIR)/Source/Core/Types/Result
INCLUDES += -I$(ROOT_DIR)/Source/Core/Types/Vec
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/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
LIBRARIES += -L$(MARTe2_DIR)/Build/$(TARGET)/Core -lMARTe2
LIBRARIES += -L$(ROOT_DIR)/Build/$(TARGET)/Components/Interfaces/DebugService -lDebugService
LIBRARIES += -L$(ROOT_DIR)/Build/$(TARGET)/Components/Interfaces/TCPLogger -lTcpLogger
all: $(OBJS) $(BUILD_DIR)/UnitTests$(EXEEXT)
echo $(OBJS)
include $(MAKEDEFAULTDIR)/MakeStdLibRules.$(TARGET)

View File

@@ -0,0 +1,93 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#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<uint32> indices;
Vec<uint32> 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 <signal.h>
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;
}

View File

@@ -1,35 +0,0 @@
#include <stdio.h>
#include <assert.h>
#include "DebugCore.h"
using namespace MARTe;
void TestRingBuffer() {
printf("Testing TraceRingBuffer...\n");
TraceRingBuffer rb;
assert(rb.Init(1024));
uint32 id = 42;
uint32 val = 12345678;
uint32 size = 4;
assert(rb.Push(id, &val, size));
assert(rb.Count() > 0);
uint32 poppedId = 0;
uint32 poppedVal = 0;
uint32 poppedSize = 0;
assert(rb.Pop(poppedId, &poppedVal, poppedSize, 4));
assert(poppedId == 42);
assert(poppedVal == 12345678);
assert(poppedSize == 4);
printf("TraceRingBuffer test passed.\n");
}
int main(int argc, char **argv) {
printf("Running MARTe2 Component Tests...\n");
TestRingBuffer();
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -5,12 +5,14 @@ edition = "2021"
[dependencies]
eframe = "0.31.0"
egui = "0.31.0"
egui_plot = "0.31.0"
tokio = { version = "1.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
byteorder = "1.4"
chrono = "0.4"
crossbeam-channel = "0.5"
regex = "1.12.3"
regex = "1.10"
socket2 = { version = "0.5", features = ["all"] }
once_cell = "1.21"
rfd = "0.15"
parquet = { version = "53.0", features = ["arrow"] }
arrow = "53.0"

File diff suppressed because it is too large Load Diff

View File

@@ -1,180 +1,386 @@
[
{
"file": "CMakeCCompilerId.c",
"file": "TcpLogger.cpp",
"arguments": [
"cc",
"CMakeCCompilerId.c"
],
"directory": "/home/martino/Projects/marte_debug/Build/CMakeFiles/4.2.3/CompilerIdC"
},
{
"file": "CMakeCXXCompilerId.cpp",
"arguments": [
"c++",
"CMakeCXXCompilerId.cpp"
],
"directory": "/home/martino/Projects/marte_debug/Build/CMakeFiles/4.2.3/CompilerIdCXX"
},
{
"file": "/usr/share/cmake/Modules/CMakeCCompilerABI.c",
"arguments": [
"cc",
"-v",
"-o",
"CMakeFiles/cmTC_27c6b.dir/CMakeCCompilerABI.c.o",
"g++",
"-c",
"/usr/share/cmake/Modules/CMakeCCompilerABI.c"
],
"directory": "/home/martino/Projects/marte_debug/Build/CMakeFiles/CMakeScratch/TryCompile-0cxTtB",
"output": "CMakeFiles/cmTC_27c6b.dir/CMakeCCompilerABI.c.o"
},
{
"file": "/usr/share/cmake/Modules/CMakeCXXCompilerABI.cpp",
"arguments": [
"c++",
"-v",
"-o",
"CMakeFiles/cmTC_2b812.dir/CMakeCXXCompilerABI.cpp.o",
"-c",
"/usr/share/cmake/Modules/CMakeCXXCompilerABI.cpp"
],
"directory": "/home/martino/Projects/marte_debug/Build/CMakeFiles/CMakeScratch/TryCompile-JvDZsz",
"output": "CMakeFiles/cmTC_2b812.dir/CMakeCXXCompilerABI.cpp.o"
},
{
"file": "/home/martino/Projects/marte_debug/Source/DebugService.cpp",
"arguments": [
"c++",
"-DARCHITECTURE=x86_gcc",
"-DENVIRONMENT=Linux",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DUSE_PTHREAD",
"-Dmarte_dev_EXPORTS",
"-I.",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L0Types",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L2Objects",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Events",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5FILES",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L6App",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L3Services",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4LoggerService",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2-components/Source/Components/DataSources/EpicsDataSource",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2-components/Source/Components/DataSources/FileDataSource",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2-components/Source/Components/GAMs/IOGAM",
"-I/home/martino/Projects/marte_debug/Source",
"-I/home/martino/Projects/marte_debug/Headers",
"-pthread",
"-fPIC",
"-MD",
"-MT",
"CMakeFiles/marte_dev.dir/Source/DebugService.cpp.o",
"-MF",
"CMakeFiles/marte_dev.dir/Source/DebugService.cpp.o.d",
"-o",
"CMakeFiles/marte_dev.dir/Source/DebugService.cpp.o",
"-c",
"/home/martino/Projects/marte_debug/Source/DebugService.cpp"
],
"directory": "/home/martino/Projects/marte_debug/Build",
"output": "CMakeFiles/marte_dev.dir/Source/DebugService.cpp.o"
},
{
"file": "/home/martino/Projects/marte_debug/Test/UnitTests/main.cpp",
"arguments": [
"c++",
"-Wall",
"-std=c++98",
"-Werror",
"-Wno-invalid-offsetof",
"-Wno-unused-variable",
"-fno-strict-aliasing",
"-frtti",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DARCHITECTURE=x86_gcc",
"-DENVIRONMENT=Linux",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DUSE_PTHREAD",
"-pthread",
"-Wno-deprecated-declarations",
"-Wno-unused-value",
"-g",
"-ggdb",
"TcpLogger.cpp",
"-o",
"../../../..//Build/x86-linux/Components/Interfaces/TCPLogger/TcpLogger.o"
],
"directory": "/home/martino/Projects/marte_debug/Source/Components/Interfaces/TCPLogger",
"output": "../../../..//Build/x86-linux/Components/Interfaces/TCPLogger/TcpLogger.o"
},
{
"file": "DebugService.cpp",
"arguments": [
"g++",
"-c",
"-I../../../..//Source/Core/Types/Result",
"-I../../../..//Source/Core/Types/Vec",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L0Types",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L2Objects",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Events",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5FILES",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L6App",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L3Services",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4LoggerService",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2-components/Source/Components/DataSources/EpicsDataSource",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2-components/Source/Components/DataSources/FileDataSource",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2-components/Source/Components/GAMs/IOGAM",
"-I/home/martino/Projects/marte_debug/Source",
"-I/home/martino/Projects/marte_debug/Headers",
"-I/home/martino/Projects/marte_debug/Test/UnitTests/../../Source",
"-I/home/martino/Projects/marte_debug/Test/UnitTests/../../Headers",
"-pthread",
"-MD",
"-MT",
"Test/UnitTests/CMakeFiles/UnitTests.dir/main.cpp.o",
"-MF",
"CMakeFiles/UnitTests.dir/main.cpp.o.d",
"-o",
"CMakeFiles/UnitTests.dir/main.cpp.o",
"-c",
"/home/martino/Projects/marte_debug/Test/UnitTests/main.cpp"
],
"directory": "/home/martino/Projects/marte_debug/Build/Test/UnitTests",
"output": "CMakeFiles/UnitTests.dir/main.cpp.o"
},
{
"file": "/home/martino/Projects/marte_debug/Test/Integration/main.cpp",
"arguments": [
"c++",
"-fPIC",
"-Wall",
"-std=c++98",
"-Werror",
"-Wno-invalid-offsetof",
"-Wno-unused-variable",
"-fno-strict-aliasing",
"-frtti",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DARCHITECTURE=x86_gcc",
"-DENVIRONMENT=Linux",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DUSE_PTHREAD",
"-pthread",
"-Wno-deprecated-declarations",
"-Wno-unused-value",
"-g",
"-ggdb",
"DebugService.cpp",
"-o",
"../../../..//Build/x86-linux/Components/Interfaces/DebugService/DebugService.o"
],
"directory": "/home/martino/Projects/marte_debug/Source/Components/Interfaces/DebugService",
"output": "../../../..//Build/x86-linux/Components/Interfaces/DebugService/DebugService.o"
},
{
"file": "UnitTests.cpp",
"arguments": [
"g++",
"-c",
"-I../../Source/Core/Types/Result",
"-I../../Source/Core/Types/Vec",
"-I../../Source/Components/Interfaces/DebugService",
"-I../../Source/Components/Interfaces/TCPLogger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L0Types",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L2Objects",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Events",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5FILES",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L3Services",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4LoggerService",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L3Streams",
"-fPIC",
"-Wall",
"-std=c++98",
"-Werror",
"-Wno-invalid-offsetof",
"-Wno-unused-variable",
"-fno-strict-aliasing",
"-frtti",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DARCHITECTURE=x86_gcc",
"-DENVIRONMENT=Linux",
"-DUSE_PTHREAD",
"-pthread",
"-Wno-deprecated-declarations",
"-Wno-unused-value",
"-g",
"-ggdb",
"UnitTests.cpp",
"-o",
"../../Build/x86-linux/Test/UnitTests/UnitTests/UnitTests.o"
],
"directory": "/home/martino/Projects/marte_debug/Test/UnitTests",
"output": "../../Build/x86-linux/Test/UnitTests/UnitTests/UnitTests.o"
},
{
"file": "SchedulerTest.cpp",
"arguments": [
"g++",
"-c",
"-I../../Source/Core/Types/Result",
"-I../../Source/Core/Types/Vec",
"-I../../Source/Components/Interfaces/DebugService",
"-I../../Source/Components/Interfaces/TCPLogger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L0Types",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L2Objects",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L6App",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L3Services",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4LoggerService",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2-components/Source/Components/DataSources/EpicsDataSource",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2-components/Source/Components/DataSources/FileDataSource",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2-components/Source/Components/GAMs/IOGAM",
"-I/home/martino/Projects/marte_debug/Source",
"-I/home/martino/Projects/marte_debug/Headers",
"-fPIC",
"-Wall",
"-std=c++98",
"-Werror",
"-Wno-invalid-offsetof",
"-Wno-unused-variable",
"-fno-strict-aliasing",
"-frtti",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DARCHITECTURE=x86_gcc",
"-DENVIRONMENT=Linux",
"-DUSE_PTHREAD",
"-pthread",
"-MD",
"-MT",
"Test/Integration/CMakeFiles/IntegrationTest.dir/main.cpp.o",
"-MF",
"CMakeFiles/IntegrationTest.dir/main.cpp.o.d",
"-Wno-deprecated-declarations",
"-Wno-unused-value",
"-g",
"-ggdb",
"SchedulerTest.cpp",
"-o",
"CMakeFiles/IntegrationTest.dir/main.cpp.o",
"-c",
"/home/martino/Projects/marte_debug/Test/Integration/main.cpp"
"../../Build/x86-linux/Test/Integration/Integration/SchedulerTest.o"
],
"directory": "/home/martino/Projects/marte_debug/Build/Test/Integration",
"output": "CMakeFiles/IntegrationTest.dir/main.cpp.o"
"directory": "/home/martino/Projects/marte_debug/Test/Integration",
"output": "../../Build/x86-linux/Test/Integration/Integration/SchedulerTest.o"
},
{
"file": "TraceTest.cpp",
"arguments": [
"g++",
"-c",
"-I../../Source/Core/Types/Result",
"-I../../Source/Core/Types/Vec",
"-I../../Source/Components/Interfaces/DebugService",
"-I../../Source/Components/Interfaces/TCPLogger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L0Types",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L2Objects",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L6App",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L3Services",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4LoggerService",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L3Streams",
"-fPIC",
"-Wall",
"-std=c++98",
"-Werror",
"-Wno-invalid-offsetof",
"-Wno-unused-variable",
"-fno-strict-aliasing",
"-frtti",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DARCHITECTURE=x86_gcc",
"-DENVIRONMENT=Linux",
"-DUSE_PTHREAD",
"-pthread",
"-Wno-deprecated-declarations",
"-Wno-unused-value",
"-g",
"-ggdb",
"TraceTest.cpp",
"-o",
"../../Build/x86-linux/Test/Integration/Integration/TraceTest.o"
],
"directory": "/home/martino/Projects/marte_debug/Test/Integration",
"output": "../../Build/x86-linux/Test/Integration/Integration/TraceTest.o"
},
{
"file": "ValidationTest.cpp",
"arguments": [
"g++",
"-c",
"-I../../Source/Core/Types/Result",
"-I../../Source/Core/Types/Vec",
"-I../../Source/Components/Interfaces/DebugService",
"-I../../Source/Components/Interfaces/TCPLogger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L0Types",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L2Objects",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L6App",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L3Services",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4LoggerService",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L3Streams",
"-fPIC",
"-Wall",
"-std=c++98",
"-Werror",
"-Wno-invalid-offsetof",
"-Wno-unused-variable",
"-fno-strict-aliasing",
"-frtti",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DARCHITECTURE=x86_gcc",
"-DENVIRONMENT=Linux",
"-DUSE_PTHREAD",
"-pthread",
"-Wno-deprecated-declarations",
"-Wno-unused-value",
"-g",
"-ggdb",
"ValidationTest.cpp",
"-o",
"../../Build/x86-linux/Test/Integration/Integration/ValidationTest.o"
],
"directory": "/home/martino/Projects/marte_debug/Test/Integration",
"output": "../../Build/x86-linux/Test/Integration/Integration/ValidationTest.o"
},
{
"file": "ConfigCommandTest.cpp",
"arguments": [
"g++",
"-c",
"-I../../Source/Core/Types/Result",
"-I../../Source/Core/Types/Vec",
"-I../../Source/Components/Interfaces/DebugService",
"-I../../Source/Components/Interfaces/TCPLogger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L0Types",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L2Objects",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L6App",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L3Services",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4LoggerService",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L3Streams",
"-fPIC",
"-Wall",
"-std=c++98",
"-Werror",
"-Wno-invalid-offsetof",
"-Wno-unused-variable",
"-fno-strict-aliasing",
"-frtti",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DARCHITECTURE=x86_gcc",
"-DENVIRONMENT=Linux",
"-DUSE_PTHREAD",
"-pthread",
"-Wno-deprecated-declarations",
"-Wno-unused-value",
"-g",
"-ggdb",
"ConfigCommandTest.cpp",
"-o",
"../../Build/x86-linux/Test/Integration/Integration/ConfigCommandTest.o"
],
"directory": "/home/martino/Projects/marte_debug/Test/Integration",
"output": "../../Build/x86-linux/Test/Integration/Integration/ConfigCommandTest.o"
},
{
"file": "IntegrationTests.cpp",
"arguments": [
"g++",
"-c",
"-I../../Source/Core/Types/Result",
"-I../../Source/Core/Types/Vec",
"-I../../Source/Components/Interfaces/DebugService",
"-I../../Source/Components/Interfaces/TCPLogger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L0Types",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L2Objects",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L3Streams",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Logger",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L4Configuration",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/BareMetal/L6App",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L3Services",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4Messages",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L4LoggerService",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/Scheduler/L5GAMs",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L1Portability",
"-I/home/martino/Projects/marte_debug/dependency/MARTe2/Source/Core/FileSystem/L3Streams",
"-fPIC",
"-Wall",
"-std=c++98",
"-Werror",
"-Wno-invalid-offsetof",
"-Wno-unused-variable",
"-fno-strict-aliasing",
"-frtti",
"-DMARTe2_TEST_ENVIRONMENT=GTest",
"-DARCHITECTURE=x86_gcc",
"-DENVIRONMENT=Linux",
"-DUSE_PTHREAD",
"-pthread",
"-Wno-deprecated-declarations",
"-Wno-unused-value",
"-g",
"-ggdb",
"IntegrationTests.cpp",
"-o",
"../../Build/x86-linux/Test/Integration/Integration/IntegrationTests.o"
],
"directory": "/home/martino/Projects/marte_debug/Test/Integration",
"output": "../../Build/x86-linux/Test/Integration/Integration/IntegrationTests.o"
}
]

22
env.fish Normal file
View File

@@ -0,0 +1,22 @@
# Get the directory of this script
set -l DIR (dirname (realpath (status -f)))
set -gx MARTe2_DIR $DIR/dependency/MARTe2
set -gx MARTe2_Components_DIR $DIR/dependency/MARTe2-components
set -gx TARGET x86-linux
# Update LD_LIBRARY_PATH
if not set -q LD_LIBRARY_PATH
set -gx LD_LIBRARY_PATH ""
end
set -gx LD_LIBRARY_PATH "$LD_LIBRARY_PATH:$MARTe2_DIR/Build/$TARGET/Core"
set -gx LD_LIBRARY_PATH "$LD_LIBRARY_PATH:$MARTe2_Components_DIR/Build/$TARGET/Components"
set -gx LD_LIBRARY_PATH "$LD_LIBRARY_PATH:$DIR/Build/$TARGET/Components/Interfaces/DebugService"
set -gx LD_LIBRARY_PATH "$LD_LIBRARY_PATH:$DIR/Build/$TARGET/Components/Interfaces/TCPLogger"
set -gx LD_LIBRARY_PATH "$LD_LIBRARY_PATH:$MARTe2_Components_DIR/Build/$TARGET/Components/DataSources/LinuxTimer"
set -gx LD_LIBRARY_PATH "$LD_LIBRARY_PATH:$MARTe2_Components_DIR/Build/$TARGET/Components/DataSources/LoggerDataSource"
set -gx LD_LIBRARY_PATH "$LD_LIBRARY_PATH:$MARTe2_Components_DIR/Build/$TARGET/Components/GAMs/IOGAM"
echo "MARTe2 Environment Set (MARTe2_DIR=$MARTe2_DIR)"
echo "MARTe2 Components Environment Set (MARTe2_Components_DIR=$MARTe2_Components_DIR)"

5
env.sh
View File

@@ -7,5 +7,10 @@ export MARTe2_Components_DIR=$DIR/dependency/MARTe2-components
export TARGET=x86-linux
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MARTe2_DIR/Build/$TARGET/Core
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MARTe2_Components_DIR/Build/$TARGET/Components
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DIR/Build/$TARGET/Components/Interfaces/DebugService
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DIR/Build/$TARGET/Components/Interfaces/TCPLogger
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MARTe2_Components_DIR/Build/$TARGET/Components/DataSources/LinuxTimer
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MARTe2_Components_DIR/Build/$TARGET/Components/DataSources/LoggerDataSource
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MARTe2_Components_DIR/Build/$TARGET/Components/GAMs/IOGAM
echo "MARTe2 Environment Set (MARTe2_DIR=$MARTe2_DIR)"
echo "MARTe2 Components Environment Set (MARTe2_Components_DIR=$MARTe2_Components_DIR)"

40
run_debug_app.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
# run_debug_app.sh - Launch the MARTe2 Debugging Environment using standard MARTeApp.ex
# 1. Environment Setup
if [ -f "./env.sh" ]; then
source ./env.sh
else
echo "ERROR: env.sh not found. Ensure you are in the project root."
exit 1
fi
# 2. Paths
MARTE_EX="${MARTe2_DIR}/Build/${TARGET}/App/MARTeApp.ex"
DEBUG_LIB="$(pwd)/Build/libmarte_dev.so"
# Component library base search path
COMPONENTS_BUILD_DIR="${MARTe2_Components_DIR}/Build/${TARGET}/Components"
# DYNAMICALLY FIND ALL COMPONENT DIRS
# MARTe2 Loader needs the specific directories containing .so files in LD_LIBRARY_PATH
ALL_COMPONENT_DIRS=$(find "$COMPONENTS_BUILD_DIR" -type d)
for dir in $ALL_COMPONENT_DIRS; do
if ls "$dir"/*.so >/dev/null 2>&1; then
export LD_LIBRARY_PATH="$dir:$LD_LIBRARY_PATH"
fi
done
# Ensure our build dir and core dir are included
export LD_LIBRARY_PATH="$(pwd)/Build:${MARTe2_DIR}/Build/${TARGET}/Core:${LD_LIBRARY_PATH}"
# 3. Cleanup
echo "Cleaning up lingering processes..."
pkill -9 MARTeApp.ex
sleep 1
# 4. Launch Application
echo "Launching standard MARTeApp.ex with debug_test.cfg..."
# PRELOAD ensures our DebugService class is available to the registry early
export LD_PRELOAD="${DEBUG_LIB}"
"$MARTE_EX" -f Test/Configurations/debug_test.cfg -l RealTimeLoader -s State1

View File

@@ -1,21 +1,16 @@
#!/bin/bash
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# Get the directory of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $DIR/env.sh
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
export MARTe2_DIR=/home/martino/Projects/marte_debug/dependency/MARTe2
export TARGET=x86-linux
echo "Cleaning up old instances..."
pkill -9 IntegrationTests
pkill -9 UnitTests
sleep 1
MARTE_APP=$MARTe2_DIR/Build/$TARGET/App/MARTeApp.ex
echo "Starting MARTe2 Unit Tests..."
$DIR/Build/$TARGET/Test/UnitTests/UnitTests/UnitTests.ex
# Build paths for all components
LIBS=$DIR/Build
LIBS=$LIBS:$MARTe2_DIR/Build/$TARGET/Core
LIBS=$LIBS:$MARTe2_Components_DIR/Build/$TARGET/Components/DataSources/LinuxTimer
LIBS=$LIBS:$MARTe2_Components_DIR/Build/$TARGET/Components/DataSources/LoggerDataSource
LIBS=$LIBS:$MARTe2_Components_DIR/Build/$TARGET/Components/GAMs/IOGAM
export LD_LIBRARY_PATH=$LIBS:$LD_LIBRARY_PATH
# ./Build/Test/Integration/IntegrationTest -f Test/Configurations/debug_test.cfg -l RealTimeLoader -s State1
$MARTE_APP -f $DIR/Test/Configurations/debug_test.cfg -l RealTimeLoader -s State1
echo ""
echo "Starting MARTe2 Integration Tests..."
$DIR/Build/$TARGET/Test/Integration/Integration/IntegrationTests.ex

View File

@@ -1,41 +0,0 @@
Project Specification: MARTe2 Universal Observability & Debugging Suite
Version: 1.1
Date: 2023-10-27
Status: Active / Implemented
1. Executive Summary
This project implements a "Zero-Code-Change" observability and debugging layer for the MARTe2 real-time framework. The system allows developers to Trace, Force, and Monitor any signal in a running MARTe2 application without modifying existing source code.
2. System Architecture
- The Universal Debug Service (C++ Core): A singleton MARTe2 Object that patches the registry and manages communication.
- The Broker Injection Layer (C++ Templates): Templated wrappers that intercept Copy() calls for tracing, forcing, and execution control.
- The Remote Analyser (Rust/egui): A high-performance, multi-threaded GUI for visualization and control.
3. Functional Requirements
3.1 Execution Control
- REQ-25: Execution Control (Pause/Resume): The system SHALL provide a mechanism to pause and resume the execution of all patched real-time threads (via Brokers), allowing for static inspection of the system state.
3.2 Discovery
- REQ-24: Tree Exploration: The GUI client SHALL request the full application tree upon connection and display it in a hierarchical tree view.
- TREE Command: Returns a recursive JSON structure representing the entire application tree, including signal metadata (Type, Dimensions, Elements).
3.3 Multi-Threaded Client (REQ-23)
- Port 8080 (TCP): Commands and Metadata.
- Port 8082 (TCP): Independent Real-Time Log Stream.
- Port 8081 (UDP): High-Speed Telemetry for Oscilloscope.
4. Communication Protocol
- LS [Path]: List nodes.
- TREE: Full recursive JSON application map.
- PAUSE / RESUME: Execution control.
- TRACE <Signal> <1/0> [Decimation]: Telemetry control.
- FORCE <Signal> <Value>: Persistent signal override.
- UNFORCE <Signal>: Remove override.
- LOG <Level> <Msg>: Port 8082 streaming format.

52
test_gui_sim.py Normal file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/env python3
import socket
import time
import subprocess
import os
import signal
# Start server
print("Starting server...")
proc = subprocess.Popen(
["./run_debug_app.sh"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd="/home/martino/Projects/marte_debug",
env=os.environ,
)
time.sleep(5) # Wait for server to start
print("Connecting to server...")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(3)
s.connect(("127.0.0.1", 8080))
# Send TREE
s.sendall(b"TREE\n")
print("Sent TREE")
# Send DISCOVER immediately (like GUI does)
s.sendall(b"DISCOVER\n")
print("Sent DISCOVER")
# Wait and read
time.sleep(1)
data = b""
while True:
try:
chunk = s.recv(4096)
if not chunk:
break
data += chunk
except:
break
print(f"Got {len(data)} bytes")
print("Contains OK TREE:", b"OK TREE" in data)
print("Contains OK DISCOVER:", b"OK DISCOVER" in data)
s.close()
proc.terminate()
proc.wait()
print("Done")