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 <noreply@anthropic.com>
This commit is contained in:
Martino Ferrari
2026-08-17 08:06:35 +02:00
co-authored by Claude Opus 4.6
parent 72c286db33
commit c827ecefff
@@ -1559,6 +1559,7 @@ bool UDPStreamerTest::TestInitialise_MulticastMode_Valid() {
ConfigurationDatabase cdb; ConfigurationDatabase cdb;
cdb.Write("Port", 44710u); cdb.Write("Port", 44710u);
cdb.Write("MulticastGroup", "239.0.0.1"); cdb.Write("MulticastGroup", "239.0.0.1");
cdb.Write("Interface", "127.0.0.1");
cdb.Write("DataPort", 44711u); cdb.Write("DataPort", 44711u);
cdb.CreateRelative("Signals"); cdb.CreateRelative("Signals");
cdb.MoveToRoot(); cdb.MoveToRoot();
@@ -1574,6 +1575,7 @@ bool UDPStreamerTest::TestInitialise_MulticastMode_DefaultDataPort() {
ConfigurationDatabase cdb; ConfigurationDatabase cdb;
cdb.Write("Port", 44712u); cdb.Write("Port", 44712u);
cdb.Write("MulticastGroup", "239.0.0.1"); cdb.Write("MulticastGroup", "239.0.0.1");
cdb.Write("Interface", "127.0.0.1");
/* DataPort intentionally omitted: should default to 44713 */ /* DataPort intentionally omitted: should default to 44713 */
cdb.CreateRelative("Signals"); cdb.CreateRelative("Signals");
cdb.MoveToRoot(); cdb.MoveToRoot();
@@ -1588,6 +1590,9 @@ bool UDPStreamerTest::TestInitialise_MulticastMode_InvalidDataPort() {
ConfigurationDatabase cdb; ConfigurationDatabase cdb;
cdb.Write("Port", 44714u); cdb.Write("Port", 44714u);
cdb.Write("MulticastGroup", "239.0.0.1"); 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.Write("DataPort", 44714u); /* same as Port — must be rejected */
cdb.CreateRelative("Signals"); cdb.CreateRelative("Signals");
cdb.MoveToRoot(); cdb.MoveToRoot();
@@ -1618,6 +1623,7 @@ bool UDPStreamerTest::TestPrepareNextState_Multicast() {
" Class = UDPStreamer\n" " Class = UDPStreamer\n"
" Port = 44716\n" " Port = 44716\n"
" MulticastGroup = \"239.0.0.1\"\n" " MulticastGroup = \"239.0.0.1\"\n"
" Interface = \"127.0.0.1\"\n"
" DataPort = 44717\n" " DataPort = 44717\n"
" MaxPayloadSize = 1400\n" " MaxPayloadSize = 1400\n"
" Signals = {\n" " Signals = {\n"
@@ -1695,6 +1701,7 @@ bool UDPStreamerTest::TestExecute_MulticastConnectDataDisconnect() {
" Class = UDPStreamer\n" " Class = UDPStreamer\n"
" Port = 44720\n" " Port = 44720\n"
" MulticastGroup = \"239.0.0.1\"\n" " MulticastGroup = \"239.0.0.1\"\n"
" Interface = \"127.0.0.1\"\n"
" DataPort = 44721\n" " DataPort = 44721\n"
" MaxPayloadSize = 1400\n" " MaxPayloadSize = 1400\n"
" Signals = {\n" " Signals = {\n"
@@ -1786,7 +1793,12 @@ bool UDPStreamerTest::TestExecute_MulticastConnectDataDisconnect() {
ok = mcastReader.Listen(44721u); ok = mcastReader.Listen(44721u);
} }
if (ok) { 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 */ /* Step 4: Trigger Synchronise() to generate a DATA packet */