Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Pass filename explicitly to compile_btest helper. NFC #21103

Merged
merged 1 commit into from
Jan 22, 2024
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
58 changes: 31 additions & 27 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 @@ -1354,12 +1357,12 @@ def get_library(self, name, generated_libs, configure=['sh', './configure'], #
build_dir = self.get_build_dir()
output_dir = self.get_dir()

# get_library() is used to compile libraries, and not link executables,
# so we don't want to pass linker flags here (emscripten warns if you
# try to pass linker settings when compiling).
emcc_args = []
if not native:
emcc_args = self.get_emcc_args(ldflags=False)
# get_library() is used to compile libraries, and not link executables,
# so we don't want to pass linker flags here (emscripten warns if you
# try to pass linker settings when compiling).
emcc_args = self.get_emcc_args(compile_only=True)

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 @@ -1662,10 +1665,6 @@ def get_freetype_library(self):
def get_poppler_library(self, env_init=None):
freetype = self.get_freetype_library()

# The fontconfig symbols are all missing from the poppler build
# e.g. FcConfigSubstitute
self.set_setting('ERROR_ON_UNDEFINED_SYMBOLS', 0)

self.emcc_args += [
'-I' + test_file('third_party/freetype/include'),
'-I' + test_file('third_party/poppler/include')
Expand All @@ -1681,6 +1680,9 @@ def get_poppler_library(self, env_init=None):
'-Wno-unknown-pragmas',
'-Wno-shift-negative-value',
'-Wno-dynamic-class-memaccess',
# The fontconfig symbols are all missing from the poppler build
# e.g. FcConfigSubstitute
'-sERROR_ON_UNDEFINED_SYMBOLS=0',
# Avoid warning about ERROR_ON_UNDEFINED_SYMBOLS being used at compile time
'-Wno-unused-command-line-argument',
'-Wno-js-compiler',
Expand Down Expand Up @@ -2111,24 +2113,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 +2175,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