diff options
Diffstat (limited to 'tests/benchmarks/network/socket')
7 files changed, 56 insertions, 114 deletions
diff --git a/tests/benchmarks/network/socket/CMakeLists.txt b/tests/benchmarks/network/socket/CMakeLists.txt index 7c122a73ef..411a933dbb 100644 --- a/tests/benchmarks/network/socket/CMakeLists.txt +++ b/tests/benchmarks/network/socket/CMakeLists.txt @@ -1,5 +1,12 @@ -# Generated from socket.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(QT_FEATURE_localserver) + add_subdirectory(qlocalsocket) +endif() + +if(QT_FEATURE_udpsocket) + add_subdirectory(qudpsocket) +endif() -add_subdirectory(qlocalsocket) add_subdirectory(qtcpserver) -add_subdirectory(qudpsocket) diff --git a/tests/benchmarks/network/socket/qlocalsocket/CMakeLists.txt b/tests/benchmarks/network/socket/qlocalsocket/CMakeLists.txt index 7c56b0b946..660f2ee5b4 100644 --- a/tests/benchmarks/network/socket/qlocalsocket/CMakeLists.txt +++ b/tests/benchmarks/network/socket/qlocalsocket/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + ##################################################################### ## tst_bench_qlocalsocket Binary: ##################################################################### @@ -5,10 +8,7 @@ qt_internal_add_benchmark(tst_bench_qlocalsocket SOURCES tst_qlocalsocket.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Network Qt::Test ) - -#### Keys ignored in scope 1:.:.:qlocalsocket.pro:<TRUE>: -# TEMPLATE = "app" diff --git a/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp index 86112f442d..a28869f24c 100644 --- a/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -1,43 +1,21 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Copyright (C) 2021 Alex Trotsenko <alex1973tr@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// Copyright (C) 2021 Alex Trotsenko <alex1973tr@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> +#include <QtTest/qtesteventloop.h> + #include <QtCore/qglobal.h> #include <QtCore/qthread.h> #include <QtCore/qsemaphore.h> #include <QtCore/qbytearray.h> -#include <QtCore/qeventloop.h> #include <QtCore/qvector.h> #include <QtCore/qelapsedtimer.h> #include <QtNetwork/qlocalsocket.h> #include <QtNetwork/qlocalserver.h> +using namespace std::chrono_literals; + class tst_QLocalSocket : public QObject { Q_OBJECT @@ -75,7 +53,9 @@ public: }); }); - QVERIFY(server.listen("foo")); + // TODO QTBUG-95136: on failure, remove the socket file and retry. + QVERIFY2(server.listen("foo"), qPrintable(server.errorString())); + running.release(); exec(); } @@ -114,6 +94,10 @@ public: }); socket->connectToServer("foo"); + QVERIFY2(socket->waitForConnected(), "The system is probably reaching the maximum " + "number of open file descriptors. On Unix, " + "try to increase the limit with 'ulimit -n 32000' " + "and run the test again."); QCOMPARE(socket->state(), QLocalSocket::ConnectedState); } } @@ -146,7 +130,7 @@ void tst_QLocalSocket::pingPong() QVERIFY(serverThread.running.tryAcquire(1, 3000)); SocketFactory factory(1, connections); - QEventLoop eventLoop; + QTestEventLoop eventLoop; QVector<qint64> bytesToRead; QElapsedTimer timer; @@ -157,15 +141,20 @@ void tst_QLocalSocket::pingPong() if (--bytesToRead[channel] == 0 && --connections == 0) { factory.stopped = true; - eventLoop.quit(); + eventLoop.exitLoop(); } }); timer.start(); emit factory.start(); - eventLoop.exec(); - - qDebug("Elapsed time: %.1f s", timer.elapsed() / 1000.0); + // QtTestLib's Watchdog defaults to 300 seconds; we want to give up before + // it bites. + eventLoop.enterLoop(290); + + if (eventLoop.timeout()) + qDebug("Timed out after %.1f s", timer.elapsed() / 1000.0); + else if (!QTest::currentTestFailed()) + qDebug("Elapsed time: %.1f s", timer.elapsed() / 1000.0); serverThread.quit(); serverThread.wait(); } @@ -188,7 +177,7 @@ void tst_QLocalSocket::dataExchange() QFETCH(int, chunkSize); Q_ASSERT(chunkSize > 0 && connections > 0); - const qint64 timeToTest = 5000; + const auto timeToTest = 5000ms; ServerThread serverThread(chunkSize); serverThread.start(); @@ -196,26 +185,26 @@ void tst_QLocalSocket::dataExchange() QVERIFY(serverThread.running.tryAcquire(1, 3000)); SocketFactory factory(chunkSize, connections); - QEventLoop eventLoop; + QTestEventLoop eventLoop; qint64 totalReceived = 0; QElapsedTimer timer; - connect(&factory, &SocketFactory::bytesReceived, - [&totalReceived, &timer, timeToTest, &factory, &eventLoop](int channel, qint64 bytes) { + connect(&factory, &SocketFactory::bytesReceived, [&](int channel, qint64 bytes) { Q_UNUSED(channel); totalReceived += bytes; - if (timer.elapsed() >= timeToTest) { + if (timer.elapsed() >= timeToTest.count()) { factory.stopped = true; - eventLoop.quit(); + eventLoop.exitLoop(); } }); timer.start(); emit factory.start(); - eventLoop.exec(); + eventLoop.enterLoop(timeToTest * 2); - qDebug("Transfer rate: %.1f MB/s", totalReceived / 1048.576 / timer.elapsed()); + if (!QTest::currentTestFailed()) + qDebug("Transfer rate: %.1f MB/s", totalReceived / 1048.576 / timer.elapsed()); serverThread.quit(); serverThread.wait(); } diff --git a/tests/benchmarks/network/socket/qtcpserver/CMakeLists.txt b/tests/benchmarks/network/socket/qtcpserver/CMakeLists.txt index f566c4f341..ae2f491df0 100644 --- a/tests/benchmarks/network/socket/qtcpserver/CMakeLists.txt +++ b/tests/benchmarks/network/socket/qtcpserver/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qtcpserver.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_bench_qtcpserver Binary: @@ -7,10 +8,7 @@ qt_internal_add_benchmark(tst_bench_qtcpserver SOURCES tst_qtcpserver.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Network Qt::Test ) - -#### Keys ignored in scope 1:.:.:qtcpserver.pro:<TRUE>: -# TEMPLATE = "app" diff --git a/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp index 06643dd1fd..68d60261d5 100644 --- a/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp +++ b/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtCore/QElapsedTimer> diff --git a/tests/benchmarks/network/socket/qudpsocket/CMakeLists.txt b/tests/benchmarks/network/socket/qudpsocket/CMakeLists.txt index 02293cdae6..0a39e8fc0c 100644 --- a/tests/benchmarks/network/socket/qudpsocket/CMakeLists.txt +++ b/tests/benchmarks/network/socket/qudpsocket/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qudpsocket.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_bench_qudpsocket Binary: @@ -7,10 +8,7 @@ qt_internal_add_benchmark(tst_bench_qudpsocket SOURCES tst_qudpsocket.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Network Qt::Test ) - -#### Keys ignored in scope 1:.:.:qudpsocket.pro:<TRUE>: -# TEMPLATE = "app" diff --git a/tests/benchmarks/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/benchmarks/network/socket/qudpsocket/tst_qudpsocket.cpp index f2fd297414..d3ef636e74 100644 --- a/tests/benchmarks/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/benchmarks/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtCore/qglobal.h> |