diff options
Diffstat (limited to 'tests/benchmarks/network/access')
20 files changed, 360 insertions, 281 deletions
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/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 3c651b16dd..7f8b09ef0e 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> @@ -76,13 +51,14 @@ void tst_QDecompressHelper::decompress() file.seek(0); QDecompressHelper helper; helper.setEncoding(encoding); + helper.setDecompressedSafetyCheckThreshold(-1); QVERIFY(helper.isValid()); helper.feed(file.readAll()); qsizetype bytes = 0; + QByteArray out(64 * 1024, Qt::Uninitialized); while (helper.hasData()) { - QByteArray out(64 * 1024, Qt::Uninitialized); qsizetype bytesRead = helper.read(out.data(), out.size()); bytes += bytesRead; } 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; |