| 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 | ** 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 | QStringList 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 | }
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | if(exeFile.isEmpty()) {
|
|---|
| 132 | printUsage(outstream);
|
|---|
| 133 | return 1;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | if(serialPortName.isEmpty()) {
|
|---|
| 137 | if(loglevel > 0)
|
|---|
| 138 | outstream << "Detecting serial ports" << endl;
|
|---|
| 139 | QList <SerialPortId> ports = enumerateSerialPorts();
|
|---|
| 140 | foreach(SerialPortId id, ports) {
|
|---|
| 141 | if(loglevel > 0)
|
|---|
| 142 | outstream << "Port Name: " << id.portName << ", "
|
|---|
| 143 | << "Friendly Name:" << id.friendlyName << endl;
|
|---|
| 144 | if(serialPortName.isEmpty()) {
|
|---|
| 145 | if(!id.friendlyName.isEmpty() &&
|
|---|
| 146 | serialPortFriendlyName.isEmpty() &&
|
|---|
| 147 | (id.friendlyName.contains("symbian", Qt::CaseInsensitive) ||
|
|---|
| 148 | id.friendlyName.contains("s60", Qt::CaseInsensitive) ||
|
|---|
| 149 | id.friendlyName.contains("nokia", Qt::CaseInsensitive)))
|
|---|
| 150 | serialPortName = id.portName;
|
|---|
| 151 | else if (!id.friendlyName.isEmpty() &&
|
|---|
| 152 | !serialPortFriendlyName.isEmpty() &&
|
|---|
| 153 | id.friendlyName.contains(serialPortFriendlyName))
|
|---|
| 154 | serialPortName = id.portName;
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 | if(serialPortName.isEmpty()) {
|
|---|
| 158 | errstream << "No phone found, ensure USB cable is connected or specify manually with -p" << endl;
|
|---|
| 159 | return 1;
|
|---|
| 160 | }
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | QScopedPointer<trk::Launcher> launcher;
|
|---|
| 164 |
|
|---|
| 165 | if(sisFile.isEmpty()) {
|
|---|
| 166 | launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyRun));
|
|---|
| 167 | launcher->setCopyFileName(exeFile, QString("c:\\sys\\bin\\") + exeFile);
|
|---|
| 168 | errstream << "System TRK required to copy EXE, use --sis if using Application TRK" << endl;
|
|---|
| 169 | } else {
|
|---|
| 170 | launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyInstallRun));
|
|---|
| 171 | launcher->addStartupActions(trk::Launcher::ActionInstall);
|
|---|
| 172 | launcher->setCopyFileName(sisFile, "c:\\data\\testtemp.sis");
|
|---|
| 173 | launcher->setInstallFileName("c:\\data\\testtemp.sis");
|
|---|
| 174 | }
|
|---|
| 175 | if(loglevel > 0)
|
|---|
| 176 | outstream << "Connecting to target via " << serialPortName << endl;
|
|---|
| 177 | #ifdef Q_OS_WIN
|
|---|
| 178 | launcher->setTrkServerName(QString("\\\\.\\") + serialPortName);
|
|---|
| 179 | #else
|
|---|
| 180 | launcher->setTrkServerName(serialPortName);
|
|---|
| 181 | #endif
|
|---|
| 182 |
|
|---|
| 183 | launcher->setFileName(QString("c:\\sys\\bin\\") + exeFile);
|
|---|
| 184 | launcher->setCommandLineArgs(cmdLine);
|
|---|
| 185 |
|
|---|
| 186 | if(loglevel > 1)
|
|---|
| 187 | launcher->setVerbose(1);
|
|---|
| 188 |
|
|---|
| 189 | TrkSignalHandler handler;
|
|---|
| 190 | handler.setLogLevel(loglevel);
|
|---|
| 191 |
|
|---|
| 192 | QObject::connect(launcher.data(), SIGNAL(copyingStarted()), &handler, SLOT(copyingStarted()));
|
|---|
| 193 | QObject::connect(launcher.data(), SIGNAL(canNotConnect(const QString &)), &handler, SLOT(canNotConnect(const QString &)));
|
|---|
| 194 | QObject::connect(launcher.data(), SIGNAL(canNotCreateFile(const QString &, const QString &)), &handler, SLOT(canNotCreateFile(const QString &, const QString &)));
|
|---|
| 195 | QObject::connect(launcher.data(), SIGNAL(canNotWriteFile(const QString &, const QString &)), &handler, SLOT(canNotWriteFile(const QString &, const QString &)));
|
|---|
| 196 | QObject::connect(launcher.data(), SIGNAL(canNotCloseFile(const QString &, const QString &)), &handler, SLOT(canNotCloseFile(const QString &, const QString &)));
|
|---|
| 197 | QObject::connect(launcher.data(), SIGNAL(installingStarted()), &handler, SLOT(installingStarted()));
|
|---|
| 198 | QObject::connect(launcher.data(), SIGNAL(canNotInstall(const QString &, const QString &)), &handler, SLOT(canNotInstall(const QString &, const QString &)));
|
|---|
| 199 | QObject::connect(launcher.data(), SIGNAL(installingFinished()), &handler, SLOT(installingFinished()));
|
|---|
| 200 | QObject::connect(launcher.data(), SIGNAL(startingApplication()), &handler, SLOT(startingApplication()));
|
|---|
| 201 | QObject::connect(launcher.data(), SIGNAL(applicationRunning(uint)), &handler, SLOT(applicationRunning(uint)));
|
|---|
| 202 | QObject::connect(launcher.data(), SIGNAL(canNotRun(const QString &)), &handler, SLOT(canNotRun(const QString &)));
|
|---|
| 203 | QObject::connect(launcher.data(), SIGNAL(applicationOutputReceived(const QString &)), &handler, SLOT(applicationOutputReceived(const QString &)));
|
|---|
| 204 | QObject::connect(launcher.data(), SIGNAL(copyProgress(int)), &handler, SLOT(copyProgress(int)));
|
|---|
| 205 | QObject::connect(launcher.data(), SIGNAL(stateChanged(int)), &handler, SLOT(stateChanged(int)));
|
|---|
| 206 | QObject::connect(launcher.data(), SIGNAL(processStopped(uint,uint,uint,QString)), &handler, SLOT(stopped(uint,uint,uint,QString)));
|
|---|
| 207 | QObject::connect(&handler, SIGNAL(resume(uint,uint)), launcher.data(), SLOT(resumeProcess(uint,uint)));
|
|---|
| 208 | QObject::connect(&handler, SIGNAL(terminate()), launcher.data(), SLOT(terminate()));
|
|---|
| 209 | QObject::connect(launcher.data(), SIGNAL(finished()), &handler, SLOT(finished()));
|
|---|
| 210 |
|
|---|
| 211 | QTimer timer;
|
|---|
| 212 | timer.setSingleShot(true);
|
|---|
| 213 | QObject::connect(&timer, SIGNAL(timeout()), &handler, SLOT(timeout()));
|
|---|
| 214 | if (timeout > 0) {
|
|---|
| 215 | timer.start(timeout);
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | QString errorMessage;
|
|---|
| 219 | if(!launcher->startServer(&errorMessage)) {
|
|---|
| 220 | errstream << errorMessage << endl;
|
|---|
| 221 | return 1;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | return a.exec();
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|