Skip to content

Commit 2f97d04

Browse files
authored
Parameterize test_legalize_js_ffi (#23190)
1 parent f615920 commit 2f97d04

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

test/test_other.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8959,39 +8959,39 @@ def test_exported_runtime_methods_metadce(self, use_legacy_name):
89598959
for export in exports:
89608960
self.assertContained(f'Module["{export}"]', js)
89618961

8962-
def test_legalize_js_ffi(self):
8963-
# test disabling of JS FFI legalization
8964-
for (args, js_ffi) in [
8965-
(['-sLEGALIZE_JS_FFI=1', '-sSIDE_MODULE', '-O1'], True),
8966-
(['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O1'], False),
8967-
(['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O0'], False),
8968-
(['-sLEGALIZE_JS_FFI=1', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], True),
8969-
(['-sLEGALIZE_JS_FFI=0', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], False),
8970-
]:
8971-
print(args)
8972-
delete_file('a.out.wasm')
8973-
cmd = [EMCC, test_file('other/ffi.c'), '-g', '-o', 'a.out.wasm'] + args
8974-
print(' '.join(cmd))
8975-
self.run_process(cmd)
8976-
text = self.get_wasm_text('a.out.wasm')
8977-
# remove internal comments and extra whitespace
8978-
text = re.sub(r'\(;[^;]+;\)', '', text)
8979-
text = re.sub(r'\$var\$*.', '', text)
8980-
text = re.sub(r'param \$\d+', 'param ', text)
8981-
text = re.sub(r' +', ' ', text)
8982-
e_add_f32 = re.search(r'func \$add_f \(param f32\) \(param f32\) \(result f32\)', text)
8983-
assert e_add_f32, 'add_f export missing'
8984-
i_i64_i32 = re.search(r'import "env" "import_ll" .*\(param i32 i32\) \(result i32\)', text)
8985-
i_i64_i64 = re.search(r'import "env" "import_ll" .*\(param i64\) \(result i64\)', text)
8986-
e_i64_i32 = re.search(r'func \$legalstub\$add_ll \(param i32\) \(param i32\) \(param i32\) \(param i32\) \(result i32\)', text)
8987-
if js_ffi:
8988-
assert i_i64_i32, 'i64 not converted to i32 in imports'
8989-
assert not i_i64_i64, 'i64 not converted to i32 in imports'
8990-
assert e_i64_i32, 'i64 not converted to i32 in exports'
8991-
else:
8992-
assert not i_i64_i32, 'i64 converted to i32 in imports'
8993-
assert i_i64_i64, 'i64 converted to i32 in imports'
8994-
assert not e_i64_i32, 'i64 converted to i32 in exports'
8962+
@parameterized({
8963+
'legal_side_O1': (['-sLEGALIZE_JS_FFI=1', '-sSIDE_MODULE', '-O1'], True),
8964+
'nolegal_side_O1': (['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O1'], False),
8965+
'nolegal_side_O0': (['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O0'], False),
8966+
'legal_O0': (['-sLEGALIZE_JS_FFI=1', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], True),
8967+
'nolegal_O0': (['-sLEGALIZE_JS_FFI=0', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], False),
8968+
})
8969+
def test_legalize_js_ffi(self, args, js_ffi):
8970+
# test disabling of JS FFI legalization when not using bigint
8971+
print(args)
8972+
delete_file('a.out.wasm')
8973+
cmd = [EMCC, test_file('other/ffi.c'), '-g', '-o', 'a.out.wasm'] + args
8974+
print(' '.join(cmd))
8975+
self.run_process(cmd)
8976+
text = self.get_wasm_text('a.out.wasm')
8977+
# remove internal comments and extra whitespace
8978+
text = re.sub(r'\(;[^;]+;\)', '', text)
8979+
text = re.sub(r'\$var\$*.', '', text)
8980+
text = re.sub(r'param \$\d+', 'param ', text)
8981+
text = re.sub(r' +', ' ', text)
8982+
e_add_f32 = re.search(r'func \$add_f \(param f32\) \(param f32\) \(result f32\)', text)
8983+
assert e_add_f32, 'add_f export missing'
8984+
i_i64_i32 = re.search(r'import "env" "import_ll" .*\(param i32 i32\) \(result i32\)', text)
8985+
i_i64_i64 = re.search(r'import "env" "import_ll" .*\(param i64\) \(result i64\)', text)
8986+
e_i64_i32 = re.search(r'func \$legalstub\$add_ll \(param i32\) \(param i32\) \(param i32\) \(param i32\) \(result i32\)', text)
8987+
if js_ffi:
8988+
assert i_i64_i32, 'i64 not converted to i32 in imports'
8989+
assert not i_i64_i64, 'i64 not converted to i32 in imports'
8990+
assert e_i64_i32, 'i64 not converted to i32 in exports'
8991+
else:
8992+
assert not i_i64_i32, 'i64 converted to i32 in imports'
8993+
assert i_i64_i64, 'i64 converted to i32 in imports'
8994+
assert not e_i64_i32, 'i64 converted to i32 in exports'
89958995

89968996
@disabled('https://github.com/WebAssembly/binaryen/pull/6428')
89978997
def test_no_legalize_js_ffi(self):

0 commit comments

Comments
 (0)