author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
#include <QtCore/QtCore> |
|
42 |
#include <QtTest/QtTest> |
|
43 |
#include <QtDBus/QtDBus> |
|
44 |
||
45 |
#include "./serverobject.h" |
|
46 |
||
47 |
static const char serviceName[] = "com.trolltech.autotests.performance"; |
|
48 |
static const int runTime = 500; |
|
49 |
||
50 |
class tst_QDBusPerformance: public QObject |
|
51 |
{ |
|
52 |
Q_OBJECT |
|
53 |
QProcess proc; |
|
54 |
QDBusInterface *target; |
|
55 |
||
56 |
QDBusInterface *remote; |
|
57 |
QDBusInterface *local; |
|
58 |
||
59 |
bool executeTest(const char *funcname, int size, const QVariant &data); |
|
60 |
||
61 |
public slots: |
|
62 |
void initTestCase_data(); |
|
63 |
void initTestCase(); |
|
64 |
void init(); |
|
65 |
||
66 |
private slots: |
|
67 |
void callSpeed(); |
|
68 |
||
69 |
void oneWay_data(); |
|
70 |
void oneWay(); |
|
71 |
void oneWayVariant_data(); |
|
72 |
void oneWayVariant(); |
|
73 |
||
74 |
void roundTrip_data(); |
|
75 |
void roundTrip(); |
|
76 |
void roundTripVariant_data(); |
|
77 |
void roundTripVariant(); |
|
78 |
}; |
|
79 |
Q_DECLARE_METATYPE(QVariant) |
|
80 |
||
81 |
void tst_QDBusPerformance::initTestCase() |
|
82 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
QDBusConnection con = QDBusConnection::sessionBus(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
QVERIFY(con.isConnected()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
QDBusServiceWatcher watcher(serviceName, con, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
QDBusServiceWatcher::WatchForRegistration); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
connect(&watcher, SIGNAL(serviceRegistered(QString)), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
&QTestEventLoop::instance(), SLOT(exitLoop())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
|
0 | 91 |
#ifdef Q_OS_WIN |
92 |
proc.start("server"); |
|
93 |
#else |
|
94 |
proc.start("./server/server"); |
|
95 |
#endif |
|
96 |
QVERIFY(proc.waitForStarted()); |
|
97 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
QTestEventLoop::instance().enterLoop(5); |
0 | 99 |
QVERIFY(con.interface()->isServiceRegistered(serviceName)); |
100 |
||
101 |
remote = new QDBusInterface(serviceName, "/", "com.trolltech.autotests.Performance", con, this); |
|
102 |
QVERIFY(remote->isValid()); |
|
103 |
||
104 |
new ServerObject("/", con, this); |
|
105 |
local = new QDBusInterface(con.baseService(), "/", "com.trolltech.autotests.Performance", con, this); |
|
106 |
QVERIFY(local->isValid()); |
|
107 |
} |
|
108 |
||
109 |
void tst_QDBusPerformance::initTestCase_data() |
|
110 |
{ |
|
111 |
QTest::addColumn<bool>("loopback"); |
|
112 |
||
113 |
QTest::newRow("normal") << false; |
|
114 |
QTest::newRow("loopback") << true; |
|
115 |
} |
|
116 |
||
117 |
void tst_QDBusPerformance::init() |
|
118 |
{ |
|
119 |
QFETCH_GLOBAL(bool, loopback); |
|
120 |
if (loopback) |
|
121 |
target = local; |
|
122 |
else |
|
123 |
target = remote; |
|
124 |
} |
|
125 |
||
126 |
void tst_QDBusPerformance::callSpeed() |
|
127 |
{ |
|
128 |
QTime timer; |
|
129 |
||
130 |
int callCount = 0; |
|
131 |
timer.start(); |
|
132 |
while (timer.elapsed() < runTime) { |
|
133 |
QDBusReply<void> reply = target->call("nothing"); |
|
134 |
QVERIFY(reply.isValid()); |
|
135 |
||
136 |
++callCount; |
|
137 |
} |
|
138 |
qDebug() << callCount << "calls in" << timer.elapsed() << "ms:" |
|
139 |
<< (callCount * 1000.0 / timer.elapsed()) << "calls/sec"; |
|
140 |
} |
|
141 |
||
142 |
bool tst_QDBusPerformance::executeTest(const char *funcname, int size, const QVariant &data) |
|
143 |
{ |
|
144 |
QTime timer; |
|
145 |
||
146 |
int callCount = 0; |
|
147 |
qint64 transferred = 0; |
|
148 |
timer.start(); |
|
149 |
while (timer.elapsed() < runTime) { |
|
150 |
QDBusMessage reply = target->call(funcname, data); |
|
151 |
if (reply.type() != QDBusMessage::ReplyMessage) |
|
152 |
return false; |
|
153 |
||
154 |
transferred += size; |
|
155 |
++callCount; |
|
156 |
} |
|
157 |
qDebug() << transferred << "bytes in" << timer.elapsed() << "ms" |
|
158 |
<< "(in" << callCount << "calls):" |
|
159 |
<< (transferred * 1000.0 / timer.elapsed() / 1024 / 1024) << "MB/s"; |
|
160 |
||
161 |
return true; |
|
162 |
} |
|
163 |
||
164 |
void tst_QDBusPerformance::oneWay_data() |
|
165 |
{ |
|
166 |
QTest::addColumn<QVariant>("data"); |
|
167 |
QTest::addColumn<int>("size"); |
|
168 |
||
169 |
QByteArray ba(256, 'a'); |
|
170 |
while (ba.size() < 8193) { |
|
171 |
QTest::newRow(QString("%1-byteArray").arg(ba.size()).toAscii()) << qVariantFromValue(ba) << ba.size(); |
|
172 |
ba += ba; |
|
173 |
} |
|
174 |
||
175 |
QString s(256, QLatin1Char('a')); |
|
176 |
while (s.size() < 8193) { |
|
177 |
QTest::newRow(QString("%1-string").arg(s.size()).toAscii()) << qVariantFromValue(s) << s.size(); |
|
178 |
s += s; |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
void tst_QDBusPerformance::oneWay() |
|
183 |
{ |
|
184 |
QFETCH(QVariant, data); |
|
185 |
QFETCH(int, size); |
|
186 |
||
187 |
QVERIFY(executeTest("size", size, data)); |
|
188 |
} |
|
189 |
||
190 |
void tst_QDBusPerformance::oneWayVariant_data() |
|
191 |
{ |
|
192 |
oneWay_data(); |
|
193 |
} |
|
194 |
||
195 |
void tst_QDBusPerformance::oneWayVariant() |
|
196 |
{ |
|
197 |
QFETCH(QVariant, data); |
|
198 |
QFETCH(int, size); |
|
199 |
||
200 |
QVERIFY(executeTest("size", size, qVariantFromValue(QDBusVariant(data)))); |
|
201 |
} |
|
202 |
||
203 |
void tst_QDBusPerformance::roundTrip_data() |
|
204 |
{ |
|
205 |
oneWay_data(); |
|
206 |
} |
|
207 |
||
208 |
void tst_QDBusPerformance::roundTrip() |
|
209 |
{ |
|
210 |
QFETCH(QVariant, data); |
|
211 |
QFETCH(int, size); |
|
212 |
||
213 |
QVERIFY(executeTest("echo", size, data)); |
|
214 |
} |
|
215 |
||
216 |
void tst_QDBusPerformance::roundTripVariant_data() |
|
217 |
{ |
|
218 |
oneWay_data(); |
|
219 |
} |
|
220 |
||
221 |
void tst_QDBusPerformance::roundTripVariant() |
|
222 |
{ |
|
223 |
QFETCH(QVariant, data); |
|
224 |
QFETCH(int, size); |
|
225 |
||
226 |
QVERIFY(executeTest("echo", size, qVariantFromValue(QDBusVariant(data)))); |
|
227 |
} |
|
228 |
||
229 |
QTEST_MAIN(tst_QDBusPerformance) |
|
230 |
#include "tst_qdbusperformance.moc" |