diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-05 18:43:12 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-05 18:43:12 +0100 |
| commit | 7721f574fad99949f85b4caf1e196b957fc0cf51 (patch) | |
| tree | d2e8bd881df5569332bc9e04e867453398a10d05 /src/tests/test_tracker.cc | |
| parent | dcda45d8ae46197d304d737c102b13643808203f (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'src/tests/test_tracker.cc')
| -rw-r--r-- | src/tests/test_tracker.cc | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/src/tests/test_tracker.cc b/src/tests/test_tracker.cc index 7ef7172..9285728 100644 --- a/src/tests/test_tracker.cc +++ b/src/tests/test_tracker.cc @@ -8,11 +8,12 @@ #include <assert.h> #include <stdio.h> -// Forward declaration for generated data to avoid compilation issues before -// generation extern const NoteParams g_tracker_samples[]; extern const uint32_t -// g_tracker_samples_count; extern const TrackerPattern g_tracker_patterns[]; -// extern const uint32_t g_tracker_patterns_count; -// extern const TrackerScore g_tracker_score; +// Forward declaration for generated data +extern const NoteParams g_tracker_samples[]; +extern const uint32_t g_tracker_samples_count; +extern const TrackerPattern g_tracker_patterns[]; +extern const uint32_t g_tracker_patterns_count; +extern const TrackerScore g_tracker_score; void test_tracker_init() { synth_init(); @@ -24,43 +25,33 @@ void test_tracker_pattern_triggering() { synth_init(); tracker_init(); - // At time 0.0f, 4 patterns are triggered: + // At time 0.0f, 3 patterns are triggered: // - crash (1 event at beat 0.0) // - kick_basic (events at beat 0.0, 2.0, 2.5) - // - snare_basic (events at beat 1.0, 3.0) - // - hihat_stressed (events at beat 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5) - // With the new event-based triggering, only events at beat 0.0 trigger immediately. + // - hihat_basic (events at beat 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5) + // With event-based triggering, only events at beat 0.0 trigger immediately. // Test 1: At music_time = 0.0f, events at beat 0.0 trigger tracker_update(0.0f); - printf("Actual active voice count at 0.0f: %d\n", - synth_get_active_voice_count()); - // Expect 3 voices: crash (beat 0.0), kick_basic (beat 0.0), hihat_stressed - // (beat 0.0) + // Expect 3 voices: crash (beat 0.0), kick (beat 0.0), hihat (beat 0.0) assert(synth_get_active_voice_count() == 3); // Test 2: At music_time = 0.25f (beat 0.5 @ 120 BPM), hihat event triggers // beat_duration = 60.0f / 120.0f = 0.5s per beat // beat 0.5 = 0.25s tracker_update(0.25f); - printf("Actual active voice count at 0.25f: %d\n", - synth_get_active_voice_count()); - // Expect 4 voices (3 previous + 1 new hihat) + // Expect 4 voices (3 previous + 1 hihat at beat 0.5) assert(synth_get_active_voice_count() == 4); - // Test 3: At music_time = 0.5f (beat 1.0), snare event triggers + // Test 3: At music_time = 0.5f (beat 1.0), hihat event triggers tracker_update(0.5f); - printf("Actual active voice count at 0.5f: %d\n", - synth_get_active_voice_count()); - // Expect 6 voices (4 previous + snare + hihat at beat 1.0) - assert(synth_get_active_voice_count() == 6); + // Expect 5 voices (4 previous + 1 hihat at beat 1.0) + assert(synth_get_active_voice_count() == 5); - // Test 4: Advance further to 2.0f (beat 4.0), new pattern triggers at 2.0f + // Test 4: Advance to 2.0f - new patterns trigger at time 2.0f tracker_update(2.0f); - printf("Actual active voice count at 2.0f: %d\n", - synth_get_active_voice_count()); - // Multiple events have triggered by now - assert(synth_get_active_voice_count() > 0); + // Many events have triggered by now + assert(synth_get_active_voice_count() > 5); printf("Tracker pattern triggering test PASSED\n"); } |
