diff options
Diffstat (limited to 'pw_perf_test/public/pw_perf_test/perf_test.h')
-rw-r--r-- | pw_perf_test/public/pw_perf_test/perf_test.h | 141 |
1 files changed, 3 insertions, 138 deletions
diff --git a/pw_perf_test/public/pw_perf_test/perf_test.h b/pw_perf_test/public/pw_perf_test/perf_test.h index e092087f9..90efb0cb0 100644 --- a/pw_perf_test/public/pw_perf_test/perf_test.h +++ b/pw_perf_test/public/pw_perf_test/perf_test.h @@ -13,13 +13,9 @@ // the License. #pragma once -#include <cstdint> -#include <limits> - -#include "pw_assert/assert.h" #include "pw_perf_test/event_handler.h" -#include "pw_perf_test/internal/duration_unit.h" -#include "pw_perf_test/internal/timer.h" +#include "pw_perf_test/internal/test_info.h" +#include "pw_perf_test/state.h" #include "pw_preprocessor/arguments.h" #define PW_PERF_TEST(name, function, ...) \ @@ -42,137 +38,6 @@ namespace pw::perf_test { -class State; - -namespace internal { - -class TestInfo; - -// Allows access to the private State object constructor -State CreateState(int durations, - EventHandler& event_handler, - const char* test_name); - -class Framework { - public: - constexpr Framework() - : event_handler_(nullptr), - tests_(nullptr), - run_info_{.total_tests = 0, .default_iterations = kDefaultIterations} {} - - static Framework& Get() { return framework_; } - - void RegisterEventHandler(EventHandler& event_handler) { - event_handler_ = &event_handler; - } - - void RegisterTest(TestInfo&); - - int RunAllTests(); - - private: - static constexpr int kDefaultIterations = 10; - - EventHandler* event_handler_; - - // Pointer to the list of tests - TestInfo* tests_; - - TestRunInfo run_info_; - - static Framework framework_; -}; - -class TestInfo { - public: - TestInfo(const char* test_name, void (*function_body)(State&)) - : run_(function_body), test_name_(test_name) { - // Once a TestInfo object is created by the macro, this adds itself to the - // list of registered tests - Framework::Get().RegisterTest(*this); - } - - // Returns the next registered test - TestInfo* next() const { return next_; } - - void SetNext(TestInfo* next) { next_ = next; } - - void Run(State& state) const { run_(state); } - - const char* test_name() const { return test_name_; } - - private: - // Function pointer to the code that will be measured - void (*run_)(State&); - - // Intrusively linked list, this acts as a pointer to the next test - TestInfo* next_ = nullptr; - - const char* test_name_; -}; - -} // namespace internal - -class State { - public: - // KeepRunning() should be called in a while loop. Responsible for managing - // iterations and timestamps. - bool KeepRunning(); - - private: - // Allows the framework to create state objects and unit tests for the state - // class - friend State internal::CreateState(int durations, - EventHandler& event_handler, - const char* test_name); - - // Privated constructor to prevent unauthorized instances of the state class. - constexpr State(int iterations, - EventHandler& event_handler, - const char* test_name) - : mean_(-1), - test_iterations_(iterations), - total_duration_(0), - min_(std::numeric_limits<int64_t>::max()), - max_(std::numeric_limits<int64_t>::min()), - iteration_start_(), - current_iteration_(-1), - event_handler_(&event_handler), - test_info{.name = test_name} { - PW_ASSERT(test_iterations_ > 0); - } - // Set public after deciding how exactly to set user-defined iterations - void SetIterations(int iterations) { - PW_ASSERT(current_iteration_ == -1); - test_iterations_ = iterations; - PW_ASSERT(test_iterations_ > 0); - } - - int64_t mean_; - - // Stores the total number of iterations wanted - int test_iterations_; - - // Stores the total duration of the tests. - int64_t total_duration_; - - // Smallest value of the iterations - int64_t min_; - - // Largest value of the iterations - int64_t max_; - - // Time at the start of the iteration - internal::Timestamp iteration_start_; - - // The current iteration - int current_iteration_; - - EventHandler* event_handler_; - - TestCase test_info; -}; - -void RunAllTests(pw::perf_test::EventHandler& handler); +void RunAllTests(EventHandler& handler); } // namespace pw::perf_test |