1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
10 ** This file contains pre-release code and may not be distributed.
11 ** You may use this file in accordance with the terms and conditions
12 ** contained in the Technology Preview License Agreement accompanying
15 ** GNU Lesser General Public License Usage
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** General Public License version 2.1 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** packaging of this file. Please review the following information to
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 ** In addition, as a special exception, Nokia gives you certain
24 ** additional rights. These rights are described in the Nokia Qt LGPL
25 ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
41 #include <QtCore/QtCore>
42 #include <QtTest/QtTest>
43 #include <QtDBus/QtDBus>
45 #include "./serverobject.h"
47 static const char serviceName
[] = "com.trolltech.autotests.performance";
48 static const int runTime
= 500;
50 class tst_QDBusPerformance
: public QObject
54 QDBusInterface
*target
;
56 QDBusInterface
*remote
;
57 QDBusInterface
*local
;
59 bool executeTest(const char *funcname
, int size
, const QVariant
&data
);
62 void initTestCase_data();
71 void oneWayVariant_data();
74 void roundTrip_data();
76 void roundTripVariant_data();
77 void roundTripVariant();
79 Q_DECLARE_METATYPE(QVariant
)
81 void tst_QDBusPerformance::initTestCase()
86 proc
.start("./server/server");
88 QVERIFY(proc
.waitForStarted());
90 QDBusConnection con
= QDBusConnection::sessionBus();
91 QVERIFY(con
.isConnected());
93 connect(con
.interface(), SIGNAL(serviceOwnerChanged(QString
,QString
,QString
)),
94 &QTestEventLoop::instance(), SLOT(exitLoop()));
98 while (timer
.elapsed() < 5000) {
99 QTestEventLoop::instance().enterLoop(5);
100 if (con
.interface()->isServiceRegistered(serviceName
))
103 QVERIFY(con
.interface()->isServiceRegistered(serviceName
));
105 remote
= new QDBusInterface(serviceName
, "/", "com.trolltech.autotests.Performance", con
, this);
106 QVERIFY(remote
->isValid());
108 new ServerObject("/", con
, this);
109 local
= new QDBusInterface(con
.baseService(), "/", "com.trolltech.autotests.Performance", con
, this);
110 QVERIFY(local
->isValid());
113 void tst_QDBusPerformance::initTestCase_data()
115 QTest::addColumn
<bool>("loopback");
117 QTest::newRow("normal") << false;
118 QTest::newRow("loopback") << true;
121 void tst_QDBusPerformance::init()
123 QFETCH_GLOBAL(bool, loopback
);
130 void tst_QDBusPerformance::callSpeed()
136 while (timer
.elapsed() < runTime
) {
137 QDBusReply
<void> reply
= target
->call("nothing");
138 QVERIFY(reply
.isValid());
142 qDebug() << callCount
<< "calls in" << timer
.elapsed() << "ms:"
143 << (callCount
* 1000.0 / timer
.elapsed()) << "calls/sec";
146 bool tst_QDBusPerformance::executeTest(const char *funcname
, int size
, const QVariant
&data
)
151 qint64 transferred
= 0;
153 while (timer
.elapsed() < runTime
) {
154 QDBusMessage reply
= target
->call(funcname
, data
);
155 if (reply
.type() != QDBusMessage::ReplyMessage
)
161 qDebug() << transferred
<< "bytes in" << timer
.elapsed() << "ms"
162 << "(in" << callCount
<< "calls):"
163 << (transferred
* 1000.0 / timer
.elapsed() / 1024 / 1024) << "MB/s";
168 void tst_QDBusPerformance::oneWay_data()
170 QTest::addColumn
<QVariant
>("data");
171 QTest::addColumn
<int>("size");
173 QByteArray
ba(256, 'a');
174 while (ba
.size() < 8193) {
175 QTest::newRow(QString("%1-byteArray").arg(ba
.size()).toAscii()) << qVariantFromValue(ba
) << ba
.size();
179 QString
s(256, QLatin1Char('a'));
180 while (s
.size() < 8193) {
181 QTest::newRow(QString("%1-string").arg(s
.size()).toAscii()) << qVariantFromValue(s
) << s
.size();
186 void tst_QDBusPerformance::oneWay()
188 QFETCH(QVariant
, data
);
191 QVERIFY(executeTest("size", size
, data
));
194 void tst_QDBusPerformance::oneWayVariant_data()
199 void tst_QDBusPerformance::oneWayVariant()
201 QFETCH(QVariant
, data
);
204 QVERIFY(executeTest("size", size
, qVariantFromValue(QDBusVariant(data
))));
207 void tst_QDBusPerformance::roundTrip_data()
212 void tst_QDBusPerformance::roundTrip()
214 QFETCH(QVariant
, data
);
217 QVERIFY(executeTest("echo", size
, data
));
220 void tst_QDBusPerformance::roundTripVariant_data()
225 void tst_QDBusPerformance::roundTripVariant()
227 QFETCH(QVariant
, data
);
230 QVERIFY(executeTest("echo", size
, qVariantFromValue(QDBusVariant(data
))));
233 QTEST_MAIN(tst_QDBusPerformance
)
234 #include "tst_qdbusperformance.moc"