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 | ** 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 qt-info@nokia.com.
|
---|
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 | launcher->setTrkServerName(QString("\\\\.\\") + serialPortName);
|
---|
179 |
|
---|
180 | launcher->setFileName(QString("c:\\sys\\bin\\") + exeFile);
|
---|
181 | launcher->setCommandLineArgs(cmdLine);
|
---|
182 |
|
---|
183 | if(loglevel > 1)
|
---|
184 | launcher->setVerbose(1);
|
---|
185 |
|
---|
186 | TrkSignalHandler handler;
|
---|
187 | handler.setLogLevel(loglevel);
|
---|
188 |
|
---|
189 | QObject::connect(launcher.data(), SIGNAL(copyingStarted()), &handler, SLOT(copyingStarted()));
|
---|
190 | QObject::connect(launcher.data(), SIGNAL(canNotConnect(const QString &)), &handler, SLOT(canNotConnect(const QString &)));
|
---|
191 | QObject::connect(launcher.data(), SIGNAL(canNotCreateFile(const QString &, const QString &)), &handler, SLOT(canNotCreateFile(const QString &, const QString &)));
|
---|
192 | QObject::connect(launcher.data(), SIGNAL(canNotWriteFile(const QString &, const QString &)), &handler, SLOT(canNotWriteFile(const QString &, const QString &)));
|
---|
193 | QObject::connect(launcher.data(), SIGNAL(canNotCloseFile(const QString &, const QString &)), &handler, SLOT(canNotCloseFile(const QString &, const QString &)));
|
---|
194 | QObject::connect(launcher.data(), SIGNAL(installingStarted()), &handler, SLOT(installingStarted()));
|
---|
195 | QObject::connect(launcher.data(), SIGNAL(canNotInstall(const QString &, const QString &)), &handler, SLOT(canNotInstall(const QString &, const QString &)));
|
---|
196 | QObject::connect(launcher.data(), SIGNAL(installingFinished()), &handler, SLOT(installingFinished()));
|
---|
197 | QObject::connect(launcher.data(), SIGNAL(startingApplication()), &handler, SLOT(startingApplication()));
|
---|
198 | QObject::connect(launcher.data(), SIGNAL(applicationRunning(uint)), &handler, SLOT(applicationRunning(uint)));
|
---|
199 | QObject::connect(launcher.data(), SIGNAL(canNotRun(const QString &)), &handler, SLOT(canNotRun(const QString &)));
|
---|
200 | QObject::connect(launcher.data(), SIGNAL(applicationOutputReceived(const QString &)), &handler, SLOT(applicationOutputReceived(const QString &)));
|
---|
201 | QObject::connect(launcher.data(), SIGNAL(copyProgress(int)), &handler, SLOT(copyProgress(int)));
|
---|
202 | QObject::connect(launcher.data(), SIGNAL(stateChanged(int)), &handler, SLOT(stateChanged(int)));
|
---|
203 | QObject::connect(launcher.data(), SIGNAL(stopped(uint,uint,uint,QString)), &handler, SLOT(stopped(uint,uint,uint,QString)));
|
---|
204 | QObject::connect(&handler, SIGNAL(resume(uint,uint)), launcher.data(), SLOT(resume(uint,uint)));
|
---|
205 | QObject::connect(&handler, SIGNAL(terminate()), launcher.data(), SLOT(terminate()));
|
---|
206 | QObject::connect(launcher.data(), SIGNAL(finished()), &handler, SLOT(finished()));
|
---|
207 |
|
---|
208 | QTimer timer;
|
---|
209 | timer.setSingleShot(true);
|
---|
210 | QObject::connect(&timer, SIGNAL(timeout()), &handler, SLOT(timeout()));
|
---|
211 | if (timeout > 0) {
|
---|
212 | timer.start(timeout);
|
---|
213 | }
|
---|
214 |
|
---|
215 | QString errorMessage;
|
---|
216 | if(!launcher->startServer(&errorMessage)) {
|
---|
217 | errstream << errorMessage << endl;
|
---|
218 | return 1;
|
---|
219 | }
|
---|
220 |
|
---|
221 | return a.exec();
|
---|
222 | }
|
---|
223 |
|
---|