Skip to content
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
17 changes: 17 additions & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,21 @@ def crossplatform(f):
return f


# without EMTEST_ALL_ENGINES set we only run tests in a single VM by
# default. in some tests we know that cross-VM differences may happen and
# so are worth testing, and they should be marked with this decorator
def all_engines(f):
assert callable(f)

@wraps(f)
def decorated(self, *args, **kwargs):
self.use_all_engines = True
self.set_setting('ENVIRONMENT', 'web,node,shell')
f(self, *args, **kwargs)

return decorated


@contextlib.contextmanager
def env_modify(updates):
"""A context manager that updates os.environ."""
Expand Down Expand Up @@ -2069,6 +2084,7 @@ def _build_and_run(self, filename, expected_output, args=None,
check_for_error=True,
interleaved_output=True,
regex=False,
input=None,
**kwargs):
logger.debug(f'_build_and_run: {filename}')

Expand All @@ -2095,6 +2111,7 @@ def _build_and_run(self, filename, expected_output, args=None,
self.fail('No JS engine present to run this test with. Check %s and the paths therein.' % config.EM_CONFIG)
for engine in engines:
js_output = self.run_js(js_file, engine, args,
input=input,
assert_returncode=assert_returncode,
interleaved_output=interleaved_output)
js_output = js_output.replace('\r\n', '\n')
Expand Down
21 changes: 1 addition & 20 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from tools import shared, building, config, utils, webassembly
import common
from common import RunnerCore, path_from_root, requires_native_clang, test_file, create_file
from common import skip_if, no_windows, is_slow_test, parameterized, parameterize
from common import skip_if, no_windows, is_slow_test, parameterized, parameterize, all_engines
from common import env_modify, with_env_modify, disabled, flaky, node_pthreads, also_without_bigint
from common import read_file, read_binary, requires_v8, requires_node, requires_dev_dependency, requires_wasm2js, requires_node_canary
from common import compiler_for, crossplatform, no_4gb, no_2gb, also_with_minimal_runtime, also_with_modularize
Expand Down Expand Up @@ -183,25 +183,6 @@ def decorated(self, dylink_reversed, *args, **kwargs):
return decorated


# without EMTEST_ALL_ENGINES set we only run tests in a single VM by
# default. in some tests we know that cross-VM differences may happen and
# so are worth testing, and they should be marked with this decorator
def all_engines(f):
assert callable(f)

@wraps(f)
def decorated(self, *args, **kwargs):
old = self.use_all_engines
self.use_all_engines = True
self.set_setting('ENVIRONMENT', 'web,node,shell')
try:
f(self, *args, **kwargs)
finally:
self.use_all_engines = old

return decorated


def no_wasm2js(note=''):
assert not callable(note)

Expand Down
39 changes: 13 additions & 26 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from common import also_with_modularize, also_with_wasmfs, with_all_fs
from common import also_with_minimal_runtime, also_without_bigint, also_with_wasm64, also_with_asan, flaky
from common import EMTEST_BUILD_VERBOSE, PYTHON, WEBIDL_BINDER, EMCMAKE, EMCONFIGURE
from common import requires_network, parameterize, copytree
from common import requires_network, parameterize, copytree, all_engines
from tools import shared, building, utils, response_file, cache
from tools.utils import read_file, write_file, delete_file, read_binary, MACOS, WINDOWS
import common
Expand Down Expand Up @@ -1696,19 +1696,15 @@ def test_export_all_and_exported_functions(self):
self.emcc('lib.c', ['-sEXPORTED_FUNCTIONS=_libfunc2', '-sEXPORT_ALL', '--pre-js', 'pre.js'], output_filename='a.out.js')
self.assertContained('libfunc\n', self.run_js('a.out.js'))

@all_engines
@also_with_wasmfs
@crossplatform
@parameterized({
'': ([],),
'closure': (['-O2', '--closure=1'],),
})
def test_stdin(self, args):
self.set_setting('ENVIRONMENT', 'node,shell')
self.emcc(test_file('module/test_stdin.c'), args=args, output_filename='out.js')

for engine in config.JS_ENGINES:
output = self.run_js('out.js', engine, input='abcdef\nghijkl\n')
self.assertContained('abcdef\nghijkl\neof', output)
self.do_runf('module/test_stdin.c', 'abcdef\nghijkl\neof', input='abcdef\nghijkl\n', cflags=args)

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

@crossplatform
@all_engines
def test_fs_stream_proto(self):
create_file('src.c', br'''
#include <stdio.h>
Expand Down Expand Up @@ -4316,10 +4313,7 @@ def test_fs_stream_proto(self):
return 0;
}
''', binary=True)
self.run_process([EMCC, 'src.c', '--embed-file', 'src.c', '-sENVIRONMENT=node,shell'])
for engine in config.JS_ENGINES:
out = self.run_js('a.out.js', engine=engine)
self.assertContained('File size: 682', out)
self.do_runf('src.c', 'File size: 682', cflags=['--embed-file', 'src.c'])

@node_pthreads
def test_node_emscripten_num_logical_cores(self):
Expand Down Expand Up @@ -6832,6 +6826,7 @@ def test_create_readonly(self):
Failed to open file for writing: /tmp/file; errno=2; Permission denied
''')

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

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

@all_engines
def test_INCOMING_MODULE_JS_API(self):
def test(args):
self.run_process([EMCC, test_file('hello_world.c'), '-O3', '--closure=1', '-sENVIRONMENT=node,shell', '--output-eol=linux'] + args)
for engine in config.JS_ENGINES:
self.assertContained('hello, world!', self.run_js('a.out.js', engine=engine))
return os.path.getsize('a.out.js')
self.do_runf('hello_world.c', 'hello, world!', cflags=['-O3', '--closure=1', '-sENVIRONMENT=node,shell', '--output-eol=linux'] + args)
return os.path.getsize('hello_world.js')
normal = test([])
changed = test(['-sINCOMING_MODULE_JS_API=[]'])
print('sizes', normal, changed)
Expand Down Expand Up @@ -12941,13 +12930,11 @@ def test_linker_input_unused(self):
# In this case the compiler does not produce any output file.
self.assertNotExists('out.o')

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

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