Skip to content

[test] Make use of is_wasm2js helper #21413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def with_both_sjlj(f):

def metafunc(self, is_native):
if is_native:
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm2js does not support wasm SjLj')
self.require_wasm_eh()
# FIXME Temporarily disabled. Enable this later when the bug is fixed.
Expand Down Expand Up @@ -691,9 +691,7 @@ def is_2gb(self):
return self.get_setting('INITIAL_MEMORY') == '2200mb'

def check_dylink(self):
if self.get_setting('ALLOW_MEMORY_GROWTH') == 1 and not self.is_wasm():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we need the memory growth check?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's subsumed by the next line... sorry for the noise.

self.skipTest('no dynamic linking with memory growth (without wasm)')
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('no dynamic linking support in wasm2js yet')
if '-fsanitize=undefined' in self.emcc_args:
self.skipTest('no dynamic linking support in UBSan yet')
Expand Down Expand Up @@ -804,7 +802,7 @@ def require_jspi(self):
# warnings-as-errors, so disable that warning
self.emcc_args += ['-Wno-experimental']
self.set_setting('ASYNCIFY', 2)
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('JSPI is not currently supported for WASM2JS')

if self.is_browser_test():
Expand Down Expand Up @@ -850,14 +848,15 @@ def setup_node_pthreads(self):
self.node_args += shared.node_pthread_flags(nodejs)

def uses_memory_init_file(self):
if self.get_setting('SIDE_MODULE') or (self.is_wasm() and not self.get_setting('WASM2JS')):
if self.get_setting('SIDE_MODULE') or self.is_wasm():
return False
elif '--memory-init-file' in self.emcc_args:

if '--memory-init-file' in self.emcc_args:
return int(self.emcc_args[self.emcc_args.index('--memory-init-file') + 1])
else:
# side modules handle memory differently; binaryen puts the memory in the wasm module
opt_supports = any(opt in self.emcc_args for opt in ('-O2', '-O3', '-Os', '-Oz'))
return opt_supports

# side modules handle memory differently; binaryen puts the memory in the wasm module
opt_supports = any(opt in self.emcc_args for opt in ('-O2', '-O3', '-Os', '-Oz'))
return opt_supports

def set_temp_dir(self, temp_dir):
self.temp_dir = temp_dir
Expand Down
4 changes: 2 additions & 2 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3989,7 +3989,7 @@ def test_pthread_gcc_atomic_fetch_and_op(self, args):
@no_4gb('https://github.com/emscripten-core/emscripten/issues/21318')
@requires_threads
def test_pthread_gcc_64bit_atomic_fetch_and_op(self):
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('https://github.com/WebAssembly/binaryen/issues/4358')
self.emcc_args += ['-Wno-sync-fetch-and-nand-semantics-changed']
self.btest_exit('pthread/test_pthread_gcc_64bit_atomic_fetch_and_op.cpp', args=['-O3', '-pthread', '-sPTHREAD_POOL_SIZE=8'])
Expand All @@ -4009,7 +4009,7 @@ def test_pthread_gcc_atomic_op_and_fetch(self):
@no_4gb('https://github.com/emscripten-core/emscripten/issues/21318')
@requires_threads
def test_pthread_gcc_64bit_atomic_op_and_fetch(self):
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('https://github.com/WebAssembly/binaryen/issues/4358')
self.emcc_args += ['-Wno-sync-fetch-and-nand-semantics-changed', '--profiling-funcs']
self.btest_exit('pthread/test_pthread_gcc_64bit_atomic_op_and_fetch.cpp', args=['-pthread', '-O2', '-sPTHREAD_POOL_SIZE=8'])
Expand Down
54 changes: 26 additions & 28 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def decorated(self, *args, **kwargs):
self.require_simd()
if self.get_setting('MEMORY64') == 2:
self.skipTest('https://github.com/WebAssembly/binaryen/issues/4638')
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm2js only supports MVP for now')
if '-O3' in self.emcc_args:
self.skipTest('SIMD tests are too slow with -O3 in the new LLVM pass manager, https://github.com/emscripten-core/emscripten/issues/13427')
Expand All @@ -62,7 +62,7 @@ def decorated(self):
if self.get_setting('MEMORY64') == 2:
self.skipTest('https://github.com/WebAssembly/binaryen/issues/4638')
# We don't actually run any tests yet, so don't require any engines.
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm2js only supports MVP for now')
self.emcc_args.append('-mrelaxed-simd')
f(self)
Expand All @@ -71,7 +71,7 @@ def decorated(self):

