11#include < emscripten/threading.h>
22#include < emscripten/wasm_worker.h>
33#include < emscripten/webaudio.h>
4- #include < stdio.h>
5- #include < stdlib.h>
64#include < assert.h>
75
86// Tests that these audio worklet compatible functions work, details in comments below:
@@ -52,35 +50,35 @@ bool ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutputs,
5250 case TEST_HAS_WAIT:
5351 // Should not have wait support here
5452 result = _emscripten_thread_supports_atomics_wait ();
55- printf (" TEST_HAS_WAIT: %d (expect: 0)\n " , result);
53+ emscripten_outf (" TEST_HAS_WAIT: %d (expect: 0)" , result);
5654 assert (!result);
5755 whichTest = TEST_TRY_ACQUIRE;
5856 break ;
5957 case TEST_TRY_ACQUIRE:
6058 // Was locked after init, should fail to acquire
6159 result = emscripten_lock_try_acquire (&testLock);
62- printf (" TEST_TRY_ACQUIRE: %d (expect: 0)\n " , result);
60+ emscripten_outf (" TEST_TRY_ACQUIRE: %d (expect: 0)" , result);
6361 assert (!result);
6462 whichTest = TEST_WAIT_ACQUIRE_FAIL;
6563 break ;
6664 case TEST_WAIT_ACQUIRE_FAIL:
6765 // Still locked so we fail to acquire
6866 result = emscripten_lock_busyspin_wait_acquire (&testLock, 100 );
69- printf (" TEST_WAIT_ACQUIRE_FAIL: %d (expect: 0)\n " , result);
67+ emscripten_outf (" TEST_WAIT_ACQUIRE_FAIL: %d (expect: 0)" , result);
7068 assert (!result);
7169 whichTest = TEST_WAIT_ACQUIRE;
7270 case TEST_WAIT_ACQUIRE:
7371 // Will get unlocked in main thread, so should quickly acquire
7472 result = emscripten_lock_busyspin_wait_acquire (&testLock, 100 );
75- printf (" TEST_WAIT_ACQUIRE: %d (expect: 1)\n " , result);
73+ emscripten_outf (" TEST_WAIT_ACQUIRE: %d (expect: 1)" , result);
7674 assert (result);
7775 whichTest = TEST_RELEASE;
7876 break ;
7977 case TEST_RELEASE:
8078 // Unlock, check the result
8179 emscripten_lock_release (&testLock);
8280 result = emscripten_lock_try_acquire (&testLock);
83- printf (" TEST_RELEASE: %d (expect: 1)\n " , result);
81+ emscripten_outf (" TEST_RELEASE: %d (expect: 1)" , result);
8482 assert (result);
8583 whichTest = TEST_WAIT_INFINTE_1;
8684 break ;
@@ -93,7 +91,7 @@ bool ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutputs,
9391 break ;
9492 case TEST_GET_NOW:
9593 result = (int ) (emscripten_get_now () - startTime);
96- printf (" TEST_GET_NOW: %d (expect: > 0)\n " , result);
94+ emscripten_outf (" TEST_GET_NOW: %d (expect: > 0)" , result);
9795 assert (result > 0 );
9896 whichTest = TEST_DONE;
9997 case TEST_DONE:
@@ -125,9 +123,12 @@ bool MainLoop(double time, void* data) {
125123 // Spin here until released in process (but don't change test until we know this case ran)
126124 whichTest = TEST_WAIT_INFINTE_2;
127125 emscripten_lock_busyspin_waitinf_acquire (&testLock);
128- printf (" TEST_WAIT_INFINTE (from main)\n " );
126+ emscripten_out (" TEST_WAIT_INFINTE (from main)" );
129127 break ;
130128 case TEST_DONE:
129+ // Finished, exit from the main thread
130+ emscripten_out (" Test success" );
131+ emscripten_force_exit (0 );
131132 return false ;
132133 default :
133134 break ;
@@ -161,4 +162,6 @@ int main() {
161162 emscripten_set_timeout_loop (MainLoop, 10 , NULL );
162163 EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context (NULL );
163164 emscripten_start_wasm_audio_worklet_thread_async (context, wasmAudioWorkletStack, sizeof (wasmAudioWorkletStack), WebAudioWorkletThreadInitialized, NULL );
165+
166+ emscripten_exit_with_live_runtime ();
164167}
0 commit comments