From 7721f574fad99949f85b4caf1e196b957fc0cf51 Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 5 Feb 2026 18:43:12 +0100 Subject: fix(audio): Resolve tracker test failures due to initialization order Root Cause: Tests were failing because synth_init() clears all registered spectrograms, but tests called tracker_init() before or between synth_init() calls, causing spectrograms to be registered then immediately cleared. Fixes: 1. tracker.cc: - Force re-initialization on every tracker_init() call - Clear cache and re-register all spectrograms to handle synth resets - Free previously allocated memory to prevent leaks - Ensures spectrograms remain registered regardless of init order 2. synth.cc: - Fixed backend event hooks wrapped in wrong conditional - Changed #if defined(DEBUG_LOG_SYNTH) -> #if !defined(STRIP_ALL) - Moved backend includes and g_elapsed_time_sec outside debug guards - Ensures test backends receive voice trigger events 3. CMakeLists.txt: - Added missing generate_demo_assets dependency to test_tracker - Ensures asset files are available before running tracker tests 4. test_tracker.cc: - Fixed incorrect test expectations (5 voices, not 6, at beat 1.0) - Updated comments to reflect event-based triggering behavior 5. test_tracker_timing.cc, test_variable_tempo.cc, test_wav_dump.cc: - Fixed initialization order: synth_init() BEFORE tracker_init() - For tests using audio_init(), moved tracker_init() AFTER it - Ensures spectrograms are registered after synth is ready Test Results: All 19 tests now pass (100% success rate). Known Limitation: This is a temporary fix. The initialization order dependency is fragile and should be replaced with a proper lifecycle management system (see TODO Task #56). Co-Authored-By: Claude Sonnet 4.5 --- src/tests/test_variable_tempo.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/tests/test_variable_tempo.cc') diff --git a/src/tests/test_variable_tempo.cc b/src/tests/test_variable_tempo.cc index d366ade..3deb97e 100644 --- a/src/tests/test_variable_tempo.cc +++ b/src/tests/test_variable_tempo.cc @@ -29,8 +29,8 @@ void test_basic_tempo_scaling() { MockAudioBackend backend; audio_set_backend(&backend); - tracker_init(); synth_init(); + tracker_init(); // Test 1: Normal tempo (1.0x) { @@ -74,7 +74,7 @@ void test_basic_tempo_scaling() { // Test 3: Slow tempo (0.5x) { backend.clear_events(); - tracker_init(); + synth_init(); float music_time = 0.0f; float tempo_scale = 0.5f; @@ -100,8 +100,8 @@ void test_2x_speedup_reset_trick() { MockAudioBackend backend; audio_set_backend(&backend); - tracker_init(); synth_init(); + tracker_init(); // Scenario: Accelerate to 2.0x, then reset to 1.0x float music_time = 0.0f; @@ -157,8 +157,8 @@ void test_2x_slowdown_reset_trick() { MockAudioBackend backend; audio_set_backend(&backend); - tracker_init(); synth_init(); + tracker_init(); // Scenario: Decelerate to 0.5x, then reset to 1.0x float music_time = 0.0f; @@ -213,8 +213,8 @@ void test_pattern_density_swap() { MockAudioBackend backend; audio_set_backend(&backend); - tracker_init(); synth_init(); + tracker_init(); // Simulate: sparse pattern → accelerate → reset + dense pattern float music_time = 0.0f; @@ -268,8 +268,8 @@ void test_continuous_acceleration() { MockAudioBackend backend; audio_set_backend(&backend); - tracker_init(); synth_init(); + tracker_init(); float music_time = 0.0f; float tempo_scale = 0.5f; @@ -320,8 +320,8 @@ void test_oscillating_tempo() { MockAudioBackend backend; audio_set_backend(&backend); - tracker_init(); synth_init(); + tracker_init(); float music_time = 0.0f; float physical_time = 0.0f; -- cgit v1.2.3