Skip to content

Commit f51beb1

Browse files
authored
Create @crossplatform_test decorator (#18997)
Currently the CircleCI windows builder uses a hardcoded list of tests. Switch to using a decorator to discover these tests, to make it easier to share the list.
1 parent a049bee commit f51beb1

File tree

5 files changed

+74
-47
lines changed

5 files changed

+74
-47
lines changed

.circleci/config.yml

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -649,48 +649,8 @@ jobs:
649649
- pip-install:
650650
python: "$EMSDK_PYTHON"
651651
- run-tests:
652-
title: "other subset"
653-
test_targets: "
654-
core0.test_dylink_basics
655-
core2.test_sse1
656-
core2.test_ccall
657-
core2.test_utf16
658-
core2.test_em_asm_unicode
659-
core2.test_em_js
660-
core2.test_em_js_pthreads
661-
core2.test_unicode_js_library
662-
other.test_reproduce
663-
other.test_stack_overflow
664-
other.test_dlmalloc_modes
665-
other.test_c_preprocessor
666-
other.test_prejs_unicode
667-
other.test_em_js_side_module
668-
other.test_es5_transpile
669-
other.test_emcc_cflags
670-
other.test_stdin
671-
other.test_bad_triple
672-
other.test_closure_externs
673-
other.test_binaryen_debug
674-
other.test_js_optimizer*
675-
other.test_output_to_nowhere
676-
other.test_emcc_dev_null
677-
other.test_cmake*
678-
other.test_system_include_paths
679-
other.test_emar_response_file
680-
other.test_special_chars_in_arguments
681-
other.test_toolchain_profiler
682-
other.test_realpath_nodefs
683-
other.test_response_file_encoding
684-
other.test_libc_progname
685-
other.test_realpath
686-
other.test_embed_file_dup
687-
other.test_dot_a_all_contents_invalid
688-
other.test_emcc_print_search_dirs
689-
other.test_emcc_print_file_name
690-
other.test_minimal_runtime_export_all_modularize
691-
other.test_pkg_config*
692-
other.test_pthreads_flag
693-
other.test_sdl2_config"
652+
title: "crossplatform tests"
653+
test_targets: "--crossplatform-only"
694654
- upload-test-results
695655
# Run a single websockify-based test to ensure it works on windows.
696656
- run-tests:

test/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ def decorated(self, *args, **kwargs):
221221
return decorated
222222

223223

224+
def crossplatform(f):
225+
f.is_crossplatform_test = True
226+
return f
227+
228+
224229
@contextlib.contextmanager
225230
def env_modify(updates):
226231
"""A context manager that updates os.environ."""

test/runner.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,21 @@ def get_all_tests(modules):
127127
return all_tests
128128

129129

130+
def get_crossplatform_tests(modules):
131+
suites = ['core2', 'other'] # We don't need all versions of every test
132+
crossplatform_tests = []
133+
# Walk over the test suites and find the test functions with the
134+
# is_crossplatform_test attribute applied by @crossplatform decorator
135+
for m in modules:
136+
for s in suites:
137+
if hasattr(m, s):
138+
testclass = getattr(m, s)
139+
for funcname in dir(testclass):
140+
if hasattr(getattr(testclass, funcname), 'is_crossplatform_test'):
141+
crossplatform_tests.append(s + '.' + funcname)
142+
return crossplatform_tests
143+
144+
130145
def tests_with_expanded_wildcards(args, all_tests):
131146
# Process wildcards, e.g. "browser.test_pthread_*" should expand to list all pthread tests
132147
new_args = []
@@ -353,6 +368,7 @@ def parse_args(args):
353368
const=True, default=False)
354369
parser.add_argument('--force64', dest='force64', action='store_const',
355370
const=True, default=None)
371+
parser.add_argument('--crossplatform-only', action='store_true')
356372
return parser.parse_args()
357373

358374

@@ -426,9 +442,12 @@ def prepend_default(arg):
426442

