From c22f52ce22f998d35ccc6ee0caa60d4e0af3b783 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 23 Feb 2011 16:59:54 +0100 Subject: Move the QDBusPerformance test to the tests/benchmark dir --- tests/auto/dbus.pro | 1 - tests/auto/qdbusperformance/.gitignore | 2 - tests/auto/qdbusperformance/qdbusperformance.pro | 8 - tests/auto/qdbusperformance/server/server.cpp | 64 ------ tests/auto/qdbusperformance/server/server.pro | 5 - tests/auto/qdbusperformance/serverobject.h | 115 ----------- tests/auto/qdbusperformance/test/test.pro | 7 - .../auto/qdbusperformance/tst_qdbusperformance.cpp | 230 --------------------- tests/benchmarks/benchmarks.pro | 1 + tests/benchmarks/dbus/dbus.pro | 3 + tests/benchmarks/dbus/qdbusperformance/.gitignore | 2 + .../dbus/qdbusperformance/qdbusperformance.pro | 4 + .../dbus/qdbusperformance/server/server.cpp | 64 ++++++ .../dbus/qdbusperformance/server/server.pro | 5 + .../dbus/qdbusperformance/serverobject.h | 115 +++++++++++ .../benchmarks/dbus/qdbusperformance/test/test.pro | 7 + .../dbus/qdbusperformance/tst_qdbusperformance.cpp | 230 +++++++++++++++++++++ 17 files changed, 431 insertions(+), 432 deletions(-) delete mode 100644 tests/auto/qdbusperformance/.gitignore delete mode 100644 tests/auto/qdbusperformance/qdbusperformance.pro delete mode 100644 tests/auto/qdbusperformance/server/server.cpp delete mode 100644 tests/auto/qdbusperformance/server/server.pro delete mode 100644 tests/auto/qdbusperformance/serverobject.h delete mode 100644 tests/auto/qdbusperformance/test/test.pro delete mode 100644 tests/auto/qdbusperformance/tst_qdbusperformance.cpp create mode 100644 tests/benchmarks/dbus/dbus.pro create mode 100644 tests/benchmarks/dbus/qdbusperformance/.gitignore create mode 100644 tests/benchmarks/dbus/qdbusperformance/qdbusperformance.pro create mode 100644 tests/benchmarks/dbus/qdbusperformance/server/server.cpp create mode 100644 tests/benchmarks/dbus/qdbusperformance/server/server.pro create mode 100644 tests/benchmarks/dbus/qdbusperformance/serverobject.h create mode 100644 tests/benchmarks/dbus/qdbusperformance/test/test.pro create mode 100644 tests/benchmarks/dbus/qdbusperformance/tst_qdbusperformance.cpp diff --git a/tests/auto/dbus.pro b/tests/auto/dbus.pro index fe21475..31b46a3 100644 --- a/tests/auto/dbus.pro +++ b/tests/auto/dbus.pro @@ -11,7 +11,6 @@ SUBDIRS=\ qdbusmetatype \ qdbuspendingcall \ qdbuspendingreply \ - qdbusperformance \ qdbusreply \ qdbusservicewatcher \ qdbustype \ diff --git a/tests/auto/qdbusperformance/.gitignore b/tests/auto/qdbusperformance/.gitignore deleted file mode 100644 index 4cd8399..0000000 --- a/tests/auto/qdbusperformance/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -tst_qdbusperformance -server/server diff --git a/tests/auto/qdbusperformance/qdbusperformance.pro b/tests/auto/qdbusperformance/qdbusperformance.pro deleted file mode 100644 index 6880518..0000000 --- a/tests/auto/qdbusperformance/qdbusperformance.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -contains(QT_CONFIG,dbus): { - TEMPLATE = subdirs - CONFIG += ordered - SUBDIRS = server test -} else { - SOURCES += ../qdbusmarshall/dummy.cpp -} diff --git a/tests/auto/qdbusperformance/server/server.cpp b/tests/auto/qdbusperformance/server/server.cpp deleted file mode 100644 index 3bd5efc..0000000 --- a/tests/auto/qdbusperformance/server/server.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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 "../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/auto/qdbusperformance/server/server.pro b/tests/auto/qdbusperformance/server/server.pro deleted file mode 100644 index 30f81dd..0000000 --- a/tests/auto/qdbusperformance/server/server.pro +++ /dev/null @@ -1,5 +0,0 @@ -SOURCES = server.cpp -HEADERS = ../serverobject.h -TARGET = server -CONFIG += qdbus -QT -= gui diff --git a/tests/auto/qdbusperformance/serverobject.h b/tests/auto/qdbusperformance/serverobject.h deleted file mode 100644 index 6f85bb4..0000000 --- a/tests/auto/qdbusperformance/serverobject.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** 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 -#include - -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/auto/qdbusperformance/test/test.pro b/tests/auto/qdbusperformance/test/test.pro deleted file mode 100644 index 9f5712e..0000000 --- a/tests/auto/qdbusperformance/test/test.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -SOURCES += ../tst_qdbusperformance.cpp -HEADERS += ../serverobject.h -TARGET = ../tst_qdbusperformance - -QT = core -CONFIG += qdbus diff --git a/tests/auto/qdbusperformance/tst_qdbusperformance.cpp b/tests/auto/qdbusperformance/tst_qdbusperformance.cpp deleted file mode 100644 index a5b4b98..0000000 --- a/tests/auto/qdbusperformance/tst_qdbusperformance.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/**************************************************************************** -** -** 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 "./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("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 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("data"); - QTest::addColumn("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/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/dbus/dbus.pro b/tests/benchmarks/dbus/dbus.pro new file mode 100644 index 0000000..b02d070 --- /dev/null +++ b/tests/benchmarks/dbus/dbus.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = \ + qdbusperformance 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 +#include + +#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 +#include + +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 +#include +#include + +#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("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 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("data"); + QTest::addColumn("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" -- cgit v0.12