From 23fc152e6ffc38452810680f12990e568836534d Mon Sep 17 00:00:00 2001 From: Madeline Busig Date: Thu, 12 Sep 2024 15:18:15 -0700 Subject: [PATCH] Add ability to start/stop test timer at specific points This timer is expected to be global, so this would make paralellizing tests difficult. However, because the main target of this project (the GBA) does not support parallelization, this is not a concern at the moment. --- include/mtl/test.hpp | 45 ++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/include/mtl/test.hpp b/include/mtl/test.hpp index abd83b4..8f0c588 100644 --- a/include/mtl/test.hpp +++ b/include/mtl/test.hpp @@ -39,6 +39,36 @@ public: m_test_names.push_back(name); } + static void reset_timer() { +#ifdef __GBA__ + REG_TM2D = UINT16_MAX; + // We must enable and disable the timer to write UINT16_MAX + // to the timer register + REG_TM2CNT = TM_ENABLE; + REG_TM2CNT &= ~TM_ENABLE; +#endif + } + + static void start_timer() { +#ifdef __GBA__ + REG_TM2D = 0; + REG_TM2CNT = TM_ENABLE; +#endif + } + + static void end_timer() { +#ifdef __GBA__ + REG_TM2CNT &= ~TM_ENABLE; +#endif + } + + static uint16_t query_timer() { +#ifdef __GBA__ + return REG_TM2D; +#endif + return UINT16_MAX; + } + static bool run_tests() { log::info << "=========================" << endl; log::info << "Running suite \"" << instance().name() << '\"' << endl; @@ -53,19 +83,10 @@ public: log::info << "Running \"" << name << "\"..." << endl; - uint16_t time = 0; + reset_timer(); + bool result = test(); -#ifdef __GBA__ - REG_TM2D = 0; - REG_TM2CNT = TM_ENABLE; -#endif - bool result = (test)(); -#ifdef __GBA__ - time = REG_TM2D; - REG_TM2CNT = ~TM_ENABLE; -#endif - - log::info << (result ? "OK" : "FAILED") << ", TIME: " << time << endl; + log::info << (result ? "OK" : "FAILED") << ", TIME: " << query_timer() << endl; if (result) { ++num_ok; } else { ++num_fail; }