Optimised failed test
This commit is contained in:
109
Test/Integration/BrokerExecuteTest.cpp
Normal file
109
Test/Integration/BrokerExecuteTest.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "DebugService.h"
|
||||
#include "DebugBrokerWrapper.h"
|
||||
#include "MemoryMapInputBroker.h"
|
||||
#include "ObjectRegistryDatabase.h"
|
||||
#include "StandardParser.h"
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
using namespace MARTe;
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
class ManualDebugMemoryMapInputBroker : public DebugMemoryMapInputBroker {
|
||||
public:
|
||||
virtual bool Execute() {
|
||||
if (infoPtr) DebugBrokerHelper::Process(service, *infoPtr);
|
||||
return true;
|
||||
}
|
||||
using MemoryMapBroker::copyTable;
|
||||
};
|
||||
|
||||
class MockDS : public DataSourceI {
|
||||
public:
|
||||
CLASS_REGISTER_DECLARATION()
|
||||
MockDS() { SetName("MockDS"); }
|
||||
virtual bool AllocateMemory() { return true; }
|
||||
virtual uint32 GetNumberOfMemoryBuffers() { return 1; }
|
||||
virtual bool GetSignalMemoryBuffer(const uint32 signalIdx, const uint32 bufferIdx, void *&signalAddress) {
|
||||
static uint32 val = 0;
|
||||
signalAddress = &val;
|
||||
return true;
|
||||
}
|
||||
virtual const char8 *GetBrokerName(StructuredDataI &data, const SignalDirection direction) { return "MemoryMapInputBroker"; }
|
||||
virtual bool GetInputBrokers(ReferenceContainer &inputBrokers, const char8 *const functionName, void *const gamMem) { return true; }
|
||||
virtual bool GetOutputBrokers(ReferenceContainer &outputBrokers, const char8 *const functionName, void *const gamMem) { return true; }
|
||||
virtual bool PrepareNextState(const char8 *const currentStateName, const char8 *const nextStateName) { return true; }
|
||||
virtual bool Synchronise() { return true; }
|
||||
};
|
||||
CLASS_REGISTER(MockDS, "1.0")
|
||||
|
||||
void RunTest() {
|
||||
printf("--- Broker Execute Path Test (Isolated) ---\n");
|
||||
|
||||
DebugService* service = new DebugService();
|
||||
service->traceBuffer.Init(1024 * 1024);
|
||||
ConfigurationDatabase cfg;
|
||||
cfg.Write("ControlPort", (uint32)0);
|
||||
cfg.Write("StreamPort", (uint32)0);
|
||||
assert(service->Initialise(cfg));
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Insert(Reference(service));
|
||||
|
||||
MockDS ds;
|
||||
uint32 gamMem = 42;
|
||||
|
||||
ManualDebugMemoryMapInputBroker* broker = new ManualDebugMemoryMapInputBroker();
|
||||
broker->service = service;
|
||||
|
||||
printf("Manually bootstrapping Broker for testing...\n");
|
||||
broker->copyTable = new MemoryMapBrokerCopyTableEntry[1];
|
||||
broker->copyTable[0].copySize = 4;
|
||||
broker->copyTable[0].dataSourcePointer = &gamMem;
|
||||
broker->copyTable[0].gamPointer = &gamMem;
|
||||
broker->copyTable[0].type = UnsignedInteger32Bit;
|
||||
|
||||
DebugSignalInfo** sigPtrs = NULL;
|
||||
DebugBrokerHelper::InitSignals(NULL_PTR(BrokerI*), ds, service, sigPtrs, 1, broker->copyTable, "TestGAM", InputSignals, &broker->anyActive);
|
||||
broker->infoPtr = &service->brokers[service->numberOfBrokers - 1];
|
||||
|
||||
printf("Broker ready. Registered signals in service: %u\n", service->numberOfSignals);
|
||||
|
||||
printf("Executing IDLE cycle...\n");
|
||||
broker->Execute();
|
||||
assert(service->traceBuffer.Count() == 0);
|
||||
|
||||
printf("Manually enabling TRACE for first signal...\n");
|
||||
// Directly enable tracing on the signal info to bypass name matching
|
||||
service->signals[0].isTracing = true;
|
||||
service->signals[0].decimationFactor = 1;
|
||||
service->signals[0].decimationCounter = 0;
|
||||
|
||||
printf("Updating brokers active status...\n");
|
||||
service->UpdateBrokersActiveStatus();
|
||||
assert(broker->anyActive == true);
|
||||
|
||||
printf("Executing TRACE cycle...\n");
|
||||
broker->Execute();
|
||||
|
||||
uint32 rbCount = service->traceBuffer.Count();
|
||||
printf("Trace Buffer Count: %u\n", rbCount);
|
||||
|
||||
if (rbCount > 0) {
|
||||
printf("SUCCESS: Data reached Trace Buffer via Broker!\n");
|
||||
uint32 rid, rsize; uint64 rts; uint32 rval;
|
||||
assert(service->traceBuffer.Pop(rid, rts, &rval, rsize, 4));
|
||||
printf("Value popped: %u (ID=%u, TS=%lu)\n", rval, rid, rts);
|
||||
assert(rval == 42);
|
||||
} else {
|
||||
printf("FAILURE: Trace Buffer is still empty.\n");
|
||||
}
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MARTe::RunTest();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user