Skip to content

Commit d3db44c

Browse files
committed
Convert all remaining wasm worker tests to btest_exit. NFC
Amongst other things this allows all these test to be run under node.
1 parent f3a5481 commit d3db44c

30 files changed

+234
-133
lines changed

test/atomic/test_wait32_notify.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ void run_test() {
4444
// This test run in both wasm workers and pthreads mode
4545
#ifdef __EMSCRIPTEN_WASM_WORKERS__
4646

47+
void do_exit() {
48+
emscripten_out("do_exit");
49+
emscripten_terminate_all_wasm_workers();
50+
emscripten_force_exit(0);
51+
}
52+
4753
void worker_main() {
4854
run_test();
49-
50-
#ifdef REPORT_RESULT
51-
REPORT_RESULT(addr);
52-
#endif
55+
assert(addr == 3);
56+
emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit);
5357
}
5458

5559
#else
@@ -69,7 +73,7 @@ bool main_loop(double time, void *userData) {
6973
// Burn one second to make sure worker finishes its test.
7074
emscripten_out("main: seen worker running");
7175
double t0 = emscripten_performance_now();
72-
while(emscripten_performance_now() < t0 + 1000);
76+
while (emscripten_performance_now() < t0 + 1000);
7377

7478
// Wake the waiter
7579
emscripten_out("main: waking worker");
@@ -91,6 +95,7 @@ int main() {
9195
static char stack[1024];
9296
emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack));
9397
emscripten_wasm_worker_post_function_v(worker, worker_main);
98+
emscripten_runtime_keepalive_push();
9499
#else
95100
pthread_create(&t, NULL, thread_main, NULL);
96101
#endif

test/atomic/test_wait64_notify.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@ void run_test() {
4747

4848
char stack[1024];
4949

50+
void do_exit() {
51+
emscripten_out("do_exit");
52+
emscripten_terminate_all_wasm_workers();
53+
emscripten_force_exit(0);
54+
}
55+
5056
void worker_main() {
5157
run_test();
52-
#ifdef REPORT_RESULT
53-
REPORT_RESULT(addr >> 32);
54-
#endif
58+
assert(addr == 0x300000000ull);
59+
emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit);
5560
}
5661

5762
#else
@@ -91,6 +96,7 @@ int main() {
9196
#ifdef __EMSCRIPTEN_WASM_WORKERS__
9297
emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack));
9398
emscripten_wasm_worker_post_function_v(worker, worker_main);
99+
emscripten_runtime_keepalive_push();
94100
#else
95101
pthread_create(&t, NULL, thread_main, NULL);
96102
#endif

test/atomic/test_wait_async.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ void asyncWaitFinishedShouldBeOk(int32_t* ptr,
7373
assert(numCalled == 2);
7474
assert(waitResult == ATOMICS_WAIT_OK);
7575
emscripten_out("test finished");
76-
#ifdef REPORT_RESULT
77-
REPORT_RESULT(0);
78-
#endif
79-
#if !defined(__EMSCRIPTEN_WASM_WORKERS__)
76+
#ifdef __EMSCRIPTEN_WASM_WORKERS__
77+
emscripten_terminate_all_wasm_workers();
78+
#else
8079
pthread_join(t, NULL);
8180
#endif
81+
emscripten_force_exit(0);
8282
}
8383

8484
int main() {

test/test_browser.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5003,7 +5003,7 @@ def test_wasm_worker_hello_embedded(self):
50035003
'pthread': (['-pthread'],),
50045004
})
50055005
def test_wasm_worker_futex_wait(self, args):
5006-
self.btest('wasm_worker/wasm_worker_futex_wait.c', expected='0', args=['-sWASM_WORKERS=1', '-sASSERTIONS'] + args)
5006+
self.btest_exit('wasm_worker/wasm_worker_futex_wait.c', args=['-sWASM_WORKERS=1', '-sASSERTIONS'] + args)
50075007

50085008
# Tests Wasm Worker thread stack setup
50095009
@also_with_minimal_runtime
@@ -5013,48 +5013,48 @@ def test_wasm_worker_futex_wait(self, args):
50135013
'2': (2,),
50145014
})
50155015
def test_wasm_worker_thread_stack(self, mode):
5016-
self.btest('wasm_worker/thread_stack.c', expected='0', args=['-sWASM_WORKERS', f'-sSTACK_OVERFLOW_CHECK={mode}'])
5016+
self.btest_exit('wasm_worker/thread_stack.c', args=['-sWASM_WORKERS', f'-sSTACK_OVERFLOW_CHECK={mode}'])
50175017

