Skip to content

Commit

Permalink
[test] Cleanup make_reftest part 2. NFC
Browse files Browse the repository at this point in the history
Avoid including/inlining browser_reporting.js in the middle of
reftest.js.
  • Loading branch information
sbc100 committed Oct 2, 2024
1 parent 649e86a commit c99347f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
34 changes: 10 additions & 24 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,6 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr
def make_reftest(self, expected):
# make sure the pngs used here have no color correction, using e.g.
# pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB infile outfile
reporting = read_file(test_file('browser_reporting.js'))
shutil.copy(expected, 'expected.png')
create_file('reftest.js', '''
function doReftest() {
Expand Down Expand Up @@ -2256,30 +2255,16 @@ def make_reftest(self, expected):
}
// floor, to allow some margin of error for antialiasing
var wrong = Math.floor(total / (img.width*img.height*3));
function reportResult(result) {
// If the main JS file is in a worker, or modularize, then we need to supply our own
// reporting logic.
if (typeof reportResultToServer === 'undefined') {
(() => {
%s
reportResultToServer(result);
})();
} else {
reportResultToServer(result);
}
}
var rebaseline = %s;
if (wrong || rebaseline) {
// Generate a png of the actual rendered image and send it back
// to the server.
Module.canvas.toBlob((blob) => {
sendFileToServer('actual.png', blob);
reportResult(wrong);
reportResultToServer(wrong);
})
} else {
reportResult(wrong);
reportResultToServer(wrong);
}
};
actualImage.src = actualUrl;
Expand Down Expand Up @@ -2314,7 +2299,7 @@ def make_reftest(self, expected):
}
setupRefTest();
''' % (reporting, EMTEST_REBASELINE))
''' % EMTEST_REBASELINE)

def compile_btest(self, filename, args, reporting=Reporting.FULL):
# Inject support code for reporting results. This adds an include a header so testcases can
Expand All @@ -2340,16 +2325,17 @@ def compile_btest(self, filename, args, reporting=Reporting.FULL):
def reftest(self, filename, reference, reference_slack=0, *args, **kwargs):
"""Special case of `btest` that uses reference image
"""
if self.proxied:
assert 'post_build' not in kwargs
kwargs['post_build'] = self.post_manual_reftest

reference = find_browser_test_file(reference)
assert 'expected' not in kwargs
expected = [str(i) for i in range(0, reference_slack + 1)]
self.make_reftest(reference)
kwargs.setdefault('args', [])
kwargs['args'] += ['--pre-js', 'reftest.js', '-sGL_TESTING']
if self.proxied:
print("XXXX")
assert 'post_build' not in kwargs
kwargs['post_build'] = self.post_manual_reftest
else:
kwargs.setdefault('args', [])
kwargs['args'] += ['--pre-js', 'reftest.js', '-sGL_TESTING']

try:
return self.btest(filename, expected=expected, *args, **kwargs)
Expand Down
26 changes: 21 additions & 5 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ def metafunc(self, proxied, *args, **kwargs):
return metafunc


def proxied(f):
assert callable(f)

@wraps(f)
def decorated(self, *args, **kwargs):
self.proxied = True
return f(self, *args, **kwargs)

return decorated


# 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 @@ -856,9 +867,11 @@ def test_sdl_canvas(self, args):

def post_manual_reftest(self):
assert os.path.exists('reftest.js')
shutil.copy(test_file('browser_reporting.js'), '.')
html = read_file('test.html')
html = html.replace('</body>', '''
<script src="reftest.js"/>
<script src="browser_reporting.js"></script>
<script src="reftest.js"></script>
<script>
var windowClose = window.close;
window.close = () => {
Expand All @@ -872,9 +885,10 @@ def post_manual_reftest(self):
</body>''')
create_file('test.html', html)

@proxied
def test_sdl_canvas_proxy(self):
create_file('data.txt', 'datum')
self.reftest('test_sdl_canvas_proxy.c', 'test_sdl_canvas_proxy.png', args=['--proxy-to-worker', '--preload-file', 'data.txt', '-lSDL', '-lGL'], post_build=self.post_manual_reftest)
self.reftest('test_sdl_canvas_proxy.c', 'test_sdl_canvas_proxy.png', args=['--proxy-to-worker', '--preload-file', 'data.txt', '-lSDL', '-lGL'])

@requires_graphics_hardware
def test_glgears_proxy_jstarget(self):
Expand Down Expand Up @@ -2934,7 +2948,7 @@ 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'])
self.reftest('test_sdl2_glshader.c', 'test_sdl_glshader.png', args=['-sUSE_SDL=2', '-sLEGACY_GL_EMULATION'])

@requires_graphics_hardware
def test_sdl2_canvas_blank(self):
Expand Down Expand Up @@ -2986,9 +3000,10 @@ def test_sdl2_image_prepare_data(self):
self.reftest('test_sdl2_image_prepare_data.c', 'screenshot.jpg', args=['--preload-file', 'screenshot.not', '-sUSE_SDL=2', '-sUSE_SDL_IMAGE=2'])

@requires_graphics_hardware
@proxied
def test_sdl2_canvas_proxy(self):
create_file('data.txt', 'datum')
self.reftest('test_sdl2_canvas_proxy.c', 'test_sdl2_canvas.png', args=['-sUSE_SDL=2', '--proxy-to-worker', '--preload-file', 'data.txt'], post_build=self.post_manual_reftest)
self.reftest('test_sdl2_canvas_proxy.c', 'test_sdl2_canvas.png', args=['-sUSE_SDL=2', '--proxy-to-worker', '--preload-file', 'data.txt'])

def test_sdl2_pumpevents(self):
# key events should be detected using SDL_PumpEvents
Expand Down Expand Up @@ -3066,8 +3081,9 @@ def test_sdl2_canvas_write(self):
self.btest_exit('test_sdl2_canvas_write.c', args=['-sUSE_SDL=2'])

@requires_graphics_hardware
@proxied
def test_sdl2_gl_frames_swap(self):
self.reftest('test_sdl2_gl_frames_swap.c', 'test_sdl2_gl_frames_swap.png', args=['--proxy-to-worker', '-sUSE_SDL=2'], post_build=self.post_manual_reftest)
self.reftest('test_sdl2_gl_frames_swap.c', 'test_sdl2_gl_frames_swap.png', args=['--proxy-to-worker', '-sUSE_SDL=2'])

@requires_graphics_hardware
def test_sdl2_ttf(self):
Expand Down

0 comments on commit c99347f

Please sign in to comment.