427443
modules = get_and_import_modules()
428444
all_tests = get_all_tests(modules)
429-
tests = tests_with_expanded_wildcards(tests, all_tests)
430-
tests = skip_requested_tests(tests, modules)
431-
tests = args_for_random_tests(tests, modules)
445+
if options.crossplatform_only:
446+
tests = get_crossplatform_tests(modules)
447+
else:
448+
tests = tests_with_expanded_wildcards(tests, all_tests)
449+
tests = skip_requested_tests(tests, modules)
450+
tests = args_for_random_tests(tests, modules)
432451
suites, unmatched_tests = load_test_suites(tests, modules)
433452
if unmatched_tests:
434453
print('ERROR: could not find the following tests: ' + ' '.join(unmatched_tests))

test/test_core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from common import RunnerCore, path_from_root, requires_native_clang, test_file, create_file
2828
from common import skip_if, needs_dylink, no_windows, no_mac, is_slow_test, parameterized
2929
from common import env_modify, with_env_modify, disabled, node_pthreads, also_with_wasm_bigint
30-
from common import read_file, read_binary, requires_v8, requires_node, compiler_for
30+
from common import read_file, read_binary, requires_v8, requires_node, compiler_for, crossplatform
3131
from common import NON_ZERO, WEBIDL_BINDER, EMBUILDER, PYTHON
3232
import clang_native
3333

@@ -2294,6 +2294,7 @@ def test_main_thread_async_em_asm(self, args, force_c=False):
22942294
def test_main_thread_em_asm_signatures(self):
22952295
self.do_core_test('test_em_asm_signatures.cpp', assert_returncode=NON_ZERO)
22962296

2297+
@crossplatform
22972298
def test_em_asm_unicode(self):
22982299
self.do_core_test('test_em_asm_unicode.cpp')
22992300
self.do_core_test('test_em_asm_unicode.cpp', force_c=True)
@@ -2334,6 +2335,7 @@ def test_em_asm_side_module(self):
23342335
'dylink': (['-sMAIN_MODULE=2'], False),
23352336
'dylink_c': (['-sMAIN_MODULE=2'], True),
23362337
})
2338+
@crossplatform
23372339
def test_em_js(self, args, force_c):
23382340
if '-sMAIN_MODULE=2' in args:
23392341
self.check_dylink()
@@ -4273,6 +4275,7 @@ def do_basic_dylink_test(self, **kwargs):
42734275
''', 'other says 11.', 'int sidey();', force_c=True, **kwargs)
42744276

42754277
@needs_dylink
4278+
@crossplatform
42764279
def test_dylink_basics(self):
42774280
self.do_basic_dylink_test(need_reverse=False)
42784281
self.verify_in_strict_mode('main.js')
@@ -5905,6 +5908,7 @@ def test_utf32(self):
59055908
self.do_runf(test_file('utf32.cpp'), 'OK.')
59065909
self.do_runf(test_file('utf32.cpp'), 'OK.', args=['-fshort-wchar'])
59075910

5911+
@crossplatform
59085912
def test_utf16(self):
59095913
self.set_setting('EXPORTED_RUNTIME_METHODS', ['writeAsciiToMemory', 'UTF16ToString', 'stringToUTF16'])
59105914
self.do_runf(test_file('core/test_utf16.cpp'), 'OK.')
@@ -6457,6 +6461,7 @@ def test_js_libraries(self):
64576461
self.do_runf('main.cpp', 'hello from lib!\n*32*\n')
64586462

64596463
@with_env_modify({'LC_ALL': 'latin-1', 'PYTHONUTF8': '0', 'PYTHONCOERCECLOCALE': '0'})
6464+
@crossplatform
64606465
def test_unicode_js_library(self):
64616466
create_file('main.c', '''
64626467
#include <stdio.h>
@@ -6736,6 +6741,7 @@ def test_neon_wasm_simd(self):
67366741

67376742
# Tests invoking the SIMD API via x86 SSE1 xmmintrin.h header (_mm_x() functions)
67386743
@wasm_simd
6744+
@crossplatform
67396745
@requires_native_clang
67406746
@no_safe_heap('has unaligned 64-bit operations in wasm')
67416747
@no_ubsan('test contains UB')
@@ -7169,6 +7175,7 @@ def test_wasm2c_sandboxing(self, mode):
71697175

71707176
### Integration tests
71717177

7178+
@crossplatform
71727179
def test_ccall(self):
71737180
self.emcc_args.append('-Wno-return-stack-address')
71747181
self.set_setting('EXPORTED_RUNTIME_METHODS', ['ccall', 'cwrap', 'STACK_SIZE'])

0 commit comments

Comments
 (0)