From aa5b1b80de8d608b8aae24099edfb998d7b9531b Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 22 Oct 2024 14:26:36 -0700 Subject: [PATCH] Cleanup node wasm worker testing. NFC Split out from #22776 --- test/atomic/test_wait_async.c | 8 ++++---- test/test_browser.py | 4 ++-- test/test_core.py | 7 ------- test/wasm_worker/malloc_wasm_worker.c | 11 ++++++++--- 4 files changed, 14 insertions(+), 16 deletions(-) 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..d6181189e92bc 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5018,7 +5018,7 @@ def test_wasm_worker_thread_stack(self, 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 @@ -5098,7 +5098,7 @@ def test_wasm_worker_wait64_notify(self): # 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 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/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(); }