def needs_non_trapping_float_to_int(f):
def decorated(self):
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm2js only supports MVP for now')
f(self)
return decorated
Expand Down Expand Up @@ -102,7 +102,7 @@ def with_both_eh_sjlj(f):
def metafunc(self, is_native):
if is_native:
# Wasm EH is currently supported only in wasm backend and V8
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm2js does not support wasm EH/SjLj')
self.require_wasm_eh()
# FIXME Temporarily disabled. Enable this later when the bug is fixed.
Expand Down Expand Up @@ -902,7 +902,7 @@ def test_longjmp_with_and_without_exceptions(self):
# Wasm SjLj with and without Wasm EH support
self.clear_setting('DISABLE_EXCEPTION_CATCHING')
self.set_setting('SUPPORT_LONGJMP', 'wasm')
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm2js does not support wasm EH/SjLj')
self.require_wasm_eh()
# FIXME Temporarily disabled. Enable this later when the bug is fixed.
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def test_exceptions_with_and_without_longjmp(self):
self.do_run_in_out_file_test('core/test_exceptions.cpp', out_suffix='_caught')
# Wasm EH with and without Wasm SjLj support
self.clear_setting('DISABLE_EXCEPTION_CATCHING')
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm2js does not support wasm EH/SjLj')
self.require_wasm_eh()
# FIXME Temporarily disabled. Enable this later when the bug is fixed.
Expand Down Expand Up @@ -2028,7 +2028,7 @@ def test_memorygrowth(self):
self.do_runf(src, '*pre: hello,4.955*\n*hello,4.955*\n*hello,4.955*')
win = read_file('test_memorygrowth.js')

if '-O2' in self.emcc_args and not self.is_wasm():
if '-O2' in self.emcc_args and self.is_wasm2js():
# Make sure ALLOW_MEMORY_GROWTH generates different code (should be less optimized)
code_start = '// EMSCRIPTEN_START_FUNCS'
self.assertContained(code_start, fail)
Expand Down Expand Up @@ -2061,7 +2061,7 @@ def test_memorygrowth_2(self):
self.do_runf(src, '*pre: hello,4.955*\n*hello,4.955*\n*hello,4.955*')
win = read_file('test_memorygrowth_2.js')

if '-O2' in self.emcc_args and not self.is_wasm():
if '-O2' in self.emcc_args and self.is_wasm2js():
# Make sure ALLOW_MEMORY_GROWTH generates different code (should be less optimized)
assert len(fail) < len(win), 'failing code - without memory growth on - is more optimized, and smaller' + str([len(fail), len(win)])

Expand All @@ -2080,7 +2080,7 @@ def test_memorygrowth_3(self):
def test_memorygrowth_MAXIMUM_MEMORY(self):
if self.has_changed_setting('ALLOW_MEMORY_GROWTH'):
self.skipTest('test needs to modify memory growth')
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm memory specific test')

# check that memory growth does not exceed the wasm mem max limit
Expand All @@ -2092,7 +2092,7 @@ def test_memorygrowth_MAXIMUM_MEMORY(self):
def test_memorygrowth_linear_step(self):
if self.has_changed_setting('ALLOW_MEMORY_GROWTH'):
self.skipTest('test needs to modify memory growth')
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm memory specific test')

