1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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$
** GNU Lesser General Public License Usage
** 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.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $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"
|