Skip to content

Commit 52e3505

Browse files
committed
enhance the test for cover all emscripten_audio_worklet_post_function_*
1 parent 261e509 commit 52e3505

File tree

2 files changed

+109
-16
lines changed

2 files changed

+109
-16
lines changed

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5484,7 +5484,7 @@ def test_audio_worklet_worker(self):
54845484
'closure': (['--closure', '1', '-Oz'],),
54855485
})
54865486
def test_audio_worklet_post_function(self, args):
5487-
self.btest('webaudio/audioworklet_post_function.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS'] + args, expected='1')
5487+
self.btest('webaudio/audioworklet_post_function.c', args=['-sAUDIO_WORKLET', '-sWASM_WORKERS'] + args, expected='16')
54885488

54895489
@parameterized({
54905490
'': ([],),

test/webaudio/audioworklet_post_function.c

Lines changed: 108 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,121 @@
66
// and the Audio Worklet thread using the
77
// emscripten_audio_worklet_post_function_*() API.
88

9-
// This event will fire on the main thread.
10-
void MessageReceivedOnMainThread(int d, int e, int f) {
11-
printf("MessageReceivedOnMainThread: d=%d, e=%d, f=%d\n", d, e, f);
12-
assert(!emscripten_current_thread_is_audio_worklet());
13-
assert(d == 1 && e == 2 && f == 3);
14-
#ifdef REPORT_RESULT
15-
REPORT_RESULT(1); // test succeeded, were able to post a message from main thread to audio thread and back!
16-
#endif
9+
// This test scenario consists of two steps
10+
// 1. post function from main thread to audio worklet thread, with testingAudioWorklet = true
11+
// 2. post function from audio worklet thread to main thread, with testingAudioWorklet = false
12+
volatile bool testingAudioWorklet = true;
13+
volatile int success = 0;
14+
15+
void v() {
16+
assert(testingAudioWorklet == emscripten_current_thread_is_audio_worklet());
17+
emscripten_out("v");
18+
++success;
19+
}
20+
21+
void vi(int i) {
22+
assert(testingAudioWorklet == emscripten_current_thread_is_audio_worklet());
23+
emscripten_out("vi");
24+
assert(i == 1);
25+
++success;
26+
}
27+
28+
void vii(int i, int j) {
29+
assert(testingAudioWorklet == emscripten_current_thread_is_audio_worklet());
30+
emscripten_out("vii");
31+
assert(i == 2);
32+
assert(j == 3);
33+
++success;
34+
}
35+
36+
void viii(int i, int j, int k) {
37+
assert(testingAudioWorklet == emscripten_current_thread_is_audio_worklet());
38+
emscripten_out("viii");
39+
assert(i == 4);
40+
assert(j == 5);
41+
assert(k == 6);
42+
++success;
43+
}
44+
45+
void vd(double i) {
46+
assert(testingAudioWorklet == emscripten_current_thread_is_audio_worklet());
47+
emscripten_out("vd");
48+
assert(i == 1.5);
49+
++success;
1750
}
1851

19-
// This event will fire on the audio worklet thread.
20-
void MessageReceivedInAudioWorkletThread(int a, int b) {
21-
printf("MessageReceivedInAudioWorkletThread: a=%d, b=%d\n", a, b);
22-
assert(emscripten_current_thread_is_audio_worklet());
23-
assert(a == 42 && b == 9000);
24-
emscripten_audio_worklet_post_function_sig(EMSCRIPTEN_AUDIO_MAIN_THREAD, (void *)MessageReceivedOnMainThread, "iii", /*d=*/1, /*e=*/2, /*f=*/3);
52+
void vdd(double i, double j) {
53+
assert(testingAudioWorklet == emscripten_current_thread_is_audio_worklet());
54+
emscripten_out("vdd");
55+
assert(i == 2.5);
56+
assert(j == 3.5);
57+
++success;
58+
}
59+
60+
void vddd(double i, double j, double k) {
61+
assert(testingAudioWorklet == emscripten_current_thread_is_audio_worklet());
62+
emscripten_out("vddd");
63+
assert(i == 4.5);
64+
assert(j == 5.5);
65+
assert(k == 6.5);
66+
++success;
67+
}
68+
69+
void viiiiiidddddd(int a, int b, int c, int d, int e, int f, double g, double h, double i, double j, double k, double l) {
70+
assert(testingAudioWorklet == emscripten_current_thread_is_audio_worklet());
71+
emscripten_out("viiiiiidddddd");
72+
assert(a == 10);
73+
assert(b == 11);
74+
assert(c == 12);
75+
assert(d == 13);
76+
assert(e == 14);
77+
assert(f == 15);
78+
assert(g == 16.5);
79+
assert(h == 17.5);
80+
assert(i == 18.5);
81+
assert(j == 19.5);
82+
assert(k == 20.5);
83+
assert(l == 21.5);
84+
++success;
85+
}
86+
87+
void sided_test_finished() {
88+
assert(testingAudioWorklet == emscripten_current_thread_is_audio_worklet());
89+
90+
if (testingAudioWorklet) { // for the first call, finishing checks for main -> audio worklet
91+
testingAudioWorklet = false;
92+
93+
// These event will fire callbacks on main thread.
94+
emscripten_audio_worklet_post_function_v(EMSCRIPTEN_AUDIO_MAIN_THREAD, v);
95+
emscripten_audio_worklet_post_function_vi(EMSCRIPTEN_AUDIO_MAIN_THREAD, vi, 1);
96+
emscripten_audio_worklet_post_function_vii(EMSCRIPTEN_AUDIO_MAIN_THREAD, vii, 2, 3);
97+
emscripten_audio_worklet_post_function_viii(EMSCRIPTEN_AUDIO_MAIN_THREAD, viii, 4, 5, 6);
98+
emscripten_audio_worklet_post_function_vd(EMSCRIPTEN_AUDIO_MAIN_THREAD, vd, 1.5);
99+
emscripten_audio_worklet_post_function_vdd(EMSCRIPTEN_AUDIO_MAIN_THREAD, vdd, 2.5, 3.5);
100+
emscripten_audio_worklet_post_function_vddd(EMSCRIPTEN_AUDIO_MAIN_THREAD, vddd, 4.5, 5.5, 6.5);
101+
emscripten_audio_worklet_post_function_sig(EMSCRIPTEN_AUDIO_MAIN_THREAD, viiiiiidddddd, "iiiiiidddddd", 10, 11, 12, 13, 14, 15, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5);
102+
emscripten_audio_worklet_post_function_v(EMSCRIPTEN_AUDIO_MAIN_THREAD, sided_test_finished);
103+
} else { // for the second call, finishing checks for audio worklet -> main
104+
#ifdef REPORT_RESULT
105+
REPORT_RESULT(success);
106+
#endif
107+
}
25108
}
26109

27110
// This callback will fire when the audio worklet thread has been initialized.
28111
void WebAudioWorkletThreadInitialized(EMSCRIPTEN_WEBAUDIO_T audioContext, bool success, void *userData) {
29112
printf("WebAudioWorkletThreadInitialized\n");
30-
emscripten_audio_worklet_post_function_vii(audioContext, MessageReceivedInAudioWorkletThread, /*a=*/42, /*b=*/9000);
113+
114+
// These event will fire callbacks on audio worklet thread.
115+
emscripten_audio_worklet_post_function_v(audioContext, v);
116+
emscripten_audio_worklet_post_function_vi(audioContext, vi, 1);
117+
emscripten_audio_worklet_post_function_vii(audioContext, vii, 2, 3);
118+
emscripten_audio_worklet_post_function_viii(audioContext, viii, 4, 5, 6);
119+
emscripten_audio_worklet_post_function_vd(audioContext, vd, 1.5);
120+
emscripten_audio_worklet_post_function_vdd(audioContext, vdd, 2.5, 3.5);
121+
emscripten_audio_worklet_post_function_vddd(audioContext, vddd, 4.5, 5.5, 6.5);
122+
emscripten_audio_worklet_post_function_sig(audioContext, viiiiiidddddd, "iiiiiidddddd", 10, 11, 12, 13, 14, 15, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5);
123+
emscripten_audio_worklet_post_function_v(audioContext, sided_test_finished);
31124
}
32125

33126
uint8_t wasmAudioWorkletStack[4096];

0 commit comments

Comments
 (0)