diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2019-10-09 16:12:02 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2019-10-10 19:54:51 +0300 |
commit | a9f06f3b527601fc0d7a1c254af414e7a313eef0 (patch) | |
tree | 6948a3dbc0553f18566c90c7c04d300896d80d73 /render-test/runner.cpp | |
parent | 026e15fe3d6dae0c3f11775d19dcfc13743ff1c0 (diff) | |
download | qtlocation-mapboxgl-a9f06f3b527601fc0d7a1c254af414e7a313eef0.tar.gz |
[render-test] Add instruction for verifying file size
For a given absolute or relative path, measure the size of the file.
This is useful for measuring if the cache has increased as expected
after moving a camera or decreased after cleaning up.
In a more hackish manner, could be used for collecting binary size
statistics of shared libraries.
Diffstat (limited to 'render-test/runner.cpp')
-rw-r--r-- | render-test/runner.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/render-test/runner.cpp b/render-test/runner.cpp index 5df167431f..6b726a8eeb 100644 --- a/render-test/runner.cpp +++ b/render-test/runner.cpp @@ -242,6 +242,31 @@ bool TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage, break; } } + // Check file size metrics. + for (const auto& expected : metadata.expectedMetrics.fileSize) { + auto actual = metadata.metrics.fileSize.find(expected.first); + if (actual == metadata.metrics.fileSize.end()) { + metadata.errorMessage = "Failed to find fileSize probe: " + expected.first; + return false; + } + if (actual->second.path != expected.second.path) { + std::stringstream ss; + ss << "Comparing different files at probe \"" << expected.first << "\": " << actual->second.path + << ", expected is " << expected.second.path << "."; + metadata.errorMessage = ss.str(); + + return false; + } + + if (actual->second.size != expected.second.size) { + std::stringstream ss; + ss << "File size does not match at probe \"" << expected.first << "\": " << actual->second.size + << ", expected is " << expected.second.size << "."; + + metadata.errorMessage = ss.str(); + return false; + } + } // Check memory metrics. for (const auto& expected : metadata.expectedMetrics.memory) { auto actual = metadata.metrics.memory.find(expected.first); @@ -313,6 +338,7 @@ bool TestRunner::runOperations(const std::string& key, TestMetadata& metadata) { static const std::string removeSourceOp("removeSource"); static const std::string setPaintPropertyOp("setPaintProperty"); static const std::string setLayoutPropertyOp("setLayoutProperty"); + static const std::string fileSizeProbeOp("probeFileSize"); static const std::string memoryProbeOp("probeMemory"); static const std::string memoryProbeStartOp("probeMemoryStart"); static const std::string memoryProbeEndOp("probeMemoryEnd"); @@ -562,6 +588,29 @@ bool TestRunner::runOperations(const std::string& key, TestMetadata& metadata) { const mbgl::JSValue* propertyValue = &operationArray[3]; layer->setLayoutProperty(propertyName, propertyValue); } + // probeFileSize + } else if (operationArray[0].GetString() == fileSizeProbeOp) { + assert(operationArray.Size() >= 3u); + assert(operationArray[1].IsString()); + assert(operationArray[2].IsString()); + + std::string mark = std::string(operationArray[1].GetString(), operationArray[1].GetStringLength()); + mbgl::filesystem::path path = std::string(operationArray[2].GetString(), operationArray[2].GetStringLength()); + assert(!path.empty()); + + if (!path.is_absolute()) { + path = metadata.paths.defaultExpectations() / path; + } + + if (mbgl::filesystem::exists(path)) { + auto size = mbgl::filesystem::file_size(path); + metadata.metrics.fileSize.emplace(std::piecewise_construct, + std::forward_as_tuple(std::move(mark)), + std::forward_as_tuple(std::move(path), size)); + } else { + metadata.errorMessage = std::string("File not found: ") + path.string(); + return false; + } // probeMemoryStart } else if (operationArray[0].GetString() == memoryProbeStartOp) { assert(!AllocationIndex::isActive()); |