Skip to content

Commit c5fb4e3

Browse files
committed
[test] Enable --rebaseline with browser reftests. NFC
These allows us to update the reference images quickly and easily directly from the commandline.
1 parent fb48649 commit c5fb4e3

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

test/browser/webgl_multi_draw.png

-1.8 KB
Loading

test/browser_reporting.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function reportResultToServer(result, port) {
2323
}
2424
}
2525

26+
function sendFileToServer(filename, contents) {
27+
fetch(`http://localhost:8888/?file=${filename}`, {method: "POST", body: contents});
28+
}
29+
2630
/**
2731
* @param {number=} port
2832
*/

test/common.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,15 +1942,15 @@ def end_headers(self):
19421942
def do_POST(self):
19431943
urlinfo = urlparse(self.path)
19441944
query = parse_qs(urlinfo.query)
1945-
# Mirror behaviour of emrun which is to write POST'd files to dump_out/ by default
19461945
if query['file']:
19471946
print('do_POST: got file: %s' % query['file'])
1948-
ensure_dir('dump_out')
1949-
filename = os.path.join('dump_out', query['file'][0])
1947+
filename = query['file'][0]
19501948
contentLength = int(self.headers['Content-Length'])
19511949
create_file(filename, self.rfile.read(contentLength), binary=True)
19521950
self.send_response(200)
19531951
self.end_headers()
1952+
else:
1953+
print(f'do_POST: unexpected POST: {urlinfo.query}')
19541954

19551955
def do_GET(self):
19561956
if self.path == '/run_harness':
@@ -2237,15 +2237,31 @@ def make_reftest(self, expected, manually_trigger=False):
22372237
total += Math.abs(expected[y*width*4 + x*4 + 2] - actual[y*width*4 + x*4 + 2]);
22382238
}
22392239
}
2240-
var wrong = Math.floor(total / (img.width*img.height*3)); // floor, to allow some margin of error for antialiasing
2241-
// If the main JS file is in a worker, or modularize, then we need to supply our own reporting logic.
2242-
if (typeof reportResultToServer === 'undefined') {
2243-
(() => {
2244-
%s
2245-
reportResultToServer(wrong);
2246-
})();
2240+
// floor, to allow some margin of error for antialiasing
2241+
var wrong = Math.floor(total / (img.width*img.height*3));
2242+
2243+
function reportResult(result) {
2244+
// If the main JS file is in a worker, or modularize, then we need to supply our own
2245+
// reporting logic.
2246+
if (typeof reportResultToServer === 'undefined') {
2247+
(() => {
2248+
%s
2249+
reportResultToServer(result);
2250+
})();
2251+
} else {
2252+
reportResultToServer(result);
2253+
}
2254+
}
2255+
2256+
if (wrong || %s) {
2257+
// Generate a png of the actual rendered image and send it back
2258+
// to the server.
2259+
Module.canvas.toBlob((blob) => {
2260+
sendFileToServer('actual.png', blob);
2261+
reportResult(wrong);
2262+
})
22472263
} else {
2248-
reportResultToServer(wrong);
2264+
reportResult(wrong);
22492265
}
22502266
};
22512267
actualImage.src = actualUrl;
@@ -2293,7 +2309,7 @@ def make_reftest(self, expected, manually_trigger=False):
22932309
}
22942310
22952311
setupRefTest();
2296-
''' % (reporting, int(manually_trigger)))
2312+
''' % (reporting, EMTEST_REBASELINE, int(manually_trigger)))
22972313

22982314
def compile_btest(self, filename, args, reporting=Reporting.FULL):
22992315
# Inject support code for reporting results. This adds an include a header so testcases can
@@ -2334,7 +2350,13 @@ def reftest(self, filename, reference, reference_slack=0, manual_reference=False
23342350
kwargs.setdefault('args', [])
23352351
kwargs['args'] += ['--pre-js', 'reftest.js', '-sGL_TESTING']
23362352

2337-
return self.btest(filename, expected=expected, *args, **kwargs)
2353+
try:
2354+
return self.btest(filename, expected=expected, *args, **kwargs)
2355+
finally:
2356+
if EMTEST_REBASELINE:
2357+
if os.path.exists('actual.png'):
2358+
print(f'overwriting expected image: {reference}')
2359+
self.run_process('pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB actual.png'.split() + [reference])
23382360

23392361
def btest_exit(self, filename, assert_returncode=0, *args, **kwargs):
23402362
"""Special case of `btest` that reports its result solely via exiting

0 commit comments

Comments
 (0)