Skip to content

Automatically report exit status in browser tests #12928

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

Merged
merged 1 commit into from
Dec 2, 2020
Merged
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
10 changes: 8 additions & 2 deletions tests/browser_reporting.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var hasModule = typeof Module === 'object' && Module;

/** @param {boolean=} sync
@param {number=} port */
function reportResultToServer(result, sync, port) {
Expand All @@ -7,9 +9,7 @@ function reportResultToServer(result, sync, port) {
reportErrorToServer("excessive reported results, sending " + result + ", test will fail");
}
reportResultToServer.reported = true;

var xhr = new XMLHttpRequest();
var hasModule = typeof Module === 'object' && Module;
if (hasModule && Module['pageThrewException']) result = 12345;
xhr.open('GET', 'http://localhost:' + port + '/report_result?' + result, !sync);
xhr.send();
Expand All @@ -36,3 +36,9 @@ if (typeof window === 'object' && window) {
xhr.send();
});
}

if (hasModule) {
Module['onExit'] = function(status) {
maybeReportResultToServer('exit:' + status);
}
}
20 changes: 12 additions & 8 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,22 +1484,26 @@ def reftest(self, expected, manually_trigger=False):
}
''' % (reporting.read(), basename, int(manually_trigger)))

def compile_btest(self, args):
def compile_btest(self, args, reporting=True):
# add in support for reporting results. this adds an include a header so testcases can
# use REPORT_RESULT, and also adds a cpp file to be compiled alongside the testcase, which
# contains the implementation of REPORT_RESULT (we can't just include that implementation in
# the header as there may be multiple files being compiled here).
args += ['-s', 'IN_TEST_HARNESS=1', '-DEMTEST_PORT_NUMBER=%d' % self.port,
'-I', path_from_root('tests'),
'-include', path_from_root('tests', 'report_result.h'),
path_from_root('tests', 'report_result.cpp')]
self.run_process([EMCC] + args + ['--pre-js', path_from_root('tests', 'browser_reporting.js')])
args += ['-s', 'IN_TEST_HARNESS=1']
if reporting:
args += ['-DEMTEST_PORT_NUMBER=%d' % self.port,
'-I', path_from_root('tests'),
'-include', path_from_root('tests', 'report_result.h'),
path_from_root('tests', 'report_result.cpp'),
'--pre-js', path_from_root('tests', 'browser_reporting.js')]
self.run_process([EMCC] + args)

def btest(self, filename, expected=None, reference=None, force_c=False,
reference_slack=0, manual_reference=False, post_build=None,
args=None, message='.', also_proxied=False,
url_suffix='', timeout=None, also_asmjs=False,
manually_trigger_reftest=False, extra_tries=1):
manually_trigger_reftest=False, extra_tries=1,
reporting=True):
assert expected or reference, 'a btest must either expect an output, or have a reference image'
if args is None:
args = []
Expand All @@ -1523,7 +1527,7 @@ def btest(self, filename, expected=None, reference=None, force_c=False,
args = [filepath, '-o', outfile] + args
# print('all args:', args)
try_delete(outfile)
self.compile_btest(args)
self.compile_btest(args, reporting)
self.assertExists(outfile)
if post_build:
post_build()
Expand Down
13 changes: 7 additions & 6 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2400,15 +2400,17 @@ def test_runtime_misuse(self):
]:
for mode in [[], ['-s', 'WASM=0']]:
print('\n', filename, extra_args, mode)

print('mem init, so async, call too early')
create_test_file('post.js', post_prep + post_test + post_hook)
self.btest(filename, expected='600', args=['--post-js', 'post.js', '--memory-init-file', '1', '-s', 'EXIT_RUNTIME=1'] + extra_args + mode)
self.btest(filename, expected='600', args=['--post-js', 'post.js', '--memory-init-file', '1', '-s', 'EXIT_RUNTIME=1'] + extra_args + mode, reporting=False)
print('sync startup, call too late')
create_test_file('post.js', post_prep + 'Module.postRun.push(function() { ' + post_test + ' });' + post_hook)
self.btest(filename, expected=str(second_code), args=['--post-js', 'post.js', '-s', 'EXIT_RUNTIME=1'] + extra_args + mode)
self.btest(filename, expected=str(second_code), args=['--post-js', 'post.js', '-s', 'EXIT_RUNTIME=1'] + extra_args + mode, reporting=False)

print('sync, runtime still alive, so all good')
create_test_file('post.js', post_prep + 'expected_ok = true; Module.postRun.push(function() { ' + post_test + ' });' + post_hook)
self.btest(filename, expected='606', args=['--post-js', 'post.js'] + extra_args + mode)
self.btest(filename, expected='606', args=['--post-js', 'post.js'] + extra_args + mode, reporting=False)

def test_cwrap_early(self):
self.btest(os.path.join('browser', 'cwrap_early.cpp'), args=['-O2', '-s', 'ASSERTIONS=1', '--pre-js', path_from_root('tests', 'browser', 'cwrap_early.js'), '-s', 'EXTRA_EXPORTED_RUNTIME_METHODS=["cwrap"]'], expected='0')
Expand Down Expand Up @@ -4539,14 +4541,13 @@ def test_base64_atob_fallback(self):
#include <stdio.h>
#include <emscripten.h>
int main() {
REPORT_RESULT(0);
return 0;
}
''')
# generate a dummy file
create_test_file('dummy_file', 'dummy')
# compile the code with the modularize feature and the preload-file option enabled
self.compile_btest(['test.c', '-s', 'MODULARIZE=1', '-s', 'EXPORT_NAME="Foo"', '--preload-file', 'dummy_file', '-s', 'SINGLE_FILE=1'])
self.compile_btest(['test.c', '-s', 'EXIT_RUNTIME', '-s', 'MODULARIZE=1', '-s', 'EXPORT_NAME="Foo"', '--preload-file', 'dummy_file', '-s', 'SINGLE_FILE=1'])
create_test_file('a.html', '''
<script>
atob = undefined;
Expand All @@ -4557,7 +4558,7 @@ def test_base64_atob_fallback(self):
var foo = Foo();
</script>
''')
self.run_browser('a.html', '...', '/report_result?0')
self.run_browser('a.html', '...', '/report_result?exit:0')

# Tests that SINGLE_FILE works as intended in generated HTML (with and without Worker)
def test_single_file_html(self):
Expand Down