Skip to content

Commit b45857f

Browse files
authored
[test] Add @also_with_proxying decorator. NFC (#21979)
1 parent 2c865a1 commit b45857f

File tree

2 files changed

+66
-39
lines changed

2 files changed

+66
-39
lines changed

test/common.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ def setUp(self):
985985
self.js_engines = config.JS_ENGINES.copy()
986986
self.settings_mods = {}
987987
self.skip_exec = None
988+
self.proxied = False
988989
self.emcc_args = ['-Wclosure', '-Werror', '-Wno-limited-postlink-optimizations']
989990
# TODO(https://github.com/emscripten-core/emscripten/issues/11121)
990991
# For historical reasons emcc compiles and links as C++ by default.
@@ -2302,17 +2303,25 @@ def btest_exit(self, filename, assert_returncode=0, *args, **kwargs):
23022303

23032304
def btest(self, filename, expected=None, reference=None,
23042305
reference_slack=0, manual_reference=None, post_build=None,
2305-
args=None, also_proxied=False,
2306-
url_suffix='', timeout=None,
2306+
args=None, url_suffix='', timeout=None,
23072307
manually_trigger_reftest=False, extra_tries=1,
23082308
reporting=Reporting.FULL,
23092309
output_basename='test'):
23102310
assert expected or reference, 'a btest must either expect an output, or have a reference image'
23112311
if args is None:
23122312
args = []
2313-
original_args = args
23142313
args = args.copy()
23152314
filename = find_browser_test_file(filename)
2315+
2316+
# Run via --proxy-to-worker. This gets set by the @also_with_proxying.
2317+
if self.proxied:
2318+
if reference:
2319+
assert not manual_reference
2320+
manual_reference = True
2321+
manually_trigger_reftest = False
2322+
assert not post_build
2323+
post_build = self.post_manual_reftest
2324+
args += ['--proxy-to-worker', '-sGL_TESTING']
23162325
if reference:
23172326
reference = find_browser_test_file(reference)
23182327
expected = [str(i) for i in range(0, reference_slack + 1)]
@@ -2340,17 +2349,6 @@ def btest(self, filename, expected=None, reference=None,
23402349
else:
23412350
self.run_browser(outfile + url_suffix, expected=['/report_result?' + e for e in expected], timeout=timeout, extra_tries=extra_tries)
23422351

2343-
if also_proxied:
2344-
print('proxied...')
2345-
if reference:
2346-
assert not manual_reference
2347-
manual_reference = True
2348-
assert not post_build
2349-
post_build = self.post_manual_reftest
2350-
# run proxied
2351-
self.btest(filename, expected, reference, reference_slack, manual_reference, post_build,
2352-
original_args + ['--proxy-to-worker', '-sGL_TESTING'], timeout=timeout)
2353-
23542352

23552353
###################################################################################################
23562354

test/test_browser.py

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from common import BrowserCore, RunnerCore, path_from_root, has_browser, EMTEST_BROWSER, Reporting
2424
from common import create_file, parameterized, ensure_dir, disabled, test_file, WEBIDL_BINDER
2525
from common import read_file, also_with_minimal_runtime, EMRUN, no_wasm64, no_2gb, no_4gb
26-
from common import requires_wasm2js, also_with_wasm2js
26+
from common import requires_wasm2js, also_with_wasm2js, parameterize
2727
from tools import shared
2828
from tools import ports
2929
from tools import utils
@@ -78,6 +78,9 @@ def do_GET(s):
7878

7979

8080
def also_with_wasmfs(f):
81+
assert callable(f)
82+
83+
@wraps(f)
8184
def metafunc(self, wasmfs, *args, **kwargs):
8285
if wasmfs:
8386
self.set_setting('WASMFS')
@@ -86,9 +89,22 @@ def metafunc(self, wasmfs, *args, **kwargs):
8689
else:
8790
f(self, *args, **kwargs)
8891

89-
metafunc._parameterize = {'': (False,),
90-
'wasmfs': (True,)}
92+
parameterize(metafunc, {'': (False,),
93+
'wasmfs': (True,)})
94+
95+
return metafunc
96+
97+
98+
def also_with_proxying(f):
99+
assert callable(f)
100+
101+
@wraps(f)
102+
def metafunc(self, proxied, *args, **kwargs):
103+
self.proxied = proxied
104+
f(self, *args, **kwargs)
91105

106+
parameterize(metafunc, {'': (False,),
107+
'proxied': (True,)})
92108
return metafunc
93109

94110

@@ -761,10 +777,11 @@ def test_sdl_image_jpeg(self):
761777
])
762778

