summaryrefslogtreecommitdiff
path: root/src/tests/test_jittered_audio.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-05 19:49:27 +0100
committerskal <pascal.massimino@gmail.com>2026-02-05 19:49:27 +0100
commit64c19b368db4aea748467b5f763add99c7deb701 (patch)
tree5c159b9a1ff19fb6078e7e08a9b9e9747c4cb3d7 /src/tests/test_jittered_audio.cc
parent4fd55777eb8b678297fb2efd207dc8cd509a6919 (diff)
perf: Reduce audio test durations for faster test suite
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.
Diffstat (limited to 'src/tests/test_jittered_audio.cc')
-rw-r--r--src/tests/test_jittered_audio.cc72
1 files changed, 38 insertions, 34 deletions
diff --git a/src/tests/test_jittered_audio.cc b/src/tests/test_jittered_audio.cc
index 92c9099..f880c74 100644
--- a/src/tests/test_jittered_audio.cc
+++ b/src/tests/test_jittered_audio.cc
@@ -24,9 +24,10 @@ void test_jittered_audio_basic() {
// At 32kHz, 10ms = 320 samples = 160 frames (stereo)
// Jitter of ±5ms means 5-15ms intervals, or 80-240 frames
JitteredAudioBackend jittered_backend;
- jittered_backend.set_base_interval(10.0f); // 10ms base interval
- jittered_backend.set_jitter_amount(5.0f); // ±5ms jitter
- jittered_backend.set_chunk_size_range(80, 240); // Realistic chunk sizes for 5-15ms
+ jittered_backend.set_base_interval(10.0f); // 10ms base interval
+ jittered_backend.set_jitter_amount(5.0f); // ±5ms jitter
+ jittered_backend.set_chunk_size_range(
+ 80, 240); // Realistic chunk sizes for 5-15ms
audio_set_backend(&jittered_backend);
audio_init();
@@ -35,13 +36,13 @@ void test_jittered_audio_basic() {
audio_start();
assert(jittered_backend.is_running());
- // Simulate main loop for 2 seconds
- const float total_time = 2.0f;
- const float dt = 1.0f / 60.0f; // 60fps
+ // Simulate main loop for 0.5 seconds (quick stress test)
+ const float total_time = 0.5f;
+ const float dt = 1.0f / 60.0f; // 60fps
float music_time = 0.0f;
for (float t = 0.0f; t < total_time; t += dt) {
- music_time += dt; // Normal tempo
+ music_time += dt; // Normal tempo
// Update tracker and fill buffer
tracker_update(music_time);
@@ -61,13 +62,13 @@ void test_jittered_audio_basic() {
printf(" Frames consumed: %d\n", frames_consumed);
printf(" Underruns: %d\n", underruns);
- // Should have consumed roughly 2 seconds worth of audio
- // At 32kHz stereo: 2 seconds = 64000 samples = 32000 frames
- assert(frames_consumed > 24000); // At least 1.5 seconds (48000 samples)
- assert(frames_consumed < 40000); // At most 2.5 seconds (80000 samples)
+ // Should have consumed roughly 0.5 seconds worth of audio
+ // At 32kHz stereo: 0.5 seconds = 16000 samples = 8000 frames
+ assert(frames_consumed > 4000); // At least 0.25 seconds (8000 samples)
+ assert(frames_consumed < 12000); // At most 0.75 seconds (24000 samples)
// Underruns are acceptable in this test, but shouldn't be excessive
- assert(underruns < 50); // Less than 50 underruns in 2 seconds
+ assert(underruns < 20); // Less than 20 underruns in 0.5 seconds
printf(" ✓ Basic jittered audio consumption PASSED\n");
}
@@ -83,9 +84,9 @@ void test_jittered_audio_with_acceleration() {
// At 32kHz, 15ms = 480 samples = 240 frames (stereo)
// Jitter of ±10ms means 5-25ms intervals, or 80-400 frames
JitteredAudioBackend jittered_backend;
- jittered_backend.set_base_interval(15.0f); // Slower consumption
- jittered_backend.set_jitter_amount(10.0f); // High jitter
- jittered_backend.set_chunk_size_range(80, 400); // Realistic stress test range
+ jittered_backend.set_base_interval(15.0f); // Slower consumption
+ jittered_backend.set_jitter_amount(10.0f); // High jitter
+ jittered_backend.set_chunk_size_range(80, 400); // Realistic stress test range
audio_set_backend(&jittered_backend);
audio_init();
@@ -94,19 +95,19 @@ void test_jittered_audio_with_acceleration() {
audio_start();
// Simulate acceleration scenario (similar to real demo)
- const float total_time = 10.0f;
+ const float total_time = 3.0f;
const float dt = 1.0f / 60.0f;
float music_time = 0.0f;
float physical_time = 0.0f;
- for (int frame = 0; frame < 600; ++frame) { // 10 seconds @ 60fps
+ for (int frame = 0; frame < 180; ++frame) { // 3 seconds @ 60fps
physical_time = frame * dt;
- // Variable tempo (accelerate from 5-10s)
+ // Variable tempo (accelerate from 1.5-3s)
float tempo_scale = 1.0f;
- if (physical_time >= 5.0f && physical_time < 10.0f) {
- const float progress = (physical_time - 5.0f) / 5.0f;
- tempo_scale = 1.0f + progress * 1.0f; // 1.0 → 2.0
+ if (physical_time >= 1.5f && physical_time < 3.0f) {
+ const float progress = (physical_time - 1.5f) / 1.5f;
+ tempo_scale = 1.0f + progress * 1.0f; // 1.0 → 2.0
}
music_time += dt * tempo_scale;
@@ -118,12 +119,14 @@ void test_jittered_audio_with_acceleration() {
// Sleep to simulate frame time
std::this_thread::sleep_for(std::chrono::milliseconds(16));
- // Progress indicator
- if (frame % 60 == 0) {
- printf(" Frame %d: music_time=%.2fs, tempo=%.2fx, consumed=%d frames, underruns=%d\r",
- frame, music_time, tempo_scale,
- jittered_backend.get_total_frames_consumed(),
- jittered_backend.get_underrun_count());
+ // Progress indicator (every 30 frames for shorter test)
+ if (frame % 30 == 0) {
+ printf(
+ " Frame %d: music_time=%.2fs, tempo=%.2fx, consumed=%d frames, "
+ "underruns=%d\r",
+ frame, music_time, tempo_scale,
+ jittered_backend.get_total_frames_consumed(),
+ jittered_backend.get_underrun_count());
fflush(stdout);
}
}
@@ -139,14 +142,15 @@ void test_jittered_audio_with_acceleration() {
printf(" Total frames consumed: %d\n", frames_consumed);
printf(" Total underruns: %d\n", underruns);
- // Should have consumed roughly 12.5 seconds worth of audio
- // (10 seconds physical time with acceleration 1.0x → 2.0x)
- // At 32kHz stereo: 12.5 seconds = 400000 samples = 200000 frames
- assert(frames_consumed > 120000); // At least 7.5 seconds (240000 samples)
- assert(frames_consumed < 240000); // At most 15 seconds (480000 samples)
+ // Should have consumed roughly 3.75 seconds worth of audio
+ // (3 seconds physical time with acceleration 1.0x → 2.0x)
+ // At 32kHz stereo: 3.75 seconds = 120000 samples = 60000 frames
+ assert(frames_consumed > 40000); // At least 2.5 seconds (80000 samples)
+ assert(frames_consumed < 80000); // At most 5 seconds (160000 samples)
- // During acceleration with jitter, some underruns are expected but not excessive
- assert(underruns < 200); // Less than 200 underruns in 10 seconds
+ // During acceleration with jitter, some underruns are expected but not
+ // excessive
+ assert(underruns < 60); // Less than 60 underruns in 3 seconds
printf(" ✓ Jittered audio with acceleration PASSED\n");
}