Skip to content

Commit

Permalink
Don't set shared.Settings from test runners (emscripten-core#6801)
Browse files Browse the repository at this point in the history
* Don't set shared.Settings from test runners, only serialize modifications

* xrange -> range

* Fix rebase

* Remove re-added skip method

* Show error on emcc Settings assertions

* Remove redundant (not-actually-used-before) arg parsing code in test setup

* Re-add removed code, use json.loads to parse the setting.

Turns out we use these overrides from the test runner to get_settings
based on default environment. Meaning, running the asm2 test suite would
have self.get_setting('WASM') == 1, because wasm is default.
  • Loading branch information
jgravelle-google authored Jul 12, 2018
1 parent 0c8c9cd commit badb580
Show file tree
Hide file tree
Showing 4 changed files with 416 additions and 333 deletions.
1 change: 1 addition & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ def check(input_file):
assert shared.Settings.PGO == 0, 'pgo not supported in fastcomp'
assert shared.Settings.QUANTUM_SIZE == 4, 'altering the QUANTUM_SIZE is not supported'
except Exception as e:
logging.error('Compiler settings error: {}'.format(e))
exit_with_error('Compiler settings are incompatible with fastcomp. You can fall back to the older compiler core, although that is not recommended, see http://kripken.github.io/emscripten-site/docs/building_from_source/LLVM-Backend.html')

assert not shared.Settings.PGO, 'cannot run PGO in ASM_JS mode'
Expand Down
33 changes: 25 additions & 8 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import webbrowser, hashlib, threading, platform
import multiprocessing, functools, stat, string, random, fnmatch
import atexit
import json
import operator
import parallel_runner

Expand Down Expand Up @@ -134,6 +135,7 @@ class RunnerCore(unittest.TestCase):
# Change this to None to get stderr reporting, for debugging purposes

env = {}
settings_mods = {}

EM_TESTRUNNER_DETECT_TEMPFILE_LEAKS = int(os.getenv('EM_TESTRUNNER_DETECT_TEMPFILE_LEAKS')) if os.getenv('EM_TESTRUNNER_DETECT_TEMPFILE_LEAKS') != None else 0

Expand All @@ -143,7 +145,7 @@ def is_emterpreter(self):
return False

def is_wasm_backend(self):
return Settings.WASM_BACKEND
return self.get_setting('WASM_BACKEND')

def uses_memory_init_file(self):
if self.emcc_args is None:
Expand All @@ -152,7 +154,8 @@ def uses_memory_init_file(self):
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
return ('-O2' in self.emcc_args or '-O3' in self.emcc_args or '-Oz' in self.emcc_args) and not (Settings.SIDE_MODULE or Settings.WASM)
opt_supports = any(opt in self.emcc_args for opt in ('-O2', '-O3', '-Oz'))
return opt_supports and not (self.get_setting('SIDE_MODULE') or self.get_setting('WASM'))

def set_temp_dir(self, temp_dir):
self.temp_dir = temp_dir
Expand All @@ -161,7 +164,7 @@ def set_temp_dir(self, temp_dir):
os.environ['EMCC_TEMP_DIR'] = self.temp_dir

def setUp(self):
Settings.reset()
self.settings_mods = {}

if self.EM_TESTRUNNER_DETECT_TEMPFILE_LEAKS:
for root, dirnames, filenames in os.walk(self.temp_dir):
Expand Down Expand Up @@ -219,6 +222,20 @@ def tearDown(self):
# assert not temp_file.endswith('.ll'), temp_file
# # TODO assert not temp_file.startswith('emscripten_'), temp_file

def get_setting(self, key):
if key in self.settings_mods:
return self.settings_mods[key]
return Settings[key]

def set_setting(self, key, value):
self.settings_mods[key] = value

def serialize_settings(self):
ret = []
for key, value in self.settings_mods.items():
ret += ['-s', '{}={}'.format(key, json.dumps(value))]
return ret

def get_dir(self):
return self.working_dir

Expand Down Expand Up @@ -307,7 +324,7 @@ def ll_to_js(self, filename, post_build):
transform.write('\nprocess(sys.argv[1])\n')
transform.close()
transform_args = ['--js-transform', "%s '%s'" % (PYTHON, transform_filename)]
Building.emcc(filename + '.o', Settings.serialize() + emcc_args + transform_args + Building.COMPILER_TEST_OPTS, filename + '.o.js')
Building.emcc(filename + '.o', self.serialize_settings() + emcc_args + transform_args + Building.COMPILER_TEST_OPTS, filename + '.o.js')
if post2: post2(filename + '.o.js')

# Build JavaScript code from source code
Expand Down Expand Up @@ -348,7 +365,7 @@ def build(self, src, dirname, filename, output_processor=None, main_file=None, a
os.remove(f + '.o')
except:
pass
args = [PYTHON, EMCC] + Building.COMPILER_TEST_OPTS + Settings.serialize() + \
args = [PYTHON, EMCC] + Building.COMPILER_TEST_OPTS + self.serialize_settings() + \
['-I', dirname, '-I', os.path.join(dirname, 'include')] + \
['-I' + include for include in includes] + \
['-c', f, '-o', f + '.o']
Expand Down Expand Up @@ -376,7 +393,7 @@ def build(self, src, dirname, filename, output_processor=None, main_file=None, a
if '.' not in all_files[i]:
shutil.move(all_files[i], all_files[i] + '.bc')
all_files[i] += '.bc'
args = [PYTHON, EMCC] + Building.COMPILER_TEST_OPTS + Settings.serialize() + \
args = [PYTHON, EMCC] + Building.COMPILER_TEST_OPTS + self.serialize_settings() + \
self.emcc_args + \
['-I', dirname, '-I', os.path.join(dirname, 'include')] + \
['-I' + include for include in includes] + \
Expand Down Expand Up @@ -477,7 +494,7 @@ def run_generated_code(self, engine, filename, args=[], check_timeout=True, outp
os.chdir(cwd)
out = open(stdout, 'r').read()
err = open(stderr, 'r').read()
if engine == SPIDERMONKEY_ENGINE and Settings.ASM_JS == 1:
if engine == SPIDERMONKEY_ENGINE and self.get_setting('ASM_JS') == 1:
err = self.validate_asmjs(err)
if output_nicerizer:
ret = output_nicerizer(out, err)
Expand Down Expand Up @@ -664,7 +681,7 @@ def do_run(self, src, expected_output, args=[], output_nicerizer=None,
js_engines=None, post_build=None, basename='src.cpp', libraries=[],
includes=[], force_c=False, build_ll_hook=None,
assert_returncode=None, assert_identical=False):
if Settings.ASYNCIFY == 1 and self.is_wasm_backend():
if self.get_setting('ASYNCIFY') == 1 and self.is_wasm_backend():
self.skipTest("wasm backend doesn't support ASYNCIFY yet")
if force_c or (main_file is not None and main_file[-2:]) == '.c':
basename = 'src.c'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@ def test_aniso(self):
if SPIDERMONKEY_ENGINE in JS_ENGINES:
# asm.js-ification check
Popen([PYTHON, EMCC, path_from_root('tests', 'aniso.c'), '-O2', '-g2', '-s', 'LEGACY_GL_EMULATION=1', '-lGL', '-lSDL', '-Wno-incompatible-pointer-types']).communicate()
Settings.ASM_JS = 1
self.set_setting('ASM_JS', 1)
self.run_generated_code(SPIDERMONKEY_ENGINE, 'a.out.js', assert_returncode=None)
print('passed asm test')

Expand Down
Loading

0 comments on commit badb580

Please sign in to comment.