diff options
Diffstat (limited to 'tests/arthur/baselineserver/src/baselineserver.cpp')
-rw-r--r-- | tests/arthur/baselineserver/src/baselineserver.cpp | 73 |
1 files changed, 56 insertions, 17 deletions
diff --git a/tests/arthur/baselineserver/src/baselineserver.cpp b/tests/arthur/baselineserver/src/baselineserver.cpp index f59600f..64b50fd 100644 --- a/tests/arthur/baselineserver/src/baselineserver.cpp +++ b/tests/arthur/baselineserver/src/baselineserver.cpp @@ -55,6 +55,11 @@ QString BaselineServer::storage; +// extra fields, for use in image metadata storage +const QString PI_ImageChecksum(QLS("ImageChecksum")); +const QString PI_RunId(QLS("RunId")); +const QString PI_CreationDate(QLS("CreationDate")); + BaselineServer::BaselineServer(QObject *parent) : QTcpServer(parent) @@ -220,16 +225,17 @@ void BaselineHandler::provideBaselineChecksums(const QByteArray &itemListBlock) for (ImageItemList::iterator i = itemList.begin(); i != itemList.end(); ++i) { i->imageChecksums.clear(); + i->status = ImageItem::BaselineNotFound; QString prefix = pathForItem(*i, true); - QFile file(prefix + QLS("metadata")); - if (file.open(QIODevice::ReadOnly)) { - QDataStream checkSums(&file); - checkSums >> i->imageChecksums; - file.close(); - i->status = ImageItem::Ok; + PlatformInfo itemData = fetchItemMetadata(prefix); + if (itemData.contains(PI_ImageChecksum)) { + bool ok = false; + quint64 checksum = itemData.value(PI_ImageChecksum).toULongLong(&ok, 16); + if (ok) { + i->imageChecksums.prepend(checksum); + i->status = ImageItem::Ok; + } } - if (!i->imageChecksums.count()) - i->status = ImageItem::BaselineNotFound; } // Find and mark blacklisted items @@ -280,18 +286,51 @@ void BaselineHandler::storeImage(const QByteArray &itemBlock, bool isBaseline) cwd.mkpath(dir); item.image.save(prefix + QLS(FileFormat), FileFormat); - //# Could use QSettings or XML or even DB, could use common file for whole dir or even whole storage - but for now, keep it simple - QFile file(prefix + QLS("metadata")); - file.open(QIODevice::WriteOnly | QIODevice::Truncate); - QDataStream checkSums(&file); - checkSums << item.imageChecksums; - file.close(); + PlatformInfo itemData = plat; + itemData.insert(PI_ImageChecksum, QString::number(item.imageChecksums.at(0), 16)); //# Only the first is stored. TBD: get rid of list + itemData.insert(PI_RunId, runId); + itemData.insert(PI_CreationDate, QDateTime::currentDateTime().toString()); + storeItemMetadata(itemData, prefix); if (!isBaseline) report.addMismatch(item); } +void BaselineHandler::storeItemMetadata(const PlatformInfo &metadata, const QString &path) +{ + QFile file(path + QLS(MetadataFileExt)); + if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + qWarning() << runId << logtime() << "ERROR: could not write to file" << file.fileName(); + return; + } + QTextStream out(&file); + PlatformInfo::const_iterator it = metadata.constBegin(); + while (it != metadata.constEnd()) { + out << it.key() << ": " << it.value() << endl; + ++it; + } + file.close(); +} + + +PlatformInfo BaselineHandler::fetchItemMetadata(const QString &path) +{ + PlatformInfo res; + QFile file(path + QLS(MetadataFileExt)); + if (!file.open(QIODevice::ReadOnly)) + return res; + QTextStream in(&file); + do { + QString line = in.readLine(); + int idx = line.indexOf(QLS(": ")); + if (idx > 0) + res.insert(line.left(idx), line.mid(idx+2)); + } while (!in.atEnd()); + return res; +} + + void BaselineHandler::receiveDisconnect() { qDebug() << runId << logtime() << "Client disconnected."; @@ -371,7 +410,7 @@ QString BaselineHandler::clearAllBaselines(const QString &context) int tot = 0; int failed = 0; QDirIterator it(BaselineServer::storagePath() + QLC('/') + context, - QStringList() << QLS("*.png") << QLS("*.metadata")); + QStringList() << QLS("*.") + QLS(FileFormat) << QLS("*.") + QLS(MetadataFileExt)); while (it.hasNext()) { tot++; if (!QFile::remove(it.next())) @@ -389,10 +428,10 @@ QString BaselineHandler::updateSingleBaseline(const QString &oldBaseline, const QProcess proc; proc.setProcessChannelMode(QProcess::MergedChannels); - proc.start(QLS("cp"), QStringList() << QLS("-f") << srcBase + QLS("png") << srcBase + QLS("metadata") << dstDir); + proc.start(QLS("cp"), QStringList() << QLS("-f") << srcBase + QLS(FileFormat) << srcBase + QLS(MetadataFileExt) << dstDir); proc.waitForFinished(); if (proc.exitCode() == 0) - res = QString("Successfully updated '%1'").arg(oldBaseline + QLS("/metadata")); + res = QString("Successfully updated '%1'").arg(oldBaseline); else res = QString("Error updating baseline: %1<br>" "Command output: <pre>%2</pre>").arg(proc.errorString(), proc.readAll().constData()); |