Skip to content

Commit

Permalink
[test] Add reftest helper method for browser tests. NFC
Browse files Browse the repository at this point in the history
This makes it easy distinguish reference tests from other btests.
  • Loading branch information
sbc100 committed Feb 22, 2024
1 parent 9e8f698 commit 4c49e1e
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 187 deletions.
32 changes: 23 additions & 9 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,17 @@ def force_delete_contents(dirname):
utils.delete_contents(dirname)


def find_browser_test_file(filename):
"""Looks for files in test/browser and then in test/
"""
if not os.path.exists(filename):
fullname = test_file('browser', filename)
if not os.path.exists(fullname):
fullname = test_file(filename)
filename = fullname
return filename


def parameterized(parameters):
"""
Mark a test as parameterized.
Expand Down Expand Up @@ -2010,7 +2021,7 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr

# @manually_trigger If set, we do not assume we should run the reftest when main() is done.
# Instead, call doReftest() in JS yourself at the right time.
def reftest(self, expected, manually_trigger=False):
def make_reftest(self, expected, manually_trigger=False):
# make sure the pngs used here have no color correction, using e.g.
# pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB infile outfile
basename = os.path.basename(expected)
Expand Down Expand Up @@ -2141,8 +2152,15 @@ 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, *args, **kwargs):
"""Special case of `btest` that uses reference image
"""
assert 'reference' not in kwargs
kwargs['reference'] = reference
return self.btest(filename, *args, **kwargs)

def btest_exit(self, filename, assert_returncode=0, *args, **kwargs):
"""Special case of btest that reports its result solely via exiting
"""Special case of `btest` that reports its result solely via exiting
with a given result code.
In this case we set EXIT_RUNTIME and we don't need to provide the
Expand All @@ -2167,15 +2185,11 @@ def btest(self, filename, expected=None, reference=None,
args = []
original_args = args
args = args.copy()
if not os.path.exists(filename):
fullname = test_file('browser', filename)
if not os.path.exists(fullname):
fullname = test_file(filename)
filename = fullname
filename = find_browser_test_file(filename)
if reference:
self.reference = reference
reference = find_browser_test_file(reference)
expected = [str(i) for i in range(0, reference_slack + 1)]
self.reftest(test_file(reference), manually_trigger=manually_trigger_reftest)
self.make_reftest(reference, manually_trigger=manually_trigger_reftest)
if not manual_reference:
args += ['--pre-js', 'reftest.js', '-sGL_TESTING']
else:
Expand Down
Loading

0 comments on commit 4c49e1e

Please sign in to comment.