Skip to content

Commit a9c7c80

Browse files
committed
Add more explicit testing for MAIN_MODULE exports. NFC
1 parent d65442e commit a9c7c80

File tree

4 files changed

+79
-29
lines changed

4 files changed

+79
-29
lines changed

tests/common.py

+16
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,22 @@ def assertTextDataContained(self, text1, text2):
743743
text2 = text2.replace('\r\n', '\n')
744744
return self.assertContained(text1, text2)
745745

746+
def assertFileContents(self, filename, contents):
747+
contents = contents.replace('\r', '')
748+
749+
if EMTEST_REBASELINE:
750+
with open(filename, 'w') as f:
751+
f.write(contents)
752+
return
753+
754+
if not os.path.exists(filename):
755+
self.fail('Test expectation file not found: ' + filename + '.\n' +
756+
'Run with EMTEST_REBASELINE to generate.')
757+
expected_content = read_file(filename)
758+
message = "Run with EMTEST_REBASELINE=1 to automatically update expectations"
759+
self.assertTextDataIdentical(expected_content, contents, message,
760+
filename, filename + '.new')
761+
746762
def assertContained(self, values, string, additional_info=''):
747763
if type(values) not in [list, tuple]:
748764
values = [values]

tests/core/test_dlfcn_self.exports

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
__THREW__
2+
___environ
3+
__c_dot_utf8
4+
__c_dot_utf8_locale
5+
__c_locale
6+
__data_end
7+
__dso_handle
8+
__env_map
9+
__environ
10+
__fsmu8
11+
__hwcap
12+
__libc
13+
__optpos
14+
__optreset
15+
__pio2_hi
16+
__pio2_lo
17+
__progname
18+
__progname_full
19+
__seed48
20+
__sig_actions
21+
__sig_pending
22+
__signgam
23+
__stderr_used
24+
__stdin_used
25+
__stdout_used
26+
__sysinfo
27+
__threwValue
28+
_environ
29+
_ns_flagdata
30+
aT
31+
atanhi
32+
atanlo
33+
daylight
34+
environ
35+
global
36+
h_errno
37+
in6addr_any
38+
in6addr_loopback
39+
optarg
40+
opterr
41+
optind
42+
optopt
43+
optreset
44+
program_invocation_name
45+
program_invocation_short_name
46+
signgam
47+
stderr
48+
stdin
49+
stdout
50+
timezone
51+
tzname

tests/test_core.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -1749,17 +1749,16 @@ def test_set_align(self):
17491749

17501750
self.do_core_test('test_set_align.c')
17511751

1752+
@no_asan('EXPORT_ALL is not compatible with Asan')
17521753
def test_emscripten_api(self):
17531754
self.set_setting('EXPORTED_FUNCTIONS', ['_main', '_save_me_aimee'])
17541755
self.do_core_test('test_emscripten_api.cpp')
17551756

1756-
if '-fsanitize=address' not in self.emcc_args:
1757-
# test EXPORT_ALL (this is not compatible with asan, which doesn't
1758-
# support dynamic linking at all or the LINKING flag)
1759-
self.set_setting('EXPORTED_FUNCTIONS', [])
1760-
self.set_setting('EXPORT_ALL')
1761-
self.set_setting('LINKABLE')
1762-
self.do_core_test('test_emscripten_api.cpp')
1757+
# test EXPORT_ALL
1758+
self.set_setting('EXPORTED_FUNCTIONS', [])
1759+
self.set_setting('EXPORT_ALL')
1760+
self.set_setting('LINKABLE')
1761+
self.do_core_test('test_emscripten_api.cpp')
17631762

17641763
def test_emscripten_run_script_string_int(self):
17651764
src = r'''
@@ -3073,18 +3072,18 @@ def test_dlfcn_self(self):
30733072
self.set_setting('MAIN_MODULE')
30743073
self.set_setting('EXPORT_ALL')
30753074

3076-
def get_data_export_count(wasm):
3075+
def get_data_exports(wasm):
30773076
wat = self.get_wasm_text(wasm)
30783077
lines = wat.splitlines()
30793078
exports = [l for l in lines if l.strip().startswith('(export ')]
30803079
data_exports = [l for l in exports if '(global ' in l]
3081-
return len(data_exports)
3080+
data_exports = [d.split()[1].strip('"') for d in data_exports]
3081+
return data_exports
30823082

30833083
self.do_core_test('test_dlfcn_self.c')
3084-
export_count = get_data_export_count('test_dlfcn_self.wasm')
3085-
# ensure there aren't too many globals; we don't want unnamed_addr
3086-
self.assertGreater(export_count, 20)
3087-
self.assertLess(export_count, 56)
3084+
data_exports = get_data_exports('test_dlfcn_self.wasm')
3085+
data_exports = '\n'.join(sorted(data_exports)) + '\n'
3086+
self.assertFileContents(test_file('core/test_dlfcn_self.exports'), data_exports)
30883087

30893088
@needs_dylink
30903089
def test_dlfcn_unique_sig(self):

tests/test_other.py

-16
Original file line numberDiff line numberDiff line change
@@ -7090,22 +7090,6 @@ def build(args=[]):
70907090
# adding --metrics should not affect code size
70917091
self.assertEqual(base_size, os.path.getsize('a.out.wasm'))
70927092

7093-
def assertFileContents(self, filename, contents):
7094-
contents = contents.replace('\r', '')
7095-
7096-
if common.EMTEST_REBASELINE:
7097-
with open(filename, 'w') as f:
7098-
f.write(contents)
7099-
return
7100-
7101-
if not os.path.exists(filename):
7102-
self.fail('Test expectation file not found: ' + filename + '.\n' +
7103-
'Run with EMTEST_REBASELINE to generate.')
7104-
expected_content = read_file(filename)
7105-
message = "Run with EMTEST_REBASELINE=1 to automatically update expectations"
7106-
self.assertTextDataIdentical(expected_content, contents, message,
7107-
filename, filename + '.new')
7108-
71097093
def run_metadce_test(self, filename, args, expected_exists, expected_not_exists, check_size=True,
71107094
check_sent=True, check_imports=True, check_exports=True, check_funcs=True):
71117095
size_slack = 0.05

0 commit comments

Comments
 (0)