8000 [test] Enable --rebaseline with browser reftests. NFC (#22600) · emscripten-core/emscripten@8eb432e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8eb432e

Browse files
authored
[test] Enable --rebaseline with browser reftests. NFC (#22600)
These allows us to update the reference images quickly and easily directly from the commandline. To test that it works I ran `./test/runner browser.test_webgl_multi_draw_arrays --rebaseline` and checked in the resulting change.
1 parent df22009 commit 8eb432e

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
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: 37 additions & 14 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,32 @@ 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+
var rebaseline = %s;
2257+
if (wrong || rebaseline) {
2258+
// Generate a png of the actual rendered image and send it back
2259+
// to the server.
2260+
Module.canvas.toBlob((blob) => {
2261+
sendFileToServer('actual.png', blob);
2262+
reportResult(wrong);
2263+
})
22472264
} else {
2248-
reportResultToServer(wrong);
2265+
reportResult(wrong);
22492266
}
22502267
};
22512268
actualImage.src = actualUrl;
@@ -2256,7 +2273,8 @@ def make_reftest(self, expected, manually_trigger=False):
22562273
/** @suppress {uselessCode} */
22572274
function setupRefTest() {
22582275
// Automatically trigger the reftest?
2259-
if (!%s) {
2276+
var manuallyTrigger = %s;
2277+
if (!manuallyTrigger) {
22602278
// Yes, automatically
22612279
22622280
Module['postRun'] = doReftest;
@@ -2293,7 +2311,7 @@ def make_reftest(self, expected, manually_trigger=False):
22932311
}
22942312
22952313
setupRefTest();
2296-
''' % (reporting, int(manually_trigger)))
2314+
''' % (reporting, EMTEST_REBASELINE, int(manually_trigger)))
22972315

22982316
def compile_btest(self, filename, args, reporting=Reporting.FULL):
22992317
# Inject support code for reporting results. This adds an include a header so testcases can
@@ -2334,7 +2352,12 @@ def reftest(self, filename, reference, reference_slack=0, manual_reference=False
23342352
kwargs.setdefault('args', [])
23352353
kwargs['args'] += ['--pre-js', 'reftest.js', '-sGL_TESTING']
23362354

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

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

test/fetch/test_fetch_post.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void doGet() {
3535
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
3636
attr.onsuccess = onGetSuccess;
3737
attr.onerror = onError;
38-
emscripten_fetch(&attr, "dump_out/newfile.txt");
38+
emscripten_fetch(&attr, "newfile.txt");
3939
}
4040

4141
void onPostSuccess(emscripten_fetch_t *fetch) {

0 commit comments

Comments
 (0)
0