From eedfeabfba1bbbc26792966238463ca3d22665a9 Mon Sep 17 00:00:00 2001 From: aavit Date: Thu, 18 Nov 2010 12:44:27 +0100 Subject: Fix black- and whitelisting of individual items --- tests/arthur/baselineserver/src/baselineserver.cpp | 75 +++++++--------------- tests/arthur/baselineserver/src/baselineserver.h | 5 +- tests/arthur/baselineserver/src/htmlpage.cpp | 42 +++++------- tests/arthur/baselineserver/src/htmlpage.h | 4 +- 4 files changed, 41 insertions(+), 85 deletions(-) diff --git a/tests/arthur/baselineserver/src/baselineserver.cpp b/tests/arthur/baselineserver/src/baselineserver.cpp index eb756fc..3f4ae95 100644 --- a/tests/arthur/baselineserver/src/baselineserver.cpp +++ b/tests/arthur/baselineserver/src/baselineserver.cpp @@ -54,6 +54,7 @@ QString BaselineServer::storage; + BaselineServer::BaselineServer(QObject *parent) : QTcpServer(parent) { @@ -221,9 +222,9 @@ void BaselineHandler::provideBaselineChecksums(const QByteArray &itemListBlock) } // Find and mark blacklisted items + QString context = pathForItem(itemList.at(0), true, false).section(QLC('/'), 0, -2); if (itemList.count() > 0) { - QString prefix = pathForItem(itemList.at(0), true).section(QLC('/'), 0, -2); - QFile file(prefix + QLS("/.blacklist")); + QFile file(BaselineServer::storagePath() + QLC('/') + context + QLS("/BLACKLIST")); if (file.open(QIODevice::ReadOnly)) { QTextStream in(&file); do { @@ -242,7 +243,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, proto.socket.peerAddress().toString(), itemList); + report.start(BaselineServer::storagePath(), runId, plat, context, itemList); } @@ -406,61 +407,29 @@ QString BaselineHandler::updateSingleBaseline(const QString &oldBaseline, const return res; } -QString BaselineHandler::blacklistTest(const QString &scriptName, const QString &host, const QString &engine, - const QString &format) +QString BaselineHandler::blacklistTest(const QString &context, const QString &itemId, bool removeFromBlacklist) { -#if 0 - QString configFile(BaselineServer::storagePath() + host + QLC('/') - + itemSubPath(engine, format) + QLS(".blacklist")); - QFile file(configFile); - if (file.open(QIODevice::Append)) { - QTextStream out(&file); - out << scriptName << endl; - return QLS("Blacklisted ") + scriptName; + QFile file(BaselineServer::storagePath() + QLC('/') + context + QLS("/BLACKLIST")); + QStringList blackList; + if (file.open(QIODevice::ReadWrite)) { + while (!file.atEnd()) + blackList.append(file.readLine().trimmed()); + + if (removeFromBlacklist) + blackList.removeAll(itemId); + else if (!blackList.contains(itemId)) + blackList.append(itemId); + + file.resize(0); + foreach (QString id, blackList) + file.write(id.toLatin1() + '\n'); + file.close(); + return QLS(removeFromBlacklist ? "Whitelisted " : "Blacklisted ") + itemId + QLS(" in context ") + context; } else { - return QLS("Unable to update blacklisted tests."); + return QLS("Unable to update blacklisted tests, failed to open ") + file.fileName(); } -#else - return QString(); -#endif } -QString BaselineHandler::whitelistTest(const QString &scriptName, const QString &host, const QString &engine, - const QString &format) -{ -#if 0 - QString configFile(BaselineServer::storagePath() + host + QLC('/') - + itemSubPath(engine, format) + QLS(".blacklist")); - QFile file(configFile); - QStringList tests; - if (file.open(QIODevice::ReadOnly)) { - QTextStream in(&file); - do { - tests << in.readLine(); - } while (!in.atEnd()); - if (tests.count() != 0) { - QMutableStringListIterator it(tests); - while (it.hasNext()) { - it.next(); - if (it.value() == scriptName) - it.remove(); - } - } - file.close(); - if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - QTextStream out(&file); - for (int i=0; i\n"; - out << "Update baseline
" -#if 0 - "Blacklist test" -#endif + + out << "

Replace baseline with rendered

" + << "

Blacklist this item

" << "\n"; - out << "\n\n"; + out << "\n\n"; QMutableVectorIterator it(imageItems); while (it.hasNext()) { @@ -162,13 +159,10 @@ void HTMLPage::end() for (int i=0; i" << imageItems.at(i).scriptName << "N/AN/AN/A"; if (imageItems.at(i).status == ImageItem::IgnoreItem) { - out << "Blacklisted
" - "Whitelist test"; + out << "Blacklisted " + << "Whitelist item"; } else { out << "Test passed"; } @@ -220,16 +214,12 @@ void HTMLPage::handleCGIQuery(const QString &query) cgiUrl.queryItemValue(QLS("format"))); } else if (command == QLS("blacklist")) { // blacklist a test - s << BaselineHandler::blacklistTest(cgiUrl.queryItemValue(QLS("scriptName")), - cgiUrl.queryItemValue(QLS("host")), - cgiUrl.queryItemValue(QLS("engine")), - cgiUrl.queryItemValue(QLS("format"))); + s << BaselineHandler::blacklistTest(cgiUrl.queryItemValue(QLS("context")), + cgiUrl.queryItemValue(QLS("itemId"))); } else if (command == QLS("whitelist")) { // whitelist a test - s << BaselineHandler::whitelistTest(cgiUrl.queryItemValue(QLS("scriptName")), - cgiUrl.queryItemValue(QLS("host")), - cgiUrl.queryItemValue(QLS("engine")), - cgiUrl.queryItemValue(QLS("format"))); + s << BaselineHandler::blacklistTest(cgiUrl.queryItemValue(QLS("context")), + cgiUrl.queryItemValue(QLS("itemId")), true); } else { s << "Unknown query:
" << query << "
"; } diff --git a/tests/arthur/baselineserver/src/htmlpage.h b/tests/arthur/baselineserver/src/htmlpage.h index bef6b55..fa4d1ed 100644 --- a/tests/arthur/baselineserver/src/htmlpage.h +++ b/tests/arthur/baselineserver/src/htmlpage.h @@ -51,7 +51,7 @@ public: HTMLPage(); ~HTMLPage(); - void start(const QString &storagePath, const QString &runId, const PlatformInfo pinfo, const QString &hostAddress, const ImageItemList &itemList); + 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 end(); QString filePath(); @@ -69,7 +69,7 @@ private: QTextStream out; QString id; PlatformInfo plat; - QString address; + QString ctx; ImageItemList imageItems; bool headerWritten; }; -- cgit v0.12