50185018
# Tests emscripten_malloc_wasm_worker() and emscripten_current_thread_is_wasm_worker() functions
50195019
@also_with_minimal_runtime
50205020
def test_wasm_worker_malloc(self):
5021-
self.btest('wasm_worker/malloc_wasm_worker.c', expected='0', args=['-sWASM_WORKERS'])
5021+
self.btest_exit('wasm_worker/malloc_wasm_worker.c', args=['-sWASM_WORKERS'])
50225022

50235023
# Tests Wasm Worker+pthreads simultaneously
50245024
@also_with_minimal_runtime
50255025
def test_wasm_worker_and_pthreads(self):
5026-
self.btest('wasm_worker/wasm_worker_and_pthread.c', expected='0', args=['-sWASM_WORKERS', '-pthread'])
5026+
self.btest_exit('wasm_worker/wasm_worker_and_pthread.c', args=['-sWASM_WORKERS', '-pthread'])
50275027

50285028
# Tests emscripten_wasm_worker_self_id() function
50295029
@also_with_minimal_runtime
50305030
def test_wasm_worker_self_id(self):
5031-
self.btest('wasm_worker/wasm_worker_self_id.c', expected='0', args=['-sWASM_WORKERS'])
5031+
self.btest_exit('wasm_worker/wasm_worker_self_id.c', args=['-sWASM_WORKERS'])
50325032

50335033
# Tests direct Wasm Assembly .S file based TLS variables in Wasm Workers
50345034
@also_with_minimal_runtime
50355035
def test_wasm_worker_tls_wasm_assembly(self):
5036-
self.btest('wasm_worker/wasm_worker_tls_wasm_assembly.c',
5037-
expected='42', args=['-sWASM_WORKERS', test_file('wasm_worker/wasm_worker_tls_wasm_assembly.S')])
5036+
self.btest_exit('wasm_worker/wasm_worker_tls_wasm_assembly.c',
5037+
args=['-sWASM_WORKERS', test_file('wasm_worker/wasm_worker_tls_wasm_assembly.S')])
50385038

50395039
# Tests C++11 keyword thread_local for TLS in Wasm Workers
50405040
@also_with_minimal_runtime
50415041
def test_wasm_worker_cpp11_thread_local(self):
5042-
self.btest('wasm_worker/cpp11_thread_local.cpp', expected='42', args=['-sWASM_WORKERS'])
5042+
self.btest_exit('wasm_worker/cpp11_thread_local.cpp', args=['-sWASM_WORKERS'])
50435043

50445044
# Tests C11 keyword _Thread_local for TLS in Wasm Workers
50455045
@also_with_minimal_runtime
50465046
def test_wasm_worker_c11__Thread_local(self):
5047-
self.btest('wasm_worker/c11__Thread_local.c', expected='42', args=['-sWASM_WORKERS', '-std=gnu11']) # Cannot test C11 - because of EM_ASM must test Gnu11.
5047+
self.btest_exit('wasm_worker/c11__Thread_local.c', args=['-sWASM_WORKERS', '-std=gnu11']) # Cannot test C11 - because of EM_ASM must test Gnu11.
50485048

50495049
# Tests GCC specific extension keyword __thread for TLS in Wasm Workers
50505050
@also_with_minimal_runtime
50515051
def test_wasm_worker_gcc___thread(self):
5052-
self.btest('wasm_worker/gcc___Thread.c', expected='42', args=['-sWASM_WORKERS', '-std=gnu11'])
5052+
self.btest_exit('wasm_worker/gcc___Thread.c', args=['-sWASM_WORKERS', '-std=gnu11'])
50535053

50545054
# Tests emscripten_wasm_worker_sleep()
50555055
@also_with_minimal_runtime
50565056
def test_wasm_worker_sleep(self):
5057-
self.btest('wasm_worker/wasm_worker_sleep.c', expected='1', args=['-sWASM_WORKERS'])
5057+
self.btest_exit('wasm_worker/wasm_worker_sleep.c', args=['-sWASM_WORKERS'])
50585058

50595059
# Tests emscripten_terminate_wasm_worker()
50605060
@also_with_minimal_runtime
@@ -5064,71 +5064,70 @@ def test_wasm_worker_terminate(self):
50645064
# Tests emscripten_terminate_all_wasm_workers()
50655065
@also_with_minimal_runtime
50665066
def test_wasm_worker_terminate_all(self):
5067-
self.set_setting('WASM_WORKERS')
50685067
# Test uses the dynCall library function in its EM_ASM code
50695068
self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$dynCall'])
5070-
self.btest('wasm_worker/terminate_all_wasm_workers.c', expected='0')
5069+
self.btest_exit('wasm_worker/terminate_all_wasm_workers.c', args=['-sWASM_WORKERS'])
50715070

