diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index 6bec890af4..7efc24c3e6 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -19,6 +19,7 @@ #include "perf_trace.h" #if EFI_UNIT_TEST +extern int timeNowUs; extern bool verboseMode; #endif /* EFI_UNIT_TEST */ @@ -144,7 +145,10 @@ int EventQueue::executeAll(efitime_t now) { // near future - spin wait for the event to happen and avoid the // overhead of rescheduling the timer. - while (current->momentX > getTimeNowNt()) ; + // yes, that's a busy wait but that's what we need here + while (current->momentX > getTimeNowNt()) { + UNIT_TEST_BUSY_WAIT_CALLBACK(); + } executionCounter++; diff --git a/firmware/global.h b/firmware/global.h index 1cb7054642..177a4c62c2 100644 --- a/firmware/global.h +++ b/firmware/global.h @@ -109,6 +109,8 @@ typedef unsigned int time_t; */ #define NT2US(nt) ((nt) / US_TO_NT_MULTIPLIER) +#define UNIT_TEST_BUSY_WAIT_CALLBACK() {} + #ifdef __cplusplus extern "C" { diff --git a/simulator/simulator/global.h b/simulator/simulator/global.h index 5836aeaaf8..3a0601f721 100644 --- a/simulator/simulator/global.h +++ b/simulator/simulator/global.h @@ -56,6 +56,8 @@ extern BaseChannel serialAdapterInstance; +#define UNIT_TEST_BUSY_WAIT_CALLBACK() {} + #ifdef __cplusplus extern "C" { diff --git a/unit_tests/global.h b/unit_tests/global.h index 656b214d5a..9a1cca1025 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -100,3 +100,5 @@ void print(const char *fmt, ...); #define lockAnyContext() false #define unlockAnyContext() {} + +#define UNIT_TEST_BUSY_WAIT_CALLBACK() { timeNowUs++; } diff --git a/unit_tests/tests/test_signal_executor.cpp b/unit_tests/tests/test_signal_executor.cpp index ae2d3cbe60..212f62ecba 100644 --- a/unit_tests/tests/test_signal_executor.cpp +++ b/unit_tests/tests/test_signal_executor.cpp @@ -38,8 +38,7 @@ static void complexCallback(TestPwm *testPwm) { { complexCallback, testPwm }); } -static void testSignalExecutor2(void) { - print("*************************************** testSignalExecutor2\r\n"); +TEST(misc, testSignalExecutor2) { EventQueue eq; TestPwm p1(&eq); TestPwm p2(&eq); @@ -85,7 +84,6 @@ TEST(misc, testSignalExecutor3) { eq.insertTask(&s1, 10, { orderCallback, (void*)1 }); eq.insertTask(&s2, 11, { orderCallback, (void*)2 }); eq.insertTask(&s3, 12, { orderCallback, (void*)3 }); - eq.executeAll(100); } @@ -160,5 +158,4 @@ TEST(misc, testSignalExecutor) { eq.executeAll(11); ASSERT_EQ(2, callbackCounter); - testSignalExecutor2(); }