summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/socket
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2020-02-26 01:00:25 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2020-02-26 18:39:21 +0100
commit75c0ffaf6d2b92cdf26092e01acdd5af4afeac97 (patch)
treebb9e85c21248790ec99b3665928872e39b14db64 /tests/auto/network/socket
parent4753d69d8934258de7fb64550e50a5cbb9b5603f (diff)
parent462c2745a5168a5b57381d05779b5d16aebe018e (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: examples/network/bearermonitor/CMakeLists.txt examples/network/CMakeLists.txt src/corelib/tools/qlinkedlist.h src/sql/kernel/qsqldriver_p.h src/sql/kernel/qsqlresult_p.h src/widgets/kernel/qwidget.cpp src/widgets/kernel/qwidget_p.h tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp tests/auto/tools/moc/allmocs_baseline_in.json Change-Id: I21a3c34570ae79ea9d30107fae71759d7eac17d9
Diffstat (limited to 'tests/auto/network/socket')
-rw-r--r--tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp21
-rw-r--r--tests/auto/network/socket/qtcpsocket/BLACKLIST7
-rw-r--r--tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp53
3 files changed, 42 insertions, 39 deletions
diff --git a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
index 1ef9382f0a..68c913ecfc 100644
--- a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
+++ b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
@@ -529,18 +529,11 @@ void tst_PlatformSocketEngine::tooManySockets()
//---------------------------------------------------------------------------
void tst_PlatformSocketEngine::bind()
{
-#if !defined Q_OS_WIN
-#if defined Q_OS_MACOS
- // On macOS >= 10.14 the bind on this port is successful.
- if (QOperatingSystemVersion::current() < QOperatingSystemVersion::MacOSMojave)
-#endif // Q_OS_MACOS
- {
- PLATFORMSOCKETENGINE binder;
- QVERIFY(binder.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol));
- QVERIFY(!binder.bind(QHostAddress::AnyIPv4, 82));
+ PLATFORMSOCKETENGINE binder;
+ QVERIFY(binder.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol));
+ QCOMPARE(binder.bind(QHostAddress::AnyIPv4, 82), QtNetworkSettings::canBindToLowPorts());
+ if (!QtNetworkSettings::canBindToLowPorts())
QCOMPARE(binder.error(), QAbstractSocket::SocketAccessError);
- }
-#endif // Q_OS_WIN
PLATFORMSOCKETENGINE binder2;
QVERIFY(binder2.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol));
@@ -552,6 +545,12 @@ void tst_PlatformSocketEngine::bind()
QCOMPARE(binder3.error(), QAbstractSocket::AddressInUseError);
if (QtNetworkSettings::hasIPv6()) {
+ PLATFORMSOCKETENGINE binder;
+ QVERIFY(binder.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv6Protocol));
+ QCOMPARE(binder.bind(QHostAddress::AnyIPv6, 82), QtNetworkSettings::canBindToLowPorts());
+ if (!QtNetworkSettings::canBindToLowPorts())
+ QCOMPARE(binder.error(), QAbstractSocket::SocketAccessError);
+
PLATFORMSOCKETENGINE binder4;
QVERIFY(binder4.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv6Protocol));
QVERIFY(binder4.bind(QHostAddress::AnyIPv6, 31180));
diff --git a/tests/auto/network/socket/qtcpsocket/BLACKLIST b/tests/auto/network/socket/qtcpsocket/BLACKLIST
index 07532710b3..129e9f0b4e 100644
--- a/tests/auto/network/socket/qtcpsocket/BLACKLIST
+++ b/tests/auto/network/socket/qtcpsocket/BLACKLIST
@@ -1,10 +1,3 @@
-[bind]
-windows-10 msvc-2015
-windows-7sp1
-[bind:[::]]
-windows
-[bind:[::]:randomport]
-windows
[timeoutConnect:ip]
windows
# QTBUG-66247
diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
index bf08d70eb3..099aa5fb51 100644
--- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
@@ -523,7 +523,7 @@ void tst_QTcpSocket::bind_data()
continue; // link-local bind will fail, at least on Linux, so skip it.
QString ip(entry.ip().toString());
- QTest::newRow(ip.toLatin1().constData()) << ip << 0 << true << ip;
+ QTest::addRow("%s:0", ip.toLatin1().constData()) << ip << 0 << true << ip;
if (!testIpv6 && entry.ip().protocol() == QAbstractSocket::IPv6Protocol)
testIpv6 = true;
@@ -531,9 +531,9 @@ void tst_QTcpSocket::bind_data()
}
// test binding to localhost
- QTest::newRow("0.0.0.0") << "0.0.0.0" << 0 << true << "0.0.0.0";
+ QTest::newRow("0.0.0.0:0") << "0.0.0.0" << 0 << true << "0.0.0.0";
if (testIpv6)
- QTest::newRow("[::]") << "::" << 0 << true << "::";
+ QTest::newRow("[::]:0") << "::" << 0 << true << "::";
// and binding with a port number...
// Since we want to test that we got the port number we asked for, we need a random port number.
@@ -551,26 +551,22 @@ void tst_QTcpSocket::bind_data()
knownBad << "198.51.100.1";
knownBad << "2001:0DB8::1";
foreach (const QString &badAddress, knownBad) {
- QTest::newRow(badAddress.toLatin1().constData()) << badAddress << 0 << false << QString();
+ QTest::addRow("%s:0", badAddress.toLatin1().constData()) << badAddress << 0 << false << QString();
}
-#ifdef Q_OS_UNIX
// try to bind to a privileged ports
// we should fail if we're not root (unless the ports are in use!)
- QTest::newRow("127.0.0.1:1") << "127.0.0.1" << 1 << !geteuid() << (geteuid() ? QString() : "127.0.0.1");
- if (testIpv6) {
#ifdef Q_OS_DARWIN
- // This case is faling in different ways, first, it manages to bind to
- // port 1 on macOS >= 10.14, but if we change the logic to not fail,
- // it's becoming flaky and sometimes fails to bind, with error 'port in use'
- // (apparently inflicted by the previous test row with 127.0.0.1). Amen.
- if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave)
- QTest::qWarn("Skipping [::]:1, see QTBUG-81905", __FILE__, __LINE__);
- else
+ // Alas, some quirk (starting from macOS 10.14): bind with port number 1
+ // fails with IPv4 (not IPv6 though, see below).
+ QTest::newRow("127.0.0.1:1") << "127.0.0.1" << 1 << false << QString();
+#else
+ QTest::newRow("127.0.0.1:1") << "127.0.0.1" << 1 << QtNetworkSettings::canBindToLowPorts()
+ << (QtNetworkSettings::canBindToLowPorts() ? "127.0.0.1" : QString());
#endif // Q_OS_DARWIN
- QTest::newRow("[::]:1") << "::" << 1 << !geteuid() << (geteuid() ? QString() : "::");
- }
-#endif
+ if (testIpv6)
+ QTest::newRow("[::]:1") << "::" << 1 << QtNetworkSettings::canBindToLowPorts()
+ << (QtNetworkSettings::canBindToLowPorts() ? "::" : QString());
}
void tst_QTcpSocket::bind()
@@ -589,13 +585,13 @@ void tst_QTcpSocket::bind()
QTcpSocket dummySocket; // used only to "use up" a file descriptor
dummySocket.bind();
- QTcpSocket *socket = newSocket();
+ std::unique_ptr<QTcpSocket> socket(newSocket());
quint16 boundPort;
qintptr fd;
if (successExpected) {
bool randomPort = port == -1;
- int attemptsLeft = 5; // only used with randomPort
+ int attemptsLeft = 5; // only used with randomPort or Windows
do {
if (randomPort) {
// try to get a random port number
@@ -655,9 +651,24 @@ void tst_QTcpSocket::bind()
QCOMPARE(acceptedSocket->peerPort(), boundPort);
QCOMPARE(socket->localAddress(), remoteAddr);
QCOMPARE(socket->socketDescriptor(), fd);
+#ifdef Q_OS_DARWIN
+ // Normally, we don't see this problem: macOS sometimes does not
+ // allow us to immediately re-use a port, thinking connection is
+ // still alive. With fixed port 1 (we testing starting from
+ // macOS 10.14), this problem shows, making the test flaky:
+ // we run this 'bind' with port 1 several times (different
+ // test cases) and the problem manifests itself as
+ // "The bound address is already in use, tried port 1".
+ QTestEventLoop cleanupHelper;
+ auto client = socket.get();
+ connect(client, &QTcpSocket::disconnected, [&cleanupHelper, client](){
+ client->close();
+ cleanupHelper.exitLoop();
+ });
+ acceptedSocket->close();
+ cleanupHelper.enterLoopMSecs(100);
+#endif // Q_OS_DARWIN
}
-
- delete socket;
}
//----------------------------------------------------------------------------------