Skip to content

Commit e167568

Browse files
committed
Use all_engines more consistently
This allows us remove some the nested loops from these tests. Ideally `all_engines` would generate separate tests for each engine but that can be a followup change.
1 parent e6587e7 commit e167568

File tree

3 files changed

+30
-43
lines changed

3 files changed

+30
-43
lines changed

test/common.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,21 @@ def crossplatform(f):
449449
return f
450450

451451

452+
# without EMTEST_ALL_ENGINES set we only run tests in a single VM by
453+
# default. in some tests we know that cross-VM differences may happen and
454+
# so are worth testing, and they should be marked with this decorator
455+
def all_engines(f):
456+
assert callable(f)
457+
458+
@wraps(f)
459+
def decorated(self, *args, **kwargs):
460+
self.use_all_engines = True
461+
self.set_setting('ENVIRONMENT', 'web,node,shell')
462+
f(self, *args, **kwargs)
463+
464+
return decorated
465+
466+
452467
@contextlib.contextmanager
453468
def env_modify(updates):
454469
"""A context manager that updates os.environ."""
@@ -2069,6 +2084,7 @@ def _build_and_run(self, filename, expected_output, args=None,
20692084
check_for_error=True,
20702085
interleaved_output=True,
20712086
regex=False,
2087+
input=None,
20722088
**kwargs):
20732089
logger.debug(f'_build_and_run: {filename}')
20742090

@@ -2095,6 +2111,7 @@ def _build_and_run(self, filename, expected_output, args=None,
20952111
self.fail('No JS engine present to run this test with. Check %s and the paths therein.' % config.EM_CONFIG)
20962112
for engine in engines:
20972113
js_output = self.run_js(js_file, engine, args,
2114+
input=input,
20982115
assert_returncode=assert_returncode,
20992116
interleaved_output=interleaved_output)
21002117
js_output = js_output.replace('\r\n', '\n')

test/test_core.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from tools import shared, building, config, utils, webassembly
2525
import common
2626
from common import RunnerCore, path_from_root, requires_native_clang, test_file, create_file
27-
from common import skip_if, no_windows, is_slow_test, parameterized, parameterize
27+
from common import skip_if, no_windows, is_slow_test, parameterized, parameterize, all_engines
2828
from common import env_modify, with_env_modify, disabled, flaky, node_pthreads, also_without_bigint
2929
from common import read_file, read_binary, requires_v8, requires_node, requires_dev_dependency, requires_wasm2js, requires_node_canary
3030
from common import compiler_for, crossplatform, no_4gb, no_2gb, also_with_minimal_runtime, also_with_modularize
@@ -183,25 +183,6 @@ def decorated(self, dylink_reversed, *args, **kwargs):
183183
return decorated
184184

185185

186-
# without EMTEST_ALL_ENGINES set we only run tests in a single VM by
187-
# default. in some tests we know that cross-VM differences may happen and
188-
# so are worth testing, and they should be marked with this decorator
189-
def all_engines(f):
190-
assert callable(f)
191-
192-
@wraps(f)
193-
def decorated(self, *args, **kwargs):
194-
old = self.use_all_engines
195-
self.use_all_engines = True
196-
self.set_setting('ENVIRONMENT', 'web,node,shell')
197-
try:
198-
f(self, *args, **kwargs)
199-
finally:
200-
self.use_all_engines = old
201-
202-
return decorated
203-
204-
205186
def no_wasm2js(note=''):
206187
assert not callable(note)
207188

test/test_other.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from common import also_with_modularize, also_with_wasmfs, with_all_fs
4343
from common import also_with_minimal_runtime, also_without_bigint, also_with_wasm64, also_with_asan, flaky
4444
from common import EMTEST_BUILD_VERBOSE, PYTHON, WEBIDL_BINDER, EMCMAKE, EMCONFIGURE
45-
from common import requires_network, parameterize, copytree
45+
from common import requires_network, parameterize, copytree, all_engines
4646
from tools import shared, building, utils, response_file, cache
4747
from tools.utils import read_file, write_file, delete_file, read_binary, MACOS, WINDOWS
4848
import common
@@ -1696,19 +1696,15 @@ def test_export_all_and_exported_functions(self):
16961696
self.emcc('lib.c', ['-sEXPORTED_FUNCTIONS=_libfunc2', '-sEXPORT_ALL', '--pre-js', 'pre.js'], output_filename='a.out.js')
16971697
self.assertContained('libfunc\n', self.run_js('a.out.js'))
16981698

1699+
@all_engines
16991700
@also_with_wasmfs
17001701
@crossplatform
17011702
@parameterized({
17021703
'': ([],),
17031704
'closure': (['-O2', '--closure=1'],),
17041705
})
17051706
def test_stdin(self, args):
1706-
self.set_setting('ENVIRONMENT', 'node,shell')
1707-
self.emcc(test_file('module/test_stdin.c'), args=args, output_filename='out.js')
1708-
1709-
for engine in config.JS_ENGINES:
1710-
output = self.run_js('out.js', engine, input='abcdef\nghijkl\n')
1711-
self.assertContained('abcdef\nghijkl\neof', output)
1707+
self.do_runf('module/test_stdin.c', 'abcdef\nghijkl\neof', input='abcdef\nghijkl\n', cflags=args)
17121708

17131709
@crossplatform
17141710
def test_module_stdin(self):
@@ -4284,6 +4280,7 @@ def test_exported_runtime_methods_from_js_library(self):
42844280
self.assertContained("Aborted('ptrToString' was not exported. add it to EXPORTED_RUNTIME_METHODS", err)
42854281

42864282
@crossplatform
4283+
@all_engines
42874284
def test_fs_stream_proto(self):
42884285
create_file('src.c', br'''
42894286
#include <stdio.h>
@@ -4316,10 +4313,7 @@ def test_fs_stream_proto(self):
43164313
return 0;
43174314
}
43184315
''', binary=True)
4319-
self.run_process([EMCC, 'src.c', '--embed-file', 'src.c', '-sENVIRONMENT=node,shell'])
4320-
for engine in config.JS_ENGINES:
4321-
out = self.run_js('a.out.js', engine=engine)
4322-
self.assertContained('File size: 682', out)
4316+
self.do_runf('src.c', 'File size: 682', cflags=['--embed-file', 'src.c'])
43234317

43244318
@node_pthreads
43254319
def test_node_emscripten_num_logical_cores(self):
@@ -6832,6 +6826,7 @@ def test_create_readonly(self):
68326826
Failed to open file for writing: /tmp/file; errno=2; Permission denied
68336827
''')
68346828

6829+
@all_engines
68356830
def test_embed_file_large(self):
68366831
# If such long files are encoded on one line,
68376832
# they overflow the interpreter's limit
@@ -6852,12 +6847,7 @@ def test_embed_file_large(self):
68526847
return 0;
68536848
}
68546849
''')
6855-
self.run_process([EMCC, 'src.c', '--embed-file', 'large.txt'])
6856-
for engine in config.JS_ENGINES:
6857-
if engine == config.V8_ENGINE:
6858-
continue # ooms
6859-
print(engine)
6860-
self.assertContained('ok\n' + str(large_size) + '\n', self.run_js('a.out.js', engine=engine))
6850+
self.do_runf('src.c', 'ok\n' + str(large_size) + '\n', cflags=['--embed-file', 'large.txt'])
68616851

