Skip to content

Commit bc895da

Browse files
authored
Revert "[test] Re-implement the @all_engines decorator based on parameteraization. NFC" (#25160)
Reverts #25115
1 parent 10e6e70 commit bc895da

File tree

4 files changed

+63
-85
lines changed

4 files changed

+63
-85
lines changed

src/parseTools.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,12 +1108,10 @@ function ENVIRONMENT_IS_WORKER_THREAD() {
11081108
}
11091109

11101110
function nodeDetectionCode() {
1111-
if (ENVIRONMENT == 'node' && ASSERTIONS == 0) {
1111+
if (ENVIRONMENT == 'node') {
11121112
// The only environment where this code is intended to run is Node.js.
11131113
// Return unconditional true so that later Closure optimizer will be able to
11141114
// optimize code size.
1115-
// Note that when ASSERTIONS are enabled we still want to runtime detect
1116-
// node so that errors can be reported when run elsewhere.
11171115
return 'true';
11181116
}
11191117
return "typeof process == 'object' && process.versions?.node && process.type != 'renderer'";

test/common.py

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -458,42 +458,19 @@ def crossplatform(f):
458458
return f
459459

460460

461-
# Without EMTEST_ALL_ENGINES set we only run tests in a single VM by default.
462-
# However, for some tests we know that cross-VM differences may happen and
463-
# so are worth testing, and they should be marked with this decorator which creates
464-
# N different variants of the test, one for each engine.
461+
# without EMTEST_ALL_ENGINES set we only run tests in a single VM by
462+
# default. in some tests we know that cross-VM differences may happen and
463+
# so are worth testing, and they should be marked with this decorator
465464
def all_engines(f):
466465
assert callable(f)
467466

468-
if len(config.JS_ENGINES) == 1 or EMTEST_ALL_ENGINES:
469-
return f
470-
471467
@wraps(f)
472-
def metafunc(self, engine, *args, **kwargs):
468+
def decorated(self, *args, **kwargs):
469+
self.use_all_engines = True
473470
self.set_setting('ENVIRONMENT', 'web,node,shell')
474-
self.js_engines = [engine]
475471
f(self, *args, **kwargs)
476472

477-
engine_mapping = {}
478-
for engine in config.JS_ENGINES:
479-
if not engine_mapping:
480-
# For the first engine we use no suffix at all.
481-
# This uffnsures that one of the tests matches the original name, meaning that
482-
# you can still run just `test_foo` and always get the first engine without
483-
# needing to write, for example, `test_foo_node`.
484-
name = ''
485-
else:
486-
basename = os.path.basename(engine[0])
487-
name = basename
488-
suffix = 1
489-
while name in engine_mapping:
490-
name = f'{basename}_{suffix}'
491-
suffix += 1
492-
engine_mapping[name] = (engine,)
493-
494-
parameterize(metafunc, engine_mapping)
495-
496-
return metafunc
473+
return decorated
497474

498475

499476
@contextlib.contextmanager
@@ -1379,6 +1356,7 @@ def setUp(self):
13791356
self.temp_files_before_run = []
13801357
self.required_engine = None
13811358
self.wasm_engines = config.WASM_ENGINES.copy()
1359+
self.use_all_engines = EMTEST_ALL_ENGINES
13821360
if self.get_current_js_engine() != config.NODE_JS_TEST:
13831361
# If our primary JS engine is something other than node then enable
13841362
# shell support.
@@ -2133,11 +2111,11 @@ def _build_and_run(self, filename, expected_output, args=None,
21332111
self.assertExists(js_file)
21342112

21352113
engines = self.js_engines.copy()
2136-
if len(engines) > 1 and not EMTEST_ALL_ENGINES:
2114+
if len(engines) > 1 and not self.use_all_engines:
21372115
engines = engines[:1]
21382116
# In standalone mode, also add wasm vms as we should be able to run there too.
21392117
if self.get_setting('STANDALONE_WASM'):
2140-
# TODO once standalone wasm support is more stable, apply EMTEST_ALL_ENGINES
2118+
# TODO once standalone wasm support is more stable, apply use_all_engines
21412119
# like with js engines, but for now as we bring it up, test in all of them
21422120
if not self.wasm_engines:
21432121
if 'EMTEST_SKIP_WASM_ENGINE' in os.environ:

test/test_core.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8782,7 +8782,6 @@ def test_mallinfo(self):
87828782
def test_wrap_malloc(self, args):
87838783
self.do_runf('core/test_wrap_malloc.c', 'OK.', cflags=args)
87848784

8785-
@all_engines
87868785
def test_environment(self):
87878786
self.set_setting('ASSERTIONS')
87888787

@@ -8794,31 +8793,33 @@ def test(assert_returncode=0):
87948793
js = read_file(self.output_name('test_hello_world'))
87958794
assert ('require(' in js) == ('node' in self.get_setting('ENVIRONMENT')), 'we should have require() calls only if node js specified'
87968795

8797-
engine = self.get_current_js_engine()
8798-
print(f'engine: {engine}')
8799-
# tell the compiler to build with just that engine
8800-
if engine == config.NODE_JS_TEST:
8801-
right = 'node'
8802-
wrong = 'shell'
8803-
else:
8804-
right = 'shell'
8805-
wrong = 'node'
8806-
# test with the right env
8807-
self.set_setting('ENVIRONMENT', right)
8808-
print('ENVIRONMENT =', self.get_setting('ENVIRONMENT'))
8809-
test()
8810-
# test with the wrong env
8811-
self.set_setting('ENVIRONMENT', wrong)
8812-
print('ENVIRONMENT =', self.get_setting('ENVIRONMENT'))
8813-
try:
8814-
test(assert_returncode=NON_ZERO)
8815-
raise Exception('unexpected success')
8816-
except Exception as e:
8817-
self.assertContained('not compiled for this environment', str(e))
8818-
# test with a combined env
8819-
self.set_setting('ENVIRONMENT', right + ',' + wrong)
8820-
print('ENVIRONMENT =', self.get_setting('ENVIRONMENT'))
8821-
test()
8796+
for engine in config.JS_ENGINES:
8797+
print(f'engine: {engine}')
8798+
# set us to test in just this engine
8799+
self.require_engine(engine)
8800+
# tell the compiler to build with just that engine
8801+
if engine == config.NODE_JS_TEST:
8802+
right = 'node'
8803+
wrong = 'shell'
8804+
else:
8805+
right = 'shell'
8806+
wrong = 'node'
8807+
# test with the right env
8808+
self.set_setting('ENVIRONMENT', right)
8809+
print('ENVIRONMENT =', self.get_setting('ENVIRONMENT'))
8810+
test()
8811+
# test with the wrong env
8812+
self.set_setting('ENVIRONMENT', wrong)
8813+
print('ENVIRONMENT =', self.get_setting('ENVIRONMENT'))
8814+
try:
8815+
test(assert_returncode=NON_ZERO)
8816+
raise Exception('unexpected success')
8817+
except Exception as e:
8818+
self.assertContained('not compiled for this environment', str(e))
8819+
# test with a combined env
8820+
self.set_setting('ENVIRONMENT', right + ',' + wrong)
8821+
print('ENVIRONMENT =', self.get_setting('ENVIRONMENT'))
8822+
test()
88228823

88238824
@requires_node
88248825
def test_postrun_exception(self):

test/test_other.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5953,12 +5953,11 @@ def test_argv0_node(self):
59535953
output = self.do_runf('code.c')
59545954
self.assertContained('I am ' + utils.normalize_path(os.path.realpath(self.get_dir())) + '/code.js', utils.normalize_path(output))
59555955

5956-
@all_engines
59575956
@parameterized({
5958-
'exit_runtime': (['-sEXIT_RUNTIME=1'],),
5959-
'': ([],),
5957+
'no_exit_runtime': [True],
5958+
'': [False],
59605959
})
5961-
def test_returncode(self, args):
5960+
def test_returncode(self, no_exit):
59625961
create_file('src.c', r'''
59635962
#include <stdio.h>
59645963
#include <stdlib.h>
@@ -5970,17 +5969,20 @@ def test_returncode(self, args):
59705969
#endif
59715970
}
59725971
''')
5973-
msg = 'but keepRuntimeAlive() is set (counter=0) due to an async operation, so halting execution but not exiting the runtime'
59745972
for code in (0, 123):
59755973
for call_exit in (0, 1):
59765974
for async_compile in (0, 1):
5977-
print('code', code, 'call_exit', call_exit, 'async_compile', async_compile)
5978-
cflags = args + [f'-DCODE={code}', f'-DCALL_EXIT={call_exit}', f'-sWASM_ASYNC_COMPILATION={async_compile}']
5979-
output = self.do_runf('src.c', cflags=cflags, assert_returncode=code)
5980-
if '-sEXIT_RUNTIME=1' not in args and call_exit:
5981-
self.assertContained(msg, output)
5982-
else:
5983-
self.assertNotContained(msg, output)
5975+
self.run_process([EMCC, 'src.c', '-sENVIRONMENT=node,shell', '-DCODE=%d' % code, '-sEXIT_RUNTIME=%d' % (1 - no_exit), '-DCALL_EXIT=%d' % call_exit, '-sWASM_ASYNC_COMPILATION=%d' % async_compile])
5976+
for engine in config.JS_ENGINES:
5977+
print(code, call_exit, async_compile, engine)
5978+
proc = self.run_process(engine + ['a.out.js'], stderr=PIPE, check=False)
5979+
msg = 'but keepRuntimeAlive() is set (counter=0) due to an async operation, so halting execution but not exiting the runtime'
5980+
if no_exit and call_exit:
5981+
self.assertContained(msg, proc.stderr)
5982+
else:
5983+
self.assertNotContained(msg, proc.stderr)
5984+
# we always emit the right exit code, whether we exit the runtime or not
5985+
self.assertEqual(proc.returncode, code)
59845986

59855987
def test_emscripten_force_exit_NO_EXIT_RUNTIME(self):
59865988
create_file('src.c', r'''
@@ -8917,7 +8919,6 @@ def test_run_order(self):
89178919
]
89188920
self.do_runf('src.c', '\n'.join(expected_order))
89198921

8920-
@all_engines
89218922
def test_override_js_execution_environment(self):
89228923
create_file('main.c', r'''
89238924
#include <emscripten.h>
@@ -8932,19 +8933,19 @@ def test_override_js_execution_environment(self):
89328933
''')
89338934
self.run_process([EMCC, 'main.c', '-sENVIRONMENT=node,shell'])
89348935
src = read_file('a.out.js')
8935-
engine = self.get_current_js_engine()
89368936
for env in ['web', 'worker', 'node', 'shell']:
8937-
actual = 'NODE' if engine == config.NODE_JS_TEST else 'SHELL'
8938-
print('env', env, 'actual', actual, 'engine', engine)
8939-
module = {'ENVIRONMENT': env}
8940-
if env != actual:
8941-
# avoid problems with arguments detection, which may cause very odd failures with the wrong environment code
8942-
module['arguments'] = []
8943-
curr = 'var Module = %s;\n' % str(module)
8944-
print(' ' + curr)
8945-
create_file('test.js', curr + src)
8946-
seen = self.run_js('test.js', assert_returncode=NON_ZERO)
8947-
self.assertContained('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node', seen)
8937+
for engine in config.JS_ENGINES:
8938+
actual = 'NODE' if engine == config.NODE_JS_TEST else 'SHELL'
8939+
print(env, actual, engine)
8940+
module = {'ENVIRONMENT': env}
8941+
if env != actual:
8942+
# avoid problems with arguments detection, which may cause very odd failures with the wrong environment code
8943+
module['arguments'] = []
8944+
curr = 'var Module = %s;\n' % str(module)
8945+
print(' ' + curr)
8946+
create_file('test.js', curr + src)
8947+
seen = self.run_js('test.js', engine=engine, assert_returncode=NON_ZERO)
8948+
self.assertContained('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node', seen)
89488949

89498950
def test_override_c_environ(self):
89508951
create_file('pre.js', r'''

0 commit comments

Comments
 (0)