50725071
# Tests emscripten_wasm_worker_post_function_*() API
50735072
@also_with_minimal_runtime
50745073
def test_wasm_worker_post_function(self):
5075-
self.btest('wasm_worker/post_function.c', expected='8', args=['-sWASM_WORKERS'])
5074+
self.btest_exit('wasm_worker/post_function.c', args=['-sWASM_WORKERS'])
50765075

50775076
# Tests emscripten_wasm_worker_post_function_*() API and EMSCRIPTEN_WASM_WORKER_ID_PARENT
50785077
# to send a message back from Worker to its parent thread.
50795078
@also_with_minimal_runtime
50805079
def test_wasm_worker_post_function_to_main_thread(self):
5081-
self.btest('wasm_worker/post_function_to_main_thread.c', expected='10', args=['-sWASM_WORKERS'])
5080+
self.btest_exit('wasm_worker/post_function_to_main_thread.c', args=['-sWASM_WORKERS'])
50825081

50835082
# Tests emscripten_navigator_hardware_concurrency() and emscripten_atomics_is_lock_free()
50845083
@also_with_minimal_runtime
50855084
def test_wasm_worker_hardware_concurrency_is_lock_free(self):
5086-
self.btest('wasm_worker/hardware_concurrency_is_lock_free.c', expected='0', args=['-sWASM_WORKERS'])
5085+
self.btest_exit('wasm_worker/hardware_concurrency_is_lock_free.c', args=['-sWASM_WORKERS'])
50875086

50885087
# Tests emscripten_atomic_wait_u32() and emscripten_atomic_notify() functions.
50895088
@also_with_minimal_runtime
50905089
def test_wasm_worker_wait32_notify(self):
5091-
self.btest('atomic/test_wait32_notify.c', expected='3', args=['-sWASM_WORKERS'])
5090+
self.btest_exit('atomic/test_wait32_notify.c', args=['-sWASM_WORKERS'])
50925091

50935092
# Tests emscripten_atomic_wait_u64() and emscripten_atomic_notify() functions.
50945093
@also_with_minimal_runtime
50955094
def test_wasm_worker_wait64_notify(self):
5096-
self.btest('atomic/test_wait64_notify.c', expected='3', args=['-sWASM_WORKERS'])
5095+
self.btest_exit('atomic/test_wait64_notify.c', args=['-sWASM_WORKERS'])
50975096

50985097
# Tests emscripten_atomic_wait_async() function.
50995098
@also_with_minimal_runtime
51005099
def test_wasm_worker_wait_async(self):
5101-
self.btest('atomic/test_wait_async.c', expected='0', args=['-sWASM_WORKERS'])
5100+
self.btest_exit('atomic/test_wait_async.c', args=['-sWASM_WORKERS'])
51025101

51035102
# Tests emscripten_atomic_cancel_wait_async() function.
51045103
@also_with_minimal_runtime
51055104
def test_wasm_worker_cancel_wait_async(self):
5106-
self.btest('wasm_worker/cancel_wait_async.c', expected='1', args=['-sWASM_WORKERS'])
5105+
self.btest_exit('wasm_worker/cancel_wait_async.c', args=['-sWASM_WORKERS'])
51075106

51085107
# Tests emscripten_atomic_cancel_all_wait_asyncs() function.
51095108
@also_with_minimal_runtime
51105109
def test_wasm_worker_cancel_all_wait_asyncs(self):
5111-
self.btest('wasm_worker/cancel_all_wait_asyncs.c', expected='1', args=['-sWASM_WORKERS'])
5110+
self.btest_exit('wasm_worker/cancel_all_wait_asyncs.c', args=['-sWASM_WORKERS'])
51125111

51135112
# Tests emscripten_atomic_cancel_all_wait_asyncs_at_address() function.
51145113
@also_with_minimal_runtime
51155114
def test_wasm_worker_cancel_all_wait_asyncs_at_address(self):
5116-
self.btest('wasm_worker/cancel_all_wait_asyncs_at_address.c', expected='1', args=['-sWASM_WORKERS'])
5115+
self.btest_exit('wasm_worker/cancel_all_wait_asyncs_at_address.c', args=['-sWASM_WORKERS'])
51175116

