COMPMID-1081: Introduced test-wide instruments

Change-Id: I5831241f3fc503717cc51136453c2bf96d4b420b
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/128484
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
diff --git a/tests/framework/Framework.cpp b/tests/framework/Framework.cpp
index 3091b66..238b5ab 100644
--- a/tests/framework/Framework.cpp
+++ b/tests/framework/Framework.cpp
@@ -288,6 +288,8 @@
 
         try
         {
+            profiler.test_start();
+
             test_case->do_setup();
 
             for(int i = 0; i < _num_iterations; ++i)
@@ -312,6 +314,8 @@
 
             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 646c665..69ea527 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 @@
     _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 @@
     {
         instrument->stop();
     }
-
     for(const auto &instrument : _instruments)
     {
         for(const auto &measurement : instrument->measurements())
@@ -61,6 +68,22 @@
     }
 }
 
+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 62a3dee..34c5224 100644
--- a/tests/framework/Profiler.h
+++ b/tests/framework/Profiler.h
@@ -57,12 +57,30 @@
      */
     void add(std::unique_ptr<Instrument> 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 0df53f4..ae4644b 100644
--- a/tests/framework/instruments/Instrument.h
+++ b/tests/framework/instruments/Instrument.h
@@ -74,20 +74,57 @@
     /** 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()
+    {
+    }
 
-    /** Stop measuring. */
-    virtual void stop() = 0;
+    /** Start measuring.
+     *
+     * Called just before the run of the test starts
+     */
+    virtual void start()
+    {
+    }
 
+    /** 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<std::string, Measurement>;
 
-    /** Return the latest measurement.
+    /** Return the latest measurements.
      *
-     * @return the latest measurement.
+     * @return the latest measurements.
      */
-    virtual MeasurementsMap measurements() const = 0;
+    virtual MeasurementsMap measurements() const
+    {
+        return MeasurementsMap();
+    }
+
+    /** Return the latest test measurements.
+     *
+     * @return the latest test measurements.
+     */
+    virtual MeasurementsMap test_measurements() const
+    {
+        return MeasurementsMap();
+    }
 
 protected:
     std::string _unit{};