From 311fca839e8f1ea42751769139d0c22477a045dc Mon Sep 17 00:00:00 2001 From: Robert Hargreaves Date: Sat, 30 Mar 2024 16:43:40 +0000 Subject: [PATCH] Test scheduler handler calls in isolation Move scheduler handler registrations to main.c (for now) --- src/main.c | 15 ++++++++ src/scheduler.c | 7 ---- tests/unit/main.c | 6 ++- tests/unit/test_scheduler.c | 75 ++++++++++++++++++++++++++++++++----- 4 files changed, 85 insertions(+), 18 deletions(-) diff --git a/src/main.c b/src/main.c index d86e3850..489bb0f6 100644 --- a/src/main.c +++ b/src/main.c @@ -7,13 +7,28 @@ #include "scheduler.h" #include "sys.h" #include "ui.h" +#include "comm_megawifi.h" +#include "everdrive_led.h" +#include "comm_demo.h" #include #include +static void registerSchedulerHandlers() +{ + scheduler_addTickHandler(*comm_megawifi_tick); + scheduler_addTickHandler(*midi_receiver_read_if_comm_ready); + scheduler_addFrameHandler(*midi_psg_tick); + scheduler_addFrameHandler(*ui_update); + scheduler_addFrameHandler(*everdrive_led_tick); + scheduler_addFrameHandler(*comm_megawifi_vsync); + scheduler_addFrameHandler(*comm_demo_vsync); +} + int main() { DMA_init(); scheduler_init(); + registerSchedulerHandlers(); log_init(); comm_init(); midi_init(M_BANK_0, P_BANK_0, ENVELOPES); diff --git a/src/scheduler.c b/src/scheduler.c index ceec96db..e1f6f575 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -27,13 +27,6 @@ void scheduler_init(void) ticks = 0; tickHandlersLength = 0; frameHandlersLength = 0; - scheduler_addTickHandler(*comm_megawifi_tick); - scheduler_addTickHandler(*midi_receiver_read_if_comm_ready); - scheduler_addFrameHandler(*midi_psg_tick); - scheduler_addFrameHandler(*ui_update); - scheduler_addFrameHandler(*everdrive_led_tick); - scheduler_addFrameHandler(*comm_megawifi_vsync); - scheduler_addFrameHandler(*comm_demo_vsync); } void scheduler_vsync(void) diff --git a/tests/unit/main.c b/tests/unit/main.c index e224fbf7..5bc1fb7f 100644 --- a/tests/unit/main.c +++ b/tests/unit/main.c @@ -260,7 +260,11 @@ int main(void) scheduler_test(test_scheduler_nothing_called_on_vsync), scheduler_test(test_scheduler_processes_frame_events_once_after_vsync), - scheduler_test(test_scheduler_tick_runs_midi_receiver), + scheduler_test(test_scheduler_registered_frame_handler_called_on_vsync), + scheduler_test(test_scheduler_registered_tick_handler_called), + scheduler_test( + test_scheduler_multiple_registered_frame_handlers_called_on_vsync), + scheduler_test(test_scheduler_multiple_registered_tick_handlers_called), applemidi_test( test_applemidi_parses_rtpmidi_packet_with_single_midi_event), diff --git a/tests/unit/test_scheduler.c b/tests/unit/test_scheduler.c index ae60a897..a8d53a90 100644 --- a/tests/unit/test_scheduler.c +++ b/tests/unit/test_scheduler.c @@ -5,6 +5,26 @@ extern void __real_scheduler_init(void); extern void __real_scheduler_tick(void); +static void dummy_frame_handler() +{ + function_called(); +} + +static void dummy_frame_handler_2() +{ + function_called(); +} + +static void dummy_tick_handler() +{ + function_called(); +} + +static void dummy_tick_handler_2() +{ + function_called(); +} + static int test_scheduler_setup(UNUSED void** state) { __real_scheduler_init(); @@ -20,25 +40,60 @@ static void test_scheduler_nothing_called_on_vsync(UNUSED void** state) static void test_scheduler_processes_frame_events_once_after_vsync( UNUSED void** state) { - expect_function_call(__wrap_comm_megawifi_tick); - expect_function_call(__wrap_midi_receiver_read_if_comm_ready); + scheduler_addFrameHandler(*dummy_frame_handler); + scheduler_addTickHandler(*dummy_tick_handler); + + expect_function_call(dummy_tick_handler); + __real_scheduler_tick(); + + scheduler_vsync(); + + expect_function_call(dummy_tick_handler); + expect_function_call(dummy_frame_handler); + __real_scheduler_tick(); +} + +static void test_scheduler_registered_frame_handler_called_on_vsync( + UNUSED void** state) +{ + scheduler_vsync(); + + scheduler_addFrameHandler(*dummy_frame_handler); + + expect_function_call(dummy_frame_handler); __real_scheduler_tick(); +} +static void test_scheduler_multiple_registered_frame_handlers_called_on_vsync( + UNUSED void** state) +{ scheduler_vsync(); - expect_function_call(__wrap_comm_megawifi_tick); - expect_function_call(__wrap_midi_receiver_read_if_comm_ready); - expect_function_call(__wrap_midi_psg_tick); - expect_function_call(__wrap_ui_update); - expect_function_call(__wrap_comm_demo_vsync); + scheduler_addFrameHandler(*dummy_frame_handler); + scheduler_addFrameHandler(*dummy_frame_handler_2); + expect_function_call(dummy_frame_handler); + expect_function_call(dummy_frame_handler_2); __real_scheduler_tick(); } -static void test_scheduler_tick_runs_midi_receiver(UNUSED void** state) +static void test_scheduler_registered_tick_handler_called(UNUSED void** state) { - expect_function_call(__wrap_comm_megawifi_tick); - expect_function_call(__wrap_midi_receiver_read_if_comm_ready); + scheduler_addTickHandler(*dummy_tick_handler); + + expect_function_call(dummy_tick_handler); + __real_scheduler_tick(); +} + +static void test_scheduler_multiple_registered_tick_handlers_called( + UNUSED void** state) +{ + scheduler_vsync(); + + scheduler_addFrameHandler(*dummy_tick_handler); + scheduler_addFrameHandler(*dummy_tick_handler_2); + expect_function_call(dummy_tick_handler); + expect_function_call(dummy_tick_handler_2); __real_scheduler_tick(); }