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/event_handler.h" 17 18 namespace pw::perf_test::internal { 19 20 // Forward declaration. 21 class TestInfo; 22 23 /// Singleton that manages and runs performance tests. 24 /// 25 /// This class mimics pw::unit_test::Framework. 26 class Framework { 27 public: Framework()28 constexpr Framework() 29 : event_handler_(nullptr), 30 tests_(nullptr), 31 run_info_{.total_tests = 0, .default_iterations = kDefaultIterations} {} 32 Get()33 static Framework& Get() { return framework_; } 34 RegisterEventHandler(EventHandler & event_handler)35 void RegisterEventHandler(EventHandler& event_handler) { 36 event_handler_ = &event_handler; 37 } 38 39 void RegisterTest(TestInfo&); 40 41 int RunAllTests(); 42 43 private: 44 static constexpr int kDefaultIterations = 10; 45 46 EventHandler* event_handler_; 47 48 // Pointer to the list of tests 49 TestInfo* tests_; 50 51 TestRunInfo run_info_; 52 53 // Singleton 54 static Framework framework_; 55 }; 56 57 } // namespace pw::perf_test::internal 58