|
| 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)) |
0 commit comments