|
43 | 43 | NON_ZERO, |
44 | 44 | PYTHON, |
45 | 45 | TEST_ROOT, |
| 46 | + WASM_MERGE, |
46 | 47 | WEBIDL_BINDER, |
47 | 48 | RunnerCore, |
48 | 49 | check_node_version, |
@@ -13275,6 +13276,90 @@ def test_pthread_js_exception(self): |
13275 | 13276 | self.set_setting('EXIT_RUNTIME') |
13276 | 13277 | self.do_runf('other/test_pthread_js_exception.c', 'missing is not defined', assert_returncode=NON_ZERO, cflags=['-pthread']) |
13277 | 13278 |
|
| 13279 | + @requires_pthreads |
| 13280 | + @requires_node_25 |
| 13281 | + def test_shared_wasmgc(self): |
| 13282 | + create_file('test_shared_wasmgc.c', r''' |
| 13283 | + #include <pthread.h> |
| 13284 | + #include <emscripten.h> |
| 13285 | + #include <emscripten/console.h> |
| 13286 | + |
| 13287 | + __attribute__((import_module("wat"))) void shared_gc_main(void); |
| 13288 | + |
| 13289 | + void print_int(int val) { |
| 13290 | + emscripten_console_logf("%d", val); |
| 13291 | + } |
| 13292 | + |
| 13293 | + void* thread_main(void* arg) { |
| 13294 | + shared_gc_main(); |
| 13295 | + return NULL; |
| 13296 | + } |
| 13297 | + |
| 13298 | + int main() { |
| 13299 | + shared_gc_main(); |
| 13300 | + |
| 13301 | + pthread_t t1, t2, t3; |
| 13302 | + pthread_create(&t1, NULL, thread_main, NULL); |
| 13303 | + pthread_create(&t2, NULL, thread_main, NULL); |
| 13304 | + pthread_create(&t3, NULL, thread_main, NULL); |
| 13305 | + |
| 13306 | + pthread_join(t1, NULL); |
| 13307 | + pthread_join(t2, NULL); |
| 13308 | + pthread_join(t3, NULL); |
| 13309 | + |
| 13310 | + return 0; |
| 13311 | + } |
| 13312 | + ''') |
| 13313 | + |
| 13314 | + create_file('shared_gc.wat', r''' |
| 13315 | + (module |
| 13316 | + (type $counter (shared (struct (field (mut i32))))) |
| 13317 | + |
| 13318 | + (import "app" "print_int" (func $print_int (param i32))) |
| 13319 | + |
| 13320 | + (global $root |
| 13321 | + (export "_shared_heap_root") |
| 13322 | + (import "env" "_shared_heap_root") |
| 13323 | + (mut (ref null (shared any))) |
| 13324 | + ) |
| 13325 | + |
| 13326 | + (func $init |
| 13327 | + (if (ref.is_null (global.get $root)) |
| 13328 | + (then |
| 13329 | + (global.set $root (struct.new $counter (i32.const 0))) |
| 13330 | + ) |
| 13331 | + ) |
| 13332 | + ) |
| 13333 | + (start $init) |
| 13334 | + |
| 13335 | + (func (export "shared_gc_main") |
| 13336 | + (call $print_int (ref.is_null (global.get $root))) |
| 13337 | + ) |
| 13338 | + ) |
| 13339 | + ''') |
| 13340 | + |
| 13341 | + out_js = self.in_dir('test_shared_wasmgc.js') |
| 13342 | + out_wasm = self.in_dir('test_shared_wasmgc.wasm') |
| 13343 | + |
| 13344 | + self.run_process([ |
| 13345 | + EMCC, '-pthread', '-sSHARED_WASMGC', '-sERROR_ON_UNDEFINED_SYMBOLS=0', |
| 13346 | + '-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', |
| 13347 | + '-sEXPORTED_FUNCTIONS=_main,_print_int', 'test_shared_wasmgc.c', '-o', |
| 13348 | + out_js, |
| 13349 | + ]) |
| 13350 | + |
| 13351 | + self.run_process([ |
| 13352 | + WASM_MERGE, '--enable-threads', '--enable-reference-types', |
| 13353 | + '--enable-gc', '--enable-shared-everything', out_wasm, 'app', |
| 13354 | + 'shared_gc.wat', 'wat', '-o', out_wasm, |
| 13355 | + ]) |
| 13356 | + |
| 13357 | + self.node_args.append('--experimental-wasm-shared') |
| 13358 | + |
| 13359 | + # TODO: Once multithreaded casting is fixed, increment and print the counter value. |
| 13360 | + output = self.run_js(out_js) |
| 13361 | + self.assertEqual(output.splitlines(), ['0', '0', '0', '0']) |
| 13362 | + |
13278 | 13363 | @crossplatform |
13279 | 13364 | def test_config_closure_compiler(self): |
13280 | 13365 | self.run_process([EMCC, test_file('hello_world.c'), '--closure=1']) |
|
0 commit comments