From 38be0d13830efd2d98281c645c3a60afe05ffece Mon Sep 17 00:00:00 2001 From: Qt by Nokia Date: Wed, 27 Apr 2011 12:05:43 +0200 Subject: Initial import from the monolithic Qt. This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12 --- tests/benchmarks/network/access/access.pro | 5 + .../access/qfile_vs_qnetworkaccessmanager/main.cpp | 196 ++++++ .../qfile_vs_qnetworkaccessmanager.pro | 13 + .../access/qnetworkdiskcache/qnetworkdiskcache.pro | 15 + .../qnetworkdiskcache/tst_qnetworkdiskcache.cpp | 435 ++++++++++++ .../network/access/qnetworkreply/qnetworkreply.pro | 13 + .../access/qnetworkreply/tst_qnetworkreply.cpp | 744 +++++++++++++++++++++ tests/benchmarks/network/kernel/kernel.pro | 3 + tests/benchmarks/network/kernel/qhostinfo/main.cpp | 120 ++++ .../network/kernel/qhostinfo/qhostinfo.pro | 13 + tests/benchmarks/network/network.pro | 13 + .../network/socket/qtcpserver/qtcpserver.pro | 13 + .../network/socket/qtcpserver/tst_qtcpserver.cpp | 280 ++++++++ tests/benchmarks/network/socket/socket.pro | 3 + .../network/ssl/qsslsocket/qsslsocket.pro | 13 + .../network/ssl/qsslsocket/tst_qsslsocket.cpp | 114 ++++ tests/benchmarks/network/ssl/ssl.pro | 3 + 17 files changed, 1996 insertions(+) create mode 100644 tests/benchmarks/network/access/access.pro create mode 100644 tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp create mode 100644 tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro create mode 100644 tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro create mode 100644 tests/benchmarks/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp create mode 100644 tests/benchmarks/network/access/qnetworkreply/qnetworkreply.pro create mode 100644 tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp create mode 100644 tests/benchmarks/network/kernel/kernel.pro create mode 100644 tests/benchmarks/network/kernel/qhostinfo/main.cpp create mode 100755 tests/benchmarks/network/kernel/qhostinfo/qhostinfo.pro create mode 100644 tests/benchmarks/network/network.pro create mode 100644 tests/benchmarks/network/socket/qtcpserver/qtcpserver.pro create mode 100644 tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp create mode 100644 tests/benchmarks/network/socket/socket.pro create mode 100644 tests/benchmarks/network/ssl/qsslsocket/qsslsocket.pro create mode 100644 tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp create mode 100644 tests/benchmarks/network/ssl/ssl.pro (limited to 'tests/benchmarks/network') diff --git a/tests/benchmarks/network/access/access.pro b/tests/benchmarks/network/access/access.pro new file mode 100644 index 0000000000..6cbd3671b8 --- /dev/null +++ b/tests/benchmarks/network/access/access.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs +SUBDIRS = \ + qfile_vs_qnetworkaccessmanager \ + qnetworkreply \ + qnetworkdiskcache diff --git a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp new file mode 100644 index 0000000000..c31e6dcb92 --- /dev/null +++ b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + +class qfile_vs_qnetworkaccessmanager : public QObject +{ + Q_OBJECT + // do not use on symbian.. 100 MB is too large.. + // but.. this is a manual test anyway, so :) +protected: + void qnamFileRead_iteration(QNetworkAccessManager &manager, QNetworkRequest &request); + void qnamImmediateFileRead_iteration(QNetworkAccessManager &manager, QNetworkRequest &request); + void qfileFileRead_iteration(); + static const int iterations = 10; + +private slots: + void qnamFileRead(); + void qnamImmediateFileRead(); + void qfileFileRead(); + + void initTestCase(); + void cleanupTestCase(); + +public: + qint64 size; + QTemporaryFile testFile; + + qfile_vs_qnetworkaccessmanager() : QObject(), size(0) {}; +}; + +void qfile_vs_qnetworkaccessmanager::initTestCase() +{ + testFile.open(); + QByteArray qba(1*1024*1024, 'x'); // 1 MB +#ifdef Q_OS_SYMBIAN + for (int i = 0; i < 10; i++) { // for Symbian only 10 MB +#else + for (int i = 0; i < 100; i++) { +#endif + testFile.write(qba); + testFile.flush(); + size += qba.size(); + } // 100 MB or 10 MB + testFile.reset(); +} + +void qfile_vs_qnetworkaccessmanager::cleanupTestCase() +{ + +} + +void qfile_vs_qnetworkaccessmanager::qnamFileRead_iteration(QNetworkAccessManager &manager, QNetworkRequest &request) +{ + QNetworkReply* reply = manager.get(request); + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + QByteArray qba = reply->readAll(); + delete reply; +} + +void qfile_vs_qnetworkaccessmanager::qnamFileRead() +{ + QNetworkAccessManager manager; + QTime t; + QNetworkRequest request(QUrl::fromLocalFile(testFile.fileName())); + + // do 3 dry runs for cache warmup + qnamFileRead_iteration(manager, request); + qnamFileRead_iteration(manager, request); + qnamFileRead_iteration(manager, request); + + t.start(); + // 10 real runs + QBENCHMARK_ONCE { + for (int i = 0; i < iterations; i++) { + qnamFileRead_iteration(manager, request); + } + } + + qint64 elapsed = t.elapsed(); + qDebug() << endl << "Finished!"; + qDebug() << "Bytes:" << size; + qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec"; +} + +void qfile_vs_qnetworkaccessmanager::qnamImmediateFileRead_iteration(QNetworkAccessManager &manager, QNetworkRequest &request) +{ + QNetworkReply* reply = manager.get(request); + QVERIFY(reply->isFinished()); // should be like that! + QByteArray qba = reply->readAll(); + delete reply; +} + +void qfile_vs_qnetworkaccessmanager::qnamImmediateFileRead() +{ + QNetworkAccessManager manager; + QTime t; + QNetworkRequest request(QUrl::fromLocalFile(testFile.fileName())); + + // do 3 dry runs for cache warmup + qnamImmediateFileRead_iteration(manager, request); + qnamImmediateFileRead_iteration(manager, request); + qnamImmediateFileRead_iteration(manager, request); + + t.start(); + // 10 real runs + QBENCHMARK_ONCE { + for (int i = 0; i < iterations; i++) { + qnamImmediateFileRead_iteration(manager, request); + } + } + + qint64 elapsed = t.elapsed(); + qDebug() << endl << "Finished!"; + qDebug() << "Bytes:" << size; + qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec"; +} + +void qfile_vs_qnetworkaccessmanager::qfileFileRead_iteration() +{ + testFile.reset(); + QByteArray qba = testFile.readAll(); +} + +void qfile_vs_qnetworkaccessmanager::qfileFileRead() +{ + QTime t; + + // do 3 dry runs for cache warmup + qfileFileRead_iteration(); + qfileFileRead_iteration(); + qfileFileRead_iteration(); + + t.start(); + // 10 real runs + QBENCHMARK_ONCE { + for (int i = 0; i < iterations; i++) { + qfileFileRead_iteration(); + } + } + + qint64 elapsed = t.elapsed(); + qDebug() << endl << "Finished!"; + qDebug() << "Bytes:" << size; + qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec"; +} + +QTEST_MAIN(qfile_vs_qnetworkaccessmanager) + +#include "main.moc" 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 new file mode 100644 index 0000000000..0949af790a --- /dev/null +++ b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro @@ -0,0 +1,13 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_qfile_vs_qnetworkaccessmanager +DEPENDPATH += . +INCLUDEPATH += . + +QT -= gui +QT += network + +CONFIG += release + +# Input +SOURCES += main.cpp diff --git a/tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro b/tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro new file mode 100644 index 0000000000..7f665b332e --- /dev/null +++ b/tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro @@ -0,0 +1,15 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_qnetworkdiskcache +DEPENDPATH += . +INCLUDEPATH += . + +QT += gui # for QDesktopServices +QT += network testlib + +CONFIG += release + +# Input +SOURCES += tst_qnetworkdiskcache.cpp + + diff --git a/tests/benchmarks/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp b/tests/benchmarks/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp new file mode 100644 index 0000000000..55cbf55bed --- /dev/null +++ b/tests/benchmarks/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp @@ -0,0 +1,435 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +enum Numbers { NumFakeCacheObjects = 200, //entries in pre-populated cache + NumInsertions = 100, //insertions to be timed + NumRemovals = 100, //removals to be timed + NumReadContent = 100, //meta requests to be timed + HugeCacheLimit = 50*1024*1024, // max size for a big cache + TinyCacheLimit = 1*512*1024}; // max size for a tiny cache + +const QString fakeURLbase = "http://127.0.0.1/fake/"; +//fake HTTP body aka payload +const QByteArray payload("Qt rocks!"); + +class tst_qnetworkdiskcache : public QObject +{ + Q_OBJECT +private: + void injectFakeData(); + void insertOneItem(); + bool isUrlCached(quint32 id); + void cleanRecursive(QString &path); + void cleanupCacheObject(); + void initCacheObject(); + QString cacheDir; + QNetworkDiskCache *cache; + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + + void timeInsertion_data(); + void timeInsertion(); + void timeRead_data(); + void timeRead(); + void timeRemoval_data(); + void timeRemoval(); + + void timeExpiration_data(); + void timeExpiration(); +}; + + +void tst_qnetworkdiskcache::initTestCase() +{ + cache = 0; +} + + +void tst_qnetworkdiskcache::cleanupTestCase() +{ + cleanupCacheObject(); + cleanRecursive(cacheDir); +} + +void tst_qnetworkdiskcache::timeInsertion_data() +{ + QTest::addColumn("cacheRootDirectory"); + + QString cacheLoc = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); + QTest::newRow("QDesktopServices Cache Location") << cacheLoc; +#ifdef Q_OS_SYMBIAN + if (QDir::drives().contains(QFileInfo("E:\\"))) + QTest::newRow("Symbian E: drive") << cacheLoc.replace(0, 1, QString("E")); +#endif + +} + +//This functions times an insert() operation. +//You can run it after populating the cache with +//fake data so that more realistic performance +//estimates are obtained. +void tst_qnetworkdiskcache::timeInsertion() +{ + + QFETCH(QString, cacheRootDirectory); + + cacheDir = QString( cacheRootDirectory + QDir::separator() + "man_qndc"); + QDir d; + qDebug() << "Setting cache directory to = " << d.absoluteFilePath(cacheDir); + + //Housekeeping + cleanRecursive(cacheDir); // slow op. + initCacheObject(); + + cache->setCacheDirectory(cacheDir); + cache->setMaximumCacheSize(qint64(HugeCacheLimit)); + cache->clear(); + + //populate some fake data to simulate partially full cache + injectFakeData(); // SLOW + + //Sanity-check that the first URL that we insert below isn't already in there. + QVERIFY(isUrlCached(NumFakeCacheObjects) == false); + + // IMPORTANT: max cache size should be HugeCacheLimit, to avoid evictions below + //time insertion of previously-uncached URLs. + QBENCHMARK_ONCE { + for (quint32 i = NumFakeCacheObjects; i < (NumFakeCacheObjects + NumInsertions); i++) { + //prepare metata for url + QNetworkCacheMetaData meta; + QString fakeURL; + QTextStream stream(&fakeURL); + stream << fakeURLbase << i; + QUrl url(fakeURL); + meta.setUrl(url); + meta.setSaveToDisk(true); + + //commit payload and metadata to disk + QIODevice *device = cache->prepare(meta); + device->write(payload); + cache->insert(device); + } + } + + //SLOW cleanup + cleanupCacheObject(); + cleanRecursive(cacheDir); + +} + +void tst_qnetworkdiskcache::timeRead_data() +{ + QTest::addColumn("cacheRootDirectory"); + + QString cacheLoc = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); + QTest::newRow("QDesktopServices Cache Location") << cacheLoc; +#ifdef Q_OS_SYMBIAN + if (QDir::drives().contains(QFileInfo("E:\\"))) + QTest::newRow("Symbian E: drive") << cacheLoc.replace(0, 1, QString("E")); +#endif + +} + +//Times metadata as well payload lookup +// i.e metaData(), rawHeaders() and data() +void tst_qnetworkdiskcache::timeRead() +{ + + QFETCH(QString, cacheRootDirectory); + + cacheDir = QString( cacheRootDirectory + QDir::separator() + "man_qndc"); + QDir d; + qDebug() << "Setting cache directory to = " << d.absoluteFilePath(cacheDir); + + //Housekeeping + cleanRecursive(cacheDir); // slow op. + initCacheObject(); + cache->setCacheDirectory(cacheDir); + cache->setMaximumCacheSize(qint64(HugeCacheLimit)); + cache->clear(); + + //populate some fake data to simulate partially full cache + injectFakeData(); + + //Entries in the cache should be > what we try to remove + QVERIFY(NumFakeCacheObjects > NumReadContent); + + //time metadata lookup of previously inserted URL. + QBENCHMARK_ONCE { + for (quint32 i = 0; i < NumReadContent; i++) { + QString fakeURL; + QTextStream stream(&fakeURL); + stream << fakeURLbase << i; + QUrl url(fakeURL); + + QNetworkCacheMetaData qndc = cache->metaData(url); + QVERIFY(qndc.isValid()); // we must have read the metadata + + QNetworkCacheMetaData::RawHeaderList raw(qndc.rawHeaders()); + QVERIFY(raw.size()); // we must have parsed the headers from the meta + + QIODevice *iodevice(cache->data(url)); + QVERIFY(iodevice); //must not be NULL + iodevice->close(); + delete iodevice; + } + } + + //Cleanup (slow) + cleanupCacheObject(); + cleanRecursive(cacheDir); + +} + +void tst_qnetworkdiskcache::timeRemoval_data() +{ + QTest::addColumn("cacheRootDirectory"); + + QString cacheLoc = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); + QTest::newRow("QDesktopServices Cache Location") << cacheLoc; +#ifdef Q_OS_SYMBIAN + if (QDir::drives().contains(QFileInfo("E:\\"))) + QTest::newRow("Symbian E: drive") << cacheLoc.replace(0, 1, QString("E")); +#endif + +} + +void tst_qnetworkdiskcache::timeRemoval() +{ + + QFETCH(QString, cacheRootDirectory); + + cacheDir = QString( cacheRootDirectory + QDir::separator() + "man_qndc"); + QDir d; + qDebug() << "Setting cache directory to = " << d.absoluteFilePath(cacheDir); + + //Housekeeping + initCacheObject(); + cleanRecursive(cacheDir); // slow op. + cache->setCacheDirectory(cacheDir); + // Make max cache size HUGE, so that evictions don't happen below + cache->setMaximumCacheSize(qint64(HugeCacheLimit)); + cache->clear(); + + //populate some fake data to simulate partially full cache + injectFakeData(); + + //Sanity-check that the URL is already in there somewhere + QVERIFY(isUrlCached(NumRemovals-1) == true); + //Entries in the cache should be > what we try to remove + QVERIFY(NumFakeCacheObjects > NumRemovals); + + //time removal of previously-inserted URL. + QBENCHMARK_ONCE { + for (quint32 i = 0; i < NumRemovals; i++) { + QString fakeURL; + QTextStream stream(&fakeURL); + stream << fakeURLbase << i; + QUrl url(fakeURL); + cache->remove(url); + } + } + + //Cleanup (slow) + cleanupCacheObject(); + cleanRecursive(cacheDir); + +} + +void tst_qnetworkdiskcache::timeExpiration_data() +{ + QTest::addColumn("cacheRootDirectory"); + + QString cacheLoc = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); + QTest::newRow("QDesktopServices Cache Location") << cacheLoc; +#ifdef Q_OS_SYMBIAN + if (QDir::drives().contains(QFileInfo("E:\\"))) + QTest::newRow("Symbian E: drive") << cacheLoc.replace(0, 1, QString("E")); +#endif + +} +void tst_qnetworkdiskcache::timeExpiration() +{ + + QFETCH(QString, cacheRootDirectory); + + cacheDir = QString( cacheRootDirectory + QDir::separator() + "man_qndc"); + QDir d; + qDebug() << "Setting cache directory to = " << d.absoluteFilePath(cacheDir); + + //Housekeeping + initCacheObject(); + cleanRecursive(cacheDir); // slow op. + cache->setCacheDirectory(cacheDir); + // Make max cache size HUGE, so that evictions don't happen below + cache->setMaximumCacheSize(qint64(HugeCacheLimit)); + cache->clear(); + + //populate some fake data to simulate partially full cache + injectFakeData(); + + //Sanity-check that the URL is already in there somewhere + QVERIFY(isUrlCached(NumRemovals-1) == true); + //Entries in the cache should be > what we try to remove + QVERIFY(NumFakeCacheObjects > NumRemovals); + + + //Set cache limit lower, so this force 1 round of eviction + cache->setMaximumCacheSize(qint64(TinyCacheLimit)); + + //time insertions of additional content, which is likely to internally cause evictions + QBENCHMARK_ONCE { + for (quint32 i = NumFakeCacheObjects; i < (NumFakeCacheObjects + NumInsertions); i++) { + //prepare metata for url + QNetworkCacheMetaData meta; + QString fakeURL; + QTextStream stream(&fakeURL); + stream << fakeURLbase << i;//codescanner::leave + QUrl url(fakeURL); + meta.setUrl(url); + meta.setSaveToDisk(true); + + //commit payload and metadata to disk + QIODevice *device = cache->prepare(meta); + device->write(payload); + cache->insert(device); // this should trigger evictions, if TinyCacheLimit is small enough + } + } + + //Cleanup (slow) + cleanupCacheObject(); + cleanRecursive(cacheDir); + +} +// This function simulates a partially or fully occupied disk cache +// like a normal user of a cache might encounter is real-life browsing. +// The point of this is to trigger degradation in file-system and media performance +// that occur due to the quantity and layout of data. +void tst_qnetworkdiskcache::injectFakeData() +{ + + QNetworkCacheMetaData::RawHeaderList headers; + headers.append(qMakePair(QByteArray("X-TestHeader"),QByteArray("HeaderValue"))); + + + //Prep cache dir with fake data using QNetworkDiskCache APIs + for (quint32 i = 0; i < NumFakeCacheObjects; i++) { + + //prepare metata for url + QNetworkCacheMetaData meta; + QString fakeURL; + QTextStream stream(&fakeURL); + stream << fakeURLbase << i; + QUrl url(fakeURL); + meta.setUrl(url); + meta.setRawHeaders(headers); + meta.setSaveToDisk(true); + + //commit payload and metadata to disk + QIODevice *device = cache->prepare(meta); + device->write(payload); + cache->insert(device); + } + +} + + +// Checks if the fake URL #id is already cached or not. +bool tst_qnetworkdiskcache::isUrlCached(quint32 id) +{ + QString str; + QTextStream stream(&str); + stream << fakeURLbase << id; + QUrl url(str); + QIODevice *iod = cache->data(url); + return ((iod == 0) ? false : true) ; + +} + + +// Utility function for recursive directory cleanup. +void tst_qnetworkdiskcache::cleanRecursive(QString &path) +{ + QDirIterator it(path, QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); + while (it.hasNext()) { + QFile f(it.next()); + bool err = f.remove(); + Q_UNUSED(err); + } + + QDirIterator it2(path, QDir::AllDirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); + while (it2.hasNext()) { + QString s(it2.next()); + QDir dir(s); + dir.rmdir(s); + } +} + +void tst_qnetworkdiskcache::cleanupCacheObject() +{ + delete cache; + cache = 0; +} + +void tst_qnetworkdiskcache::initCacheObject() +{ + + cache = new QNetworkDiskCache(); + +} +QTEST_MAIN(tst_qnetworkdiskcache) +#include "tst_qnetworkdiskcache.moc" diff --git a/tests/benchmarks/network/access/qnetworkreply/qnetworkreply.pro b/tests/benchmarks/network/access/qnetworkreply/qnetworkreply.pro new file mode 100644 index 0000000000..9d96dc7025 --- /dev/null +++ b/tests/benchmarks/network/access/qnetworkreply/qnetworkreply.pro @@ -0,0 +1,13 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_qnetworkreply +DEPENDPATH += . +INCLUDEPATH += . + +QT -= gui +QT += network + +CONFIG += release + +# Input +SOURCES += tst_qnetworkreply.cpp diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp new file mode 100644 index 0000000000..9a07aa4940 --- /dev/null +++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -0,0 +1,744 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +// This file contains benchmarks for QNetworkReply functions. + +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../../../auto/network-settings.h" + + +Q_DECLARE_METATYPE(QSharedPointer) + +class TimedSender: public QThread +{ + Q_OBJECT + qint64 totalBytes; + QSemaphore ready; + QByteArray dataToSend; + QTcpSocket *client; + int timeout; + int port; +public: + int transferRate; + TimedSender(int ms) + : totalBytes(0), timeout(ms), port(-1), transferRate(-1) + { + dataToSend = QByteArray(16*1024, '@'); + start(); + ready.acquire(); + } + + inline int serverPort() const { return port; } + +private slots: + void writeMore() + { + while (client->bytesToWrite() < 128 * 1024) { + writePacket(dataToSend); + } + } + +protected: + void run() + { + QTcpServer server; + server.listen(); + port = server.serverPort(); + ready.release(); + + server.waitForNewConnection(-1); + client = server.nextPendingConnection(); + + writeMore(); + connect(client, SIGNAL(bytesWritten(qint64)), SLOT(writeMore()), Qt::DirectConnection); + + QEventLoop eventLoop; + QTimer::singleShot(timeout, &eventLoop, SLOT(quit())); + + QTime timer; + timer.start(); + eventLoop.exec(); + disconnect(client, SIGNAL(bytesWritten(qint64)), this, 0); + + // wait for the connection to shut down + client->disconnectFromHost(); + if (!client->waitForDisconnected(10000)) + return; + + transferRate = totalBytes * 1000 / timer.elapsed(); + qDebug() << "TimedSender::run" << "receive rate:" << (transferRate / 1024) << "kB/s in" + << timer.elapsed() << "ms"; + } + + void writePacket(const QByteArray &array) + { + client->write(array); + totalBytes += array.size(); + } +}; + + +class QNetworkReplyPtr: public QSharedPointer +{ +public: + inline QNetworkReplyPtr(QNetworkReply *ptr = 0) + : QSharedPointer(ptr) + { } + + inline operator QNetworkReply *() const { return data(); } +}; + + +class DataReader: public QObject +{ + Q_OBJECT +public: + qint64 totalBytes; + QByteArray data; + QIODevice *device; + bool accumulate; + DataReader(QIODevice *dev, bool acc = true) : totalBytes(0), device(dev), accumulate(acc) + { + connect(device, SIGNAL(readyRead()), SLOT(doRead())); + } + +public slots: + void doRead() + { + QByteArray buffer; + buffer.resize(device->bytesAvailable()); + qint64 bytesRead = device->read(buffer.data(), device->bytesAvailable()); + if (bytesRead == -1) { + QTestEventLoop::instance().exitLoop(); + return; + } + buffer.truncate(bytesRead); + totalBytes += bytesRead; + + if (accumulate) + data += buffer; + } +}; + +class ThreadedDataReader: public QThread +{ + Q_OBJECT + // used to make the constructor only return after the tcp server started listening + QSemaphore ready; + QTcpSocket *client; + int timeout; + int port; +public: + qint64 transferRate; + ThreadedDataReader() + : port(-1), transferRate(-1) + { + start(); + ready.acquire(); + } + + inline int serverPort() const { return port; } + +protected: + void run() + { + QTcpServer server; + server.listen(); + port = server.serverPort(); + ready.release(); + + server.waitForNewConnection(-1); + client = server.nextPendingConnection(); + + QEventLoop eventLoop; + DataReader reader(client, false); + QObject::connect(client, SIGNAL(disconnected()), &eventLoop, SLOT(quit())); + + QTime timer; + timer.start(); + eventLoop.exec(); + qint64 elapsed = timer.elapsed(); + + transferRate = reader.totalBytes * 1000 / elapsed; + qDebug() << "ThreadedDataReader::run" << "send rate:" << (transferRate / 1024) << "kB/s in" << elapsed << "msec"; + } +}; + +class DataGenerator: public QIODevice +{ + Q_OBJECT + enum { Idle, Started, Stopped } state; +public: + DataGenerator() : state(Idle) + { open(ReadOnly); } + + virtual bool isSequential() const { return true; } + virtual qint64 bytesAvailable() const { 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) + { + if (state == Stopped) + return -1; // EOF + + // return as many bytes as are wanted + memset(data, '@', maxlen); + return maxlen; + } + virtual qint64 writeData(const char *, qint64) + { return -1; } +}; + +class ThreadedDataReaderHttpServer: public QThread +{ + Q_OBJECT + // used to make the constructor only return after the tcp server started listening + QSemaphore ready; + QTcpSocket *client; + int timeout; + int port; +public: + qint64 transferRate; + ThreadedDataReaderHttpServer() + : port(-1), transferRate(-1) + { + start(); + ready.acquire(); + } + + inline int serverPort() const { return port; } + +protected: + void run() + { + QTcpServer server; + server.listen(); + port = server.serverPort(); + ready.release(); + + QVERIFY(server.waitForNewConnection(10*1000)); + client = server.nextPendingConnection(); + + // read lines until we read the empty line seperating HTTP request from HTTP request body + do { + if (client->canReadLine()) { + QString line = client->readLine(); + if (line == "\n" || line == "\r\n") + break; // empty line + } + if (!client->waitForReadyRead(10*1000)) { + client->close(); + return; + } + } while (client->state() == QAbstractSocket::ConnectedState); + + client->write("HTTP/1.0 200 OK\r\n"); + client->write("Content-length: 0\r\n"); + client->write("\r\n"); + client->flush(); + + QCoreApplication::processEvents(); + + QEventLoop eventLoop; + DataReader reader(client, false); + QObject::connect(client, SIGNAL(disconnected()), &eventLoop, SLOT(quit())); + + QTime timer; + timer.start(); + eventLoop.exec(); + qint64 elapsed = timer.elapsed(); + + transferRate = reader.totalBytes * 1000 / elapsed; + qDebug() << "ThreadedDataReaderHttpServer::run" << "send rate:" << (transferRate / 1024) << "kB/s in" << elapsed << "msec"; + } +}; + + +class FixedSizeDataGenerator : public QIODevice +{ + Q_OBJECT + enum { Idle, Started, Stopped } state; +public: + FixedSizeDataGenerator(qint64 size) : state(Idle) + { open(ReadOnly | Unbuffered); + toBeGeneratedTotalCount = toBeGeneratedCount = size; + } + + virtual qint64 bytesAvailable() const + { + return state == Started ? toBeGeneratedCount + QIODevice::bytesAvailable() : 0; + } + + virtual bool isSequential() const{ + return false; + } + + virtual bool reset() const{ + return false; + } + + qint64 size() const { + return toBeGeneratedTotalCount; + } + +public slots: + void start() { state = Started; emit readyRead(); } + +protected: + virtual qint64 readData(char *data, qint64 maxlen) + { + memset(data, '@', maxlen); + + if (toBeGeneratedCount <= 0) { + return -1; + } + + qint64 n = qMin(maxlen, toBeGeneratedCount); + toBeGeneratedCount -= n; + + if (toBeGeneratedCount <= 0) { + // make sure this is a queued connection! + emit readChannelFinished(); + } + + return n; + } + virtual qint64 writeData(const char *, qint64) + { return -1; } + + qint64 toBeGeneratedCount; + qint64 toBeGeneratedTotalCount; +}; + +class HttpDownloadPerformanceServer : QObject { + Q_OBJECT; + qint64 dataSize; + qint64 dataSent; + QTcpServer server; + QTcpSocket *client; + bool serverSendsContentLength; + bool chunkedEncoding; + +public: + HttpDownloadPerformanceServer (qint64 ds, bool sscl, bool ce) : dataSize(ds), dataSent(0), + client(0), serverSendsContentLength(sscl), chunkedEncoding(ce) { + server.listen(); + connect(&server, SIGNAL(newConnection()), this, SLOT(newConnectionSlot())); + } + + int serverPort() { + return server.serverPort(); + } + +public slots: + + void newConnectionSlot() { + client = server.nextPendingConnection(); + client->setParent(this); + connect(client, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); + connect(client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot(qint64))); + } + + void readyReadSlot() { + client->readAll(); + client->write("HTTP/1.0 200 OK\n"); + if (serverSendsContentLength) + client->write(QString("Content-Length: " + QString::number(dataSize) + "\n").toAscii()); + if (chunkedEncoding) + client->write(QString("Transfer-Encoding: chunked\n").toAscii()); + client->write("Connection: close\n\n"); + } + + void bytesWrittenSlot(qint64 amount) { + Q_UNUSED(amount); + if (dataSent == dataSize && client) { + // close eventually + + // chunked encoding: we have to send a last "empty" chunk + if (chunkedEncoding) + client->write(QString("0\r\n\r\n").toAscii()); + + client->disconnectFromHost(); + server.close(); + client = 0; + return; + } + + // send data + if (client && client->bytesToWrite() < 100*1024 && dataSent < dataSize) { + qint64 amount = qMin(qint64(16*1024), dataSize - dataSent); + QByteArray data(amount, '@'); + + if (chunkedEncoding) { + client->write(QString(QString("%1").arg(amount,0,16).toUpper() + "\r\n").toAscii()); + client->write(data.constData(), amount); + client->write(QString("\r\n").toAscii()); + } else { + client->write(data.constData(), amount); + } + + dataSent += amount; + } + } +}; + +class HttpDownloadPerformanceClient : QObject { + Q_OBJECT; + QIODevice *device; + public: + HttpDownloadPerformanceClient (QIODevice *dev) : device(dev){ + connect(dev, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); + } + + public slots: + void readyReadSlot() { + device->readAll(); + } + +}; + + + + +class tst_qnetworkreply : public QObject +{ + Q_OBJECT + + QNetworkAccessManager manager; +private slots: + void httpLatency(); + +#ifndef QT_NO_OPENSSL + void echoPerformance_data(); + void echoPerformance(); +#endif + + void downloadPerformance(); + void uploadPerformance(); + void performanceControlRate(); + void httpUploadPerformance(); + void httpDownloadPerformance_data(); + void httpDownloadPerformance(); + void httpDownloadPerformanceDownloadBuffer_data(); + void httpDownloadPerformanceDownloadBuffer(); +}; + +void tst_qnetworkreply::httpLatency() +{ + QNetworkAccessManager manager; + QBENCHMARK{ + 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); + QVERIFY(!QTestEventLoop::instance().timeout()); + delete reply; + } +} + +#ifndef QT_NO_OPENSSL +void tst_qnetworkreply::echoPerformance_data() +{ + QTest::addColumn("ssl"); + QTest::newRow("no_ssl") << false; + QTest::newRow("ssl") << true; +} + +void tst_qnetworkreply::echoPerformance() +{ + QFETCH(bool, ssl); + QNetworkAccessManager manager; + QNetworkRequest request(QUrl((ssl ? "https://" : "http://") + QtNetworkSettings::serverName() + "/qtest/cgi-bin/echo.cgi")); + + QByteArray data; + data.resize(1024*1024*10); // 10 MB + // init with garbage. needed so ssl cannot compress it in an efficient way. + for (int i = 0; i < data.size() / sizeof(int); i++) { + int r = qrand(); + data.data()[i*sizeof(int)] = r; + } + + QBENCHMARK{ + QNetworkReply* reply = manager.post(request, data); + connect(reply, SIGNAL(sslErrors( const QList &)), reply, SLOT(ignoreSslErrors())); + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); + QTestEventLoop::instance().enterLoop(5); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(reply->error() == QNetworkReply::NoError); + delete reply; + } +} +#endif + +void tst_qnetworkreply::downloadPerformance() +{ + // unlike the above function, this one tries to send as fast as possible + // and measures how fast it was. + TimedSender sender(5000); + QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(sender.serverPort()) + "/?bare=1"); + QNetworkReplyPtr reply = manager.get(request); + DataReader reader(reply, false); + + QTime loopTime; + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + loopTime.start(); + QTestEventLoop::instance().enterLoop(40); + int elapsedTime = loopTime.elapsed(); + sender.wait(); + + qint64 receivedBytes = reader.totalBytes; + qDebug() << "tst_QNetworkReply::downloadPerformance" << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and" + << elapsedTime << "ms"; +} + +void tst_qnetworkreply::uploadPerformance() +{ + ThreadedDataReader reader; + DataGenerator generator; + + + QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1"); + QNetworkReplyPtr reply = manager.put(request, &generator); + generator.start(); + connect(&reader, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTimer::singleShot(5000, &generator, SLOT(stop())); + + QTestEventLoop::instance().enterLoop(30); + QCOMPARE(reply->error(), QNetworkReply::NoError); + QVERIFY(!QTestEventLoop::instance().timeout()); +} + +void tst_qnetworkreply::httpUploadPerformance() +{ +#if defined(Q_OS_SYMBIAN) || defined(Q_WS_WINCE_WM) + // SHow some mercy for non-desktop platform/s + enum {UploadSize = 4*1024*1024}; // 4 MB +#else + enum {UploadSize = 128*1024*1024}; // 128 MB +#endif + ThreadedDataReaderHttpServer reader; + FixedSizeDataGenerator generator(UploadSize); + + QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1")); + request.setHeader(QNetworkRequest::ContentLengthHeader,UploadSize); + + QNetworkReplyPtr reply = manager.put(request, &generator); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + + QTime time; + generator.start(); + time.start(); + QTestEventLoop::instance().enterLoop(40); + qint64 elapsed = time.elapsed(); + reader.exit(); + reader.wait(); + QVERIFY(reply->isFinished()); + QCOMPARE(reply->error(), QNetworkReply::NoError); + QVERIFY(!QTestEventLoop::instance().timeout()); + + qDebug() << "tst_QNetworkReply::httpUploadPerformance" << elapsed << "msec, " + << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec"; +} + + +void tst_qnetworkreply::performanceControlRate() +{ + // this is a control comparison for the other two above + // it does the same thing, but instead bypasses the QNetworkAccess system + qDebug() << "The following are the maximum transfer rates that we can get in this system" + " (bypassing QNetworkAccess)"; + + TimedSender sender(5000); + QTcpSocket sink; + sink.connectToHost("127.0.0.1", sender.serverPort()); + DataReader reader(&sink, false); + + QTime loopTime; + connect(&sink, SIGNAL(disconnected()), &QTestEventLoop::instance(), SLOT(exitLoop())); + loopTime.start(); + QTestEventLoop::instance().enterLoop(40); + int elapsedTime = loopTime.elapsed(); + sender.wait(); + + qint64 receivedBytes = reader.totalBytes; + qDebug() << "tst_QNetworkReply::performanceControlRate" << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and" + << elapsedTime << "ms"; +} + +void tst_qnetworkreply::httpDownloadPerformance_data() +{ + QTest::addColumn("serverSendsContentLength"); + QTest::addColumn("chunkedEncoding"); + + QTest::newRow("Server sends no Content-Length") << false << false; + QTest::newRow("Server sends Content-Length") << true << false; + QTest::newRow("Server uses chunked encoding") << false << true; + +} + +void tst_qnetworkreply::httpDownloadPerformance() +{ + QFETCH(bool, serverSendsContentLength); + QFETCH(bool, chunkedEncoding); +#if defined(Q_OS_SYMBIAN) || defined(Q_WS_WINCE_WM) + // Show some mercy to non-desktop platform/s + enum {UploadSize = 4*1024*1024}; // 4 MB +#else + enum {UploadSize = 128*1024*1024}; // 128 MB +#endif + HttpDownloadPerformanceServer server(UploadSize, serverSendsContentLength, chunkedEncoding); + + QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(server.serverPort()) + "/?bare=1")); + QNetworkReplyPtr reply = manager.get(request); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); + HttpDownloadPerformanceClient client(reply); + + QTime time; + time.start(); + QTestEventLoop::instance().enterLoop(40); + QCOMPARE(reply->error(), QNetworkReply::NoError); + QVERIFY(!QTestEventLoop::instance().timeout()); + + qint64 elapsed = time.elapsed(); + qDebug() << "tst_QNetworkReply::httpDownloadPerformance" << elapsed << "msec, " + << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec"; +}; + +enum HttpDownloadPerformanceDownloadBufferTestType { + JustDownloadBuffer, + DownloadBufferButUseRead, + NoDownloadBuffer +}; +Q_DECLARE_METATYPE(HttpDownloadPerformanceDownloadBufferTestType) + +class HttpDownloadPerformanceClientDownloadBuffer : QObject { + Q_OBJECT +private: + HttpDownloadPerformanceDownloadBufferTestType testType; + QNetworkReply *reply; + qint64 uploadSize; + QList bytesAvailableList; +public: + HttpDownloadPerformanceClientDownloadBuffer (QNetworkReply *reply, HttpDownloadPerformanceDownloadBufferTestType testType, qint64 uploadSize) + : testType(testType), reply(reply), uploadSize(uploadSize) + { + connect(reply, SIGNAL(finished()), this, SLOT(finishedSlot())); + } + + public slots: + void finishedSlot() { + if (testType == JustDownloadBuffer) { + // We have a download buffer and use it. This should be the fastest benchmark result. + QVariant downloadBufferAttribute = reply->attribute(QNetworkRequest::DownloadBufferAttribute); + QSharedPointer data = downloadBufferAttribute.value >(); + } else if (testType == DownloadBufferButUseRead) { + // We had a download buffer but we benchmark here the "legacy" read() way to access it + char* replyData = (char*) qMalloc(uploadSize); + QVERIFY(reply->read(replyData, uploadSize) == uploadSize); + qFree(replyData); + } else if (testType == NoDownloadBuffer) { + // We did not have a download buffer but we still need to benchmark having the data, e.g. reading it all. + // This should be the slowest benchmark result. + char* replyData = (char*) qMalloc(uploadSize); + QVERIFY(reply->read(replyData, uploadSize) == uploadSize); + qFree(replyData); + } + + QMetaObject::invokeMethod(&QTestEventLoop::instance(), "exitLoop", Qt::QueuedConnection); + } +}; + +void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer_data() +{ + QTest::addColumn("testType"); + + QTest::newRow("use-download-buffer") << JustDownloadBuffer; + QTest::newRow("use-download-buffer-but-use-read") << DownloadBufferButUseRead; + QTest::newRow("do-not-use-download-buffer") << NoDownloadBuffer; +} + +// Please note that the whole "zero copy" download buffer API is private right now. Do not use it. +void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer() +{ + QFETCH(HttpDownloadPerformanceDownloadBufferTestType, testType); + + // On my Linux Desktop the results are already visible with 128 kB, however we use this to have good results. +#if defined(Q_OS_SYMBIAN) || defined(Q_WS_WINCE_WM) + // Show some mercy to non-desktop platform/s + enum {UploadSize = 4*1024*1024}; // 4 MB +#else + enum {UploadSize = 32*1024*1024}; // 32 MB +#endif + + HttpDownloadPerformanceServer server(UploadSize, true, false); + + QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(server.serverPort()) + "/?bare=1")); + if (testType == JustDownloadBuffer || testType == DownloadBufferButUseRead) + request.setAttribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute, 1024*1024*128); // 128 MB is max allowed + + QNetworkAccessManager manager; + QNetworkReplyPtr reply = manager.get(request); + + HttpDownloadPerformanceClientDownloadBuffer client(reply, testType, UploadSize); + + QBENCHMARK_ONCE { + QTestEventLoop::instance().enterLoop(40); + QCOMPARE(reply->error(), QNetworkReply::NoError); + QVERIFY(reply->isFinished()); + QVERIFY(!QTestEventLoop::instance().timeout()); + } +} + +QTEST_MAIN(tst_qnetworkreply) + +#include "tst_qnetworkreply.moc" diff --git a/tests/benchmarks/network/kernel/kernel.pro b/tests/benchmarks/network/kernel/kernel.pro new file mode 100644 index 0000000000..1ec3071f03 --- /dev/null +++ b/tests/benchmarks/network/kernel/kernel.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = \ + qhostinfo diff --git a/tests/benchmarks/network/kernel/qhostinfo/main.cpp b/tests/benchmarks/network/kernel/qhostinfo/main.cpp new file mode 100644 index 0000000000..c12ebc3044 --- /dev/null +++ b/tests/benchmarks/network/kernel/qhostinfo/main.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include +#include + +#include +#include + +#include "private/qhostinfo_p.h" + +class tst_qhostinfo : public QObject +{ + Q_OBJECT +public slots: + void init(); +private slots: + void lookupSpeed_data(); + void lookupSpeed(); +}; + +class SignalReceiver : public QObject +{ + Q_OBJECT +public: + SignalReceiver(int nrc) : receiveCount(0), neededReceiveCount(nrc) {}; + int receiveCount; + int neededReceiveCount; +public slots: + void resultsReady(const QHostInfo) { + receiveCount++; + if (receiveCount == neededReceiveCount) + QTestEventLoop::instance().exitLoop(); + } +}; + +void tst_qhostinfo::init() +{ + // delete the cache so inidividual testcase results are independant from each other + qt_qhostinfo_clear_cache(); +} + +void tst_qhostinfo::lookupSpeed_data() +{ + QTest::addColumn("cache"); + QTest::newRow("WithCache") << true; + QTest::newRow("WithoutCache") << false; +} + +void tst_qhostinfo::lookupSpeed() +{ + QFETCH(bool, cache); + qt_qhostinfo_enable_cache(cache); + + QStringList hostnameList; + hostnameList << "www.ovi.com" << "www.nokia.com" << "qt.nokia.com" << "www.trolltech.com" << "troll.no" + << "www.qtcentre.org" << "forum.nokia.com" << "www.forum.nokia.com" << "wiki.forum.nokia.com" + << "www.nokia.no" << "nokia.de" << "127.0.0.1" << "----"; + // also add some duplicates: + hostnameList << "www.nokia.com" << "127.0.0.1" << "www.trolltech.com"; + // and some more + hostnameList << hostnameList; + + const int COUNT = hostnameList.size(); + + SignalReceiver receiver(COUNT); + + QBENCHMARK { + for (int i = 0; i < hostnameList.size(); i++) + QHostInfo::lookupHost(hostnameList.at(i), &receiver, SLOT(resultsReady(const QHostInfo))); + QTestEventLoop::instance().enterLoop(20); + QVERIFY(!QTestEventLoop::instance().timeout()); + } +} + + +QTEST_MAIN(tst_qhostinfo) + +#include "main.moc" diff --git a/tests/benchmarks/network/kernel/qhostinfo/qhostinfo.pro b/tests/benchmarks/network/kernel/qhostinfo/qhostinfo.pro new file mode 100755 index 0000000000..e621d50e45 --- /dev/null +++ b/tests/benchmarks/network/kernel/qhostinfo/qhostinfo.pro @@ -0,0 +1,13 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_qhostinfo +DEPENDPATH += . +INCLUDEPATH += . + +QT -= gui +QT += network + +CONFIG += release + +# Input +SOURCES += main.cpp diff --git a/tests/benchmarks/network/network.pro b/tests/benchmarks/network/network.pro new file mode 100644 index 0000000000..692a0a1b7e --- /dev/null +++ b/tests/benchmarks/network/network.pro @@ -0,0 +1,13 @@ +TEMPLATE = subdirs +SUBDIRS = \ + access \ + kernel \ + ssl \ + socket + +TRUSTED_BENCHMARKS += \ + kernel/qhostinfo \ + socket/qtcpserver \ + ssl/qsslsocket + +include(../trusted-benchmarks.pri) \ No newline at end of file diff --git a/tests/benchmarks/network/socket/qtcpserver/qtcpserver.pro b/tests/benchmarks/network/socket/qtcpserver/qtcpserver.pro new file mode 100644 index 0000000000..e5b9346954 --- /dev/null +++ b/tests/benchmarks/network/socket/qtcpserver/qtcpserver.pro @@ -0,0 +1,13 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_qtcpserver +DEPENDPATH += . +INCLUDEPATH += . + +QT -= gui +QT += network + +CONFIG += release + +# Input +SOURCES += tst_qtcpserver.cpp diff --git a/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp new file mode 100644 index 0000000000..aaccad0d61 --- /dev/null +++ b/tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp @@ -0,0 +1,280 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Just to get Q_OS_SYMBIAN +#include + +#include + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +Q_DECLARE_METATYPE(QNetworkProxy) +Q_DECLARE_METATYPE(QList) + +#include "../../../../auto/network-settings.h" + +//TESTED_CLASS= +//TESTED_FILES= + +class tst_QTcpServer : public QObject +{ + Q_OBJECT + +public: + tst_QTcpServer(); + virtual ~tst_QTcpServer(); + + +public slots: + void initTestCase_data(); + void init(); + void cleanup(); +private slots: + void ipv4LoopbackPerformanceTest(); + void ipv6LoopbackPerformanceTest(); + void ipv4PerformanceTest(); +}; + +tst_QTcpServer::tst_QTcpServer() +{ + Q_SET_DEFAULT_IAP +} + +tst_QTcpServer::~tst_QTcpServer() +{ +} + +void tst_QTcpServer::initTestCase_data() +{ + QTest::addColumn("setProxy"); + QTest::addColumn("proxyType"); + + QTest::newRow("WithoutProxy") << false << 0; + QTest::newRow("WithSocks5Proxy") << true << int(QNetworkProxy::Socks5Proxy); +} + +void tst_QTcpServer::init() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) { + QFETCH_GLOBAL(int, proxyType); + if (proxyType == QNetworkProxy::Socks5Proxy) { + QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080)); + } + } +} + +void tst_QTcpServer::cleanup() +{ + QNetworkProxy::setApplicationProxy(QNetworkProxy::DefaultProxy); +} + +//---------------------------------------------------------------------------------- +void tst_QTcpServer::ipv4LoopbackPerformanceTest() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + return; + + QTcpServer server; + QVERIFY(server.listen(QHostAddress::LocalHost)); + + QVERIFY(server.isListening()); + + QTcpSocket clientA; + clientA.connectToHost(QHostAddress::LocalHost, server.serverPort()); + QVERIFY(clientA.waitForConnected(5000)); + QVERIFY(clientA.state() == QAbstractSocket::ConnectedState); + + QVERIFY(server.waitForNewConnection()); + QTcpSocket *clientB = server.nextPendingConnection(); + QVERIFY(clientB); + + QByteArray buffer(16384, '@'); + QTime stopWatch; + stopWatch.start(); + qlonglong totalWritten = 0; + while (stopWatch.elapsed() < 5000) { + QVERIFY(clientA.write(buffer.data(), buffer.size()) > 0); + clientA.flush(); + totalWritten += buffer.size(); + while (clientB->waitForReadyRead(100)) { + if (clientB->bytesAvailable() == 16384) + break; + } + clientB->read(buffer.data(), buffer.size()); + clientB->write(buffer.data(), buffer.size()); + clientB->flush(); + totalWritten += buffer.size(); + while (clientA.waitForReadyRead(100)) { + if (clientA.bytesAvailable() == 16384) + break; + } + clientA.read(buffer.data(), buffer.size()); + } + + qDebug("\t\t%s: %.1fMB/%.1fs: %.1fMB/s", + server.serverAddress().toString().toLatin1().constData(), + totalWritten / (1024.0 * 1024.0), + stopWatch.elapsed() / 1000.0, + (totalWritten / (stopWatch.elapsed() / 1000.0)) / (1024 * 1024)); + + delete clientB; +} + +//---------------------------------------------------------------------------------- +void tst_QTcpServer::ipv6LoopbackPerformanceTest() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + return; +#if defined(Q_WS_WINCE_WM) + QSKIP("WinCE WM: Not yet supported", SkipAll); +#endif + +#if defined(Q_OS_SYMBIAN) + QSKIP("Symbian: IPv6 is not yet supported", SkipAll); +#endif + QTcpServer server; + if (!server.listen(QHostAddress::LocalHostIPv6, 0)) { + QVERIFY(server.serverError() == QAbstractSocket::UnsupportedSocketOperationError); + } else { + QTcpSocket clientA; + clientA.connectToHost(server.serverAddress(), server.serverPort()); + QVERIFY(clientA.waitForConnected(5000)); + + QVERIFY(server.waitForNewConnection(5000)); + QTcpSocket *clientB = server.nextPendingConnection(); + QVERIFY(clientB); + + QByteArray buffer(16384, '@'); + QTime stopWatch; + stopWatch.start(); + qlonglong totalWritten = 0; + while (stopWatch.elapsed() < 5000) { + clientA.write(buffer.data(), buffer.size()); + clientA.flush(); + totalWritten += buffer.size(); + while (clientB->waitForReadyRead(100)) { + if (clientB->bytesAvailable() == 16384) + break; + } + clientB->read(buffer.data(), buffer.size()); + clientB->write(buffer.data(), buffer.size()); + clientB->flush(); + totalWritten += buffer.size(); + while (clientA.waitForReadyRead(100)) { + if (clientA.bytesAvailable() == 16384) + break; + } + clientA.read(buffer.data(), buffer.size()); + } + + qDebug("\t\t%s: %.1fMB/%.1fs: %.1fMB/s", + server.serverAddress().toString().toLatin1().constData(), + totalWritten / (1024.0 * 1024.0), + stopWatch.elapsed() / 1000.0, + (totalWritten / (stopWatch.elapsed() / 1000.0)) / (1024 * 1024)); + delete clientB; + } +} + +//---------------------------------------------------------------------------------- +void tst_QTcpServer::ipv4PerformanceTest() +{ + QTcpSocket probeSocket; + probeSocket.connectToHost(QtNetworkSettings::serverName(), 143); + QVERIFY(probeSocket.waitForConnected(5000)); + + QTcpServer server; + QVERIFY(server.listen(probeSocket.localAddress(), 0)); + + QTcpSocket clientA; + clientA.connectToHost(server.serverAddress(), server.serverPort()); + QVERIFY(clientA.waitForConnected(5000)); + + QVERIFY(server.waitForNewConnection(5000)); + QTcpSocket *clientB = server.nextPendingConnection(); + QVERIFY(clientB); + + QByteArray buffer(16384, '@'); + QTime stopWatch; + stopWatch.start(); + qlonglong totalWritten = 0; + while (stopWatch.elapsed() < 5000) { + qlonglong writtenA = clientA.write(buffer.data(), buffer.size()); + clientA.flush(); + totalWritten += buffer.size(); + while (clientB->waitForReadyRead(100)) { + if (clientB->bytesAvailable() == writtenA) + break; + } + clientB->read(buffer.data(), buffer.size()); + qlonglong writtenB = clientB->write(buffer.data(), buffer.size()); + clientB->flush(); + totalWritten += buffer.size(); + while (clientA.waitForReadyRead(100)) { + if (clientA.bytesAvailable() == writtenB) + break; + } + clientA.read(buffer.data(), buffer.size()); + } + + qDebug("\t\t%s: %.1fMB/%.1fs: %.1fMB/s", + probeSocket.localAddress().toString().toLatin1().constData(), + totalWritten / (1024.0 * 1024.0), + stopWatch.elapsed() / 1000.0, + (totalWritten / (stopWatch.elapsed() / 1000.0)) / (1024 * 1024)); + + delete clientB; +} + +QTEST_MAIN(tst_QTcpServer) +#include "tst_qtcpserver.moc" diff --git a/tests/benchmarks/network/socket/socket.pro b/tests/benchmarks/network/socket/socket.pro new file mode 100644 index 0000000000..2d676a2c6e --- /dev/null +++ b/tests/benchmarks/network/socket/socket.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = \ + qtcpserver diff --git a/tests/benchmarks/network/ssl/qsslsocket/qsslsocket.pro b/tests/benchmarks/network/ssl/qsslsocket/qsslsocket.pro new file mode 100644 index 0000000000..da34a028d3 --- /dev/null +++ b/tests/benchmarks/network/ssl/qsslsocket/qsslsocket.pro @@ -0,0 +1,13 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_qsslsocket +DEPENDPATH += . +INCLUDEPATH += . + +QT -= gui +QT += network + +CONFIG += release + +# Input +SOURCES += tst_qsslsocket.cpp diff --git a/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp new file mode 100644 index 0000000000..041b61a50a --- /dev/null +++ b/tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include +#include + + +#include "../../../../auto/network-settings.h" + +//TESTED_CLASS= +//TESTED_FILES= + +class tst_QSslSocket : public QObject +{ + Q_OBJECT + +public: + tst_QSslSocket(); + virtual ~tst_QSslSocket(); + + +public slots: + void initTestCase_data(); + void init(); + void cleanup(); +private slots: + void rootCertLoading(); + void systemCaCertificates(); +}; + +tst_QSslSocket::tst_QSslSocket() +{ +} + +tst_QSslSocket::~tst_QSslSocket() +{ +} + +void tst_QSslSocket::initTestCase_data() +{ +} + +void tst_QSslSocket::init() +{ +} + +void tst_QSslSocket::cleanup() +{ +} + +//---------------------------------------------------------------------------------- + +void tst_QSslSocket::rootCertLoading() +{ + QBENCHMARK_ONCE { + QSslSocket socket; + socket.connectToHostEncrypted(QtNetworkSettings::serverName(), 443); + socket.waitForEncrypted(); + } +} + +void tst_QSslSocket::systemCaCertificates() +{ + // The results of this test change if the benchmarking system changes too much. + // Therefore this benchmark is only good for manual regression checking between + // Qt versions. + QBENCHMARK_ONCE { + QList list = QSslSocket::systemCaCertificates(); + } +} + +QTEST_MAIN(tst_QSslSocket) +#include "tst_qsslsocket.moc" diff --git a/tests/benchmarks/network/ssl/ssl.pro b/tests/benchmarks/network/ssl/ssl.pro new file mode 100644 index 0000000000..0c8529d2f7 --- /dev/null +++ b/tests/benchmarks/network/ssl/ssl.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = \ + qsslsocket -- cgit v1.2.3