Skip to content

Commit

Permalink
[test] Pass filename explicitly to compile_btest helper. NFC
Browse files Browse the repository at this point in the history
This allows us to use `compiler_for` to determine whether to run
`EMCC` or `EMXX` appropriately.
  • Loading branch information
sbc100 committed Jan 18, 2024
1 parent 8915f2b commit 9b067e5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 71 deletions.
33 changes: 22 additions & 11 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,11 @@ def setUp(self):
self.js_engines = config.JS_ENGINES.copy()
self.settings_mods = {}
self.emcc_args = ['-Wclosure', '-Werror', '-Wno-limited-postlink-optimizations']
# TODO(https://github.com/emscripten-core/emscripten/issues/11121)
# For historical reasons emcc compiles and links as C++ by default.
# However we want to run our tests in a more strict manner. We can
# remove this if the issue above is ever fixed.
self.set_setting('NO_DEFAULT_TO_CXX')
self.ldflags = []
# Increate stack trace limit to maximise usefulness of test failure reports
self.node_args = ['--stack-trace-limit=50']
Expand Down Expand Up @@ -954,9 +959,13 @@ def has_changed_setting(self, key):
def clear_setting(self, key):
self.settings_mods.pop(key, None)

def serialize_settings(self):
def serialize_settings(self, ldflags=True):
ret = []
# Incomplete list of link-only settings
link_only_settings = ['NO_DEFAULT_TO_CXX', 'DEFAULT_LIBRARY_FUNCS_TO_INCLUDE']
for key, value in self.settings_mods.items():
if not ldflags and key in link_only_settings:
continue
if value == 1:
ret.append(f'-s{key}')
elif type(value) is list:
Expand Down Expand Up @@ -994,7 +1003,7 @@ def get_emcc_args(self, main_file=False, ldflags=True):
def is_ldflag(f):
return any(f.startswith(s) for s in ['-sENVIRONMENT=', '--pre-js=', '--post-js='])

args = self.serialize_settings() + self.emcc_args
args = self.serialize_settings(ldflags) + self.emcc_args
if ldflags:
args += self.ldflags
else:
Expand Down Expand Up @@ -2106,24 +2115,26 @@ def reftest(self, expected, manually_trigger=False):
setupRefTest();
''' % (reporting, basename, int(manually_trigger)))

def compile_btest(self, args, reporting=Reporting.FULL):
def compile_btest(self, filename, args, reporting=Reporting.FULL):
# Inject support code for reporting results. This adds an include a header so testcases can
# use REPORT_RESULT, and also adds a cpp file to be compiled alongside the testcase, which
# contains the implementation of REPORT_RESULT (we can't just include that implementation in
# the header as there may be multiple files being compiled here).
if reporting != Reporting.NONE:
# For basic reporting we inject JS helper funtions to report result back to server.
args += ['-DEMTEST_PORT_NUMBER=%d' % self.port,
'--pre-js', test_file('browser_reporting.js')]
args += ['--pre-js', test_file('browser_reporting.js')]
if reporting == Reporting.FULL:
# If C reporting (i.e. REPORT_RESULT macro) is required
# also compile in report_result.c and forice-include report_result.h
args += ['-I' + TEST_ROOT,
'-include', test_file('report_result.h'),
test_file('report_result.c')]
self.run_process([EMCC, '-c', '-I' + TEST_ROOT,
'-DEMTEST_PORT_NUMBER=%d' % self.port,
test_file('report_result.c')] + self.get_emcc_args(ldflags=False))
args += ['report_result.o', '-include', test_file('report_result.h')]
if EMTEST_BROWSER == 'node':
args.append('-DEMTEST_NODE')
self.run_process([EMCC] + self.get_emcc_args() + args)
if not os.path.exists(filename):
filename = test_file(filename)
self.run_process([compiler_for(filename), filename] + self.get_emcc_args() + args)

def btest_exit(self, filename, assert_returncode=0, *args, **kwargs):
"""Special case of btest that reports its result solely via exiting
Expand Down Expand Up @@ -2166,10 +2177,10 @@ def btest(self, filename, expected=None, reference=None,
# manual_reference only makes sense for reference tests
assert manual_reference is None
outfile = output_basename + '.html'
args += [filename, '-o', outfile]
args += ['-o', outfile]
# print('all args:', args)
utils.delete_file(outfile)
self.compile_btest(args, reporting=reporting)
self.compile_btest(filename, args, reporting=reporting)
self.assertExists(outfile)
if post_build:
post_build()
Expand Down
Loading

0 comments on commit 9b067e5

Please sign in to comment.