diff --git a/test/atomic/test_wait32_notify.c b/test/atomic/test_wait32_notify.c index 52840c17621e7..86ec05cf0d7d7 100644 --- a/test/atomic/test_wait32_notify.c +++ b/test/atomic/test_wait32_notify.c @@ -44,12 +44,16 @@ void run_test() { // This test run in both wasm workers and pthreads mode #ifdef __EMSCRIPTEN_WASM_WORKERS__ +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { run_test(); - -#ifdef REPORT_RESULT - REPORT_RESULT(addr); -#endif + assert(addr == 3); + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } #else @@ -69,7 +73,7 @@ bool main_loop(double time, void *userData) { // Burn one second to make sure worker finishes its test. emscripten_out("main: seen worker running"); double t0 = emscripten_performance_now(); - while(emscripten_performance_now() < t0 + 1000); + while (emscripten_performance_now() < t0 + 1000); // Wake the waiter emscripten_out("main: waking worker"); @@ -91,6 +95,7 @@ int main() { static char stack[1024]; emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_runtime_keepalive_push(); #else pthread_create(&t, NULL, thread_main, NULL); #endif diff --git a/test/atomic/test_wait64_notify.c b/test/atomic/test_wait64_notify.c index 9a885cf3a48f9..1d0baba6e7931 100644 --- a/test/atomic/test_wait64_notify.c +++ b/test/atomic/test_wait64_notify.c @@ -47,11 +47,16 @@ void run_test() { char stack[1024]; +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { run_test(); -#ifdef REPORT_RESULT - REPORT_RESULT(addr >> 32); -#endif + assert(addr == 0x300000000ull); + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } #else @@ -91,6 +96,7 @@ int main() { #ifdef __EMSCRIPTEN_WASM_WORKERS__ emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_runtime_keepalive_push(); #else pthread_create(&t, NULL, thread_main, NULL); #endif diff --git a/test/atomic/test_wait_async.c b/test/atomic/test_wait_async.c index 0d9555a90c15f..2b6aa7f977c16 100644 --- a/test/atomic/test_wait_async.c +++ b/test/atomic/test_wait_async.c @@ -73,12 +73,12 @@ void asyncWaitFinishedShouldBeOk(int32_t* ptr, assert(numCalled == 2); assert(waitResult == ATOMICS_WAIT_OK); emscripten_out("test finished"); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif -#if !defined(__EMSCRIPTEN_WASM_WORKERS__) +#ifdef __EMSCRIPTEN_WASM_WORKERS__ + emscripten_terminate_all_wasm_workers(); +#else pthread_join(t, NULL); #endif + emscripten_force_exit(0); } int main() { diff --git a/test/test_browser.py b/test/test_browser.py index 568c2245ce2ba..2aa4596a917af 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5003,7 +5003,7 @@ def test_wasm_worker_hello_embedded(self): 'pthread': (['-pthread'],), }) def test_wasm_worker_futex_wait(self, args): - self.btest('wasm_worker/wasm_worker_futex_wait.c', expected='0', args=['-sWASM_WORKERS=1', '-sASSERTIONS'] + args) + self.btest_exit('wasm_worker/wasm_worker_futex_wait.c', args=['-sWASM_WORKERS=1', '-sASSERTIONS'] + args) # Tests Wasm Worker thread stack setup @also_with_minimal_runtime @@ -5013,48 +5013,48 @@ def test_wasm_worker_futex_wait(self, args): '2': (2,), }) def test_wasm_worker_thread_stack(self, mode): - self.btest('wasm_worker/thread_stack.c', expected='0', args=['-sWASM_WORKERS', f'-sSTACK_OVERFLOW_CHECK={mode}']) + self.btest_exit('wasm_worker/thread_stack.c', args=['-sWASM_WORKERS', f'-sSTACK_OVERFLOW_CHECK={mode}']) # Tests emscripten_malloc_wasm_worker() and emscripten_current_thread_is_wasm_worker() functions @also_with_minimal_runtime def test_wasm_worker_malloc(self): - self.btest('wasm_worker/malloc_wasm_worker.c', expected='0', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/malloc_wasm_worker.c', args=['-sWASM_WORKERS']) # Tests Wasm Worker+pthreads simultaneously @also_with_minimal_runtime def test_wasm_worker_and_pthreads(self): - self.btest('wasm_worker/wasm_worker_and_pthread.c', expected='0', args=['-sWASM_WORKERS', '-pthread']) + self.btest_exit('wasm_worker/wasm_worker_and_pthread.c', args=['-sWASM_WORKERS', '-pthread']) # Tests emscripten_wasm_worker_self_id() function @also_with_minimal_runtime def test_wasm_worker_self_id(self): - self.btest('wasm_worker/wasm_worker_self_id.c', expected='0', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/wasm_worker_self_id.c', args=['-sWASM_WORKERS']) # Tests direct Wasm Assembly .S file based TLS variables in Wasm Workers @also_with_minimal_runtime def test_wasm_worker_tls_wasm_assembly(self): - self.btest('wasm_worker/wasm_worker_tls_wasm_assembly.c', - expected='42', args=['-sWASM_WORKERS', test_file('wasm_worker/wasm_worker_tls_wasm_assembly.S')]) + self.btest_exit('wasm_worker/wasm_worker_tls_wasm_assembly.c', + args=['-sWASM_WORKERS', test_file('wasm_worker/wasm_worker_tls_wasm_assembly.S')]) # Tests C++11 keyword thread_local for TLS in Wasm Workers @also_with_minimal_runtime def test_wasm_worker_cpp11_thread_local(self): - self.btest('wasm_worker/cpp11_thread_local.cpp', expected='42', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/cpp11_thread_local.cpp', args=['-sWASM_WORKERS']) # Tests C11 keyword _Thread_local for TLS in Wasm Workers @also_with_minimal_runtime def test_wasm_worker_c11__Thread_local(self): - 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. + self.btest_exit('wasm_worker/c11__Thread_local.c', args=['-sWASM_WORKERS', '-std=gnu11']) # Cannot test C11 - because of EM_ASM must test Gnu11. # Tests GCC specific extension keyword __thread for TLS in Wasm Workers @also_with_minimal_runtime def test_wasm_worker_gcc___thread(self): - self.btest('wasm_worker/gcc___Thread.c', expected='42', args=['-sWASM_WORKERS', '-std=gnu11']) + self.btest_exit('wasm_worker/gcc___Thread.c', args=['-sWASM_WORKERS', '-std=gnu11']) # Tests emscripten_wasm_worker_sleep() @also_with_minimal_runtime def test_wasm_worker_sleep(self): - self.btest('wasm_worker/wasm_worker_sleep.c', expected='1', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/wasm_worker_sleep.c', args=['-sWASM_WORKERS']) # Tests emscripten_terminate_wasm_worker() @also_with_minimal_runtime @@ -5064,71 +5064,70 @@ def test_wasm_worker_terminate(self): # Tests emscripten_terminate_all_wasm_workers() @also_with_minimal_runtime def test_wasm_worker_terminate_all(self): - self.set_setting('WASM_WORKERS') # Test uses the dynCall library function in its EM_ASM code self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$dynCall']) - self.btest('wasm_worker/terminate_all_wasm_workers.c', expected='0') + self.btest_exit('wasm_worker/terminate_all_wasm_workers.c', args=['-sWASM_WORKERS']) # Tests emscripten_wasm_worker_post_function_*() API @also_with_minimal_runtime def test_wasm_worker_post_function(self): - self.btest('wasm_worker/post_function.c', expected='8', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/post_function.c', args=['-sWASM_WORKERS']) # Tests emscripten_wasm_worker_post_function_*() API and EMSCRIPTEN_WASM_WORKER_ID_PARENT # to send a message back from Worker to its parent thread. @also_with_minimal_runtime def test_wasm_worker_post_function_to_main_thread(self): - self.btest('wasm_worker/post_function_to_main_thread.c', expected='10', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/post_function_to_main_thread.c', args=['-sWASM_WORKERS']) # Tests emscripten_navigator_hardware_concurrency() and emscripten_atomics_is_lock_free() @also_with_minimal_runtime def test_wasm_worker_hardware_concurrency_is_lock_free(self): - self.btest('wasm_worker/hardware_concurrency_is_lock_free.c', expected='0', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/hardware_concurrency_is_lock_free.c', args=['-sWASM_WORKERS']) # Tests emscripten_atomic_wait_u32() and emscripten_atomic_notify() functions. @also_with_minimal_runtime def test_wasm_worker_wait32_notify(self): - self.btest('atomic/test_wait32_notify.c', expected='3', args=['-sWASM_WORKERS']) + self.btest_exit('atomic/test_wait32_notify.c', args=['-sWASM_WORKERS']) # Tests emscripten_atomic_wait_u64() and emscripten_atomic_notify() functions. @also_with_minimal_runtime def test_wasm_worker_wait64_notify(self): - self.btest('atomic/test_wait64_notify.c', expected='3', args=['-sWASM_WORKERS']) + self.btest_exit('atomic/test_wait64_notify.c', args=['-sWASM_WORKERS']) # Tests emscripten_atomic_wait_async() function. @also_with_minimal_runtime def test_wasm_worker_wait_async(self): - self.btest('atomic/test_wait_async.c', expected='0', args=['-sWASM_WORKERS']) + self.btest_exit('atomic/test_wait_async.c', args=['-sWASM_WORKERS']) # Tests emscripten_atomic_cancel_wait_async() function. @also_with_minimal_runtime def test_wasm_worker_cancel_wait_async(self): - self.btest('wasm_worker/cancel_wait_async.c', expected='1', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/cancel_wait_async.c', args=['-sWASM_WORKERS']) # Tests emscripten_atomic_cancel_all_wait_asyncs() function. @also_with_minimal_runtime def test_wasm_worker_cancel_all_wait_asyncs(self): - self.btest('wasm_worker/cancel_all_wait_asyncs.c', expected='1', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/cancel_all_wait_asyncs.c', args=['-sWASM_WORKERS']) # Tests emscripten_atomic_cancel_all_wait_asyncs_at_address() function. @also_with_minimal_runtime def test_wasm_worker_cancel_all_wait_asyncs_at_address(self): - self.btest('wasm_worker/cancel_all_wait_asyncs_at_address.c', expected='1', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/cancel_all_wait_asyncs_at_address.c', args=['-sWASM_WORKERS']) # Tests emscripten_lock_init(), emscripten_lock_waitinf_acquire() and emscripten_lock_release() @also_with_minimal_runtime def test_wasm_worker_lock_waitinf(self): - self.btest('wasm_worker/lock_waitinf_acquire.c', expected='4000', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/lock_waitinf_acquire.c', args=['-sWASM_WORKERS']) # Tests emscripten_lock_wait_acquire() and emscripten_lock_try_acquire() in Worker. @also_with_minimal_runtime def test_wasm_worker_lock_wait(self): - self.btest('wasm_worker/lock_wait_acquire.c', expected='0', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/lock_wait_acquire.c', args=['-sWASM_WORKERS']) # Tests emscripten_lock_wait_acquire() between two Wasm Workers. @also_with_minimal_runtime def test_wasm_worker_lock_wait2(self): - self.btest('wasm_worker/lock_wait_acquire2.c', expected='0', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/lock_wait_acquire2.c', args=['-sWASM_WORKERS']) # Tests emscripten_lock_async_acquire() function. @also_with_minimal_runtime @@ -5138,12 +5137,12 @@ def test_wasm_worker_lock_async_acquire(self): # Tests emscripten_lock_busyspin_wait_acquire() in Worker and main thread. @also_with_minimal_runtime def test_wasm_worker_lock_busyspin_wait(self): - self.btest('wasm_worker/lock_busyspin_wait_acquire.c', expected='0', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/lock_busyspin_wait_acquire.c', args=['-sWASM_WORKERS']) # Tests emscripten_lock_busyspin_waitinf_acquire() in Worker and main thread. @also_with_minimal_runtime def test_wasm_worker_lock_busyspin_waitinf(self): - self.btest('wasm_worker/lock_busyspin_waitinf_acquire.c', expected='1', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/lock_busyspin_waitinf_acquire.c', args=['-sWASM_WORKERS']) # Tests that proxied JS functions cannot be called from Wasm Workers @also_with_minimal_runtime @@ -5152,18 +5151,18 @@ def test_wasm_worker_no_proxied_js_functions(self): self.set_setting('ASSERTIONS') # Test uses the dynCall library function in its EM_ASM code self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$dynCall']) - self.btest('wasm_worker/no_proxied_js_functions.c', expected='0', - args=['--js-library', test_file('wasm_worker/no_proxied_js_functions.js')]) + self.btest_exit('wasm_worker/no_proxied_js_functions.c', + args=['--js-library', test_file('wasm_worker/no_proxied_js_functions.js')]) # Tests emscripten_semaphore_init(), emscripten_semaphore_waitinf_acquire() and emscripten_semaphore_release() @also_with_minimal_runtime def test_wasm_worker_semaphore_waitinf_acquire(self): - self.btest('wasm_worker/semaphore_waitinf_acquire.c', expected='0', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/semaphore_waitinf_acquire.c', args=['-sWASM_WORKERS']) # Tests emscripten_semaphore_try_acquire() on the main thread @also_with_minimal_runtime def test_wasm_worker_semaphore_try_acquire(self): - self.btest('wasm_worker/semaphore_try_acquire.c', expected='0', args=['-sWASM_WORKERS']) + self.btest_exit('wasm_worker/semaphore_try_acquire.c', args=['-sWASM_WORKERS']) # Tests that calling any proxied function in a Wasm Worker will abort at runtime when ASSERTIONS are enabled. def test_wasm_worker_proxied_function(self): diff --git a/test/test_core.py b/test/test_core.py index f6b746780beb3..24d5133b44ee9 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -9647,23 +9647,16 @@ def test_emscripten_async_load_script(self): self.run_process([FILE_PACKAGER, 'test.data', '--preload', 'file1.txt', 'file2.txt', '--from-emcc', '--js-output=script2.js']) self.do_runf('test_emscripten_async_load_script.c', emcc_args=['-sFORCE_FILESYSTEM']) - def prep_wasm_worker_in_node(self): - # Auto exit after 3 seconds in Nodejs environment to get WASM Worker stdout - self.add_pre_run("setTimeout(()=>process.exit(), 3000);") - @node_pthreads def test_wasm_worker_hello(self): - self.prep_wasm_worker_in_node() self.do_run_in_out_file_test('wasm_worker/hello_wasm_worker.c', emcc_args=['-sWASM_WORKERS']) @node_pthreads def test_wasm_worker_malloc(self): - self.prep_wasm_worker_in_node() self.do_run_in_out_file_test('wasm_worker/malloc_wasm_worker.c', emcc_args=['-sWASM_WORKERS']) @node_pthreads def test_wasm_worker_wait_async(self): - self.prep_wasm_worker_in_node() self.do_runf('atomic/test_wait_async.c', emcc_args=['-sWASM_WORKERS']) diff --git a/test/wasm_worker/c11__Thread_local.c b/test/wasm_worker/c11__Thread_local.c index 58875dead0649..ce9760ff2a74b 100644 --- a/test/wasm_worker/c11__Thread_local.c +++ b/test/wasm_worker/c11__Thread_local.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -8,9 +9,9 @@ _Thread_local int __attribute__((aligned(64))) tls = 1; void main_thread_func() { assert(!emscripten_current_thread_is_wasm_worker()); emscripten_outf("%d", tls); -#ifdef REPORT_RESULT - REPORT_RESULT(tls); -#endif + assert(tls == 42); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); } void worker_main() { @@ -32,4 +33,5 @@ int main() { tls = 42; emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/cancel_all_wait_asyncs.c b/test/wasm_worker/cancel_all_wait_asyncs.c index 526fbb981dae3..3b01b775e88f9 100644 --- a/test/wasm_worker/cancel_all_wait_asyncs.c +++ b/test/wasm_worker/cancel_all_wait_asyncs.c @@ -17,9 +17,8 @@ void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData) { emscripten_out("asyncWaitFinishedShouldBeCalled"); -#ifdef REPORT_RESULT - REPORT_RESULT(testSucceeded); -#endif + assert(testSucceeded); + emscripten_force_exit(0); } int main() { @@ -70,4 +69,5 @@ int main() { emscripten_out("Notifying an async wait after value changing should trigger the callback"); numWoken = emscripten_atomic_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS); #endif + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/cancel_all_wait_asyncs_at_address.c b/test/wasm_worker/cancel_all_wait_asyncs_at_address.c index 83d0801de49d0..91c08540c1c60 100644 --- a/test/wasm_worker/cancel_all_wait_asyncs_at_address.c +++ b/test/wasm_worker/cancel_all_wait_asyncs_at_address.c @@ -17,9 +17,8 @@ void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData) { emscripten_out("asyncWaitFinishedShouldBeCalled"); -#ifdef REPORT_RESULT - REPORT_RESULT(testSucceeded); -#endif + assert(testSucceeded); + emscripten_force_exit(0); } int main() { @@ -74,4 +73,6 @@ int main() { emscripten_out("Notifying an async wait after value changing should trigger the callback"); numWoken = emscripten_atomic_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS); #endif + + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/cancel_wait_async.c b/test/wasm_worker/cancel_wait_async.c index 61b0f952803c9..dd047ff851e53 100644 --- a/test/wasm_worker/cancel_wait_async.c +++ b/test/wasm_worker/cancel_wait_async.c @@ -17,9 +17,8 @@ void asyncWaitFinishedShouldNotBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT void asyncWaitFinishedShouldBeCalled(int32_t *ptr, uint32_t val, ATOMICS_WAIT_RESULT_T waitResult, void *userData) { emscripten_out("asyncWaitFinishedShouldBeCalled"); -#ifdef REPORT_RESULT - REPORT_RESULT(testSucceeded); -#endif + assert(testSucceeded); + emscripten_force_exit(0); } int main() { @@ -62,4 +61,5 @@ int main() { emscripten_out("Notifying an async wait after value changing should trigger the callback"); numWoken = emscripten_atomic_notify((int32_t*)&addr, EMSCRIPTEN_NOTIFY_ALL_WAITERS); #endif + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/cpp11_thread_local.cpp b/test/wasm_worker/cpp11_thread_local.cpp index e726232fcc90a..02348df6b7ab3 100644 --- a/test/wasm_worker/cpp11_thread_local.cpp +++ b/test/wasm_worker/cpp11_thread_local.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -7,9 +8,9 @@ thread_local int tls = 1; void main_thread_func() { assert(!emscripten_current_thread_is_wasm_worker()); emscripten_outf("%d", tls); -#ifdef REPORT_RESULT - REPORT_RESULT(tls); -#endif + assert(tls == 42); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); } void worker_main() { @@ -29,4 +30,5 @@ int main() { tls = 42; emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/gcc___Thread.c b/test/wasm_worker/gcc___Thread.c index 1d065377f6bb1..d7c828bcb06ad 100644 --- a/test/wasm_worker/gcc___Thread.c +++ b/test/wasm_worker/gcc___Thread.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -8,9 +9,9 @@ __thread int tls = 1; void main_thread_func() { assert(!emscripten_current_thread_is_wasm_worker()); emscripten_outf("%d", tls); -#ifdef REPORT_RESULT - REPORT_RESULT(tls); -#endif + assert(tls == 42); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); } void worker_main() { @@ -30,4 +31,5 @@ int main() { tls = 42; emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/hardware_concurrency_is_lock_free.c b/test/wasm_worker/hardware_concurrency_is_lock_free.c index f02b0c6718b55..430e0146e2ea6 100644 --- a/test/wasm_worker/hardware_concurrency_is_lock_free.c +++ b/test/wasm_worker/hardware_concurrency_is_lock_free.c @@ -1,4 +1,5 @@ -#include +#include +#include #include #include @@ -16,11 +17,15 @@ void test() { assert(!emscripten_atomics_is_lock_free(31)); } +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { test(); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } char stack[1024]; @@ -29,4 +34,5 @@ int main() { test(); emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/lock_busyspin_wait_acquire.c b/test/wasm_worker/lock_busyspin_wait_acquire.c index 165a4fdb6df62..cad4e96ea356d 100644 --- a/test/wasm_worker/lock_busyspin_wait_acquire.c +++ b/test/wasm_worker/lock_busyspin_wait_acquire.c @@ -38,11 +38,15 @@ void test() { emscripten_lock_release(&lock); } +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { test(); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } char stack[1024]; @@ -52,4 +56,5 @@ int main() { emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/lock_busyspin_waitinf_acquire.c b/test/wasm_worker/lock_busyspin_waitinf_acquire.c index 8a42a168420e1..fbca8e3752de1 100644 --- a/test/wasm_worker/lock_busyspin_waitinf_acquire.c +++ b/test/wasm_worker/lock_busyspin_waitinf_acquire.c @@ -10,12 +10,16 @@ emscripten_lock_t lock = EMSCRIPTEN_LOCK_T_STATIC_INITIALIZER; volatile int sharedState = 0; +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { emscripten_lock_busyspin_waitinf_acquire(&lock); emscripten_atomic_add_u32((void*)&sharedState, 1); -#ifdef REPORT_RESULT - REPORT_RESULT(sharedState); -#endif + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } char stack[1024]; @@ -36,4 +40,6 @@ int main() { emscripten_wasm_worker_post_function_v(worker, worker_main); emscripten_set_timeout(releaseLock, 1000, 0); + + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/lock_wait_acquire.c b/test/wasm_worker/lock_wait_acquire.c index e85dc1ad435ae..b05cd470163d5 100644 --- a/test/wasm_worker/lock_wait_acquire.c +++ b/test/wasm_worker/lock_wait_acquire.c @@ -8,6 +8,12 @@ emscripten_lock_t lock = EMSCRIPTEN_LOCK_T_STATIC_INITIALIZER; +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { // Expect no contention on free lock. bool success = emscripten_lock_wait_acquire(&lock, 0); @@ -40,9 +46,7 @@ void worker_main() { success = emscripten_lock_try_acquire(&lock); assert(success); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } char stack[1024]; @@ -50,4 +54,5 @@ char stack[1024]; int main() { emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/lock_wait_acquire2.c b/test/wasm_worker/lock_wait_acquire2.c index 196ca6502a553..5ae577b533899 100644 --- a/test/wasm_worker/lock_wait_acquire2.c +++ b/test/wasm_worker/lock_wait_acquire2.c @@ -21,6 +21,12 @@ void worker1_main() { emscripten_out("worker1 released lock"); } +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker2_main() { emscripten_out("worker2 main sleeping 500 msecs"); emscripten_wasm_worker_sleep(500 * 1000000ull); @@ -34,9 +40,7 @@ void worker2_main() { emscripten_out("worker2 wait_acquired lock"); assert(success); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } char stack1[1024]; @@ -47,4 +51,5 @@ int main() { emscripten_wasm_worker_t worker2 = emscripten_create_wasm_worker(stack2, sizeof(stack2)); emscripten_wasm_worker_post_function_v(worker1, worker1_main); emscripten_wasm_worker_post_function_v(worker2, worker2_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/lock_waitinf_acquire.c b/test/wasm_worker/lock_waitinf_acquire.c index b704011a3bdfc..e60dce7098720 100644 --- a/test/wasm_worker/lock_waitinf_acquire.c +++ b/test/wasm_worker/lock_waitinf_acquire.c @@ -15,12 +15,17 @@ volatile int sharedState1 = 1; volatile int numWorkersAlive = 0; +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void test_ended() { emscripten_outf("Worker %d last thread to finish. Reporting test end with sharedState0=%d, sharedState1=%d", emscripten_wasm_worker_self_id(), sharedState0, sharedState1); assert(sharedState0 == sharedState1 + 1 || sharedState1 == sharedState0 + 1); -#ifdef REPORT_RESULT - REPORT_RESULT(sharedState0); -#endif + assert(sharedState0 == 4000); + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } void worker_main() { @@ -62,4 +67,6 @@ int main() { emscripten_wasm_worker_t worker = emscripten_malloc_wasm_worker(1024); emscripten_wasm_worker_post_function_v(worker, worker_main); } + + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/malloc_wasm_worker.c b/test/wasm_worker/malloc_wasm_worker.c index e9939699bd9f4..3e9784be8d5da 100644 --- a/test/wasm_worker/malloc_wasm_worker.c +++ b/test/wasm_worker/malloc_wasm_worker.c @@ -5,12 +5,16 @@ // Test emscripten_malloc_wasm_worker() and emscripten_current_thread_is_wasm_worker() functions +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { emscripten_out("Hello from wasm worker!"); assert(emscripten_current_thread_is_wasm_worker()); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } int main() { @@ -18,4 +22,5 @@ int main() { emscripten_wasm_worker_t worker = emscripten_malloc_wasm_worker(/*stack size: */1024); assert(worker); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/no_proxied_js_functions.c b/test/wasm_worker/no_proxied_js_functions.c index 97b9351405262..ee91cec0a1b37 100644 --- a/test/wasm_worker/no_proxied_js_functions.c +++ b/test/wasm_worker/no_proxied_js_functions.c @@ -1,4 +1,5 @@ -#include +#include +#include #include #include @@ -32,11 +33,15 @@ void test() { proxied_js_function(); } +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { assert(should_throw(test)); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } char stack[1024]; @@ -45,4 +50,5 @@ int main() { proxied_js_function(); emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/post_function.c b/test/wasm_worker/post_function.c index 29216b3794b3c..f9043c248ebcc 100644 --- a/test/wasm_worker/post_function.c +++ b/test/wasm_worker/post_function.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -70,10 +71,15 @@ void viiiiiidddddd(int a, int b, int c, int d, int e, int f, double g, double h, ++success; } +void do_exit() { + assert(success == 8); + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void test_finished() { -#ifdef REPORT_RESULT - REPORT_RESULT(success); -#endif + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } char stack[1024]; @@ -90,4 +96,5 @@ int main() { emscripten_wasm_worker_post_function_vddd(worker, vddd, 4.5, 5.5, 6.5); emscripten_wasm_worker_post_function_sig(worker, viiiiiidddddd, "iiiiiidddddd", 10, 11, 12, 13, 14, 15, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5); emscripten_wasm_worker_post_function_v(worker, test_finished); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/post_function_to_main_thread.c b/test/wasm_worker/post_function_to_main_thread.c index 0aa151f2bfdb6..3c233fc65775d 100644 --- a/test/wasm_worker/post_function_to_main_thread.c +++ b/test/wasm_worker/post_function_to_main_thread.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -10,9 +11,8 @@ void test_success(int i, double d) { assert(!emscripten_current_thread_is_wasm_worker()); assert(i == 10); assert(d == 0.5); -#ifdef REPORT_RESULT - REPORT_RESULT(i); -#endif + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); } void worker_main() { @@ -26,4 +26,5 @@ char stack[1024]; int main() { emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/semaphore_try_acquire.c b/test/wasm_worker/semaphore_try_acquire.c index ec956b0f0eda8..cdb552b805f4e 100644 --- a/test/wasm_worker/semaphore_try_acquire.c +++ b/test/wasm_worker/semaphore_try_acquire.c @@ -30,7 +30,5 @@ int main() { idx = emscripten_semaphore_try_acquire(&available, 9); assert(idx == 1); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif + return 0; } diff --git a/test/wasm_worker/semaphore_waitinf_acquire.c b/test/wasm_worker/semaphore_waitinf_acquire.c index 3bcc36e397dcd..0b0c65d5725b7 100644 --- a/test/wasm_worker/semaphore_waitinf_acquire.c +++ b/test/wasm_worker/semaphore_waitinf_acquire.c @@ -31,6 +31,12 @@ void worker_main() { emscripten_semaphore_release(&threadsCompleted, 1); } +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void control_thread() { // Wait until we have three threads available to start running. emscripten_out("control_thread: waiting for three threads to complete loading"); @@ -62,9 +68,7 @@ void control_thread() { assert(threadCounter == 6); emscripten_out("control_thread: test finished"); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } int main() { @@ -78,4 +82,6 @@ int main() { emscripten_wasm_worker_t worker = emscripten_malloc_wasm_worker(1024); emscripten_wasm_worker_post_function_v(worker, worker_main); } + + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/terminate_all_wasm_workers.c b/test/wasm_worker/terminate_all_wasm_workers.c index 0afe657edaec9..512d0fb734f7e 100644 --- a/test/wasm_worker/terminate_all_wasm_workers.c +++ b/test/wasm_worker/terminate_all_wasm_workers.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -12,17 +12,13 @@ static volatile int worker_started = 0; void this_function_should_not_be_called(void *userData) { worker_started = -1; emscripten_err("this_function_should_not_be_called"); -#ifdef REPORT_RESULT - REPORT_RESULT(1/*fail*/); -#endif + assert(0); } void test_passed(void *userData) { if (worker_started == 2) { emscripten_err("test_passed"); -#ifdef REPORT_RESULT - REPORT_RESULT(0/*ok*/); -#endif + emscripten_force_exit(0); } } diff --git a/test/wasm_worker/thread_stack.c b/test/wasm_worker/thread_stack.c index 8269555d61828..340d9964b6a31 100644 --- a/test/wasm_worker/thread_stack.c +++ b/test/wasm_worker/thread_stack.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -13,6 +13,12 @@ void *thread_stack[NUM_THREADS]; volatile int threadsOk = 0; +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void test_stack(int i) { emscripten_outf("In thread %d, stack low addr=%p, emscripten_stack_get_base()=%p, emscripten_stack_get_end()=%p, THREAD_STACK_SIZE=%d", i, thread_stack[i], @@ -30,9 +36,7 @@ void test_stack(int i) { emscripten_outf("%d", ok); if (ok == 1) { emscripten_out("Test finished!"); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } } @@ -45,4 +49,6 @@ int main() { emscripten_outf("Created thread %d with stack ptr=%p, end=%p, size=%x", i, thread_stack[i], thread_stack[i] + THREAD_STACK_SIZE, THREAD_STACK_SIZE); emscripten_wasm_worker_post_function_vi(worker, test_stack, i); } + + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/wasm_worker_and_pthread.c b/test/wasm_worker/wasm_worker_and_pthread.c index 63afb9d5ef83a..2897435bd96f7 100644 --- a/test/wasm_worker/wasm_worker_and_pthread.c +++ b/test/wasm_worker/wasm_worker_and_pthread.c @@ -25,6 +25,12 @@ void *thread_main(void *arg) { return 0; } +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { emscripten_out("hello from wasm worker!"); assert(!am_i_pthread()); @@ -34,9 +40,8 @@ void worker_main() { while(!emscripten_atomic_cas_u32((void*)&pthread_ran, 0, 1)) emscripten_wasm_worker_sleep(10); -#ifdef REPORT_RESULT - REPORT_RESULT(0); -#endif + + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } int main() { @@ -45,4 +50,5 @@ int main() { emscripten_wasm_worker_t worker = emscripten_malloc_wasm_worker(/*stack size: */1024); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/wasm_worker_futex_wait.c b/test/wasm_worker/wasm_worker_futex_wait.c index 7830fca63b397..2d3dbb2e8d82c 100644 --- a/test/wasm_worker/wasm_worker_futex_wait.c +++ b/test/wasm_worker/wasm_worker_futex_wait.c @@ -1,9 +1,10 @@ // Test that emscripten_futex_wait() works in a Wasm Worker. -#include +#include #include #include #include +#include #include #include #include @@ -20,16 +21,22 @@ void wake_worker() { emscripten_set_timeout(wake_worker_after_delay, 500, 0); } +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { printf("Worker sleeping for futex wait.\n"); emscripten_wasm_worker_post_function_v(0, wake_worker); int rc = emscripten_futex_wait(&futex_value, 0, INFINITY); printf("emscripten_futex_wait returned with code %d.\n", rc); -#ifdef REPORT_RESULT - REPORT_RESULT(rc); -#endif + assert(rc == 0); + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } int main() { emscripten_wasm_worker_post_function_v(emscripten_malloc_wasm_worker(1024), worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/wasm_worker_self_id.c b/test/wasm_worker/wasm_worker_self_id.c index d846f9ee51f4f..e2c746e0fbea7 100644 --- a/test/wasm_worker/wasm_worker_self_id.c +++ b/test/wasm_worker/wasm_worker_self_id.c @@ -1,3 +1,5 @@ +#include +#include #include #include @@ -8,12 +10,16 @@ emscripten_wasm_worker_t worker2 = 0; int successes = 0; +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void test_success() { -#ifdef REPORT_RESULT if (__atomic_add_fetch(&successes, 1, __ATOMIC_SEQ_CST) == 2) { - REPORT_RESULT(0); + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } -#endif } void worker1_main() { @@ -41,4 +47,5 @@ int main() { worker2 = emscripten_create_wasm_worker(stack2, sizeof(stack2)); emscripten_wasm_worker_post_function_v(worker1, worker1_main); emscripten_wasm_worker_post_function_v(worker2, worker2_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/wasm_worker_sleep.c b/test/wasm_worker/wasm_worker_sleep.c index e81dc56c45ee5..8dc881ca91cd8 100644 --- a/test/wasm_worker/wasm_worker_sleep.c +++ b/test/wasm_worker/wasm_worker_sleep.c @@ -1,13 +1,23 @@ +#include +#include #include #include +int exitStatus = 1; + +void do_exit() { + emscripten_out("do_exit"); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); +} + void worker_main() { double t0 = emscripten_performance_now(); emscripten_wasm_worker_sleep(/*nsecs=*/1500*1000000); double t1 = emscripten_performance_now(); -#ifdef REPORT_RESULT - REPORT_RESULT(t1-t0 >= 1500); -#endif + assert(t1-t0 >= 1500); + exitStatus = t1-t0 >= 1500; + emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit); } char stack[1024]; @@ -15,4 +25,5 @@ char stack[1024]; int main() { emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); } diff --git a/test/wasm_worker/wasm_worker_tls_wasm_assembly.c b/test/wasm_worker/wasm_worker_tls_wasm_assembly.c index ad737f4f40c23..216ed48276b8f 100644 --- a/test/wasm_worker/wasm_worker_tls_wasm_assembly.c +++ b/test/wasm_worker/wasm_worker_tls_wasm_assembly.c @@ -11,9 +11,9 @@ void set_tls_variable(int var); void main_thread_func() { assert(!emscripten_current_thread_is_wasm_worker()); assert(globalData == 3); -#ifdef REPORT_RESULT - REPORT_RESULT(get_tls_variable()); -#endif + assert(get_tls_variable() == 42); + emscripten_terminate_all_wasm_workers(); + emscripten_force_exit(0); } void worker_main() { @@ -34,4 +34,5 @@ int main() { set_tls_variable(42); emscripten_wasm_worker_t worker = emscripten_create_wasm_worker(stack, sizeof(stack)); emscripten_wasm_worker_post_function_v(worker, worker_main); + emscripten_exit_with_live_runtime(); }