xref: /aosp_15_r20/external/pigweed/pw_perf_test/public/pw_perf_test/internal/test_info.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2023 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 "pw_perf_test/state.h"
17 
18 namespace pw::perf_test::internal {
19 
20 /// Represents a single test case.
21 ///
22 /// Each instance includes a pointer to a function which constructs and runs the
23 /// test class. These are statically allocated instead of the test classes, as
24 /// test classes can be very large.
25 ///
26 /// This class mimics pw::unit_test::TestInfo.
27 class TestInfo {
28  public:
29   TestInfo(const char* test_name, void (*function_body)(State&));
30 
31   // Returns the next registered test
next()32   TestInfo* next() const { return next_; }
33 
SetNext(TestInfo * next)34   void SetNext(TestInfo* next) { next_ = next; }
35 
Run(State & state)36   void Run(State& state) const { run_(state); }
37 
test_name()38   const char* test_name() const { return test_name_; }
39 
40  private:
41   // Function pointer to the code that will be measured
42   void (*run_)(State&);
43 
44   // Intrusively linked list, this acts as a pointer to the next test
45   TestInfo* next_ = nullptr;
46 
47   const char* test_name_;
48 };
49 
50 }  // namespace pw::perf_test::internal
51