|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the tools applications 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 |
|
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> |
|
56 using namespace std; |
|
57 |
|
58 const int debugLevel = 0; |
|
59 void 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 |
|
66 QString project_builtin_regx() { return QString();} |
|
67 static QString pwd; |
|
68 QString qmake_getpwd() |
|
69 { |
|
70 if(pwd.isNull()) |
|
71 pwd = QDir::currentPath(); |
|
72 return pwd; |
|
73 } |
|
74 bool qmake_setpwd(const QString &p) |
|
75 { |
|
76 if(QDir::setCurrent(p)) { |
|
77 pwd = QDir::currentPath(); |
|
78 return true; |
|
79 } |
|
80 return false; |
|
81 } |
|
82 |
|
83 namespace 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 |
|
102 void 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 " -timeout <value> : Specify a timeout value after which the test will be terminated\n" |
|
133 " -1 specifies waiting forever (default)\n" |
|
134 " 0 specifies starting the process detached\n" |
|
135 " >0 wait <value> seconds\n" |
|
136 "\n"; |
|
137 } |
|
138 |
|
139 int main(int argc, char **argv) |
|
140 { |
|
141 QStringList arguments; |
|
142 for (int i=0; i<argc; ++i) |
|
143 arguments.append(QString::fromLatin1(argv[i])); |
|
144 |
|
145 TestConfiguration::init(); |
|
146 |
|
147 QStringList launchArguments; |
|
148 QString resultFile; |
|
149 QString proFile; |
|
150 QString cacheFile; |
|
151 int timeout = -1; |
|
152 bool cleanupQt = false; |
|
153 bool cleanupProject = false; |
|
154 |
|
155 for (int i=1; i<arguments.size(); ++i) { |
|
156 if (arguments.at(i).toLower() == QLatin1String("-help") |
|
157 || arguments.at(i).toLower() == QLatin1String("--help") |
|
158 || arguments.at(i).toLower() == QLatin1String("/?")) { |
|
159 usage(); |
|
160 return 0; |
|
161 } else if (arguments.at(i).toLower() == QLatin1String("-o")) { |
|
162 if (++i == arguments.size()) { |
|
163 cout << "Error: No output file specified!" << endl; |
|
164 return -1; |
|
165 } |
|
166 resultFile = arguments.at(i); |
|
167 } else if (arguments.at(i).toLower() == QLatin1String("-eventdelay") |
|
168 || arguments.at(i).toLower() == QLatin1String("-keydelay") |
|
169 || arguments.at(i).toLower() == QLatin1String("-mousedelay") |
|
170 || arguments.at(i).toLower() == QLatin1String("-maxwarnings")) { |
|
171 launchArguments.append(arguments.at(i++)); |
|
172 if (i == arguments.size()) { |
|
173 cout << "Please specify value for:" << qPrintable(arguments.at(i-1).mid(1)) << endl; |
|
174 return -1; |
|
175 } |
|
176 launchArguments.append(arguments.at(i)); |
|
177 } else if (arguments.at(i).toLower() == QLatin1String("-debug")) { |
|
178 TestConfiguration::testDebug = true; |
|
179 Option::before_user_vars.append("CONFIG-=release"); |
|
180 Option::before_user_vars.append("CONFIG+=debug"); |
|
181 } else if (arguments.at(i).toLower() == QLatin1String("-release")) { |
|
182 TestConfiguration::testDebug = false; |
|
183 Option::before_user_vars.append("CONFIG-=debug"); |
|
184 Option::before_user_vars.append("CONFIG+=release"); |
|
185 } else if (arguments.at(i).toLower() == QLatin1String("-libpath")) { |
|
186 if (++i == arguments.size()) { |
|
187 cout << "Error: No library path specified!" << endl; |
|
188 return -1; |
|
189 } |
|
190 TestConfiguration::remoteLibraryPath = arguments.at(i); |
|
191 } else if (arguments.at(i).toLower() == QLatin1String("-qt-delete")) { |
|
192 cleanupQt = true; |
|
193 } else if (arguments.at(i).toLower() == QLatin1String("-project-delete")) { |
|
194 cleanupProject = true; |
|
195 } else if (arguments.at(i).toLower() == QLatin1String("-delete")) { |
|
196 cleanupQt = true; |
|
197 cleanupProject = true; |
|
198 } else if (arguments.at(i).toLower() == QLatin1String("-conf")) { |
|
199 if (++i == arguments.size()) { |
|
200 cout << "Error: No qt.conf file specified!" << endl; |
|
201 return -1; |
|
202 } |
|
203 if (!QFileInfo(arguments.at(i)).exists()) |
|
204 cout << "Warning: could not find qt.conf file at:" << qPrintable(arguments.at(i)) << endl; |
|
205 else |
|
206 TestConfiguration::localQtConf = arguments.at(i); |
|
207 } else if (arguments.at(i).toLower() == QLatin1String("-f")) { |
|
208 if (++i == arguments.size()) { |
|
209 cout << "Error: No output file specified!" << endl; |
|
210 return -1; |
|
211 } |
|
212 proFile = arguments.at(i); |
|
213 } else if (arguments.at(i).toLower() == QLatin1String("-cache")) { |
|
214 if (++i == arguments.size()) { |
|
215 cout << "Error: No cache file specified!" << endl; |
|
216 return -1; |
|
217 } |
|
218 cacheFile = arguments.at(i); |
|
219 } else if (arguments.at(i).toLower() == QLatin1String("-timeout")) { |
|
220 if (++i == arguments.size()) { |
|
221 cout << "Error: No timeout value specified!" << endl; |
|
222 return -1; |
|
223 } |
|
224 timeout = QString(arguments.at(i)).toInt(); |
|
225 } else { |
|
226 launchArguments.append(arguments.at(i)); |
|
227 } |
|
228 } |
|
229 |
|
230 // check for .pro file |
|
231 if (proFile.isEmpty()) { |
|
232 proFile = QDir::current().dirName() + QLatin1String(".pro"); |
|
233 if (!QFileInfo(proFile).exists()) { |
|
234 cout << "Error: Could not find project file in current directory." << endl; |
|
235 return -1; |
|
236 } |
|
237 debugOutput(QString::fromLatin1("Using Project File:").append(proFile),1); |
|
238 } |
|
239 |
|
240 Option::before_user_vars.append("CONFIG+=build_pass"); |
|
241 |
|
242 // read target and deployment rules |
|
243 int qmakeArgc = 1; |
|
244 char* qmakeArgv[] = { "qmake.exe" }; |
|
245 Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING; |
|
246 Option::output_dir = qmake_getpwd(); |
|
247 if (!cacheFile.isEmpty()) |
|
248 Option::mkfile::cachefile = cacheFile; |
|
249 int ret = Option::init(qmakeArgc, qmakeArgv); |
|
250 if(ret != Option::QMAKE_CMDLINE_SUCCESS) { |
|
251 cout << "Error: could not parse " << qPrintable(proFile) << endl; |
|
252 return -1; |
|
253 } |
|
254 |
|
255 QMakeProperty prop; |
|
256 QMakeProject project(&prop); |
|
257 |
|
258 project.read(proFile); |
|
259 if (project.values("TEMPLATE").join(" ").toLower() != QString("app")) { |
|
260 cout << "Error: Can only test executables!" << endl; |
|
261 return -1; |
|
262 } |
|
263 // Check wether the project is still in debug/release mode after reading |
|
264 // If .pro specifies to be one mode only, we need to accept this |
|
265 if (project.isActiveConfig("debug")) |
|
266 TestConfiguration::testDebug = true; |
|
267 else |
|
268 TestConfiguration::testDebug = false; |
|
269 |
|
270 QString destDir = project.values("DESTDIR").join(" "); |
|
271 if (!destDir.isEmpty()) { |
|
272 if (QDir::isRelativePath(destDir)) { |
|
273 QFileInfo fi(proFile); |
|
274 if (destDir == QLatin1String(".")) |
|
275 destDir = fi.absolutePath() + "/" + destDir + "/" + (TestConfiguration::testDebug ? "debug" : "release"); |
|
276 else |
|
277 destDir = fi.absolutePath() + QDir::separator() + destDir; |
|
278 } |
|
279 } else { |
|
280 QFileInfo fi(proFile); |
|
281 destDir = fi.absolutePath(); |
|
282 destDir += QDir::separator() + QLatin1String(TestConfiguration::testDebug ? "debug" : "release"); |
|
283 } |
|
284 |
|
285 DeploymentList qtDeploymentList; |
|
286 DeploymentList projectDeploymentList; |
|
287 |
|
288 TestConfiguration::localExecutable = Option::fixPathToLocalOS(destDir + QDir::separator() + project.values("TARGET").join(" ") + QLatin1String(".exe")); |
|
289 TestConfiguration::remoteTestPath = QLatin1String("\\Program Files\\") + Option::fixPathToLocalOS(project.values("TARGET").join(QLatin1String(" "))); |
|
290 if (!arguments.contains(QLatin1String("-libpath"), Qt::CaseInsensitive)) |
|
291 TestConfiguration::remoteLibraryPath = TestConfiguration::remoteTestPath; |
|
292 |
|
293 QString targetExecutable = Option::fixPathToLocalOS(project.values("TARGET").join(QLatin1String(" "))); |
|
294 int last = targetExecutable.lastIndexOf(QLatin1Char('\\')); |
|
295 targetExecutable = targetExecutable.mid( last == -1 ? 0 : last+1 ); |
|
296 TestConfiguration::remoteExecutable = TestConfiguration::remoteTestPath + QDir::separator() + targetExecutable + QLatin1String(".exe"); |
|
297 projectDeploymentList.append(CopyItem(TestConfiguration::localExecutable , TestConfiguration::remoteExecutable)); |
|
298 |
|
299 // deploy |
|
300 #ifdef QT_CETEST_NO_ACTIVESYNC |
|
301 CeTcpSyncConnection connection; |
|
302 #else |
|
303 ActiveSyncConnection connection; |
|
304 #endif |
|
305 if (!connection.connect()) { |
|
306 cout << "Error: Could not connect to device!" << endl; |
|
307 return -1; |
|
308 } |
|
309 DeploymentHandler deployment; |
|
310 deployment.setConnection(&connection); |
|
311 |
|
312 deployment.initQtDeploy(&project, qtDeploymentList, TestConfiguration::remoteLibraryPath); |
|
313 deployment.initProjectDeploy(&project , projectDeploymentList, TestConfiguration::remoteTestPath); |
|
314 |
|
315 // add qt.conf |
|
316 if (TestConfiguration::localQtConf != QLatin1String("no")) { |
|
317 QString qtConfOrigin = QFileInfo(TestConfiguration::localQtConf).absoluteFilePath(); |
|
318 QString qtConfTarget = Option::fixPathToLocalOS(TestConfiguration::remoteTestPath + QDir::separator() + QLatin1String("qt.conf")); |
|
319 projectDeploymentList.append(CopyItem(qtConfOrigin, qtConfTarget)); |
|
320 } |
|
321 |
|
322 if (!deployment.deviceDeploy(qtDeploymentList) || !deployment.deviceDeploy(projectDeploymentList)) { |
|
323 cout << "Error: Could not copy file(s) to device" << endl; |
|
324 return -1; |
|
325 } |
|
326 |
|
327 // launch |
|
328 launchArguments.append("-o"); |
|
329 launchArguments.append(TestConfiguration::remoteResultFile); |
|
330 |
|
331 cout << endl << "Remote Launch:" << qPrintable(TestConfiguration::remoteExecutable) << " " << qPrintable(launchArguments.join(" ")) << endl; |
|
332 if (!connection.execute(TestConfiguration::remoteExecutable, launchArguments.join(" "), timeout)) { |
|
333 cout << "Error: Could not execute target file" << endl; |
|
334 return -1; |
|
335 } |
|
336 |
|
337 |
|
338 // copy result file |
|
339 // show results |
|
340 if (resultFile.isEmpty()) { |
|
341 QString tempResultFile = Option::fixPathToLocalOS(QDir::tempPath() + "/qt_ce_temp_result_file.txt"); |
|
342 if (connection.copyFileFromDevice(TestConfiguration::remoteResultFile, tempResultFile)) { |
|
343 QFile file(tempResultFile); |
|
344 QByteArray arr; |
|
345 if (file.open(QIODevice::ReadOnly)) { |
|
346 arr = file.readAll(); |
|
347 cout << arr.constData() << endl; |
|
348 } |
|
349 file.close(); |
|
350 file.remove(); |
|
351 } |
|
352 } else { |
|
353 connection.copyFileFromDevice(TestConfiguration::remoteResultFile, resultFile); |
|
354 } |
|
355 |
|
356 // delete |
|
357 connection.deleteFile(TestConfiguration::remoteResultFile); |
|
358 if (cleanupQt) |
|
359 deployment.cleanup(qtDeploymentList); |
|
360 if (cleanupProject) |
|
361 deployment.cleanup(projectDeploymentList); |
|
362 return 0; |
|
363 } |