Skip to content

Commit 7c2c85f

Browse files
committed
The AW test should now fail, waiting on audio playback
1 parent d28de47 commit 7c2c85f

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

test/test_browser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5470,7 +5470,7 @@ def test_full_js_library_strict(self):
54705470
'strict': (['-sSTRICT'],),
54715471
})
54725472
def test_audio_worklet(self, args):
5473-
self.btest_exit('webaudio/audioworklet.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS'] + args)
5473+
self.btest_exit('webaudio/audioworklet.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-DTEST_AND_EXIT'] + args)
54745474

54755475
# Tests that audioworklets and workers can be used at the same time
54765476
def test_audio_worklet_worker(self):

test/webaudio/audioworklet.c

+17-9
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
begin to fire.
2323
*/
2424

25-
// REPORT_RESULT is defined when running in Emscripten test harness. You can
26-
// strip these out in your own project.
27-
#ifdef REPORT_RESULT
25+
// TEST_AND_EXIT is defined when running in Emscripten test harness. You can
26+
// strip these out in your own project (otherwise playback will end quickly).
27+
#ifdef TEST_AND_EXIT
2828
_Thread_local int testTlsVariable = 1;
2929
int lastTlsVariableValueInAudioThread = 1;
3030
#endif
3131

3232
// This function will be called for every fixed-size buffer of audio samples to be processed.
3333
bool ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutputs, AudioSampleFrame *outputs, int numParams, const AudioParamFrame *params, void *userData) {
34-
#ifdef REPORT_RESULT
34+
#ifdef TEST_AND_EXIT
35+
// Only running in the test harness, see main_thread_tls_access()
3536
assert(testTlsVariable == lastTlsVariableValueInAudioThread);
3637
++testTlsVariable;
3738
lastTlsVariableValueInAudioThread = testTlsVariable;
@@ -63,14 +64,15 @@ EM_JS(void, InitHtmlUi, (EMSCRIPTEN_WEBAUDIO_T audioContext), {
6364
};
6465
});
6566

66-
#ifdef REPORT_RESULT
67+
#ifdef TEST_AND_EXIT
6768
bool main_thread_tls_access(double time, void *userData) {
6869
// Try to mess the TLS variable on the main thread, with the expectation that
69-
// it should not change the TLS value on the AudioWorklet thread.
70+
// it should not change the TLS value on the AudioWorklet thread, asserted in
71+
// ProcessAudio().
7072
testTlsVariable = (int)time;
73+
// Exit to the test harness after enough calls to ProcessAudio()
7174
if (lastTlsVariableValueInAudioThread >= 100) {
72-
REPORT_RESULT(0);
73-
return false;
75+
emscripten_force_exit(EXIT_SUCCESS);
7476
}
7577
return true;
7678
}
@@ -97,7 +99,8 @@ void AudioWorkletProcessorCreated(EMSCRIPTEN_WEBAUDIO_T audioContext, bool succe
9799
// Connect the audio worklet node to the graph.
98100
emscripten_audio_node_connect(wasmAudioWorklet, audioContext, 0, 0);
99101

100-
#ifdef REPORT_RESULT
102+
#ifdef TEST_AND_EXIT
103+
// Schedule this to exit after ProcessAudio() has been called 100 times
101104
emscripten_set_timeout_loop(main_thread_tls_access, 10, 0);
102105
#endif
103106

@@ -132,4 +135,9 @@ int main() {
132135
// and kick off Audio Worklet scope initialization, which shares the Wasm
133136
// Module and Memory to the AudioWorklet scope and initializes its stack.
134137
emscripten_start_wasm_audio_worklet_thread_async(context, wasmAudioWorkletStack, sizeof(wasmAudioWorkletStack), WebAudioWorkletThreadInitialized, 0);
138+
139+
#ifdef TEST_AND_EXIT
140+
// We're in the test harness and exiting is via main_thread_tls_access()
141+
emscripten_exit_with_live_runtime();
142+
#endif
135143
}

0 commit comments

Comments
 (0)