Skip to content

Commit 2dfefb1

Browse files
committed
Extended tests to support MEMORY64 options
1 parent 8ea671d commit 2dfefb1

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

test/webaudio/audioworklet_test_shared.inc

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// Shared code for the audio worklet mixer tests.
22

3+
// Defines an offset in GB from where to start the stack (for testing >2GB and
4+
// >4GB heaps). See _main_().
5+
#ifndef TEST_OFFSET_GB
6+
#define TEST_OFFSET_GB 0
7+
#endif
8+
39
// Helper for MEMORY64 to cast an audio context or type to a void*
410
#define WA_2_VOIDP(ctx) ((void*) (intptr_t) ctx)
511
// Helper for MEMORY64 to cast a void* to an audio context or type
@@ -28,10 +34,10 @@ EM_JS(EMSCRIPTEN_WEBAUDIO_T, createTrack, (EMSCRIPTEN_WEBAUDIO_T ctxID, const ch
2834
var context = emscriptenGetAudioObject(ctxID);
2935
if (context) {
3036
var audio = document.createElement('audio');
31-
32-
// Workaround for UTF8ToString() needing a JS number
33-
url = Number(BigInt.asUintN(53, url));
34-
37+
#if __wasm64__
38+
// Workaround for UTF8ToString() needing a JS number and from64() not working in EM_JS
39+
url = Number(url);
40+
#endif
3541
audio.src = UTF8ToString(url);
3642
audio.loop = looping;
3743
var track = context.createMediaElementSource(audio);
@@ -86,18 +92,43 @@ void initialised(EMSCRIPTEN_WEBAUDIO_T context, bool success, void* data) {
8692
emscripten_create_wasm_audio_worklet_processor_async(context, &opts, &processorCreated, NULL);
8793
}
8894

89-
9095
// Common entry point for the mixer tests
91-
int main() {
92-
char* const emptySpace = malloc(2147483648);
93-
(void) emptySpace;
94-
char* const workletStack = malloc(AUDIO_STACK_SIZE);
95-
//static char workletStack[AUDIO_STACK_SIZE];
96+
// stackSize - audio worklet stack size in bytes
97+
// return true if the requested memory could be allocated
98+
bool _main_(int stackSize) {
99+
// Optional empty space before the audio worklet's stack
100+
#if TEST_OFFSET_GB > 0
101+
char* const emptySpace = malloc(1073741824L * TEST_OFFSET_GB);
102+
if (emptySpace) {
103+
printf("Empty space allocated (%dGB)\n", TEST_OFFSET_GB);
104+
} else {
105+
printf("Failed to allocate the required memory offset\n");
106+
return false;
107+
}
108+
#endif
109+
110+
char* const workletStack = memalign(16, stackSize);
111+
if (!workletStack) {
112+
printf("Failed to allocate the required worklet stack\n");
113+
return false;
114+
}
115+
116+
#if TEST_OFFSET_GB > 0
117+
free(emptySpace);
118+
#endif
119+
96120
EMSCRIPTEN_WEBAUDIO_T context = emscripten_create_audio_context(NULL);
97-
emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, AUDIO_STACK_SIZE, &initialised, NULL);
121+
emscripten_start_wasm_audio_worklet_thread_async(context, workletStack, stackSize, &initialised, NULL);
98122
#ifndef BROWSER_TEST
99123
// Special case: browser tests need to exit instantly, interactive tests need to wait
100124
emscripten_runtime_keepalive_push();
101125
#endif
102-
return 0;
126+
return true;
127+
}
128+
129+
int main() {
130+
if (_main_(AUDIO_STACK_SIZE)) {
131+
return EXIT_SUCCESS;
132+
}
133+
return EXIT_FAILURE;
103134
}

0 commit comments

Comments
 (0)