Skip to content

Commit 56c2b34

Browse files
authored
Cleanup run_codesize_test. NFC (#24387)
This change removes the `expected_exists`, `expected_not_exists` arguments which are no longer used. These lists are now redundant since we check instead with golden files. We had a few places where `waka` was being passed to `expected_not_exists` but there are no code size tests that use a symbols called `waka`. Perhaps there once was and this was just cargo-culted? Also, remove the now-unnecessary use of `*args` which was making it hard to understand exactly which arguments the tests were using.
1 parent 9b2c53a commit 56c2b34

File tree

2 files changed

+58
-73
lines changed

2 files changed

+58
-73
lines changed

test/other/codesize/hello_libcxx.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
#include <iostream>
77

8-
int main()
9-
{
8+
int main() {
109
std::cout << "hello, world!" << std::endl;
1110
return 0;
1211
}

test/test_other.py

Lines changed: 57 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9178,16 +9178,15 @@ def test_unoptimized_code_size(self):
91789178
test_file('other/test_unoptimized_code_size_strict.js.size'),
91799179
os.path.getsize('strict.js'))
91809180

9181-
def run_codesize_test(self, filename, args=[], expected_exists=[], expected_not_exists=[], # noqa
9182-
check_funcs=True):
9181+
def run_codesize_test(self, filename, emcc_args, check_funcs=True):
91839182

91849183
# in -Os, -Oz, we remove imports wasm doesn't need
9185-
print('Running metadce test: %s:' % filename, args, expected_exists, expected_not_exists, check_funcs)
9184+
print('Running codesize test: %s:' % filename, emcc_args, check_funcs)
91869185
filename = test_file('other/codesize', filename)
91879186
expected_basename = test_file('other/codesize', self.id().split('.')[-1])
91889187

91899188
# Run once without closure and parse output to find wasmImports
9190-
build_cmd = [compiler_for(filename), filename, '--output-eol=linux', '--emit-minification-map=minify.map'] + args + self.get_emcc_args()
9189+
build_cmd = [compiler_for(filename), filename, '--output-eol=linux', '--emit-minification-map=minify.map'] + emcc_args + self.get_emcc_args()
91919190
self.run_process(build_cmd + ['-g2'])
91929191
# find the imports we send from JS
91939192
# TODO(sbc): Find a way to do that that doesn't depend on internal details of
@@ -9213,19 +9212,14 @@ def run_codesize_test(self, filename, args=[], expected_exists=[], expected_not_
92139212

92149213
self.run_process(build_cmd + ['--profiling-funcs', '--closure=1'])
92159214

9216-
for exists in expected_exists:
9217-
self.assertIn(exists, sent)
9218-
for not_exists in expected_not_exists:
9219-
self.assertNotIn(not_exists, sent)
9220-
92219215
js_size = os.path.getsize('a.out.js')
92229216
gz_size = get_file_gzipped_size('a.out.js')
92239217
js_size_file = expected_basename + '.jssize'
92249218
gz_size_file = expected_basename + '.gzsize'
92259219
self.check_expected_size_in_file('js', js_size_file, js_size)
92269220
self.check_expected_size_in_file('gz', gz_size_file, gz_size)
92279221

9228-
if '-sSINGLE_FILE' in args:
9222+
if '-sSINGLE_FILE' in emcc_args:
92299223
# No wasm file in the final output so we skip the rest of the
92309224
# testing
92319225
return
@@ -9277,25 +9271,25 @@ def strip_numeric_suffixes(funcname):
92779271
self.assertFileContents(filename, data)
92789272

92799273
@parameterized({
9280-
'O0': ([], [], ['waka']), # noqa
9281-
'O1': (['-O1'], [], ['waka']), # noqa
9282-
'O2': (['-O2'], [], ['waka']), # noqa
9274+
'O0': ([],),
9275+
'O1': (['-O1'],),
9276+
'O2': (['-O2'],),
92839277
# in -O3, -Os and -Oz we metadce, and they shrink it down to the minimal output we want
9284-
'O3': (['-O3'], [], []), # noqa
9285-
'Os': (['-Os'], [], []), # noqa
9286-
'Oz': (['-Oz'], [], []), # noqa
9287-
'Os_mr': (['-Os', '-sMINIMAL_RUNTIME'], [], [], 74), # noqa
9278+
'O3': (['-O3'],), # noqa
9279+
'Os': (['-Os'],), # noqa
9280+
'Oz': (['-Oz'],), # noqa
9281+
'Os_mr': (['-Os', '-sMINIMAL_RUNTIME'],),
92889282
# EVAL_CTORS also removes the __wasm_call_ctors function
9289-
'Oz-ctors': (['-Oz', '-sEVAL_CTORS'], [], []), # noqa
9290-
'64': (['-Oz', '-sMEMORY64'], [], []), # noqa
9283+
'Oz-ctors': (['-Oz', '-sEVAL_CTORS'],),
9284+
'64': (['-Oz', '-sMEMORY64'],),
92919285
# WasmFS should not be fully linked into a minimal program.
9292-
'wasmfs': (['-Oz', '-sWASMFS'], [], []), # noqa
9293-
'esm': (['-Oz', '-sEXPORT_ES6'], [], []), # noqa
9286+
'wasmfs': (['-Oz', '-sWASMFS'],),
9287+
'esm': (['-Oz', '-sEXPORT_ES6'],),
92949288
})
9295-
def test_codesize_minimal(self, *args):
9289+
def test_codesize_minimal(self, args):
92969290
self.set_setting('STRICT')
92979291
self.emcc_args.append('--no-entry')
9298-
self.run_codesize_test('minimal.c', *args)
9292+
self.run_codesize_test('minimal.c', args)
92999293

93009294
@node_pthreads
93019295
@parameterized({
@@ -9306,88 +9300,80 @@ def test_codesize_minimal_pthreads(self, args):
93069300
self.run_codesize_test('minimal_main.c', ['-Oz', '-pthread', '-sPROXY_TO_PTHREAD', '-sSTRICT'] + args)
93079301

93089302
@parameterized({
9309-
'noexcept': (['-O2'], [], ['waka']), # noqa
9303+
'noexcept': (['-O2'],), # noqa
93109304
# exceptions increases code size significantly
9311-
'except': (['-O2', '-fexceptions'], [], ['waka']), # noqa
9305+
'except': (['-O2', '-fexceptions'],), # noqa
93129306
# exceptions does not pull in demangling by default, which increases code size
9313-
'mangle': (['-O2', '-fexceptions',
9314-
'-sEXPORTED_FUNCTIONS=_main,_free,___cxa_demangle', '-Wno-deprecated'], [], ['waka']), # noqa
9307+
'mangle': (['-O2', '-fexceptions', '-sEXPORTED_FUNCTIONS=_main,_free,___cxa_demangle', '-Wno-deprecated'],), # noqa
93159308
# Wasm EH's code size increase is smaller than that of Emscripten EH
9316-
'except_wasm': (['-O2', '-fwasm-exceptions', '-sWASM_LEGACY_EXCEPTIONS=0'], [], ['waka']),
9317-
'except_wasm_legacy': (['-O2', '-fwasm-exceptions', '-sWASM_LEGACY_EXCEPTIONS'], [], ['waka']),
9309+
'except_wasm': (['-O2', '-fwasm-exceptions', '-sWASM_LEGACY_EXCEPTIONS=0'],),
9310+
'except_wasm_legacy': (['-O2', '-fwasm-exceptions', '-sWASM_LEGACY_EXCEPTIONS'],),
93189311
# eval_ctors 1 can partially optimize, but runs into getenv() for locale
93199312
# code. mode 2 ignores those and fully optimizes out the ctors
9320-
'ctors1': (['-O2', '-sEVAL_CTORS'], [], ['waka']),
9321-
'ctors2': (['-O2', '-sEVAL_CTORS=2'], [], ['waka']),
9322-
'wasmfs': (['-O2', '-sWASMFS'], [], ['waka']),
9323-
'lto': (['-Oz', '-flto'], [], ['waka']),
9313+
'ctors1': (['-O2', '-sEVAL_CTORS'],),
9314+
'ctors2': (['-O2', '-sEVAL_CTORS=2'],),
9315+
'wasmfs': (['-O2', '-sWASMFS'],),
9316+
'lto': (['-Oz', '-flto'],),
93249317
})
9325-
def test_codesize_cxx(self, *args):
9318+
def test_codesize_cxx(self, args):
93269319
# do not check functions in this test as there are a lot of libc++ functions
93279320
# pulled in here, and small LLVM backend changes can affect their size and
93289321
# lead to different inlining decisions which add or remove a function
9329-
self.run_codesize_test('hello_libcxx.cpp', *args, check_funcs=False)
9322+
self.run_codesize_test('hello_libcxx.cpp', args, check_funcs=False)
93309323

93319324
@parameterized({
9332-
'O0': ([], [], ['waka']),
9333-
'O1': (['-O1'], [], ['waka']),
9334-
'O2': (['-O2'], [], ['waka']),
9335-
'O3': (['-O3'], [], []), # in -O3, -Os and -Oz we metadce
9336-
'Os': (['-Os'], [], []),
9337-
'Oz': (['-Oz'], [], []),
9325+
'O0': ([],),
9326+
'O1': (['-O1'],),
9327+
'O2': (['-O2'],),
9328+
'O3': (['-O3'],), # in -O3, -Os and -Oz we metadce
9329+
'Os': (['-Os'],),
9330+
'Oz': (['-Oz'],),
93389331
# finally, check what happens when we export nothing. wasm should be almost empty
9339-
'export_nothing': (['-Os', '-sEXPORTED_FUNCTIONS=[]'], [], []),
9332+
'export_nothing': (['-Os', '-sEXPORTED_FUNCTIONS=[]'],),
93409333
# we don't metadce with linkable code! other modules may want stuff
93419334
# TODO(sbc): Investivate why the number of exports is order of magnitude
93429335
# larger for wasm backend.
9343-
'dylink': (['-O3', '-sMAIN_MODULE=2'], [], []),
9336+
'dylink': (['-O3', '-sMAIN_MODULE=2'],),
93449337
# WasmFS should not be fully linked into a hello world program.
9345-
'wasmfs': (['-O3', '-sWASMFS'], [], []),
9346-
'single_file': (['-O3', '-sSINGLE_FILE'], [], []), # noqa
9338+
'wasmfs': (['-O3', '-sWASMFS'],),
9339+
'single_file': (['-O3', '-sSINGLE_FILE'],), # noqa
93479340
})
9348-
def test_codesize_hello(self, *args):
9349-
self.run_codesize_test('hello_world.c', *args)
9341+
def test_codesize_hello(self, args):
9342+
self.run_codesize_test('hello_world.c', args)
93509343

93519344
@parameterized({
9352-
'O3': ('mem.c', ['-O3'],
9353-
[], []), # noqa
9345+
'O3': ('mem.c', ['-O3']),
93549346
# argc/argv support code etc. is in the wasm
9355-
'O3_standalone': ('mem.c', ['-O3', '-sSTANDALONE_WASM'],
9356-
[], []), # noqa
9347+
'O3_standalone': ('mem.c', ['-O3', '-sSTANDALONE_WASM']),
93579348
# without argc/argv, no support code for them is emitted
9358-
'O3_standalone_narg': ('mem_no_argv.c', ['-O3', '-sSTANDALONE_WASM'],
9359-
[], []), # noqa
9349+
'O3_standalone_narg': ('mem_no_argv.c', ['-O3', '-sSTANDALONE_WASM']),
93609350
# without main, no support code for argc/argv is emitted either
9361-
'O3_standalone_lib': ('mem_no_main.c', ['-O3', '-sSTANDALONE_WASM', '--no-entry'],
9362-
[], []), # noqa
9351+
'O3_standalone_lib': ('mem_no_main.c', ['-O3', '-sSTANDALONE_WASM', '--no-entry']),
93639352
# Growth support code is in JS, no significant change in the wasm
9364-
'O3_grow': ('mem.c', ['-O3', '-sALLOW_MEMORY_GROWTH'],
9365-
[], []), # noqa
9353+
'O3_grow': ('mem.c', ['-O3', '-sALLOW_MEMORY_GROWTH']),
93669354
# Growth support code is in the wasm
9367-
'O3_grow_standalone': ('mem.c', ['-O3', '-sALLOW_MEMORY_GROWTH', '-sSTANDALONE_WASM'],
9368-
[], []), # noqa
9355+
'O3_grow_standalone': ('mem.c', ['-O3', '-sALLOW_MEMORY_GROWTH', '-sSTANDALONE_WASM']),
93699356
# without argc/argv, no support code for them is emitted, even with lto
93709357
'O3_standalone_narg_flto':
9371-
('mem_no_argv.c', ['-O3', '-sSTANDALONE_WASM', '-flto'],
9372-
[], []), # noqa
9358+
('mem_no_argv.c', ['-O3', '-sSTANDALONE_WASM', '-flto']), # noqa
93739359
})
9374-
def test_codesize_mem(self, filename, *args):
9375-
self.run_codesize_test(filename, *args)
9360+
def test_codesize_mem(self, filename, args):
9361+
self.run_codesize_test(filename, args)
93769362

93779363
@parameterized({
9378-
'O3': (['-O3'], [], []), # noqa
9364+
'O3': (['-O3'],),
93799365
# argc/argv support code etc. is in the wasm
9380-
'O3_standalone': (['-O3', '-sSTANDALONE_WASM'], [], []), # noqa
9366+
'O3_standalone': (['-O3', '-sSTANDALONE_WASM'],),
93819367
})
9382-
def test_codesize_libcxxabi_message(self, *args):
9383-
self.run_codesize_test('libcxxabi_message.cpp', *args)
9368+
def test_codesize_libcxxabi_message(self, args):
9369+
self.run_codesize_test('libcxxabi_message.cpp', args)
93849370

93859371
@parameterized({
9386-
'js_fs': (['-O3', '-sNO_WASMFS'], [], []), # noqa
9387-
'wasmfs': (['-O3', '-sWASMFS'], [], []), # noqa
9372+
'js_fs': (['-O3', '-sNO_WASMFS'],), # noqa
9373+
'wasmfs': (['-O3', '-sWASMFS'],), # noqa
93889374
})
9389-
def test_codesize_files(self, *args):
9390-
self.run_codesize_test('files.cpp', *args)
9375+
def test_codesize_files(self, args):
9376+
self.run_codesize_test('files.cpp', args)
93919377

93929378
def test_exported_runtime_methods_metadce(self):
93939379
exports = ['stackSave', 'stackRestore', 'stackAlloc', 'FS']

0 commit comments

Comments
 (0)