From 64c19b368db4aea748467b5f763add99c7deb701 Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 5 Feb 2026 19:49:27 +0100 Subject: perf: Reduce audio test durations for faster test suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Optimized long-running audio tests to significantly improve test suite performance while maintaining test coverage. Changes: - WavDumpBackend: Added set_duration() method with configurable duration - Default remains 60s for debugging/production use - Test now uses 2s instead of 60s (140x faster: 60s → 0.43s) - JitteredAudioBackendTest: Reduced simulation durations - Test 1: 2.0s → 0.5s (4x faster) - Test 2: 10.0s → 3.0s (3.3x faster) - Overall: 14.49s → 4.48s (3.2x faster) - Updated assertions for shorter durations - Progress indicators adjusted for shorter tests Results: - Total test suite time: 18.31s → 8.29s (55% faster) - All 20 tests still pass - Tests still properly validate intended behavior handoff(Claude): Optimized audio test performance to speed up development iteration without sacrificing test coverage. WavDumpBackend now has configurable duration via set_duration() method. --- src/tests/test_wav_dump.cc | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/tests/test_wav_dump.cc') diff --git a/src/tests/test_wav_dump.cc b/src/tests/test_wav_dump.cc index 753d548..f350330 100644 --- a/src/tests/test_wav_dump.cc +++ b/src/tests/test_wav_dump.cc @@ -1,10 +1,10 @@ // This file is part of the 64k demo project. // Regression test for WAV dump backend to prevent format mismatches. -#include "audio/wav_dump_backend.h" #include "audio/audio.h" #include "audio/synth.h" #include "audio/tracker.h" +#include "audio/wav_dump_backend.h" #include #include #include @@ -13,18 +13,18 @@ // Helper to read WAV header and verify format struct WavHeader { - char riff[4]; // "RIFF" - uint32_t chunk_size; // File size - 8 - char wave[4]; // "WAVE" - char fmt[4]; // "fmt " + char riff[4]; // "RIFF" + uint32_t chunk_size; // File size - 8 + char wave[4]; // "WAVE" + char fmt[4]; // "fmt " uint32_t subchunk1_size; - uint16_t audio_format; // 1 = PCM + uint16_t audio_format; // 1 = PCM uint16_t num_channels; uint32_t sample_rate; uint32_t byte_rate; uint16_t block_align; uint16_t bits_per_sample; - char data[4]; // "data" + char data[4]; // "data" uint32_t data_size; }; @@ -36,6 +36,7 @@ void test_wav_format_matches_live_audio() { // Create WAV dump backend WavDumpBackend wav_backend; wav_backend.set_output_file(test_file); + wav_backend.set_duration(2.0f); // Only 2 seconds for quick testing audio_set_backend(&wav_backend); // Initialize audio system (calls synth_init internally) @@ -45,7 +46,7 @@ void test_wav_format_matches_live_audio() { tracker_init(); // Manually trigger some audio for testing - tracker_update(0.0f); // Trigger patterns at t=0 + tracker_update(0.0f); // Trigger patterns at t=0 // Render short duration (1 second = 60 updates @ 60Hz) for (int i = 0; i < 60; ++i) { @@ -55,7 +56,7 @@ void test_wav_format_matches_live_audio() { // Simulate audio render (WavDumpBackend will handle this in start()) } - audio_start(); // This triggers the actual WAV rendering + audio_start(); // This triggers the actual WAV rendering audio_shutdown(); // Read and verify WAV header @@ -74,7 +75,7 @@ void test_wav_format_matches_live_audio() { // CRITICAL: Verify stereo format (matches miniaudio config) printf(" Checking num_channels...\n"); - assert(header.num_channels == 2); // MUST be stereo! + assert(header.num_channels == 2); // MUST be stereo! // Verify sample rate matches miniaudio printf(" Checking sample_rate...\n"); @@ -86,7 +87,7 @@ void test_wav_format_matches_live_audio() { // Verify audio format is PCM printf(" Checking audio_format...\n"); - assert(header.audio_format == 1); // PCM + assert(header.audio_format == 1); // PCM // Verify calculated values printf(" Checking byte_rate...\n"); @@ -99,24 +100,23 @@ void test_wav_format_matches_live_audio() { header.num_channels * (header.bits_per_sample / 8); assert(header.block_align == expected_block_align); - // Verify data size is reasonable (60 seconds of audio) + // Verify data size is reasonable (2 seconds of audio) printf(" Checking data_size...\n"); const uint32_t bytes_per_sample = header.bits_per_sample / 8; const uint32_t expected_bytes_per_sec = header.sample_rate * header.num_channels * bytes_per_sample; - const uint32_t expected_size_60s = expected_bytes_per_sec * 60; + const uint32_t expected_size_2s = expected_bytes_per_sec * 2; - printf(" Data size: %u bytes (expected ~%u bytes for 60s)\n", - header.data_size, expected_size_60s); + printf(" Data size: %u bytes (expected ~%u bytes for 2s)\n", + header.data_size, expected_size_2s); - // Be lenient: allow 50-70 seconds worth of data - const uint32_t expected_min_size = expected_bytes_per_sec * 50; - const uint32_t expected_max_size = expected_bytes_per_sec * 70; + // Be lenient: allow 1.5-2.5 seconds worth of data + const uint32_t expected_min_size = expected_bytes_per_sec * 1.5; + const uint32_t expected_max_size = expected_bytes_per_sec * 2.5; - // Note: Currently seeing 2x expected size - may be a header writing bug // For now, accept if stereo format is correct (main regression test goal) if (header.data_size < expected_min_size || - header.data_size > expected_max_size * 2) { + header.data_size > expected_max_size) { printf(" WARNING: Data size outside expected range\n"); // Don't fail on this for now - stereo format is the critical check } @@ -136,7 +136,7 @@ void test_wav_format_matches_live_audio() { printf(" Checking for actual audio data...\n"); printf(" Non-zero samples: %d / 1000\n", non_zero_count); - assert(non_zero_count > 100); // Should have plenty of non-zero samples + assert(non_zero_count > 100); // Should have plenty of non-zero samples fclose(f); @@ -155,8 +155,8 @@ void test_wav_stereo_buffer_size() { const int sample_rate = 32000; const float update_dt = 1.0f / 60.0f; - const int frames_per_update = (int)(sample_rate * update_dt); // ~533 - const int samples_per_update = frames_per_update * 2; // ~1066 (stereo) + const int frames_per_update = (int)(sample_rate * update_dt); // ~533 + const int samples_per_update = frames_per_update * 2; // ~1066 (stereo) printf(" Update rate: 60 Hz\n"); printf(" Frames per update: %d\n", frames_per_update); -- cgit v1.2.3