diff options
Diffstat (limited to 'tests/arthur/baselineserver')
-rw-r--r-- | tests/arthur/baselineserver/src/baselineserver.cpp | 188 | ||||
-rw-r--r-- | tests/arthur/baselineserver/src/baselineserver.h | 16 | ||||
-rw-r--r-- | tests/arthur/baselineserver/src/baselineserver.pro | 7 | ||||
-rw-r--r-- | tests/arthur/baselineserver/src/baselineserver.qrc | 5 | ||||
-rw-r--r-- | tests/arthur/baselineserver/src/htmlpage.cpp | 228 | ||||
-rw-r--r-- | tests/arthur/baselineserver/src/main.cpp | 2 | ||||
-rw-r--r-- | tests/arthur/baselineserver/src/report.cpp | 296 | ||||
-rw-r--r-- | tests/arthur/baselineserver/src/report.h (renamed from tests/arthur/baselineserver/src/htmlpage.h) | 45 | ||||
-rw-r--r-- | tests/arthur/baselineserver/src/templates/view.html | 79 |
9 files changed, 514 insertions, 352 deletions
diff --git a/tests/arthur/baselineserver/src/baselineserver.cpp b/tests/arthur/baselineserver/src/baselineserver.cpp index 7679f13..f59600f 100644 --- a/tests/arthur/baselineserver/src/baselineserver.cpp +++ b/tests/arthur/baselineserver/src/baselineserver.cpp @@ -51,6 +51,7 @@ #include <QHostInfo> #include <QTextStream> #include <QProcess> +#include <QDirIterator> QString BaselineServer::storage; @@ -96,9 +97,11 @@ void BaselineServer::heartbeat() QFileInfo me(QCoreApplication::applicationFilePath()); if (me.lastModified() == meLastMod) return; + if (!me.exists() || !me.isExecutable()) + return; - // (could close() here to avoid accepting new connections, to avoid livelock) - // also, could check for a timeout to force exit, to avoid hung threads blocking + //# (could close() here to avoid accepting new connections, to avoid livelock) + //# also, could check for a timeout to force exit, to avoid hung threads blocking bool isServing = false; foreach(BaselineThread *thread, findChildren<BaselineThread *>()) { if (thread->isRunning()) { @@ -142,36 +145,43 @@ const char *BaselineHandler::logtime() //return QTime::currentTime().toString(QLS("mm:ss.zzz")); } -void BaselineHandler::receiveRequest() +bool BaselineHandler::establishConnection() { - if (!connectionEstablished) { - if (!proto.acceptConnection(&plat)) { - qWarning() << runId << logtime() << "Accepting new connection from" << proto.socket.peerAddress().toString() << "failed." << proto.errorMessage(); - proto.socket.disconnectFromHost(); - return; - } - QString logMsg; - foreach (QString key, plat.keys()) { - if (key != PI_HostName && key != PI_HostAddress) - logMsg += key + QLS(": '") + plat.value(key) + QLS("', "); - } - qDebug() << runId << logtime() << "Connection established with" << plat.value(PI_HostName) - << "[" << qPrintable(plat.value(PI_HostAddress)) << "]" << logMsg; + if (!proto.acceptConnection(&plat)) { + qWarning() << runId << logtime() << "Accepting new connection from" << proto.socket.peerAddress().toString() << "failed." << proto.errorMessage(); + proto.socket.disconnectFromHost(); + return false; + } + QString logMsg; + foreach (QString key, plat.keys()) { + if (key != PI_HostName && key != PI_HostAddress) + logMsg += key + QLS(": '") + plat.value(key) + QLS("', "); + } + qDebug() << runId << logtime() << "Connection established with" << plat.value(PI_HostName) + << "[" << qPrintable(plat.value(PI_HostAddress)) << "]" << logMsg; - // Filter on branch - QString branch = plat.value(PI_PulseGitBranch); - if (branch.isEmpty()) { - // Not run by Pulse, i.e. ad hoc run: Ok. - } - else if (branch != QLS("master-integration") || !plat.value(PI_GitCommit).contains(QLS("Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into master-integration"))) { - qDebug() << runId << logtime() << "Did not pass branch/staging repo filter, disconnecting."; - proto.sendBlock(BaselineProtocol::Abort, QByteArray("This branch/staging repo is not assigned to be tested.")); - proto.socket.disconnectFromHost(); - return; - } + // Filter on branch + QString branch = plat.value(PI_PulseGitBranch); + if (branch.isEmpty()) { + // Not run by Pulse, i.e. ad hoc run: Ok. + } + else if (branch != QLS("master-integration") || !plat.value(PI_GitCommit).contains(QLS("Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into master-integration"))) { + qDebug() << runId << logtime() << "Did not pass branch/staging repo filter, disconnecting."; + proto.sendBlock(BaselineProtocol::Abort, QByteArray("This branch/staging repo is not assigned to be tested.")); + proto.socket.disconnectFromHost(); + return false; + } - proto.sendBlock(BaselineProtocol::Ack, QByteArray()); - connectionEstablished = true; + proto.sendBlock(BaselineProtocol::Ack, QByteArray()); + + report.init(this, runId, plat); + return true; +} + +void BaselineHandler::receiveRequest() +{ + if (!connectionEstablished) { + connectionEstablished = establishConnection(); return; } @@ -205,8 +215,8 @@ void BaselineHandler::provideBaselineChecksums(const QByteArray &itemListBlock) ImageItemList itemList; QDataStream ds(itemListBlock); ds >> itemList; - qDebug() << runId << logtime() << "Received request for checksums for" << itemList.count() << "items, engine" - << itemList.at(0).engineAsString() << "pixel format" << itemList.at(0).formatAsString(); + qDebug() << runId << logtime() << "Received request for checksums for" << itemList.count() + << "items in test function" << itemList.at(0).testFunction; for (ImageItemList::iterator i = itemList.begin(); i != itemList.end(); ++i) { i->imageChecksums.clear(); @@ -229,10 +239,10 @@ void BaselineHandler::provideBaselineChecksums(const QByteArray &itemListBlock) if (file.open(QIODevice::ReadOnly)) { QTextStream in(&file); do { - QString scriptName = in.readLine(); - if (!scriptName.isNull()) { + QString itemName = in.readLine(); + if (!itemName.isNull()) { for (ImageItemList::iterator i = itemList.begin(); i != itemList.end(); ++i) { - if (i->scriptName == scriptName) + if (i->itemName == itemName) i->status = ImageItem::IgnoreItem; } } @@ -244,7 +254,7 @@ void BaselineHandler::provideBaselineChecksums(const QByteArray &itemListBlock) QDataStream ods(&block, QIODevice::WriteOnly); ods << itemList; proto.sendBlock(BaselineProtocol::Ack, block); - report.start(BaselineServer::storagePath(), runId, plat, context, itemList); + report.addItems(itemList); } @@ -255,7 +265,14 @@ void BaselineHandler::storeImage(const QByteArray &itemBlock, bool isBaseline) ds >> item; QString prefix = pathForItem(item, isBaseline); - qDebug() << runId << logtime() << "Received" << (isBaseline ? "baseline" : "mismatched") << "image for:" << item.scriptName << "Storing in" << prefix; + qDebug() << runId << logtime() << "Received" << (isBaseline ? "baseline" : "mismatched") << "image for:" << item.itemName << "Storing in" << prefix; + + QString msg; + if (isBaseline) + msg = QLS("New baseline image stored: ") + pathForItem(item, true, true) + QLS(FileFormat); + else + msg = BaselineServer::baseUrl() + report.filePath(); + proto.sendBlock(BaselineProtocol::Ack, msg.toLatin1()); QString dir = prefix.section(QLC('/'), 0, -2); QDir cwd; @@ -271,19 +288,7 @@ void BaselineHandler::storeImage(const QByteArray &itemBlock, bool isBaseline) file.close(); if (!isBaseline) - report.addItem(pathForItem(item, true, false) + QLS(FileFormat), - pathForItem(item, false, false) + QLS(FileFormat), - item); - - QByteArray msg(isBaseline ? "New baseline image stored: " : - "Mismatch report: " ); - msg += BaselineServer::baseUrl(); - if (isBaseline) - msg += pathForItem(item, true, false).toLatin1() + FileFormat; - else - msg += report.filePath(); - - proto.sendBlock(BaselineProtocol::Ack, msg); + report.addMismatch(item); } @@ -295,7 +300,7 @@ void BaselineHandler::receiveDisconnect() } -void BaselineHandler::mapPlatformInfo() +void BaselineHandler::mapPlatformInfo() const { mapped = plat; @@ -304,10 +309,13 @@ void BaselineHandler::mapPlatformInfo() if (host.isEmpty() || host == QLS("localhost")) { host = plat.value(PI_HostAddress); } else { - // remove index postfix typical of vm hostnames - host.remove(QRegExp(QLS("\\d+$"))); - if (host.endsWith(QLC('-'))) - host.chop(1); + //# Site specific, should be in a config file + if (!host.startsWith(QLS("oldhcp"))) { + // remove index postfix typical of vm hostnames + host.remove(QRegExp(QLS("\\d+$"))); + if (host.endsWith(QLC('-'))) + host.chop(1); + } } if (host.isEmpty()) host = QLS("unknownhost"); @@ -322,22 +330,23 @@ void BaselineHandler::mapPlatformInfo() mapped.insert(PI_QtVersion, ver.prepend(QLS("Qt-"))); //### TBD: remove patch version } -QString BaselineHandler::pathForItem(const ImageItem &item, bool isBaseline, bool absolute) +QString BaselineHandler::pathForItem(const ImageItem &item, bool isBaseline, bool absolute) const { if (mapped.isEmpty()) mapPlatformInfo(); - QString itemName = item.scriptName; - if (itemName.contains(QLC('.'))) - itemName.replace(itemName.lastIndexOf(QLC('.')), 1, QLC('_')); + QString itemName = item.itemName.simplified(); + itemName.replace(QLC(' '), QLC('_')); + itemName.replace(QLC('.'), QLC('_')); itemName.append(QLC('_')); - itemName.append(QString::number(item.scriptChecksum, 16).rightJustified(4, QLC('0'))); + itemName.append(QString::number(item.itemChecksum, 16).rightJustified(4, QLC('0'))); QStringList path; if (absolute) path += BaselineServer::storagePath(); + path += mapped.value(PI_TestCase); path += QLS(isBaseline ? "baselines" : "mismatches"); - path += item.engineAsString() + QLC('_') + item.formatAsString(); + path += item.testFunction; path += mapped.value(PI_QtVersion); path += mapped.value(PI_QMakeSpec); path += mapped.value(PI_HostName); @@ -349,43 +358,26 @@ QString BaselineHandler::pathForItem(const ImageItem &item, bool isBaseline, boo } -QString BaselineHandler::updateAllBaselines(const QString &host, const QString &id, - const QString &engine, const QString &format) +QString BaselineHandler::view(const QString &baseline, const QString &rendered, const QString &compared) { -#if 0 - QString basePath(BaselineServer::storagePath()); - QString srcDir(basePath + host + QLC('/') + itemSubPath(engine, format, false) + id); - QString dstDir(basePath + host + QLC('/') + itemSubPath(engine, format)); - - QDir dir(srcDir); - QStringList nameFilter; - nameFilter << "*.metadata" << "*.png"; - QStringList fileList = dir.entryList(nameFilter, QDir::Files | QDir::NoDotAndDotDot); - - // remove the generated _fuzzycompared.png and _compared.png files from the list - QMutableStringListIterator it(fileList); - while (it.hasNext()) { - it.next(); - if (it.value().endsWith(QLS("compared.png"))) - it.remove(); - } + QFile f(":/templates/view.html"); + f.open(QIODevice::ReadOnly); + return QString::fromLatin1(f.readAll()).arg('/'+baseline, '/'+rendered, '/'+compared); +} - QString res; - QProcess proc; - proc.setWorkingDirectory(srcDir); - proc.setProcessChannelMode(QProcess::MergedChannels); - proc.start(QLS("cp"), QStringList() << QLS("-f") << fileList << dstDir); - proc.waitForFinished(); - if (proc.exitCode() == 0) - res = QLS("Successfully updated baseline for all failed tests."); - else - res = QString("Error updating baseline: %1<br>" - "Command output: <pre>%2</pre>").arg(proc.errorString(), proc.readAll().constData()); - return res; -#else - return QString(); -#endif +QString BaselineHandler::clearAllBaselines(const QString &context) +{ + int tot = 0; + int failed = 0; + QDirIterator it(BaselineServer::storagePath() + QLC('/') + context, + QStringList() << QLS("*.png") << QLS("*.metadata")); + while (it.hasNext()) { + tot++; + if (!QFile::remove(it.next())) + failed++; + } + return QString(QLS("%1 of %2 baselines cleared from context ")).arg((tot-failed)/2).arg(tot/2) + context; } QString BaselineHandler::updateSingleBaseline(const QString &oldBaseline, const QString &newBaseline) @@ -408,6 +400,7 @@ QString BaselineHandler::updateSingleBaseline(const QString &oldBaseline, const return res; } + QString BaselineHandler::blacklistTest(const QString &context, const QString &itemId, bool removeFromBlacklist) { QFile file(BaselineServer::storagePath() + QLC('/') + context + QLS("/BLACKLIST")); @@ -450,11 +443,10 @@ void BaselineHandler::testPathMapping() << QLS("localhost"); ImageItem item; - item.scriptName = QLS("arcs.qps"); - item.engine = ImageItem::Raster; - item.renderFormat = QImage::Format_ARGB32_Premultiplied; + item.testFunction = QLS("testPathMapping"); + item.itemName = QLS("arcs.qps"); item.imageChecksums << 0x0123456789abcdefULL; - item.scriptChecksum = 0x0123; + item.itemChecksum = 0x0123; plat.insert(PI_QtVersion, QLS("4.8.0")); plat.insert(PI_BuildKey, QLS("(nobuildkey)")); diff --git a/tests/arthur/baselineserver/src/baselineserver.h b/tests/arthur/baselineserver/src/baselineserver.h index d49aedb..e09a9d0 100644 --- a/tests/arthur/baselineserver/src/baselineserver.h +++ b/tests/arthur/baselineserver/src/baselineserver.h @@ -50,7 +50,7 @@ #include <QDateTime> #include "baselineprotocol.h" -#include "htmlpage.h" +#include "report.h" // #seconds between update checks #define HEARTBEAT 10 @@ -99,9 +99,11 @@ class BaselineHandler : public QObject public: BaselineHandler(int socketDescriptor = -1); void testPathMapping(); + QString pathForItem(const ImageItem &item, bool isBaseline = true, bool absolute = true) const; - static QString updateAllBaselines(const QString &host, const QString &id, - const QString &engine, const QString &format); + // CGI callbacks: + static QString view(const QString &baseline, const QString &rendered, const QString &compared); + static QString clearAllBaselines(const QString &context); static QString updateSingleBaseline(const QString &oldBaseline, const QString &newBaseline); static QString blacklistTest(const QString &context, const QString &itemId, bool removeFromBlacklist = false); @@ -110,19 +112,19 @@ private slots: void receiveDisconnect(); private: + bool establishConnection(); void provideBaselineChecksums(const QByteArray &itemListBlock); void storeImage(const QByteArray &itemBlock, bool isBaseline); - void mapPlatformInfo(); - QString pathForItem(const ImageItem &item, bool isBaseline = true, bool absolute = true); + void mapPlatformInfo() const; const char *logtime(); QString computeMismatchScore(const QImage& baseline, const QImage& rendered); BaselineProtocol proto; PlatformInfo plat; - PlatformInfo mapped; + mutable PlatformInfo mapped; bool connectionEstablished; QString runId; - HTMLPage report; + Report report; }; #endif // BASELINESERVER_H diff --git a/tests/arthur/baselineserver/src/baselineserver.pro b/tests/arthur/baselineserver/src/baselineserver.pro index a7be03d..770662b 100644 --- a/tests/arthur/baselineserver/src/baselineserver.pro +++ b/tests/arthur/baselineserver/src/baselineserver.pro @@ -20,8 +20,11 @@ include(../../common/baselineprotocol.pri) SOURCES += main.cpp \ baselineserver.cpp \ - htmlpage.cpp + report.cpp HEADERS += \ baselineserver.h \ - htmlpage.h + report.h + +RESOURCES += \ + baselineserver.qrc diff --git a/tests/arthur/baselineserver/src/baselineserver.qrc b/tests/arthur/baselineserver/src/baselineserver.qrc new file mode 100644 index 0000000..b5cd6af --- /dev/null +++ b/tests/arthur/baselineserver/src/baselineserver.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>templates/view.html</file> + </qresource> +</RCC> diff --git a/tests/arthur/baselineserver/src/htmlpage.cpp b/tests/arthur/baselineserver/src/htmlpage.cpp deleted file mode 100644 index f75da88..0000000 --- a/tests/arthur/baselineserver/src/htmlpage.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "htmlpage.h" -#include "baselineprotocol.h" -#include "baselineserver.h" -#include <QDir> -#include <QProcess> -#include <QUrl> - -HTMLPage::HTMLPage() - : headerWritten(false) -{ -} - -HTMLPage::~HTMLPage() -{ - end(); -} - -QString HTMLPage::filePath() -{ - return path; -} - -void HTMLPage::start(const QString &storagepath, const QString &runId, const PlatformInfo pinfo, const QString &context, const ImageItemList &itemList) -{ - end(); - - id = runId; - plat = pinfo; - ctx = context; - root = storagepath + QLC('/'); - imageItems = itemList; - QString dir = root + QLS("reports/"); - QDir cwd; - if (!cwd.exists(dir)) - cwd.mkpath(dir); -} - - -void HTMLPage::writeHeader(const ImageItem &item) -{ - path = QLS("reports/") + id + QLC('_') + item.engineAsString() - + QLC('_') + item.formatAsString() + QLS(".html"); - - QString pageUrl = BaselineServer::baseUrl() + path; - - file.setFileName(root + path); - if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) - qWarning() << "Failed to open report file" << file.fileName(); - out.setDevice(&file); - - out << "<html><body><h1>Lancelot results from run " << id << "</h1>\n\n"; - out << "<h3>Platform Info:</h3>\n"; - out << "<table>\n"; - foreach (QString key, plat.keys()) - out << "<tr><td>" << key << "</td><td>" << plat.value(key) << "</td></tr>\n"; - out << "</table>\n"; - -#if 0 - out << "<h3><a href=\"/cgi-bin/server.cgi?cmd=updateAllBaselines&id="<< id << "&host=" << plat.hostName - << "&engine=" << item.engineAsString() << "&format=" << item.formatAsString() - << "&url=" << pageUrl - << "\">Update all baselines</a><br>"; -#endif - out << "<table border=\"2\">\n" - "<tr>\n" - "<td><b>Script</b></td>\n" - "<td><b>Baseline</b></td>\n" - "<td><b>Rendered</b></td>\n" - "<td><b>Comparison</b></td>\n" - "<td><b>Info/Action</b></td>\n" - "</b></tr><br>"; -} - - -void HTMLPage::writeFooter() -{ - out << "</table>\n</body></html>\n"; -} - - -void HTMLPage::addItem(const QString &baseline, const QString &rendered, const ImageItem &item) -{ - if (!headerWritten) { - writeHeader(item); - headerWritten = true; - } - QString compared = generateCompared(baseline, rendered); - QString pageUrl = BaselineServer::baseUrl() + path; - - out << "<tr>\n"; - out << "<td>" << item.scriptName << "</td>\n"; - QStringList images = QStringList() << baseline << rendered << compared; - foreach(const QString& img, images) - out << "<td><a href=\"/" << img << "\"><img src=\"/" << img << "\" width=240 height=240></a></td>\n"; - - out << "<td><p><a href=\"/cgi-bin/server.cgi?cmd=updateSingleBaseline&oldBaseline=" << baseline - << "&newBaseline=" << rendered << "&url=" << pageUrl << "\">Replace baseline with rendered</a></p>" - << "<p><a href=\"/cgi-bin/server.cgi?cmd=blacklist&context=" << ctx - << "&itemId=" << item.scriptName << "&url=" << pageUrl << "\">Blacklist this item</a></p>" - << "</td>\n"; - out << "</tr>\n\n"; - - QMutableVectorIterator<ImageItem> it(imageItems); - while (it.hasNext()) { - it.next(); - if (it.value().scriptName == item.scriptName) { - it.remove(); - break; - } - } -} - - -void HTMLPage::end() -{ - if (file.isOpen()) { - // Add the names of the scripts that passed the test, or were blacklisted - QString pageUrl = BaselineServer::baseUrl() + path; - for (int i=0; i<imageItems.count(); ++i) { - out << "<tr><td>" << imageItems.at(i).scriptName << "</td><td>N/A</td><td>N/A</td><td>N/A</td><td>"; - if (imageItems.at(i).status == ImageItem::IgnoreItem) { - out << "<span style=\"background-color:yellow\">Blacklisted</span> " - << "<a href=\"/cgi-bin/server.cgi?cmd=whitelist&context=" << ctx - << "&itemId=" << imageItems.at(i).scriptName << "&url=" << pageUrl - << "\">Whitelist item</a>"; - } else { - out << "<span style=\"color:green\">Test passed</span>"; - } - out << "</td></tr>\n"; - } - - writeFooter(); - out.flush(); - file.close(); - path.clear(); - headerWritten = false; - } -} - - -QString HTMLPage::generateCompared(const QString &baseline, const QString &rendered, bool fuzzy) -{ - QString res = rendered; - QFileInfo fi(res); - res.chop(fi.suffix().length() + 1); - res += QLS(fuzzy ? "_fuzzycompared.png" : "_compared.png"); - QStringList args; - if (fuzzy) - args << QLS("-fuzz") << QLS("5%"); - args << root+baseline << root+rendered << root+res; - QProcess::execute(QLS("compare"), args); - return res; -} - - -void HTMLPage::handleCGIQuery(const QString &query) -{ - QUrl cgiUrl(QLS("http://dummy/cgi-bin/dummy.cgi?") + query); - QTextStream s(stdout); - s << "Content-Type: text/html\r\n\r\n" - << "<HTML>"; -// << "Contents of QUERY_STRING:<br>" -// << "Full string = " << query << "<br>"; - - QString command(cgiUrl.queryItemValue("cmd")); - - if (command == QLS("updateSingleBaseline")) { - s << BaselineHandler::updateSingleBaseline(cgiUrl.queryItemValue(QLS("oldBaseline")), - cgiUrl.queryItemValue(QLS("newBaseline"))); - } else if (command == QLS("updateAllBaselines")) { - s << BaselineHandler::updateAllBaselines(cgiUrl.queryItemValue(QLS("host")), - cgiUrl.queryItemValue(QLS("id")), - cgiUrl.queryItemValue(QLS("engine")), - cgiUrl.queryItemValue(QLS("format"))); - } else if (command == QLS("blacklist")) { - // blacklist a test - s << BaselineHandler::blacklistTest(cgiUrl.queryItemValue(QLS("context")), - cgiUrl.queryItemValue(QLS("itemId"))); - } else if (command == QLS("whitelist")) { - // whitelist a test - s << BaselineHandler::blacklistTest(cgiUrl.queryItemValue(QLS("context")), - cgiUrl.queryItemValue(QLS("itemId")), true); - } else { - s << "Unknown query:<br>" << query << "<br>"; - } - s << "<p><a href=\"" << cgiUrl.queryItemValue(QLS("url")) << "\">Back to report</a>"; - s << "</HTML>"; -} diff --git a/tests/arthur/baselineserver/src/main.cpp b/tests/arthur/baselineserver/src/main.cpp index a5ec4db..bf41f41 100644 --- a/tests/arthur/baselineserver/src/main.cpp +++ b/tests/arthur/baselineserver/src/main.cpp @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) QString queryString(qgetenv("QUERY_STRING")); if (!queryString.isEmpty()) { // run as CGI script - HTMLPage::handleCGIQuery(queryString); + Report::handleCGIQuery(queryString); return 0; } diff --git a/tests/arthur/baselineserver/src/report.cpp b/tests/arthur/baselineserver/src/report.cpp new file mode 100644 index 0000000..f5bb418 --- /dev/null +++ b/tests/arthur/baselineserver/src/report.cpp @@ -0,0 +1,296 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "report.h" +#include "baselineprotocol.h" +#include "baselineserver.h" +#include <QDir> +#include <QProcess> +#include <QUrl> + +Report::Report() + : written(false), numItems(0), numMismatches(0) +{ +} + +Report::~Report() +{ + end(); +} + +QString Report::filePath() +{ + return path; +} + +void Report::init(const BaselineHandler *h, const QString &r, const PlatformInfo &p) +{ + handler = h; + runId = r; + plat = p; + rootDir = BaselineServer::storagePath() + QLC('/'); + reportDir = plat.value(PI_TestCase) + QLC('/') + (plat.value(PI_PulseGitBranch).isEmpty() ? QLS("reports/adhoc/") : QLS("reports/pulse/")); + QString dir = rootDir + reportDir; + QDir cwd; + if (!cwd.exists(dir)) + cwd.mkpath(dir); + path = reportDir + QLS("Report_") + runId + QLS(".html"); +} + +void Report::addItems(const ImageItemList &items) +{ + if (items.isEmpty()) + return; + numItems += items.size(); + QString func = items.at(0).testFunction; + if (!testFunctions.contains(func)) + testFunctions.append(func); + itemLists[func] += items; +} + +void Report::addMismatch(const ImageItem &item) +{ + if (!testFunctions.contains(item.testFunction)) { + qWarning() << "Report::addMismatch: unknown testfunction" << item.testFunction; + return; + } + bool found = false; + ImageItemList &list = itemLists[item.testFunction]; + for (ImageItemList::iterator it = list.begin(); it != list.end(); ++it) { + if (it->itemName == item.itemName && it->itemChecksum == item.itemChecksum) { + it->status = ImageItem::Mismatch; + found = true; + break; + } + } + if (found) + numMismatches++; + else + qWarning() << "Report::addMismatch: unknown item" << item.itemName << "in testfunction" << item.testFunction; +} + +void Report::end() +{ + if (written || !numMismatches) + return; + write(); + written = true; +} + + +void Report::write() +{ + QFile file(rootDir + path); + if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + qWarning() << "Failed to open report file" << file.fileName(); + return; + } + out.setDevice(&file); + + writeHeader(); + foreach(const QString &func, testFunctions) { + writeFunctionResults(itemLists.value(func)); + } + writeFooter(); + file.close(); +} + + +void Report::writeHeader() +{ + QString title = plat.value(PI_TestCase) + QLS(" Qt Baseline Test Report"); + out << "<head><title>" << title << "</title></head>\n" + << "<html><body><h1>" << title << "</h1>\n" + << "<p>Run Id: <b>" << runId << "</b></p>\n" + << "<p>Summary: <b>" << numMismatches << " of " << numItems << "</b> items reported mismatching</p>\n\n"; + out << "<h3>Platform Info:</h3>\n" + << "<table>\n"; + foreach (QString key, plat.keys()) + out << "<tr><td>" << key << "</td><td>" << plat.value(key) << "</td></tr>\n"; + out << "</table>\n\n"; +} + + +void Report::writeFunctionResults(const ImageItemList &list) +{ + QString testFunction = list.at(0).testFunction; + QString pageUrl = BaselineServer::baseUrl() + path; + QString ctx = handler->pathForItem(list.at(0), true, false).section(QLC('/'), 0, -2); + + out << "\n<p> </p><h3>Test function: " << testFunction << "</h3>\n"; + out << "<p><a href=\"/cgi-bin/server.cgi?cmd=clearAllBaselines&context=" << ctx << "&url=" << pageUrl + << "\"><b><big>Clear all baselines</big></b></a></h3> (They will be recreated by the next run)</p>\n\n"; + + out << "<table border=\"2\">\n" + "<tr>\n" + "<th width=123>Item</th>\n" + "<th width=246>Baseline</th>\n" + "<th width=246>Rendered</th>\n" + "<th width=246>Comparison (diffs are <span style=\"color:red\">RED</span>)</th>\n" + "<th width=246>Info/Action</th>\n" + "</tr>\n\n"; + + foreach (const ImageItem &item, list) { + out << "<tr>\n"; + out << "<td>" << item.itemName << "</td>\n"; + QString baseline = handler->pathForItem(item, true, false) + QLS(FileFormat); + if (item.status == ImageItem::Mismatch) { + QString rendered = handler->pathForItem(item, false, false) + QLS(FileFormat); + writeItem(baseline, rendered, item, ctx); + } + else { + out << "<td align=center><a href=\"/" << baseline << "\">view</a></td>\n" + << "<td align=center colspan=2><small>n/a</small></td>\n" + << "<td align=center>"; + switch (item.status) { + case ImageItem::BaselineNotFound: + out << "Baseline not found/regenerated"; + break; + case ImageItem::IgnoreItem: + out << "<span style=\"background-color:yellow\">Blacklisted</span> " + << "<a href=\"/cgi-bin/server.cgi?cmd=whitelist&context=" << ctx + << "&itemId=" << item.itemName << "&url=" << pageUrl + << "\">Whitelist this item</a>"; + break; + case ImageItem::Ok: + out << "<span style=\"color:green\"><small>No mismatch reported</small></span>"; + break; + default: + out << "?"; + break; + } + out << "</td>\n"; + } + out << "</tr>\n\n"; + } + + out << "</table>\n"; +} + +void Report::writeItem(const QString &baseline, const QString &rendered, const ImageItem &item, const QString &ctx) +{ + QString compared = generateCompared(baseline, rendered); + QString pageUrl = BaselineServer::baseUrl() + path; + + QStringList images = QStringList() << baseline << rendered << compared; + foreach (const QString& img, images) + out << "<td height=246 align=center><a href=\"/" << img << "\"><img src=\"/" << generateThumbnail(img) << "\"></a></td>\n"; + + out << "<td align=center>\n" + << "<p><span style=\"color:red\">Mismatch reported</span></p>\n" + << "<p><a href=\"/cgi-bin/server.cgi?cmd=updateSingleBaseline&oldBaseline=" << baseline + << "&newBaseline=" << rendered << "&url=" << pageUrl << "\">Replace baseline with rendered</a></p>\n" + << "<p><a href=\"/cgi-bin/server.cgi?cmd=blacklist&context=" << ctx + << "&itemId=" << item.itemName << "&url=" << pageUrl << "\">Blacklist this item</a></p>\n" + << "<p><a href=\"/cgi-bin/server.cgi?cmd=view&baseline=" << baseline << "&rendered=" << rendered + << "&compared=" << compared << "&url=" << pageUrl << "\">Inspect</a></p>\n" + << "</td>\n"; +} + +void Report::writeFooter() +{ + out << "\n</body></html>\n"; +} + + +QString Report::generateCompared(const QString &baseline, const QString &rendered, bool fuzzy) +{ + QString res = rendered; + QFileInfo fi(res); + res.chop(fi.suffix().length() + 1); + res += QLS(fuzzy ? "_fuzzycompared.png" : "_compared.png"); + QStringList args; + if (fuzzy) + args << QLS("-fuzz") << QLS("5%"); + args << rootDir+baseline << rootDir+rendered << rootDir+res; + QProcess::execute(QLS("compare"), args); + return res; +} + + +QString Report::generateThumbnail(const QString &image) +{ + QString res = image; + QFileInfo imgFI(rootDir+image); + res.chop(imgFI.suffix().length() + 1); + res += QLS("_thumbnail.jpg"); + QFileInfo resFI(rootDir+res); + if (resFI.exists() && resFI.lastModified() > imgFI.lastModified()) + return res; + QStringList args; + args << rootDir+image << QLS("-resize") << QLS("240x240>") << QLS("-quality") << QLS("50") << rootDir+res; + QProcess::execute(QLS("convert"), args); + return res; +} + + +void Report::handleCGIQuery(const QString &query) +{ + QUrl cgiUrl(QLS("http://dummy/cgi-bin/dummy.cgi?") + query); + QTextStream s(stdout); + s << "Content-Type: text/html\r\n\r\n" + << "<HTML>"; + + QString command(cgiUrl.queryItemValue("cmd")); + + if (command == QLS("view")) { + s << BaselineHandler::view(cgiUrl.queryItemValue(QLS("baseline")), + cgiUrl.queryItemValue(QLS("rendered")), + cgiUrl.queryItemValue(QLS("compared"))); + } + else if (command == QLS("updateSingleBaseline")) { + s << BaselineHandler::updateSingleBaseline(cgiUrl.queryItemValue(QLS("oldBaseline")), + cgiUrl.queryItemValue(QLS("newBaseline"))); + } else if (command == QLS("clearAllBaselines")) { + s << BaselineHandler::clearAllBaselines(cgiUrl.queryItemValue(QLS("context"))); + } else if (command == QLS("blacklist")) { + // blacklist a test + s << BaselineHandler::blacklistTest(cgiUrl.queryItemValue(QLS("context")), + cgiUrl.queryItemValue(QLS("itemId"))); + } else if (command == QLS("whitelist")) { + // whitelist a test + s << BaselineHandler::blacklistTest(cgiUrl.queryItemValue(QLS("context")), + cgiUrl.queryItemValue(QLS("itemId")), true); + } else { + s << "Unknown query:<br>" << query << "<br>"; + } + s << "<p><a href=\"" << cgiUrl.queryItemValue(QLS("url")) << "\">Back to report</a>"; + s << "</HTML>"; +} diff --git a/tests/arthur/baselineserver/src/htmlpage.h b/tests/arthur/baselineserver/src/report.h index fa4d1ed..0df613a 100644 --- a/tests/arthur/baselineserver/src/htmlpage.h +++ b/tests/arthur/baselineserver/src/report.h @@ -38,40 +38,53 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#ifndef HTMLPAGE_H -#define HTMLPAGE_H +#ifndef REPORT_H +#define REPORT_H #include "baselineprotocol.h" #include <QFile> #include <QTextStream> +#include <QMap> +#include <QStringList> -class HTMLPage +class BaselineHandler; + +class Report { public: - HTMLPage(); - ~HTMLPage(); + Report(); + ~Report(); - void start(const QString &storagePath, const QString &runId, const PlatformInfo pinfo, const QString &context, const ImageItemList &itemList); - void addItem(const QString &baseline, const QString &rendered, const ImageItem &item); + void init(const BaselineHandler *h, const QString &r, const PlatformInfo &p); + void addItems(const ImageItemList& items); + void addMismatch(const ImageItem& item); void end(); + QString filePath(); static void handleCGIQuery(const QString &query); private: - void writeHeader(const ImageItem &item); + void write(); + void writeFunctionResults(const ImageItemList &list); + void writeItem(const QString &baseline, const QString &rendered, const ImageItem &item, const QString &ctx); + void writeHeader(); void writeFooter(); QString generateCompared(const QString &baseline, const QString &rendered, bool fuzzy = false); + QString generateThumbnail(const QString &image); - QString root; + const BaselineHandler *handler; + QString runId; + PlatformInfo plat; + QString rootDir; + QString reportDir; QString path; - QFile file; + QStringList testFunctions; + QMap<QString, ImageItemList> itemLists; + bool written; + int numItems; + int numMismatches; QTextStream out; - QString id; - PlatformInfo plat; - QString ctx; - ImageItemList imageItems; - bool headerWritten; }; -#endif // HTMLPAGE_H +#endif // REPORT_H diff --git a/tests/arthur/baselineserver/src/templates/view.html b/tests/arthur/baselineserver/src/templates/view.html new file mode 100644 index 0000000..c048f47 --- /dev/null +++ b/tests/arthur/baselineserver/src/templates/view.html @@ -0,0 +1,79 @@ +<h3>Lancelot Viewer</h3> + +<p> +Zoom: +<input name="zoom" id="z1" type="radio" checked="Checked">1x</input> +<input name="zoom" id="z2" type="radio">2x</input> +<input name="zoom" id="z4" type="radio">4x</input> +</p> + +<p><table> +<tr> +<td><input name="imgselect" id="baseline" type="radio" checked="Checked">Baseline</input></td> +<td>%1</td> +</tr> +<tr> +<td><input name="imgselect" id="rendered" type="radio">Rendered</input></td> +<td>%2</td> +</tr> +<tr> +<td><input name="imgselect" id="compared" type="radio">Differences</input></td> +<td></td> +</tr> +</table></p> + + +<p> +<canvas id="c" width="800" height="800"></canvas> +</p> + +<script> + var canvas = document.getElementById("c"); + var context = canvas.getContext("2d"); + var cat = new Image(); + cat.src = "%1"; + var z = 1; + cat.onload = function() { + context.mozImageSmoothingEnabled = false; + context.drawImage(cat, 0, 0, z*cat.width, z*cat.height); + }; + + var bbut = document.getElementById("baseline"); + bbut.onclick = function() { + cat.src = "%1"; + }; + + var rbut = document.getElementById("rendered"); + rbut.onclick = function() { + cat.src = "%2"; + }; + + var cbut = document.getElementById("compared"); + cbut.onclick = function() { + cat.src = "%3"; + }; + + function setZoom(zoom) + { + z = zoom; + canvas.width = z*800; + canvas.height = z*800; + context.mozImageSmoothingEnabled = false; + context.drawImage(cat, 0, 0, z*cat.width, z*cat.height); + } + + var z1but = document.getElementById("z1"); + z1but.onclick = function() { + setZoom(1); + }; + + var z2but = document.getElementById("z2"); + z2but.onclick = function() { + setZoom(2); + }; + + var z4but = document.getElementById("z4"); + z4but.onclick = function() { + setZoom(4); + }; +</script> |