From c4f397ee11fc3cea1fc132ebe1db24e3970bb477 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Nov 2017 12:15:37 -0800 Subject: tst_QUdpSocket: Don't use interface-local IPv6 multicast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The FreeBSD kernel treats them specially, just like link-local (that's probably why it calls them "interface-local" instead of "node-local"). So instead let's use a random address, which will avoid multiple tst_qudpsocket, when run on the same network at the same time, receiving each other's datagrams. It could happen, considering this test has an 800-second timeout limit. Change-Id: Ifb5969bf206e4cd7b14efffd14fb592a3166547e Reviewed-by: Edward Welbourne Reviewed-by: MÃ¥rten Nordheim --- .../network/socket/qudpsocket/tst_qudpsocket.cpp | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'tests/auto/network/socket') diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 9050bbbc93..69d549d738 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -124,6 +125,7 @@ private: bool m_skipUnsupportedIPv6Tests; QList allAddresses; + QHostAddress multicastGroup4, multicastGroup6; QUdpSocket *m_asyncSender; QUdpSocket *m_asyncReceiver; }; @@ -208,6 +210,20 @@ void tst_QUdpSocket::initTestCase() allAddresses = QNetworkInterface::allAddresses(); m_skipUnsupportedIPv6Tests = shouldSkipIpv6TestsForBrokenSetsockopt(); + // Create a pair of random multicast groups so we avoid clashing with any + // other tst_qudpsocket running on the same network at the same time. + quint64 r[2] = { + // ff14:: is temporary, not prefix-based, admin-local + qToBigEndian(Q_UINT64_C(0xff14) << 48), + QRandomGenerator64::global()->generate64() + }; + multicastGroup6.setAddress(*reinterpret_cast(&r)); + + // 239.0.0.0/8 is "Organization-Local Scope" + multicastGroup4.setAddress((239U << 24) | (r[1] & 0xffffff)); + + qDebug() << "Will use multicast groups" << multicastGroup4 << multicastGroup6; + if (EmulationDetector::isRunningArmOnX86()) QSKIP("This test is unreliable due to QEMU emulation shortcomings."); } @@ -1232,9 +1248,9 @@ void tst_QUdpSocket::multicastLoopbackOption() void tst_QUdpSocket::multicastJoinBeforeBind_data() { QTest::addColumn("groupAddress"); - QTest::newRow("valid ipv4 group address") << QHostAddress("239.255.118.62"); + QTest::newRow("valid ipv4 group address") << multicastGroup4; QTest::newRow("invalid ipv4 group address") << QHostAddress(QHostAddress::Broadcast); - QTest::newRow("valid ipv6 group address") << QHostAddress("FF01::114"); + QTest::newRow("valid ipv6 group address") << multicastGroup6; QTest::newRow("invalid ipv6 group address") << QHostAddress(QHostAddress::AnyIPv6); } @@ -1254,8 +1270,8 @@ void tst_QUdpSocket::multicastJoinBeforeBind() void tst_QUdpSocket::multicastLeaveAfterClose_data() { QTest::addColumn("groupAddress"); - QTest::newRow("ipv4") << QHostAddress("239.255.118.62"); - QTest::newRow("ipv6") << QHostAddress("FF01::114"); + QTest::newRow("ipv4") << multicastGroup4; + QTest::newRow("ipv6") << multicastGroup6; } void tst_QUdpSocket::multicastLeaveAfterClose() @@ -1342,9 +1358,9 @@ void tst_QUdpSocket::setMulticastInterface() void tst_QUdpSocket::multicast_data() { QHostAddress anyAddress = QHostAddress(QHostAddress::AnyIPv4); - QHostAddress groupAddress = QHostAddress("239.255.118.62"); + QHostAddress groupAddress = multicastGroup4; QHostAddress any6Address = QHostAddress(QHostAddress::AnyIPv6); - QHostAddress group6Address = QHostAddress("FF01::114"); + QHostAddress group6Address = multicastGroup6; QHostAddress dualAddress = QHostAddress(QHostAddress::Any); QTest::addColumn("bindAddress"); -- cgit v1.2.3