summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-11-28 12:15:37 -0800
committerThiago Macieira <thiago.macieira@intel.com>2017-12-24 17:14:19 +0000
commitc4f397ee11fc3cea1fc132ebe1db24e3970bb477 (patch)
tree1e6c769731287f81e42ab7fc1bed83d9b09863a1
parentbbcd4533889b3f3ae45917d638e06bedc9e5c536 (diff)
tst_QUdpSocket: Don't use interface-local IPv6 multicast
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 <edward.welbourne@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp28
1 files changed, 22 insertions, 6 deletions
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 <qfileinfo.h>
#include <qdatastream.h>
#include <qdebug.h>
+#include <qrandom.h>
#include <qudpsocket.h>
#include <qhostaddress.h>
#include <qhostinfo.h>
@@ -124,6 +125,7 @@ private:
bool m_skipUnsupportedIPv6Tests;
QList<QHostAddress> 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<Q_IPV6ADDR *>(&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<QHostAddress>("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<QHostAddress>("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<QHostAddress>("bindAddress");