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 20, 2024
1 parent edc1a75 commit edad436
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 92 deletions.
45 changes: 25 additions & 20 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from tools.shared import EMCC, EMXX, DEBUG, EMCONFIGURE, EMCMAKE
from tools.shared import get_canonical_temp_dir, path_from_root
from tools.utils import MACOS, WINDOWS, read_file, read_binary, write_binary, exit_with_error
from tools.settings import COMPILE_TIME_SETTINGS
from tools import shared, line_endings, building, config, utils

logger = logging.getLogger('common')
Expand Down Expand Up @@ -771,7 +772,7 @@ def require_jspi(self):
# emcc warns about stack switching being experimental, and we build with
# warnings-as-errors, so disable that warning
self.emcc_args += ['-Wno-experimental']
self.emcc_args += ['-sASYNCIFY=2']
self.set_setting('ASYNCIFY', 2)
if not self.is_wasm():
self.skipTest('JSPI is not currently supported for WASM2JS')

Expand Down Expand Up @@ -959,9 +960,11 @@ 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, compile_only=False):
ret = []
for key, value in self.settings_mods.items():
if compile_only and key not in COMPILE_TIME_SETTINGS:
continue
if value == 1:
ret.append(f'-s{key}')
elif type(value) is list:
Expand Down Expand Up @@ -995,15 +998,15 @@ def add_on_exit(self, code):
# param @main_file whether this is the main file of the test. some arguments
# (like --pre-js) do not need to be passed when building
# libraries, for example
def get_emcc_args(self, main_file=False, ldflags=True):
def get_emcc_args(self, main_file=False, compile_only=False):
def is_ldflag(f):
return any(f.startswith(s) for s in ['-sENVIRONMENT=', '--pre-js=', '--post-js='])

args = self.serialize_settings() + self.emcc_args
if ldflags:
args += self.ldflags
else:
args = self.serialize_settings(compile_only) + self.emcc_args
if compile_only:
args = [a for a in args if not is_ldflag(a)]
else:
args += self.ldflags
if not main_file:
for i, arg in enumerate(args):
if arg in ('--pre-js', '--post-js'):
Expand Down Expand Up @@ -1359,7 +1362,7 @@ def get_library(self, name, generated_libs, configure=['sh', './configure'], #
# try to pass linker settings when compiling).
emcc_args = []
if not native:
emcc_args = self.get_emcc_args(ldflags=False)
emcc_args = self.get_emcc_args(compile_only=False)

hash_input = (str(emcc_args) + ' $ ' + str(env_init)).encode('utf-8')
cache_name = name + ','.join([opt for opt in emcc_args if len(opt) < 7]) + '_' + hashlib.md5(hash_input).hexdigest() + cache_name_extra
Expand Down Expand Up @@ -1408,7 +1411,7 @@ def run_process(self, cmd, check=True, **args):
self.fail(f'subprocess exited with non-zero return code({e.returncode}): `{shared.shlex_join(cmd)}`')

def emcc(self, filename, args=[], output_filename=None, **kwargs): # noqa
cmd = [compiler_for(filename), filename] + self.get_emcc_args(ldflags='-c' not in args) + args
cmd = [compiler_for(filename), filename] + self.get_emcc_args(compile_only='-c' in args) + args
if output_filename:
cmd += ['-o', output_filename]
self.run_process(cmd, **kwargs)
Expand Down Expand Up @@ -2111,24 +2114,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')]
# If C reporting (i.e. the REPORT_RESULT macro) is required we
# also include report_result.c and force-include report_result.h
self.run_process([EMCC, '-c', '-I' + TEST_ROOT,
'-DEMTEST_PORT_NUMBER=%d' % self.port,
test_file('report_result.c')] + self.get_emcc_args(compile_only=True))
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 @@ -2171,10 +2176,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 edad436

Please sign in to comment.