Skip to content

Commit 104f746

Browse files
authored
Move reftest code to test_browser.py. NFC (#22675)
Hopefully the last in my long chain of recent reftest changes.
1 parent 2d4436b commit 104f746

File tree

2 files changed

+53
-52
lines changed

2 files changed

+53
-52
lines changed

test/common.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,14 +2204,6 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr
22042204
time.sleep(5)
22052205
print('(moving on..)')
22062206

2207-
def make_reftest(self, expected):
2208-
# make sure the pngs used here have no color correction, using e.g.
2209-
# pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB infile outfile
2210-
shutil.copy(expected, 'expected.png')
2211-
create_file('reftest.js', f'''
2212-
const reftestRebaseline = {EMTEST_REBASELINE};
2213-
''' + read_file(test_file('reftest.js')))
2214-
22152207
def compile_btest(self, filename, args, reporting=Reporting.FULL):
22162208
# Inject support code for reporting results. This adds an include a header so testcases can
22172209
# 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):
22332225
filename = test_file(filename)
22342226
self.run_process([compiler_for(filename), filename] + self.get_emcc_args() + args)
22352227

2236-
def reftest(self, filename, reference, reference_slack=0, *args, **kwargs):
2237-
"""Special case of `btest` that uses reference image
2238-
"""
2239-
reference = find_browser_test_file(reference)
2240-
assert 'expected' not in kwargs
2241-
expected = [str(i) for i in range(0, reference_slack + 1)]
2242-
self.make_reftest(reference)
2243-
if self.proxied:
2244-
assert 'post_build' not in kwargs
2245-
kwargs['post_build'] = self.post_manual_reftest
2246-
create_file('fakereftest.js', 'var reftestUnblock = () => {}; var reftestBlock = () => {};')
2247-
kwargs['args'] += ['--pre-js', 'fakereftest.js']
2248-
else:
2249-
kwargs.setdefault('args', [])
2250-
kwargs['args'] += ['--pre-js', 'reftest.js', '-sGL_TESTING']
2251-
2252-
try:
2253-
return self.btest(filename, expected=expected, *args, **kwargs)
2254-
finally:
2255-
if EMTEST_REBASELINE and os.path.exists('actual.png'):
2256-
print(f'overwriting expected image: {reference}')
2257-
self.run_process('pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB actual.png'.split() + [reference])
2258-
22592228
def btest_exit(self, filename, assert_returncode=0, *args, **kwargs):
22602229
"""Special case of `btest` that reports its result solely via exiting
22612230
with a given result code.

test/test_browser.py

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
from pathlib import Path
2121
from urllib.request import urlopen
2222

23+
import common
2324
from common import BrowserCore, RunnerCore, path_from_root, has_browser, EMTEST_BROWSER, Reporting
2425
from common import create_file, parameterized, ensure_dir, disabled, test_file, WEBIDL_BINDER
2526
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
2728
from tools import shared
2829
from tools import ports
2930
from tools import utils
@@ -247,6 +248,57 @@ def require_jspi(self):
247248
self.skipTest(f'Current browser ({EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.')
248249
super(browser, self).require_jspi()
249250

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+
250302
def test_sdl1_in_emscripten_nonstrict_mode(self):
251303
if 'EMCC_STRICT' in os.environ and int(os.environ['EMCC_STRICT']):
252304
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):
865917
def test_sdl_canvas(self, args):
866918
self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args)
867919

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-
888920
@proxied
889921
def test_sdl_canvas_proxy(self):
890922
create_file('data.txt', 'datum')

0 commit comments

Comments
 (0)