Skip to content

Commit 62d3011

Browse files
committed
Automatically report exit status in browser tests
This means that tests don't necessarily need to call REPORT_RESULT. I'm going to be taking advantage of this in #12923. Also, don't initialize EXIT_STATUS to zero, but leave it as undefined. It seems useful to be able to tell the diference between a program that exits with a zero status and one that has not in fact exited yet.
1 parent c178575 commit 62d3011

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

tests/browser_reporting.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var hasModule = typeof Module === 'object' && Module;
2+
13
/** @param {boolean=} sync
24
@param {number=} port */
35
function reportResultToServer(result, sync, port) {
@@ -7,9 +9,7 @@ function reportResultToServer(result, sync, port) {
79
reportErrorToServer("excessive reported results, sending " + result + ", test will fail");
810
}
911
reportResultToServer.reported = true;
10-
1112
var xhr = new XMLHttpRequest();
12-
var hasModule = typeof Module === 'object' && Module;
1313
if (hasModule && Module['pageThrewException']) result = 12345;
1414
xhr.open('GET', 'http://localhost:' + port + '/report_result?' + result, !sync);
1515
xhr.send();
@@ -36,3 +36,9 @@ if (typeof window === 'object' && window) {
3636
xhr.send();
3737
});
3838
}
39+
40+
if (hasModule) {
41+
Module['onExit'] = function(status) {
42+
maybeReportResultToServer('exit:' + status);
43+
}
44+
}

tests/report_result.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
#ifndef REPORT_RESULT_H_
1111
#define REPORT_RESULT_H_
1212

13-
#include <stdio.h>
14-
1513
#ifdef __EMSCRIPTEN__
1614

17-
#include <emscripten.h>
18-
1915
#ifdef __cplusplus
2016
extern "C" {
2117
#endif
18+
2219
void _ReportResult(int result, int sync);
2320
void _MaybeReportResult(int result, int sync);
21+
2422
#ifdef __cplusplus
2523
}
2624
#endif
@@ -40,7 +38,9 @@ void _MaybeReportResult(int result, int sync);
4038

4139
#else
4240

41+
#include <stdio.h>
4342
#include <stdlib.h>
43+
4444
#define REPORT_RESULT(result) \
4545
do { \
4646
printf("result: %d\n", result); \

tests/test_browser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4548,15 +4548,14 @@ def test_base64_atob_fallback(self):
45484548
#include <stdio.h>
45494549
#include <emscripten.h>
45504550
int main() {
4551-
REPORT_RESULT(0);
45524551
return 0;
45534552
}
45544553
'''
45554554
create_test_file('test.c', self.with_report_result(src))
45564555
# generate a dummy file
45574556
create_test_file('dummy_file', 'dummy')
45584557
# compile the code with the modularize feature and the preload-file option enabled
4559-
self.compile_btest(['test.c', '-s', 'MODULARIZE=1', '-s', 'EXPORT_NAME="Foo"', '--preload-file', 'dummy_file', '-s', 'SINGLE_FILE=1'])
4558+
self.compile_btest(['test.c', '-s', 'EXIT_RUNTIME', '-s', 'MODULARIZE=1', '-s', 'EXPORT_NAME="Foo"', '--preload-file', 'dummy_file', '-s', 'SINGLE_FILE=1'])
45604559
create_test_file('a.html', '''
45614560
<script>
45624561
atob = undefined;
@@ -4567,7 +4566,7 @@ def test_base64_atob_fallback(self):
45674566
var foo = Foo();
45684567
</script>
45694568
''')
4570-
self.run_browser('a.html', '...', '/report_result?0')
4569+
self.run_browser('a.html', '...', '/report_result?exit:0')
45714570

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

0 commit comments

Comments
 (0)