|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 #include <QCoreApplication> |
|
43 #include <QTextStream> |
|
44 #include <QStringList> |
|
45 #include <QScopedPointer> |
|
46 #include <QTimer> |
|
47 #include "trkutils.h" |
|
48 #include "trkdevice.h" |
|
49 #include "launcher.h" |
|
50 |
|
51 #include "trksignalhandler.h" |
|
52 #include "serenum.h" |
|
53 |
|
54 void printUsage(QTextStream& outstream) |
|
55 { |
|
56 outstream << "runtest [options] <program> [program arguments]" << endl |
|
57 << "-s, --sis <file> specify sis file to install" << endl |
|
58 << "-p, --portname <COMx> specify COM port to use by device name" << endl |
|
59 << "-f, --portfriendlyname <substring> specify COM port to use by friendly name" << endl |
|
60 << "-t, --timeout <milliseconds> terminate test if timeout occurs" << endl |
|
61 << "-v, --verbose show debugging output" << endl |
|
62 << "-q, --quiet hide progress messages" << endl |
|
63 << endl |
|
64 << "USB COM ports can usually be autodetected" << endl; |
|
65 } |
|
66 |
|
67 int main(int argc, char *argv[]) |
|
68 { |
|
69 QCoreApplication a(argc, argv); |
|
70 |
|
71 QString serialPortName; |
|
72 QString serialPortFriendlyName; |
|
73 QString sisFile; |
|
74 QString exeFile; |
|
75 QString cmdLine; |
|
76 QStringList args = QCoreApplication::arguments(); |
|
77 QTextStream outstream(stdout); |
|
78 QTextStream errstream(stderr); |
|
79 int loglevel=1; |
|
80 int timeout=0; |
|
81 for (int i=1;i<args.size();i++) { |
|
82 QString arg = args.at(i); |
|
83 if (arg.startsWith("-")) { |
|
84 if (args.size() < i+2) { |
|
85 errstream << "Command line missing argument parameters" << endl; |
|
86 return 1; |
|
87 } |
|
88 QString param = args.at(i+1); |
|
89 if(arg.compare("--portname", Qt::CaseSensitive) == 0 |
|
90 || arg.compare("-p", Qt::CaseSensitive) == 0) { |
|
91 serialPortName = param; |
|
92 i++; |
|
93 } |
|
94 else if(arg.compare("--portfriendlyname", Qt::CaseSensitive) == 0 |
|
95 || arg.compare("-f", Qt::CaseSensitive) == 0) { |
|
96 serialPortFriendlyName = param; |
|
97 i++; |
|
98 } |
|
99 else if(arg.compare("--sis", Qt::CaseSensitive) == 0 |
|
100 || arg.compare("-s", Qt::CaseSensitive) == 0) { |
|
101 sisFile = param; |
|
102 i++; |
|
103 } |
|
104 else if(arg.compare("--timeout", Qt::CaseSensitive) == 0 |
|
105 || arg.compare("-t", Qt::CaseSensitive) == 0) { |
|
106 bool ok; |
|
107 timeout = param.toInt(&ok); |
|
108 if (!ok) { |
|
109 errstream << "Timeout must be specified in milliseconds" << endl; |
|
110 return 1; |
|
111 } |
|
112 i++; |
|
113 } |
|
114 else if(arg.compare("--verbose", Qt::CaseSensitive) == 0 |
|
115 || arg.compare("-v", Qt::CaseSensitive) == 0) |
|
116 loglevel=2; |
|
117 else if(arg.compare("--quiet", Qt::CaseSensitive) == 0 |
|
118 || arg.compare("-q", Qt::CaseSensitive) == 0) |
|
119 loglevel=0; |
|
120 else |
|
121 errstream << "unknown command line option " << arg << endl; |
|
122 } else { |
|
123 exeFile = arg; |
|
124 i++; |
|
125 for(;i<args.size();i++) { |
|
126 cmdLine.append(args.at(i)); |
|
127 if(i + 1 < args.size()) cmdLine.append(' '); |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 if(exeFile.isEmpty()) { |
|
133 printUsage(outstream); |
|
134 return 1; |
|
135 } |
|
136 |
|
137 if(serialPortName.isEmpty()) { |
|
138 if(loglevel > 0) |
|
139 outstream << "Detecting serial ports" << endl; |
|
140 QList <SerialPortId> ports = enumerateSerialPorts(); |
|
141 foreach(SerialPortId id, ports) { |
|
142 if(loglevel > 0) |
|
143 outstream << "Port Name: " << id.portName << ", " |
|
144 << "Friendly Name:" << id.friendlyName << endl; |
|
145 if(serialPortName.isEmpty()) { |
|
146 if(!id.friendlyName.isEmpty() && |
|
147 serialPortFriendlyName.isEmpty() && |
|
148 (id.friendlyName.contains("symbian", Qt::CaseInsensitive) || |
|
149 id.friendlyName.contains("s60", Qt::CaseInsensitive) || |
|
150 id.friendlyName.contains("nokia", Qt::CaseInsensitive))) |
|
151 serialPortName = id.portName; |
|
152 else if (!id.friendlyName.isEmpty() && |
|
153 !serialPortFriendlyName.isEmpty() && |
|
154 id.friendlyName.contains(serialPortFriendlyName)) |
|
155 serialPortName = id.portName; |
|
156 } |
|
157 } |
|
158 if(serialPortName.isEmpty()) { |
|
159 errstream << "No phone found, ensure USB cable is connected or specify manually with -p" << endl; |
|
160 return 1; |
|
161 } |
|
162 } |
|
163 |
|
164 QScopedPointer<trk::Launcher> launcher; |
|
165 |
|
166 if(sisFile.isEmpty()) { |
|
167 launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyRun)); |
|
168 launcher->setCopyFileName(exeFile, QString("c:\\sys\\bin\\") + exeFile); |
|
169 errstream << "System TRK required to copy EXE, use --sis if using Application TRK" << endl; |
|
170 } else { |
|
171 launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyInstallRun)); |
|
172 launcher->addStartupActions(trk::Launcher::ActionInstall); |
|
173 launcher->setCopyFileName(sisFile, "c:\\data\\testtemp.sis"); |
|
174 launcher->setInstallFileName("c:\\data\\testtemp.sis"); |
|
175 } |
|
176 if(loglevel > 0) |
|
177 outstream << "Connecting to target via " << serialPortName << endl; |
|
178 #ifdef Q_OS_WIN |
|
179 launcher->setTrkServerName(QString("\\\\.\\") + serialPortName); |
|
180 #else |
|
181 launcher->setTrkServerName(serialPortName); |
|
182 #endif |
|
183 |
|
184 launcher->setFileName(QString("c:\\sys\\bin\\") + exeFile); |
|
185 launcher->setCommandLineArgs(cmdLine); |
|
186 |
|
187 if(loglevel > 1) |
|
188 launcher->setVerbose(1); |
|
189 |
|
190 TrkSignalHandler handler; |
|
191 handler.setLogLevel(loglevel); |
|
192 |
|
193 QObject::connect(launcher.data(), SIGNAL(copyingStarted()), &handler, SLOT(copyingStarted())); |
|
194 QObject::connect(launcher.data(), SIGNAL(canNotConnect(const QString &)), &handler, SLOT(canNotConnect(const QString &))); |
|
195 QObject::connect(launcher.data(), SIGNAL(canNotCreateFile(const QString &, const QString &)), &handler, SLOT(canNotCreateFile(const QString &, const QString &))); |
|
196 QObject::connect(launcher.data(), SIGNAL(canNotWriteFile(const QString &, const QString &)), &handler, SLOT(canNotWriteFile(const QString &, const QString &))); |
|
197 QObject::connect(launcher.data(), SIGNAL(canNotCloseFile(const QString &, const QString &)), &handler, SLOT(canNotCloseFile(const QString &, const QString &))); |
|
198 QObject::connect(launcher.data(), SIGNAL(installingStarted()), &handler, SLOT(installingStarted())); |
|
199 QObject::connect(launcher.data(), SIGNAL(canNotInstall(const QString &, const QString &)), &handler, SLOT(canNotInstall(const QString &, const QString &))); |
|
200 QObject::connect(launcher.data(), SIGNAL(installingFinished()), &handler, SLOT(installingFinished())); |
|
201 QObject::connect(launcher.data(), SIGNAL(startingApplication()), &handler, SLOT(startingApplication())); |
|
202 QObject::connect(launcher.data(), SIGNAL(applicationRunning(uint)), &handler, SLOT(applicationRunning(uint))); |
|
203 QObject::connect(launcher.data(), SIGNAL(canNotRun(const QString &)), &handler, SLOT(canNotRun(const QString &))); |
|
204 QObject::connect(launcher.data(), SIGNAL(applicationOutputReceived(const QString &)), &handler, SLOT(applicationOutputReceived(const QString &))); |
|
205 QObject::connect(launcher.data(), SIGNAL(copyProgress(int)), &handler, SLOT(copyProgress(int))); |
|
206 QObject::connect(launcher.data(), SIGNAL(stateChanged(int)), &handler, SLOT(stateChanged(int))); |
|
207 QObject::connect(launcher.data(), SIGNAL(stopped(uint,uint,uint,QString)), &handler, SLOT(stopped(uint,uint,uint,QString))); |
|
208 QObject::connect(&handler, SIGNAL(resume(uint,uint)), launcher.data(), SLOT(resume(uint,uint))); |
|
209 QObject::connect(&handler, SIGNAL(terminate()), launcher.data(), SLOT(terminate())); |
|
210 QObject::connect(launcher.data(), SIGNAL(finished()), &handler, SLOT(finished())); |
|
211 |
|
212 QTimer timer; |
|
213 timer.setSingleShot(true); |
|
214 QObject::connect(&timer, SIGNAL(timeout()), &handler, SLOT(timeout())); |
|
215 if (timeout > 0) { |
|
216 timer.start(timeout); |
|
217 } |
|
218 |
|
219 QString errorMessage; |
|
220 if(!launcher->startServer(&errorMessage)) { |
|
221 errstream << errorMessage << endl; |
|
222 return 1; |
|
223 } |
|
224 |
|
225 return a.exec(); |
|
226 } |
|
227 |