From c827ecefff786f20b56361e0e1a72f70065b37c9 Mon Sep 17 00:00:00 2001 From: Martino Ferrari Date: Mon, 17 Aug 2026 08:06:35 +0200 Subject: [PATCH] test: fix UDPStreamer multicast tests broken by mandatory Interface Commit 3e0a481 made Interface mandatory for multicast in both UDPStreamer::Initialise and UDPSServer::Initialise and updated Docs/UDPStreamer.md, but left the GTest configs untouched. All four multicast tests have failed since. Add Interface to the five multicast configs. The field is parsed with inet_addr(), so it takes a dotted-quad, not an interface name; 127.0.0.1 keeps the tests self-contained and off the LAN. TestInitialise_MulticastMode_InvalidDataPort was passing for the wrong reason: UDPStreamer.cpp rejected it on the missing Interface before the DataPort == Port check could run. It now proves what its name claims. TestExecute_MulticastConnectDataDisconnect additionally needed the two-argument Join(): the single-argument form passes INADDR_ANY, so the reader joined the default-route interface while the server sent on loopback via IP_MULTICAST_IF, and the DATA datagram never arrived. GTest: 132/132 (was 128/132), multicast subset stable over 3 runs. Co-Authored-By: Claude Opus 4.6 --- .../DataSources/UDPStreamer/UDPStreamerTest.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Test/Components/DataSources/UDPStreamer/UDPStreamerTest.cpp b/Test/Components/DataSources/UDPStreamer/UDPStreamerTest.cpp index 279d868..819ff35 100644 --- a/Test/Components/DataSources/UDPStreamer/UDPStreamerTest.cpp +++ b/Test/Components/DataSources/UDPStreamer/UDPStreamerTest.cpp @@ -1559,6 +1559,7 @@ bool UDPStreamerTest::TestInitialise_MulticastMode_Valid() { ConfigurationDatabase cdb; cdb.Write("Port", 44710u); cdb.Write("MulticastGroup", "239.0.0.1"); + cdb.Write("Interface", "127.0.0.1"); cdb.Write("DataPort", 44711u); cdb.CreateRelative("Signals"); cdb.MoveToRoot(); @@ -1574,6 +1575,7 @@ bool UDPStreamerTest::TestInitialise_MulticastMode_DefaultDataPort() { ConfigurationDatabase cdb; cdb.Write("Port", 44712u); cdb.Write("MulticastGroup", "239.0.0.1"); + cdb.Write("Interface", "127.0.0.1"); /* DataPort intentionally omitted: should default to 44713 */ cdb.CreateRelative("Signals"); cdb.MoveToRoot(); @@ -1588,6 +1590,9 @@ bool UDPStreamerTest::TestInitialise_MulticastMode_InvalidDataPort() { ConfigurationDatabase cdb; cdb.Write("Port", 44714u); cdb.Write("MulticastGroup", "239.0.0.1"); + /* Interface is mandatory for multicast; supply it so the rejection below + * is provably caused by DataPort == Port and not by a missing Interface. */ + cdb.Write("Interface", "127.0.0.1"); cdb.Write("DataPort", 44714u); /* same as Port — must be rejected */ cdb.CreateRelative("Signals"); cdb.MoveToRoot(); @@ -1618,6 +1623,7 @@ bool UDPStreamerTest::TestPrepareNextState_Multicast() { " Class = UDPStreamer\n" " Port = 44716\n" " MulticastGroup = \"239.0.0.1\"\n" + " Interface = \"127.0.0.1\"\n" " DataPort = 44717\n" " MaxPayloadSize = 1400\n" " Signals = {\n" @@ -1695,6 +1701,7 @@ bool UDPStreamerTest::TestExecute_MulticastConnectDataDisconnect() { " Class = UDPStreamer\n" " Port = 44720\n" " MulticastGroup = \"239.0.0.1\"\n" + " Interface = \"127.0.0.1\"\n" " DataPort = 44721\n" " MaxPayloadSize = 1400\n" " Signals = {\n" @@ -1786,7 +1793,12 @@ bool UDPStreamerTest::TestExecute_MulticastConnectDataDisconnect() { ok = mcastReader.Listen(44721u); } if (ok) { - ok = mcastReader.Join("239.0.0.1"); + /* Join on the same interface the streamer sends from (Interface = + * 127.0.0.1 sets IP_MULTICAST_IF on the server's data socket). The + * single-argument Join() would pass INADDR_ANY, letting the kernel + * pick the default-route interface, and the datagram would never + * reach this socket. */ + ok = mcastReader.Join("239.0.0.1", "127.0.0.1"); } /* Step 4: Trigger Synchronise() to generate a DATA packet */