summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorSami Lempinen <sami.lempinen@nokia.com>2011-04-28 08:10:57 (GMT)
committerSami Lempinen <sami.lempinen@nokia.com>2011-04-28 08:10:57 (GMT)
commit95de3f34d9dba4cd95f1f3d32b35c4a4d97e70d9 (patch)
tree7be35a9028b5c83b792190fb954127e9f558baf5 /tests/benchmarks
parent9d6530b9774de482b0b3a29720f7f756e986f5c7 (diff)
parent8e615d9b07f6146b5cb6b56c4cd2e32376a8b429 (diff)
downloadQt-95de3f34d9dba4cd95f1f3d32b35c4a4d97e70d9.zip
Qt-95de3f34d9dba4cd95f1f3d32b35c4a4d97e70d9.tar.gz
Qt-95de3f34d9dba4cd95f1f3d32b35c4a4d97e70d9.tar.bz2
Merge remote-tracking branch 'qt/4.8'
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/benchmarks.pro1
-rw-r--r--tests/benchmarks/corelib/io/qdir/qdir.pro4
-rw-r--r--tests/benchmarks/dbus/dbus.pro4
-rw-r--r--tests/benchmarks/dbus/qdbusperformance/.gitignore2
-rw-r--r--tests/benchmarks/dbus/qdbusperformance/qdbusperformance.pro4
-rw-r--r--tests/benchmarks/dbus/qdbusperformance/server/server.cpp64
-rw-r--r--tests/benchmarks/dbus/qdbusperformance/server/server.pro5
-rw-r--r--tests/benchmarks/dbus/qdbusperformance/serverobject.h115
-rw-r--r--tests/benchmarks/dbus/qdbusperformance/test/test.pro7
-rw-r--r--tests/benchmarks/dbus/qdbusperformance/tst_qdbusperformance.cpp230
-rw-r--r--tests/benchmarks/dbus/qdbustype/main.cpp115
-rw-r--r--tests/benchmarks/dbus/qdbustype/qdbustype.pro8
-rw-r--r--tests/benchmarks/network/access/access.pro3
-rw-r--r--tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro15
-rw-r--r--tests/benchmarks/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp435
-rw-r--r--tests/benchmarks/script/script.pro3
16 files changed, 1011 insertions, 4 deletions
diff --git a/tests/benchmarks/benchmarks.pro b/tests/benchmarks/benchmarks.pro
index 00a1b37..b5e3a4b 100644
--- a/tests/benchmarks/benchmarks.pro
+++ b/tests/benchmarks/benchmarks.pro
@@ -7,6 +7,7 @@ SUBDIRS = \
svg
contains(QT_CONFIG, opengl): SUBDIRS += opengl
contains(QT_CONFIG, declarative): SUBDIRS += declarative
+contains(QT_CONFIG, dbus): SUBDIRS += dbus
check-trusted.CONFIG += recursive
QMAKE_EXTRA_TARGETS += check-trusted
diff --git a/tests/benchmarks/corelib/io/qdir/qdir.pro b/tests/benchmarks/corelib/io/qdir/qdir.pro
index c572566..2c18e75 100644
--- a/tests/benchmarks/corelib/io/qdir/qdir.pro
+++ b/tests/benchmarks/corelib/io/qdir/qdir.pro
@@ -1,2 +1,4 @@
TEMPLATE = subdirs
-SUBDIRS = 10000
+SUBDIRS = \
+ 10000 \
+ tree
diff --git a/tests/benchmarks/dbus/dbus.pro b/tests/benchmarks/dbus/dbus.pro
new file mode 100644
index 0000000..989a0db
--- /dev/null
+++ b/tests/benchmarks/dbus/dbus.pro
@@ -0,0 +1,4 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ qdbusperformance \
+ qdbustype
diff --git a/tests/benchmarks/dbus/qdbusperformance/.gitignore b/tests/benchmarks/dbus/qdbusperformance/.gitignore
new file mode 100644
index 0000000..4cd8399
--- /dev/null
+++ b/tests/benchmarks/dbus/qdbusperformance/.gitignore
@@ -0,0 +1,2 @@
+tst_qdbusperformance
+server/server
diff --git a/tests/benchmarks/dbus/qdbusperformance/qdbusperformance.pro b/tests/benchmarks/dbus/qdbusperformance/qdbusperformance.pro
new file mode 100644
index 0000000..90f88a7
--- /dev/null
+++ b/tests/benchmarks/dbus/qdbusperformance/qdbusperformance.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+TEMPLATE = subdirs
+CONFIG += ordered
+SUBDIRS = server test
diff --git a/tests/benchmarks/dbus/qdbusperformance/server/server.cpp b/tests/benchmarks/dbus/qdbusperformance/server/server.cpp
new file mode 100644
index 0000000..3bd5efc
--- /dev/null
+++ b/tests/benchmarks/dbus/qdbusperformance/server/server.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** 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 <QtCore/QtCore>
+#include <QtDBus/QtDBus>
+
+#include "../serverobject.h"
+
+static const char serviceName[] = "com.trolltech.autotests.performance";
+static const char objectPath[] = "/";
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+
+ QDBusConnection con = QDBusConnection::sessionBus();
+ if (!con.isConnected())
+ exit(1);
+
+ if (!con.registerService(serviceName))
+ exit(2);
+
+ ServerObject obj(objectPath, con);
+ printf("ready.\n");
+ return app.exec();
+}
+
diff --git a/tests/benchmarks/dbus/qdbusperformance/server/server.pro b/tests/benchmarks/dbus/qdbusperformance/server/server.pro
new file mode 100644
index 0000000..30f81dd
--- /dev/null
+++ b/tests/benchmarks/dbus/qdbusperformance/server/server.pro
@@ -0,0 +1,5 @@
+SOURCES = server.cpp
+HEADERS = ../serverobject.h
+TARGET = server
+CONFIG += qdbus
+QT -= gui
diff --git a/tests/benchmarks/dbus/qdbusperformance/serverobject.h b/tests/benchmarks/dbus/qdbusperformance/serverobject.h
new file mode 100644
index 0000000..6f85bb4
--- /dev/null
+++ b/tests/benchmarks/dbus/qdbusperformance/serverobject.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+
+#ifndef SERVEROBJECT_H
+#define SERVEROBJECT_H
+
+#include <QObject>
+#include <QtDBus/QtDBus>
+
+class ServerObject: public QObject
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "com.trolltech.autotests.Performance")
+public:
+ ServerObject(const QString &objectPath, QDBusConnection conn, QObject *parent = 0)
+ : QObject(parent)
+ {
+ conn.registerObject(objectPath, this, QDBusConnection::ExportAllSlots);
+ }
+
+public slots:
+ Q_NOREPLY void noReply(const QByteArray &)
+ {
+ // black hole
+ }
+ Q_NOREPLY void noReply(const QString &)
+ {
+ // black hole
+ }
+ Q_NOREPLY void noReply(const QDBusVariant &)
+ {
+ // black hole
+ }
+
+ int size(const QByteArray &data)
+ {
+ return data.size();
+ }
+ int size(const QString &data)
+ {
+ return data.size();
+ }
+ int size(const QDBusVariant &data)
+ {
+ QVariant v = data.variant();
+ switch (v.type())
+ {
+ case QVariant::ByteArray:
+ return v.toByteArray().size();
+ case QVariant::StringList:
+ return v.toStringList().size();
+ case QVariant::String:
+ default:
+ return v.toString().size();
+ }
+ }
+
+ QByteArray echo(const QByteArray &data)
+ {
+ return data;
+ }
+ QString echo(const QString &data)
+ {
+ return data;
+ }
+ QDBusVariant echo(const QDBusVariant &data)
+ {
+ return data;
+ }
+
+ void nothing()
+ {
+ }
+};
+
+#endif
diff --git a/tests/benchmarks/dbus/qdbusperformance/test/test.pro b/tests/benchmarks/dbus/qdbusperformance/test/test.pro
new file mode 100644
index 0000000..9f5712e
--- /dev/null
+++ b/tests/benchmarks/dbus/qdbusperformance/test/test.pro
@@ -0,0 +1,7 @@
+load(qttest_p4)
+SOURCES += ../tst_qdbusperformance.cpp
+HEADERS += ../serverobject.h
+TARGET = ../tst_qdbusperformance
+
+QT = core
+CONFIG += qdbus
diff --git a/tests/benchmarks/dbus/qdbusperformance/tst_qdbusperformance.cpp b/tests/benchmarks/dbus/qdbusperformance/tst_qdbusperformance.cpp
new file mode 100644
index 0000000..a5b4b98
--- /dev/null
+++ b/tests/benchmarks/dbus/qdbusperformance/tst_qdbusperformance.cpp
@@ -0,0 +1,230 @@
+/****************************************************************************
+**
+** 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 <QtCore/QtCore>
+#include <QtTest/QtTest>
+#include <QtDBus/QtDBus>
+
+#include "./serverobject.h"
+
+static const char serviceName[] = "com.trolltech.autotests.performance";
+static const int runTime = 500;
+
+class tst_QDBusPerformance: public QObject
+{
+ Q_OBJECT
+ QProcess proc;
+ QDBusInterface *target;
+
+ QDBusInterface *remote;
+ QDBusInterface *local;
+
+ bool executeTest(const char *funcname, int size, const QVariant &data);
+
+public slots:
+ void initTestCase_data();
+ void initTestCase();
+ void init();
+
+private slots:
+ void callSpeed();
+
+ void oneWay_data();
+ void oneWay();
+ void oneWayVariant_data();
+ void oneWayVariant();
+
+ void roundTrip_data();
+ void roundTrip();
+ void roundTripVariant_data();
+ void roundTripVariant();
+};
+Q_DECLARE_METATYPE(QVariant)
+
+void tst_QDBusPerformance::initTestCase()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QVERIFY(con.isConnected());
+
+ QDBusServiceWatcher watcher(serviceName, con,
+ QDBusServiceWatcher::WatchForRegistration);
+ connect(&watcher, SIGNAL(serviceRegistered(QString)),
+ &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+#ifdef Q_OS_WIN
+ proc.start("server");
+#else
+ proc.start("./server/server");
+#endif
+ QVERIFY(proc.waitForStarted());
+
+ QTestEventLoop::instance().enterLoop(5);
+ QVERIFY(con.interface()->isServiceRegistered(serviceName));
+
+ remote = new QDBusInterface(serviceName, "/", "com.trolltech.autotests.Performance", con, this);
+ QVERIFY(remote->isValid());
+
+ new ServerObject("/", con, this);
+ local = new QDBusInterface(con.baseService(), "/", "com.trolltech.autotests.Performance", con, this);
+ QVERIFY(local->isValid());
+}
+
+void tst_QDBusPerformance::initTestCase_data()
+{
+ QTest::addColumn<bool>("loopback");
+
+ QTest::newRow("normal") << false;
+ QTest::newRow("loopback") << true;
+}
+
+void tst_QDBusPerformance::init()
+{
+ QFETCH_GLOBAL(bool, loopback);
+ if (loopback)
+ target = local;
+ else
+ target = remote;
+}
+
+void tst_QDBusPerformance::callSpeed()
+{
+ QElapsedTimer timer;
+
+ int callCount = 0;
+ timer.start();
+ while (timer.elapsed() < runTime) {
+ QDBusReply<void> reply = target->call("nothing");
+ QVERIFY(reply.isValid());
+
+ ++callCount;
+ }
+ qDebug() << callCount << "calls in" << timer.elapsed() << "ms:"
+ << (callCount * 1000.0 / timer.elapsed()) << "calls/sec";
+}
+
+bool tst_QDBusPerformance::executeTest(const char *funcname, int size, const QVariant &data)
+{
+ QElapsedTimer timer;
+
+ int callCount = 0;
+ qint64 transferred = 0;
+ timer.start();
+ while (timer.elapsed() < runTime) {
+ QDBusMessage reply = target->call(funcname, data);
+ if (reply.type() != QDBusMessage::ReplyMessage)
+ return false;
+
+ transferred += size;
+ ++callCount;
+ }
+ qDebug() << transferred << "bytes in" << timer.elapsed() << "ms"
+ << "(in" << callCount << "calls):"
+ << (transferred * 1000.0 / timer.elapsed() / 1024 / 1024) << "MB/s";
+
+ return true;
+}
+
+void tst_QDBusPerformance::oneWay_data()
+{
+ QTest::addColumn<QVariant>("data");
+ QTest::addColumn<int>("size");
+
+ QByteArray ba(256, 'a');
+ while (ba.size() < 8193) {
+ QTest::newRow(QString("%1-byteArray").arg(ba.size()).toAscii()) << qVariantFromValue(ba) << ba.size();
+ ba += ba;
+ }
+
+ QString s(256, QLatin1Char('a'));
+ while (s.size() < 8193) {
+ QTest::newRow(QString("%1-string").arg(s.size()).toAscii()) << qVariantFromValue(s) << s.size();
+ s += s;
+ }
+}
+
+void tst_QDBusPerformance::oneWay()
+{
+ QFETCH(QVariant, data);
+ QFETCH(int, size);
+
+ QVERIFY(executeTest("size", size, data));
+}
+
+void tst_QDBusPerformance::oneWayVariant_data()
+{
+ oneWay_data();
+}
+
+void tst_QDBusPerformance::oneWayVariant()
+{
+ QFETCH(QVariant, data);
+ QFETCH(int, size);
+
+ QVERIFY(executeTest("size", size, qVariantFromValue(QDBusVariant(data))));
+}
+
+void tst_QDBusPerformance::roundTrip_data()
+{
+ oneWay_data();
+}
+
+void tst_QDBusPerformance::roundTrip()
+{
+ QFETCH(QVariant, data);
+ QFETCH(int, size);
+
+ QVERIFY(executeTest("echo", size, data));
+}
+
+void tst_QDBusPerformance::roundTripVariant_data()
+{
+ oneWay_data();
+}
+
+void tst_QDBusPerformance::roundTripVariant()
+{
+ QFETCH(QVariant, data);
+ QFETCH(int, size);
+
+ QVERIFY(executeTest("echo", size, qVariantFromValue(QDBusVariant(data))));
+}
+
+QTEST_MAIN(tst_QDBusPerformance)
+#include "tst_qdbusperformance.moc"
diff --git a/tests/benchmarks/dbus/qdbustype/main.cpp b/tests/benchmarks/dbus/qdbustype/main.cpp
new file mode 100644
index 0000000..abaae7e
--- /dev/null
+++ b/tests/benchmarks/dbus/qdbustype/main.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** 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 FOO module 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 <QtTest/QtTest>
+#include <QtCore/QCoreApplication>
+
+#include <QtDBus/private/qdbusutil_p.h>
+
+#include <dbus/dbus.h>
+
+class tst_QDBusType: public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void benchmarkSignature_data();
+ void benchmarkSignature();
+};
+
+static inline void benchmarkAddRow(const char *name, const char *data)
+{
+ QTest::newRow(QByteArray("native-") + name) << data << true;
+ QTest::newRow(name) << data << false;
+}
+
+void tst_QDBusType::benchmarkSignature_data()
+{
+ QTest::addColumn<QString>("data");
+ QTest::addColumn<bool>("useNative");
+
+ for (int loopCount = 0; loopCount < 2; ++loopCount) {
+ bool useNative = loopCount;
+ QByteArray prefix = useNative ? "native-" : "";
+
+ benchmarkAddRow("single-invalid", "~");
+ benchmarkAddRow("single-invalid-array", "a~");
+ benchmarkAddRow("single-invalid-struct", "(.)");
+
+ benchmarkAddRow("single-char", "b");
+ benchmarkAddRow("single-array", "as");
+ benchmarkAddRow("single-simplestruct", "(y)");
+ benchmarkAddRow("single-simpledict", "a{sv}");
+ benchmarkAddRow("single-complexdict", "a{s(aya{io})}");
+
+ benchmarkAddRow("multiple-char", "ssg");
+ benchmarkAddRow("multiple-arrays", "asasay");
+
+ benchmarkAddRow("struct-missingclose", "(ayyyy");
+ benchmarkAddRow("longstruct", "(yyyyyyayasy)");
+ benchmarkAddRow("invalid-longstruct", "(yyyyyyayas.y)");
+ benchmarkAddRow("complexstruct", "(y(aasay)oga{sv})");
+ benchmarkAddRow("multiple-simple-structs", "(y)(y)(y)");
+ }
+}
+
+void tst_QDBusType::benchmarkSignature()
+{
+ QFETCH(QString, data);
+ QFETCH(bool, useNative);
+
+ bool result;
+ if (useNative) {
+ dbus_signature_validate(data.toLatin1(), 0);
+ QBENCHMARK {
+ result = dbus_signature_validate(data.toLatin1(), 0);
+ }
+ } else {
+ QDBusUtil::isValidSignature(data);
+ QBENCHMARK {
+ result = QDBusUtil::isValidSignature(data);
+ }
+ }
+ Q_UNUSED(result);
+}
+
+QTEST_MAIN(tst_QDBusType)
+
+#include "main.moc"
diff --git a/tests/benchmarks/dbus/qdbustype/qdbustype.pro b/tests/benchmarks/dbus/qdbustype/qdbustype.pro
new file mode 100644
index 0000000..d480a05
--- /dev/null
+++ b/tests/benchmarks/dbus/qdbustype/qdbustype.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+TARGET = tst_bench_qdbustype
+QT -= gui
+QT += dbus
+QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS
+LIBS_PRIVATE += $$QT_LIBS_DBUS
+
+SOURCES += main.cpp
diff --git a/tests/benchmarks/network/access/access.pro b/tests/benchmarks/network/access/access.pro
index 43357e2..6cbd367 100644
--- a/tests/benchmarks/network/access/access.pro
+++ b/tests/benchmarks/network/access/access.pro
@@ -1,4 +1,5 @@
TEMPLATE = subdirs
SUBDIRS = \
qfile_vs_qnetworkaccessmanager \
- qnetworkreply
+ qnetworkreply \
+ qnetworkdiskcache
diff --git a/tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro b/tests/benchmarks/network/access/qnetworkdiskcache/qnetworkdiskcache.pro
new file mode 100644
index 0000000..7f665b3
--- /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 0000000..55cbf55
--- /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 <QNetworkDiskCache>
+#include <QNetworkCacheMetaData>
+#include <QDir>
+#include <QBuffer>
+#include <QTextStream>
+#include <QDebug>
+#include <QtTest/QtTest>
+#include <QIODevice>
+#include <QDesktopServices>
+
+
+
+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<QString>("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<QString>("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<QString>("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<QString>("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/script/script.pro b/tests/benchmarks/script/script.pro
index 80278d0..5da05e7 100644
--- a/tests/benchmarks/script/script.pro
+++ b/tests/benchmarks/script/script.pro
@@ -14,7 +14,6 @@ TRUSTED_BENCHMARKS += \
qscriptclass \
qscriptvalue \
qscriptengine \
- qscriptobject \
- context2d
+ qscriptqobject
include(../trusted-benchmarks.pri)