From 426f714c04f563c892f35e0f5dfd97137dc977d9 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Thu, 12 Dec 2019 09:34:35 +0200 Subject: [test runner] Introduce TestOperation --- render-test/runner.cpp | 25 ++++++++++++++++--------- render-test/runner.hpp | 2 ++ 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'render-test') diff --git a/render-test/runner.cpp b/render-test/runner.cpp index bd4af20e21..4037d42e45 100644 --- a/render-test/runner.cpp +++ b/render-test/runner.cpp @@ -1245,7 +1245,8 @@ bool TestRunner::run(TestMetadata& metadata) { } } -using InjectedProbeMap = std::map>; +using InjectedProbeMap = std::map; + bool runInjectedProbe(const std::set& probes, TestContext& ctx, const InjectedProbeMap& probeMap) { for (const auto& probe : probes) { auto it = probeMap.find(probe); @@ -1253,23 +1254,24 @@ bool runInjectedProbe(const std::set& probes, TestContext& ctx, con ctx.getMetadata().errorMessage = std::string("Unsupported operation: ") + probe; return false; } - it->second(ctx); + if (!it->second(ctx)) return false; } return true; } bool TestRunner::runInjectedProbesBegin(TestContext& ctx) { - const std::string mark = " - default - start"; + static const std::string mark = " - default - start"; static const InjectedProbeMap beginInjectedProbeMap = { {// Injected memory probe begin memoryProbeOp, - [&mark](TestContext& ctx) { + [](TestContext& ctx) { assert(!AllocationIndex::isActive()); AllocationIndex::setActive(true); ctx.getMetadata().metrics.memory.emplace(std::piecewise_construct, std::forward_as_tuple(memoryProbeOp + mark), std::forward_as_tuple(AllocationIndex::getAllocatedSizePeak(), AllocationIndex::getAllocationsCount())); + return true; }}, {// Injected gfx probe begin gfxProbeOp, @@ -1277,27 +1279,29 @@ bool TestRunner::runInjectedProbesBegin(TestContext& ctx) { assert(!ctx.gfxProbeActive); ctx.gfxProbeActive = true; ctx.baselineGfxProbe = ctx.activeGfxProbe; + return true; }}, {// Injected network probe begin networkProbeOp, - [&mark](TestContext& ctx) { + [](TestContext& ctx) { assert(!ProxyFileSource::isTrackingActive()); ProxyFileSource::setTrackingActive(true); ctx.getMetadata().metrics.network.emplace( std::piecewise_construct, std::forward_as_tuple(networkProbeOp + mark), std::forward_as_tuple(ProxyFileSource::getRequestCount(), ProxyFileSource::getTransferredSize())); + return true; }}}; return runInjectedProbe(manifest.getProbes(), ctx, beginInjectedProbeMap); } bool TestRunner::runInjectedProbesEnd(TestContext& ctx, mbgl::gfx::RenderingStats stats) { - const std::string mark = " - default - end"; + static const std::string mark = " - default - end"; static const InjectedProbeMap endInjectedProbeMap = { {// Injected memory probe end memoryProbeOp, - [&mark](TestContext& ctx) { + [](TestContext& ctx) { assert(AllocationIndex::isActive()); auto emplaced = ctx.getMetadata().metrics.memory.emplace( std::piecewise_construct, @@ -1309,10 +1313,11 @@ bool TestRunner::runInjectedProbesEnd(TestContext& ctx, mbgl::gfx::RenderingStat emplaced.first->second.tolerance = 0.2f; AllocationIndex::setActive(false); AllocationIndex::reset(); + return true; }}, {// Injected gfx probe end gfxProbeOp, - [&mark, &stats](TestContext& ctx) { + [&stats](TestContext& ctx) { assert(ctx.gfxProbeActive); ctx.activeGfxProbe = GfxProbe(stats, ctx.activeGfxProbe); @@ -1324,16 +1329,18 @@ bool TestRunner::runInjectedProbesEnd(TestContext& ctx, mbgl::gfx::RenderingStat ctx.getMetadata().metrics.gfx.insert({gfxProbeOp + mark, metricProbe}); ctx.gfxProbeActive = false; + return true; }}, {// Injected network probe end networkProbeOp, - [&mark](TestContext& ctx) { + [](TestContext& ctx) { assert(ProxyFileSource::isTrackingActive()); ctx.getMetadata().metrics.network.emplace( std::piecewise_construct, std::forward_as_tuple(networkProbeOp + mark), std::forward_as_tuple(ProxyFileSource::getRequestCount(), ProxyFileSource::getTransferredSize())); ProxyFileSource::setTrackingActive(false); + return true; }}}; return runInjectedProbe(manifest.getProbes(), ctx, endInjectedProbeMap); diff --git a/render-test/runner.hpp b/render-test/runner.hpp index d278d90ec4..7076cdfd78 100644 --- a/render-test/runner.hpp +++ b/render-test/runner.hpp @@ -26,6 +26,8 @@ protected: virtual ~TestContext() = default; }; +using TestOperation = std::function; + class TestRunner { public: enum class UpdateResults { NO, DEFAULT, PLATFORM, METRICS, REBASELINE }; -- cgit v1.2.1