From 9fb0cac961f70d1937c5fa3eafeaee1385c89768 Mon Sep 17 00:00:00 2001 From: Anthony Barbier Date: Fri, 20 Apr 2018 15:46:21 +0100 Subject: COMPMID-1081: Introduced test-wide instruments Change-Id: I5831241f3fc503717cc51136453c2bf96d4b420b Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/128484 Tested-by: Jenkins Reviewed-by: Georgios Pinitas --- tests/framework/Framework.cpp | 4 +++ tests/framework/Profiler.cpp | 27 +++++++++++++++-- tests/framework/Profiler.h | 22 ++++++++++++-- tests/framework/instruments/Instrument.h | 51 +++++++++++++++++++++++++++----- 4 files changed, 93 insertions(+), 11 deletions(-) (limited to 'tests/framework') diff --git a/tests/framework/Framework.cpp b/tests/framework/Framework.cpp index 3091b6677b..238b5ab2c0 100644 --- a/tests/framework/Framework.cpp +++ b/tests/framework/Framework.cpp @@ -288,6 +288,8 @@ void Framework::run_test(const TestInfo &info, TestCaseFactory &test_factory) try { + profiler.test_start(); + test_case->do_setup(); for(int i = 0; i < _num_iterations; ++i) @@ -312,6 +314,8 @@ void Framework::run_test(const TestInfo &info, TestCaseFactory &test_factory) test_case->do_teardown(); + profiler.test_stop(); + // Change status to success if no error has happend if(result.status == TestResult::Status::NOT_RUN) { diff --git a/tests/framework/Profiler.cpp b/tests/framework/Profiler.cpp index 646c66556c..69ea527a80 100644 --- a/tests/framework/Profiler.cpp +++ b/tests/framework/Profiler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -37,6 +37,14 @@ void Profiler::add(std::unique_ptr instrument) _instruments.emplace_back(std::move(instrument)); } +void Profiler::test_start() +{ + for(auto &instrument : _instruments) + { + instrument->test_start(); + } +} + void Profiler::start() { for(auto &instrument : _instruments) @@ -51,7 +59,6 @@ void Profiler::stop() { instrument->stop(); } - for(const auto &instrument : _instruments) { for(const auto &measurement : instrument->measurements()) @@ -61,6 +68,22 @@ void Profiler::stop() } } +void Profiler::test_stop() +{ + for(auto &instrument : _instruments) + { + instrument->test_stop(); + } + + for(const auto &instrument : _instruments) + { + for(const auto &measurement : instrument->test_measurements()) + { + _measurements[instrument->id() + "/" + measurement.first].push_back(measurement.second); + } + } +} + const Profiler::MeasurementsMap &Profiler::measurements() const { return _measurements; diff --git a/tests/framework/Profiler.h b/tests/framework/Profiler.h index 62a3dee92e..34c5224528 100644 --- a/tests/framework/Profiler.h +++ b/tests/framework/Profiler.h @@ -57,12 +57,30 @@ public: */ void add(std::unique_ptr instrument); - /** Start all added instruments to measure performance. */ + /** Call test_start() on all the added instruments + * + * Called before the test set up starts + */ + void test_start(); + + /** Call start() on all the added instruments + * + * Called just before the run of the test starts + */ void start(); - /** Stop all added instruments. */ + /** Call stop() on all the added instruments + * + * Called just after the run of the test ends + */ void stop(); + /** Call test_stop() on all the added instruments + * + * Called after the test teardown ended + */ + void test_stop(); + /** Return measurements for all instruments. * * @return measurements for all instruments. diff --git a/tests/framework/instruments/Instrument.h b/tests/framework/instruments/Instrument.h index 0df53f4210..ae4644b200 100644 --- a/tests/framework/instruments/Instrument.h +++ b/tests/framework/instruments/Instrument.h @@ -74,20 +74,57 @@ public: /** Identifier for the instrument */ virtual std::string id() const = 0; - /** Start measuring. */ - virtual void start() = 0; + /** Start of the test + * + * Called before the test set up starts + */ + virtual void test_start() + { + } + + /** Start measuring. + * + * Called just before the run of the test starts + */ + virtual void start() + { + } - /** Stop measuring. */ - virtual void stop() = 0; + /** Stop measuring. + * + * Called just after the run of the test ends + */ + virtual void stop() + { + } + /** End of the test + * + * Called after the test teardown ended + */ + virtual void test_stop() + { + } /** Map of measurements */ using MeasurementsMap = std::map; - /** Return the latest measurement. + /** Return the latest measurements. + * + * @return the latest measurements. + */ + virtual MeasurementsMap measurements() const + { + return MeasurementsMap(); + } + + /** Return the latest test measurements. * - * @return the latest measurement. + * @return the latest test measurements. */ - virtual MeasurementsMap measurements() const = 0; + virtual MeasurementsMap test_measurements() const + { + return MeasurementsMap(); + } protected: std::string _unit{}; -- cgit v1.2.1