763779
@also_with_wasmfs
780+
@also_with_proxying
764781
def test_sdl_image_prepare(self):
765782
# load an image file, get pixel data.
766783
shutil.copyfile(test_file('screenshot.jpg'), 'screenshot.not')
767-
self.reftest('test_sdl_image_prepare.c', 'screenshot.jpg', args=['--preload-file', 'screenshot.not', '-lSDL', '-lGL'], also_proxied=True, manually_trigger_reftest=True)
784+
self.reftest('test_sdl_image_prepare.c', 'screenshot.jpg', args=['--preload-file', 'screenshot.not', '-lSDL', '-lGL'], manually_trigger_reftest=True)
768785

769786
@parameterized({
770787
'': ([],),
@@ -1957,8 +1974,9 @@ def test_sdl_glshader(self):
19571974

19581975
@no_wasm64('TODO: LEGACY_GL_EMULATION + wasm64')
19591976
@requires_graphics_hardware
1977+
@also_with_proxying
19601978
def test_sdl_glshader2(self):
1961-
self.btest_exit('test_sdl_glshader2.c', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL', '-sGL_ENABLE_GET_PROC_ADDRESS'], also_proxied=True)
1979+
self.btest_exit('test_sdl_glshader2.c', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL', '-sGL_ENABLE_GET_PROC_ADDRESS'])
19621980

19631981
@requires_graphics_hardware
19641982
def test_gl_glteximage(self):
@@ -1990,9 +2008,10 @@ def test_gl_ps_strides(self):
19902008
self.reftest('gl_ps_strides.c', 'gl_ps_strides.png', args=['--preload-file', 'screenshot.png', '-sLEGACY_GL_EMULATION', '-lGL', '-lSDL', '--use-preload-plugins'])
19912009

19922010
@requires_graphics_hardware
2011+
@also_with_proxying
19932012
def test_gl_ps_worker(self):
19942013
shutil.copyfile(test_file('screenshot.png'), 'screenshot.png')
1995-
self.reftest('gl_ps_worker.c', 'gl_ps.png', args=['--preload-file', 'screenshot.png', '-sLEGACY_GL_EMULATION', '-lGL', '-lSDL', '--use-preload-plugins'], reference_slack=1, also_proxied=True)
2014+
self.reftest('gl_ps_worker.c', 'gl_ps.png', args=['--preload-file', 'screenshot.png', '-sLEGACY_GL_EMULATION', '-lGL', '-lSDL', '--use-preload-plugins'], reference_slack=1)
19962015

19972016
@requires_graphics_hardware
19982017
def test_gl_renderers(self):
@@ -2013,8 +2032,9 @@ def test_gl_vertex_buffer(self):
20132032
self.reftest('gl_vertex_buffer.c', 'gl_vertex_buffer.png', args=['-sGL_UNSAFE_OPTS=0', '-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'], reference_slack=1)
20142033

20152034
@requires_graphics_hardware
2035+
@also_with_proxying
20162036
def test_gles2_uniform_arrays(self):
2017-
self.btest('gles2_uniform_arrays.cpp', args=['-sGL_ASSERTIONS', '-lGL', '-lSDL'], expected='1', also_proxied=True)
2037+
self.btest('gles2_uniform_arrays.cpp', args=['-sGL_ASSERTIONS', '-lGL', '-lSDL'], expected='1')
20182038

20192039
@requires_graphics_hardware
20202040
def test_gles2_conformance(self):
@@ -2056,19 +2076,23 @@ def test_cubegeom_pre3(self):
20562076
'': ([],),
20572077
'tracing': (['-sTRACE_WEBGL_CALLS'],),
20582078
})
2079+
@also_with_proxying
20592080
@requires_graphics_hardware
20602081
def test_cubegeom(self, args):
2061-
# proxy only in the simple, normal case (we can't trace GL calls when
2062-
# proxied)
2063-
self.reftest('third_party/cubegeom/cubegeom.c', 'third_party/cubegeom/cubegeom.png', args=['-O2', '-g', '-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'] + args, also_proxied=not args)
2082+
if self.proxied and args:
2083+
# proxy only in the simple, normal case (we can't trace GL calls when proxied)
2084+
self.skipTest('tracing + proxying not supported')
2085+
self.reftest('third_party/cubegeom/cubegeom.c', 'third_party/cubegeom/cubegeom.png', args=['-O2', '-g', '-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'] + args)
20642086

20652087
@requires_graphics_hardware
2088+
@also_with_proxying
20662089
def test_cubegeom_regal(self):
2067-
self.reftest('third_party/cubegeom/cubegeom.c', 'third_party/cubegeom/cubegeom.png', args=['-O2', '-g', '-DUSE_REGAL', '-sUSE_REGAL', '-lGL', '-lSDL', '-lc++', '-lc++abi'], also_proxied=True)
2090+
self.reftest('third_party/cubegeom/cubegeom.c', 'third_party/cubegeom/cubegeom.png', args=['-O2', '-g', '-DUSE_REGAL', '-sUSE_REGAL', '-lGL', '-lSDL', '-lc++', '-lc++abi'])
20682091

20692092
@requires_graphics_hardware
2093+
@also_with_proxying
20702094
def test_cubegeom_regal_mt(self):
2071-
self.reftest('third_party/cubegeom/cubegeom.c', 'third_party/cubegeom/cubegeom.png', args=['-O2', '-g', '-pthread', '-DUSE_REGAL', '-pthread', '-sUSE_REGAL', '-lGL', '-lSDL', '-lc++', '-lc++abi'], also_proxied=False)
2095+
self.reftest('third_party/cubegeom/cubegeom.c', 'third_party/cubegeom/cubegeom.png', args=['-O2', '-g', '-pthread', '-DUSE_REGAL', '-pthread', '-sUSE_REGAL', '-lGL', '-lSDL', '-lc++', '-lc++abi'])
20722096

20732097
@requires_graphics_hardware
20742098
@parameterized({
@@ -2102,12 +2126,14 @@ def test_cubegeom_color(self):
21022126
self.reftest('third_party/cubegeom/cubegeom_color.c', 'third_party/cubegeom/cubegeom_color.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'])
21032127

21042128
@requires_graphics_hardware
2129+
@also_with_proxying
21052130
def test_cubegeom_normal(self):
2106-
self.reftest('third_party/cubegeom/cubegeom_normal.c', 'third_party/cubegeom/cubegeom_normal.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'], also_proxied=True)
2131+
self.reftest('third_party/cubegeom/cubegeom_normal.c', 'third_party/cubegeom/cubegeom_normal.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'])
21072132

21082133
@requires_graphics_hardware
2134+
@also_with_proxying
21092135
def test_cubegeom_normal_dap(self): # draw is given a direct pointer to clientside memory, no element array buffer
2110-
self.reftest('third_party/cubegeom/cubegeom_normal_dap.c', 'third_party/cubegeom/cubegeom_normal.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'], also_proxied=True)
2136+
self.reftest('third_party/cubegeom/cubegeom_normal_dap.c', 'third_party/cubegeom/cubegeom_normal.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'])
21112137

