42 #include <QCoreApplication> |
42 #include <QCoreApplication> |
43 #include <QTextStream> |
43 #include <QTextStream> |
44 #include <QStringList> |
44 #include <QStringList> |
45 #include <QScopedPointer> |
45 #include <QScopedPointer> |
46 #include <QTimer> |
46 #include <QTimer> |
|
47 #include <QFileInfo> |
47 #include "symbianutils/trkutils.h" |
48 #include "symbianutils/trkutils.h" |
48 #include "symbianutils/trkdevice.h" |
49 #include "symbianutils/trkdevice.h" |
49 #include "symbianutils/launcher.h" |
50 #include "symbianutils/launcher.h" |
50 |
51 |
51 #include "trksignalhandler.h" |
52 #include "trksignalhandler.h" |
52 #include "serenum.h" |
53 #include "serenum.h" |
53 |
54 |
54 void printUsage(QTextStream& outstream) |
55 void printUsage(QTextStream& outstream, QString exeName) |
55 { |
56 { |
56 outstream << "runtest [options] <program> [program arguments]" << endl |
57 outstream << exeName << " [options] [program] [program arguments]" << endl |
57 << "-s, --sis <file> specify sis file to install" << endl |
58 << "-s, --sis <file> specify sis file to install" << endl |
58 << "-p, --portname <COMx> specify COM port to use by device name" << endl |
59 << "-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 << "-f, --portfriendlyname <substring> specify COM port to use by friendly name" << endl |
60 << "-t, --timeout <milliseconds> terminate test if timeout occurs" << endl |
61 << "-t, --timeout <milliseconds> terminate test if timeout occurs" << endl |
61 << "-v, --verbose show debugging output" << endl |
62 << "-v, --verbose show debugging output" << endl |
62 << "-q, --quiet hide progress messages" << endl |
63 << "-q, --quiet hide progress messages" << endl |
|
64 << "-d, --download <remote file> <local file> copy file from phone to PC after running test" << endl |
63 << endl |
65 << endl |
64 << "USB COM ports can usually be autodetected" << endl; |
66 << "USB COM ports can usually be autodetected, use -p or -f to force a specific port." << endl |
|
67 << "If using System TRK, it is possible to copy the program directly to sys/bin on the phone." << endl |
|
68 << "-s can be used with both System and Application TRK to install the program" << endl; |
65 } |
69 } |
66 |
70 |
|
71 #define CHECK_PARAMETER_EXISTS if(!it.hasNext()) { printUsage(outstream, args[0]); return 1; } |
67 int main(int argc, char *argv[]) |
72 int main(int argc, char *argv[]) |
68 { |
73 { |
69 QCoreApplication a(argc, argv); |
74 QCoreApplication a(argc, argv); |
70 |
75 |
71 QString serialPortName; |
76 QString serialPortName; |
74 QString exeFile; |
79 QString exeFile; |
75 QStringList cmdLine; |
80 QStringList cmdLine; |
76 QStringList args = QCoreApplication::arguments(); |
81 QStringList args = QCoreApplication::arguments(); |
77 QTextStream outstream(stdout); |
82 QTextStream outstream(stdout); |
78 QTextStream errstream(stderr); |
83 QTextStream errstream(stderr); |
|
84 QString downloadRemoteFile; |
|
85 QString downloadLocalFile; |
79 int loglevel=1; |
86 int loglevel=1; |
80 int timeout=0; |
87 int timeout=0; |
81 for (int i=1;i<args.size();i++) { |
88 QListIterator<QString> it(args); |
82 QString arg = args.at(i); |
89 it.next(); //skip name of program |
|
90 while (it.hasNext()) { |
|
91 QString arg = it.next(); |
|
92 |
83 if (arg.startsWith("-")) { |
93 if (arg.startsWith("-")) { |
84 if (args.size() < i+2) { |
94 if (arg == "--portname" || arg == "-p") { |
85 errstream << "Command line missing argument parameters" << endl; |
95 CHECK_PARAMETER_EXISTS |
86 return 1; |
96 serialPortName = it.next(); |
87 } |
97 } |
88 QString param = args.at(i+1); |
98 else if (arg == "--portfriendlyname" || arg == "-f") { |
89 if(arg.compare("--portname", Qt::CaseSensitive) == 0 |
99 CHECK_PARAMETER_EXISTS |
90 || arg.compare("-p", Qt::CaseSensitive) == 0) { |
100 serialPortFriendlyName = it.next(); |
91 serialPortName = param; |
101 } |
92 i++; |
102 else if (arg == "--sis" || arg == "-s") { |
93 } |
103 CHECK_PARAMETER_EXISTS |
94 else if(arg.compare("--portfriendlyname", Qt::CaseSensitive) == 0 |
104 sisFile = it.next(); |
95 || arg.compare("-f", Qt::CaseSensitive) == 0) { |
105 if (!QFileInfo(sisFile).exists()) { |
96 serialPortFriendlyName = param; |
106 errstream << "Sis file (" << sisFile << ") doesn't exist" << endl; |
97 i++; |
107 return 1; |
98 } |
108 } |
99 else if(arg.compare("--sis", Qt::CaseSensitive) == 0 |
109 } |
100 || arg.compare("-s", Qt::CaseSensitive) == 0) { |
110 else if (arg == "--download" || arg == "-d") { |
101 sisFile = param; |
111 CHECK_PARAMETER_EXISTS |
102 i++; |
112 downloadRemoteFile = it.next(); |
103 } |
113 CHECK_PARAMETER_EXISTS |
104 else if(arg.compare("--timeout", Qt::CaseSensitive) == 0 |
114 downloadLocalFile = it.next(); |
105 || arg.compare("-t", Qt::CaseSensitive) == 0) { |
115 } |
|
116 else if (arg == "--timeout" || arg == "-t") { |
|
117 CHECK_PARAMETER_EXISTS |
106 bool ok; |
118 bool ok; |
107 timeout = param.toInt(&ok); |
119 timeout = it.next().toInt(&ok); |
108 if (!ok) { |
120 if (!ok) { |
109 errstream << "Timeout must be specified in milliseconds" << endl; |
121 errstream << "Timeout must be specified in milliseconds" << endl; |
110 return 1; |
122 return 1; |
111 } |
123 } |
112 i++; |
124 } |
113 } |
125 else if (arg == "--verbose" || arg == "-v") |
114 else if(arg.compare("--verbose", Qt::CaseSensitive) == 0 |
|
115 || arg.compare("-v", Qt::CaseSensitive) == 0) |
|
116 loglevel=2; |
126 loglevel=2; |
117 else if(arg.compare("--quiet", Qt::CaseSensitive) == 0 |
127 else if (arg == "--quiet" || arg == "-q") |
118 || arg.compare("-q", Qt::CaseSensitive) == 0) |
|
119 loglevel=0; |
128 loglevel=0; |
120 else |
129 else |
121 errstream << "unknown command line option " << arg << endl; |
130 errstream << "unknown command line option " << arg << endl; |
122 } else { |
131 } else { |
123 exeFile = arg; |
132 exeFile = arg; |
124 i++; |
133 while(it.hasNext()) { |
125 for(;i<args.size();i++) { |
134 cmdLine.append(it.next()); |
126 cmdLine.append(args.at(i)); |
|
127 } |
135 } |
128 } |
136 } |
129 } |
137 } |
130 |
138 |
131 if(exeFile.isEmpty()) { |
139 if (exeFile.isEmpty() && sisFile.isEmpty() && |
132 printUsage(outstream); |
140 (downloadLocalFile.isEmpty() || downloadRemoteFile.isEmpty())) { |
|
141 printUsage(outstream, args[0]); |
133 return 1; |
142 return 1; |
134 } |
143 } |
135 |
144 |
136 if (serialPortName.isEmpty()) { |
145 if (serialPortName.isEmpty()) { |
137 if (loglevel > 0) |
146 if (loglevel > 0) |
138 outstream << "Detecting serial ports" << endl; |
147 outstream << "Detecting serial ports" << endl; |
139 QList <SerialPortId> ports = enumerateSerialPorts(); |
148 foreach (const SerialPortId &id, enumerateSerialPorts()) { |
140 foreach(SerialPortId id, ports) { |
|
141 if (loglevel > 0) |
149 if (loglevel > 0) |
142 outstream << "Port Name: " << id.portName << ", " |
150 outstream << "Port Name: " << id.portName << ", " |
143 << "Friendly Name:" << id.friendlyName << endl; |
151 << "Friendly Name:" << id.friendlyName << endl; |
144 if (serialPortName.isEmpty()) { |
152 if (!id.friendlyName.isEmpty() |
145 if (!id.friendlyName.isEmpty() |
153 && serialPortFriendlyName.isEmpty() |
146 && serialPortFriendlyName.isEmpty() |
154 && (id.friendlyName.contains("symbian", Qt::CaseInsensitive) |
147 && (id.friendlyName.contains("symbian", Qt::CaseInsensitive) |
155 || id.friendlyName.contains("s60", Qt::CaseInsensitive) |
148 || id.friendlyName.contains("s60", Qt::CaseInsensitive) |
156 || id.friendlyName.contains("nokia", Qt::CaseInsensitive))) { |
149 || id.friendlyName.contains("nokia", Qt::CaseInsensitive))) |
157 serialPortName = id.portName; |
150 serialPortName = id.portName; |
158 break; |
151 else if (!id.friendlyName.isEmpty() |
159 } else if (!id.friendlyName.isEmpty() |
152 && !serialPortFriendlyName.isEmpty() |
160 && !serialPortFriendlyName.isEmpty() |
153 && id.friendlyName.contains(serialPortFriendlyName)) |
161 && id.friendlyName.contains(serialPortFriendlyName)) { |
154 serialPortName = id.portName; |
162 serialPortName = id.portName; |
|
163 break; |
155 } |
164 } |
156 } |
165 } |
157 if (serialPortName.isEmpty()) { |
166 if (serialPortName.isEmpty()) { |
158 errstream << "No phone found, ensure USB cable is connected or specify manually with -p" << endl; |
167 errstream << "No phone found, ensure USB cable is connected or specify manually with -p" << endl; |
159 return 1; |
168 return 1; |
160 } |
169 } |
161 } |
170 } |
162 |
171 |
163 QScopedPointer<trk::Launcher> launcher; |
172 QScopedPointer<trk::Launcher> launcher; |
164 |
173 launcher.reset(new trk::Launcher(trk::Launcher::ActionPingOnly)); |
165 if (sisFile.isEmpty()) { |
174 QFileInfo info(exeFile); |
166 launcher.reset(new trk::Launcher(trk::Launcher::ActionCopyRun)); |
175 if (!sisFile.isEmpty()) { |
167 launcher->setCopyFileName(exeFile, QString("c:\\sys\\bin\\") + exeFile); |
176 launcher->addStartupActions(trk::Launcher::ActionCopyInstall); |
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"); |
177 launcher->setCopyFileName(sisFile, "c:\\data\\testtemp.sis"); |
173 launcher->setInstallFileName("c:\\data\\testtemp.sis"); |
178 launcher->setInstallFileName("c:\\data\\testtemp.sis"); |
|
179 } |
|
180 else if (info.exists()) { |
|
181 launcher->addStartupActions(trk::Launcher::ActionCopy); |
|
182 launcher->setCopyFileName(exeFile, QString("c:\\sys\\bin\\") + info.fileName()); |
|
183 } |
|
184 if (!exeFile.isEmpty()) { |
|
185 launcher->addStartupActions(trk::Launcher::ActionRun); |
|
186 launcher->setFileName(QString("c:\\sys\\bin\\") + info.fileName()); |
|
187 launcher->setCommandLineArgs(cmdLine); |
|
188 } |
|
189 if (!downloadRemoteFile.isEmpty() && !downloadLocalFile.isEmpty()) { |
|
190 launcher->addStartupActions(trk::Launcher::ActionDownload); |
|
191 launcher->setDownloadFileName(downloadRemoteFile, downloadLocalFile); |
174 } |
192 } |
175 if (loglevel > 0) |
193 if (loglevel > 0) |
176 outstream << "Connecting to target via " << serialPortName << endl; |
194 outstream << "Connecting to target via " << serialPortName << endl; |
177 launcher->setTrkServerName(serialPortName); |
195 launcher->setTrkServerName(serialPortName); |
178 |
|
179 launcher->setFileName(QString("c:\\sys\\bin\\") + exeFile); |
|
180 launcher->setCommandLineArgs(cmdLine); |
|
181 |
196 |
182 if (loglevel > 1) |
197 if (loglevel > 1) |
183 launcher->setVerbose(1); |
198 launcher->setVerbose(1); |
184 |
199 |
185 TrkSignalHandler handler; |
200 TrkSignalHandler handler; |