Skip to content

Commit

Permalink
[test] Add @also_with_proxying decorator. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed May 22, 2024
1 parent 4d22ffe commit 86801e0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 37 deletions.
25 changes: 11 additions & 14 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ 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.
Expand Down Expand Up @@ -2302,17 +2303,24 @@ def btest_exit(self, filename, assert_returncode=0, *args, **kwargs):

def btest(self, filename, expected=None, reference=None,
reference_slack=0, manual_reference=None, post_build=None,
args=None, also_proxied=False,
url_suffix='', timeout=None,
args=None, url_suffix='', timeout=None,
manually_trigger_reftest=False, extra_tries=1,
reporting=Reporting.FULL,
output_basename='test'):
assert expected or reference, 'a btest must either expect an output, or have a reference image'
if args is None:
args = []
original_args = 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:
if reference:
assert not manual_reference
manual_reference = True
assert not post_build
post_build = self.post_manual_reftest
args += ['--proxy-to-worker', '-sGL_TESTING']
if reference:
reference = find_browser_test_file(reference)
expected = [str(i) for i in range(0, reference_slack + 1)]
Expand Down Expand Up @@ -2340,17 +2348,6 @@ def btest(self, filename, expected=None, reference=None,
else:
self.run_browser(outfile + url_suffix, expected=['/report_result?' + e for e in expected], timeout=timeout, extra_tries=extra_tries)

if also_proxied:
print('proxied...')
if reference:
assert not manual_reference
manual_reference = True
assert not post_build
post_build = self.post_manual_reftest
# run proxied
self.btest(filename, expected, reference, reference_slack, manual_reference, post_build,
original_args + ['--proxy-to-worker', '-sGL_TESTING'], timeout=timeout)


###################################################################################################

Expand Down
75 changes: 52 additions & 23 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from common import BrowserCore, RunnerCore, path_from_root, has_browser, EMTEST_BROWSER, Reporting
from common import create_file, parameterized, ensure_dir, disabled, test_file, WEBIDL_BINDER
from common import read_file, also_with_minimal_runtime, EMRUN, no_wasm64, no_2gb, no_4gb
from common import requires_wasm2js, also_with_wasm2js
from common import requires_wasm2js, also_with_wasm2js, parameterize
from tools import shared
from tools import ports
from tools import utils
Expand Down Expand Up @@ -78,6 +78,9 @@ def do_GET(s):


def also_with_wasmfs(f):
assert callable(f)

@wraps(f)
def metafunc(self, wasmfs, *args, **kwargs):
if wasmfs:
self.set_setting('WASMFS')
Expand All @@ -92,6 +95,19 @@ def metafunc(self, wasmfs, *args, **kwargs):
return metafunc


def also_with_proxying(f):
assert callable(f)

@wraps(f)
def metafunc(self, proxied, *args, **kwargs):
self.proxied = proxied
f(self, *args, **kwargs)

parameterize(metafunc, {'': (False,),
'proxied': (True,)})
return metafunc


# This is similar to @core.no_wasmfs, but it disable WasmFS and runs the test
# normally. That is, in core we skip the test if we are in the wasmfs.* mode,
# while in browser we don't have such modes, so we force the test to run without
Expand Down Expand Up @@ -761,10 +777,11 @@ def test_sdl_image_jpeg(self):
])

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

@parameterized({
'': ([],),
Expand Down Expand Up @@ -1957,8 +1974,9 @@ def test_sdl_glshader(self):

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

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

@requires_graphics_hardware
@also_with_proxying
def test_gl_ps_worker(self):
shutil.copyfile(test_file('screenshot.png'), 'screenshot.png')
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)
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)

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

@requires_graphics_hardware
@also_with_proxying
def test_gles2_uniform_arrays(self):
self.btest('gles2_uniform_arrays.cpp', args=['-sGL_ASSERTIONS', '-lGL', '-lSDL'], expected='1', also_proxied=True)
self.btest('gles2_uniform_arrays.cpp', args=['-sGL_ASSERTIONS', '-lGL', '-lSDL'], expected='1')

@requires_graphics_hardware
def test_gles2_conformance(self):
Expand Down Expand Up @@ -2056,19 +2076,23 @@ def test_cubegeom_pre3(self):
'': ([],),
'tracing': (['-sTRACE_WEBGL_CALLS'],),
})
@also_with_proxying
@requires_graphics_hardware
def test_cubegeom(self, args):
# proxy only in the simple, normal case (we can't trace GL calls when
# proxied)
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)
if self.proxied 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)

@requires_graphics_hardware
@also_with_proxying
def test_cubegeom_regal(self):
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)
self.reftest('third_party/cubegeom/cubegeom.c', 'third_party/cubegeom/cubegeom.png', args=['-O2', '-g', '-DUSE_REGAL', '-sUSE_REGAL', '-lGL', '-lSDL', '-lc++', '-lc++abi'])

@requires_graphics_hardware
@also_with_proxying
def test_cubegeom_regal_mt(self):
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)
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'])

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

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

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

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

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

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

@requires_graphics_hardware
@also_with_proxying
def test_cube_explosion(self):
self.reftest('cube_explosion.c', 'cube_explosion.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'], also_proxied=True)
self.reftest('cube_explosion.c', 'cube_explosion.png', args=['-sLEGACY_GL_EMULATION', '-lGL', '-lSDL'])

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

@requires_graphics_hardware
@parameterized({
'': ([], True),
# fails on proxy
'closure': (['--closure=1', '-g1'], False),
})
def test_sdl2_glshader(self, args, also_proxied):
self.reftest('test_sdl2_glshader.c', 'test_sdl_glshader.png', args=args + ['-sUSE_SDL=2', '-O2', '-sLEGACY_GL_EMULATION'], also_proxied=also_proxied)
@also_with_proxying
def test_sdl2_glshader(self):
if not self.proxied:
# 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', '-O2', '-sLEGACY_GL_EMULATION'])

@requires_graphics_hardware
def test_sdl2_canvas_blank(self):
Expand Down Expand Up @@ -4781,8 +4808,9 @@ def test_load_js_from_blob_with_pthreads(self):
self.run_browser('hello_thread_with_blob_url.html', '/report_result?exit:0')

# Tests that SINGLE_FILE works as intended in generated HTML (with and without Worker)
@also_with_proxying
def test_single_file_html(self):
self.btest('single_file_static_initializer.cpp', '19', args=['-sSINGLE_FILE'], also_proxied=True)
self.btest('single_file_static_initializer.cpp', '19', args=['-sSINGLE_FILE'])
self.assertExists('test.html')
self.assertNotExists('test.js')
self.assertNotExists('test.worker.js')
Expand Down Expand Up @@ -4946,8 +4974,9 @@ def test_emscripten_request_animation_frame(self):
def test_emscripten_request_animation_frame_loop(self):
self.btest_exit('emscripten_request_animation_frame_loop.c')

@also_with_proxying
def test_request_animation_frame(self):
self.btest_exit('request_animation_frame.cpp', also_proxied=True)
self.btest_exit('request_animation_frame.cpp')

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

0 comments on commit 86801e0

Please sign in to comment.