Skip to content

Commit 202dd9c

Browse files
committed
Integrate posixtestsuite for pthread testing
This change adds posixtestsuite as a git submodule (in tests/third_party). It also adds a new test suite that auto-populates based on the files in `posixtestsuite/conformance/interfaces/pthread_*` The submodule is optional in that the testsuite simply remains empty if it is not found.
1 parent dfb6fda commit 202dd9c

File tree

5 files changed

+102
-2
lines changed

5 files changed

+102
-2
lines changed

.circleci/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ commands:
123123
# Must be absolute path or relative path from working_directory
124124
at: ~/
125125
- checkout
126+
- run:
127+
name: submodule update
128+
command: git submodule update --init
126129
- emsdk-env
127130
- npm-install
128131
- run:
@@ -384,7 +387,7 @@ jobs:
384387
steps:
385388
- run-tests:
386389
# also add a few asan tests
387-
test_targets: "wasm2 asan.test_embind* asan.test_abort_on_exceptions asan.test_ubsan_full_left_shift_fsanitize_integer"
390+
test_targets: "wasm2 asan.test_embind* asan.test_abort_on_exceptions asan.test_ubsan_full_left_shift_fsanitize_integer posixtest.test_pthread_create_1_1"
388391
test-wasm3:
389392
executor: bionic
390393
steps:

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "tests/third_party/posixtestsuite"]
2+
path = tests/third_party/posixtestsuite
3+
url = https://github.com/juj/posixtestsuite

tests/runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ def make_executable(name):
305305
'asan',
306306
'lsan',
307307
'wasm2ss',
308+
'posixtest',
308309
]
309310

310311

@@ -1829,7 +1830,7 @@ def flattened_tests(loaded_tests):
18291830

18301831

18311832
def suite_for_module(module, tests):
1832-
suite_supported = module.__name__ in ('test_core', 'test_other')
1833+
suite_supported = module.__name__ in ('test_core', 'test_other', 'test_posixtest')
18331834
if not EMTEST_SAVE_DIR:
18341835
has_multiple_tests = len(tests) > 1
18351836
has_multiple_cores = parallel_testsuite.num_cores() > 1

tests/test_posixtest.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright 2020 The Emscripten Authors. All rights reserved.
2+
# Emscripten is available under two separate licenses, the MIT license and the
3+
# University of Illinois/NCSA Open Source License. Both these licenses can be
4+
# found in the LICENSE file.
5+
6+
import glob
7+
import os
8+
9+
from runner import RunnerCore, path_from_root
10+
from tools import config
11+
from tools.shared import EMCC
12+
13+
testsuite_root = path_from_root('tests/third_party/posixtestsuite')
14+
15+
16+
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
22+
"""
23+
pass
24+
25+
26+
def filter_tests(all_tests):
27+
pthread_tests = [t for t in all_tests if t.startswith('pthread_')]
28+
# filter out some tests we don't support
29+
pthread_tests = [t for t in pthread_tests if not t.startswith('pthread_atfork')]
30+
pthread_tests = [t for t in pthread_tests if not t.startswith('pthread_atsigmask')]
31+
return pthread_tests
32+
33+
34+
def get_pthread_tests():
35+
# For now, we don't require the submodule to exist. In this case we just report
36+
# no tests
37+
pthread_test_root = os.path.join(testsuite_root, 'conformance', 'interfaces')
38+
if not os.path.exists(pthread_test_root):
39+
return []
40+
pthread_tests = filter_tests(os.listdir(pthread_test_root))
41+
pthread_tests = [os.path.join(pthread_test_root, t) for t in pthread_tests]
42+
return pthread_tests
43+
44+
45+
engine = config.NODE_JS + ['--experimental-wasm-threads', '--experimental-wasm-bulk-memory']
46+
47+
# Mark certain tests as not passing
48+
disabled = {
49+
'test_pthread_create_11_1': 'never returns',
50+
'test_pthread_barrier_wait_2_1': 'never returns',
51+
'test_pthread_cond_timedwait_2_6': 'never returns',
52+
'test_pthread_cond_timedwait_4_3': 'never returns',
53+
'test_pthread_attr_setscope_5_1': 'internally skipped (PTS_UNTESTED)',
54+
'test_pthread_cond_wait_2_3': 'never returns',
55+
'test_pthread_create_5_1': 'never returns',
56+
'test_pthread_exit_1_2': 'never returns',
57+
'test_pthread_exit_2_2': 'never returns',
58+
'test_pthread_exit_3_2': 'never returns',
59+
'test_pthread_exit_4_1': 'never returns',
60+
}
61+
62+
def make_test(name, testfile):
63+
64+
def f(self):
65+
if name in disabled:
66+
self.skipTest(disabled[name])
67+
args = [testfile,
68+
'-I' + os.path.join(testsuite_root, 'include'),
69+
'-Werror',
70+
'-Wno-format-security',
71+
'-Wno-int-conversion',
72+
'-sUSE_PTHREADS',
73+
'-sEXIT_RUNTIME',
74+
'-sTOTAL_MEMORY=268435456',
75+
'-sPTHREAD_POOL_SIZE=40']
76+
# TODO(sbc): Run as btest
77+
# self.compile_btest(args)
78+
self.run_process([EMCC, '-o', 'test.js'] + args)
79+
self.run_js('test.js', engine=engine)
80+
81+
return f
82+
83+
84+
for testdir in get_pthread_tests():
85+
basename = os.path.basename(testdir)
86+
for test_file in glob.glob(os.path.join(testdir, '*.c')):
87+
if not os.path.basename(test_file)[0].isdigit():
88+
continue
89+
test_suffix = os.path.splitext(os.path.basename(test_file))[0]
90+
test_suffix = test_suffix.replace('-', '_')
91+
test_name = 'test_' + basename + '_' + test_suffix
92+
setattr(posixtest, test_name, make_test(test_name, test_file))

tests/third_party/posixtestsuite

Submodule posixtestsuite added at 2637242

0 commit comments

Comments
 (0)