68626852
def test_force_exit(self):
68636853
create_file('src.c', r'''
@@ -12535,12 +12525,11 @@ def test_small_js_flags(self):
1253512525
self.emcc(test_file('browser_test_hello_world.c'), ['-O3', '--closure=1', '-sINCOMING_MODULE_JS_API=[]', '-sENVIRONMENT=web', '--output-eol=linux'])
1253612526
self.check_output_sizes('a.out.js')
1253712527

12528+
@all_engines
1253812529
def test_INCOMING_MODULE_JS_API(self):
1253912530
def test(args):
12540-
self.run_process([EMCC, test_file('hello_world.c'), '-O3', '--closure=1', '-sENVIRONMENT=node,shell', '--output-eol=linux'] + args)
12541-
for engine in config.JS_ENGINES:
12542-
self.assertContained('hello, world!', self.run_js('a.out.js', engine=engine))
12543-
return os.path.getsize('a.out.js')
12531+
self.do_runf('hello_world.c', 'hello, world!', cflags=['-O3', '--closure=1', '-sENVIRONMENT=node,shell', '--output-eol=linux'] + args)
12532+
return os.path.getsize('hello_world.js')
1254412533
normal = test([])
1254512534
changed = test(['-sINCOMING_MODULE_JS_API=[]'])
1254612535
print('sizes', normal, changed)
@@ -12941,13 +12930,13 @@ def test_linker_input_unused(self):
1294112930
# In this case the compiler does not produce any output file.
1294212931
self.assertNotExists('out.o')
1294312932

12933+
@all_engines
1294412934
def test_non_wasm_without_wasm_in_vm(self):
1294512935
# Test that our non-wasm output does not depend on wasm support in the vm.
1294612936
self.run_process([EMCC, test_file('hello_world.c'), '-sWASM=0', '-sENVIRONMENT=node,shell'])
1294712937
js = read_file('a.out.js')
1294812938
create_file('a.out.js', 'var WebAssembly = null;\n' + js)
12949-
for engine in config.JS_ENGINES:
12950-
self.assertContained('hello, world!', self.run_js('a.out.js', engine=engine))
12939+
self.assertContained('hello, world!', self.run_js('a.out.js'))
1295112940

1295212941
def test_empty_output_extension(self):
1295312942
# Default to JS output when no extension is present

0 commit comments

Comments
 (0)