From c9ff25ec9ca7a9c00e4aea7b7ff23e34064a2a1f Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Thu, 22 Sep 2011 15:57:31 +0100 Subject: runonphone - Implement CODA autodetection If runonphone is executed without specifying the debug agent, then it will attempt to autodetect it by sending a CODA ping to the USB port. If there is a reply within 1 second, then CODA mode is used. If not, then TRK mode is used. TRK drops unrecognised messages, so the CODA ping is ignored and initialisation starts normally when the TRK ping is sent. Autodetect can be skipped by using the --coda or --trk arguments on the command line to force use of a specific debug agent. Reviewed-By: mread --- tools/runonphone/codasignalhandler.cpp | 10 ++++--- tools/runonphone/main.cpp | 31 ++++++++++++++++++---- .../symbianutils/symbiandevicemanager.cpp | 3 +++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/tools/runonphone/codasignalhandler.cpp b/tools/runonphone/codasignalhandler.cpp index 2de6fbc..1df7834 100644 --- a/tools/runonphone/codasignalhandler.cpp +++ b/tools/runonphone/codasignalhandler.cpp @@ -188,10 +188,15 @@ int CodaSignalHandler::run() connect(this, SIGNAL(done()), this, SLOT(finished())); d->codaDevice->sendSerialPing(false); - if (d->timeout > 0) - QTimer::singleShot(d->timeout, this, SLOT(timeout())); + QTimer timer; + if (d->timeout > 0) { + connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); + timer.setSingleShot(true); + timer.start(d->timeout); + } d->eventLoop = new QEventLoop(); d->eventLoop->exec(); + timer.stop(); int result = d->result; reportMessage(tr("Done.")); @@ -199,7 +204,6 @@ int CodaSignalHandler::run() disconnect(d->codaDevice.data(), 0, this, 0); SymbianUtils::SymbianDeviceManager::instance()->releaseCodaDevice(d->codaDevice); - QCoreApplication::quit(); return result; } diff --git a/tools/runonphone/main.cpp b/tools/runonphone/main.cpp index 39fa983..6dd53fc 100644 --- a/tools/runonphone/main.cpp +++ b/tools/runonphone/main.cpp @@ -70,7 +70,8 @@ void printUsage(QTextStream& outstream, QString exeName) << "-T, --tempfile specify temporary sis file name" << endl << "--nocrashlog Don't capture call stack if test crashes" << endl << "--crashlogpath Path to save crash logs (default=working dir)" << endl - << "--coda Use CODA instead of TRK (default agent)" << endl + << "--coda Use CODA instead of detecting the debug agent" << endl + << "--trk Use TRK instead of detecting the debug agent" << endl << endl << "USB COM ports can usually be autodetected, use -p or -f to force a specific port." << endl << "TRK is the default debugging agent, use --coda option when using CODA instead of TRK." << endl @@ -99,7 +100,7 @@ int main(int argc, char *argv[]) int loglevel=1; int timeout=0; bool crashlog = true; - bool coda = false; + enum {AgentUnknown, AgentCoda, AgentTRK} debugAgent = AgentUnknown; QString crashlogpath; QListIterator it(args); it.next(); //skip name of program @@ -154,7 +155,9 @@ int main(int argc, char *argv[]) } } else if (arg == "--coda") - coda = true; + debugAgent = AgentCoda; + else if (arg == "--trk") + debugAgent = AgentTRK; else if (arg == "--tempfile" || arg == "-T") { CHECK_PARAMETER_EXISTS dstName = it.next(); @@ -225,7 +228,24 @@ int main(int argc, char *argv[]) QFileInfo info(exeFile); QFileInfo uploadInfo(uploadLocalFile); - if (coda) { + if (debugAgent == AgentUnknown) { + outstream << "detecting debug agent..." << endl; + CodaSignalHandler codaDetector; + //auto detect agent + codaDetector.setSerialPortName(serialPortName); + codaDetector.setLogLevel(loglevel); + codaDetector.setActionType(ActionPingOnly); + codaDetector.setTimeout(1000); + if (!codaDetector.run()) { + debugAgent = AgentCoda; + outstream << " - Coda is found" << endl; + } else { + debugAgent = AgentTRK; + outstream << " - Coda is not found, defaulting to TRK" << endl; + } + } + + if (debugAgent == AgentCoda) { codaHandler.setSerialPortName(serialPortName); codaHandler.setLogLevel(loglevel); @@ -257,7 +277,8 @@ int main(int argc, char *argv[]) return codaHandler.run(); } else { - launcher.reset(new trk::Launcher(trk::Launcher::ActionPingOnly)); + launcher.reset(new trk::Launcher(trk::Launcher::ActionPingOnly, + SymbianUtils::SymbianDeviceManager::instance()->acquireDevice(serialPortName))); QStringList srcNames, dstNames; if (!sisFile.isEmpty()) { launcher->addStartupActions(trk::Launcher::ActionCopyInstall); diff --git a/tools/runonphone/symbianutils/symbiandevicemanager.cpp b/tools/runonphone/symbianutils/symbiandevicemanager.cpp index e8d0b5e..0b7f581 100644 --- a/tools/runonphone/symbianutils/symbiandevicemanager.cpp +++ b/tools/runonphone/symbianutils/symbiandevicemanager.cpp @@ -183,6 +183,9 @@ SymbianDevice::TrkDevicePtr SymbianDevice::acquireDevice() << "acquired: " << m_data->deviceAcquired << " open: " << isOpen(); if (isNull() || m_data->deviceAcquired) return TrkDevicePtr(); + //if port was opened for coda (but is not acquired) then close it first. + if (m_data->codaDevice) + m_data->codaDevice->device()->close(); if (m_data->device.isNull()) { m_data->device = TrkDevicePtr(new trk::TrkDevice); m_data->device->setPort(m_data->portName); -- cgit v0.12 From 8610ee14b8636641651a8ba6040cca16c4141ed6 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Mon, 3 Oct 2011 16:27:34 +0100 Subject: QNAM - fix poor performance of HEAD request with authentication QHttpNetworkReply was waiting for a body to be sent for 401 and 407 responses, whereas with a HTTP HEAD request, there will be no body. This delayed the authentication signal until after the http channel is closed by the server after a timeout. For example with the server used for autotesting, the authentication signal is delayed 15 seconds. When the server has a very long timeout, the authentication signal may not be emitted at all. Task-Number: QT-5304 Reviewed-By: Martin Petersson --- src/network/access/qhttpnetworkreply.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 1a02200..6173b39 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -891,7 +891,7 @@ bool QHttpNetworkReplyPrivate::expectContent() || statusCode == 204 || statusCode == 304) return false; if (request.operation() == QHttpNetworkRequest::Head) - return !shouldEmitSignals(); + return false; // no body expected for HEAD request qint64 expectedContentLength = contentLength(); if (expectedContentLength == 0) return false; -- cgit v0.12 From 3dfaa160e19c3563d0c229fbdb951d314adc918c Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Mon, 3 Oct 2011 16:29:43 +0100 Subject: Create auto test for http HEAD request This is in order to have a regression test for QT-5304. However the test is also checking basic functionality of head requests too. Task-Number: QT-5304 Reviewed-By: Martin Petersson --- tests/auto/qnetworkreply/.gitattributes | 1 + tests/auto/qnetworkreply/index.html | 3 ++ tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 61 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 tests/auto/qnetworkreply/index.html diff --git a/tests/auto/qnetworkreply/.gitattributes b/tests/auto/qnetworkreply/.gitattributes index 80252cf..7fa30e3 100644 --- a/tests/auto/qnetworkreply/.gitattributes +++ b/tests/auto/qnetworkreply/.gitattributes @@ -1,3 +1,4 @@ rfc3252.txt -crlf bigfile -crlf resource -crlf +index.html -crlf diff --git a/tests/auto/qnetworkreply/index.html b/tests/auto/qnetworkreply/index.html new file mode 100644 index 0000000..135db79 --- /dev/null +++ b/tests/auto/qnetworkreply/index.html @@ -0,0 +1,3 @@ +