21122138
@requires_graphics_hardware
21132139
def test_cubegeom_normal_dap_far(self): # indices do nto start from 0
@@ -2131,8 +2157,9 @@ def test_cubegeom_mt(self):
21312157
self.reftest('third_party/cubegeom/cubegeom_mt.c', 'third_party/cubegeom/cubegeom_mt.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL']) # multitexture
21322158

21332159
@requires_graphics_hardware
2160+
@also_with_proxying
21342161
def test_cubegeom_color2(self):
2135-
self.reftest('third_party/cubegeom/cubegeom_color2.c', 'third_party/cubegeom/cubegeom_color2.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'], also_proxied=True)
2162+
self.reftest('third_party/cubegeom/cubegeom_color2.c', 'third_party/cubegeom/cubegeom_color2.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'])
21362163

21372164
@requires_graphics_hardware
21382165
def test_cubegeom_texturematrix(self):
@@ -2171,8 +2198,9 @@ def test_cubegeom_u4fv_2(self):
21712198
self.reftest('third_party/cubegeom/cubegeom_u4fv_2.c', 'third_party/cubegeom/cubegeom_u4fv_2.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'])
21722199

21732200
@requires_graphics_hardware
2201+
@also_with_proxying
21742202
def test_cube_explosion(self):
2175-
self.reftest('cube_explosion.c', 'cube_explosion.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'], also_proxied=True)
2203+
self.reftest('cube_explosion.c', 'cube_explosion.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'])
21762204

