Skip to content

Commit 2dcfb14

Browse files
committed
Tidy test, run (and exit)
1 parent aa9b393 commit 2dcfb14

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

test/test_interactive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def test_audio_worklet(self):
296296
# Tests AudioWorklet with emscripten_lock_busyspin_wait_acquire() and friends.
297297
@also_with_minimal_runtime
298298
def test_audio_worklet_emscripten_locks(self):
299-
self.btest('webaudio/audioworklet_emscripten_locks.c', expected='0', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-pthread', '-sPTHREAD_POOL_SIZE=2'])
299+
self.btest_exit('webaudio/audioworklet_emscripten_locks.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS', '-pthread', '-sPTHREAD_POOL_SIZE=2'])
300300

301301
# Tests a second AudioWorklet example: sine wave tone generator.
302302
def test_audio_worklet_tone_generator(self):

test/webaudio/audioworklet_emscripten_locks.c

+21-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include <stdlib.h>
66
#include <assert.h>
77

8-
// Tests that these audio worklet compatible functions work, details in comments below.
8+
// Tests that these audio worklet compatible functions work, details in comments below:
9+
//
910
// - emscripten_thread_supports_atomics_wait()
1011
// - emscripten_lock_init()
1112
// - emscripten_lock_try_acquire()
@@ -35,8 +36,11 @@ typedef enum {
3536
TEST_DONE
3637
} Test;
3738

39+
// Lock used in all the tests
3840
emscripten_lock_t testLock = EMSCRIPTEN_LOCK_T_STATIC_INITIALIZER;
41+
// Which test is running (sometimes in the worklet, sometimes in the main thread)
3942
_Atomic Test whichTest = TEST_HAS_WAIT;
43+
// Time at which the test starts taken in main()
4044
double startTime = 0;
4145

4246
bool ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutputs, AudioSampleFrame *outputs, int numParams, const AudioParamFrame *params, void *userData) {
@@ -63,7 +67,7 @@ bool ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutputs,
6367
assert(!result);
6468
whichTest = TEST_WAIT_ACQUIRE;
6569
case TEST_WAIT_ACQUIRE:
66-
// Will get unlocked in main, so should quickly acquire
70+
// Will get unlocked in main thread, so should quickly acquire
6771
result = emscripten_lock_busyspin_wait_acquire(&testLock, 100);
6872
printf("TEST_WAIT_ACQUIRE: %d\n", result);
6973
assert(result);
@@ -78,16 +82,22 @@ bool ProcessAudio(int numInputs, const AudioSampleFrame *inputs, int numOutputs,
7882
whichTest = TEST_WAIT_INFINTE_1;
7983
break;
8084
case TEST_WAIT_INFINTE_1:
81-
// Still locked when we enter here
85+
// Still locked when we enter here but move on in the main thread
86+
break;
87+
case TEST_WAIT_INFINTE_2:
88+
emscripten_lock_release(&testLock);
89+
whichTest = TEST_GET_NOW;
90+
break;
8291
case TEST_GET_NOW:
8392
result = (int) (emscripten_get_now() - startTime);
8493
printf("TEST_GET_NOW: %d\n", result);
85-
assert(result);
94+
assert(result > 0);
8695
whichTest = TEST_DONE;
96+
case TEST_DONE:
97+
return false;
8798
default:
8899
break;
89100
}
90-
91101
return true;
92102
}
93103

@@ -103,17 +113,19 @@ EM_JS(void, InitHtmlUi, (EMSCRIPTEN_WEBAUDIO_T audioContext), {
103113
});
104114

105115
bool MainLoop(double time, void* data) {
106-
int result = 0;
107116
switch (whichTest) {
108117
case TEST_WAIT_ACQUIRE:
109118
// Release here to acquire in process
110119
emscripten_lock_release(&testLock);
111120
break;
112121
case TEST_WAIT_INFINTE_1:
113-
// Spin here until released in process
122+
// Spin here until released in process (but don't change test until we know this case ran)
123+
whichTest = TEST_WAIT_INFINTE_2;
114124
emscripten_lock_busyspin_waitinf_acquire(&testLock);
115-
whichTest = TEST_DONE;
125+
printf("TEST_WAIT_INFINTE (from main)\n");
116126
break;
127+
case TEST_DONE:
128+
return false;
117129
default:
118130
break;
119131
}
@@ -133,7 +145,7 @@ void WebAudioWorkletThreadInitialized(EMSCRIPTEN_WEBAUDIO_T audioContext, bool s
133145
emscripten_create_wasm_audio_worklet_processor_async(audioContext, &opts, AudioWorkletProcessorCreated, NULL);
134146
}
135147

136-
uint8_t wasmAudioWorkletStack[4096];
148+
uint8_t wasmAudioWorkletStack[2048];
137149

138150
int main() {
139151
// Main thread init and acquire (work passes to the processor)

0 commit comments

Comments
 (0)