xref: /aosp_15_r20/external/pigweed/pw_perf_test/framework.cc (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 
15 #include "pw_perf_test/internal/framework.h"
16 
17 #include "pw_perf_test/internal/test_info.h"
18 #include "pw_perf_test/internal/timer.h"
19 
20 namespace pw::perf_test::internal {
21 
22 Framework Framework::framework_;
23 
RunAllTests()24 int Framework::RunAllTests() {
25   if (!internal::TimerPrepare()) {
26     return false;
27   }
28 
29   event_handler_->RunAllTestsStart(run_info_);
30 
31   for (const TestInfo* test = tests_; test != nullptr; test = test->next()) {
32     State test_state = internal::CreateState(
33         kDefaultIterations, *event_handler_, test->test_name());
34     test->Run(test_state);
35   }
36   internal::TimerCleanup();
37   event_handler_->RunAllTestsEnd();
38   return true;
39 }
40 
RegisterTest(TestInfo & new_test)41 void Framework::RegisterTest(TestInfo& new_test) {
42   ++run_info_.total_tests;
43   if (tests_ == nullptr) {
44     tests_ = &new_test;
45     return;
46   }
47   TestInfo* info = tests_;
48   for (; info->next() != nullptr; info = info->next()) {
49   }
50   info->SetNext(&new_test);
51 }
52 
53 }  // namespace pw::perf_test::internal
54