21772205
@requires_graphics_hardware
21782206
def test_glgettexenv(self):
@@ -3069,13 +3097,12 @@ def test_sdl2_threads(self):
30693097
self.btest_exit('test_sdl2_threads.c', args=['-pthread', '-sUSE_SDL=2', '-sPROXY_TO_PTHREAD'])
30703098

30713099
@requires_graphics_hardware
3072-
@parameterized({
3073-
'': ([], True),
3074-
# fails on proxy
3075-
'closure': (['--closure=1', '-g1'], False),
3076-
})
3077-
def test_sdl2_glshader(self, args, also_proxied):
3078-
self.reftest('test_sdl2_glshader.c', 'test_sdl_glshader.png', args=args + ['-sUSE_SDL=2', '-O2', '-sLEGACY_GL_EMULATION'], also_proxied=also_proxied)
3100+
@also_with_proxying
3101+
def test_sdl2_glshader(self):
3102+
if not self.proxied:
3103+
# closure build current fails on proxying
3104+
self.emcc_args += ['--closure=1', '-g1']
3105+
self.reftest('test_sdl2_glshader.c', 'test_sdl_glshader.png', args=['-sUSE_SDL=2', '-O2', '-sLEGACY_GL_EMULATION'])
30793106

30803107
@requires_graphics_hardware
30813108
def test_sdl2_canvas_blank(self):
@@ -4781,8 +4808,9 @@ def test_load_js_from_blob_with_pthreads(self):
47814808
self.run_browser('hello_thread_with_blob_url.html', '/report_result?exit:0')
47824809

47834810
# Tests that SINGLE_FILE works as intended in generated HTML (with and without Worker)
4811+
@also_with_proxying
47844812
def test_single_file_html(self):
4785-
self.btest('single_file_static_initializer.cpp', '19', args=['-sSINGLE_FILE'], also_proxied=True)
4813+
self.btest('single_file_static_initializer.cpp', '19', args=['-sSINGLE_FILE'])
47864814
self.assertExists('test.html')
47874815
self.assertNotExists('test.js')
47884816
self.assertNotExists('test.worker.js')
@@ -4946,8 +4974,9 @@ def test_emscripten_request_animation_frame(self):
49464974
def test_emscripten_request_animation_frame_loop(self):
49474975
self.btest_exit('emscripten_request_animation_frame_loop.c')
49484976

4977+
@also_with_proxying
49494978
def test_request_animation_frame(self):
4950-
self.btest_exit('request_animation_frame.cpp', also_proxied=True)
4979+
self.btest_exit('request_animation_frame.cpp')
49514980

49524981
def test_emscripten_set_timeout(self):
49534982
self.btest_exit('emscripten_set_timeout.c', args=['-pthread', '-sPROXY_TO_PTHREAD'])

0 commit comments

Comments
 (0)