Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/runonphone/main.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4545#include <QScopedPointer>
    4646#include <QTimer>
     47#include <QFileInfo>
    4748#include "symbianutils/trkutils.h"
    4849#include "symbianutils/trkdevice.h"
     
    5152#include "trksignalhandler.h"
    5253#include "serenum.h"
    53 
    54 void printUsage(QTextStream& outstream)
     54#include "ossignalconverter.h"
     55
     56void printUsage(QTextStream& outstream, QString exeName)
    5557{
    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
     58    outstream << exeName << " [options] [program] [program arguments]" << endl
     59            << "-s, --sis <file>                         specify sis file to install" << endl
     60            << "-p, --portname <COMx>                    specify COM port to use by device name" << endl
     61            << "-f, --portfriendlyname <substring>       specify COM port to use by friendly name" << endl
     62            << "-t, --timeout <milliseconds>             terminate test if timeout occurs" << endl
     63            << "-v, --verbose                            show debugging output" << endl
     64            << "-q, --quiet                              hide progress messages" << endl
     65            << "-d, --download <remote file> <local file> copy file from phone to PC after running test" << endl
     66            << "--nocrashlog                             Don't capture call stack if test crashes" << endl
     67            << "--crashlogpath <dir>                     Path to save crash logs (default=working dir)" << endl
    6368            << endl
    64             << "USB COM ports can usually be autodetected" << endl;
     69            << "USB COM ports can usually be autodetected, use -p or -f to force a specific port." << endl
     70            << "If using System TRK, it is possible to copy the program directly to sys/bin on the phone." << endl
     71            << "-s can be used with both System and Application TRK to install the program" << endl;
    6572}
    6673
     74#define CHECK_PARAMETER_EXISTS if(!it.hasNext()) { printUsage(outstream, args[0]); return 1; }
    6775int main(int argc, char *argv[])
    6876{
     
    7785    QTextStream outstream(stdout);
    7886    QTextStream errstream(stderr);
     87    QString downloadRemoteFile;
     88    QString downloadLocalFile;
    7989    int loglevel=1;
    8090    int timeout=0;
    81     for (int i=1;i<args.size();i++) {
    82         QString arg = args.at(i);
     91    bool crashlog = true;
     92    QString crashlogpath;
     93    QListIterator<QString> it(args);
     94    it.next(); //skip name of program
     95    while (it.hasNext()) {
     96        QString arg = it.next();
     97
    8398        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) {
     99            if (arg == "--portname" || arg == "-p") {
     100                CHECK_PARAMETER_EXISTS
     101                serialPortName = it.next();
     102            }
     103            else if (arg == "--portfriendlyname" || arg == "-f") {
     104                CHECK_PARAMETER_EXISTS
     105                serialPortFriendlyName = it.next();
     106            }
     107            else if (arg == "--sis" || arg == "-s") {
     108                CHECK_PARAMETER_EXISTS
     109                sisFile = it.next();
     110                if (!QFileInfo(sisFile).exists()) {
     111                    errstream << "Sis file (" << sisFile << ") doesn't exist" << endl;
     112                    return 1;
     113                }
     114            }
     115            else if (arg == "--download" || arg == "-d") {
     116                CHECK_PARAMETER_EXISTS
     117                downloadRemoteFile = it.next();
     118                CHECK_PARAMETER_EXISTS
     119                downloadLocalFile = it.next();
     120            }
     121            else if (arg == "--timeout" || arg == "-t") {
     122                CHECK_PARAMETER_EXISTS
    106123                bool ok;
    107                 timeout = param.toInt(&ok);
     124                timeout = it.next().toInt(&ok);
    108125                if (!ok) {
    109126                    errstream << "Timeout must be specified in milliseconds" << endl;
    110127                    return 1;
    111128                }
    112                 i++;
    113             }
    114             else if(arg.compare("--verbose", Qt::CaseSensitive) == 0
    115                     || arg.compare("-v", Qt::CaseSensitive) == 0)
     129            }
     130            else if (arg == "--verbose" || arg == "-v")
    116131                loglevel=2;
    117             else if(arg.compare("--quiet", Qt::CaseSensitive) == 0
    118                     || arg.compare("-q", Qt::CaseSensitive) == 0)
     132            else if (arg == "--quiet" || arg == "-q")
    119133                loglevel=0;
     134            else if (arg == "--nocrashlog")
     135                crashlog = false;
     136            else if (arg == "--crashlogpath") {
     137                CHECK_PARAMETER_EXISTS
     138                crashlogpath = it.next();
     139            }
    120140            else
    121141                errstream << "unknown command line option " << arg << endl;
    122142        } else {
    123143            exeFile = arg;
    124             i++;
    125             for(;i<args.size();i++) {
    126                 cmdLine.append(args.at(i));
     144            while(it.hasNext()) {
     145                cmdLine.append(it.next());
    127146            }
    128147        }
    129148    }
    130149
    131     if(exeFile.isEmpty()) {
    132         printUsage(outstream);
     150    if (exeFile.isEmpty() && sisFile.isEmpty() &&
     151        (downloadLocalFile.isEmpty() || downloadRemoteFile.isEmpty())) {
     152        printUsage(outstream, args[0]);
    133153        return 1;
    134154    }
     
    137157        if (loglevel > 0)
    138158            outstream << "Detecting serial ports" << endl;
    139         QList <SerialPortId> ports = enumerateSerialPorts();
    140         foreach(SerialPortId id, ports) {
     159        foreach (const SerialPortId &id, enumerateSerialPorts(loglevel)) {
    141160            if (loglevel > 0)
    142161                outstream << "Port Name: " << id.portName << ", "
    143162                     << "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;
     163            if (!id.friendlyName.isEmpty()
     164                    && serialPortFriendlyName.isEmpty()
     165                    && (id.friendlyName.contains("symbian", Qt::CaseInsensitive)
     166                        || id.friendlyName.contains("s60", Qt::CaseInsensitive)
     167                        || id.friendlyName.contains("nokia", Qt::CaseInsensitive))) {
     168                serialPortName = id.portName;
     169                break;
     170            } else if (!id.friendlyName.isEmpty()
     171                    && !serialPortFriendlyName.isEmpty()
     172                    && id.friendlyName.contains(serialPortFriendlyName)) {
     173                serialPortName = id.portName;
     174                break;
    155175            }
    156176        }
     
    162182
    163183    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);
     184    launcher.reset(new trk::Launcher(trk::Launcher::ActionPingOnly));
     185    QFileInfo info(exeFile);
     186    if (!sisFile.isEmpty()) {
     187        launcher->addStartupActions(trk::Launcher::ActionCopyInstall);
    172188        launcher->setCopyFileName(sisFile, "c:\\data\\testtemp.sis");
    173189        launcher->setInstallFileName("c:\\data\\testtemp.sis");
     190    }
     191    else if (info.exists()) {
     192        launcher->addStartupActions(trk::Launcher::ActionCopy);
     193        launcher->setCopyFileName(exeFile, QString("c:\\sys\\bin\\") + info.fileName());
     194    }
     195    if (!exeFile.isEmpty()) {
     196        launcher->addStartupActions(trk::Launcher::ActionRun);
     197        launcher->setFileName(QString("c:\\sys\\bin\\") + info.fileName());
     198        launcher->setCommandLineArgs(cmdLine);
     199    }
     200    if (!downloadRemoteFile.isEmpty() && !downloadLocalFile.isEmpty()) {
     201        launcher->addStartupActions(trk::Launcher::ActionDownload);
     202        launcher->setDownloadFileName(downloadRemoteFile, downloadLocalFile);
    174203    }
    175204    if (loglevel > 0)
     
    177206    launcher->setTrkServerName(serialPortName);
    178207
    179     launcher->setFileName(QString("c:\\sys\\bin\\") + exeFile);
    180     launcher->setCommandLineArgs(cmdLine);
    181 
    182208    if (loglevel > 1)
    183209        launcher->setVerbose(1);
     
    185211    TrkSignalHandler handler;
    186212    handler.setLogLevel(loglevel);
     213    handler.setCrashLogging(crashlog);
     214    handler.setCrashLogPath(crashlogpath);
    187215
    188216    QObject::connect(launcher.data(), SIGNAL(copyingStarted()), &handler, SLOT(copyingStarted()));
     
    201229    QObject::connect(launcher.data(), SIGNAL(stateChanged(int)), &handler, SLOT(stateChanged(int)));
    202230    QObject::connect(launcher.data(), SIGNAL(processStopped(uint,uint,uint,QString)), &handler, SLOT(stopped(uint,uint,uint,QString)));
     231    QObject::connect(launcher.data(), SIGNAL(libraryLoaded(trk::Library)), &handler, SLOT(libraryLoaded(trk::Library)));
     232    QObject::connect(launcher.data(), SIGNAL(libraryUnloaded(trk::Library)), &handler, SLOT(libraryUnloaded(trk::Library)));
     233    QObject::connect(launcher.data(), SIGNAL(registersAndCallStackReadComplete(const QList<uint> &,const QByteArray &)), &handler, SLOT(registersAndCallStackReadComplete(const QList<uint> &,const QByteArray &)));
    203234    QObject::connect(&handler, SIGNAL(resume(uint,uint)), launcher.data(), SLOT(resumeProcess(uint,uint)));
    204235    QObject::connect(&handler, SIGNAL(terminate()), launcher.data(), SLOT(terminate()));
     236    QObject::connect(&handler, SIGNAL(getRegistersAndCallStack(uint,uint)), launcher.data(), SLOT(getRegistersAndCallStack(uint,uint)));
    205237    QObject::connect(launcher.data(), SIGNAL(finished()), &handler, SLOT(finished()));
     238
     239    QObject::connect(OsSignalConverter::instance(), SIGNAL(terminate()), launcher.data(), SLOT(terminate()), Qt::QueuedConnection);
    206240
    207241    QTimer timer;
Note: See TracChangeset for help on using the changeset viewer.