From d0a84cb7d9866d4d46141ef2735697de3302d50b Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Sun, 25 Aug 2019 19:55:21 +0300 Subject: [test runner] Introduce probe_memory_.. API for render tests --- render-test/metadata.hpp | 14 ++++++++++++++ render-test/runner.cpp | 28 ++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/render-test/metadata.hpp b/render-test/metadata.hpp index 98e208fe54..308c9074f0 100644 --- a/render-test/metadata.hpp +++ b/render-test/metadata.hpp @@ -7,6 +7,8 @@ #include "filesystem.hpp" +#include + struct TestStatistics { TestStatistics() = default; @@ -27,6 +29,16 @@ struct TestPaths { } }; +struct MemoryProbe { + MemoryProbe() = default; + MemoryProbe(size_t size_, size_t allocations_) + : size(size_) + , allocations(allocations_) {} + + size_t size; + size_t allocations; +}; + struct TestMetadata { TestMetadata() = default; @@ -59,4 +71,6 @@ struct TestMetadata { std::string errorMessage; double difference = 0.0; + + std::map memoryProbes; }; \ No newline at end of file diff --git a/render-test/runner.cpp b/render-test/runner.cpp index 192978ffa5..5424eaa447 100644 --- a/render-test/runner.cpp +++ b/render-test/runner.cpp @@ -18,6 +18,7 @@ #include +#include "allocation_index.hpp" #include "metadata.hpp" #include "parser.hpp" #include "runner.hpp" @@ -25,7 +26,7 @@ #include #include #include - +#include // static const std::string& TestRunner::getBasePath() { @@ -155,6 +156,9 @@ 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 memoryProbeOp("probeMemory"); + static const std::string memoryProbeStartOp("probeMemoryStart"); + static const std::string memoryProbeEndOp("probeMemoryEnd"); // wait if (operationArray[0].GetString() == waitOp) { @@ -392,7 +396,25 @@ bool TestRunner::runOperations(const std::string& key, TestMetadata& metadata) { const mbgl::JSValue* propertyValue = &operationArray[3]; layer->setLayoutProperty(propertyName, propertyValue); } - + // probeMemoryStart + } else if (operationArray[0].GetString() == memoryProbeStartOp) { + assert(!AllocationIndex::isActive()); + AllocationIndex::setActive(true); + // probeMemory + } else if (operationArray[0].GetString() == memoryProbeOp) { + assert(AllocationIndex::isActive()); + assert(operationArray.Size() >= 2u); + assert(operationArray[1].IsString()); + std::string mark = std::string(operationArray[1].GetString(), operationArray[1].GetStringLength()); + + metadata.memoryProbes.emplace(std::piecewise_construct, + std::forward_as_tuple(std::move(mark)), + std::forward_as_tuple(AllocationIndex::getAllocatedSize(), AllocationIndex::getAllocationsCount())); + // probeMemoryEnd + } else if (operationArray[0].GetString() == memoryProbeEndOp) { + assert(AllocationIndex::isActive()); + AllocationIndex::setActive(false); + AllocationIndex::reset(); } else { metadata.errorMessage = std::string("Unsupported operation: ") + operationArray[0].GetString(); return false; @@ -414,6 +436,8 @@ TestRunner::Impl::Impl(const TestMetadata& metadata) mbgl::ResourceOptions().withCacheOnlyRequestsSupport(false)) {} bool TestRunner::run(TestMetadata& metadata) { + AllocationIndex::setActive(false); + AllocationIndex::reset(); std::string key = mbgl::util::toString(uint32_t(metadata.mapMode)) + "/" + mbgl::util::toString(metadata.pixelRatio) + "/" + mbgl::util::toString(uint32_t(metadata.crossSourceCollisions)); -- cgit v1.2.1