Skip to content

Commit 618db7c

Browse files
authored
Remove js_engines argument in test runners (#16932)
There were very few callers that used this argument and they were all better served by calling `self.require_node` or `self.require_v8` which fail in a more descriptive way. Some of these tests already have `@require_node`. Others could be parameterized allowing the MEMFS version to run on any VM and only the nodefs flavor to be limited to node.
1 parent 7a55a1d commit 618db7c

File tree

3 files changed

+68
-56
lines changed

3 files changed

+68
-56
lines changed

tests/common.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,16 +1089,14 @@ def ccshared(src, linkto=[]):
10891089
''' % locals(),
10901090
'a: loaded\na: b (prev: (null))\na: c (prev: b)\n')
10911091

1092-
def filtered_js_engines(self, js_engines=None):
1093-
if js_engines is None:
1094-
js_engines = self.js_engines
1095-
for engine in js_engines:
1092+
def filtered_js_engines(self):
1093+
for engine in self.js_engines:
10961094
assert engine in config.JS_ENGINES, "js engine does not exist in config.JS_ENGINES"
10971095
assert type(engine) == list
10981096
for engine in self.banned_js_engines:
10991097
assert type(engine) in (list, type(None))
11001098
banned = [b[0] for b in self.banned_js_engines if b]
1101-
return [engine for engine in js_engines if engine and engine[0] not in banned]
1099+
return [engine for engine in self.js_engines if engine and engine[0] not in banned]
11021100

11031101
def do_run(self, src, expected_output=None, force_c=False, **kwargs):
11041102
if 'no_build' in kwargs:
@@ -1128,7 +1126,7 @@ def do_run_in_out_file_test(self, *path, **kwargs):
11281126
## Does a complete test - builds, runs, checks output, etc.
11291127
def _build_and_run(self, filename, expected_output, args=[], output_nicerizer=None,
11301128
no_build=False,
1131-
js_engines=None, libraries=[],
1129+
libraries=[],
11321130
includes=[],
11331131
assert_returncode=0, assert_identical=False, assert_all=False,
11341132
check_for_error=True, force_c=False, emcc_args=[],
@@ -1145,7 +1143,7 @@ def _build_and_run(self, filename, expected_output, args=[], output_nicerizer=No
11451143
output_basename=output_basename)
11461144
self.assertExists(js_file)
11471145

1148-
engines = self.filtered_js_engines(js_engines)
1146+
engines = self.filtered_js_engines()
11491147
if len(engines) > 1 and not self.use_all_engines:
11501148
engines = engines[:1]
11511149
# In standalone mode, also add wasm vms as we should be able to run there too.

tests/test_core.py

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,12 @@ def test_i64_varargs(self):
518518
self.do_core_test('test_i64_varargs.c', args='waka fleefl asdfasdfasdfasdf'.split())
519519

520520
@no_wasm2js('wasm_bigint')
521+
@require_node
521522
def test_i64_invoke_bigint(self):
522523
self.set_setting('WASM_BIGINT')
523524
self.emcc_args += ['-fexceptions']
524525
self.node_args += ['--experimental-wasm-bigint']
525-
self.do_core_test('test_i64_invoke_bigint.cpp', js_engines=[config.NODE_JS])
526+
self.do_core_test('test_i64_invoke_bigint.cpp')
526527

527528
def test_vararg_copy(self):
528529
self.do_run_in_out_file_test('va_arg/test_va_copy.c')
@@ -5404,15 +5405,17 @@ def test_proc_self_fd(self):
54045405
def test_fwrite_0(self):
54055406
self.do_core_test('test_fwrite_0.c')
54065407

5407-
def test_fgetc_ungetc(self):
5408+
@parameterized({
5409+
'': (['MEMFS']),
5410+
'nodefs': (['NODEFS'])
5411+
})
5412+
def test_fgetc_ungetc(self, fs):
54085413
print('TODO: update this test once the musl ungetc-on-EOF-stream bug is fixed upstream and reaches us')
5409-
orig_compiler_opts = self.emcc_args.copy()
5410-
for fs in ['MEMFS', 'NODEFS']:
5411-
print(fs)
5412-
self.emcc_args = orig_compiler_opts + ['-D' + fs]
5413-
if fs == 'NODEFS':
5414-
self.emcc_args += ['-lnodefs.js']
5415-
self.do_runf(test_file('stdio/test_fgetc_ungetc.c'), 'success', js_engines=[config.NODE_JS])
5414+
self.emcc_args += ['-D' + fs]
5415+
if fs == 'NODEFS':
5416+
self.require_node()
5417+
self.emcc_args += ['-lnodefs.js']
5418+
self.do_runf(test_file('stdio/test_fgetc_ungetc.c'), 'success')
54165419

54175420
def test_fgetc_unsigned(self):
54185421
src = r'''
@@ -5811,6 +5814,7 @@ def test_signals(self):
58115814
self.do_core_test(test_file('test_signals.c'))
58125815

58135816
@no_windows('https://github.com/emscripten-core/emscripten/issues/8882')
5817+
@require_node
58145818
def test_unistd_access(self):
58155819
self.uses_es6 = True
58165820
orig_compiler_opts = self.emcc_args.copy()
@@ -5823,13 +5827,13 @@ def test_unistd_access(self):
58235827
self.emcc_args += ['-sFORCE_FILESYSTEM']
58245828
if fs == 'NODEFS':
58255829
self.emcc_args += ['-lnodefs.js']
5826-
self.do_run_in_out_file_test('unistd/access.c', js_engines=[config.NODE_JS])
5830+
self.do_run_in_out_file_test('unistd/access.c')
58275831
# Node.js fs.chmod is nearly no-op on Windows
58285832
# TODO: NODERAWFS in WasmFS
58295833
if not WINDOWS and not self.get_setting('WASMFS'):
58305834
self.emcc_args = orig_compiler_opts
58315835
self.set_setting('NODERAWFS')
5832-
self.do_run_in_out_file_test('unistd/access.c', js_engines=[config.NODE_JS])
5836+
self.do_run_in_out_file_test('unistd/access.c')
58335837

58345838
def test_unistd_curdir(self):
58355839
self.uses_es6 = True
@@ -5847,19 +5851,22 @@ def test_unistd_pipe(self):
58475851
def test_unistd_dup(self):
58485852
self.do_run_in_out_file_test('unistd/dup.c')
58495853

5850-
def test_unistd_truncate(self):
5854+
@parameterized({
5855+
'': (['MEMFS']),
5856+
'nodefs': (['NODEFS'])
5857+
})
5858+
def test_unistd_truncate(self, fs):
58515859
self.uses_es6 = True
58525860
orig_compiler_opts = self.emcc_args.copy()
5853-
for fs in ['MEMFS', 'NODEFS']:
5854-
self.emcc_args = orig_compiler_opts + ['-D' + fs]
5855-
if self.get_setting('WASMFS'):
5856-
if fs == 'NODEFS':
5857-
# TODO: NODEFS in WasmFS
5858-
continue
5859-
self.emcc_args += ['-sFORCE_FILESYSTEM']
5861+
self.emcc_args = orig_compiler_opts + ['-D' + fs]
5862+
if self.get_setting('WASMFS'):
58605863
if fs == 'NODEFS':
5861-
self.emcc_args += ['-lnodefs.js']
5862-
self.do_run_in_out_file_test('unistd/truncate.c', js_engines=[config.NODE_JS])
5864+
self.skipTest('TODO: NODEFS in WasmFS')
5865+
self.emcc_args += ['-sFORCE_FILESYSTEM']
5866+
if fs == 'NODEFS':
5867+
self.emcc_args += ['-lnodefs.js']
5868+
self.require_node()
5869+
self.do_run_in_out_file_test('unistd/truncate.c')
58635870

58645871
@no_windows("Windows throws EPERM rather than EACCES or EINVAL")
58655872
@unittest.skipIf(WINDOWS or os.geteuid() == 0, "Root access invalidates this test by being able to write on readonly files")
@@ -5884,33 +5891,36 @@ def test_unistd_sysconf_phys_pages(self):
58845891
self.do_runf(filename, str(expected) + ', errno: 0')
58855892

58865893
@no_windows('https://github.com/emscripten-core/emscripten/issues/8882')
5887-
def test_unistd_unlink(self):
5888-
self.clear()
5889-
orig_compiler_opts = self.emcc_args.copy()
5890-
for fs in ['MEMFS', 'NODEFS']:
5891-
if fs == 'NODEFS' and self.get_setting('WASMFS'):
5892-
# TODO: NODEFS in WasmFS
5893-
continue
5894-
self.emcc_args = orig_compiler_opts + ['-D' + fs]
5895-
# symlinks on node.js on non-linux behave differently (e.g. on Windows they require administrative privileges)
5896-
# so skip testing those bits on that combination.
5897-
if fs == 'NODEFS':
5898-
self.emcc_args += ['-lnodefs.js']
5899-
if WINDOWS:
5900-
self.emcc_args += ['-DNO_SYMLINK=1']
5901-
if MACOS:
5902-
continue
5903-
self.do_runf(test_file('unistd/unlink.c'), 'success', js_engines=[config.NODE_JS])
5894+
@parameterized({
5895+
'': (['MEMFS']),
5896+
'nodefs': (['NODEFS']),
5897+
'noderawfs': (['NODERAWFS']),
5898+
})
5899+
def test_unistd_unlink(self, fs):
5900+
if fs in ('NODEFS', 'NODERAWFS'):
5901+
self.require_node()
5902+
if self.get_setting('WASMFS'):
5903+
self.skipTest('NODEFS in WasmFS')
5904+
5905+
self.emcc_args += ['-D' + fs]
5906+
# symlinks on node.js on non-linux behave differently (e.g. on Windows they require administrative privileges)
5907+
# so skip testing those bits on that combination.
5908+
if fs == 'NODEFS':
5909+
self.emcc_args += ['-lnodefs.js']
5910+
if WINDOWS:
5911+
self.emcc_args += ['-DNO_SYMLINK=1']
5912+
if MACOS:
5913+
self.skipTest()
59045914

59055915
# Several differences/bugs on non-linux including https://github.com/nodejs/node/issues/18014
59065916
# TODO: NODERAWFS in WasmFS
5907-
if not WINDOWS and not MACOS and not self.get_setting('WASMFS'):
5908-
self.emcc_args = orig_compiler_opts + ['-DNODERAWFS']
5917+
if fs == 'NODERAWFS':
5918+
self.set_setting('NODERAWFS')
59095919
# 0 if root user
59105920
if os.geteuid() == 0:
59115921
self.emcc_args += ['-DSKIP_ACCESS_TESTS']
5912-
self.set_setting('NODERAWFS')
5913-
self.do_runf(test_file('unistd/unlink.c'), 'success', js_engines=[config.NODE_JS])
5922+
5923+
self.do_runf(test_file('unistd/unlink.c'), 'success')
59145924

59155925
@parameterized({
59165926
'memfs': (['-DMEMFS'], False),
@@ -5960,14 +5970,18 @@ def test_unistd_io(self):
59605970
self.do_run_in_out_file_test('unistd/io.c')
59615971

59625972
@no_windows('https://github.com/emscripten-core/emscripten/issues/8882')
5963-
def test_unistd_misc(self):
5973+
@parameterized({
5974+
'': (['MEMFS']),
5975+
'nodefs': (['NODEFS']),
5976+
})
5977+
def test_unistd_misc(self, fs):
59645978
self.set_setting('LLD_REPORT_UNDEFINED')
59655979
orig_compiler_opts = self.emcc_args.copy()
5966-
for fs in ['MEMFS', 'NODEFS']:
5967-
self.emcc_args = orig_compiler_opts + ['-D' + fs]
5968-
if fs == 'NODEFS':
5969-
self.emcc_args += ['-lnodefs.js']
5970-
self.do_run_in_out_file_test('unistd/misc.c', js_engines=[config.NODE_JS], interleaved_output=False)
5980+
self.emcc_args = orig_compiler_opts + ['-D' + fs]
5981+
if fs == 'NODEFS':
5982+
self.require_node()
5983+
self.emcc_args += ['-lnodefs.js']
5984+
self.do_run_in_out_file_test('unistd/misc.c', interleaved_output=False)
59715985

59725986
# i64s in the API, which we'd need to legalize for JS, so in standalone mode
59735987
# all we can test is wasm VMs

tests/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11649,7 +11649,7 @@ def test_unistd_close_noderawfs(self):
1164911649
}
1165011650
''')
1165111651
self.emcc_args += ['--pre-js', 'pre.js']
11652-
self.do_run_in_out_file_test('unistd/close.c', js_engines=[config.NODE_JS])
11652+
self.do_run_in_out_file_test('unistd/close.c')
1165311653

1165411654
# WASMFS tests
1165511655

0 commit comments

Comments
 (0)