Files
MARTe-Integrated-Components/Test/Components/DataSources/UDPStreamerClient/UDPStreamerClientTest.h
T
Martino FerrariandClaude Sonnet 4.6 14d5351a81 fix: UDPSClient uses two-arg Join so multicast receiver lands on the right interface
UDPSClient::ConnectMulticast was calling the single-arg BasicUDPSocket::Join,
which forwards NULL as the local interface and lets the kernel bind to
INADDR_ANY.  On a multi-homed host (or when the server sends on loopback via
Interface = "127.0.0.1") the client joins the wrong interface and silently
receives nothing.

Fix: read the optional Interface key inside the useMulticast block in
UDPSClient::Initialise; in ConnectMulticast call the two-arg
Join(group, interface) when Interface is set, and fall back to the one-arg
call otherwise to preserve the existing INADDR_ANY behaviour for configs that
omit it.

Forward the new optional Interface key through UDPStreamerClient (read from
DataSource config, written into the UDPSClient ConfigurationDatabase only
when non-empty).  Extend the "Joined multicast group" log to report the
interface name or "default".

Regression test TestExecute_MulticastReceivesDataOnInterface: mock TCP
control listener + multicast UDP DATA socket with IP_MULTICAST_IF set to
127.0.0.1, verifying a uint32 value of 424242 reaches DataSource signal
memory.  Confirmed FAILED without the Join fix and PASSED with it.

Suite: 133/133 (was 132/132 before this commit).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-08-17 08:23:41 +02:00

172 lines
5.8 KiB
C++

/**
* @file UDPStreamerClientTest.h
* @brief Header file for class UDPStreamerClientTest
* @date 01/07/2026
* @author Martino Ferrari
*
* @copyright 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
*
* @warning 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 permissions and limitations under the Licence.
*
* @details This header file contains the declaration of the class UDPStreamerClientTest
* with all of its public, protected and private members. It may also include
* definitions for inline methods which need to be visible to the compiler.
*/
#ifndef UDPSTREAMERCLIENTTEST_H_
#define UDPSTREAMERCLIENTTEST_H_
/*---------------------------------------------------------------------------*/
/* Standard header includes */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Project header includes */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Class declaration */
/*---------------------------------------------------------------------------*/
/**
* @brief Tests the UDPStreamerClient DataSource public methods.
*/
class UDPStreamerClientTest {
public:
/**
* @brief Tests Initialise with a fully valid unicast configuration.
*/
bool TestInitialise_Valid();
/**
* @brief Tests that a missing ServerAddress uses the default (127.0.0.1).
*/
bool TestInitialise_DefaultServerAddress();
/**
* @brief Tests that a missing Port uses the default (44500).
*/
bool TestInitialise_DefaultPort();
/**
* @brief Tests Initialise with MulticastGroup and an explicit DataPort.
*/
bool TestInitialise_MulticastMode_Valid();
/**
* @brief Tests Initialise with a sub-second float32 SilenceTimeout (0.25 s)
* forwarded through to the UDPSClient receiver.
*/
bool TestInitialise_SilenceTimeoutFloat();
/**
* @brief Tests that DataPort defaults to Port+1 when MulticastGroup is
* set but DataPort is absent.
*/
bool TestInitialise_MulticastMode_DefaultDataPort();
/**
* @brief Tests SetConfiguredDatabase / AllocateMemory with several
* signals of different types and array sizes.
*/
bool TestSetConfiguredDatabase_MultipleSignals();
/**
* @brief Tests PrepareNextState starts the background receiver thread.
*/
bool TestPrepareNextState_StartsReceiver();
/**
* @brief Tests that Synchronise() with no data received is a safe no-op.
*/
bool TestSynchronise_NoData();
/**
* @brief Tests the full OnUDPSConfig -> OnUDPSData -> Synchronise path
* for a single unquantised scalar signal.
*/
bool TestOnUDPSConfig_BasicAccept();
/**
* @brief Tests that a CONFIG with a different signal count is rejected.
*/
bool TestOnUDPSConfig_SignalCountMismatch();
/**
* @brief Tests that a CONFIG with a mismatched signal name is rejected.
*/
bool TestOnUDPSConfig_NameMismatch();
/**
* @brief Tests that a CONFIG with a mismatched element count is rejected.
*/
bool TestOnUDPSConfig_ElementCountMismatch();
/**
* @brief Tests that an undersized CONFIG payload is safely rejected.
*/
bool TestOnUDPSConfig_TooSmallPayload();
/**
* @brief Tests UINT16 dequantisation into a Float32Bit destination signal.
*/
bool TestOnUDPSData_QuantizedUint16();
/**
* @brief Tests INT8 dequantisation formula into a Float64Bit destination signal.
*/
bool TestOnUDPSData_QuantizedInt8();
/**
* @brief Tests that multiple signals decode into the correct buffer offsets.
*/
bool TestOnUDPSData_MultipleSignalsOrder();
/**
* @brief Tests Accumulate publishing mode: scalar signals publish only the
* most recent sample, array signals publish once regardless of numSamples.
*/
bool TestOnUDPSData_AccumulateMode();
/**
* @brief Tests that an undersized DATA payload (missing timestamp) is a safe no-op.
*/
bool TestOnUDPSData_TooSmallPayload();
/**
* @brief Tests that OnUDPSData before a valid CONFIG is a safe no-op.
*/
bool TestOnUDPSData_BeforeConfig();
/**
* @brief Tests that OnUDPSDisconnected() invalidates the CONFIG so
* subsequent DATA payloads are ignored until a new CONFIG arrives.
*/
bool TestOnUDPSDisconnected_InvalidatesConfig();
/**
* @brief Tests the full CONNECT -> CONFIG -> DATA flow over real loopback
* UDP sockets, mirroring the server side of the wire protocol.
*/
bool TestExecute_ConnectConfigDataEndToEnd();
/**
* @brief Regression test: verifies that UDPStreamerClient receives multicast
* DATA when Interface is set to "127.0.0.1", ensuring the two-argument
* Join(group, interface) path in UDPSClient::ConnectMulticast is taken.
* This test fails without the UDPSClient multicastInterface fix.
*/
bool TestExecute_MulticastReceivesDataOnInterface();
};
#endif /* UDPSTREAMERCLIENTTEST_H_ */