Welcome to qt-test-server

+fluke +

This is a network test server. It serves as a cacheing ftp and http proxy, transparent http/socks5 proxy, imap, ftp and http server, plus more.

diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 70287a9..3d1e35e 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -197,6 +197,8 @@ private Q_SLOTS: void getFromHttp(); void getErrors_data(); void getErrors(); + void headFromHttp_data(); + void headFromHttp(); void putToFile_data(); void putToFile(); void putToFtp_data(); @@ -1610,6 +1612,65 @@ void tst_QNetworkReply::getFromHttp() QCOMPARE(reply->readAll(), reference.readAll()); } +void tst_QNetworkReply::headFromHttp_data() +{ + QTest::addColumn("referenceSize"); + QTest::addColumn("url"); + QTest::addColumn("contentType"); + QTest::addColumn("proxy"); + + qint64 rfcsize = QFileInfo(SRCDIR "/rfc3252.txt").size(); + qint64 bigfilesize = QFileInfo(SRCDIR "/bigfile").size(); + qint64 indexsize = QFileInfo(SRCDIR "/index.html").size(); + + //testing proxies, mainly for the 407 response from http proxy + for (int i = 0; i < proxies.count(); ++i) { + QTest::newRow("rfc" + proxies.at(i).tag) << rfcsize << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt") << "text/plain" << proxies.at(i).proxy; + QTest::newRow("bigfile" + proxies.at(i).tag) << bigfilesize << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/bigfile") << "text/plain" << proxies.at(i).proxy; + QTest::newRow("index" + proxies.at(i).tag) << indexsize << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/") << "text/html" << proxies.at(i).proxy; + QTest::newRow("with-authentication" + proxies.at(i).tag) << rfcsize << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfcs-auth/rfc3252.txt") << "text/plain" << proxies.at(i).proxy; + QTest::newRow("cgi" + proxies.at(i).tag) << (qint64)-1 << QUrl("http://qt-test-server/qtest/cgi-bin/httpcachetest_expires500.cgi") << "text/html" << proxies.at(i).proxy; + } +} + +void tst_QNetworkReply::headFromHttp() +{ + QFETCH(qint64, referenceSize); + QFETCH(QUrl, url); + QFETCH(QString, contentType); + QFETCH(QNetworkProxy, proxy); + + QNetworkRequest request(url); + QNetworkReplyPtr reply; + + QElapsedTimer time; + time.start(); + + manager.setProxy(proxy); + connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + connect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), + SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); + + RUN_REQUEST(runSimpleRequest(QNetworkAccessManager::HeadOperation, request, reply)); + + manager.disconnect(SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); + manager.disconnect(SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), + this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); + + QVERIFY(time.elapsed() < 8000); //check authentication didn't wait for the server to timeout the http connection (15s on qt test server) + + QCOMPARE(reply->url(), request.url()); + QCOMPARE(reply->error(), QNetworkReply::NoError); + QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); + // only compare when the header is set. + if (reply->header(QNetworkRequest::ContentLengthHeader).isValid() && referenceSize >= 0) + QCOMPARE(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), referenceSize); + if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) + QCOMPARE(reply->header(QNetworkRequest::ContentTypeHeader).toString(), contentType); +} + void tst_QNetworkReply::getErrors_data() { QTest::addColumn("url"); -- cgit v0.12