[render-test] Add tolerance to file-size tests

This commit is contained in:
Thiago Marcos P. Santos
2019-10-13 17:49:49 +03:00
parent 2187980a87
commit 8b3a222c81
9 changed files with 27 additions and 16 deletions

View File

@@ -31,12 +31,20 @@ struct TestPaths {
}
};
inline std::tuple<bool, float> checkValue(float expected, float actual, float tolerance) {
float delta = expected * tolerance;
assert(delta >= 0.0f);
return std::make_tuple(std::abs(expected - actual) <= delta, delta);
}
struct FileSizeProbe {
FileSizeProbe() = default;
FileSizeProbe(std::string path_, uintmax_t size_) : path(std::move(path_)), size(size_) {}
FileSizeProbe(std::string path_, uintmax_t size_, float tolerance_)
: path(std::move(path_)), size(size_), tolerance(tolerance_) {}
std::string path;
uintmax_t size;
float tolerance;
};
struct MemoryProbe {

View File

@@ -478,7 +478,7 @@ TestMetrics readExpectedMetrics(const mbgl::filesystem::path& path) {
result.fileSize.emplace(std::piecewise_construct,
std::forward_as_tuple(std::move(mark)),
std::forward_as_tuple(std::move(filePath), probeValue[2].GetUint64()));
std::forward_as_tuple(std::move(filePath), probeValue[2].GetUint64(), 0.f));
}
}

View File

@@ -258,7 +258,8 @@ bool TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
return false;
}
if (actual->second.size != expected.second.size) {
auto result = checkValue(expected.second.size, actual->second.size, actual->second.tolerance);
if (!std::get<bool>(result)) {
std::stringstream ss;
ss << "File size does not match at probe \"" << expected.first << "\": " << actual->second.size
<< ", expected is " << expected.second.size << ".";
@@ -574,14 +575,16 @@ bool TestRunner::runOperations(const std::string& key, TestMetadata& metadata) {
}
} else if (operationArray[0].GetString() == fileSizeProbeOp) {
// probeFileSize
assert(operationArray.Size() >= 3u);
assert(operationArray.Size() >= 4u);
assert(operationArray[1].IsString());
assert(operationArray[2].IsString());
assert(operationArray[3].IsNumber());
std::string mark = std::string(operationArray[1].GetString(), operationArray[1].GetStringLength());
std::string path = std::string(operationArray[2].GetString(), operationArray[2].GetStringLength());
assert(!path.empty());
float tolerance = operationArray[3].GetDouble();
mbgl::filesystem::path filePath(path);
if (!filePath.is_absolute()) {
@@ -592,7 +595,7 @@ bool TestRunner::runOperations(const std::string& key, TestMetadata& metadata) {
auto size = mbgl::filesystem::file_size(filePath);
metadata.metrics.fileSize.emplace(std::piecewise_construct,
std::forward_as_tuple(std::move(mark)),
std::forward_as_tuple(std::move(path), size));
std::forward_as_tuple(std::move(path), size, tolerance));
} else {
metadata.errorMessage = std::string("File not found: ") + path;
return false;

View File

@@ -3,8 +3,8 @@
"metadata": {
"test": {
"operations": [
["probeFileSize", "style", "style.json"],
["probeFileSize", "image", "expected.png"]
["probeFileSize", "style", "style.json", 0],
["probeFileSize", "image", "expected.png", 0]
],
"width": 64,
"height": 64

View File

@@ -3,8 +3,8 @@
"metadata": {
"test": {
"operations": [
["probeFileSize", "style", "style.aaaa"],
["probeFileSize", "image", "expected.bbb"]
["probeFileSize", "style", "style.aaaa", 0],
["probeFileSize", "image", "expected.bbb", 0]
],
"width": 64,
"height": 64

View File

@@ -3,8 +3,8 @@
"metadata": {
"test": {
"operations": [
["probeFileSize", "style", "style.json"],
["probeFileSize", "image", "expected.png"]
["probeFileSize", "style", "style.json", 0],
["probeFileSize", "image", "expected.png", 0]
],
"width": 64,
"height": 64

View File

@@ -3,8 +3,8 @@
"metadata": {
"test": {
"operations": [
["probeFileSize", "style", "style.json"],
["probeFileSize", "image", "expected.png"]
["probeFileSize", "style", "style.json", 0],
["probeFileSize", "image", "expected.png", 0]
],
"width": 64,
"height": 64

View File

@@ -8,7 +8,7 @@
[
"style",
"style.json",
510
516
]
]
}

View File

@@ -3,8 +3,8 @@
"metadata": {
"test": {
"operations": [
["probeFileSize", "style", "style.json"],
["probeFileSize", "image", "expected.png"]
["probeFileSize", "style", "style.json", 0],
["probeFileSize", "image", "expected.png", 0]
],
"width": 64,
"height": 64