|
20 | 20 | from pathlib import Path |
21 | 21 | from urllib.request import urlopen |
22 | 22 |
|
| 23 | +import common |
23 | 24 | from common import BrowserCore, RunnerCore, path_from_root, has_browser, EMTEST_BROWSER, Reporting |
24 | 25 | from common import create_file, parameterized, ensure_dir, disabled, test_file, WEBIDL_BINDER |
25 | 26 | 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, parameterize |
| 27 | +from common import requires_wasm2js, also_with_wasm2js, parameterize, find_browser_test_file |
27 | 28 | from tools import shared |
28 | 29 | from tools import ports |
29 | 30 | from tools import utils |
@@ -247,6 +248,57 @@ def require_jspi(self): |
247 | 248 | self.skipTest(f'Current browser ({EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.') |
248 | 249 | super(browser, self).require_jspi() |
249 | 250 |
|
| 251 | + def post_manual_reftest(self): |
| 252 | + assert os.path.exists('reftest.js') |
| 253 | + shutil.copy(test_file('browser_reporting.js'), '.') |
| 254 | + html = read_file('test.html') |
| 255 | + html = html.replace('</body>', ''' |
| 256 | +<script src="browser_reporting.js"></script> |
| 257 | +<script src="reftest.js"></script> |
| 258 | +<script> |
| 259 | +var windowClose = window.close; |
| 260 | +window.close = () => { |
| 261 | + // wait for rafs to arrive and the screen to update before reftesting |
| 262 | + setTimeout(() => { |
| 263 | + doReftest(); |
| 264 | + setTimeout(windowClose, 5000); |
| 265 | + }, 1000); |
| 266 | +}; |
| 267 | +</script> |
| 268 | +</body>''') |
| 269 | + create_file('test.html', html) |
| 270 | + |
| 271 | + def make_reftest(self, expected): |
| 272 | + # make sure the pngs used here have no color correction, using e.g. |
| 273 | + # pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB infile outfile |
| 274 | + shutil.copy(expected, 'expected.png') |
| 275 | + create_file('reftest.js', f''' |
| 276 | + const reftestRebaseline = {common.EMTEST_REBASELINE}; |
| 277 | + ''' + read_file(test_file('reftest.js'))) |
| 278 | + |
| 279 | + def reftest(self, filename, reference, reference_slack=0, *args, **kwargs): |
| 280 | + """Special case of `btest` that uses reference image |
| 281 | + """ |
| 282 | + reference = find_browser_test_file(reference) |
| 283 | + assert 'expected' not in kwargs |
| 284 | + expected = [str(i) for i in range(0, reference_slack + 1)] |
| 285 | + self.make_reftest(reference) |
| 286 | + if self.proxied: |
| 287 | + assert 'post_build' not in kwargs |
| 288 | + kwargs['post_build'] = self.post_manual_reftest |
| 289 | + create_file('fakereftest.js', 'var reftestUnblock = () => {}; var reftestBlock = () => {};') |
| 290 | + kwargs['args'] += ['--pre-js', 'fakereftest.js'] |
| 291 | + else: |
| 292 | + kwargs.setdefault('args', []) |
| 293 | + kwargs['args'] += ['--pre-js', 'reftest.js', '-sGL_TESTING'] |
| 294 | + |
| 295 | + try: |
| 296 | + return self.btest(filename, expected=expected, *args, **kwargs) |
| 297 | + finally: |
| 298 | + if common.EMTEST_REBASELINE and os.path.exists('actual.png'): |
| 299 | + print(f'overwriting expected image: {reference}') |
| 300 | + self.run_process('pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB actual.png'.split() + [reference]) |
| 301 | + |
250 | 302 | def test_sdl1_in_emscripten_nonstrict_mode(self): |
251 | 303 | if 'EMCC_STRICT' in os.environ and int(os.environ['EMCC_STRICT']): |
252 | 304 | 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): |
865 | 917 | def test_sdl_canvas(self, args): |
866 | 918 | self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args) |
867 | 919 |
|
868 | | - def post_manual_reftest(self): |
869 | | - assert os.path.exists('reftest.js') |
870 | | - shutil.copy(test_file('browser_reporting.js'), '.') |
871 | | - html = read_file('test.html') |
872 | | - html = html.replace('</body>', ''' |
873 | | -<script src="browser_reporting.js"></script> |
874 | | -<script src="reftest.js"></script> |
875 | | -<script> |
876 | | -var windowClose = window.close; |
877 | | -window.close = () => { |
878 | | - // wait for rafs to arrive and the screen to update before reftesting |
879 | | - setTimeout(() => { |
880 | | - doReftest(); |
881 | | - setTimeout(windowClose, 5000); |
882 | | - }, 1000); |
883 | | -}; |
884 | | -</script> |
885 | | -</body>''') |
886 | | - create_file('test.html', html) |
887 | | - |
888 | 920 | @proxied |
889 | 921 | def test_sdl_canvas_proxy(self): |
890 | 922 | create_file('data.txt', 'datum') |
|
0 commit comments