From 4527b7694ae2f16fc53c3560f118eb5c76db2290 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 31 Jul 2020 14:41:29 -0700 Subject: [PATCH 1/2] expose the problem --- firmware/controllers/system/timer/event_queue.cpp | 13 +++++++++++++ unit_tests/global_execution_queue.cpp | 5 +++++ unit_tests/global_execution_queue.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index c69397c532..7275fc8d77 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -209,5 +209,18 @@ scheduling_s *EventQueue::getElementAtIndexForUnitText(int index) { } void EventQueue::clear(void) { + // Flush the queue, resetting all scheduling_s as though we'd executed them + while(head) { + auto x = head; + // link next element to head + head = x->nextScheduling_s; + + // Reset this element + x->momentX = 0; + x->isScheduled = false; + x->nextScheduling_s = nullptr; + x->action = {}; + } + head = nullptr; } diff --git a/unit_tests/global_execution_queue.cpp b/unit_tests/global_execution_queue.cpp index 3b8ca5bd4e..38b24fb964 100644 --- a/unit_tests/global_execution_queue.cpp +++ b/unit_tests/global_execution_queue.cpp @@ -10,6 +10,11 @@ bool_t debugSignalExecutor = false; extern bool verboseMode; +TestExecutor::~TestExecutor() { + // Flush the queue and reset all scheduling_s at the end of a test's execution + clear(); +} + void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) { if (debugSignalExecutor) { printf("scheduleTask %d\r\n", delayUs); diff --git a/unit_tests/global_execution_queue.h b/unit_tests/global_execution_queue.h index f52cf0875a..8d7d0e3fc7 100644 --- a/unit_tests/global_execution_queue.h +++ b/unit_tests/global_execution_queue.h @@ -12,6 +12,8 @@ class TestExecutor : public ExecutorInterface { public: + ~TestExecutor(); + void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override; void scheduleByTimestampNt(scheduling_s *scheduling, efitick_t timeNt, action_s action) override; void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) override; From 244378aba181230a524497e1feb2b190516a4da6 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 31 Jul 2020 14:41:42 -0700 Subject: [PATCH 2/2] fix the problem --- firmware/controllers/engine_cycle/map_averaging.cpp | 2 +- firmware/controllers/engine_cycle/rpm_calculator.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/firmware/controllers/engine_cycle/map_averaging.cpp b/firmware/controllers/engine_cycle/map_averaging.cpp index e7eac6a6fe..6f2657e977 100644 --- a/firmware/controllers/engine_cycle/map_averaging.cpp +++ b/firmware/controllers/engine_cycle/map_averaging.cpp @@ -350,11 +350,11 @@ float getMap(void) { void initMapAveraging(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { logger = sharedLogger; +#if !EFI_UNIT_TEST #if EFI_SHAFT_POSITION_INPUT addTriggerEventListener(&mapAveragingTriggerCallback, "MAP averaging", engine); #endif /* EFI_SHAFT_POSITION_INPUT */ -#if !EFI_UNIT_TEST addConsoleAction("faststat", showMapStats); #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index a1283626f4..094e80fb1f 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -358,7 +358,9 @@ void initRpmCalculator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { return; } +#if !EFI_UNIT_TEST addTriggerEventListener(tdcMarkCallback, "chart TDC mark", engine); +#endif addTriggerEventListener(rpmShaftPositionCallback, "rpm reporter", engine); }