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

Last change on this file since 729 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

  • Property svn:eol-style set to native
File size: 16.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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
48#include "deployment.h"
49#include <option.h>
50#include <project.h>
51#include <property.h>
52#include <qstringlist.h>
53#include <qfileinfo.h>
54#include <qdir.h>
55#include <iostream>
56using namespace std;
57
58const int debugLevel = 0;
59void debugOutput(const QString& text, int level)
60{
61 if (level <= debugLevel)
62 cout << qPrintable(text) << endl;
63}
64
65// needed for QMake sources to compile
66QString project_builtin_regx() { return QString();}
67static QString pwd;
68QString qmake_getpwd()
69{
70 if(pwd.isNull())
71 pwd = QDir::currentPath();
72 return pwd;
73}
74bool qmake_setpwd(const QString &p)
75{
76 if(QDir::setCurrent(p)) {
77 pwd = QDir::currentPath();
78 return true;
79 }
80 return false;
81}
82
83namespace TestConfiguration {
84 QString localExecutable;
85 QString localQtConf;
86 QString remoteTestPath;
87 QString remoteLibraryPath;
88 QString remoteExecutable;
89 QString remoteResultFile;
90
91 bool testDebug;
92 void init()
93 {
94 testDebug = true;
95 localQtConf = QLatin1String("no");
96 remoteTestPath = QLatin1String("\\Program Files\\qt_test");
97 remoteLibraryPath = remoteTestPath;
98 remoteResultFile = QLatin1String("\\qt_test_results.txt");
99 }
100}
101
102void usage()
103{
104 cout <<
105 "QTestLib options\n"
106 " -functions : Returns a list of current testfunctions\n"
107 " -xml : Outputs results as XML document\n"
108 " -lightxml : Outputs results as stream of XML tags\n"
109 " -o filename: Writes all output into a file\n"
110 " -silent : Only outputs warnings and failures\n"
111 " -v1 : Print enter messages for each testfunction\n"
112 " -v2 : Also print out each QVERIFY/QCOMPARE/QTEST\n"
113 " -vs : Print every signal emitted\n"
114 " -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n"
115 " -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n"
116 " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n"
117 " -keyevent-verbose : Turn on verbose messages for keyboard simulation\n"
118 " -maxwarnings n : Sets the maximum amount of messages to output.\n"
119 " 0 means unlimited, default: 2000\n"
120 " -help : This help\n";
121 cout <<
122 "cetest specific options\n"
123 " -debug : Test debug version[default]\n"
124 " -release : Test release version\n"
125 " -libpath <path> : Remote path to deploy Qt libraries to\n"
126 " -qt-delete : Delete the Qt libraries after execution\n"
127 " -project-delete : Delete the project file(s) after execution\n"
128 " -delete : Delete everything deployed after execution\n"
129 " -conf : Specify location of qt.conf file\n"
130 " -f <file> : Specify project file\n"
131 " -cache <file> : Specify .qmake.cache file to use\n"
132 " -d : Increase qmake debugging \n"
133 " -timeout <value> : Specify a timeout value after which the test will be terminated\n"
134 " -1 specifies waiting forever (default)\n"
135 " 0 specifies starting the process detached\n"
136 " >0 wait <value> seconds\n"
137 "\n";
138}
139
140int main(int argc, char **argv)
141{
142 QStringList arguments;
143 for (int i=0; i<argc; ++i)
144 arguments.append(QString::fromLatin1(argv[i]));
145
146 TestConfiguration::init();
147
148 QStringList launchArguments;
149 QString resultFile;
150 QString proFile;
151 QString cacheFile;
152 int timeout = -1;
153 bool cleanupQt = false;
154 bool cleanupProject = false;
155
156 for (int i=1; i<arguments.size(); ++i) {
157 if (arguments.at(i).toLower() == QLatin1String("-help")
158 || arguments.at(i).toLower() == QLatin1String("--help")
159 || arguments.at(i).toLower() == QLatin1String("/?")) {
160 usage();
161 return 0;
162 } else if (arguments.at(i).toLower() == QLatin1String("-o")) {
163 if (++i == arguments.size()) {
164 cout << "Error: No output file specified!" << endl;
165 return -1;
166 }
167 resultFile = arguments.at(i);
168 } else if (arguments.at(i).toLower() == QLatin1String("-eventdelay")
169 || arguments.at(i).toLower() == QLatin1String("-keydelay")
170 || arguments.at(i).toLower() == QLatin1String("-mousedelay")
171 || arguments.at(i).toLower() == QLatin1String("-maxwarnings")) {
172 launchArguments.append(arguments.at(i++));
173 if (i == arguments.size()) {
174 cout << "Please specify value for:" << qPrintable(arguments.at(i-1).mid(1)) << endl;
175 return -1;
176 }
177 launchArguments.append(arguments.at(i));
178 } else if (arguments.at(i).toLower() == QLatin1String("-debug")) {
179 TestConfiguration::testDebug = true;
180 Option::before_user_vars.append("CONFIG-=release");
181 Option::before_user_vars.append("CONFIG+=debug");
182 } else if (arguments.at(i).toLower() == QLatin1String("-release")) {
183 TestConfiguration::testDebug = false;
184 Option::before_user_vars.append("CONFIG-=debug");
185 Option::before_user_vars.append("CONFIG+=release");
186 } else if (arguments.at(i).toLower() == QLatin1String("-libpath")) {
187 if (++i == arguments.size()) {
188 cout << "Error: No library path specified!" << endl;
189 return -1;
190 }
191 TestConfiguration::remoteLibraryPath = arguments.at(i);
192 } else if (arguments.at(i).toLower() == QLatin1String("-qt-delete")) {
193 cleanupQt = true;
194 } else if (arguments.at(i).toLower() == QLatin1String("-project-delete")) {
195 cleanupProject = true;
196 } else if (arguments.at(i).toLower() == QLatin1String("-delete")) {
197 cleanupQt = true;
198 cleanupProject = true;
199 } else if (arguments.at(i).toLower() == QLatin1String("-conf")) {
200 if (++i == arguments.size()) {
201 cout << "Error: No qt.conf file specified!" << endl;
202 return -1;
203 }
204 if (!QFileInfo(arguments.at(i)).exists())
205 cout << "Warning: could not find qt.conf file at:" << qPrintable(arguments.at(i)) << endl;
206 else
207 TestConfiguration::localQtConf = arguments.at(i);
208 } else if (arguments.at(i).toLower() == QLatin1String("-f")) {
209 if (++i == arguments.size()) {
210 cout << "Error: No output file specified!" << endl;
211 return -1;
212 }
213 proFile = arguments.at(i);
214 } else if (arguments.at(i).toLower() == QLatin1String("-cache")) {
215 if (++i == arguments.size()) {
216 cout << "Error: No cache file specified!" << endl;
217 return -1;
218 }
219 cacheFile = arguments.at(i);
220 } else if (arguments.at(i).toLower() == QLatin1String("-d")) {
221 Option::debug_level++;
222 } else if (arguments.at(i).toLower() == QLatin1String("-timeout")) {
223 if (++i == arguments.size()) {
224 cout << "Error: No timeout value specified!" << endl;
225 return -1;
226 }
227 timeout = QString(arguments.at(i)).toInt();
228 } else {
229 launchArguments.append(arguments.at(i));
230 }
231 }
232
233 // check for .pro file
234 if (proFile.isEmpty()) {
235 proFile = QDir::current().dirName() + QLatin1String(".pro");
236 if (!QFileInfo(proFile).exists()) {
237 cout << "Error: Could not find project file in current directory." << endl;
238 return -1;
239 }
240 debugOutput(QString::fromLatin1("Using Project File:").append(proFile),1);
241 }else {
242 if (!QFileInfo(proFile).exists()) {
243 cout << "Error: Project file does not exist " << qPrintable(proFile) << endl;
244 return -1;
245 }
246 }
247
248 Option::before_user_vars.append("CONFIG+=build_pass");
249
250 // read target and deployment rules passing the .pro to use instead of
251 // relying on qmake guessing the .pro to use
252 int qmakeArgc = 2;
253 QByteArray ba(QFile::encodeName(proFile));
254 char* proFileEncodedName = ba.data();
255 char* qmakeArgv[2] = { "qmake.exe", proFileEncodedName };
256
257 Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
258 Option::output_dir = qmake_getpwd();
259 if (!cacheFile.isEmpty())
260 Option::mkfile::cachefile = cacheFile;
261 int ret = Option::init(qmakeArgc, qmakeArgv);
262 if(ret != Option::QMAKE_CMDLINE_SUCCESS) {
263 cout << "Error: could not parse " << qPrintable(proFile) << endl;
264 return -1;
265 }
266
267 QMakeProperty prop;
268 QMakeProject project(&prop);
269
270 project.read(proFile);
271 if (project.values("TEMPLATE").join(" ").toLower() != QString("app")) {
272 cout << "Error: Can only test executables!" << endl;
273 return -1;
274 }
275 // Check wether the project is still in debug/release mode after reading
276 // If .pro specifies to be one mode only, we need to accept this
277 if (project.isActiveConfig("debug"))
278 TestConfiguration::testDebug = true;
279 else
280 TestConfiguration::testDebug = false;
281
282 // determine what is the real mkspec to use if the default mkspec is being used
283 if (Option::mkfile::qmakespec.endsWith("/default"))
284 project.values("QMAKESPEC") = project.values("QMAKESPEC_ORIGINAL");
285 else
286 project.values("QMAKESPEC") = QStringList() << Option::mkfile::qmakespec;
287
288 // ensure that QMAKESPEC is non-empty .. to meet requirements of QList::at()
289 if (project.values("QMAKESPEC").isEmpty()){
290 cout << "Error: QMAKESPEC not set after parsing " << qPrintable(proFile) << endl;
291 return -1;
292 }
293
294 // ensure that QT_CE_C_RUNTIME is non-empty .. to meet requirements of QList::at()
295 if (project.values("QT_CE_C_RUNTIME").isEmpty()){
296 cout << "Error: QT_CE_C_RUNTIME not defined in mkspec/qconfig.pri " << qPrintable(project.values("QMAKESPEC").join(" "));
297 return -1;
298 }
299
300 QString destDir = project.values("DESTDIR").join(" ");
301 if (!destDir.isEmpty()) {
302 if (QDir::isRelativePath(destDir)) {
303 QFileInfo fi(proFile);
304 if (destDir == QLatin1String("."))
305 destDir = fi.absolutePath() + "/" + destDir + "/" + (TestConfiguration::testDebug ? "debug" : "release");
306 else
307 destDir = fi.absolutePath() + QDir::separator() + destDir;
308 }
309 } else {
310 QFileInfo fi(proFile);
311 destDir = fi.absolutePath();
312 destDir += QDir::separator() + QLatin1String(TestConfiguration::testDebug ? "debug" : "release");
313 }
314
315 DeploymentList qtDeploymentList;
316 DeploymentList projectDeploymentList;
317
318 TestConfiguration::localExecutable = Option::fixPathToLocalOS(destDir + QDir::separator() + project.values("TARGET").join(" ") + QLatin1String(".exe"));
319 TestConfiguration::remoteTestPath = QLatin1String("\\Program Files\\") + Option::fixPathToLocalOS(project.values("TARGET").join(QLatin1String(" ")));
320 if (!arguments.contains(QLatin1String("-libpath"), Qt::CaseInsensitive))
321 TestConfiguration::remoteLibraryPath = TestConfiguration::remoteTestPath;
322
323 QString targetExecutable = Option::fixPathToLocalOS(project.values("TARGET").join(QLatin1String(" ")));
324 int last = targetExecutable.lastIndexOf(QLatin1Char('\\'));
325 targetExecutable = targetExecutable.mid( last == -1 ? 0 : last+1 );
326 TestConfiguration::remoteExecutable = TestConfiguration::remoteTestPath + QDir::separator() + targetExecutable + QLatin1String(".exe");
327 projectDeploymentList.append(CopyItem(TestConfiguration::localExecutable , TestConfiguration::remoteExecutable));
328
329 // deploy
330#ifdef QT_CETEST_NO_ACTIVESYNC
331 CeTcpSyncConnection connection;
332#else
333 ActiveSyncConnection connection;
334#endif
335 if (!connection.connect()) {
336 cout << "Error: Could not connect to device!" << endl;
337 return -1;
338 }
339 DeploymentHandler deployment;
340 deployment.setConnection(&connection);
341
342 deployment.initQtDeploy(&project, qtDeploymentList, TestConfiguration::remoteLibraryPath);
343 deployment.initProjectDeploy(&project , projectDeploymentList, TestConfiguration::remoteTestPath);
344
345 // add qt.conf
346 if (TestConfiguration::localQtConf != QLatin1String("no")) {
347 QString qtConfOrigin = QFileInfo(TestConfiguration::localQtConf).absoluteFilePath();
348 QString qtConfTarget = Option::fixPathToLocalOS(TestConfiguration::remoteTestPath + QDir::separator() + QLatin1String("qt.conf"));
349 projectDeploymentList.append(CopyItem(qtConfOrigin, qtConfTarget));
350 }
351
352 if (!deployment.deviceDeploy(qtDeploymentList) || !deployment.deviceDeploy(projectDeploymentList)) {
353 cout << "Error: Could not copy file(s) to device" << endl;
354 return -1;
355 }
356
357 // launch
358 launchArguments.append("-o");
359 launchArguments.append(TestConfiguration::remoteResultFile);
360
361 cout << endl << "Remote Launch:" << qPrintable(TestConfiguration::remoteExecutable) << " " << qPrintable(launchArguments.join(" ")) << endl;
362 if (!connection.execute(TestConfiguration::remoteExecutable, launchArguments.join(" "), timeout)) {
363 cout << "Error: Could not execute target file" << endl;
364 return -1;
365 }
366
367
368 // copy result file
369 // show results
370 if (resultFile.isEmpty()) {
371 QString tempResultFile = Option::fixPathToLocalOS(QDir::tempPath() + "/qt_ce_temp_result_file.txt");
372 if (connection.copyFileFromDevice(TestConfiguration::remoteResultFile, tempResultFile)) {
373 QFile file(tempResultFile);
374 QByteArray arr;
375 if (file.open(QIODevice::ReadOnly)) {
376 arr = file.readAll();
377 cout << arr.constData() << endl;
378 }
379 file.close();
380 file.remove();
381 }
382 } else {
383 connection.copyFileFromDevice(TestConfiguration::remoteResultFile, resultFile);
384 }
385
386 // delete
387 connection.deleteFile(TestConfiguration::remoteResultFile);
388 if (cleanupQt)
389 deployment.cleanup(qtDeploymentList);
390 if (cleanupProject)
391 deployment.cleanup(projectDeploymentList);
392 return 0;
393}
Note: See TracBrowser for help on using the repository browser.