Skip to content

Commit 69b1d2c

Browse files
committed
.
1 parent 55c419f commit 69b1d2c

File tree

5 files changed

+60
-14
lines changed

5 files changed

+60
-14
lines changed

src/preamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var ABORT = false;
6060
// set by exit() and abort(). Passed to 'onExit' handler.
6161
// NOTE: This is also used as the process return code code in shell environments
6262
// but only when noExitRuntime is false.
63-
var EXITSTATUS = 0;
63+
var EXITSTATUS;
6464

6565
/** @type {function(*, string=)} */
6666
function assert(condition, text) {

tests/browser_reporting.js

Lines changed: 12 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,13 @@ if (typeof window === 'object' && window) {
3636
xhr.send();
3737
});
3838
}
39+
40+
function reportExitStatus() {
41+
maybeReportResultToServer('exit:' + EXITSTATUS);
42+
}
43+
44+
45+
if (hasModule) {
46+
Module.postRun = Module.postRun || [];
47+
Module.postRun.push(reportExitStatus);
48+
}

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/runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ def make_executable(name):
306306
'lsan',
307307
'wasm2ss',
308308
'posixtest',
309+
'posixtest_browser',
309310
]
310311

311312

@@ -1830,7 +1831,8 @@ def flattened_tests(loaded_tests):
18301831

18311832

18321833
def suite_for_module(module, tests):
1833-
suite_supported = module.__name__ in ('test_core', 'test_other', 'test_posixtest')
1834+
# TODO(sbc): Figure out how to add posixtest here but not posixtest_browser
1835+
suite_supported = module.__name__ in ('test_core', 'test_other']
18341836
if not EMTEST_SAVE_DIR:
18351837
has_multiple_tests = len(tests) > 1
18361838
has_multiple_cores = parallel_testsuite.num_cores() > 1

tests/test_posixtest.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,34 @@
33
# University of Illinois/NCSA Open Source License. Both these licenses can be
44
# found in the LICENSE file.
55

6+
"""Runs the pthreads test from the upstream posixtest suite in:
7+
./tests/third_party/posixtestsuite
8+
See
9+
https://github.com/juj/posixtestsuite
10+
"""
11+
612
import glob
713
import os
814

9-
from runner import RunnerCore, path_from_root
15+
from runner import RunnerCore, BrowserCore, path_from_root
1016
from tools import config
1117
from tools.shared import EMCC
1218

1319
testsuite_root = path_from_root('tests/third_party/posixtestsuite')
1420

1521

1622
class posixtest(RunnerCore):
17-
"""Testsuite that is automatically pupulated from the pthread tests
18-
that are part of the upstream posixtest suite in:
19-
./tests/third_party/posixtestsuite
20-
See
21-
https://github.com/juj/posixtestsuite
23+
"""Run the suite under node (and in parallel)
24+
25+
This class get populated dynamically below.
26+
"""
27+
pass
28+
29+
30+
class posixtest_browser(BrowserCore):
31+
"""Run the suite in the browser (serially)
32+
33+
This class get populated dynamically below.
2234
"""
2335
pass
2436

@@ -95,6 +107,27 @@ def f(self):
95107
return f
96108

97109

110+
def make_test_browser(name, testfile):
111+
112+
def f(self):
113+
if name in disabled:
114+
self.skipTest(disabled[name])
115+
args = ['-I' + os.path.join(testsuite_root, 'include'),
116+
'-Werror',
117+
'-Wno-format-security',
118+
'-Wno-int-conversion',
119+
'-sUSE_PTHREADS',
120+
'-sEXIT_RUNTIME',
121+
'-sTOTAL_MEMORY=268435456',
122+
'-sPTHREAD_POOL_SIZE=40']
123+
# Only are only needed for browser tests of the was btest
124+
# injects headers using `-include` flag.
125+
args += ['-Wno-macro-redefined', '-D_GNU_SOURCE']
126+
self.btest(testfile, args=args, expected='exit:0')
127+
128+
return f
129+
130+
98131
for testdir in get_pthread_tests():
99132
basename = os.path.basename(testdir)
100133
for test_file in glob.glob(os.path.join(testdir, '*.c')):
@@ -104,3 +137,4 @@ def f(self):
104137
test_suffix = test_suffix.replace('-', '_')
105138
test_name = 'test_' + basename + '_' + test_suffix
106139
setattr(posixtest, test_name, make_test(test_name, test_file))
140+
setattr(posixtest_browser, test_name, make_test_browser(test_name, test_file))

0 commit comments

Comments
 (0)