Optimised failed test

This commit is contained in:
Martino Ferrari
2026-02-25 21:07:27 +01:00
parent dfb399bbba
commit f8f04856ed
17 changed files with 1842 additions and 557 deletions

View File

@@ -9,6 +9,7 @@
#include "Vector.h"
#include "FastPollingMutexSem.h"
#include "HighResolutionTimer.h"
#include "Atomic.h"
// Original broker headers
#include "MemoryMapInputBroker.h"
@@ -30,42 +31,37 @@ namespace MARTe {
*/
class DebugBrokerHelper {
public:
static void Process(DebugService* service, DebugSignalInfo** signalInfoPointers, Vector<uint32>& activeIndices, Vector<uint32>& activeSizes, FastPollingMutexSem& activeMutex) {
static void Process(DebugService* service, BrokerInfo& info) {
if (service == NULL_PTR(DebugService*)) return;
// Re-establish break logic
while (service->IsPaused()) {
Sleep::MSec(10);
}
activeMutex.FastLock();
uint32 n = activeIndices.GetNumberOfElements();
if (n > 0 && signalInfoPointers != NULL_PTR(DebugSignalInfo**)) {
// Capture timestamp ONCE per broker cycle for lowest impact
if (*info.anyActiveFlag) {
uint32 idx = info.currentSetIdx;
BrokerActiveSet& set = info.sets[idx];
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];
service->ProcessSignal(s, size, ts);
for (uint32 i = 0; i < set.numForced; i++) {
SignalExecuteInfo& s = set.forcedSignals[i];
DebugService::CopySignal(s.memoryAddress, s.forcedValue, s.size);
}
for (uint32 i = 0; i < set.numTraced; i++) {
SignalExecuteInfo& s = set.tracedSignals[i];
(void)service->traceBuffer.Push(s.internalID, ts, s.memoryAddress, s.size);
}
}
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, Vector<uint32>* activeIndices, Vector<uint32>* activeSizes, FastPollingMutexSem* activeMutex) {
static void InitSignals(BrokerI* broker, DataSourceI &dataSourceIn, DebugService* &service, DebugSignalInfo** &signalInfoPointers, uint32 numCopies, MemoryMapBrokerCopyTableEntry* copyTable, const char8* functionName, SignalDirection direction, volatile bool* anyActiveFlag) {
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 == NULL_PTR(DebugService*)) service = DebugService::Instance();
if (service && (copyTable != NULL_PTR(MemoryMapBrokerCopyTableEntry*))) {
StreamString dsPath;
@@ -75,21 +71,19 @@ public:
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);
}
if (mmb != NULL_PTR(MemoryMapBroker*)) dsIdx = mmb->GetDSCopySignalIndex(i);
StreamString signalName;
if (!dataSourceIn.GetSignalName(dsIdx, signalName)) signalName = "Unknown";
if (!dataSourceIn.GetSignalName(dsIdx, signalName)) {
signalName.Printf("Signal_%u", dsIdx);
}
// Register canonical name
StreamString dsFullName;
dsFullName.Printf("%s.%s", dsPath.Buffer(), signalName.Buffer());
StreamString dsFullName = dsPath;
if (dsFullName.Size() > 0) dsFullName += ".";
dsFullName += signalName;
service->RegisterSignal(addr, type, dsFullName.Buffer());
// Register alias
if (functionName != NULL_PTR(const char8*)) {
StreamString gamFullName;
const char8* dirStr = (direction == InputSignals) ? "In" : "Out";
@@ -97,207 +91,147 @@ public:
if (gamRef.IsValid()) {
StreamString absGamPath;
DebugService::GetFullObjectName(*(gamRef.operator->()), absGamPath);
gamFullName.Printf("%s.%s.%s", absGamPath.Buffer(), dirStr, signalName.Buffer());
gamFullName = absGamPath;
} else {
gamFullName.Printf("%s.%s.%s", functionName, dirStr, signalName.Buffer());
gamFullName = functionName;
}
gamFullName += ".";
gamFullName += dirStr;
gamFullName += ".";
gamFullName += signalName;
signalInfoPointers[i] = service->RegisterSignal(addr, type, gamFullName.Buffer());
} else {
signalInfoPointers[i] = service->RegisterSignal(addr, type, dsFullName.Buffer());
}
}
// Register broker in DebugService for optimized control
service->RegisterBroker(signalInfoPointers, numCopies, mmb, anyActiveFlag, activeIndices, activeSizes, activeMutex);
service->RegisterBroker(signalInfoPointers, numCopies, mmb, anyActiveFlag);
}
}
};
/**
* @brief Template class to instrument any MARTe2 Broker.
*/
template <typename BaseClass>
class DebugBrokerWrapper : public BaseClass {
class DebugMemoryMapInputBroker : public MemoryMapInputBroker, public DebugBrokerI {
public:
DebugBrokerWrapper() : BaseClass() {
service = NULL_PTR(DebugService*);
signalInfoPointers = NULL_PTR(DebugSignalInfo**);
numSignals = 0;
anyActive = false;
DebugMemoryMapInputBroker() : MemoryMapInputBroker(), service(NULL), infoPtr(NULL), anyActive(false) {
(void)ObjectRegistryDatabase::Instance()->Insert(Reference(this));
}
virtual ~DebugBrokerWrapper() {
if (signalInfoPointers) delete[] signalInfoPointers;
}
virtual void SetService(DebugService* s) { service = s; }
virtual bool IsLinked() const { return infoPtr != NULL; }
virtual bool Execute() {
bool ret = BaseClass::Execute();
if (ret && (anyActive || (service && service->IsPaused()))) {
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices, activeSizes, activeMutex);
}
bool ret = MemoryMapInputBroker::Execute();
if (ret && infoPtr) DebugBrokerHelper::Process(service, *infoPtr);
return ret;
}
virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem) {
bool ret = BaseClass::Init(direction, ds, name, gamMem);
bool ret = MemoryMapInputBroker::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);
DebugSignalInfo** sigPtrs = NULL;
DebugBrokerHelper::InitSignals(this, ds, service, sigPtrs, GetNumberOfCopies(), this->copyTable, name, direction, &anyActive);
if (service) infoPtr = service->GetBrokerInfo(service->numberOfBrokers - 1);
}
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) {
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;
DebugService* service;
BrokerInfo* infoPtr;
volatile bool anyActive;
Vector<uint32> activeIndices;
Vector<uint32> activeSizes;
FastPollingMutexSem activeMutex;
};
template <typename BaseClass>
class DebugBrokerWrapperNoOptim : public BaseClass {
template <typename T>
class DebugGenericBroker : public T, public DebugBrokerI {
public:
DebugBrokerWrapperNoOptim() : BaseClass() {
service = NULL_PTR(DebugService*);
signalInfoPointers = NULL_PTR(DebugSignalInfo**);
numSignals = 0;
anyActive = false;
DebugGenericBroker() : T(), service(NULL), infoPtr(NULL), anyActive(false) {
(void)ObjectRegistryDatabase::Instance()->Insert(Reference(this));
}
virtual ~DebugBrokerWrapperNoOptim() {
if (signalInfoPointers) delete[] signalInfoPointers;
}
virtual void SetService(DebugService* s) { service = s; }
virtual bool IsLinked() const { return infoPtr != NULL; }
virtual bool Execute() {
bool ret = BaseClass::Execute();
if (ret && (anyActive || (service && service->IsPaused()))) {
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices, activeSizes, activeMutex);
}
bool ret = T::Execute();
if (ret && infoPtr) DebugBrokerHelper::Process(service, *infoPtr);
return ret;
}
virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem) {
bool ret = BaseClass::Init(direction, ds, name, gamMem);
bool ret = T::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);
DebugSignalInfo** sigPtrs = NULL;
DebugBrokerHelper::InitSignals(this, ds, service, sigPtrs, this->GetNumberOfCopies(), this->copyTable, name, direction, &anyActive);
if (service) infoPtr = service->GetBrokerInfo(service->numberOfBrokers - 1);
}
return ret;
}
DebugService *service;
DebugSignalInfo **signalInfoPointers;
uint32 numSignals;
DebugService* service;
BrokerInfo* infoPtr;
volatile bool anyActive;
Vector<uint32> activeIndices;
Vector<uint32> activeSizes;
FastPollingMutexSem activeMutex;
};
class DebugMemoryMapAsyncOutputBroker : public MemoryMapAsyncOutputBroker {
class DebugMemoryMapAsyncOutputBroker : public MemoryMapAsyncOutputBroker, public DebugBrokerI {
public:
DebugMemoryMapAsyncOutputBroker() : MemoryMapAsyncOutputBroker() {
service = NULL_PTR(DebugService*);
signalInfoPointers = NULL_PTR(DebugSignalInfo**);
numSignals = 0;
anyActive = false;
}
virtual ~DebugMemoryMapAsyncOutputBroker() {
if (signalInfoPointers) delete[] signalInfoPointers;
DebugMemoryMapAsyncOutputBroker() : MemoryMapAsyncOutputBroker(), service(NULL), infoPtr(NULL), anyActive(false) {
(void)ObjectRegistryDatabase::Instance()->Insert(Reference(this));
}
virtual void SetService(DebugService* s) { service = s; }
virtual bool IsLinked() const { return infoPtr != NULL; }
virtual bool Execute() {
bool ret = MemoryMapAsyncOutputBroker::Execute();
if (ret && (anyActive || (service && service->IsPaused()))) {
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices, activeSizes, activeMutex);
}
if (ret && infoPtr) DebugBrokerHelper::Process(service, *infoPtr);
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);
virtual bool InitWithBufferParameters(const SignalDirection d, DataSourceI &ds, const char8* n, void* m, const uint32 nb, const ProcessorType& c, const uint32 s) {
bool ret = MemoryMapAsyncOutputBroker::InitWithBufferParameters(d, ds, n, m, nb, c, s);
if (ret) {
numSignals = this->GetNumberOfCopies();
DebugBrokerHelper::InitSignals(this, dataSourceIn, service, signalInfoPointers, numSignals, this->copyTable, functionName, direction, &anyActive, &activeIndices, &activeSizes, &activeMutex);
DebugSignalInfo** sigPtrs = NULL;
DebugBrokerHelper::InitSignals(this, ds, service, sigPtrs, this->GetNumberOfCopies(), this->copyTable, n, d, &anyActive);
if (service) infoPtr = service->GetBrokerInfo(service->numberOfBrokers - 1);
}
return ret;
}
DebugService *service;
DebugSignalInfo **signalInfoPointers;
uint32 numSignals;
DebugService* service;
BrokerInfo* infoPtr;
volatile bool anyActive;
Vector<uint32> activeIndices;
Vector<uint32> activeSizes;
FastPollingMutexSem activeMutex;
};
class DebugMemoryMapAsyncTriggerOutputBroker : public MemoryMapAsyncTriggerOutputBroker {
class DebugMemoryMapAsyncTriggerOutputBroker : public MemoryMapAsyncTriggerOutputBroker, public DebugBrokerI {
public:
DebugMemoryMapAsyncTriggerOutputBroker() : MemoryMapAsyncTriggerOutputBroker() {
service = NULL_PTR(DebugService*);
signalInfoPointers = NULL_PTR(DebugSignalInfo**);
numSignals = 0;
anyActive = false;
}
virtual ~DebugMemoryMapAsyncTriggerOutputBroker() {
if (signalInfoPointers) delete[] signalInfoPointers;
DebugMemoryMapAsyncTriggerOutputBroker() : MemoryMapAsyncTriggerOutputBroker(), service(NULL), infoPtr(NULL), anyActive(false) {
(void)ObjectRegistryDatabase::Instance()->Insert(Reference(this));
}
virtual void SetService(DebugService* s) { service = s; }
virtual bool IsLinked() const { return infoPtr != NULL; }
virtual bool Execute() {
bool ret = MemoryMapAsyncTriggerOutputBroker::Execute();
if (ret && (anyActive || (service && service->IsPaused()))) {
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices, activeSizes, activeMutex);
}
if (ret && infoPtr) DebugBrokerHelper::Process(service, *infoPtr);
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);
virtual bool InitWithTriggerParameters(const SignalDirection d, DataSourceI &ds, const char8* n, void* m, const uint32 nb, const uint32 pre, const uint32 post, const ProcessorType& c, const uint32 s) {
bool ret = MemoryMapAsyncTriggerOutputBroker::InitWithTriggerParameters(d, ds, n, m, nb, pre, post, c, s);
if (ret) {
numSignals = this->GetNumberOfCopies();
DebugBrokerHelper::InitSignals(this, dataSourceIn, service, signalInfoPointers, numSignals, this->copyTable, functionName, direction, &anyActive, &activeIndices, &activeSizes, &activeMutex);
DebugSignalInfo** sigPtrs = NULL;
DebugBrokerHelper::InitSignals(this, ds, service, sigPtrs, this->GetNumberOfCopies(), this->copyTable, n, d, &anyActive);
if (service) infoPtr = service->GetBrokerInfo(service->numberOfBrokers - 1);
}
return ret;
}
DebugService *service;
DebugSignalInfo **signalInfoPointers;
uint32 numSignals;
DebugService* service;
BrokerInfo* infoPtr;
volatile bool anyActive;
Vector<uint32> activeIndices;
Vector<uint32> activeSizes;
FastPollingMutexSem activeMutex;
};
typedef DebugGenericBroker<MemoryMapOutputBroker> DebugMemoryMapOutputBroker;
typedef DebugGenericBroker<MemoryMapSynchronisedInputBroker> DebugMemoryMapSynchronisedInputBroker;
typedef DebugGenericBroker<MemoryMapSynchronisedOutputBroker> DebugMemoryMapSynchronisedOutputBroker;
typedef DebugGenericBroker<MemoryMapInterpolatedInputBroker> DebugMemoryMapInterpolatedInputBroker;
typedef DebugGenericBroker<MemoryMapMultiBufferInputBroker> DebugMemoryMapMultiBufferInputBroker;
typedef DebugGenericBroker<MemoryMapMultiBufferOutputBroker> DebugMemoryMapMultiBufferOutputBroker;
typedef DebugGenericBroker<MemoryMapSynchronisedMultiBufferInputBroker> DebugMemoryMapSynchronisedMultiBufferInputBroker;
typedef DebugGenericBroker<MemoryMapSynchronisedMultiBufferOutputBroker> DebugMemoryMapSynchronisedMultiBufferOutputBroker;
template <typename T>
class DebugBrokerBuilder : public ObjectBuilder {
public:
virtual Object *Build(HeapI* const heap) const { return new (heap) T(); }
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;
@@ -308,7 +242,6 @@ typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedMultiBufferInputBroker> Deb
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedMultiBufferOutputBroker> DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapAsyncOutputBroker> DebugMemoryMapAsyncOutputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapAsyncTriggerOutputBroker> DebugMemoryMapAsyncTriggerOutputBrokerBuilder;
// LCOV_EXCL_STOP
}