diff options
author | Trond Kjernåsen <trond.kjernasen@nokia.com> | 2010-09-30 15:11:09 (GMT) |
---|---|---|
committer | Trond Kjernåsen <trond.kjernasen@nokia.com> | 2010-09-30 15:11:09 (GMT) |
commit | 72b1a614748add429f301ea156760fafc01a5128 (patch) | |
tree | 65f167d610d73c7670e25ce957631dcaee64f249 /tests/arthur/baselineserver/src/baselineserver.cpp | |
parent | e1bdeb521fa1c53a8039fec77fad80994b394413 (diff) | |
download | Qt-72b1a614748add429f301ea156760fafc01a5128.zip Qt-72b1a614748add429f301ea156760fafc01a5128.tar.gz Qt-72b1a614748add429f301ea156760fafc01a5128.tar.bz2 |
Added support for updating the baselines via the generated HTML reports.
The baselineserver can now run as a CGI binary if it detects that
the QUERY_STRING variable is set. Currently it only handles
commands for updating the baselines for failed tests.
For this to work properly the baselineserver binary needs to have
the setuid bit set, so that when it's run as a CGI binary, it will have
the proper rights to move files around. The server currently
assumes the CGI binary is a link to the baselineserver executable
named 'server.cgi' in the configured 'cgi-bin' directory.
Diffstat (limited to 'tests/arthur/baselineserver/src/baselineserver.cpp')
-rw-r--r-- | tests/arthur/baselineserver/src/baselineserver.cpp | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/tests/arthur/baselineserver/src/baselineserver.cpp b/tests/arthur/baselineserver/src/baselineserver.cpp index c25bfc4..41e48eb 100644 --- a/tests/arthur/baselineserver/src/baselineserver.cpp +++ b/tests/arthur/baselineserver/src/baselineserver.cpp @@ -6,6 +6,7 @@ #include <QFileInfo> #include <QHostInfo> #include <QTextStream> +#include <QProcess> QString BaselineServer::storage; @@ -29,6 +30,13 @@ QString BaselineServer::storagePath() return storage; } +QString BaselineServer::baseUrl() +{ + return QLS("http://") + + QHostInfo::localHostName().toLatin1() + '.' + + QHostInfo::localDomainName().toLatin1() + '/'; +} + void BaselineServer::incomingConnection(int socketDescriptor) { qDebug() << "Server: New connection!"; @@ -190,9 +198,7 @@ void BaselineHandler::storeImage(const QByteArray &itemBlock, bool isBaseline) QByteArray msg(isBaseline ? "New baseline image stored: " : "Mismatch report: " ); - msg += "http://" - + QHostInfo::localHostName().toLatin1() + '.' - + QHostInfo::localDomainName().toLatin1() + '/'; + msg += BaselineServer::baseUrl(); if (isBaseline) msg += pathForItem(item, true, false).toLatin1() + FileFormat; else @@ -243,6 +249,64 @@ 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 basePath(BaselineServer::storagePath()); + QString srcDir(basePath + host + QLC('/') + + QString(QLS("mismatches_%1_%2/")).arg(engine, format) + + id); + QString dstDir(basePath + host + QLC('/') + + QString(QLS("baselines_%1_%2/")).arg(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(); + } + + 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; +} + +QString BaselineHandler::updateSingleBaseline(const QString &oldBaseline, const QString &newBaseline) +{ + QString res; + QString basePath(BaselineServer::storagePath()); + QString srcBase(basePath + newBaseline.left(newBaseline.length() - 3)); + QString dstDir(basePath + oldBaseline.left(oldBaseline.lastIndexOf(QLC('/')))); + + QProcess proc; + proc.setProcessChannelMode(QProcess::MergedChannels); + proc.start(QLS("cp"), QStringList() << QLS("-f") << srcBase + QLS("png") << srcBase + QLS("metadata") << dstDir); + proc.waitForFinished(); + if (proc.exitCode() == 0) + res = QString("Successfully updated '%1'").arg(oldBaseline + QLS("/metadata")); + else + res = QString("Error updating baseline: %1<br>" + "Command output: <pre>%2</pre>").arg(proc.errorString(), proc.readAll().constData()); + + return res; +} + void BaselineHandler::testPathMapping() { qDebug() << "Storage prefix:" << BaselineServer::storagePath(); |