Skip to content

Improve browser reftest reporting. NFC #24147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/reftest.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ function doReftest() {
}
}
// floor, to allow some margin of error for antialiasing
var wrong = Math.floor(total / (img.width*img.height*3));
var delta = Math.floor(total / (img.width*img.height*3));
console.log(`image delta = ${delta}`);
var wrong = delta > reftestSlack;
if (wrong || reftestRebaseline) {
// Generate a png of the actual rendered image and send it back
// to the server.
Module['canvas'].toBlob((blob) => {
sendFileToServer('actual.png', blob);
reportResultToServer(wrong);
reportResultToServer(wrong ? `mismatch:${delta}` : 'match');
})
} else {
reportResultToServer(wrong);
reportResultToServer('match');
}
};
actualImage.src = actualUrl;
Expand Down
8 changes: 4 additions & 4 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,12 @@ def post_manual_reftest(self):
</body>''')
create_file('test.html', html)

def make_reftest(self, expected):
def make_reftest(self, expected, reference_slack=0):
# 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 reftestSlack = {reference_slack};
const reftestRebaseline = {common.EMTEST_REBASELINE};
''' + read_file(test_file('reftest.js')))

Expand All @@ -277,8 +278,7 @@ def reftest(self, filename, reference, reference_slack=0, *args, **kwargs):
"""
reference = find_browser_test_file(reference)
assert 'expected' not in kwargs
expected = [str(i) for i in range(reference_slack + 1)]
self.make_reftest(reference)
self.make_reftest(reference, reference_slack)
if '--proxy-to-worker' in self.emcc_args:
assert 'post_build' not in kwargs
kwargs['post_build'] = self.post_manual_reftest
Expand All @@ -289,7 +289,7 @@ def reftest(self, filename, reference, reference_slack=0, *args, **kwargs):
kwargs['emcc_args'] += ['--pre-js', 'reftest.js', '-sGL_TESTING']

try:
return self.btest(filename, expected=expected, *args, **kwargs)
return self.btest(filename, expected='match', *args, **kwargs)
finally:
if common.EMTEST_REBASELINE and os.path.exists('actual.png'):
print(f'overwriting expected image: {reference}')
Expand Down