diff --git a/tests/browser_reporting.js b/tests/browser_reporting.js index 21418a52fe555..48742204c243f 100644 --- a/tests/browser_reporting.js +++ b/tests/browser_reporting.js @@ -1,3 +1,5 @@ +var hasModule = typeof Module === 'object' && Module; + /** @param {boolean=} sync @param {number=} port */ function reportResultToServer(result, sync, port) { @@ -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(); @@ -36,3 +36,9 @@ if (typeof window === 'object' && window) { xhr.send(); }); } + +if (hasModule) { + Module['onExit'] = function(status) { + maybeReportResultToServer('exit:' + status); + } +} diff --git a/tests/runner.py b/tests/runner.py index dcadb768cb8dd..7aef46c99dfda 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -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 = [] @@ -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() diff --git a/tests/test_browser.py b/tests/test_browser.py index 07be0293033dc..5dd11af76d281 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -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') @@ -4539,14 +4541,13 @@ def test_base64_atob_fallback(self): #include #include 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', ''' ''') - 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):