xref: /aosp_15_r20/external/pigweed/pw_perf_test/public/pw_perf_test/event_handler.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2022 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15 
16 #include <cstdint>
17 
18 namespace pw::perf_test {
19 
20 /// Data reported on completion of an iteration.
21 struct TestIteration {
22   uint32_t number = 0;
23   float result = 0;
24 };
25 
26 /// Data reported for each `Measurement` upon completion of a performance test.
27 struct TestMeasurement {
28   float mean = 0;
29   float max = 0;
30   float min = 0;
31 };
32 
33 /// Stores information on the upcoming collection of tests.
34 ///
35 /// In order to match gtest, these integer types are not sized
36 struct TestRunInfo {
37   int total_tests = 0;
38   int default_iterations = 0;
39 };
40 
41 /// Describes the performance test being run.
42 struct TestCase {
43   const char* name = nullptr;
44 };
45 
46 /// Collects and reports test results.
47 ///
48 /// Both the state and the framework classes use these functions to report what
49 /// happens at each stage.
50 class EventHandler {
51  public:
52   virtual ~EventHandler() = default;
53 
54   /// A performance test is starting.
55   virtual void RunAllTestsStart(const TestRunInfo& test_run_info) = 0;
56 
57   /// A performance test has ended.
58   virtual void RunAllTestsEnd() = 0;
59 
60   /// A performance test case is starting.
61   virtual void TestCaseStart(const TestCase& test_case) = 0;
62 
63   /// A performance test case has completed an iteration.
64   virtual void TestCaseIteration(const TestIteration& test_iteration) = 0;
65 
66   /// A performance test case has produced a `Measurement`.
67   virtual void TestCaseMeasure(const TestMeasurement& test_measurement) = 0;
68 
69   /// A performance test case has ended.
70   virtual void TestCaseEnd(const TestCase& test_case) = 0;
71 };
72 
73 }  // namespace pw::perf_test
74