summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp')
-rw-r--r--tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp101
1 files changed, 35 insertions, 66 deletions
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);