@@ -4912,7 +4912,12 @@ def test_warn_dylibs(self):
49124912 'O2': [['-O2']],
49134913 'O3': [['-O3']],
49144914 })
4915- def test_symbol_map(self, opts):
4915+ @parameterized({
4916+ '': [1],
4917+ 'wasm2js': [0],
4918+ 'wasm2js_2': [2],
4919+ })
4920+ def test_symbol_map(self, wasm, opts):
49164921 def get_symbols_lines(symbols_file):
49174922 self.assertTrue(os.path.isfile(symbols_file), "Symbols file %s isn't created" % symbols_file)
49184923 # check that the map is correct
@@ -4939,10 +4944,8 @@ def guess_symbols_file_type(symbols_file):
49394944 UNMINIFIED_HEAP8 = 'var HEAP8 = new '
49404945 UNMINIFIED_MIDDLE = 'function middle'
49414946
4942- for wasm in [0, 1, 2]:
4943- print(opts, wasm)
4944- self.clear()
4945- create_file('src.c', r'''
4947+ self.clear()
4948+ create_file('src.c', r'''
49464949#include <emscripten.h>
49474950
49484951EM_JS(int, run_js, (), {
@@ -4962,47 +4965,48 @@ def guess_symbols_file_type(symbols_file):
49624965EM_ASM({ _middle() });
49634966}
49644967''')
4965- cmd = [EMCC, 'src.c', '--emit-symbol-map'] + opts
4966- if wasm != 1:
4967- cmd.append(f'-sWASM={wasm}')
4968- self.run_process(cmd)
4968+ cmd = [EMCC, 'src.c', '--emit-symbol-map'] + opts
4969+ if wasm != 1:
4970+ cmd.append(f'-sWASM={wasm}')
4971+ self.run_process(cmd)
49694972
4970- minified_middle = get_minified_middle('a.out.js.symbols')
4971- self.assertNotEqual(minified_middle, None, "Missing minified 'middle' function")
4972- if wasm:
4973- # stack traces are standardized enough that we can easily check that the
4974- # minified name is actually in the output
4975- stack_trace_reference = 'wasm-function[%s]' % minified_middle
4976- out = self.run_js('a.out.js')
4977- self.assertContained(stack_trace_reference, out)
4978- # make sure there are no symbols in the wasm itself
4979- wat = self.get_wasm_text('a.out.wasm')
4980- for func_start in ('(func $middle', '(func $_middle'):
4981- self.assertNotContained(func_start, wat)
4982-
4983- # Ensure symbols file type according to `-sWASM=` mode
4984- if wasm == 0:
4985- self.assertEqual(guess_symbols_file_type('a.out.js.symbols'), 'js', 'Primary symbols file should store JS mappings')
4986- elif wasm == 1:
4987- self.assertEqual(guess_symbols_file_type('a.out.js.symbols'), 'wasm', 'Primary symbols file should store Wasm mappings')
4988- elif wasm == 2:
4989- # special case when both JS and Wasm targets are created
4990- minified_middle_2 = get_minified_middle('a.out.wasm.js.symbols')
4991- self.assertNotEqual(minified_middle_2, None, "Missing minified 'middle' function")
4992- self.assertEqual(guess_symbols_file_type('a.out.js.symbols'), 'wasm', 'Primary symbols file should store Wasm mappings')
4993- self.assertEqual(guess_symbols_file_type('a.out.wasm.js.symbols'), 'js', 'Secondary symbols file should store JS mappings')
4994-
4995- # check we don't keep unnecessary debug info with wasm2js when emitting
4996- # a symbol map
4997- if wasm == 0 and '-O' in str(opts):
4998- js = read_file('a.out.js')
4999- self.assertNotContained(UNMINIFIED_HEAP8, js)
5000- self.assertNotContained(UNMINIFIED_MIDDLE, js)
5001- # verify those patterns would exist with more debug info
5002- self.run_process(cmd + ['--profiling-funcs'])
5003- js = read_file('a.out.js')
5004- self.assertContained(UNMINIFIED_HEAP8, js)
5005- self.assertContained(UNMINIFIED_MIDDLE, js)
4973+ minified_middle = get_minified_middle('a.out.js.symbols')
4974+ self.assertNotEqual(minified_middle, None, "Missing minified 'middle' function")
4975+ if wasm:
4976+ # stack traces are standardized enough that we can easily check that the
4977+ # minified name is actually in the output
4978+ stack_trace_reference = 'wasm-function[%s]' % minified_middle
4979+ out = self.run_js('a.out.js')
4980+ self.assertContained(stack_trace_reference, out)
4981+ # make sure there are no symbols in the wasm itself
4982+ wat = self.get_wasm_text('a.out.wasm')
4983+ for func_start in ('(func $middle', '(func $_middle'):
4984+ self.assertNotContained(func_start, wat)
4985+
4986+ # Ensure symbols file type according to `-sWASM=` mode
4987+ if wasm == 0:
4988+ self.assertEqual(guess_symbols_file_type('a.out.js.symbols'), 'js', 'Primary symbols file should store JS mappings')
4989+ elif wasm == 1:
4990+ self.assertEqual(guess_symbols_file_type('a.out.js.symbols'), 'wasm', 'Primary symbols file should store Wasm mappings')
4991+ elif wasm == 2:
4992+ # special case when both JS and Wasm targets are created
4993+ minified_middle_2 = get_minified_middle('a.out.wasm.js.symbols')
4994+ self.assertNotEqual(minified_middle_2, None, "Missing minified 'middle' function")
4995+ self.assertEqual(guess_symbols_file_type('a.out.js.symbols'), 'wasm', 'Primary symbols file should store Wasm mappings')
4996+ self.assertEqual(guess_symbols_file_type('a.out.wasm.js.symbols'), 'js', 'Secondary symbols file should store JS mappings')
4997+ return
4998+
4999+ # check we don't keep unnecessary debug info with wasm2js when emitting
5000+ # a symbol map
5001+ if wasm == 0 and '-O' in str(opts):
5002+ js = read_file('a.out.js')
5003+ self.assertNotContained(UNMINIFIED_HEAP8, js)
5004+ self.assertNotContained(UNMINIFIED_MIDDLE, js)
5005+ # verify those patterns would exist with more debug info
5006+ self.run_process(cmd + ['--profiling-funcs'])
5007+ js = read_file('a.out.js')
5008+ self.assertContained(UNMINIFIED_HEAP8, js)
5009+ self.assertContained(UNMINIFIED_MIDDLE, js)
50065010
50075011 @parameterized({
50085012 '': [[]],
@@ -9148,6 +9152,18 @@ def test_single_file_shell(self):
91489152 def test_single_file_shell_sync_compile(self):
91499153 self.do_runf('hello_world.c', emcc_args=['-sSINGLE_FILE', '-sWASM_ASYNC_COMPILATION=0'])
91509154
9155+ def test_single_file_no_clobber_wasm(self):
9156+ create_file('hello_world.wasm', 'not wasm')
9157+ self.do_runf('hello_world.c', emcc_args=['-sSINGLE_FILE'])
9158+ self.assertExists('hello_world.js')
9159+ self.assertFileContents('hello_world.wasm', 'not wasm')
9160+
9161+ def test_wasm2js_no_clobber_wasm(self):
9162+ create_file('hello_world.wasm', 'not wasm')
9163+ self.do_runf('hello_world.c', emcc_args=['-sWASM=0'])
9164+ self.assertExists('hello_world.js')
9165+ self.assertFileContents('hello_world.wasm', 'not wasm')
9166+
91519167 def test_emar_M(self):
91529168 create_file('file1', ' ')
91539169 create_file('file2', ' ')
0 commit comments