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; }