summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/network
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/network')
-rw-r--r--tests/benchmarks/network/.prev_CMakeLists.txt8
-rw-r--r--tests/benchmarks/network/CMakeLists.txt5
-rw-r--r--tests/benchmarks/network/access/CMakeLists.txt10
-rw-r--r--tests/benchmarks/network/access/access.pro11
-rw-r--r--tests/benchmarks/network/access/qdecompresshelper/.prev_CMakeLists.txt19
-rw-r--r--tests/benchmarks/network/access/qdecompresshelper/50mb.txt.zstbin0 -> 1665 bytes
-rw-r--r--tests/benchmarks/network/access/qdecompresshelper/CMakeLists.txt13
-rw-r--r--tests/benchmarks/network/access/qdecompresshelper/main.cpp33
-rw-r--r--tests/benchmarks/network/access/qdecompresshelper/qdecompresshelper.pro8
-rw-r--r--tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/CMakeLists.txt10
-rw-r--r--tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp32
-rw-r--r--tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro9
-rw-r--r--tests/benchmarks/network/access/qhttpheaders/CMakeLists.txt10
-rw-r--r--tests/benchmarks/network/access/qhttpheaders/tst_bench_qhttpheaders.cpp266
-rw-r--r--tests/benchmarks/network/access/qnetworkdiskcache/CMakeLists.txt10
-rw-r--r--tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro8
-rw-r--r--tests/benchmarks/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp32
-rw-r--r--tests/benchmarks/network/access/qnetworkreply/CMakeLists.txt10
-rw-r--r--tests/benchmarks/network/access/qnetworkreply/qnetworkreply.pro9
-rw-r--r--tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp101
-rw-r--r--tests/benchmarks/network/access/qnetworkreply_from_cache/CMakeLists.txt7
-rw-r--r--tests/benchmarks/network/access/qnetworkreply_from_cache/qnetworkreply_from_cache.pro3
-rw-r--r--tests/benchmarks/network/access/qnetworkreply_from_cache/tst_qnetworkreply_from_cache.cpp41
-rw-r--r--tests/benchmarks/network/kernel/CMakeLists.txt3
-rw-r--r--tests/benchmarks/network/kernel/kernel.pro4
-rw-r--r--tests/benchmarks/network/kernel/qhostinfo/CMakeLists.txt10
-rw-r--r--tests/benchmarks/network/kernel/qhostinfo/main.cpp29
-rw-r--r--tests/benchmarks/network/kernel/qhostinfo/qhostinfo.pro9
-rw-r--r--tests/benchmarks/network/network.pro19
-rw-r--r--tests/benchmarks/network/socket/CMakeLists.txt12
-rw-r--r--tests/benchmarks/network/socket/qlocalsocket/CMakeLists.txt14
-rw-r--r--tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp214
-rw-r--r--tests/benchmarks/network/socket/qtcpserver/CMakeLists.txt10
-rw-r--r--tests/benchmarks/network/socket/qtcpserver/qtcpserver.pro9
-rw-r--r--tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp33
-rw-r--r--tests/benchmarks/network/socket/qudpsocket/CMakeLists.txt10
-rw-r--r--tests/benchmarks/network/socket/qudpsocket/qudpsocket.pro8
-rw-r--r--tests/benchmarks/network/socket/qudpsocket/tst_qudpsocket.cpp31
-rw-r--r--tests/benchmarks/network/socket/socket.pro4
-rw-r--r--tests/benchmarks/network/ssl/CMakeLists.txt3
-rw-r--r--tests/benchmarks/network/ssl/qsslsocket/CMakeLists.txt10
-rw-r--r--tests/benchmarks/network/ssl/qsslsocket/qsslsocket.pro9
-rw-r--r--tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp33
-rw-r--r--tests/benchmarks/network/ssl/ssl.pro3
44 files changed, 635 insertions, 497 deletions
diff --git a/tests/benchmarks/network/.prev_CMakeLists.txt b/tests/benchmarks/network/.prev_CMakeLists.txt
deleted file mode 100644
index 8b1a7ac1ff..0000000000
--- a/tests/benchmarks/network/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-# Generated from network.pro.
-
-add_subdirectory(access)
-add_subdirectory(kernel)
-add_subdirectory(socket)
-if(QT_FEATURE_openssl)
- add_subdirectory(ssl)
-endif()
diff --git a/tests/benchmarks/network/CMakeLists.txt b/tests/benchmarks/network/CMakeLists.txt
index 4f20fb5ccd..50558e6999 100644
--- a/tests/benchmarks/network/CMakeLists.txt
+++ b/tests/benchmarks/network/CMakeLists.txt
@@ -1,6 +1,6 @@
-# Generated from network.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-# special case begin
# SSL library include path is not propagated with private tests which results in
# test not being able to find the ssl header when they are not in the standard
# include paths
@@ -13,7 +13,6 @@ if (QT_FEATURE_private_tests)
include_directories($<TARGET_PROPERTY:WrapOpenSSLHeaders::WrapOpenSSLHeaders,INTERFACE_INCLUDE_DIRECTORIES>)
endif()
endif()
-# special case end
add_subdirectory(access)
add_subdirectory(kernel)
diff --git a/tests/benchmarks/network/access/CMakeLists.txt b/tests/benchmarks/network/access/CMakeLists.txt
index 3069505252..bc5148af55 100644
--- a/tests/benchmarks/network/access/CMakeLists.txt
+++ b/tests/benchmarks/network/access/CMakeLists.txt
@@ -1,9 +1,13 @@
-# Generated from access.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qfile_vs_qnetworkaccessmanager)
+add_subdirectory(qhttpheaders)
add_subdirectory(qnetworkreply)
-add_subdirectory(qnetworkreply_from_cache)
-add_subdirectory(qnetworkdiskcache)
+if(QT_FEATURE_networkdiskcache)
+ add_subdirectory(qnetworkreply_from_cache)
+ add_subdirectory(qnetworkdiskcache)
+endif()
if(QT_FEATURE_private_tests)
add_subdirectory(qdecompresshelper)
endif()
diff --git a/tests/benchmarks/network/access/access.pro b/tests/benchmarks/network/access/access.pro
deleted file mode 100644
index fed262601b..0000000000
--- a/tests/benchmarks/network/access/access.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = \
- qfile_vs_qnetworkaccessmanager \
- qnetworkreply \
- qnetworkreply_from_cache \
- qnetworkdiskcache
-
-qtConfig(private_tests): \
- SUBDIRS += \
- qdecompresshelper \
-
diff --git a/tests/benchmarks/network/access/qdecompresshelper/.prev_CMakeLists.txt b/tests/benchmarks/network/access/qdecompresshelper/.prev_CMakeLists.txt
deleted file mode 100644
index cec7aad7b2..0000000000
--- a/tests/benchmarks/network/access/qdecompresshelper/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-# Generated from qdecompresshelper.pro.
-
-#####################################################################
-## qdecompresshelper Binary:
-#####################################################################
-
-qt_add_executable(qdecompresshelper
- SOURCES
- main.cpp
- DEFINES
- SRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
- PUBLIC_LIBRARIES
- Qt::NetworkPrivate
- Qt::Test
-)
-
-#### Keys ignored in scope 1:.:.:qdecompresshelper.pro:<TRUE>:
-# TEMPLATE = "app"
-# _REQUIREMENTS = "qtConfig(private_tests)"
diff --git a/tests/benchmarks/network/access/qdecompresshelper/50mb.txt.zst b/tests/benchmarks/network/access/qdecompresshelper/50mb.txt.zst
new file mode 100644
index 0000000000..e9546e230e
--- /dev/null
+++ b/tests/benchmarks/network/access/qdecompresshelper/50mb.txt.zst
Binary files differ
diff --git a/tests/benchmarks/network/access/qdecompresshelper/CMakeLists.txt b/tests/benchmarks/network/access/qdecompresshelper/CMakeLists.txt
index af7676b561..d2ca8db69d 100644
--- a/tests/benchmarks/network/access/qdecompresshelper/CMakeLists.txt
+++ b/tests/benchmarks/network/access/qdecompresshelper/CMakeLists.txt
@@ -1,19 +1,16 @@
-# Generated from qdecompresshelper.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## qdecompresshelper Binary:
#####################################################################
-qt_add_executable(qdecompresshelper
+qt_internal_add_benchmark(qdecompresshelper
SOURCES
main.cpp
DEFINES
- SRC_DIR=${CMAKE_CURRENT_SOURCE_DIR} # special case
- PUBLIC_LIBRARIES
+ SRC_DIR=${CMAKE_CURRENT_SOURCE_DIR}
+ LIBRARIES
Qt::NetworkPrivate
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:decompresshelper.pro:<TRUE>:
-# TEMPLATE = "app"
-# _REQUIREMENTS = "qtConfig(private_tests)"
diff --git a/tests/benchmarks/network/access/qdecompresshelper/main.cpp b/tests/benchmarks/network/access/qdecompresshelper/main.cpp
index 5296c9681c..09c24af668 100644
--- a/tests/benchmarks/network/access/qdecompresshelper/main.cpp
+++ b/tests/benchmarks/network/access/qdecompresshelper/main.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 <QtNetwork/private/qdecompresshelper_p.h>
@@ -57,6 +32,10 @@ void tst_QDecompressHelper::decompress_data()
QTest::addRow("brotli") << QByteArray("br") << srcDir + QString("50mb.txt.br");
dataAdded = true;
#endif
+#if QT_CONFIG(zstd)
+ QTest::addRow("zstandard") << QByteArray("zstd") << srcDir + QString("50mb.txt.zst");
+ dataAdded = true;
+#endif
if (!dataAdded)
QSKIP("There's no decompression support");
}
diff --git a/tests/benchmarks/network/access/qdecompresshelper/qdecompresshelper.pro b/tests/benchmarks/network/access/qdecompresshelper/qdecompresshelper.pro
deleted file mode 100644
index f87442260e..0000000000
--- a/tests/benchmarks/network/access/qdecompresshelper/qdecompresshelper.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-requires(qtConfig(private_tests))
-TEMPLATE = app
-QT = network-private testlib
-
-SOURCES = main.cpp
-CONFIG += release
-
-DEFINES += SRC_DIR="$$PWD"
diff --git a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/CMakeLists.txt b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/CMakeLists.txt
index f34a3c475c..fd1592ad17 100644
--- a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/CMakeLists.txt
+++ b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/CMakeLists.txt
@@ -1,16 +1,14 @@
-# Generated from qfile_vs_qnetworkaccessmanager.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qfile_vs_qnetworkaccessmanager Binary:
#####################################################################
-qt_add_benchmark(tst_bench_qfile_vs_qnetworkaccessmanager
+qt_internal_add_benchmark(tst_bench_qfile_vs_qnetworkaccessmanager
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qfile_vs_qnetworkaccessmanager.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp
index 7f0f0190ec..372158163f 100644
--- a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp
+++ b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp
@@ -1,33 +1,9 @@
-/****************************************************************************
-**
-** 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 <QDebug>
#include <qtest.h>
-#include <QtTest/QtTest>
+#include <QTest>
+#include <QTestEventLoop>
#include <QtNetwork/qnetworkreply.h>
#include <QtNetwork/qnetworkrequest.h>
#include <QtNetwork/qnetworkaccessmanager.h>
diff --git a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro
deleted file mode 100644
index eccabd5d89..0000000000
--- a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-TEMPLATE = app
-TARGET = tst_bench_qfile_vs_qnetworkaccessmanager
-
-QT -= gui
-QT += network testlib
-
-CONFIG += release
-
-SOURCES += main.cpp
diff --git a/tests/benchmarks/network/access/qhttpheaders/CMakeLists.txt b/tests/benchmarks/network/access/qhttpheaders/CMakeLists.txt
new file mode 100644
index 0000000000..6e89259141
--- /dev/null
+++ b/tests/benchmarks/network/access/qhttpheaders/CMakeLists.txt
@@ -0,0 +1,10 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_internal_add_benchmark(tst_bench_qhttpheaders
+ SOURCES
+ tst_bench_qhttpheaders.cpp
+ LIBRARIES
+ Qt::Test
+ Qt::Network
+)
diff --git a/tests/benchmarks/network/access/qhttpheaders/tst_bench_qhttpheaders.cpp b/tests/benchmarks/network/access/qhttpheaders/tst_bench_qhttpheaders.cpp
new file mode 100644
index 0000000000..424b475b27
--- /dev/null
+++ b/tests/benchmarks/network/access/qhttpheaders/tst_bench_qhttpheaders.cpp
@@ -0,0 +1,266 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtNetwork/qhttpheaders.h>
+
+#include <QtCore/qstring.h>
+#include <QTest>
+
+using namespace Qt::StringLiterals;
+
+class tst_QHttpHeaders : public QObject
+{
+ Q_OBJECT
+private slots:
+ void initTestCase();
+
+ void append_enum();
+ void append_string_data();
+ void append_string();
+
+ void contains_enum_data() { setupBasicEnumData(); }
+ void contains_enum();
+ void contains_string_data() { setupBasicStringData(); }
+ void contains_string();
+
+ void values_enum_data() { setupBasicEnumData(); }
+ void values_enum();
+ void values_string_data() { setupBasicStringData(); }
+ void values_string();
+
+ void combinedValue_enum_data() { setupBasicEnumData(); }
+ void combinedValue_enum();
+ void combinedValue_string_data() { setupBasicStringData(); }
+ void combinedValue_string();
+
+ void removeAll_enum_data() { setupBasicEnumData(); }
+ void removeAll_enum();
+ void removeAll_string_data() { setupBasicStringData(); }
+ void removeAll_string();
+
+private:
+ using WKH = QHttpHeaders::WellKnownHeader;
+
+ void setupBasicEnumData()
+ {
+ QTest::addColumn<WKH>("name");
+ QTest::addColumn<bool>("exists");
+
+ QTest::newRow("Nonexistent enum") << WKH::CDNLoop << false;
+ QTest::newRow("Existent enum") << WKH::Accept << true;
+ }
+
+ void setupBasicStringData()
+ {
+ QTest::addColumn<QString>("name");
+ QTest::addColumn<bool>("exists");
+
+ QTest::newRow("Nonexistent string") << "cdn-loop" << false;
+ QTest::newRow("Existent wellknown string") << "accept" << true;
+ QTest::newRow("Existent custom string") << "customheader" << true;
+ }
+
+ const QString customNameLowCase = u"customm-name"_s; // Not a typo, same length as knownName
+ const QString customNameMixCase = u"Customm-Name"_s;
+ const QString knownNameLowCase = u"content-type"_s;
+ const QString knownNameMixCase = u"Content-Type"_s;
+ static constexpr QAnyStringView value1{"value1"};
+ static constexpr QAnyStringView value2{"value2"};
+ static constexpr QAnyStringView value3{"value3"};
+ static constexpr QAnyStringView value4{"value4"};
+
+ QHttpHeaders m_complexHeaders;
+ QHttpHeaders m_simpleHeaders;
+};
+
+void tst_QHttpHeaders::initTestCase()
+{
+ // A mix of known and custom headers in non-alphabetical order.
+ // "accept" (wellknown header) and "customheader" (custom header)
+ // have four values and in same order: value3, value1, value2, value4
+ m_complexHeaders.append(WKH::Upgrade, value1);
+ m_complexHeaders.append("timeout", value1);
+ m_complexHeaders.append(WKH::KeepAlive, value1);
+ m_complexHeaders.append("nel", value1);
+ m_complexHeaders.append(WKH::Date, value1);
+ m_complexHeaders.append("accept", value3);
+ m_complexHeaders.append("customheader", value3);
+ m_complexHeaders.append(WKH::SoapAction, value1);
+ m_complexHeaders.append("foobar", value1);
+ m_complexHeaders.append(WKH::Accept, value1);
+ m_complexHeaders.append("customheader", value1);
+ m_complexHeaders.append(WKH::Cookie, value1);
+ m_complexHeaders.append("cookie", value1);
+ m_complexHeaders.append(WKH::ProxyStatus, value1);
+ m_complexHeaders.append("cookie", value1);
+ m_complexHeaders.append(WKH::Accept, value2);
+ m_complexHeaders.append("customheader", value2);
+ m_complexHeaders.append(WKH::Authorization, value1);
+ m_complexHeaders.append("content-type", value1);
+ m_complexHeaders.append(WKH::Destination, value1);
+ m_complexHeaders.append("rover", value1);
+ m_complexHeaders.append("accept", value4);
+ m_complexHeaders.append("customheader", value4);
+ m_complexHeaders.append(WKH::Range, value1);
+ m_complexHeaders.append("destination", value1);
+ m_complexHeaders.append(WKH::Location, value1);
+ m_complexHeaders.append("font", value1);
+
+ // Simple headers with one value-less entry; having at least one entry ensures
+ // we don't include initial memory allocation into a test, and having
+ // as few as possible reduces cost of copying (header re-set)
+ m_simpleHeaders.append(WKH::Accept, "");
+}
+
+void tst_QHttpHeaders::append_enum()
+{
+ QHttpHeaders headers;
+ QBENCHMARK {
+ headers = m_simpleHeaders; // (Re-)set as we'll modify the headers
+ headers.append(WKH::Link, value1);
+ }
+ QCOMPARE(headers.size(), m_simpleHeaders.size() + 1);
+ QCOMPARE(headers.nameAt(headers.size() - 1), "link");
+}
+
+void tst_QHttpHeaders::append_string_data()
+{
+ QTest::addColumn<QString>("name");
+ QTest::newRow("Custom lowcase string") << customNameLowCase;
+ QTest::newRow("WellKnown lowcase string") << knownNameLowCase;
+ QTest::newRow("Custom mixcase string") << customNameMixCase;
+ QTest::newRow("WellKnown mixcase string") << knownNameMixCase;
+}
+
+void tst_QHttpHeaders::append_string()
+{
+ QFETCH(QString, name);
+
+ QHttpHeaders headers;
+ QBENCHMARK {
+ headers = m_simpleHeaders; // (Re-)set as we'll modify the headers
+ headers.append(name, value1);
+ }
+ QCOMPARE(headers.size(), m_simpleHeaders.size() + 1);
+ QCOMPARE(headers.nameAt(headers.size() - 1), name.toLower());
+}
+
+void tst_QHttpHeaders::contains_enum()
+{
+ QFETCH(WKH, name);
+ QFETCH(bool, exists);
+
+ bool result;
+ QBENCHMARK {
+ result = m_complexHeaders.contains(name);
+ }
+ QCOMPARE(result, exists);
+}
+
+void tst_QHttpHeaders::contains_string()
+{
+ QFETCH(QString, name);
+ QFETCH(bool, exists);
+
+ bool result;
+ QBENCHMARK {
+ result = m_complexHeaders.contains(name);
+ }
+ QCOMPARE(result, exists);
+}
+
+void tst_QHttpHeaders::values_enum()
+{
+ QFETCH(WKH, name);
+ QFETCH(bool, exists);
+
+ QList<QByteArray> result;
+ const QList<QByteArray> expectedResult{"value3", "value1", "value2", "value4"};
+ QBENCHMARK {
+ result = m_complexHeaders.values(name);
+ }
+ if (exists)
+ QCOMPARE(result, expectedResult);
+ else
+ QVERIFY(result.isEmpty());
+}
+
+void tst_QHttpHeaders::values_string()
+{
+ QFETCH(QString, name);
+ QFETCH(bool, exists);
+
+ QList<QByteArray> result;
+ const QList<QByteArray> expectedResult{"value3", "value1", "value2", "value4"};
+ QBENCHMARK {
+ result = m_complexHeaders.values(name);
+ }
+ if (exists)
+ QCOMPARE(result, expectedResult);
+ else
+ QVERIFY(result.isEmpty());
+}
+
+void tst_QHttpHeaders::combinedValue_enum()
+{
+ QFETCH(WKH, name);
+ QFETCH(bool, exists);
+
+ QByteArray result;
+ constexpr QByteArrayView expectedResult = "value3, value1, value2, value4";
+ QBENCHMARK {
+ result = m_complexHeaders.combinedValue(name);
+ }
+ if (exists)
+ QCOMPARE(result, expectedResult);
+ else
+ QVERIFY(result.isEmpty());
+}
+
+void tst_QHttpHeaders::combinedValue_string()
+{
+ QFETCH(QString, name);
+ QFETCH(bool, exists);
+
+ QByteArray result;
+ constexpr QByteArrayView expectedResult = "value3, value1, value2, value4";
+ QBENCHMARK {
+ result = m_complexHeaders.combinedValue(name);
+ }
+ if (exists)
+ QCOMPARE(result, expectedResult);
+ else
+ QVERIFY(result.isEmpty());
+}
+
+void tst_QHttpHeaders::removeAll_enum()
+{
+ QFETCH(WKH, name);
+ QFETCH(bool, exists);
+
+ QHttpHeaders headers = m_complexHeaders;
+ QCOMPARE(headers.contains(name), exists);
+ QBENCHMARK {
+ headers = m_complexHeaders; // Restore as we'll modify the headers
+ headers.removeAll(name);
+ }
+ QVERIFY(!headers.contains(name));
+}
+
+void tst_QHttpHeaders::removeAll_string()
+{
+ QFETCH(QString, name);
+ QFETCH(bool, exists);
+
+ QHttpHeaders headers = m_complexHeaders;
+ QCOMPARE(headers.contains(name), exists);
+ QBENCHMARK {
+ headers = m_complexHeaders; // Restore as we'll modify the headers
+ headers.removeAll(name);
+ }
+ QVERIFY(!headers.contains(name));
+}
+
+QTEST_MAIN(tst_QHttpHeaders)
+
+#include "tst_bench_qhttpheaders.moc"
diff --git a/tests/benchmarks/network/access/qnetworkdiskcache/CMakeLists.txt b/tests/benchmarks/network/access/qnetworkdiskcache/CMakeLists.txt
index e7f966da66..e049b221ff 100644
--- a/tests/benchmarks/network/access/qnetworkdiskcache/CMakeLists.txt
+++ b/tests/benchmarks/network/access/qnetworkdiskcache/CMakeLists.txt
@@ -1,16 +1,14 @@
-# Generated from qnetworkdiskcache.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qnetworkdiskcache Binary:
#####################################################################
-qt_add_benchmark(tst_bench_qnetworkdiskcache
+qt_internal_add_benchmark(tst_bench_qnetworkdiskcache
SOURCES
tst_qnetworkdiskcache.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qnetworkdiskcache.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro b/tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro
deleted file mode 100644
index a9e040bf1e..0000000000
--- a/tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-TEMPLATE = app
-TARGET = tst_bench_qnetworkdiskcache
-
-QT = core network testlib
-
-CONFIG += release
-
-SOURCES += tst_qnetworkdiskcache.cpp
diff --git a/tests/benchmarks/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp b/tests/benchmarks/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp
index 7142fdc130..c70248f590 100644
--- a/tests/benchmarks/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp
+++ b/tests/benchmarks/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QNetworkDiskCache>
#include <QNetworkCacheMetaData>
@@ -32,9 +7,10 @@
#include <QBuffer>
#include <QTextStream>
#include <QDebug>
-#include <QtTest/QtTest>
+#include <QTest>
#include <QIODevice>
#include <QStandardPaths>
+#include <QDirIterator>
diff --git a/tests/benchmarks/network/access/qnetworkreply/CMakeLists.txt b/tests/benchmarks/network/access/qnetworkreply/CMakeLists.txt
index feefb7c825..1d13192d97 100644
--- a/tests/benchmarks/network/access/qnetworkreply/CMakeLists.txt
+++ b/tests/benchmarks/network/access/qnetworkreply/CMakeLists.txt
@@ -1,18 +1,16 @@
-# Generated from qnetworkreply.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qnetworkreply Binary:
#####################################################################
-qt_add_benchmark(tst_bench_qnetworkreply
+qt_internal_add_benchmark(tst_bench_qnetworkreply
SOURCES
tst_qnetworkreply.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Network
Qt::NetworkPrivate
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qnetworkreply.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/network/access/qnetworkreply/qnetworkreply.pro b/tests/benchmarks/network/access/qnetworkreply/qnetworkreply.pro
deleted file mode 100644
index 2378cd4862..0000000000
--- a/tests/benchmarks/network/access/qnetworkreply/qnetworkreply.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-TEMPLATE = app
-TARGET = tst_bench_qnetworkreply
-
-QT -= gui
-QT += core-private network network-private testlib
-
-CONFIG += release
-
-SOURCES += tst_qnetworkreply.cpp
diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 559ed82834..bab2743513 100644
--- a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -1,35 +1,13 @@
-/****************************************************************************
-**
-** 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
// This file contains benchmarks for QNetworkReply functions.
#include <QDebug>
#include <qtest.h>
-#include <QtTest/QtTest>
+#include <QTest>
+#include <QTestEventLoop>
+#include <QSemaphore>
+#include <QTimer>
#include <QtCore/qrandom.h>
#include <QtCore/QElapsedTimer>
#include <QtNetwork/qnetworkreply.h>
@@ -41,11 +19,10 @@
#ifdef QT_BUILD_INTERNAL
#include <QtNetwork/private/qhostinfo_p.h>
-#ifndef QT_NO_OPENSSL
-#include <QtNetwork/private/qsslsocket_openssl_p.h>
-#endif
#endif
+using namespace std::chrono_literals;
+
Q_DECLARE_METATYPE(QSharedPointer<char>)
class TimedSender: public QThread
@@ -78,7 +55,7 @@ private slots:
}
protected:
- void run()
+ void run() override
{
QTcpServer server;
server.listen();
@@ -160,7 +137,6 @@ class ThreadedDataReader: public QThread
// used to make the constructor only return after the tcp server started listening
QSemaphore ready;
QTcpSocket *client;
- int timeout;
int port;
public:
qint64 transferRate;
@@ -174,7 +150,7 @@ public:
inline int serverPort() const { return port; }
protected:
- void run()
+ void run() override
{
QTcpServer server;
server.listen();
@@ -206,15 +182,15 @@ public:
DataGenerator() : state(Idle)
{ open(ReadOnly); }
- virtual bool isSequential() const { return true; }
- virtual qint64 bytesAvailable() const { return state == Started ? 1024*1024 : 0; }
+ bool isSequential() const override { return true; }
+ qint64 bytesAvailable() const override { return state == Started ? 1024*1024 : 0; }
public slots:
void start() { state = Started; emit readyRead(); }
void stop() { state = Stopped; emit readyRead(); }
protected:
- virtual qint64 readData(char *data, qint64 maxlen)
+ qint64 readData(char *data, qint64 maxlen) override
{
if (state == Stopped)
return -1; // EOF
@@ -223,8 +199,7 @@ protected:
memset(data, '@', maxlen);
return maxlen;
}
- virtual qint64 writeData(const char *, qint64)
- { return -1; }
+ qint64 writeData(const char *, qint64) override { return -1; }
};
class ThreadedDataReaderHttpServer: public QThread
@@ -233,7 +208,6 @@ class ThreadedDataReaderHttpServer: public QThread
// used to make the constructor only return after the tcp server started listening
QSemaphore ready;
QTcpSocket *client;
- int timeout;
int port;
public:
qint64 transferRate;
@@ -247,7 +221,7 @@ public:
inline int serverPort() const { return port; }
protected:
- void run()
+ void run() override
{
QTcpServer server;
server.listen();
@@ -302,28 +276,22 @@ public:
toBeGeneratedTotalCount = toBeGeneratedCount = size;
}
- virtual qint64 bytesAvailable() const
+ qint64 bytesAvailable() const override
{
return state == Started ? toBeGeneratedCount + QIODevice::bytesAvailable() : 0;
}
- virtual bool isSequential() const{
- return false;
- }
+ bool isSequential() const override { return false; }
- virtual bool reset() {
- return false;
- }
+ bool reset() override { return false; }
- qint64 size() const {
- return toBeGeneratedTotalCount;
- }
+ qint64 size() const override { return toBeGeneratedTotalCount; }
public slots:
void start() { state = Started; emit readyRead(); }
protected:
- virtual qint64 readData(char *data, qint64 maxlen)
+ qint64 readData(char *data, qint64 maxlen) override
{
memset(data, '@', maxlen);
@@ -341,8 +309,7 @@ protected:
return n;
}
- virtual qint64 writeData(const char *, qint64)
- { return -1; }
+ qint64 writeData(const char *, qint64) override { return -1; }
qint64 toBeGeneratedCount;
qint64 toBeGeneratedTotalCount;
@@ -491,7 +458,7 @@ void tst_qnetworkreply::httpLatency()
QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/"));
QNetworkReply* reply = manager.get(request);
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
- QTestEventLoop::instance().enterLoop(5);
+ QTestEventLoop::instance().enterLoop(5s);
QVERIFY(!QTestEventLoop::instance().timeout());
delete reply;
}
@@ -505,7 +472,7 @@ QPair<QNetworkReply *, qint64> tst_qnetworkreply::runGetRequest(
QNetworkReply *reply = manager->get(request);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors()));
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
- QTestEventLoop::instance().enterLoop(20);
+ QTestEventLoop::instance().enterLoop(20s);
qint64 elapsed = timer.elapsed();
return qMakePair(reply, elapsed);
}
@@ -536,7 +503,7 @@ void tst_qnetworkreply::echoPerformance()
QNetworkReply* reply = manager.post(request, data);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors()));
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
- QTestEventLoop::instance().enterLoop(5);
+ QTestEventLoop::instance().enterLoop(5s);
QVERIFY(!QTestEventLoop::instance().timeout());
QVERIFY(reply->error() == QNetworkReply::NoError);
delete reply;
@@ -545,7 +512,7 @@ void tst_qnetworkreply::echoPerformance()
void tst_qnetworkreply::preConnectEncrypted()
{
- QFETCH(int, sleepTime);
+ QFETCH(std::chrono::milliseconds, sleepTime);
QString hostName = QLatin1String("www.google.com");
QNetworkAccessManager manager;
@@ -576,7 +543,7 @@ void tst_qnetworkreply::preConnectEncrypted()
// now try to make the connection beforehand
manager.connectToHostEncrypted(hostName);
- QTestEventLoop::instance().enterLoopMSecs(sleepTime);
+ QTestEventLoop::instance().enterLoop(sleepTime);
// now make another request and hopefully use the existing connection
QPair<QNetworkReply *, qint64> preConnectResult = runGetRequest(&manager, request);
@@ -594,12 +561,12 @@ void tst_qnetworkreply::preConnectEncrypted()
void tst_qnetworkreply::preConnectEncrypted_data()
{
#ifndef QT_NO_OPENSSL
- QTest::addColumn<int>("sleepTime");
+ QTest::addColumn<std::chrono::milliseconds>("sleepTime");
// start a new normal request after preconnecting is done
- QTest::newRow("HTTPS-2secs") << 2000;
+ QTest::newRow("HTTPS-2secs") << 2000ms;
// start a new normal request while preconnecting is in-flight
- QTest::newRow("HTTPS-100ms") << 100;
+ QTest::newRow("HTTPS-100ms") << 100ms;
#endif // QT_NO_OPENSSL
}
@@ -641,9 +608,11 @@ void tst_qnetworkreply::uploadPerformance()
QVERIFY(!QTestEventLoop::instance().timeout());
}
+constexpr qint64 MiB = 1024 * 1024;
+
void tst_qnetworkreply::httpUploadPerformance()
{
- enum {UploadSize = 128*1024*1024}; // 128 MB
+ constexpr qint64 UploadSize = 128 * MiB;
ThreadedDataReaderHttpServer reader;
FixedSizeDataGenerator generator(UploadSize);
@@ -711,7 +680,7 @@ void tst_qnetworkreply::httpDownloadPerformance()
QFETCH(bool, serverSendsContentLength);
QFETCH(bool, chunkedEncoding);
- enum {UploadSize = 128*1024*1024}; // 128 MB
+ constexpr qint64 UploadSize = 128 * MiB;
HttpDownloadPerformanceServer server(UploadSize, serverSendsContentLength, chunkedEncoding);
@@ -948,9 +917,9 @@ void tst_qnetworkreply::preConnect()
manager.clearAccessCache();
// now try to make the connection beforehand
- QFETCH(int, sleepTime);
+ QFETCH(std::chrono::milliseconds, sleepTime);
manager.connectToHost(hostName);
- QTestEventLoop::instance().enterLoopMSecs(sleepTime);
+ QTestEventLoop::instance().enterLoop(sleepTime);
// now make another request and hopefully use the existing connection
QPair<QNetworkReply *, qint64> preConnectResult = runGetRequest(&manager, request);
diff --git a/tests/benchmarks/network/access/qnetworkreply_from_cache/CMakeLists.txt b/tests/benchmarks/network/access/qnetworkreply_from_cache/CMakeLists.txt
index 4f321d125a..3e9bf3d23e 100644
--- a/tests/benchmarks/network/access/qnetworkreply_from_cache/CMakeLists.txt
+++ b/tests/benchmarks/network/access/qnetworkreply_from_cache/CMakeLists.txt
@@ -1,13 +1,14 @@
-# Generated from qnetworkreply_from_cache.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qnetworkreply_from_cache Binary:
#####################################################################
-qt_add_benchmark(tst_bench_qnetworkreply_from_cache
+qt_internal_add_benchmark(tst_bench_qnetworkreply_from_cache
SOURCES
tst_qnetworkreply_from_cache.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
Qt::Test
)
diff --git a/tests/benchmarks/network/access/qnetworkreply_from_cache/qnetworkreply_from_cache.pro b/tests/benchmarks/network/access/qnetworkreply_from_cache/qnetworkreply_from_cache.pro
deleted file mode 100644
index e1fabffe4d..0000000000
--- a/tests/benchmarks/network/access/qnetworkreply_from_cache/qnetworkreply_from_cache.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-TARGET = tst_bench_qnetworkreply_from_cache
-QT = core network testlib
-SOURCES += tst_qnetworkreply_from_cache.cpp
diff --git a/tests/benchmarks/network/access/qnetworkreply_from_cache/tst_qnetworkreply_from_cache.cpp b/tests/benchmarks/network/access/qnetworkreply_from_cache/tst_qnetworkreply_from_cache.cpp
index ff8e49a9a8..c18daa8195 100644
--- a/tests/benchmarks/network/access/qnetworkreply_from_cache/tst_qnetworkreply_from_cache.cpp
+++ b/tests/benchmarks/network/access/qnetworkreply_from_cache/tst_qnetworkreply_from_cache.cpp
@@ -1,32 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
-** 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
+#include <QBuffer>
+#include <QTestEventLoop>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkDiskCache>
#include <QtNetwork/QNetworkReply>
@@ -38,14 +15,14 @@
class NetworkDiskCache : public QNetworkDiskCache
{
public:
- NetworkDiskCache(QObject *parent = 0)
+ NetworkDiskCache(QObject *parent = nullptr)
: QNetworkDiskCache(parent)
{
}
QByteArray cachedData;
- virtual QNetworkCacheMetaData metaData(const QUrl &url)
+ QNetworkCacheMetaData metaData(const QUrl &url) override
{
QNetworkCacheMetaData metaData;
if (!cachedData.isEmpty()) {
@@ -58,7 +35,7 @@ public:
return metaData;
}
- virtual QIODevice *data(const QUrl &/*url*/)
+ QIODevice *data(const QUrl &/*url*/) override
{
if (cachedData.isEmpty())
return 0;
diff --git a/tests/benchmarks/network/kernel/CMakeLists.txt b/tests/benchmarks/network/kernel/CMakeLists.txt
index 13a7caecdb..4310cdc1ee 100644
--- a/tests/benchmarks/network/kernel/CMakeLists.txt
+++ b/tests/benchmarks/network/kernel/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from kernel.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
if(QT_FEATURE_private_tests)
add_subdirectory(qhostinfo)
diff --git a/tests/benchmarks/network/kernel/kernel.pro b/tests/benchmarks/network/kernel/kernel.pro
deleted file mode 100644
index 7b18eefda2..0000000000
--- a/tests/benchmarks/network/kernel/kernel.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-TEMPLATE = subdirs
-
-qtConfig(private_tests): SUBDIRS += \
- qhostinfo
diff --git a/tests/benchmarks/network/kernel/qhostinfo/CMakeLists.txt b/tests/benchmarks/network/kernel/qhostinfo/CMakeLists.txt
index 0d847e60c5..83b63ca501 100644
--- a/tests/benchmarks/network/kernel/qhostinfo/CMakeLists.txt
+++ b/tests/benchmarks/network/kernel/qhostinfo/CMakeLists.txt
@@ -1,18 +1,16 @@
-# Generated from qhostinfo.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qhostinfo Binary:
#####################################################################
-qt_add_benchmark(tst_bench_qhostinfo
+qt_internal_add_benchmark(tst_bench_qhostinfo
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Network
Qt::NetworkPrivate
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qhostinfo.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/network/kernel/qhostinfo/main.cpp b/tests/benchmarks/network/kernel/qhostinfo/main.cpp
index 88112908d5..66e4f52ec2 100644
--- a/tests/benchmarks/network/kernel/qhostinfo/main.cpp
+++ b/tests/benchmarks/network/kernel/qhostinfo/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QDebug>
diff --git a/tests/benchmarks/network/kernel/qhostinfo/qhostinfo.pro b/tests/benchmarks/network/kernel/qhostinfo/qhostinfo.pro
deleted file mode 100644
index 41dae0051b..0000000000
--- a/tests/benchmarks/network/kernel/qhostinfo/qhostinfo.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-TEMPLATE = app
-TARGET = tst_bench_qhostinfo
-
-QT -= gui
-QT += core-private network network-private testlib
-
-CONFIG += release
-
-SOURCES += main.cpp
diff --git a/tests/benchmarks/network/network.pro b/tests/benchmarks/network/network.pro
deleted file mode 100644
index d53041eb61..0000000000
--- a/tests/benchmarks/network/network.pro
+++ /dev/null
@@ -1,19 +0,0 @@
-TEMPLATE = subdirs
-QT_FOR_CONFIG += network-private
-
-SUBDIRS = \
- access \
- kernel \
- socket
-
-TRUSTED_BENCHMARKS += \
- kernel/qhostinfo \
- socket/qtcpserver
-
-qtConfig(openssl) {
- SUBDIRS += ssl
- TRUSTED_BENCHMARKS += ssl/qsslsocket
-}
-
-include(../trusted-benchmarks.pri)
-
diff --git a/tests/benchmarks/network/socket/CMakeLists.txt b/tests/benchmarks/network/socket/CMakeLists.txt
index 6d54bc05f5..411a933dbb 100644
--- a/tests/benchmarks/network/socket/CMakeLists.txt
+++ b/tests/benchmarks/network/socket/CMakeLists.txt
@@ -1,4 +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(qtcpserver)
-add_subdirectory(qudpsocket)
diff --git a/tests/benchmarks/network/socket/qlocalsocket/CMakeLists.txt b/tests/benchmarks/network/socket/qlocalsocket/CMakeLists.txt
new file mode 100644
index 0000000000..660f2ee5b4
--- /dev/null
+++ b/tests/benchmarks/network/socket/qlocalsocket/CMakeLists.txt
@@ -0,0 +1,14 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## tst_bench_qlocalsocket Binary:
+#####################################################################
+
+qt_internal_add_benchmark(tst_bench_qlocalsocket
+ SOURCES
+ tst_qlocalsocket.cpp
+ LIBRARIES
+ Qt::Network
+ Qt::Test
+)
diff --git a/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp
new file mode 100644
index 0000000000..a28869f24c
--- /dev/null
+++ b/tests/benchmarks/network/socket/qlocalsocket/tst_qlocalsocket.cpp
@@ -0,0 +1,214 @@
+// 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/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
+
+private slots:
+ void pingPong_data();
+ void pingPong();
+ void dataExchange_data();
+ void dataExchange();
+};
+
+class ServerThread : public QThread
+{
+public:
+ QSemaphore running;
+
+ explicit ServerThread(int chunkSize)
+ {
+ buffer.resize(chunkSize);
+ }
+
+ void run() override
+ {
+ QLocalServer server;
+
+ connect(&server, &QLocalServer::newConnection, [this, &server]() {
+ auto socket = server.nextPendingConnection();
+
+ connect(socket, &QLocalSocket::readyRead, [this, socket]() {
+ const qint64 bytesAvailable = socket->bytesAvailable();
+ Q_ASSERT(bytesAvailable <= this->buffer.size());
+
+ QCOMPARE(socket->read(this->buffer.data(), bytesAvailable), bytesAvailable);
+ QCOMPARE(socket->write(this->buffer.data(), bytesAvailable), bytesAvailable);
+ });
+ });
+
+ // TODO QTBUG-95136: on failure, remove the socket file and retry.
+ QVERIFY2(server.listen("foo"), qPrintable(server.errorString()));
+
+ running.release();
+ exec();
+ }
+
+protected:
+ QByteArray buffer;
+};
+
+class SocketFactory : public QObject
+{
+ Q_OBJECT
+
+public:
+ bool stopped = false;
+
+ explicit SocketFactory(int chunkSize, int connections)
+ {
+ buffer.resize(chunkSize);
+ for (int i = 0; i < connections; ++i) {
+ QLocalSocket *socket = new QLocalSocket(this);
+ Q_CHECK_PTR(socket);
+
+ connect(this, &SocketFactory::start, [this, socket]() {
+ QCOMPARE(socket->write(this->buffer), this->buffer.size());
+ });
+
+ connect(socket, &QLocalSocket::readyRead, [i, this, socket]() {
+ const qint64 bytesAvailable = socket->bytesAvailable();
+ Q_ASSERT(bytesAvailable <= this->buffer.size());
+
+ QCOMPARE(socket->read(this->buffer.data(), bytesAvailable), bytesAvailable);
+ emit this->bytesReceived(i, bytesAvailable);
+
+ if (!this->stopped)
+ QCOMPARE(socket->write(this->buffer.data(), bytesAvailable), bytesAvailable);
+ });
+
+ 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);
+ }
+ }
+
+signals:
+ void start();
+ void bytesReceived(int channel, qint64 bytes);
+
+protected:
+ QByteArray buffer;
+};
+
+void tst_QLocalSocket::pingPong_data()
+{
+ QTest::addColumn<int>("connections");
+ for (int value : {10, 50, 100, 1000, 5000})
+ QTest::addRow("connections: %d", value) << value;
+}
+
+void tst_QLocalSocket::pingPong()
+{
+ QFETCH(int, connections);
+
+ const int iterations = 100000;
+ Q_ASSERT(iterations >= connections && connections > 0);
+
+ ServerThread serverThread(1);
+ serverThread.start();
+ // Wait for server to start.
+ QVERIFY(serverThread.running.tryAcquire(1, 3000));
+
+ SocketFactory factory(1, connections);
+ QTestEventLoop eventLoop;
+ QVector<qint64> bytesToRead;
+ QElapsedTimer timer;
+
+ bytesToRead.fill(iterations / connections, connections);
+ connect(&factory, &SocketFactory::bytesReceived,
+ [&bytesToRead, &connections, &factory, &eventLoop](int channel, qint64 bytes) {
+ Q_UNUSED(bytes);
+
+ if (--bytesToRead[channel] == 0 && --connections == 0) {
+ factory.stopped = true;
+ eventLoop.exitLoop();
+ }
+ });
+
+ timer.start();
+ emit factory.start();
+ // 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();
+}
+
+void tst_QLocalSocket::dataExchange_data()
+{
+ QTest::addColumn<int>("connections");
+ QTest::addColumn<int>("chunkSize");
+ for (int connections : {1, 5, 10}) {
+ for (int chunkSize : {100, 1000, 10000, 100000}) {
+ QTest::addRow("connections: %d, chunk size: %d",
+ connections, chunkSize) << connections << chunkSize;
+ }
+ }
+}
+
+void tst_QLocalSocket::dataExchange()
+{
+ QFETCH(int, connections);
+ QFETCH(int, chunkSize);
+
+ Q_ASSERT(chunkSize > 0 && connections > 0);
+ const auto timeToTest = 5000ms;
+
+ ServerThread serverThread(chunkSize);
+ serverThread.start();
+ // Wait for server to start.
+ QVERIFY(serverThread.running.tryAcquire(1, 3000));
+
+ SocketFactory factory(chunkSize, connections);
+ QTestEventLoop eventLoop;
+ qint64 totalReceived = 0;
+ QElapsedTimer timer;
+
+ connect(&factory, &SocketFactory::bytesReceived, [&](int channel, qint64 bytes) {
+ Q_UNUSED(channel);
+
+ totalReceived += bytes;
+ if (timer.elapsed() >= timeToTest.count()) {
+ factory.stopped = true;
+ eventLoop.exitLoop();
+ }
+ });
+
+ timer.start();
+ emit factory.start();
+ eventLoop.enterLoop(timeToTest * 2);
+
+ if (!QTest::currentTestFailed())
+ qDebug("Transfer rate: %.1f MB/s", totalReceived / 1048.576 / timer.elapsed());
+ serverThread.quit();
+ serverThread.wait();
+}
+
+QTEST_MAIN(tst_QLocalSocket)
+
+#include "tst_qlocalsocket.moc"
diff --git a/tests/benchmarks/network/socket/qtcpserver/CMakeLists.txt b/tests/benchmarks/network/socket/qtcpserver/CMakeLists.txt
index 7f20130b37..ae2f491df0 100644
--- a/tests/benchmarks/network/socket/qtcpserver/CMakeLists.txt
+++ b/tests/benchmarks/network/socket/qtcpserver/CMakeLists.txt
@@ -1,16 +1,14 @@
-# Generated from qtcpserver.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qtcpserver Binary:
#####################################################################
-qt_add_benchmark(tst_bench_qtcpserver
+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/qtcpserver.pro b/tests/benchmarks/network/socket/qtcpserver/qtcpserver.pro
deleted file mode 100644
index ebf1891433..0000000000
--- a/tests/benchmarks/network/socket/qtcpserver/qtcpserver.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-TEMPLATE = app
-TARGET = tst_bench_qtcpserver
-
-QT -= gui
-QT += network testlib
-
-CONFIG += release
-
-SOURCES += tst_qtcpserver.cpp
diff --git a/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp
index f35e5cd3db..68d60261d5 100644
--- a/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp
+++ b/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp
@@ -1,32 +1,7 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
#include <QtCore/QElapsedTimer>
#include <qglobal.h>
#include <qcoreapplication.h>
diff --git a/tests/benchmarks/network/socket/qudpsocket/CMakeLists.txt b/tests/benchmarks/network/socket/qudpsocket/CMakeLists.txt
index ff357490e7..0a39e8fc0c 100644
--- a/tests/benchmarks/network/socket/qudpsocket/CMakeLists.txt
+++ b/tests/benchmarks/network/socket/qudpsocket/CMakeLists.txt
@@ -1,16 +1,14 @@
-# Generated from qudpsocket.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qudpsocket Binary:
#####################################################################
-qt_add_benchmark(tst_bench_qudpsocket
+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/qudpsocket.pro b/tests/benchmarks/network/socket/qudpsocket/qudpsocket.pro
deleted file mode 100644
index 8df5340e2e..0000000000
--- a/tests/benchmarks/network/socket/qudpsocket/qudpsocket.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-TEMPLATE = app
-TARGET = tst_bench_qudpsocket
-
-QT = network testlib
-
-CONFIG += release
-
-SOURCES += tst_qudpsocket.cpp
diff --git a/tests/benchmarks/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/benchmarks/network/socket/qudpsocket/tst_qudpsocket.cpp
index e6dbbf9dfa..d3ef636e74 100644
--- a/tests/benchmarks/network/socket/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/benchmarks/network/socket/qudpsocket/tst_qudpsocket.cpp
@@ -1,32 +1,7 @@
-/****************************************************************************
-**
-** 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 <QtTest/QtTest>
+#include <QTest>
#include <QtCore/qglobal.h>
#include <QtCore/qcoreapplication.h>
#include <QtNetwork/qudpsocket.h>
diff --git a/tests/benchmarks/network/socket/socket.pro b/tests/benchmarks/network/socket/socket.pro
deleted file mode 100644
index d428a4d973..0000000000
--- a/tests/benchmarks/network/socket/socket.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = \
- qtcpserver \
- qudpsocket
diff --git a/tests/benchmarks/network/ssl/CMakeLists.txt b/tests/benchmarks/network/ssl/CMakeLists.txt
index bc469359f1..579816e153 100644
--- a/tests/benchmarks/network/ssl/CMakeLists.txt
+++ b/tests/benchmarks/network/ssl/CMakeLists.txt
@@ -1,3 +1,4 @@
-# Generated from ssl.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qsslsocket)
diff --git a/tests/benchmarks/network/ssl/qsslsocket/CMakeLists.txt b/tests/benchmarks/network/ssl/qsslsocket/CMakeLists.txt
index f8e546c970..70e4448b73 100644
--- a/tests/benchmarks/network/ssl/qsslsocket/CMakeLists.txt
+++ b/tests/benchmarks/network/ssl/qsslsocket/CMakeLists.txt
@@ -1,16 +1,14 @@
-# Generated from qsslsocket.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qsslsocket Binary:
#####################################################################
-qt_add_benchmark(tst_bench_qsslsocket
+qt_internal_add_benchmark(tst_bench_qsslsocket
SOURCES
tst_qsslsocket.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qsslsocket.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/network/ssl/qsslsocket/qsslsocket.pro b/tests/benchmarks/network/ssl/qsslsocket/qsslsocket.pro
deleted file mode 100644
index a67c0d66df..0000000000
--- a/tests/benchmarks/network/ssl/qsslsocket/qsslsocket.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-TEMPLATE = app
-TARGET = tst_bench_qsslsocket
-
-QT -= gui
-QT += network testlib
-
-CONFIG += release
-
-SOURCES += tst_qsslsocket.cpp
diff --git a/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp
index d44556db58..fd5f49863a 100644
--- a/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp
+++ b/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp
@@ -1,32 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
#include <qcoreapplication.h>
#include <qsslconfiguration.h>
diff --git a/tests/benchmarks/network/ssl/ssl.pro b/tests/benchmarks/network/ssl/ssl.pro
deleted file mode 100644
index 0c8529d2f7..0000000000
--- a/tests/benchmarks/network/ssl/ssl.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = \
- qsslsocket