From 4b684fb390c0bb63c8a68b6281fd5a77629a94d2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 16 Apr 2010 12:13:57 +0200 Subject: Split the remote and the local tests in two, in preparation for SSL tests --- .../network_remote_stresstest.pro | 8 + .../tst_network_remote_stresstest.cpp | 435 +++++++++++++++++++++ .../manual/network_remote_stresstest/url-list.qrc | 5 + .../manual/network_remote_stresstest/url-list.txt | 64 +++ .../network_stresstest/tst_network_stresstest.cpp | 282 +------------ tests/manual/network_stresstest/url-list.txt | 64 --- tests/manual/network_stresstest/wwwfiles.qrc | 1 - 7 files changed, 529 insertions(+), 330 deletions(-) create mode 100644 tests/manual/network_remote_stresstest/network_remote_stresstest.pro create mode 100644 tests/manual/network_remote_stresstest/tst_network_remote_stresstest.cpp create mode 100644 tests/manual/network_remote_stresstest/url-list.qrc create mode 100644 tests/manual/network_remote_stresstest/url-list.txt delete mode 100644 tests/manual/network_stresstest/url-list.txt diff --git a/tests/manual/network_remote_stresstest/network_remote_stresstest.pro b/tests/manual/network_remote_stresstest/network_remote_stresstest.pro new file mode 100644 index 0000000..9ed1090 --- /dev/null +++ b/tests/manual/network_remote_stresstest/network_remote_stresstest.pro @@ -0,0 +1,8 @@ +load(qttest_p4) + +QT = core network + +SOURCES += tst_network_remote_stresstest.cpp + +RESOURCES += url-list.qrc + diff --git a/tests/manual/network_remote_stresstest/tst_network_remote_stresstest.cpp b/tests/manual/network_remote_stresstest/tst_network_remote_stresstest.cpp new file mode 100644 index 0000000..dca09c1 --- /dev/null +++ b/tests/manual/network_remote_stresstest/tst_network_remote_stresstest.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 +#include + +#ifdef QT_BUILD_INTERNAL +# include +#endif + +#include +#ifdef Q_OS_UNIX +# include +# include +# include +# include +# include +# include +# include +# include +# include + +typedef int SOCKET; +# define INVALID_SOCKET -1 +# define SOCKET_ERROR -1 + +#elif defined(Q_OS_WIN) +# include +#endif + +Q_DECLARE_METATYPE(QVector) + +class tst_NetworkRemoteStressTest : public QObject +{ + Q_OBJECT +public: + enum { AttemptCount = 100 }; + tst_NetworkRemoteStressTest(); + + qint64 byteCounter; + QNetworkAccessManager manager; + QVector httpUrls; + bool intermediateDebug; + +private: + void clearManager(); + +public slots: + void initTestCase_data(); + void init(); + + void slotReadAll() { byteCounter += static_cast(sender())->readAll().size(); } + +private Q_SLOTS: + void blockingSequentialRemoteHosts(); + void sequentialRemoteHosts(); + void parallelRemoteHosts_data(); + void parallelRemoteHosts(); + void namRemoteGet_data(); + void namRemoteGet(); +}; + +tst_NetworkRemoteStressTest::tst_NetworkRemoteStressTest() + : intermediateDebug(qgetenv("STRESSDEBUG").toInt() > 0) +{ +#ifdef Q_OS_WIN + WSAData wsadata; + + // IPv6 requires Winsock v2.0 or better. + WSAStartup(MAKEWORD(2,0), &wsadata); +#elif defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) + ::signal(SIGALRM, SIG_IGN); +#endif + + QFile urlList(":/url-list.txt"); + if (urlList.open(QIODevice::ReadOnly)) { + while (!urlList.atEnd()) { + QByteArray line = urlList.readLine().trimmed(); + QUrl url = QUrl::fromEncoded(line); + if (url.scheme() == "http") + httpUrls << url; + } + } + + httpUrls << httpUrls; +} + +void tst_NetworkRemoteStressTest::initTestCase_data() +{ + QTest::addColumn >("urlList"); + + QTest::newRow("no-ssl") << httpUrls; +} + +void tst_NetworkRemoteStressTest::init() +{ + // clear the internal cache +#ifndef QT_BUILD_INTERNAL + if (strncmp(QTest::currentTestFunction(), "nam") == 0) + QSKIP("QNetworkAccessManager tests disabled", SkipAll); +#endif + qDebug() << QTest::currentTestFunction() << QTest::currentDataTag(); +} + +void tst_NetworkRemoteStressTest::clearManager() +{ +#ifdef QT_BUILD_INTERNAL + QNetworkAccessManagerPrivate::clearCache(&manager); + manager.setProxy(QNetworkProxy()); + manager.setCache(0); +#endif +} + +bool nativeLookup(const char *hostname, int port, QByteArray &buf) +{ +#if !defined(QT_NO_GETADDRINFO) && 0 + addrinfo *res = 0; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + + int result = getaddrinfo(QUrl::toAce(hostname).constData(), QByteArray::number(port).constData(), &hints, &res); + if (!result) + return false; + for (addrinfo *node = res; node; node = node->ai_next) { + if (node->ai_family == AF_INET) { + buf = QByteArray((char *)node->ai_addr, node->ai_addrlen); + break; + } + } + freeaddrinfo(res); +#else + hostent *result = gethostbyname(hostname); + if (!result || result->h_addrtype != AF_INET) + return false; + + struct sockaddr_in s; + s.sin_family = AF_INET; + s.sin_port = htons(port); + s.sin_addr = *(struct in_addr *) result->h_addr_list[0]; + + buf = QByteArray((char *)&s, sizeof s); +#endif + + return !buf.isEmpty(); +} + +bool nativeSelect(int fd, int timeout, bool selectForWrite) +{ + if (timeout < 0) + return false; + + // wait for connected + fd_set fds, fde; + FD_ZERO(&fds); + FD_ZERO(&fde); + FD_SET(fd, &fds); + FD_SET(fd, &fde); + + int ret; + do { + struct timeval tv; + tv.tv_sec = timeout / 1000; + tv.tv_usec = timeout % 1000; + if (selectForWrite) + ret = ::select(fd + 1, 0, &fds, &fde, &tv); + else + ret = ::select(fd + 1, &fds, 0, &fde, &tv); + } while (ret == -1 && errno == EINTR); + return ret != 0; +} + +void tst_NetworkRemoteStressTest::blockingSequentialRemoteHosts() +{ + QFETCH_GLOBAL(QVector, urlList); + + qint64 totalBytes = 0; + QElapsedTimer outerTimer; + outerTimer.start(); + + for (int i = 0; i < urlList.size(); ++i) { + const QUrl &url = urlList.at(i); + QElapsedTimer timeout; + byteCounter = 0; + timeout.start(); + + QTcpSocket socket; + socket.connectToHost(url.host(), url.port(80)); + QVERIFY2(socket.waitForConnected(10000), "Timeout connecting"); + + socket.write("GET " + url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment) + " HTTP/1.0\r\n" + "Connection: close\r\n" + "User-Agent: tst_QTcpSocket_stresstest/1.0\r\n" + "Host: " + url.encodedHost() + "\r\n" + "\r\n"); + while (socket.bytesToWrite()) + QVERIFY2(socket.waitForBytesWritten(10000), "Timeout writing"); + + while (socket.state() == QAbstractSocket::ConnectedState && !timeout.hasExpired(10000)) { + socket.waitForReadyRead(10000); + byteCounter += socket.readAll().size(); // discard + } + QVERIFY2(!timeout.hasExpired(10000), "Timeout reading"); + + totalBytes += byteCounter; + if (intermediateDebug) { + double rate = (byteCounter * 1.0 / timeout.elapsed()); + qDebug() << i << url << byteCounter << "bytes in" << timeout.elapsed() << "ms:" + << (rate / 1024.0 * 1000) << "kB/s"; + } + } + qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; +} + +void tst_NetworkRemoteStressTest::sequentialRemoteHosts() +{ + QFETCH_GLOBAL(QVector, urlList); + + qint64 totalBytes = 0; + QElapsedTimer outerTimer; + outerTimer.start(); + + for (int i = 0; i < urlList.size(); ++i) { + const QUrl &url = urlList.at(i); + QElapsedTimer timeout; + byteCounter = 0; + timeout.start(); + + QTcpSocket socket; + socket.connectToHost(url.host(), url.port(80)); + + socket.write("GET " + url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment) + " HTTP/1.0\r\n" + "Connection: close\r\n" + "User-Agent: tst_QTcpSocket_stresstest/1.0\r\n" + "Host: " + url.encodedHost() + "\r\n" + "\r\n"); + connect(&socket, SIGNAL(readyRead()), SLOT(slotReadAll())); + + QTestEventLoop::instance().connect(&socket, SIGNAL(disconnected()), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(30); + QVERIFY2(!QTestEventLoop::instance().timeout(), "Timeout"); + + totalBytes += byteCounter; + if (intermediateDebug) { + double rate = (byteCounter * 1.0 / timeout.elapsed()); + qDebug() << i << url << byteCounter << "bytes in" << timeout.elapsed() << "ms:" + << (rate / 1024.0 * 1000) << "kB/s"; + } + } + qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; +} + +void tst_NetworkRemoteStressTest::parallelRemoteHosts_data() +{ + QTest::addColumn("parallelAttempts"); + QTest::newRow("1") << 1; + QTest::newRow("2") << 2; + QTest::newRow("4") << 4; + QTest::newRow("5") << 5; + QTest::newRow("6") << 6; + QTest::newRow("8") << 8; + QTest::newRow("10") << 10; + QTest::newRow("25") << 25; + QTest::newRow("500") << 500; +} + +void tst_NetworkRemoteStressTest::parallelRemoteHosts() +{ + QFETCH_GLOBAL(QVector, urlList); + + QFETCH(int, parallelAttempts); + + qint64 totalBytes = 0; + QElapsedTimer outerTimer; + outerTimer.start(); + + QVector::ConstIterator it = urlList.constBegin(); + while (it != urlList.constEnd()) { + QElapsedTimer timeout; + byteCounter = 0; + timeout.start(); + + QVector > sockets; + sockets.reserve(parallelAttempts); + for (int j = 0; j < parallelAttempts && it != urlList.constEnd(); ++j, ++it) { + const QUrl &url = *it; + QTcpSocket *socket = new QTcpSocket; + socket->connectToHost(url.host(), url.port(80)); + + socket->write("GET " + url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment) + " HTTP/1.0\r\n" + "Connection: close\r\n" + "User-Agent: tst_QTcpSocket_stresstest/1.0\r\n" + "Host: " + url.encodedHost() + "\r\n" + "\r\n"); + connect(socket, SIGNAL(readyRead()), SLOT(slotReadAll())); + QTestEventLoop::instance().connect(socket, SIGNAL(disconnected()), SLOT(exitLoop())); + + sockets.append(QSharedPointer(socket)); + } + + while (!timeout.hasExpired(30000)) { + QTestEventLoop::instance().enterLoop(10); + int done = 0; + for (int j = 0; j < sockets.size(); ++j) + done += sockets[j]->state() == QAbstractSocket::UnconnectedState ? 1 : 0; + if (done == sockets.size()) + break; + } + + totalBytes += byteCounter; + if (intermediateDebug) { + double rate = (byteCounter * 1.0 / timeout.elapsed()); + qDebug() << byteCounter << "bytes in" << timeout.elapsed() << "ms:" + << (rate / 1024.0 * 1000) << "kB/s"; + } + } + qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; +} + +void tst_NetworkRemoteStressTest::namRemoteGet_data() +{ + QTest::addColumn("parallelAttempts"); + QTest::newRow("1") << 1; + QTest::newRow("2") << 2; + QTest::newRow("4") << 4; + QTest::newRow("5") << 5; + QTest::newRow("6") << 6; + QTest::newRow("8") << 8; + QTest::newRow("10") << 10; + QTest::newRow("25") << 25; + QTest::newRow("500") << 500; +} + +void tst_NetworkRemoteStressTest::namRemoteGet() +{ + QFETCH_GLOBAL(QVector, urlList); + + QFETCH(int, parallelAttempts); + bool pipelineAllowed = false;// QFETCH(bool, pipelineAllowed); + + qint64 totalBytes = 0; + QElapsedTimer outerTimer; + outerTimer.start(); + + QVector::ConstIterator it = urlList.constBegin(); + while (it != urlList.constEnd()) { + QElapsedTimer timeout; + byteCounter = 0; + timeout.start(); + + QNetworkRequest req; + req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, pipelineAllowed); + + QVector > replies; + replies.reserve(parallelAttempts); + for (int j = 0; j < parallelAttempts && it != urlList.constEnd(); ++j) { + req.setUrl(*it++); + QNetworkReply *r = manager.get(req); + + connect(r, SIGNAL(readyRead()), SLOT(slotReadAll())); + QTestEventLoop::instance().connect(r, SIGNAL(finished()), SLOT(exitLoop())); + + replies.append(QSharedPointer(r)); + } + + while (!timeout.hasExpired(30000)) { + QTestEventLoop::instance().enterLoop(10); + int done = 0; + for (int j = 0; j < replies.size(); ++j) + done += replies[j]->isFinished() ? 1 : 0; + if (done == replies.size()) + break; + } + replies.clear(); + + QVERIFY2(!timeout.hasExpired(30000), "Timeout"); + totalBytes += byteCounter; + if (intermediateDebug) { + double rate = (byteCounter * 1.0 / timeout.elapsed()); + qDebug() << byteCounter << "bytes in" << timeout.elapsed() << "ms:" + << (rate / 1024.0 * 1000) << "kB/s"; + } + } + qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; +} + +QTEST_MAIN(tst_NetworkRemoteStressTest); + +#include "tst_network_remote_stresstest.moc" diff --git a/tests/manual/network_remote_stresstest/url-list.qrc b/tests/manual/network_remote_stresstest/url-list.qrc new file mode 100644 index 0000000..ec529e5 --- /dev/null +++ b/tests/manual/network_remote_stresstest/url-list.qrc @@ -0,0 +1,5 @@ + + + url-list.txt + + diff --git a/tests/manual/network_remote_stresstest/url-list.txt b/tests/manual/network_remote_stresstest/url-list.txt new file mode 100644 index 0000000..3d6d7a9 --- /dev/null +++ b/tests/manual/network_remote_stresstest/url-list.txt @@ -0,0 +1,64 @@ +http://www.digicert.com/CACerts/DigiCertAssuredIDRootCA.crt +http://www.digicert.com/CACerts/DigiCertGlobalRootCA.crt +http://www.digicert.com/CACerts/DigiCertHighAssuranceEVRootCA.crt +http://www.quovadis.bm/public/qvrca2.crt +http://www.quovadis.bm/public/qvrca3.crt +https://secure.globalsign.net/cacert/root-r2.crt +http://secure.globalsign.net/cacert/Root-R1.crt +http://www.certplus.com/PC/certplus_class2.pem +https://www.startssl.com/certs/ca.crt +http://www.turktrust.com.tr/sertifikalar/TURKTRUST_Elektronik_Sertifika_Hizmet_Saglayicisi.crt +http://www.turktrust.com.tr/sertifikalar/kok_s2.crt +http://crt.comodoca.com/COMODOCertificationAuthority.crt +http://crt.comodoca.com/COMODOECCCertificationAuthority.crt +https://bugzilla.mozilla.org/attachment.cgi?id=368998 +https://bugzilla.mozilla.org/attachment.cgi?id=335538 +https://bugzilla.mozilla.org/attachment.cgi?id=304810 +https://www.securetrust.com/legal/STCA.txt +https://www.securetrust.com/legal/SGCA.txt +http://www.securetrust.com/legal/XGCA.txt +http://www.diginotar.nl/files/Rootcertificaten/DigiNotar%20root%20CA2007.crt +https://bugzilla.mozilla.org/attachment.cgi?id=294057 +https://bugzilla.mozilla.org/attachment.cgi?id=368997 +https://bugzilla.mozilla.org/attachment.cgi?id=306731 +https://certs.starfieldtech.com/repository/valicert_class2_root.crt +https://certs.godaddy.com/repository/gd-class2-root.crt +https://certs.starfieldtech.com/repository/sf-class2-root.crt +ftp://ftp.networksolutions.com/certs/netsolevroot.crt +https://bugzilla.mozilla.org/attachment.cgi?id=335551 +https://bugzilla.mozilla.org/attachment.cgi?id=369000 +https://bugzilla.mozilla.org/attachment.cgi?id=306736 +https://bugzilla.mozilla.org/attachment.cgi?id=267983 +https://swisssign.net/cgi-bin/authority/download?ca=50AFCC078715476F38C5B465D1DE95AAE9DF9CCC&into=browser +https://swisssign.net/cgi-bin/authority/download?ca=5B257B96A465517EB839F3C078665EE83AE7F0EE&into=browser +https://swisssign.net/cgi-bin/authority/download?ca=17A0CDC1E441B63A5B3BCB459DBD1CC298FA8658&into=browser +http://apps.identrust.com/roots/DSTROOTCAX3.cer +https://bugzilla.mozilla.org/attachment.cgi?id=277051 +http://www.ssi.gouv.fr/IMG/crt/igca-rsa.crt +http://www.e-szigno.hu/RootCA.crt +http://www.s-trust.de/service_support/zertifikatsmanagement/verzeichnisdienste/download_wurzelzertifikate/ordner_crt_dateien/authentication.crt +http://public.wisekey.com/crt/owgrgaca.crt +http://www.trustcenter.de/media/class_2_ii.der +http://www.trustcenter.de/media/class_3_ii.der +http://www.trustcenter.de/media/Universal_CA-I.der +http://www.certigna.fr/ca/ACcertigna.crt +https://repository.secomtrust.net/EV-Root1/EVRoot1ca.cer +http://www.certicamara.com/ac_offline_raiz_certicamara.crt +http://fedir.comsign.co.il/cacert/ComsignCA.crt +http://fedir.comsign.co.il/cacert/ComsignSecuredCA.crt +http://crl.pki.wellsfargo.com/wsprca.crt +http://cacert.omniroot.com/ct_root_ss.crt +http://www.kamusm.gov.tr/BilgiDeposu/KOKSHS.v3.crt +https://bugzilla.mozilla.org/attachment.cgi?id=380381 +http://210.71.154.6/download/ROOTeCA.cer +https://bugzilla.mozilla.org/attachment.cgi?id=359654 +http://www.gpki.go.jp/apcaself/APCAroot.der +https://bugzilla.mozilla.org/attachment.cgi?id=405525 +https://bugzilla.mozilla.org/attachment.cgi?id=361508 +https://bugzilla.mozilla.org/attachment.cgi?id=361508 +http://www.hongkongpost.gov.hk/product/download/root/img/smartid_rt.cacert +http://www.sk.ee/files/JUUR-SK.der +https://bugzilla.mozilla.org/attachment.cgi?id=408102 +http://www.disig.eu/ca/cert/ca_disig.der +https://bugzilla.mozilla.org/attachment.cgi?id=365241 +https://www2.jcsinc.co.jp/repository/certs/SSAD-rca.der diff --git a/tests/manual/network_stresstest/tst_network_stresstest.cpp b/tests/manual/network_stresstest/tst_network_stresstest.cpp index d3b007a..34d83e1 100644 --- a/tests/manual/network_stresstest/tst_network_stresstest.cpp +++ b/tests/manual/network_stresstest/tst_network_stresstest.cpp @@ -76,17 +76,16 @@ typedef int SOCKET; # include #endif -class tst_QTcpSocket_stresstest : public QObject +class tst_NetworkStressTest : public QObject { Q_OBJECT public: enum { AttemptCount = 100 }; - tst_QTcpSocket_stresstest(); + tst_NetworkStressTest(); MiniHttpServer server; qint64 byteCounter; QNetworkAccessManager manager; - QVector httpUrls; bool intermediateDebug; private: @@ -109,16 +108,9 @@ private Q_SLOTS: void parallelConnectDisconnect(); void namGet_data(); void namGet(); - - void blockingSequentialRemoteHosts(); - void sequentialRemoteHosts(); - void parallelRemoteHosts_data(); - void parallelRemoteHosts(); - void namRemoteGet_data(); - void namRemoteGet(); }; -tst_QTcpSocket_stresstest::tst_QTcpSocket_stresstest() +tst_NetworkStressTest::tst_NetworkStressTest() : intermediateDebug(qgetenv("STRESSDEBUG").toInt() > 0) { #ifdef Q_OS_WIN @@ -129,21 +121,9 @@ tst_QTcpSocket_stresstest::tst_QTcpSocket_stresstest() #elif defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) ::signal(SIGALRM, SIG_IGN); #endif - - QFile urlList(":/url-list.txt"); - if (urlList.open(QIODevice::ReadOnly)) { - while (!urlList.atEnd()) { - QByteArray line = urlList.readLine().trimmed(); - QUrl url = QUrl::fromEncoded(line); - if (url.scheme() == "http") - httpUrls << url; - } - } - - httpUrls << httpUrls; } -void tst_QTcpSocket_stresstest::initTestCase_data() +void tst_NetworkStressTest::initTestCase_data() { QTest::addColumn("isLocalhost"); QTest::addColumn("hostname"); @@ -153,7 +133,7 @@ void tst_QTcpSocket_stresstest::initTestCase_data() QTest::newRow("remote") << false << QtNetworkSettings::serverName() << 80; } -void tst_QTcpSocket_stresstest::init() +void tst_NetworkStressTest::init() { // clear the internal cache #ifndef QT_BUILD_INTERNAL @@ -162,7 +142,7 @@ void tst_QTcpSocket_stresstest::init() #endif } -void tst_QTcpSocket_stresstest::clearManager() +void tst_NetworkStressTest::clearManager() { #ifdef QT_BUILD_INTERNAL QNetworkAccessManagerPrivate::clearCache(&manager); @@ -230,7 +210,7 @@ bool nativeSelect(int fd, int timeout, bool selectForWrite) return ret != 0; } -void tst_QTcpSocket_stresstest::nativeBlockingConnectDisconnect() +void tst_NetworkStressTest::nativeBlockingConnectDisconnect() { QFETCH_GLOBAL(QString, hostname); QFETCH_GLOBAL(int, port); @@ -304,7 +284,7 @@ void tst_QTcpSocket_stresstest::nativeBlockingConnectDisconnect() #endif } -void tst_QTcpSocket_stresstest::nativeNonBlockingConnectDisconnect() +void tst_NetworkStressTest::nativeNonBlockingConnectDisconnect() { QFETCH_GLOBAL(QString, hostname); QFETCH_GLOBAL(int, port); @@ -418,7 +398,7 @@ void tst_QTcpSocket_stresstest::nativeNonBlockingConnectDisconnect() qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 / 1024 * 1000 / outerTimer.elapsed()) << "MB/s"; } -void tst_QTcpSocket_stresstest::blockingConnectDisconnect() +void tst_NetworkStressTest::blockingConnectDisconnect() { QFETCH_GLOBAL(QString, hostname); QFETCH_GLOBAL(int, port); @@ -459,7 +439,7 @@ void tst_QTcpSocket_stresstest::blockingConnectDisconnect() qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 / 1024 * 1000 / outerTimer.elapsed()) << "MB/s"; } -void tst_QTcpSocket_stresstest::blockingPipelined() +void tst_NetworkStressTest::blockingPipelined() { QFETCH_GLOBAL(QString, hostname); QFETCH_GLOBAL(int, port); @@ -504,7 +484,7 @@ void tst_QTcpSocket_stresstest::blockingPipelined() qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 / 1024 * 1000 / outerTimer.elapsed()) << "MB/s"; } -void tst_QTcpSocket_stresstest::blockingMultipleRequests() +void tst_NetworkStressTest::blockingMultipleRequests() { QFETCH_GLOBAL(QString, hostname); QFETCH_GLOBAL(int, port); @@ -588,7 +568,7 @@ void tst_QTcpSocket_stresstest::blockingMultipleRequests() qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 / 1024 * 1000 / outerTimer.elapsed()) << "MB/s"; } -void tst_QTcpSocket_stresstest::connectDisconnect() +void tst_NetworkStressTest::connectDisconnect() { QFETCH_GLOBAL(QString, hostname); QFETCH_GLOBAL(int, port); @@ -626,7 +606,7 @@ void tst_QTcpSocket_stresstest::connectDisconnect() qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 / 1024 * 1000 / outerTimer.elapsed()) << "MB/s"; } -void tst_QTcpSocket_stresstest::parallelConnectDisconnect_data() +void tst_NetworkStressTest::parallelConnectDisconnect_data() { QTest::addColumn("parallelAttempts"); QTest::newRow("1") << 1; @@ -641,7 +621,7 @@ void tst_QTcpSocket_stresstest::parallelConnectDisconnect_data() QTest::newRow("500") << 500; } -void tst_QTcpSocket_stresstest::parallelConnectDisconnect() +void tst_NetworkStressTest::parallelConnectDisconnect() { QFETCH_GLOBAL(QString, hostname); QFETCH_GLOBAL(int, port); @@ -697,7 +677,7 @@ void tst_QTcpSocket_stresstest::parallelConnectDisconnect() qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 / 1024 * 1000 / outerTimer.elapsed()) << "MB/s"; } -void tst_QTcpSocket_stresstest::namGet_data() +void tst_NetworkStressTest::namGet_data() { QTest::addColumn("parallelAttempts"); QTest::addColumn("pipelineAllowed"); @@ -724,7 +704,7 @@ void tst_QTcpSocket_stresstest::namGet_data() QTest::newRow("500p") << 500 << true; } -void tst_QTcpSocket_stresstest::namGet() +void tst_NetworkStressTest::namGet() { QFETCH_GLOBAL(QString, hostname); QFETCH_GLOBAL(int, port); @@ -786,234 +766,6 @@ void tst_QTcpSocket_stresstest::namGet() qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 / 1024 * 1000 / outerTimer.elapsed()) << "MB/s"; } -void tst_QTcpSocket_stresstest::blockingSequentialRemoteHosts() -{ - QFETCH_GLOBAL(bool, isLocalhost); - if (isLocalhost) - return; - - qint64 totalBytes = 0; - QElapsedTimer outerTimer; - outerTimer.start(); - - for (int i = 0; i < httpUrls.size(); ++i) { - const QUrl &url = httpUrls.at(i); - QElapsedTimer timeout; - byteCounter = 0; - timeout.start(); - - QTcpSocket socket; - socket.connectToHost(url.host(), url.port(80)); - QVERIFY2(socket.waitForConnected(10000), "Timeout connecting"); - - socket.write("GET " + url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment) + " HTTP/1.0\r\n" - "Connection: close\r\n" - "User-Agent: tst_QTcpSocket_stresstest/1.0\r\n" - "Host: " + url.encodedHost() + "\r\n" - "\r\n"); - while (socket.bytesToWrite()) - QVERIFY2(socket.waitForBytesWritten(10000), "Timeout writing"); - - while (socket.state() == QAbstractSocket::ConnectedState && !timeout.hasExpired(10000)) { - socket.waitForReadyRead(10000); - byteCounter += socket.readAll().size(); // discard - } - QVERIFY2(!timeout.hasExpired(10000), "Timeout reading"); - - totalBytes += byteCounter; - if (intermediateDebug) { - double rate = (byteCounter * 1.0 / timeout.elapsed()); - qDebug() << i << url << byteCounter << "bytes in" << timeout.elapsed() << "ms:" - << (rate / 1024.0 * 1000) << "kB/s"; - } - } - qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; -} - -void tst_QTcpSocket_stresstest::sequentialRemoteHosts() -{ - QFETCH_GLOBAL(bool, isLocalhost); - if (isLocalhost) - return; - - qint64 totalBytes = 0; - QElapsedTimer outerTimer; - outerTimer.start(); - - for (int i = 0; i < httpUrls.size(); ++i) { - const QUrl &url = httpUrls.at(i); - QElapsedTimer timeout; - byteCounter = 0; - timeout.start(); - - QTcpSocket socket; - socket.connectToHost(url.host(), url.port(80)); - - socket.write("GET " + url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment) + " HTTP/1.0\r\n" - "Connection: close\r\n" - "User-Agent: tst_QTcpSocket_stresstest/1.0\r\n" - "Host: " + url.encodedHost() + "\r\n" - "\r\n"); - connect(&socket, SIGNAL(readyRead()), SLOT(slotReadAll())); - - QTestEventLoop::instance().connect(&socket, SIGNAL(disconnected()), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(30); - QVERIFY2(!QTestEventLoop::instance().timeout(), "Timeout"); - - totalBytes += byteCounter; - if (intermediateDebug) { - double rate = (byteCounter * 1.0 / timeout.elapsed()); - qDebug() << i << url << byteCounter << "bytes in" << timeout.elapsed() << "ms:" - << (rate / 1024.0 * 1000) << "kB/s"; - } - } - qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; -} - -void tst_QTcpSocket_stresstest::parallelRemoteHosts_data() -{ - QTest::addColumn("parallelAttempts"); - QTest::newRow("1") << 1; - QTest::newRow("2") << 2; - QTest::newRow("4") << 4; - QTest::newRow("5") << 5; - QTest::newRow("6") << 6; - QTest::newRow("8") << 8; - QTest::newRow("10") << 10; - QTest::newRow("25") << 25; - QTest::newRow("500") << 500; -} - -void tst_QTcpSocket_stresstest::parallelRemoteHosts() -{ - QFETCH_GLOBAL(bool, isLocalhost); - if (isLocalhost) - return; - - QFETCH(int, parallelAttempts); - - qint64 totalBytes = 0; - QElapsedTimer outerTimer; - outerTimer.start(); - - QVector::ConstIterator it = httpUrls.constBegin(); - while (it != httpUrls.constEnd()) { - QElapsedTimer timeout; - byteCounter = 0; - timeout.start(); - - QVector > sockets; - sockets.reserve(parallelAttempts); - for (int j = 0; j < parallelAttempts && it != httpUrls.constEnd(); ++j, ++it) { - const QUrl &url = *it; - QTcpSocket *socket = new QTcpSocket; - socket->connectToHost(url.host(), url.port(80)); - - socket->write("GET " + url.toEncoded(QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment) + " HTTP/1.0\r\n" - "Connection: close\r\n" - "User-Agent: tst_QTcpSocket_stresstest/1.0\r\n" - "Host: " + url.encodedHost() + "\r\n" - "\r\n"); - connect(socket, SIGNAL(readyRead()), SLOT(slotReadAll())); - QTestEventLoop::instance().connect(socket, SIGNAL(disconnected()), SLOT(exitLoop())); - - sockets.append(QSharedPointer(socket)); - } - - while (!timeout.hasExpired(30000)) { - QTestEventLoop::instance().enterLoop(10); - int done = 0; - for (int j = 0; j < sockets.size(); ++j) - done += sockets[j]->state() == QAbstractSocket::UnconnectedState ? 1 : 0; - if (done == sockets.size()) - break; - } - - totalBytes += byteCounter; - if (intermediateDebug) { - double rate = (byteCounter * 1.0 / timeout.elapsed()); - qDebug() << byteCounter << "bytes in" << timeout.elapsed() << "ms:" - << (rate / 1024.0 * 1000) << "kB/s"; - } - } - qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; -} - -void tst_QTcpSocket_stresstest::namRemoteGet_data() -{ - QTest::addColumn("parallelAttempts"); - QTest::newRow("1") << 1; - QTest::newRow("2") << 2; - QTest::newRow("4") << 4; - QTest::newRow("5") << 5; - QTest::newRow("6") << 6; - QTest::newRow("8") << 8; - QTest::newRow("10") << 10; - QTest::newRow("25") << 25; - QTest::newRow("500") << 500; -} - -void tst_QTcpSocket_stresstest::namRemoteGet() -{ - QFETCH_GLOBAL(bool, isLocalhost); - if (isLocalhost) - return; - - QFETCH(int, parallelAttempts); - bool pipelineAllowed = false;// QFETCH(bool, pipelineAllowed); - - if (parallelAttempts > 100) { - QFETCH_GLOBAL(bool, isLocalhost); - if (!isLocalhost) - QSKIP("Localhost-only test", SkipSingle); - } - - qint64 totalBytes = 0; - QElapsedTimer outerTimer; - outerTimer.start(); - - QVector::ConstIterator it = httpUrls.constBegin(); - while (it != httpUrls.constEnd()) { - QElapsedTimer timeout; - byteCounter = 0; - timeout.start(); - - QNetworkRequest req; - req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, pipelineAllowed); - - QVector > replies; - replies.reserve(parallelAttempts); - for (int j = 0; j < parallelAttempts && it != httpUrls.constEnd(); ++j) { - req.setUrl(*it++); - QNetworkReply *r = manager.get(req); - - connect(r, SIGNAL(readyRead()), SLOT(slotReadAll())); - QTestEventLoop::instance().connect(r, SIGNAL(finished()), SLOT(exitLoop())); - - replies.append(QSharedPointer(r)); - } - - while (!timeout.hasExpired(30000)) { - QTestEventLoop::instance().enterLoop(10); - int done = 0; - for (int j = 0; j < replies.size(); ++j) - done += replies[j]->isFinished() ? 1 : 0; - if (done == replies.size()) - break; - } - replies.clear(); - - QVERIFY2(!timeout.hasExpired(30000), "Timeout"); - totalBytes += byteCounter; - if (intermediateDebug) { - double rate = (byteCounter * 1.0 / timeout.elapsed()); - qDebug() << byteCounter << "bytes in" << timeout.elapsed() << "ms:" - << (rate / 1024.0 * 1000) << "kB/s"; - } - } - qDebug() << "Average transfer rate was" << (totalBytes / 1024.0 * 1000 / outerTimer.elapsed()) << "kB/s"; -} - -QTEST_MAIN(tst_QTcpSocket_stresstest); +QTEST_MAIN(tst_NetworkStressTest); #include "tst_network_stresstest.moc" diff --git a/tests/manual/network_stresstest/url-list.txt b/tests/manual/network_stresstest/url-list.txt deleted file mode 100644 index 3d6d7a9..0000000 --- a/tests/manual/network_stresstest/url-list.txt +++ /dev/null @@ -1,64 +0,0 @@ -http://www.digicert.com/CACerts/DigiCertAssuredIDRootCA.crt -http://www.digicert.com/CACerts/DigiCertGlobalRootCA.crt -http://www.digicert.com/CACerts/DigiCertHighAssuranceEVRootCA.crt -http://www.quovadis.bm/public/qvrca2.crt -http://www.quovadis.bm/public/qvrca3.crt -https://secure.globalsign.net/cacert/root-r2.crt -http://secure.globalsign.net/cacert/Root-R1.crt -http://www.certplus.com/PC/certplus_class2.pem -https://www.startssl.com/certs/ca.crt -http://www.turktrust.com.tr/sertifikalar/TURKTRUST_Elektronik_Sertifika_Hizmet_Saglayicisi.crt -http://www.turktrust.com.tr/sertifikalar/kok_s2.crt -http://crt.comodoca.com/COMODOCertificationAuthority.crt -http://crt.comodoca.com/COMODOECCCertificationAuthority.crt -https://bugzilla.mozilla.org/attachment.cgi?id=368998 -https://bugzilla.mozilla.org/attachment.cgi?id=335538 -https://bugzilla.mozilla.org/attachment.cgi?id=304810 -https://www.securetrust.com/legal/STCA.txt -https://www.securetrust.com/legal/SGCA.txt -http://www.securetrust.com/legal/XGCA.txt -http://www.diginotar.nl/files/Rootcertificaten/DigiNotar%20root%20CA2007.crt -https://bugzilla.mozilla.org/attachment.cgi?id=294057 -https://bugzilla.mozilla.org/attachment.cgi?id=368997 -https://bugzilla.mozilla.org/attachment.cgi?id=306731 -https://certs.starfieldtech.com/repository/valicert_class2_root.crt -https://certs.godaddy.com/repository/gd-class2-root.crt -https://certs.starfieldtech.com/repository/sf-class2-root.crt -ftp://ftp.networksolutions.com/certs/netsolevroot.crt -https://bugzilla.mozilla.org/attachment.cgi?id=335551 -https://bugzilla.mozilla.org/attachment.cgi?id=369000 -https://bugzilla.mozilla.org/attachment.cgi?id=306736 -https://bugzilla.mozilla.org/attachment.cgi?id=267983 -https://swisssign.net/cgi-bin/authority/download?ca=50AFCC078715476F38C5B465D1DE95AAE9DF9CCC&into=browser -https://swisssign.net/cgi-bin/authority/download?ca=5B257B96A465517EB839F3C078665EE83AE7F0EE&into=browser -https://swisssign.net/cgi-bin/authority/download?ca=17A0CDC1E441B63A5B3BCB459DBD1CC298FA8658&into=browser -http://apps.identrust.com/roots/DSTROOTCAX3.cer -https://bugzilla.mozilla.org/attachment.cgi?id=277051 -http://www.ssi.gouv.fr/IMG/crt/igca-rsa.crt -http://www.e-szigno.hu/RootCA.crt -http://www.s-trust.de/service_support/zertifikatsmanagement/verzeichnisdienste/download_wurzelzertifikate/ordner_crt_dateien/authentication.crt -http://public.wisekey.com/crt/owgrgaca.crt -http://www.trustcenter.de/media/class_2_ii.der -http://www.trustcenter.de/media/class_3_ii.der -http://www.trustcenter.de/media/Universal_CA-I.der -http://www.certigna.fr/ca/ACcertigna.crt -https://repository.secomtrust.net/EV-Root1/EVRoot1ca.cer -http://www.certicamara.com/ac_offline_raiz_certicamara.crt -http://fedir.comsign.co.il/cacert/ComsignCA.crt -http://fedir.comsign.co.il/cacert/ComsignSecuredCA.crt -http://crl.pki.wellsfargo.com/wsprca.crt -http://cacert.omniroot.com/ct_root_ss.crt -http://www.kamusm.gov.tr/BilgiDeposu/KOKSHS.v3.crt -https://bugzilla.mozilla.org/attachment.cgi?id=380381 -http://210.71.154.6/download/ROOTeCA.cer -https://bugzilla.mozilla.org/attachment.cgi?id=359654 -http://www.gpki.go.jp/apcaself/APCAroot.der -https://bugzilla.mozilla.org/attachment.cgi?id=405525 -https://bugzilla.mozilla.org/attachment.cgi?id=361508 -https://bugzilla.mozilla.org/attachment.cgi?id=361508 -http://www.hongkongpost.gov.hk/product/download/root/img/smartid_rt.cacert -http://www.sk.ee/files/JUUR-SK.der -https://bugzilla.mozilla.org/attachment.cgi?id=408102 -http://www.disig.eu/ca/cert/ca_disig.der -https://bugzilla.mozilla.org/attachment.cgi?id=365241 -https://www2.jcsinc.co.jp/repository/certs/SSAD-rca.der diff --git a/tests/manual/network_stresstest/wwwfiles.qrc b/tests/manual/network_stresstest/wwwfiles.qrc index 2290861..4d602a1 100644 --- a/tests/manual/network_stresstest/wwwfiles.qrc +++ b/tests/manual/network_stresstest/wwwfiles.qrc @@ -1,6 +1,5 @@ qtest - url-list.txt -- cgit v0.12