From 512e600ea769b92c12974ea9f672e37ef6a92d5a Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 6 Jan 2025 11:53:38 -0800 Subject: [PATCH] [test] Simplify `also_with_proxying`. NFC (#23296) Implement `also_with_proxying` solely in `test_browser.py` avoiding the need for `self.proxying` handling in `common.js`. --- test/common.py | 11 +++-------- test/test_browser.py | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/test/common.py b/test/common.py index 04c02ab73d069..10a8ab2fc8c71 100644 --- a/test/common.py +++ b/test/common.py @@ -1115,7 +1115,6 @@ def setUp(self): self.js_engines = config.JS_ENGINES.copy() self.settings_mods = {} self.skip_exec = None - self.proxied = False 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. @@ -1284,7 +1283,7 @@ def add_on_exit(self, code): # libraries, for example def get_emcc_args(self, main_file=False, compile_only=False, asm_only=False): def is_ldflag(f): - return any(f.startswith(s) for s in ['-sEXPORT_ES6', '-sPROXY_TO_PTHREAD', '-sENVIRONMENT=', '--pre-js=', '--post-js=', '-sPTHREAD_POOL_SIZE=']) + return any(f.startswith(s) for s in ['-sEXPORT_ES6', '--proxy-to-worker', '-sGL_TESTING', '-sPROXY_TO_WORKER', '-sPROXY_TO_PTHREAD', '-sENVIRONMENT=', '--pre-js=', '--post-js=', '-sPTHREAD_POOL_SIZE=']) args = self.serialize_settings(compile_only or asm_only) + self.emcc_args if asm_only: @@ -1690,7 +1689,8 @@ 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(compile_only='-c' in args) + args + compile_only = '-c' in args or '-sSIDE_MODULE' in args + cmd = [compiler_for(filename), filename] + self.get_emcc_args(compile_only=compile_only) + args if output_filename: cmd += ['-o', output_filename] self.run_process(cmd, **kwargs) @@ -2324,11 +2324,6 @@ def btest(self, filename, expected=None, args = [] args = args.copy() filename = find_browser_test_file(filename) - - # Run via --proxy-to-worker. This gets set by the @also_with_proxying. - if self.proxied: - args += ['--proxy-to-worker', '-sGL_TESTING'] - outfile = output_basename + '.html' args += ['-o', outfile] # print('all args:', args) diff --git a/test/test_browser.py b/test/test_browser.py index 20f0388ceeee7..b16e2481d989f 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -105,7 +105,8 @@ def also_with_proxying(f): def metafunc(self, proxied, *args, **kwargs): if DEBUG: print('parameterize:proxied=%d' % proxied) - self.proxied = proxied + if proxied: + self.proxy_to_worker() f(self, *args, **kwargs) parameterize(metafunc, {'': (False,), @@ -118,7 +119,7 @@ def proxied(f): @wraps(f) def decorated(self, *args, **kwargs): - self.proxied = True + self.proxy_to_worker() return f(self, *args, **kwargs) return decorated @@ -243,6 +244,9 @@ def setUp(self): '-Wno-int-conversion', ] + def proxy_to_worker(self): + self.emcc_args += ['--proxy-to-worker', '-sGL_TESTING'] + def require_jspi(self): if not is_chrome(): self.skipTest(f'Current browser ({EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.') @@ -283,7 +287,7 @@ def reftest(self, filename, reference, reference_slack=0, *args, **kwargs): assert 'expected' not in kwargs expected = [str(i) for i in range(0, reference_slack + 1)] self.make_reftest(reference) - if self.proxied: + if '--proxy-to-worker' in self.emcc_args: assert 'post_build' not in kwargs kwargs['post_build'] = self.post_manual_reftest create_file('fakereftest.js', 'var reftestUnblock = () => {}; var reftestBlock = () => {};') @@ -2032,7 +2036,7 @@ def test_cubegeom_pre3(self): }) @requires_graphics_hardware def test_cubegeom(self, args): - if self.proxied and args: + if '--proxy-to-worker' in self.emcc_args and args: # proxy only in the simple, normal case (we can't trace GL calls when proxied) self.skipTest('tracing + proxying not supported') self.reftest('third_party/cubegeom/cubegeom.c', 'third_party/cubegeom/cubegeom.png', args=['-O2', '-g', '-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'] + args) @@ -3003,7 +3007,7 @@ def test_sdl2_threads(self): @requires_graphics_hardware @also_with_proxying def test_sdl2_glshader(self): - if not self.proxied: + if '--proxy-to-worker' not in self.emcc_args: # closure build current fails on proxying self.emcc_args += ['--closure=1', '-g1'] self.reftest('test_sdl2_glshader.c', 'test_sdl_glshader.png', args=['-sUSE_SDL=2', '-sLEGACY_GL_EMULATION']) @@ -3443,11 +3447,8 @@ def test_webidl(self, args): self.btest('webidl/test.cpp', '1', args=['--post-js', 'glue.js', '-I.', '-DBROWSER'] + args) @no_wasm64('https://github.com/llvm/llvm-project/issues/98778') - @parameterized({ - '': ([],), - 'proxy_to_worker': (['--proxy-to-worker'],), - }) - def test_dylink(self, args): + @also_with_proxying + def test_dylink(self): create_file('main.c', r''' #include #include @@ -3468,7 +3469,7 @@ def test_dylink(self, args): } ''') self.emcc('side.c', ['-sSIDE_MODULE', '-O2', '-o', 'side.wasm']) - self.btest_exit('main.c', args=['-sMAIN_MODULE=2', '-O2', 'side.wasm'] + args) + self.btest_exit('main.c', args=['-sMAIN_MODULE=2', '-O2', 'side.wasm']) def test_dlopen_async(self): create_file('side.c', 'int foo = 42;\n')