diff options
20 files changed, 945 insertions, 390 deletions
diff --git a/tests/arthur/baselineserver/src/baselineserver.cpp b/tests/arthur/baselineserver/src/baselineserver.cpp index 0399224..6351dff 100644 --- a/tests/arthur/baselineserver/src/baselineserver.cpp +++ b/tests/arthur/baselineserver/src/baselineserver.cpp @@ -97,6 +97,8 @@ 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 @@ -143,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; } @@ -206,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(); @@ -230,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; } } @@ -245,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); } @@ -256,7 +265,7 @@ 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 dir = prefix.section(QLC('/'), 0, -2); QDir cwd; @@ -272,19 +281,15 @@ 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); + report.addMismatch(item); - QByteArray msg(isBaseline ? "New baseline image stored: " : - "Mismatch report: " ); - msg += BaselineServer::baseUrl(); + QString msg; if (isBaseline) - msg += pathForItem(item, true, false).toLatin1() + FileFormat; + msg = QLS("New baseline image stored: ") + pathForItem(item, true, true) + QLS(FileFormat); else - msg += report.filePath(); + msg = BaselineServer::baseUrl() + report.filePath(); - proto.sendBlock(BaselineProtocol::Ack, msg); + proto.sendBlock(BaselineProtocol::Ack, msg.toLatin1()); } @@ -296,7 +301,7 @@ void BaselineHandler::receiveDisconnect() } -void BaselineHandler::mapPlatformInfo() +void BaselineHandler::mapPlatformInfo() const { mapped = plat; @@ -326,22 +331,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); @@ -353,6 +359,14 @@ QString BaselineHandler::pathForItem(const ImageItem &item, bool isBaseline, boo } +QString BaselineHandler::view(const QString &baseline, const QString &rendered, const QString &compared) +{ + QFile f(":/templates/view.html"); + f.open(QIODevice::ReadOnly); + return QString::fromLatin1(f.readAll()).arg('/'+baseline, '/'+rendered, '/'+compared); +} + + QString BaselineHandler::clearAllBaselines(const QString &context) { int tot = 0; @@ -387,6 +401,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")); @@ -429,11 +444,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 c5cb45e..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,7 +99,10 @@ class BaselineHandler : public QObject public: BaselineHandler(int socketDescriptor = -1); void testPathMapping(); + QString pathForItem(const ImageItem &item, bool isBaseline = true, bool absolute = true) const; + // 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); @@ -109,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 9659505..0000000 --- a/tests/arthur/baselineserver/src/htmlpage.cpp +++ /dev/null @@ -1,239 +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; - reportDir = pinfo.value(PI_PulseGitBranch).isEmpty() ? QLS("reports/adhoc/") : QLS("reports/pulse/"); - QString dir = root + reportDir; - QDir cwd; - if (!cwd.exists(dir)) - cwd.mkpath(dir); -} - - -void HTMLPage::writeHeader(const ImageItem &item) -{ - path = reportDir + 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 << "<p><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></p>\n\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 << "<p><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> (diffs are <span style=\"color:red\">RED</span>)</td>\n" - "<td><b>Info/Action</b></td>\n" - "</b></tr><br>"; -} - - -void HTMLPage::writeFooter() -{ - out << "</table></p>\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=\"/" << generateThumbnail(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; -} - - -QString HTMLPage::generateThumbnail(const QString &image) -{ - QString res = image; - QFileInfo imgFI(root+image); - res.chop(imgFI.suffix().length() + 1); - res += QLS("_thumbnail.jpg"); - QFileInfo resFI(root+res); - if (resFI.exists() && resFI.lastModified() > imgFI.lastModified()) - return res; - QStringList args; - args << root+image << QLS("-resize") << QLS("240x240") << QLS("-quality") << QLS("50") << root+res; - QProcess::execute(QLS("convert"), 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("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/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 5f1e051..0df613a 100644 --- a/tests/arthur/baselineserver/src/htmlpage.h +++ b/tests/arthur/baselineserver/src/report.h @@ -38,42 +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; - QString path; + const BaselineHandler *handler; + QString runId; + PlatformInfo plat; + QString rootDir; QString reportDir; - QFile file; + QString path; + 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> diff --git a/tests/arthur/common/baselineprotocol.cpp b/tests/arthur/common/baselineprotocol.cpp index 5ed58b4..e4445bd 100644 --- a/tests/arthur/common/baselineprotocol.cpp +++ b/tests/arthur/common/baselineprotocol.cpp @@ -48,6 +48,7 @@ #include <QFileInfo> #include <QDir> #include <QTime> +#include <QPointer> #ifndef QMAKESPEC #define QMAKESPEC "Unknown" @@ -128,11 +129,10 @@ PlatformInfo::PlatformInfo(bool useLocal) ImageItem &ImageItem::operator=(const ImageItem &other) { - scriptName = other.scriptName; - scriptChecksum = other.scriptChecksum; + testFunction = other.testFunction; + itemName = other.itemName; + itemChecksum = other.itemChecksum; status = other.status; - renderFormat = other.renderFormat; - engine = other.engine; image = other.image; imageChecksums = other.imageChecksums; return *this; @@ -165,6 +165,7 @@ quint64 ImageItem::computeChecksum(const QImage &image) return (quint64(h1) << 32) | h2; } +#if 0 QString ImageItem::engineAsString() const { switch (engine) { @@ -205,6 +206,7 @@ QString ImageItem::formatAsString() const return QLS("UnknownFormat"); return QLS(formatNames[renderFormat]); } +#endif void ImageItem::writeImageToStream(QDataStream &out) const { @@ -249,24 +251,24 @@ void ImageItem::readImageFromStream(QDataStream &in) QDataStream & operator<< (QDataStream &stream, const ImageItem &ii) { - stream << ii.scriptName << ii.scriptChecksum << quint8(ii.status) << quint8(ii.renderFormat) - << quint8(ii.engine) << ii.imageChecksums; + stream << ii.testFunction << ii.itemName << ii.itemChecksum << quint8(ii.status) << ii.imageChecksums; ii.writeImageToStream(stream); return stream; } QDataStream & operator>> (QDataStream &stream, ImageItem &ii) { - quint8 encFormat, encStatus, encEngine; - stream >> ii.scriptName >> ii.scriptChecksum >> encStatus >> encFormat - >> encEngine >> ii.imageChecksums; - ii.renderFormat = QImage::Format(encFormat); + quint8 encStatus; + stream >> ii.testFunction >> ii.itemName >> ii.itemChecksum >> encStatus >> ii.imageChecksums; ii.status = ImageItem::ItemStatus(encStatus); - ii.engine = ImageItem::GraphicsEngine(encEngine); ii.readImageFromStream(stream); return stream; } +BaselineProtocol::BaselineProtocol() +{ +} + BaselineProtocol::~BaselineProtocol() { socket.close(); @@ -275,7 +277,7 @@ BaselineProtocol::~BaselineProtocol() } -bool BaselineProtocol::connect(bool *dryrun) +bool BaselineProtocol::connect(const QString &testCase, bool *dryrun) { errMsg.clear(); QByteArray serverName(qgetenv("QT_LANCELOT_SERVER")); @@ -292,6 +294,7 @@ bool BaselineProtocol::connect(bool *dryrun) } PlatformInfo pi(true); + pi.insert(PI_TestCase, testCase); QByteArray block; QDataStream ds(&block, QIODevice::ReadWrite); ds << pi; @@ -342,11 +345,15 @@ bool BaselineProtocol::acceptConnection(PlatformInfo *pi) } -bool BaselineProtocol::requestBaselineChecksums(ImageItemList *itemList) +bool BaselineProtocol::requestBaselineChecksums(const QString &testFunction, ImageItemList *itemList) { errMsg.clear(); if (!itemList) return false; + + for(ImageItemList::iterator it = itemList->begin(); it != itemList->end(); it++) + it->testFunction = testFunction; + QByteArray block; QDataStream ds(&block, QIODevice::ReadWrite); ds << *itemList; diff --git a/tests/arthur/common/baselineprotocol.h b/tests/arthur/common/baselineprotocol.h index baffb4a..2315bc3 100644 --- a/tests/arthur/common/baselineprotocol.h +++ b/tests/arthur/common/baselineprotocol.h @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef BASELINEPROTOCOL_H #define BASELINEPROTOCOL_H @@ -46,12 +47,14 @@ #include <QImage> #include <QVector> #include <QMap> +#include <QPointer> #define QLS QLatin1String #define QLC QLatin1Char #define FileFormat "png" +const QString PI_TestCase(QLS("TestCase")); const QString PI_HostName(QLS("HostName")); const QString PI_HostAddress(QLS("HostAddress")); const QString PI_OSName(QLS("OSName")); @@ -73,39 +76,32 @@ struct ImageItem { public: ImageItem() - : status(Ok), renderFormat(QImage::Format_Invalid), engine(Raster), scriptChecksum(0) + : status(Ok), itemChecksum(0) {} ImageItem(const ImageItem &other) { *this = other; } ~ImageItem() {} ImageItem &operator=(const ImageItem &other); - static quint64 computeChecksum(const QImage& image); - QString engineAsString() const; - QString formatAsString() const; - void writeImageToStream(QDataStream &stream) const; - void readImageFromStream(QDataStream &stream); + static quint64 computeChecksum(const QImage& image); enum ItemStatus { Ok = 0, BaselineNotFound = 1, - IgnoreItem = 2 - }; - - enum GraphicsEngine { - Raster = 0, - OpenGL = 1 + IgnoreItem = 2, + Mismatch = 3 }; - QString scriptName; + QString testFunction; + QString itemName; ItemStatus status; - QImage::Format renderFormat; - GraphicsEngine engine; QImage image; QList<quint64> imageChecksums; - // tbd: add diffscore - quint16 scriptChecksum; + quint16 itemChecksum; + + void writeImageToStream(QDataStream &stream) const; + void readImageFromStream(QDataStream &stream); }; QDataStream & operator<< (QDataStream &stream, const ImageItem &ii); QDataStream & operator>> (QDataStream &stream, ImageItem& ii); @@ -114,17 +110,20 @@ Q_DECLARE_METATYPE(ImageItem); typedef QVector<ImageItem> ImageItemList; + class BaselineProtocol { public: - BaselineProtocol() {} + BaselineProtocol(); ~BaselineProtocol(); + static BaselineProtocol *instance(QObject *parent = 0); + // **************************************************** // Important constants here // **************************************************** enum Constant { - ProtocolVersion = 3, + ProtocolVersion = 4, ServerPort = 54129, Timeout = 5000 }; @@ -143,8 +142,10 @@ public: }; // For client: - bool connect(bool *dryrun = 0); - bool requestBaselineChecksums(ImageItemList *itemList); + + // For advanced client: + bool connect(const QString &testCase, bool *dryrun = 0); + bool requestBaselineChecksums(const QString &testFunction, ImageItemList *itemList); bool submitNewBaseline(const ImageItem &item, QByteArray *serverMsg); bool submitMismatch(const ImageItem &item, QByteArray *serverMsg); diff --git a/tests/arthur/common/baselineprotocol.pri b/tests/arthur/common/baselineprotocol.pri index 996f9d5..62e38a6 100644 --- a/tests/arthur/common/baselineprotocol.pri +++ b/tests/arthur/common/baselineprotocol.pri @@ -1,4 +1,5 @@ INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD QT *= network diff --git a/tests/arthur/common/qbaselinetest.cpp b/tests/arthur/common/qbaselinetest.cpp new file mode 100644 index 0000000..e95b510 --- /dev/null +++ b/tests/arthur/common/qbaselinetest.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** 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 "qbaselinetest.h" +#include "baselineprotocol.h" + +namespace QBaselineTest { + +bool connected = false; +bool triedConnecting = false; +BaselineProtocol proto; + + +bool checkImage(const QImage& img, const char *name, quint16 checksum, QByteArray *msg, bool *error) +{ + QByteArray itemName; + bool hasName = qstrlen(name); + const char *tag = QTest::currentDataTag(); + if (qstrlen(tag)) { + itemName = tag; + if (hasName) + itemName.append('_').append(name); + } else { + itemName = hasName ? name : "default_name"; + } + + *msg = "Baseline check of image '" + itemName + "': "; + + if (!triedConnecting) { + triedConnecting = true; + if (!proto.connect(QTest::testObject()->metaObject()->className())) { + *msg += "Failed to connect to baseline server: " + proto.errorMessage().toLatin1(); + *error = true; + return true; + } + connected = true; + } + if (!connected) { + *msg = "Not connected to baseline server."; + *error = true; + return true; + } + + ImageItem item; + item.itemName = QLatin1String(itemName); + item.itemChecksum = checksum; + item.testFunction = QLatin1String(QTest::currentTestFunction()); + ImageItemList list; + list.append(item); + if (!proto.requestBaselineChecksums(QLatin1String(QTest::currentTestFunction()), &list) || list.isEmpty()) { + *msg = "Communication with baseline server failed: " + proto.errorMessage().toLatin1(); + *error = true; + return true; + } + item.image = img; + item.imageChecksums.prepend(ImageItem::computeChecksum(img)); + QByteArray srvMsg; + switch (list.at(0).status) { + case ImageItem::IgnoreItem : + qDebug() << msg->constData() << "Ignored, blacklisted on server."; + return true; + break; + case ImageItem::BaselineNotFound: + if (proto.submitNewBaseline(item, &srvMsg)) + qDebug() << msg->constData() << "Baseline not found on server. New baseline uploaded."; + else + qDebug() << msg->constData() << "Baseline not found on server. Uploading of new baseline failed:" << srvMsg; + return true; + break; + case ImageItem::Ok: + break; + default: + qWarning() << "Unexpected reply from baseline server."; + return true; + break; + } + *error = false; + // The actual comparison of the given image with the baseline: + if (list.at(0).imageChecksums.contains(item.imageChecksums.at(0))) + return true; + proto.submitMismatch(item, &srvMsg); + *msg += "Mismatch. See report:\n " + srvMsg; + return false; +} + +} diff --git a/tests/arthur/common/qbaselinetest.h b/tests/arthur/common/qbaselinetest.h new file mode 100644 index 0000000..3445c72 --- /dev/null +++ b/tests/arthur/common/qbaselinetest.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef BASELINETEST_H +#define BASELINETEST_H + +#include <QTest> + +namespace QBaselineTest { +bool checkImage(const QImage& img, const char *name, quint16 checksum, QByteArray *msg, bool *error); +} + +#define QBASELINE_CHECK_SUM(image, name, checksum)\ +do {\ + QByteArray _msg;\ + bool _err = false;\ + if (!QBaselineTest::checkImage((image), (name), (checksum), &_msg, &_err)) {\ + QFAIL(_msg.constData());\ + } else if (_err) {\ + QSKIP(_msg.constData(), SkipSingle);\ + }\ +} while (0) + +#define QBASELINE_CHECK(image, name) QBASELINE_CHECK_SUM(image, name, 0) + +#endif // BASELINETEST_H diff --git a/tests/arthur/common/qbaselinetest.pri b/tests/arthur/common/qbaselinetest.pri new file mode 100644 index 0000000..5420c6e --- /dev/null +++ b/tests/arthur/common/qbaselinetest.pri @@ -0,0 +1,13 @@ +QT *= testlib + +SOURCES += \ + $$PWD/qbaselinetest.cpp + +HEADERS += \ + $$PWD/qbaselinetest.h + +win32|symbian*:MKSPEC=$$replace(QMAKESPEC, \\\\, /) +else:MKSPEC=$$QMAKESPEC +DEFINES += QMAKESPEC=\\\"$$MKSPEC\\\" + +include($$PWD/baselineprotocol.pri) diff --git a/tests/auto/baselineexample/baselineexample.pro b/tests/auto/baselineexample/baselineexample.pro new file mode 100644 index 0000000..30feecc --- /dev/null +++ b/tests/auto/baselineexample/baselineexample.pro @@ -0,0 +1,18 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-12-09T14:55:13 +# +#------------------------------------------------- + +QT += testlib + +TARGET = tst_baselineexample +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += tst_baselineexample.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" + +include($$QT_SOURCE_TREE/tests/arthur/common/qbaselinetest.pri) diff --git a/tests/auto/baselineexample/tst_baselineexample.cpp b/tests/auto/baselineexample/tst_baselineexample.cpp new file mode 100644 index 0000000..28cbec5 --- /dev/null +++ b/tests/auto/baselineexample/tst_baselineexample.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** 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 <qbaselinetest.h> +#include <QPushButton> + +class tst_BaselineExample : public QObject +{ + Q_OBJECT + +public: + tst_BaselineExample(); + +private Q_SLOTS: + void testBasicUsage(); + void testMultipleImages(); + void testDataDriven_data(); + void testDataDriven(); + void testDataDrivenMultiple_data(); + void testDataDrivenMultiple(); + void testChecksum_data(); + void testChecksum(); +}; + + +tst_BaselineExample::tst_BaselineExample() +{ +} + + +void tst_BaselineExample::testBasicUsage() +{ + // Generate an image: + QPushButton b("Press me!"); + b.resize(100, 50); + b.show(); + QTest::qWaitForWindowShown(&b); + QImage img1 = QPixmap::grabWidget(&b).toImage(); + QVERIFY(!img1.isNull()); + + // Compare it to baseline on server: + QBASELINE_CHECK(img1, "button"); +} + + +void tst_BaselineExample::testMultipleImages() +{ + QPushButton b("Press me!"); + b.resize(100, 50); + b.show(); + QTest::qWaitForWindowShown(&b); + QBASELINE_CHECK(QPixmap::grabWidget(&b).toImage(), "text1"); + + b.setText("Kick me!"); + QTest::qWait(50); + QBASELINE_CHECK(QPixmap::grabWidget(&b).toImage(), "text2"); +} + + +void tst_BaselineExample::testDataDriven_data() +{ + QTest::addColumn<QString>("label"); + QTest::newRow("short") << "Ok!"; + QTest::newRow("long") << "A really long button text that just does not seem to end"; + QTest::newRow("empty") << ""; +} + + +void tst_BaselineExample::testDataDriven() +{ + QFETCH(QString, label); + QPushButton b(label); + b.resize(100, 50); + b.show(); + QTest::qWaitForWindowShown(&b); + QBASELINE_CHECK(QPixmap::grabWidget(&b).toImage(), 0); +} + + +void tst_BaselineExample::testDataDrivenMultiple_data() +{ + testDataDriven_data(); +} + + +void tst_BaselineExample::testDataDrivenMultiple() +{ + QFETCH(QString, label); + QPushButton b(label); + b.resize(100, 50); + b.show(); + QTest::qWaitForWindowShown(&b); + QBASELINE_CHECK(QPixmap::grabWidget(&b).toImage(), "normal"); + + b.setText(label.prepend('&')); + QTest::qWait(50); + QBASELINE_CHECK(QPixmap::grabWidget(&b).toImage(), "shortcut"); +} + + +void tst_BaselineExample::testChecksum_data() +{ + testDataDriven_data(); +} + + +void tst_BaselineExample::testChecksum() +{ + QFETCH(QString, label); + QPushButton b(label); + b.resize(100, 50); + b.show(); + QTest::qWaitForWindowShown(&b); + QBASELINE_CHECK_SUM(QPixmap::grabWidget(&b).toImage(), 0, quint16(qHash(label))); +} + + +QTEST_MAIN(tst_BaselineExample); + +#include "tst_baselineexample.moc" diff --git a/tests/auto/lancelot/lancelot.pro b/tests/auto/lancelot/lancelot.pro index 4535b83..6d6edf8 100644 --- a/tests/auto/lancelot/lancelot.pro +++ b/tests/auto/lancelot/lancelot.pro @@ -7,9 +7,6 @@ SOURCES += tst_lancelot.cpp \ HEADERS += $$QT_SOURCE_TREE/tests/arthur/common/paintcommands.h RESOURCES += $$QT_SOURCE_TREE/tests/arthur/common/images.qrc -include($$QT_SOURCE_TREE/tests/arthur/common/baselineprotocol.pri) -win32|symbian*:MKSPEC=$$replace(QMAKESPEC, \\\\, /) -else:MKSPEC=$$QMAKESPEC -DEFINES += QMAKESPEC=\\\"$$MKSPEC\\\" +include($$QT_SOURCE_TREE/tests/arthur/common/qbaselinetest.pri) !symbian:!wince*:DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/lancelot/tst_lancelot.cpp b/tests/auto/lancelot/tst_lancelot.cpp index 7c6fe66..4bde927 100644 --- a/tests/auto/lancelot/tst_lancelot.cpp +++ b/tests/auto/lancelot/tst_lancelot.cpp @@ -66,10 +66,15 @@ public: static bool simfail; private: - ImageItem render(const ImageItem &item); + enum GraphicsEngine { + Raster = 0, + OpenGL = 1 + }; + + bool setupTestSuite(const QStringList& blacklist); + void runTestSuite(GraphicsEngine engine, QImage::Format format); + ImageItem render(const ImageItem &item, GraphicsEngine engine, QImage::Format format); void paint(QPaintDevice *device, const QStringList &script, const QString &filePath); - void runTestSuite(); - bool setupTestSuite(ImageItem::GraphicsEngine engine, QImage::Format format, const QStringList& blacklist); BaselineProtocol proto; ImageItemList baseList; @@ -108,7 +113,7 @@ void tst_Lancelot::initTestCase() #if defined(Q_OS_SOMEPLATFORM) QSKIP("This test is not supported on this platform.", SkipAll); #endif - if (!proto.connect(&dryRunMode)) + if (!proto.connect(QLatin1String("tst_Lancelot"), &dryRunMode)) QSKIP(qPrintable(proto.errorMessage()), SkipAll); QDir qpsDir(scriptsDir); @@ -125,8 +130,8 @@ void tst_Lancelot::initTestCase() file.open(QFile::ReadOnly); QByteArray cont = file.readAll(); scripts.insert(fileName, QString::fromLatin1(cont).split(QLatin1Char('\n'), QString::SkipEmptyParts)); - it->scriptName = fileName; - it->scriptChecksum = qChecksum(cont.constData(), cont.size()); + it->itemName = fileName; + it->itemChecksum = qChecksum(cont.constData(), cont.size()); it++; } } @@ -135,42 +140,42 @@ void tst_Lancelot::initTestCase() void tst_Lancelot::testRasterARGB32PM_data() { QStringList localBlacklist; - if (!setupTestSuite(ImageItem::Raster, QImage::Format_ARGB32_Premultiplied, localBlacklist)) + if (!setupTestSuite(localBlacklist)) QSKIP("Communication with baseline image server failed.", SkipAll); } void tst_Lancelot::testRasterARGB32PM() { - runTestSuite(); + runTestSuite(Raster, QImage::Format_ARGB32_Premultiplied); } void tst_Lancelot::testRasterRGB32_data() { QStringList localBlacklist; - if (!setupTestSuite(ImageItem::Raster, QImage::Format_RGB32, localBlacklist)) + if (!setupTestSuite(localBlacklist)) QSKIP("Communication with baseline image server failed.", SkipAll); } void tst_Lancelot::testRasterRGB32() { - runTestSuite(); + runTestSuite(Raster, QImage::Format_RGB32); } void tst_Lancelot::testRasterRGB16_data() { QStringList localBlacklist; - if (!setupTestSuite(ImageItem::Raster, QImage::Format_RGB16, localBlacklist)) + if (!setupTestSuite(localBlacklist)) QSKIP("Communication with baseline image server failed.", SkipAll); } void tst_Lancelot::testRasterRGB16() { - runTestSuite(); + runTestSuite(Raster, QImage::Format_RGB16); } @@ -178,7 +183,7 @@ void tst_Lancelot::testRasterRGB16() void tst_Lancelot::testOpenGL_data() { QStringList localBlacklist = QStringList() << QLatin1String("rasterops.qps"); - if (!setupTestSuite(ImageItem::OpenGL, QImage::Format_RGB32, localBlacklist)) + if (!setupTestSuite(localBlacklist)) QSKIP("Communication with baseline image server failed.", SkipAll); } @@ -197,45 +202,39 @@ void tst_Lancelot::testOpenGL() ok = true; } if (ok) - runTestSuite(); + runTestSuite(OpenGL, QImage::Format_RGB32); else QSKIP("System under test does not meet preconditions for GL testing. Skipping.", SkipAll); } #endif -bool tst_Lancelot::setupTestSuite(ImageItem::GraphicsEngine engine, QImage::Format format, const QStringList& blacklist) +bool tst_Lancelot::setupTestSuite(const QStringList& blacklist) { QTest::addColumn<ImageItem>("baseline"); ImageItemList itemList(baseList); - - for(ImageItemList::iterator it = itemList.begin(); it != itemList.end(); it++) { - it->engine = engine; - it->renderFormat = format; - } - - if (!proto.requestBaselineChecksums(&itemList)) { + if (!proto.requestBaselineChecksums(QTest::currentTestFunction(), &itemList)) { QWARN(qPrintable(proto.errorMessage())); return false; } foreach(const ImageItem& item, itemList) { - if (!blacklist.contains(item.scriptName)) - QTest::newRow(item.scriptName.toLatin1()) << item; + if (!blacklist.contains(item.itemName)) + QTest::newRow(item.itemName.toLatin1()) << item; } return true; } -void tst_Lancelot::runTestSuite() +void tst_Lancelot::runTestSuite(GraphicsEngine engine, QImage::Format format) { QFETCH(ImageItem, baseline); if (baseline.status == ImageItem::IgnoreItem) QSKIP("Blacklisted by baseline server.", SkipSingle); - ImageItem rendered = render(baseline); + ImageItem rendered = render(baseline, engine, format); if (rendered.image.isNull()) { // Assume an error in the test environment, not Qt QWARN("Error: Failed to render image."); QSKIP("Aborted due to errors.", SkipSingle); @@ -253,26 +252,26 @@ void tst_Lancelot::runTestSuite() if (dryRunMode) qDebug() << "Dryrun mode, ignoring detected mismatch." << serverMsg; else - QFAIL("Rendered image differs from baseline.\n" + serverMsg); + QFAIL("Rendered image differs from baseline. Report:\n " + serverMsg); } } -ImageItem tst_Lancelot::render(const ImageItem &item) +ImageItem tst_Lancelot::render(const ImageItem &item, GraphicsEngine engine, QImage::Format format) { ImageItem res = item; res.imageChecksums.clear(); res.image = QImage(); - QString filePath = scriptsDir + item.scriptName; - QStringList script = scripts.value(item.scriptName); + QString filePath = scriptsDir + item.itemName; + QStringList script = scripts.value(item.itemName); - if (item.engine == ImageItem::Raster) { - QImage img(800, 800, item.renderFormat); + if (engine == Raster) { + QImage img(800, 800, format); paint(&img, script, QFileInfo(filePath).absoluteFilePath()); // eh yuck (filePath stuff) res.image = img; res.imageChecksums.append(ImageItem::computeChecksum(img)); #ifndef QT_NO_OPENGL - } else if (item.engine == ImageItem::OpenGL) { + } else if (engine == OpenGL) { QGLWidget glWidget; if (glWidget.isValid()) { glWidget.makeCurrent(); @@ -281,7 +280,7 @@ ImageItem tst_Lancelot::render(const ImageItem &item) fboFormat.setAttachment(QGLFramebufferObject::CombinedDepthStencil); QGLFramebufferObject fbo(800, 800, fboFormat); paint(&fbo, script, QFileInfo(filePath).absoluteFilePath()); // eh yuck (filePath stuff) - res.image = fbo.toImage().convertToFormat(item.renderFormat); + res.image = fbo.toImage().convertToFormat(format); res.imageChecksums.append(ImageItem::computeChecksum(res.image)); } #endif diff --git a/tests/auto/other.pro b/tests/auto/other.pro index d1a7a86..512cd25 100644 --- a/tests/auto/other.pro +++ b/tests/auto/other.pro @@ -4,6 +4,7 @@ TEMPLATE=subdirs SUBDIRS=\ # exceptionsafety_objects \ shouldn't enable it +# baselineexample \ Just an example demonstrating qbaselinetest usage lancelot \ qaccessibility \ qalgorithms \ |