Skip to content

[test] Parameterize test_function_exports_are_small. NFC #21843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -10703,27 +10703,33 @@ def test_emscripten_license(self, expect_license, args):
# unminified exported name exactly once. (need to contain the export name once for unminified
# access from calling code, and should not have the unminified name exist more than once, that
# would be wasteful for size)
def test_function_exports_are_small(self):
def test(args, closure, opt):
extra_args = args + opt + closure
print(extra_args)
args = [EMCC, test_file('long_function_name_in_export.c'), '-o', 'a.html', '-sENVIRONMENT=web', '-sDECLARE_ASM_MODULE_EXPORTS=0', '-Werror'] + extra_args
self.run_process(args)
@parameterized({
'': ([],),
'closure': (['--closure=1'],),
})
@parameterized({
'O2': (['-O2'],),
'O3': (['-O3'],),
'Os': (['-Os'],),
})
@parameterized({
'sync': (['-sWASM_ASYNC_COMPILATION=0'],),
'wasm2js': (['-sWASM=0', '-Wno-closure'],),
})
def test_function_exports_are_small(self, args, opt, closure):
extra_args = args + opt + closure
args = [EMCC, test_file('long_function_name_in_export.c'), '-o', 'a.html', '-sENVIRONMENT=web', '-sDECLARE_ASM_MODULE_EXPORTS=0', '-Werror'] + extra_args
self.run_process(args)

output = read_file('a.js')
delete_file('a.js')
self.assertNotContained('_thisIsAFunctionExportedFromAsmJsOrWasmWithVeryLongFunction', output)

# TODO: Add stricter testing when Wasm side is also optimized: (currently Wasm does still need
# to reference exports multiple times)
if '-sWASM=0' in args:
num_times_export_is_referenced = output.count('thisIsAFunctionExportedFromAsmJsOrWasmWithVeryLongFunction')
self.assertEqual(num_times_export_is_referenced, 1)

for closure in [[], ['--closure=1']]:
for opt in [['-O2'], ['-O3'], ['-Os']]:
test(['-sWASM=0', '-Wno-closure'], closure, opt)
test(['-sWASM_ASYNC_COMPILATION=0'], closure, opt)
output = read_file('a.js')
delete_file('a.js')
self.assertNotContained('_thisIsAFunctionExportedFromAsmJsOrWasmWithVeryLongFunction', output)

# TODO: Add stricter testing when Wasm side is also optimized: (currently Wasm does still need
# to reference exports multiple times)
if '-sWASM=0' in args:
num_times_export_is_referenced = output.count('thisIsAFunctionExportedFromAsmJsOrWasmWithVeryLongFunction')
self.assertEqual(num_times_export_is_referenced, 1)

@parameterized({
'hello_world_wasm': ('hello_world', False, True),
Expand Down