# check that memory growth does not exceed the wasm mem max limit and is exactly or one step below the wasm mem max
Expand All @@ -2105,7 +2105,7 @@ def test_memorygrowth_linear_step(self):
def test_memorygrowth_geometric_step(self):
if self.has_changed_setting('ALLOW_MEMORY_GROWTH'):
self.skipTest('test needs to modify memory growth')
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm memory specific test')

self.emcc_args += ['-sALLOW_MEMORY_GROWTH', '-sMEMORY_GROWTH_GEOMETRIC_STEP=8.5', '-sMEMORY_GROWTH_GEOMETRIC_CAP=32MB']
Expand Down Expand Up @@ -4030,8 +4030,6 @@ def test_dylink_no_export(self):

@needs_dylink
def test_dylink_memory_growth(self):
if not self.is_wasm():
self.skipTest('wasm only')
self.set_setting('ALLOW_MEMORY_GROWTH')
self.do_basic_dylink_test()

Expand Down Expand Up @@ -4884,7 +4882,7 @@ def test_dylink_hyper_dupe(self):
''',
expected=['sidef: 10, sideg: 20.\nbsidef: 536.\nonly_in_second_0: 10, 20, 1337\nonly_in_third_1: 36, 49, 500, 1221\nonly_in_third_0: 36, 49, 500\nonly_in_second_1: 10, 20, 1337, 2112\n'],
# in wasm, we can't flip as the side would have an EM_ASM, which we don't support yet TODO
need_reverse=not self.is_wasm())
need_reverse=self.is_wasm2js())

print('check warnings')
full = self.run_js('src.js')
Expand Down Expand Up @@ -4927,7 +4925,7 @@ def test_dylink_load_compiled_side_module(self):
''',
expected=['sidef: 10'],
# in wasm, we can't flip as the side would have an EM_ASM, which we don't support yet TODO
need_reverse=not self.is_wasm())
need_reverse=self.is_wasm2js())

@needs_dylink
def test_dylink_dso_needed(self):
Expand Down Expand Up @@ -5363,7 +5361,7 @@ def test_langinfo(self):

def test_files(self):
# Use closure here, to test we don't break FS stuff
if '-O3' in self.emcc_args and not self.is_wasm():
if '-O3' in self.emcc_args and self.is_wasm2js():
print('closure 2')
self.emcc_args += ['--closure', '2'] # Use closure 2 here for some additional coverage
# Sadly --closure=2 is not yet free of closure warnings
Expand Down Expand Up @@ -6204,7 +6202,7 @@ def test_iostream_and_determinism(self):
shutil.copy2('src.js', 'src.js.previous')

# Same but for the wasm file.
if self.is_wasm() and not self.get_setting('WASM2JS'):
if self.is_wasm():
if os.path.exists('src.wasm.previous'):
self.assertBinaryEqual('src.wasm', 'src.wasm.previous')
shutil.copy2('src.wasm', 'src.wasm.previous')
Expand Down Expand Up @@ -7730,7 +7728,7 @@ def test_source_map(self, args):
self.emcc(os.path.abspath('src.cpp'),
self.get_emcc_args(),
out_filename)
map_referent = out_filename if not self.is_wasm() else wasm_filename
map_referent = out_filename if self.is_wasm2js() else wasm_filename
# after removing the @line and @sourceMappingURL comments, the build
# result should be identical to the non-source-mapped debug version.
# this is worth checking because the parser AST swaps strings for token
Expand Down Expand Up @@ -7908,7 +7906,7 @@ def test_modularize_closure_pre(self):
# test that the combination of modularize + closure + pre-js works. in that mode,
# closure should not minify the Module object in a way that the pre-js cannot use it.
create_file('post.js', 'var TheModule = Module();\n')
if not self.is_wasm():
if self.is_wasm2js():
# TODO(sbc): Fix closure warnings with MODULARIZE + WASM=0
self.ldflags.append('-Wno-error=closure')

