Skip to content

Commit 512e600

Browse files
authored
[test] Simplify also_with_proxying. NFC (emscripten-core#23296)
Implement `also_with_proxying` solely in `test_browser.py` avoiding the need for `self.proxying` handling in `common.js`.
1 parent d0de8d8 commit 512e600

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

test/common.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,6 @@ def setUp(self):
11151115
self.js_engines = config.JS_ENGINES.copy()
11161116
self.settings_mods = {}
11171117
self.skip_exec = None
1118-
self.proxied = False
11191118
self.emcc_args = ['-Wclosure', '-Werror', '-Wno-limited-postlink-optimizations']
11201119
# TODO(https://github.com/emscripten-core/emscripten/issues/11121)
11211120
# For historical reasons emcc compiles and links as C++ by default.
@@ -1284,7 +1283,7 @@ def add_on_exit(self, code):
12841283
# libraries, for example
12851284
def get_emcc_args(self, main_file=False, compile_only=False, asm_only=False):
12861285
def is_ldflag(f):
1287-
return any(f.startswith(s) for s in ['-sEXPORT_ES6', '-sPROXY_TO_PTHREAD', '-sENVIRONMENT=', '--pre-js=', '--post-js=', '-sPTHREAD_POOL_SIZE='])
1286+
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='])
12881287

12891288
args = self.serialize_settings(compile_only or asm_only) + self.emcc_args
12901289
if asm_only:
@@ -1690,7 +1689,8 @@ def run_process(self, cmd, check=True, **args):
16901689
self.fail(f'subprocess exited with non-zero return code({e.returncode}): `{shared.shlex_join(cmd)}`')
16911690

16921691
def emcc(self, filename, args=[], output_filename=None, **kwargs): # noqa
1693-
cmd = [compiler_for(filename), filename] + self.get_emcc_args(compile_only='-c' in args) + args
1692+
compile_only = '-c' in args or '-sSIDE_MODULE' in args
1693+
cmd = [compiler_for(filename), filename] + self.get_emcc_args(compile_only=compile_only) + args
16941694
if output_filename:
16951695
cmd += ['-o', output_filename]
16961696
self.run_process(cmd, **kwargs)
@@ -2324,11 +2324,6 @@ def btest(self, filename, expected=None,
23242324
args = []
23252325
args = args.copy()
23262326
filename = find_browser_test_file(filename)
2327-
2328-
# Run via --proxy-to-worker. This gets set by the @also_with_proxying.
2329-
if self.proxied:
2330-
args += ['--proxy-to-worker', '-sGL_TESTING']
2331-
23322327
outfile = output_basename + '.html'
23332328
args += ['-o', outfile]
23342329
# print('all args:', args)

test/test_browser.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def also_with_proxying(f):
105105
def metafunc(self, proxied, *args, **kwargs):
106106
if DEBUG:
107107
print('parameterize:proxied=%d' % proxied)
108-
self.proxied = proxied
108+
if proxied:
109+
self.proxy_to_worker()
109110
f(self, *args, **kwargs)
110111

111112
parameterize(metafunc, {'': (False,),
@@ -118,7 +119,7 @@ def proxied(f):
118119

119120
@wraps(f)
120121
def decorated(self, *args, **kwargs):
121-
self.proxied = True
122+
self.proxy_to_worker()
122123
return f(self, *args, **kwargs)
123124

124125
return decorated
@@ -243,6 +244,9 @@ def setUp(self):
243244
'-Wno-int-conversion',
244245
]
245246

247+
def proxy_to_worker(self):
248+
self.emcc_args += ['--proxy-to-worker', '-sGL_TESTING']
249+
246250
def require_jspi(self):
247251
if not is_chrome():
248252
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):
283287
assert 'expected' not in kwargs
284288
expected = [str(i) for i in range(0, reference_slack + 1)]
285289
self.make_reftest(reference)
286-
if self.proxied:
290+
if '--proxy-to-worker' in self.emcc_args:
287291
assert 'post_build' not in kwargs
288292
kwargs['post_build'] = self.post_manual_reftest
289293
create_file('fakereftest.js', 'var reftestUnblock = () => {}; var reftestBlock = () => {};')
@@ -2032,7 +2036,7 @@ def test_cubegeom_pre3(self):
20322036
})
20332037
@requires_graphics_hardware
20342038
def test_cubegeom(self, args):
2035-
if self.proxied and args:
2039+
if '--proxy-to-worker' in self.emcc_args and args:
20362040
# proxy only in the simple, normal case (we can't trace GL calls when proxied)
20372041
self.skipTest('tracing + proxying not supported')
20382042
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):
30033007
@requires_graphics_hardware
30043008
@also_with_proxying
30053009
def test_sdl2_glshader(self):
3006-
if not self.proxied:
3010+
if '--proxy-to-worker' not in self.emcc_args:
30073011
# closure build current fails on proxying
30083012
self.emcc_args += ['--closure=1', '-g1']
30093013
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):
34433447
self.btest('webidl/test.cpp', '1', args=['--post-js', 'glue.js', '-I.', '-DBROWSER'] + args)
34443448

34453449
@no_wasm64('https://github.com/llvm/llvm-project/issues/98778')
3446-
@parameterized({
3447-
'': ([],),
3448-
'proxy_to_worker': (['--proxy-to-worker'],),
3449-
})
3450-
def test_dylink(self, args):
3450+
@also_with_proxying
3451+
def test_dylink(self):
34513452
create_file('main.c', r'''
34523453
#include <assert.h>
34533454
#include <stdio.h>
@@ -3468,7 +3469,7 @@ def test_dylink(self, args):
34683469
}
34693470
''')
34703471
self.emcc('side.c', ['-sSIDE_MODULE', '-O2', '-o', 'side.wasm'])
3471-
self.btest_exit('main.c', args=['-sMAIN_MODULE=2', '-O2', 'side.wasm'] + args)
3472+
self.btest_exit('main.c', args=['-sMAIN_MODULE=2', '-O2', 'side.wasm'])
34723473

34733474
def test_dlopen_async(self):
34743475
create_file('side.c', 'int foo = 42;\n')

0 commit comments

Comments
 (0)