Implemented full e2e testing

This commit is contained in:
Martino Ferrari
2026-07-02 10:10:57 +02:00
parent f8c79131c9
commit f2042d624b
35 changed files with 2419 additions and 78 deletions
+42
View File
@@ -1,7 +1,10 @@
#include "TestCommon.h"
#include "BasicTCPSocket.h"
#include "HighResolutionTimer.h"
#include "StringHelper.h"
#include "TimeoutType.h"
#include "UDPSProtocol.h"
#include <sys/socket.h>
namespace MARTe {
@@ -71,4 +74,43 @@ bool SendCommandGAM(uint16 port, const char8* cmd, StreamString &reply) {
return false;
}
bool ReadUDPSTraceScalar(BasicUDPSocket &sock, uint32 overallTimeoutMs, uint32 &value) {
uint64 start = HighResolutionTimer::Counter();
float64 budgetS = (float64)overallTimeoutMs / 1000.0;
uint32 quantumMs = (overallTimeoutMs < 50u) ? overallTimeoutMs : 50u;
if (quantumMs == 0u) quantumMs = 1u;
for (;;) {
float64 elapsed = (float64)(HighResolutionTimer::Counter() - start) * HighResolutionTimer::Period();
if (elapsed >= budgetS) break;
char buffer[2048];
uint32 size = 2048;
TimeoutType timeout(quantumMs);
if (sock.Read(buffer, size, timeout)) {
if (size >= UDPS_HEADER_SIZE) {
UDPSPacketHeader hdr;
memcpy(&hdr, buffer, UDPS_HEADER_SIZE);
if (hdr.magic == UDPS_MAGIC && hdr.type == UDPS_TYPE_DATA) {
uint32 off = UDPS_HEADER_SIZE + 8u; // skip 8-byte HRT timestamp
if (size >= off + sizeof(uint32)) {
memcpy(&value, buffer + off, sizeof(uint32));
return true;
}
}
}
// CONFIG packet, undersized datagram, or bad magic — keep polling.
}
}
return false;
}
void GrowUDPRecvBuffer(BasicUDPSocket &sock, uint32 bytes) {
Handle fd = sock.GetReadHandle();
if (fd >= 0) {
int32 sz = static_cast<int32>(bytes);
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz));
}
}
}