Expand Down Expand Up @@ -8396,7 +8394,7 @@ def verify_broken(args):
@no_sanitize('no wasm2js support yet in sanitizers')
@requires_wasm2js
def test_wasm2js(self):
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('redundant to test wasm2js in wasm2js* mode')
self.set_setting('WASM', 0)
self.do_core_test('test_hello_world.c')
Expand All @@ -8412,7 +8410,7 @@ def test_wasm2js(self):
@no_sanitize('no wasm2js support yet in sanitizers')
@requires_wasm2js
def test_maybe_wasm2js(self):
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('redundant to test wasm2js in wasm2js* mode')
self.set_setting('MAYBE_WASM2JS')
# see that running as wasm works
Expand All @@ -8434,7 +8432,7 @@ def test_maybe_wasm2js(self):
'minimal_runtime': (['-sMINIMAL_RUNTIME'],),
})
def test_wasm2js_fallback(self, args):
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('redundant to test wasm2js in wasm2js* mode')

cmd = [EMCC, test_file('small_hello_world.c'), '-sWASM=2'] + args
Expand Down Expand Up @@ -8736,7 +8734,7 @@ def test_return_address(self):
@no_lsan('-fsanitize-minimal-runtime cannot be used with LSan')
def test_ubsan_minimal_too_many_errors(self):
self.emcc_args += ['-fsanitize=undefined', '-fsanitize-minimal-runtime']
if not self.is_wasm():
if self.is_wasm2js():
if self.is_optimizing():
self.skipTest('test can only be run without optimizations on asm.js')
# Need to use `-g` to get proper line numbers in asm.js
Expand All @@ -8750,10 +8748,10 @@ def test_ubsan_minimal_too_many_errors(self):
@no_lsan('-fsanitize-minimal-runtime cannot be used with LSan')
def test_ubsan_minimal_errors_same_place(self):
self.emcc_args += ['-fsanitize=undefined', '-fsanitize-minimal-runtime']
if not self.is_wasm():
if self.is_wasm2js():
if self.is_optimizing():
self.skipTest('test can only be run without optimizations on asm.js')
# Need to use `-g` to get proper line numbers in asm.js
self.skipTest('test can only be run without optimizations under wasm2js')
# Need to use `-g` to get proper line numbers in wasm2js
self.emcc_args += ['-g']
self.do_runf('core/test_ubsan_minimal_errors_same_place.c',
expected_output='ubsan: add-overflow by 0x[0-9a-z]*\n' * 5,
Expand Down Expand Up @@ -8851,7 +8849,7 @@ def test_ubsan_full_static_cast(self, args):
@no_wasm2js('TODO: sanitizers in wasm2js')
def test_ubsan_full_stack_trace(self, g_flag, expected_output):
if g_flag == '-gsource-map':
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm2js has no source map support')
elif self.get_setting('EVAL_CTORS'):
self.skipTest('EVAL_CTORS does not support source maps')
Expand Down Expand Up @@ -8963,7 +8961,7 @@ def test_asan(self, name, expected_output, cflags=None):
if '-Oz' in self.emcc_args:
self.skipTest('-Oz breaks source maps')

if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('wasm2js has no ASan support')

self.emcc_args.append('-fsanitize=address')
Expand Down
4 changes: 2 additions & 2 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -9655,7 +9655,7 @@ def test_EM_ASM_ES6(self, args):
self.do_runf('src.c', 'hello!', emcc_args=args)

def test_check_sourcemapurl(self):
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('only supported with wasm')
self.run_process([EMCC, test_file('hello_123.c'), '-gsource-map', '-o', 'a.js', '--source-map-base', 'dir/'])
output = read_binary('a.wasm')
Expand All @@ -9681,7 +9681,7 @@ def test_check_source_map_args(self):
'profiling': ['--profiling'] # -gsource-map --profiling should still emit a source map; see #8584
})
def test_check_sourcemapurl_default(self, *args):
if not self.is_wasm():
if self.is_wasm2js():
self.skipTest('only supported with wasm')

self.run_process([EMCC, test_file('hello_123.c'), '-gsource-map', '-o', 'a.js'] + list(args))
Expand Down