Skip to content

Commit 8064a6c

Browse files
authored
Cleanup node wasm worker testing. NFC (#22777)
Split out from #22776
1 parent 53d4e60 commit 8064a6c

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5018,7 +5018,7 @@ def test_wasm_worker_thread_stack(self, mode):
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
@@ -5098,7 +5098,7 @@ def test_wasm_worker_wait64_notify(self):
50985098
# Tests emscripten_atomic_wait_async() function.
50995099
@also_with_minimal_runtime
51005100
def test_wasm_worker_wait_async(self):
5101-
self.btest('atomic/test_wait_async.c', expected='0', args=['-sWASM_WORKERS'])
5101+
self.btest_exit('atomic/test_wait_async.c', args=['-sWASM_WORKERS'])
51025102

51035103
# Tests emscripten_atomic_cancel_wait_async() function.
51045104
@also_with_minimal_runtime

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/malloc_wasm_worker.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55

66
// Test emscripten_malloc_wasm_worker() and emscripten_current_thread_is_wasm_worker() functions
77

8+
void do_exit() {
9+
emscripten_out("do_exit");
10+
emscripten_terminate_all_wasm_workers();
11+
emscripten_force_exit(0);
12+
}
13+
814
void worker_main() {
915
emscripten_out("Hello from wasm worker!");
1016
assert(emscripten_current_thread_is_wasm_worker());
11-
#ifdef REPORT_RESULT
12-
REPORT_RESULT(0);
13-
#endif
17+
emscripten_wasm_worker_post_function_v(EMSCRIPTEN_WASM_WORKER_ID_PARENT, do_exit);
1418
}
1519

1620
int main() {
1721
assert(!emscripten_current_thread_is_wasm_worker());
1822
emscripten_wasm_worker_t worker = emscripten_malloc_wasm_worker(/*stack size: */1024);
1923
assert(worker);
2024
emscripten_wasm_worker_post_function_v(worker, worker_main);
25+
emscripten_exit_with_live_runtime();
2126
}

0 commit comments

Comments
 (0)