source: trunk/tools/qtestlib/wince/cetest/main.cpp

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 17.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the tools applications of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifdef QT_CETEST_NO_ACTIVESYNC
43# include "cetcpsyncconnection.h"
44#else
45# include "activesyncconnection.h"
46#endif
47
48const int SLEEP_AFTER_RESET = 60000; // sleep for 1 minute
49const int SLEEP_RECONNECT = 2000; // sleep for 2 seconds before trying another reconnect
50
51#include "deployment.h"
52#include <option.h>
53#include <project.h>
54#include <property.h>
55#include <qstringlist.h>
56#include <qfileinfo.h>
57#include <qdir.h>
58#include <iostream>
59using namespace std;
60
61const int debugLevel = 0;
62void debugOutput(const QString& text, int level)
63{
64 if (level <= debugLevel)
65 cout << qPrintable(text) << endl;
66}
67
68// needed for QMake sources to compile
69QString project_builtin_regx() { return QString();}
70static QString pwd;
71QString qmake_getpwd()
72{
73 if(pwd.isNull())
74 pwd = QDir::currentPath();
75 return pwd;
76}
77bool qmake_setpwd(const QString &p)
78{
79 if(QDir::setCurrent(p)) {
80 pwd = QDir::currentPath();
81 return true;
82 }
83 return false;
84}
85
86namespace TestConfiguration {
87 QString localExecutable;
88 QString localQtConf;
89 QString remoteTestPath;
90 QString remoteLibraryPath;
91 QString remoteExecutable;
92 QString remoteResultFile;
93
94 bool testDebug;
95 void init()
96 {
97 testDebug = true;
98 localQtConf = QLatin1String("no");
99 remoteTestPath = QLatin1String("\\Program Files\\qt_test");
100 remoteLibraryPath = remoteTestPath;
101 remoteResultFile = QLatin1String("\\qt_test_results.txt");
102 }
103}
104
105void usage()
106{
107 cout <<
108 "QTestLib options\n"
109 " -functions : Returns a list of current testfunctions\n"
110 " -xml : Outputs results as XML document\n"
111 " -lightxml : Outputs results as stream of XML tags\n"
112 " -o filename: Writes all output into a file\n"
113 " -silent : Only outputs warnings and failures\n"
114 " -v1 : Print enter messages for each testfunction\n"
115 " -v2 : Also print out each QVERIFY/QCOMPARE/QTEST\n"
116 " -vs : Print every signal emitted\n"
117 " -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n"
118 " -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n"
119 " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n"
120 " -keyevent-verbose : Turn on verbose messages for keyboard simulation\n"
121 " -maxwarnings n : Sets the maximum amount of messages to output.\n"
122 " 0 means unlimited, default: 2000\n"
123 " -help : This help\n";
124 cout <<
125 "cetest specific options\n"
126 " -debug : Test debug version[default]\n"
127 " -release : Test release version\n"
128 " -libpath <path> : Remote path to deploy Qt libraries to\n"
129 " -reset : Reset device before starting a test\n"
130 " -awake : Device does not go sleep mode\n"
131 " -qt-delete : Delete the Qt libraries after execution\n"
132 " -project-delete : Delete the project file(s) after execution\n"
133 " -delete : Delete everything deployed after execution\n"
134 " -conf : Specify location of qt.conf file\n"
135 " -f <file> : Specify project file\n"
136 " -cache <file> : Specify .qmake.cache file to use\n"
137 " -d : Increase qmake debugging \n"
138 " -timeout <value> : Specify a timeout value after which the test will be terminated\n"
139 " -1 specifies waiting forever (default)\n"
140 " 0 specifies starting the process detached\n"
141 " >0 wait <value> seconds\n"
142 "\n";
143}
144
145int main(int argc, char **argv)
146{
147 QStringList arguments;
148 for (int i=0; i<argc; ++i)
149 arguments.append(QString::fromLatin1(argv[i]));
150
151 TestConfiguration::init();
152
153 QStringList launchArguments;
154 QString resultFile;
155 QString proFile;
156 QString cacheFile;
157 int timeout = -1;
158 bool cleanupQt = false;
159 bool cleanupProject = false;
160 bool deviceReset = false;
161 bool keepAwake = false;
162
163 for (int i=1; i<arguments.size(); ++i) {
164 if (arguments.at(i).toLower() == QLatin1String("-help")
165 || arguments.at(i).toLower() == QLatin1String("--help")
166 || arguments.at(i).toLower() == QLatin1String("/?")) {
167 usage();
168 return 0;
169 } else if (arguments.at(i).toLower() == QLatin1String("-o")) {
170 if (++i == arguments.size()) {
171 cout << "Error: No output file specified!" << endl;
172 return -1;
173 }
174 resultFile = arguments.at(i);
175 } else if (arguments.at(i).toLower() == QLatin1String("-eventdelay")
176 || arguments.at(i).toLower() == QLatin1String("-keydelay")
177 || arguments.at(i).toLower() == QLatin1String("-mousedelay")
178 || arguments.at(i).toLower() == QLatin1String("-maxwarnings")) {
179 launchArguments.append(arguments.at(i++));
180 if (i == arguments.size()) {
181 cout << "Please specify value for:" << qPrintable(arguments.at(i-1).mid(1)) << endl;
182 return -1;
183 }
184 launchArguments.append(arguments.at(i));
185 } else if (arguments.at(i).toLower() == QLatin1String("-debug")) {
186 TestConfiguration::testDebug = true;
187 Option::before_user_vars.append("CONFIG-=release");
188 Option::before_user_vars.append("CONFIG+=debug");
189 } else if (arguments.at(i).toLower() == QLatin1String("-release")) {
190 TestConfiguration::testDebug = false;
191 Option::before_user_vars.append("CONFIG-=debug");
192 Option::before_user_vars.append("CONFIG+=release");
193 } else if (arguments.at(i).toLower() == QLatin1String("-libpath")) {
194 if (++i == arguments.size()) {
195 cout << "Error: No library path specified!" << endl;
196 return -1;
197 }
198 TestConfiguration::remoteLibraryPath = arguments.at(i);
199 } else if (arguments.at(i).toLower() == QLatin1String("-qt-delete")) {
200 cleanupQt = true;
201 } else if (arguments.at(i).toLower() == QLatin1String("-project-delete")) {
202 cleanupProject = true;
203 } else if (arguments.at(i).toLower() == QLatin1String("-delete")) {
204 cleanupQt = true;
205 cleanupProject = true;
206 } else if (arguments.at(i).toLower() == QLatin1String("-reset")) {
207 deviceReset = true;
208 } else if (arguments.at(i).toLower() == QLatin1String("-awake")) {
209 keepAwake = true;
210 } else if (arguments.at(i).toLower() == QLatin1String("-conf")) {
211 if (++i == arguments.size()) {
212 cout << "Error: No qt.conf file specified!" << endl;
213 return -1;
214 }
215 if (!QFileInfo(arguments.at(i)).exists())
216 cout << "Warning: could not find qt.conf file at:" << qPrintable(arguments.at(i)) << endl;
217 else
218 TestConfiguration::localQtConf = arguments.at(i);
219 } else if (arguments.at(i).toLower() == QLatin1String("-f")) {
220 if (++i == arguments.size()) {
221 cout << "Error: No output file specified!" << endl;
222 return -1;
223 }
224 proFile = arguments.at(i);
225 } else if (arguments.at(i).toLower() == QLatin1String("-cache")) {
226 if (++i == arguments.size()) {
227 cout << "Error: No cache file specified!" << endl;
228 return -1;
229 }
230 cacheFile = arguments.at(i);
231 } else if (arguments.at(i).toLower() == QLatin1String("-d")) {
232 Option::debug_level++;
233 } else if (arguments.at(i).toLower() == QLatin1String("-timeout")) {
234 if (++i == arguments.size()) {
235 cout << "Error: No timeout value specified!" << endl;
236 return -1;
237 }
238 timeout = QString(arguments.at(i)).toInt();
239 } else {
240 launchArguments.append(arguments.at(i));
241 }
242 }
243
244 // check for .pro file
245 if (proFile.isEmpty()) {
246 proFile = QDir::current().dirName() + QLatin1String(".pro");
247 if (!QFileInfo(proFile).exists()) {
248 cout << "Error: Could not find project file in current directory." << endl;
249 return -1;
250 }
251 debugOutput(QString::fromLatin1("Using Project File:").append(proFile),1);
252 }else {
253 if (!QFileInfo(proFile).exists()) {
254 cout << "Error: Project file does not exist " << qPrintable(proFile) << endl;
255 return -1;
256 }
257 }
258
259 Option::before_user_vars.append("CONFIG+=build_pass");
260
261 // read target and deployment rules passing the .pro to use instead of
262 // relying on qmake guessing the .pro to use
263 int qmakeArgc = 2;
264 QByteArray ba(QFile::encodeName(proFile));
265 char* proFileEncodedName = ba.data();
266 char* qmakeArgv[2] = { "qmake.exe", proFileEncodedName };
267
268 Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
269 Option::output_dir = qmake_getpwd();
270 if (!cacheFile.isEmpty())
271 Option::mkfile::cachefile = cacheFile;
272 int ret = Option::init(qmakeArgc, qmakeArgv);
273 if(ret != Option::QMAKE_CMDLINE_SUCCESS) {
274 cout << "Error: could not parse " << qPrintable(proFile) << endl;
275 return -1;
276 }
277
278 QMakeProperty prop;
279 QMakeProject project(&prop);
280
281 project.read(proFile);
282 if (project.values("TEMPLATE").join(" ").toLower() != QString("app")) {
283 cout << "Error: Can only test executables!" << endl;
284 return -1;
285 }
286 // Check whether the project is still in debug/release mode after reading
287 // If .pro specifies to be one mode only, we need to accept this
288 if (project.isActiveConfig("debug") && !project.isActiveConfig("release")) {
289 TestConfiguration::testDebug = true;
290 debugOutput("ActiveConfig: debug only in .pro.", 1);
291 }
292 if (!project.isActiveConfig("debug") && project.isActiveConfig("release")) {
293 TestConfiguration::testDebug = false;
294 debugOutput("ActiveConfig: release only in .pro.", 1);
295 }
296
297 // determine what is the real mkspec to use if the default mkspec is being used
298 if (Option::mkfile::qmakespec.endsWith("/default"))
299 project.values("QMAKESPEC") = project.values("QMAKESPEC_ORIGINAL");
300 else
301 project.values("QMAKESPEC") = QStringList() << Option::mkfile::qmakespec;
302
303 // ensure that QMAKESPEC is non-empty .. to meet requirements of QList::at()
304 if (project.values("QMAKESPEC").isEmpty()){
305 cout << "Error: QMAKESPEC not set after parsing " << qPrintable(proFile) << endl;
306 return -1;
307 }
308
309 // ensure that QT_CE_C_RUNTIME is non-empty .. to meet requirements of QList::at()
310 if (project.values("QT_CE_C_RUNTIME").isEmpty()){
311 cout << "Error: QT_CE_C_RUNTIME not defined in mkspec/qconfig.pri " << qPrintable(project.values("QMAKESPEC").join(" "));
312 return -1;
313 }
314
315 QString destDir = project.values("DESTDIR").join(" ");
316 if (!destDir.isEmpty()) {
317 if (QDir::isRelativePath(destDir)) {
318 QFileInfo fi(proFile);
319 if (destDir == QLatin1String("."))
320 destDir = fi.absolutePath() + "/" + destDir + "/" + (TestConfiguration::testDebug ? "debug" : "release");
321 else
322 destDir = fi.absolutePath() + QDir::separator() + destDir;
323 }
324 } else {
325 QFileInfo fi(proFile);
326 destDir = fi.absolutePath();
327 destDir += QDir::separator() + QLatin1String(TestConfiguration::testDebug ? "debug" : "release");
328 }
329
330 DeploymentList qtDeploymentList;
331 DeploymentList projectDeploymentList;
332
333 TestConfiguration::localExecutable = Option::fixPathToLocalOS(destDir + QDir::separator() + project.values("TARGET").join(" ") + QLatin1String(".exe"));
334 TestConfiguration::remoteTestPath = QLatin1String("\\Program Files\\") + Option::fixPathToLocalOS(project.values("TARGET").join(QLatin1String(" ")));
335 if (!arguments.contains(QLatin1String("-libpath"), Qt::CaseInsensitive))
336 TestConfiguration::remoteLibraryPath = TestConfiguration::remoteTestPath;
337
338 QString targetExecutable = Option::fixPathToLocalOS(project.values("TARGET").join(QLatin1String(" ")));
339 int last = targetExecutable.lastIndexOf(QLatin1Char('\\'));
340 targetExecutable = targetExecutable.mid( last == -1 ? 0 : last+1 );
341 TestConfiguration::remoteExecutable = TestConfiguration::remoteTestPath + QDir::separator() + targetExecutable + QLatin1String(".exe");
342 projectDeploymentList.append(CopyItem(TestConfiguration::localExecutable , TestConfiguration::remoteExecutable));
343
344 // deploy
345#ifdef QT_CETEST_NO_ACTIVESYNC
346 CeTcpSyncConnection connection;
347#else
348 ActiveSyncConnection connection;
349#endif
350 if (!connection.connect()) {
351 cout << "Error: Could not connect to device!" << endl;
352 return -1;
353 }
354 DeploymentHandler deployment;
355 deployment.setConnection(&connection);
356
357 deployment.initQtDeploy(&project, qtDeploymentList, TestConfiguration::remoteLibraryPath);
358 deployment.initProjectDeploy(&project , projectDeploymentList, TestConfiguration::remoteTestPath);
359
360 // add qt.conf
361 if (TestConfiguration::localQtConf != QLatin1String("no")) {
362 QString qtConfOrigin = QFileInfo(TestConfiguration::localQtConf).absoluteFilePath();
363 QString qtConfTarget = Option::fixPathToLocalOS(TestConfiguration::remoteTestPath + QDir::separator() + QLatin1String("qt.conf"));
364 projectDeploymentList.append(CopyItem(qtConfOrigin, qtConfTarget));
365 }
366
367 if (!deployment.deviceDeploy(qtDeploymentList) || !deployment.deviceDeploy(projectDeploymentList)) {
368 cout << "Error: Could not copy file(s) to device" << endl;
369 return -1;
370 }
371 // device power mode
372 if (keepAwake)
373 {
374 int retVal = 0;
375 if (!connection.setDeviceAwake(true, &retVal)) {
376 cout << "Error: Could not set unattended mode on device" << endl;
377 return -1;
378 }
379 }
380
381 // reset device
382 if (deviceReset)
383 {
384 if (!connection.resetDevice()) {
385 //if (!connection.toggleDevicePower( &retVal)) {
386 cout << "Error: Could not reset the device" << endl;
387 return -1;
388 }
389 cout << " Entering sleep after reset for " << SLEEP_AFTER_RESET / 1000 << " seconds ... " << endl;
390 Sleep(SLEEP_AFTER_RESET);
391 cout << " ... woke up. " << endl;
392 connection.disconnect();
393 // reconnect after reset
394 int retryCount = 21;
395 while (--retryCount)
396 {
397 if (!connection.connect())
398 Sleep(SLEEP_RECONNECT);
399 else
400 break;
401 }
402 if (!connection.isConnected())
403 {
404 cout << "Error: Could not connect to device!" << endl;
405 return -1;
406 }
407 }
408
409 // launch
410 launchArguments.append("-o");
411 launchArguments.append(TestConfiguration::remoteResultFile);
412
413 cout << endl << "Remote Launch:" << qPrintable(TestConfiguration::remoteExecutable) << " " << qPrintable(launchArguments.join(" ")) << endl;
414 if (!connection.execute(TestConfiguration::remoteExecutable, launchArguments.join(" "), timeout)) {
415 cout << "Error: Could not execute target file" << endl;
416 return -1;
417 }
418
419
420 // copy result file
421 // show results
422 if (resultFile.isEmpty()) {
423 QString tempResultFile = Option::fixPathToLocalOS(QDir::tempPath() + "/qt_ce_temp_result_file.txt");
424 if (connection.copyFileFromDevice(TestConfiguration::remoteResultFile, tempResultFile)) {
425 QFile file(tempResultFile);
426 QByteArray arr;
427 if (file.open(QIODevice::ReadOnly)) {
428 arr = file.readAll();
429 cout << arr.constData() << endl;
430 }
431 file.close();
432 file.remove();
433 }
434 } else {
435 connection.copyFileFromDevice(TestConfiguration::remoteResultFile, resultFile);
436 }
437
438 // delete
439 connection.deleteFile(TestConfiguration::remoteResultFile);
440 if (cleanupQt)
441 deployment.cleanup(qtDeploymentList);
442 if (cleanupProject)
443 deployment.cleanup(projectDeploymentList);
444 return 0;
445}
Note: See TracBrowser for help on using the repository browser.