51185117
# Tests emscripten_lock_init(), emscripten_lock_waitinf_acquire() and emscripten_lock_release()
51195118
@also_with_minimal_runtime
51205119
def test_wasm_worker_lock_waitinf(self):
5121-
self.btest('wasm_worker/lock_waitinf_acquire.c', expected='4000', args=['-sWASM_WORKERS'])
5120+
self.btest_exit('wasm_worker/lock_waitinf_acquire.c', args=['-sWASM_WORKERS'])
51225121

51235122
# Tests emscripten_lock_wait_acquire() and emscripten_lock_try_acquire() in Worker.
51245123
@also_with_minimal_runtime
51255124
def test_wasm_worker_lock_wait(self):
5126-
self.btest('wasm_worker/lock_wait_acquire.c', expected='0', args=['-sWASM_WORKERS'])
5125+
self.btest_exit('wasm_worker/lock_wait_acquire.c', args=['-sWASM_WORKERS'])
51275126

51285127
# Tests emscripten_lock_wait_acquire() between two Wasm Workers.
51295128
@also_with_minimal_runtime
51305129
def test_wasm_worker_lock_wait2(self):
5131-
self.btest('wasm_worker/lock_wait_acquire2.c', expected='0', args=['-sWASM_WORKERS'])
5130+
self.btest_exit('wasm_worker/lock_wait_acquire2.c', args=['-sWASM_WORKERS'])
51325131

51335132
# Tests emscripten_lock_async_acquire() function.
51345133
@also_with_minimal_runtime
@@ -5138,12 +5137,12 @@ def test_wasm_worker_lock_async_acquire(self):
51385137
# Tests emscripten_lock_busyspin_wait_acquire() in Worker and main thread.
51395138
@also_with_minimal_runtime
51405139
def test_wasm_worker_lock_busyspin_wait(self):
5141-
self.btest('wasm_worker/lock_busyspin_wait_acquire.c', expected='0', args=['-sWASM_WORKERS'])
5140+
self.btest_exit('wasm_worker/lock_busyspin_wait_acquire.c', args=['-sWASM_WORKERS'])
51425141

51435142
# Tests emscripten_lock_busyspin_waitinf_acquire() in Worker and main thread.
51445143
@also_with_minimal_runtime
51455144
def test_wasm_worker_lock_busyspin_waitinf(self):
5146-
self.btest('wasm_worker/lock_busyspin_waitinf_acquire.c', expected='1', args=['-sWASM_WORKERS'])
5145+
self.btest_exit('wasm_worker/lock_busyspin_waitinf_acquire.c', args=['-sWASM_WORKERS'])
51475146

51485147
# Tests that proxied JS functions cannot be called from Wasm Workers
51495148
@also_with_minimal_runtime
@@ -5152,18 +5151,18 @@ def test_wasm_worker_no_proxied_js_functions(self):
51525151
self.set_setting('ASSERTIONS')
51535152
# Test uses the dynCall library function in its EM_ASM code
51545153
self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$dynCall'])
5155-
self.btest('wasm_worker/no_proxied_js_functions.c', expected='0',
5156-
args=['--js-library', test_file('wasm_worker/no_proxied_js_functions.js')])
5154+
self.btest_exit('wasm_worker/no_proxied_js_functions.c',
5155+
args=['--js-library', test_file('wasm_worker/no_proxied_js_functions.js')])
51575156

51585157
# Tests emscripten_semaphore_init(), emscripten_semaphore_waitinf_acquire() and emscripten_semaphore_release()
51595158
@also_with_minimal_runtime
51605159
def test_wasm_worker_semaphore_waitinf_acquire(self):
5161-
self.btest('wasm_worker/semaphore_waitinf_acquire.c', expected='0', args=['-sWASM_WORKERS'])
5160+
self.btest_exit('wasm_worker/semaphore_waitinf_acquire.c', args=['-sWASM_WORKERS'])
51625161

51635162
# Tests emscripten_semaphore_try_acquire() on the main thread
51645163
@also_with_minimal_runtime
51655164
def test_wasm_worker_semaphore_try_acquire(self):
5166-
self.btest('wasm_worker/semaphore_try_acquire.c', expected='0', args=['-sWASM_WORKERS'])
5165+
self.btest_exit('wasm_worker/semaphore_try_acquire.c', args=['-sWASM_WORKERS'])
51675166

51685167
# Tests that calling any proxied function in a Wasm Worker will abort at runtime when ASSERTIONS are enabled.
51695168
def test_wasm_worker_proxied_function(self):

