From 56b3223a666404407f362146069ed713adf33928 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 3 Jan 2024 15:50:51 -0800 Subject: [PATCH] Prefer C over C++ for simple compiler tests. NFC --- test/test_other.py | 86 +++++++++++----------- tools/maint/check_for_unused_test_files.py | 5 +- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index b8be932a6619..ddab3a98d3f0 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2372,7 +2372,7 @@ def test_link_memcpy(self): self.assertNotContained('warning: library.js memcpy should not be running, it is only for testing!', output) def test_undefined_exported_function(self): - cmd = [EMXX, test_file('hello_world.cpp')] + cmd = [EMCC, test_file('hello_world.c')] self.run_process(cmd) # adding a missing symbol to EXPORTED_FUNCTIONS should cause failure @@ -5348,19 +5348,19 @@ def test(args): def test_dashE_respect_dashO(self): # issue #3365 - with_dash_o = self.run_process([EMXX, test_file('hello_world.cpp'), '-E', '-o', 'ignored.js'], stdout=PIPE, stderr=PIPE).stdout - without_dash_o = self.run_process([EMXX, test_file('hello_world.cpp'), '-E'], stdout=PIPE, stderr=PIPE).stdout + with_dash_o = self.run_process([EMCC, test_file('hello_world.c'), '-E', '-o', 'ignored.js'], stdout=PIPE, stderr=PIPE).stdout + without_dash_o = self.run_process([EMCC, test_file('hello_world.c'), '-E'], stdout=PIPE, stderr=PIPE).stdout self.assertEqual(len(with_dash_o), 0) self.assertNotEqual(len(without_dash_o), 0) def test_dashM(self): - out = self.run_process([EMXX, test_file('hello_world.cpp'), '-M'], stdout=PIPE).stdout + out = self.run_process([EMCC, test_file('hello_world.c'), '-M'], stdout=PIPE).stdout self.assertContained('hello_world.o:', out) # Verify output is just a dependency rule instead of bitcode or js def test_dashM_respect_dashO(self): # issue #3365 - with_dash_o = self.run_process([EMXX, test_file('hello_world.cpp'), '-M', '-o', 'ignored.js'], stdout=PIPE).stdout - without_dash_o = self.run_process([EMXX, test_file('hello_world.cpp'), '-M'], stdout=PIPE).stdout + with_dash_o = self.run_process([EMCC, test_file('hello_world.c'), '-M', '-o', 'ignored.js'], stdout=PIPE).stdout + without_dash_o = self.run_process([EMCC, test_file('hello_world.c'), '-M'], stdout=PIPE).stdout self.assertEqual(len(with_dash_o), 0) self.assertNotEqual(len(without_dash_o), 0) @@ -7598,42 +7598,42 @@ def test_dash_s_link_flag(self): # its used to set a settings based on looking at the argument that follows. # Test the case when -s is the last flag - self.run_process([EMXX, test_file('hello_world.cpp'), '-s']) + self.run_process([EMCC, test_file('hello_world.c'), '-s']) self.assertContained('hello, world!', self.run_js('a.out.js')) # Test the case when the following flag is all uppercase but starts with a `-` - self.run_process([EMXX, test_file('hello_world.cpp'), '-s', '-DFOO']) + self.run_process([EMCC, test_file('hello_world.c'), '-s', '-DFOO']) self.assertContained('hello, world!', self.run_js('a.out.js')) # Test that case when the following flag is not all uppercase - self.run_process([EMXX, '-s', test_file('hello_world.cpp')]) + self.run_process([EMCC, '-s', test_file('hello_world.c')]) self.assertContained('hello, world!', self.run_js('a.out.js')) def test_dash_s_response_file_string(self): create_file('response_file.txt', 'MyModule\n') create_file('response_file.json', '"MyModule"\n') - self.run_process([EMXX, test_file('hello_world.cpp'), '-sEXPORT_NAME=@response_file.txt']) - self.run_process([EMXX, test_file('hello_world.cpp'), '-sEXPORT_NAME=@response_file.json']) + self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_NAME=@response_file.txt']) + self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_NAME=@response_file.json']) def test_dash_s_response_file_list(self): create_file('response_file.txt', '_main\n_malloc\n') create_file('response_file.json', '["_main", "_malloc"]\n') - self.run_process([EMXX, test_file('hello_world.cpp'), '-sEXPORTED_FUNCTIONS=@response_file.txt']) - self.run_process([EMXX, test_file('hello_world.cpp'), '-sEXPORTED_FUNCTIONS=@response_file.json']) + self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=@response_file.txt']) + self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=@response_file.json']) def test_dash_s_response_file_misssing(self): - err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-sEXPORTED_FUNCTIONS=@foo']) + err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=@foo']) self.assertContained('error: foo: file not found parsing argument: EXPORTED_FUNCTIONS=@foo', err) def test_dash_s_unclosed_quote(self): # Unclosed quote - err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-s', "TEST_KEY='MISSING_QUOTE"]) + err = self.expect_fail([EMCC, test_file('hello_world.c'), '-s', "TEST_KEY='MISSING_QUOTE"]) self.assertNotContained('AssertionError', err) # Do not mention that it is an assertion error self.assertContained('unclosed opened quoted string. expected final character to be "\'"', err) def test_dash_s_single_quote(self): # Only one quote - err = self.expect_fail([EMXX, test_file('hello_world.cpp'), "-sTEST_KEY='"]) + err = self.expect_fail([EMCC, test_file('hello_world.c'), "-sTEST_KEY='"]) self.assertNotContained('AssertionError', err) # Do not mention that it is an assertion error self.assertContained('unclosed opened quoted string.', err) @@ -7669,7 +7669,7 @@ def test_dash_s_typo(self): def test_dash_s_with_space(self): self.run_process([EMCC, test_file('hello_world.c'), '-s', 'EXPORT_ALL']) - err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-s', 'EXPORTED_FUNCTIONS=foo']) + err = self.expect_fail([EMCC, test_file('hello_world.c'), '-s', 'EXPORTED_FUNCTIONS=foo']) self.assertContained('error: undefined exported symbol: "foo"', err) def test_dash_s_hex(self): @@ -8007,13 +8007,13 @@ def test_binaryen_warn_mem(self): # if user changes INITIAL_MEMORY at runtime, the wasm module may not accept the memory import if # it is too big/small create_file('pre.js', 'Module.INITIAL_MEMORY = 50 * 1024 * 1024') - self.run_process([EMXX, test_file('hello_world.cpp'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY']) + self.run_process([EMCC, test_file('hello_world.c'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY']) out = self.run_js('a.out.js', assert_returncode=NON_ZERO) self.assertContained('LinkError', out) self.assertContained("memory import 2 has a larger maximum size 800 than the module's declared maximum", out) self.assertNotContained('hello, world!', out) # and with memory growth, all should be good - self.run_process([EMXX, test_file('hello_world.cpp'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sALLOW_MEMORY_GROWTH', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY']) + self.run_process([EMCC, test_file('hello_world.c'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sALLOW_MEMORY_GROWTH', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY']) self.assertContained('hello, world!', self.run_js('a.out.js')) def test_memory_size(self): @@ -8113,7 +8113,7 @@ def test_binaryen_debug(self): ]: print(args, expect_emit_text) delete_file('a.out.wat') - cmd = [EMXX, test_file('hello_world.cpp')] + args + cmd = [EMCC, test_file('hello_world.c')] + args print(' '.join(cmd)) self.run_process(cmd) js = read_file('a.out.js') @@ -8141,7 +8141,7 @@ def test_binaryen_ignore_implicit_traps(self): def test_binaryen_passes_extra(self): def build(args): - return self.run_process([EMXX, test_file('hello_world.cpp'), '-O3'] + args, stdout=PIPE).stdout + return self.run_process([EMCC, test_file('hello_world.c'), '-O3'] + args, stdout=PIPE).stdout build([]) base_size = os.path.getsize('a.out.wasm') @@ -8396,7 +8396,7 @@ def test_exported_runtime_methods_metadce(self, use_legacy_name): setting_name = 'EXPORTED_RUNTIME_METHODS' if use_legacy_name: setting_name = 'EXTRA_EXPORTED_RUNTIME_METHODS' - err = self.run_process([EMXX, test_file('hello_world.cpp'), '-Os', '-s%s=%s' % (setting_name, ','.join(exports))], stderr=PIPE).stderr + err = self.run_process([EMCC, test_file('hello_world.c'), '-Os', '-s%s=%s' % (setting_name, ','.join(exports))], stderr=PIPE).stderr if use_legacy_name: self.assertContained('warning: EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead [-Wdeprecated]', err) js = read_file('a.out.js') @@ -8517,7 +8517,7 @@ def test_wasm_target_and_STANDALONE_WASM(self): print(opts, potentially_expect_minified_exports_and_imports, target, ' => ', expect_minified_exports_and_imports, standalone) self.clear() - self.run_process([EMXX, test_file('hello_world.cpp'), '-o', target] + opts) + self.run_process([EMCC, test_file('hello_world.c'), '-o', target] + opts) self.assertExists('out.wasm') if target.endswith('.wasm'): # only wasm requested @@ -8641,7 +8641,7 @@ def test_lto_flags(self): (['-sWASM_OBJECT_FILES=0'], True), (['-sWASM_OBJECT_FILES'], False), ]: - self.run_process([EMXX, test_file('hello_world.cpp')] + flags + ['-c', '-o', 'a.o']) + self.run_process([EMCC, test_file('hello_world.c')] + flags + ['-c', '-o', 'a.o']) seen_bitcode = building.is_bitcode('a.o') self.assertEqual(expect_bitcode, seen_bitcode, 'must emit LTO-capable bitcode when flags indicate so (%s)' % str(flags)) @@ -8658,7 +8658,7 @@ def test_wasm_nope(self): print(opts) # check we show a good error message if there is no wasm support create_file('pre.js', 'WebAssembly = undefined;\n') - self.run_process([EMXX, test_file('hello_world.cpp'), '--pre-js', 'pre.js'] + opts) + self.run_process([EMCC, test_file('hello_world.c'), '--pre-js', 'pre.js'] + opts) out = self.run_js('a.out.js', assert_returncode=NON_ZERO) self.assertContained('no native wasm support detected', out) @@ -8849,7 +8849,7 @@ def test_jsrun(self): def test_error_on_missing_libraries(self): # -llsomenonexistingfile is an error by default - err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-lsomenonexistingfile']) + err = self.expect_fail([EMCC, test_file('hello_world.c'), '-lsomenonexistingfile']) self.assertContained('wasm-ld: error: unable to find library -lsomenonexistingfile', err) # Tests that if user accidentally attempts to link native object code, we show an error @@ -11477,32 +11477,32 @@ def test_missing_stdlibs(self): # Certain standard libraries are expected to be useable via -l flags but # don't actually exist in our standard library path. Make sure we don't # error out when linking with these flags. - self.run_process([EMXX, test_file('hello_world.cpp'), '-lm', '-ldl', '-lrt', '-lpthread']) + self.run_process([EMCC, test_file('hello_world.c'), '-lm', '-ldl', '-lrt', '-lpthread']) def test_supported_linker_flags(self): - out = self.run_process([EMXX, test_file('hello_world.cpp'), '-Wl,-rpath=foo'], stderr=PIPE).stderr + out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-rpath=foo'], stderr=PIPE).stderr self.assertContained('warning: ignoring unsupported linker flag: `-rpath=foo`', out) - out = self.run_process([EMXX, test_file('hello_world.cpp'), '-Wl,-rpath-link,foo'], stderr=PIPE).stderr + out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-rpath-link,foo'], stderr=PIPE).stderr self.assertContained('warning: ignoring unsupported linker flag: `-rpath-link`', out) - out = self.run_process([EMXX, test_file('hello_world.cpp'), + out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,--no-check-features,-mllvm,--data-sections'], stderr=PIPE).stderr self.assertNotContained('warning: ignoring unsupported linker flag', out) - out = self.run_process([EMXX, test_file('hello_world.cpp'), '-Wl,-allow-shlib-undefined'], stderr=PIPE).stderr + out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-allow-shlib-undefined'], stderr=PIPE).stderr self.assertContained('warning: ignoring unsupported linker flag: `-allow-shlib-undefined`', out) - out = self.run_process([EMXX, test_file('hello_world.cpp'), '-Wl,--allow-shlib-undefined'], stderr=PIPE).stderr + out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,--allow-shlib-undefined'], stderr=PIPE).stderr self.assertContained('warning: ignoring unsupported linker flag: `--allow-shlib-undefined`', out) - out = self.run_process([EMXX, test_file('hello_world.cpp'), '-Wl,-version-script,foo'], stderr=PIPE).stderr + out = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-version-script,foo'], stderr=PIPE).stderr self.assertContained('warning: ignoring unsupported linker flag: `-version-script`', out) def test_supported_linker_flag_skip_next(self): # Regression test for a bug where skipping an unsupported linker flag # could skip the next unrelated linker flag. - err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-Wl,-rpath=foo', '-lbar']) + err = self.expect_fail([EMCC, test_file('hello_world.c'), '-Wl,-rpath=foo', '-lbar']) self.assertContained('error: unable to find library -lbar', err) def test_linker_flags_pass_through(self): @@ -11519,11 +11519,11 @@ def test_linker_flags_pass_through(self): self.assertContained('wasm-ld: warning: unknown -z value: foo', err) def test_linker_flags_unused(self): - err = self.run_process([EMXX, test_file('hello_world.cpp'), '-c', '-lbar'], stderr=PIPE).stderr + err = self.run_process([EMCC, test_file('hello_world.c'), '-c', '-lbar'], stderr=PIPE).stderr self.assertContained("warning: -lbar: 'linker' input unused [-Wunused-command-line-argument]", err) def test_linker_input_unused(self): - self.run_process([EMXX, '-c', test_file('hello_world.cpp')]) + self.run_process([EMCC, '-c', test_file('hello_world.c')]) err = self.run_process([EMCC, 'hello_world.o', '-c', '-o', 'out.o'], stderr=PIPE).stderr self.assertContained("clang: warning: hello_world.o: 'linker' input unused [-Wunused-command-line-argument]", err) # In this case the compiler does not produce any output file. @@ -11531,7 +11531,7 @@ def test_linker_input_unused(self): def test_non_wasm_without_wasm_in_vm(self): # Test that our non-wasm output does not depend on wasm support in the vm. - self.run_process([EMXX, test_file('hello_world.cpp'), '-sWASM=0', '-sENVIRONMENT=node,shell']) + self.run_process([EMCC, test_file('hello_world.c'), '-sWASM=0', '-sENVIRONMENT=node,shell']) js = read_file('a.out.js') create_file('a.out.js', 'var WebAssembly = null;\n' + js) for engine in config.JS_ENGINES: @@ -11539,7 +11539,7 @@ def test_non_wasm_without_wasm_in_vm(self): def test_empty_output_extension(self): # Default to JS output when no extension is present - self.run_process([EMXX, test_file('hello_world.cpp'), '-Werror', '-o', 'hello']) + self.run_process([EMCC, test_file('hello_world.c'), '-Werror', '-o', 'hello']) self.assertContained('hello, world!', self.run_js('hello')) def test_backwards_deps_in_archive(self): @@ -11652,11 +11652,11 @@ def test_stdin_compile_and_link(self): def test_stdout_link(self): # linking to stdout `-` doesn't work, we have no way to pass such an output filename # through post-link tools such as binaryen. - err = self.expect_fail([EMXX, '-o', '-', test_file('hello_world.cpp')]) + err = self.expect_fail([EMCC, '-o', '-', test_file('hello_world.c')]) self.assertContained('invalid output filename: `-`', err) self.assertNotExists('-') - err = self.expect_fail([EMXX, '-o', '-foo', test_file('hello_world.cpp')]) + err = self.expect_fail([EMCC, '-o', '-foo', test_file('hello_world.c')]) self.assertContained('invalid output filename: `-foo`', err) self.assertNotExists('-foo') @@ -11685,7 +11685,7 @@ def ok(args, filename='hello_world.cpp', expected='hello, world!'): def fail(args, details): print('fail', args, details) args += ['-sERROR_ON_WASM_CHANGES_AFTER_LINK'] - err = self.expect_fail([EMXX, test_file('hello_world.cpp')] + args) + err = self.expect_fail([EMCC, test_file('hello_world.c')] + args) self.assertContained('changes to the wasm are required after link, but disallowed by ERROR_ON_WASM_CHANGES_AFTER_LINK', err) self.assertContained(details, err) @@ -11699,7 +11699,7 @@ def fail(args, details): @crossplatform def test_output_to_nowhere(self): - self.run_process([EMXX, test_file('hello_world.cpp'), '-o', os.devnull, '-c']) + self.run_process([EMCC, test_file('hello_world.c'), '-o', os.devnull, '-c']) # Test that passing -sMIN_X_VERSION=-1 on the command line will result in browser X being not supported at all. # I.e. -sMIN_X_VERSION=-1 is equal to -sMIN_X_VERSION=Infinity @@ -11739,7 +11739,7 @@ def test(args, expect_fail): # legacy browsers may lack Promise, which wasm2js depends on. see what # happens when we kill the global Promise function. create_file('extern-post.js', extern_post_js) - self.run_process([EMXX, test_file('hello_world.cpp')] + constant_args + args + ['--extern-post-js', 'extern-post.js']) + self.run_process([EMCC, test_file('hello_world.c')] + constant_args + args + ['--extern-post-js', 'extern-post.js']) js = read_file('a.out.js') create_file('a.out.js', 'Promise = undefined;\n' + js) return self.run_js('a.out.js', assert_returncode=NON_ZERO if expect_fail else 0) diff --git a/tools/maint/check_for_unused_test_files.py b/tools/maint/check_for_unused_test_files.py index b1017d597677..a0668998d2ba 100755 --- a/tools/maint/check_for_unused_test_files.py +++ b/tools/maint/check_for_unused_test_files.py @@ -11,7 +11,7 @@ script_dir = os.path.dirname(os.path.abspath(__file__)) root_dir = os.path.dirname(os.path.dirname(script_dir)) -test_dir = os.path.join(root_dir, 'tests') +test_dir = os.path.join(root_dir, 'test') ignore_dirs = { 'third_party', 'metadce', @@ -26,6 +26,7 @@ } ignore_root_patterns = ['runner.*', 'test_*.py'] ignore_root_files = { + 'check_clean.py', 'jsrun.py', 'clang_native.py', 'common.py', @@ -97,7 +98,7 @@ def main(args): check_file(test_dir, arg) return 0 - for (dirpath, dirnames, filenames) in os.walk(test_dir): + for dirpath, dirnames, filenames in os.walk(test_dir): if os.path.basename(dirpath) in ignore_dirs: dirnames.clear() filenames.clear()