Skip to content

Commit c2fa39c

Browse files
authored
Add number of wasm funcs to other.test_metadce (#7307)
* but ignore # of functions in main module, it changes a lot
1 parent 7be1dd2 commit c2fa39c

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

tests/test_other.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8186,8 +8186,8 @@ def break_cashew():
81868186
def test_binaryen_metadce(self):
81878187
def test(filename, expectations):
81888188
# in -Os, -Oz, we remove imports wasm doesn't need
8189-
for args, expected_len, expected_exists, expected_not_exists, expected_wasm_size, expected_wasm_imports, expected_wasm_exports in expectations:
8190-
print(args, expected_len, expected_exists, expected_not_exists, expected_wasm_size, expected_wasm_imports, expected_wasm_exports)
8189+
for args, expected_len, expected_exists, expected_not_exists, expected_wasm_size, expected_wasm_imports, expected_wasm_exports, expected_wasm_funcs in expectations:
8190+
print(args, expected_len, expected_exists, expected_not_exists, expected_wasm_size, expected_wasm_imports, expected_wasm_exports, expected_wasm_funcs)
81918191
run_process([PYTHON, EMCC, filename, '-g2'] + args)
81928192
# find the imports we send from JS
81938193
js = open('a.out.js').read()
@@ -8212,23 +8212,26 @@ def test(filename, expectations):
82128212
wast = run_process([os.path.join(Building.get_binaryen_bin(), 'wasm-dis'), 'a.out.wasm'], stdout=PIPE).stdout
82138213
imports = wast.count('(import ')
82148214
exports = wast.count('(export ')
8215+
funcs = wast.count('\n (func ')
82158216
self.assertEqual(imports, expected_wasm_imports)
82168217
self.assertEqual(exports, expected_wasm_exports)
8218+
if expected_wasm_funcs is not None:
8219+
self.assertEqual(funcs, expected_wasm_funcs)
82178220

82188221
print('test on hello world')
82198222
test(path_from_root('tests', 'hello_world.cpp'), [
8220-
([], 23, ['abort', 'tempDoublePtr'], ['waka'], 46505, 24, 19), # noqa
8221-
(['-O1'], 18, ['abort', 'tempDoublePtr'], ['waka'], 12630, 16, 17), # noqa
8222-
(['-O2'], 18, ['abort', 'tempDoublePtr'], ['waka'], 12616, 16, 17), # noqa
8223-
(['-O3'], 7, ['abort'], ['tempDoublePtr', 'waka'], 2818, 10, 2), # noqa; in -O3, -Os and -Oz we metadce
8224-
(['-Os'], 7, ['abort'], ['tempDoublePtr', 'waka'], 2771, 10, 2), # noqa
8225-
(['-Oz'], 7, ['abort'], ['tempDoublePtr', 'waka'], 2765, 10, 2), # noqa
8223+
([], 23, ['abort', 'tempDoublePtr'], ['waka'], 46505, 24, 19, 62), # noqa
8224+
(['-O1'], 18, ['abort', 'tempDoublePtr'], ['waka'], 12630, 16, 17, 34), # noqa
8225+
(['-O2'], 18, ['abort', 'tempDoublePtr'], ['waka'], 12616, 16, 17, 33), # noqa
8226+
(['-O3'], 7, ['abort'], ['tempDoublePtr', 'waka'], 2818, 10, 2, 21), # noqa; in -O3, -Os and -Oz we metadce
8227+
(['-Os'], 7, ['abort'], ['tempDoublePtr', 'waka'], 2771, 10, 2, 21), # noqa
8228+
(['-Oz'], 7, ['abort'], ['tempDoublePtr', 'waka'], 2765, 10, 2, 21), # noqa
82268229
# finally, check what happens when we export nothing. wasm should be almost empty
82278230
(['-Os', '-s', 'EXPORTED_FUNCTIONS=[]'],
8228-
0, [], ['tempDoublePtr', 'waka'], 8, 0, 0), # noqa; totally empty!
8231+
0, [], ['tempDoublePtr', 'waka'], 8, 0, 0, 0), # noqa; totally empty!
82298232
# but we don't metadce with linkable code! other modules may want it
82308233
(['-O3', '-s', 'MAIN_MODULE=1'],
8231-
1529, ['invoke_i'], ['waka'], 469663, 149, 1443),
8234+
1529, ['invoke_i'], ['waka'], 469663, 149, 1443, None), # noqa; don't compare the # of functions in a main module, which changes a lot
82328235
]) # noqa
82338236

82348237
print('test on a minimal pure computational thing')
@@ -8241,20 +8244,20 @@ def test(filename, expectations):
82418244
}
82428245
''')
82438246
test('minimal.c', [
8244-
([], 23, ['abort', 'tempDoublePtr'], ['waka'], 22712, 24, 18), # noqa
8245-
(['-O1'], 11, ['abort', 'tempDoublePtr'], ['waka'], 10450, 9, 15), # noqa
8246-
(['-O2'], 11, ['abort', 'tempDoublePtr'], ['waka'], 10440, 9, 15), # noqa
8247+
([], 23, ['abort', 'tempDoublePtr'], ['waka'], 22712, 24, 18, 31), # noqa
8248+
(['-O1'], 11, ['abort', 'tempDoublePtr'], ['waka'], 10450, 9, 15, 15), # noqa
8249+
(['-O2'], 11, ['abort', 'tempDoublePtr'], ['waka'], 10440, 9, 15, 15), # noqa
82478250
# in -O3, -Os and -Oz we metadce, and they shrink it down to the minimal output we want
8248-
(['-O3'], 0, [], ['tempDoublePtr', 'waka'], 58, 0, 1), # noqa
8249-
(['-Os'], 0, [], ['tempDoublePtr', 'waka'], 58, 0, 1), # noqa
8250-
(['-Oz'], 0, [], ['tempDoublePtr', 'waka'], 58, 0, 1), # noqa
8251+
(['-O3'], 0, [], ['tempDoublePtr', 'waka'], 58, 0, 1, 1), # noqa
8252+
(['-Os'], 0, [], ['tempDoublePtr', 'waka'], 58, 0, 1, 1), # noqa
8253+
(['-Oz'], 0, [], ['tempDoublePtr', 'waka'], 58, 0, 1, 1), # noqa
82518254
])
82528255

82538256
print('test on libc++: see effects of emulated function pointers')
82548257
test(path_from_root('tests', 'hello_libcxx.cpp'), [
8255-
(['-O2'], 53, ['abort', 'tempDoublePtr'], ['waka'], 208677, 30, 44), # noqa
8258+
(['-O2'], 53, ['abort', 'tempDoublePtr'], ['waka'], 208677, 30, 44, 661), # noqa
82568259
(['-O2', '-s', 'EMULATED_FUNCTION_POINTERS=1'],
8257-
54, ['abort', 'tempDoublePtr'], ['waka'], 208677, 30, 25), # noqa
8260+
54, ['abort', 'tempDoublePtr'], ['waka'], 208677, 30, 25, 622), # noqa
82588261
]) # noqa
82598262

82608263
# ensures runtime exports work, even with metadce

0 commit comments

Comments
 (0)