Skip to content

Commit 43479ae

Browse files
authored
Refactor other.test_embind. NFC (emscripten-core#20502)
1 parent 0f15c2a commit 43479ae

2 files changed

Lines changed: 48 additions & 41 deletions

File tree

test/common.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import contextlib
1414
import difflib
1515
import hashlib
16+
import itertools
1617
import logging
1718
import multiprocessing
1819
import os
@@ -509,7 +510,14 @@ def test_something_subtest2(self):
509510
# runs test_something(4, 5, 6)
510511
"""
511512
def decorator(func):
512-
func._parameterize = parameters
513+
prev = getattr(func, '_parameterize', None)
514+
if prev:
515+
# If we're parameterizing 2nd time, construct a cartesian product for various combinations.
516+
func._parameterize = {
517+
'_'.join(filter(None, [k1, k2])): v1 + v2 for (k1, v1), (k2, v2) in itertools.product(prev.items(), parameters.items())
518+
}
519+
else:
520+
func._parameterize = parameters
513521
return func
514522
return decorator
515523

test/test_other.py

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,53 +2862,52 @@ def test_embind_closure_no_dynamic_execution(self):
28622862

28632863
@is_slow_test
28642864
@parameterized({
2865-
'': [[]],
2866-
'no_utf8': [['-sEMBIND_STD_STRING_IS_UTF8=0']],
2867-
'no_dynamic': [['-sDYNAMIC_EXECUTION=0']],
2865+
'': [],
2866+
'no_utf8': ['-sEMBIND_STD_STRING_IS_UTF8=0'],
2867+
'no_dynamic': ['-sDYNAMIC_EXECUTION=0'],
28682868
})
2869-
@with_env_modify({'EMCC_CLOSURE_ARGS': '--externs ' + shlex.quote(test_file('embind/underscore-externs.js'))})
2870-
def test_embind(self, extra_args):
2871-
test_cases = [
2872-
(['-lembind']),
2873-
# Ensure embind compiles under C++17 where "noexcept" became part of the function signature.
2874-
(['-lembind', '-std=c++17']),
2875-
(['-lembind', '-O1']),
2876-
(['-lembind', '-O2']),
2877-
(['-lembind', '-O2', '-sALLOW_MEMORY_GROWTH', test_file('embind/isMemoryGrowthEnabled=true.cpp')]),
2878-
(['-lembind', '-O2', '--closure=1']),
2869+
@parameterized({
2870+
'': [],
2871+
# Ensure embind compiles under C++17 where "noexcept" became part of the function signature.
2872+
'cxx17': ['-std=c++17'],
2873+
'o1': ['-O1'],
2874+
'o2': ['-O2'],
2875+
'o2_mem_growth': ['-O2', '-sALLOW_MEMORY_GROWTH', test_file('embind/isMemoryGrowthEnabled=true.cpp')],
2876+
'o2_closure': ['-O2', '--closure=1', '--closure-args', '--externs ' + shlex.quote(test_file('embind/underscore-externs.js'))],
2877+
})
2878+
def test_embind(self, *extra_args):
2879+
self.emcc_args += [
2880+
'-lembind',
2881+
'-sRETAIN_COMPILER_SETTINGS',
2882+
'-sEXPORTED_RUNTIME_METHODS=getCompilerSetting',
2883+
'-sWASM_ASYNC_COMPILATION=0',
2884+
# This test uses a `CustomSmartPtr` class which has 1MB of data embedded in
2885+
# it which means we need more stack space than normal.
2886+
'-sSTACK_SIZE=2MB',
2887+
'--pre-js', test_file('embind/test.pre.js'),
2888+
'--post-js', test_file('embind/test.post.js'),
28792889
]
2880-
extra_args = extra_args + ['-sRETAIN_COMPILER_SETTINGS', '-sEXPORTED_RUNTIME_METHODS=getCompilerSetting']
2881-
test_cases = [t + extra_args for t in test_cases]
2882-
for args in test_cases:
2883-
print(args)
2884-
self.clear()
2890+
self.emcc_args += extra_args
28852891

2886-
testFiles = [
2887-
test_file('embind/underscore-1.4.2.js'),
2888-
test_file('embind/imvu_test_adapter.js'),
2889-
test_file('embind/embind.test.js'),
2890-
]
2892+
js_file = self.build(test_file('embind/embind_test.cpp'))
28912893

2892-
self.run_process(
2893-
[EMXX, test_file('embind/embind_test.cpp'),
2894-
'--pre-js', test_file('embind/test.pre.js'),
2895-
'--post-js', test_file('embind/test.post.js'),
2896-
'-sWASM_ASYNC_COMPILATION=0',
2897-
# This test uses a `CustomSmartPtr` class which has 1MB of data embedded in
2898-
# it which means we need more stack space than normal.
2899-
'-sSTACK_SIZE=2MB'] + args)
2894+
testFiles = [
2895+
test_file('embind/underscore-1.4.2.js'),
2896+
test_file('embind/imvu_test_adapter.js'),
2897+
test_file('embind/embind.test.js'),
2898+
]
29002899

2901-
if '-sDYNAMIC_EXECUTION=0' in args:
2902-
js_binary_str = read_file('a.out.js')
2903-
self.assertNotContained('new Function(', js_binary_str)
2904-
self.assertNotContained('eval(', js_binary_str)
2900+
if '-sDYNAMIC_EXECUTION=0' in extra_args:
2901+
js_binary_str = read_file(js_file)
2902+
self.assertNotContained('new Function(', js_binary_str)
2903+
self.assertNotContained('eval(', js_binary_str)
29052904

2906-
with open('a.out.js', 'ab') as f:
2907-
for tf in testFiles:
2908-
f.write(read_binary(tf))
2905+
with open(js_file, 'ab') as f:
2906+
for tf in testFiles:
2907+
f.write(read_binary(tf))
29092908

2910-
output = self.run_js('a.out.js')
2911-
self.assertNotContained('FAIL', output)
2909+
output = self.run_js(js_file)
2910+
self.assertNotContained('FAIL', output)
29122911

29132912
@requires_node
29142913
def test_embind_finalization(self):

0 commit comments

Comments
 (0)