test/test_core.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9647,23 +9647,16 @@ def test_emscripten_async_load_script(self):
96479647
self.run_process([FILE_PACKAGER, 'test.data', '--preload', 'file1.txt', 'file2.txt', '--from-emcc', '--js-output=script2.js'])
96489648
self.do_runf('test_emscripten_async_load_script.c', emcc_args=['-sFORCE_FILESYSTEM'])
96499649

9650-
def prep_wasm_worker_in_node(self):
9651-
# Auto exit after 3 seconds in Nodejs environment to get WASM Worker stdout
9652-
self.add_pre_run("setTimeout(()=>process.exit(), 3000);")
9653-
96549650
@node_pthreads
96559651
def test_wasm_worker_hello(self):
9656-
self.prep_wasm_worker_in_node()
96579652
self.do_run_in_out_file_test('wasm_worker/hello_wasm_worker.c', emcc_args=['-sWASM_WORKERS'])
96589653

96599654
@node_pthreads
96609655
def test_wasm_worker_malloc(self):
9661-
self.prep_wasm_worker_in_node()
96629656
self.do_run_in_out_file_test('wasm_worker/malloc_wasm_worker.c', emcc_args=['-sWASM_WORKERS'])
96639657

96649658
@node_pthreads
96659659
def test_wasm_worker_wait_async(self):
9666-
self.prep_wasm_worker_in_node()
96679660
self.do_runf('atomic/test_wait_async.c', emcc_args=['-sWASM_WORKERS'])
96689661

96699662

test/wasm_worker/c11__Thread_local.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <emscripten/console.h>
2+
#include <emscripten/emscripten.h>
23
#include <emscripten/wasm_worker.h>
34
#include <assert.h>
45
#include <threads.h>
@@ -8,9 +9,9 @@ _Thread_local int __attribute__((aligned(64))) tls = 1;
89
void main_thread_func() {
910
assert(!emscripten_current_thread_is_wasm_worker());
1011
emscripten_outf("%d", tls);
11-
#ifdef REPORT_RESULT
12-
REPORT_RESULT(tls);
13-
#endif
12+
assert(tls == 42);
13+
emscripten_terminate_all_wasm_workers();
14+
emscripten_force_exit(0);
1415
}
1516

1617
void worker_main() {
@@ -32,4 +33,5 @@ int main() {
3233
tls = 42;
3334
emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack));
3435
emscripten_wasm_worker_post_function_v(worker, worker_main);
36+
emscripten_exit_with_live_runtime();
3537
}

test/wasm_worker/cancel_all_wait_asyncs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT
1717

1818
void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData) {
1919
emscripten_out("asyncWaitFinishedShouldBeCalled");
20-
#ifdef REPORT_RESULT
21-
REPORT_RESULT(testSucceeded);
22-
#endif
20+
assert(testSucceeded);
21+
emscripten_force_exit(0);
2322
}
2423

2524
int main() {
@@ -70,4 +69,5 @@ int main() {
7069
emscripten_out("Notifying an async wait after value changing should trigger the callback");
7170
numWoken = emscripten_atomic_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
7271
#endif
72+
emscripten_exit_with_live_runtime();
7373
}

test/wasm_worker/cancel_all_wait_asyncs_at_address.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT
1717

1818
void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData) {
1919
emscripten_out("asyncWaitFinishedShouldBeCalled");
20-
#ifdef REPORT_RESULT
21-
REPORT_RESULT(testSucceeded);
22-
#endif
20+
assert(testSucceeded);
21+
emscripten_force_exit(0);
2322
}
2423

2524
int main() {
@@ -74,4 +73,6 @@ int main() {
7473
emscripten_out("Notifying an async wait after value changing should trigger the callback");
7574
numWoken = emscripten_atomic_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
7675
#endif
76+
77+
emscripten_exit_with_live_runtime();
7778
}

test/wasm_worker/cancel_wait_async.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT
1717

1818
void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData) {
1919
emscripten_out("asyncWaitFinishedShouldBeCalled");
20-
#ifdef REPORT_RESULT
21-
REPORT_RESULT(testSucceeded);
22-
#endif
20+
assert(testSucceeded);
21+
emscripten_force_exit(0);
2322
}
2423

2524
int main() {
@@ -62,4 +61,5 @@ int main() {
6261
emscripten_out("Notifying an async wait after value changing should trigger the callback");
6362
numWoken = emscripten_atomic_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS);
6463
#endif
64+
emscripten_exit_with_live_runtime();
6565
}

0 commit comments

Comments
 (0)