diff --git a/test/common.py b/test/common.py index 296d2ff1b9fec..918c3953e21f2 100644 --- a/test/common.py +++ b/test/common.py @@ -2204,14 +2204,6 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr time.sleep(5) print('(moving on..)') - 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 - shutil.copy(expected, 'expected.png') - create_file('reftest.js', f''' - const reftestRebaseline = {EMTEST_REBASELINE}; - ''' + read_file(test_file('reftest.js'))) - def compile_btest(self, filename, args, reporting=Reporting.FULL): # Inject support code for reporting results. This adds an include a header so testcases can # use REPORT_RESULT, and also adds a cpp file to be compiled alongside the testcase, which @@ -2233,29 +2225,6 @@ def compile_btest(self, filename, args, reporting=Reporting.FULL): filename = test_file(filename) self.run_process([compiler_for(filename), filename] + self.get_emcc_args() + args) - def reftest(self, filename, reference, reference_slack=0, *args, **kwargs): - """Special case of `btest` that uses reference image - """ - 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) - if self.proxied: - assert 'post_build' not in kwargs - kwargs['post_build'] = self.post_manual_reftest - create_file('fakereftest.js', 'var reftestUnblock = () => {}; var reftestBlock = () => {};') - kwargs['args'] += ['--pre-js', 'fakereftest.js'] - else: - kwargs.setdefault('args', []) - kwargs['args'] += ['--pre-js', 'reftest.js', '-sGL_TESTING'] - - try: - return self.btest(filename, expected=expected, *args, **kwargs) - finally: - if EMTEST_REBASELINE and os.path.exists('actual.png'): - print(f'overwriting expected image: {reference}') - self.run_process('pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB actual.png'.split() + [reference]) - def btest_exit(self, filename, assert_returncode=0, *args, **kwargs): """Special case of `btest` that reports its result solely via exiting with a given result code. diff --git a/test/test_browser.py b/test/test_browser.py index 6ea79fed05343..40ef18ef085dd 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -20,10 +20,11 @@ from pathlib import Path from urllib.request import urlopen +import common 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, parameterize +from common import requires_wasm2js, also_with_wasm2js, parameterize, find_browser_test_file from tools import shared from tools import ports from tools import utils @@ -247,6 +248,57 @@ def require_jspi(self): self.skipTest(f'Current browser ({EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.') super(browser, self).require_jspi() + 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('', ''' + + + +''') + create_file('test.html', html) + + 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 + shutil.copy(expected, 'expected.png') + create_file('reftest.js', f''' + const reftestRebaseline = {common.EMTEST_REBASELINE}; + ''' + read_file(test_file('reftest.js'))) + + def reftest(self, filename, reference, reference_slack=0, *args, **kwargs): + """Special case of `btest` that uses reference image + """ + 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) + if self.proxied: + assert 'post_build' not in kwargs + kwargs['post_build'] = self.post_manual_reftest + create_file('fakereftest.js', 'var reftestUnblock = () => {}; var reftestBlock = () => {};') + kwargs['args'] += ['--pre-js', 'fakereftest.js'] + else: + kwargs.setdefault('args', []) + kwargs['args'] += ['--pre-js', 'reftest.js', '-sGL_TESTING'] + + try: + return self.btest(filename, expected=expected, *args, **kwargs) + finally: + if common.EMTEST_REBASELINE and os.path.exists('actual.png'): + print(f'overwriting expected image: {reference}') + self.run_process('pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB actual.png'.split() + [reference]) + def test_sdl1_in_emscripten_nonstrict_mode(self): if 'EMCC_STRICT' in os.environ and int(os.environ['EMCC_STRICT']): self.skipTest('This test requires being run in non-strict mode (EMCC_STRICT env. variable unset)') @@ -865,26 +917,6 @@ def test_sdl_stb_image_cleanup(self): def test_sdl_canvas(self, args): self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + 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('', ''' - - - -''') - create_file('test.html', html) - @proxied def test_sdl_canvas_proxy(self): create_file('data.txt', 'datum')