Skip to content

Commit 06aff8b

Browse files
committed
LSan is just a link time thing, no need to optimize source in test
1 parent 07b1574 commit 06aff8b

File tree

4 files changed

+47
-34
lines changed

4 files changed

+47
-34
lines changed
File renamed without changes.
File renamed without changes.

tests/test_core.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7737,40 +7737,6 @@ def modify_env(filename):
77377737
self.do_run(open(path_from_root('tests', 'core', 'test_ubsan_full_null_ref.cpp')).read(),
77387738
post_build=modify_env, assert_all=True, expected_output=expected_output)
77397739

7740-
@no_fastcomp('lsan not supported on fastcomp')
7741-
def test_lsan_leaks(self):
7742-
self.emcc_args += ['-fsanitize=leak']
7743-
self.set_setting('ALLOW_MEMORY_GROWTH', 1)
7744-
self.do_run(open(path_from_root('tests', 'core', 'test_lsan_leaks.c')).read(),
7745-
assert_all=True, check_for_error=False, expected_output=[
7746-
'Direct leak of 2048 byte(s) in 1 object(s) allocated from',
7747-
'Direct leak of 1337 byte(s) in 1 object(s) allocated from',
7748-
'Direct leak of 42 byte(s) in 1 object(s) allocated from',
7749-
])
7750-
7751-
@no_fastcomp('lsan not supported on fastcomp')
7752-
def test_lsan_stack_trace(self):
7753-
self.emcc_args += ['-fsanitize=leak', '-g4']
7754-
self.set_setting('ALLOW_MEMORY_GROWTH', 1)
7755-
self.do_run(open(path_from_root('tests', 'core', 'test_lsan_leaks.c')).read(),
7756-
assert_all=True, check_for_error=False, expected_output=[
7757-
'Direct leak of 2048 byte(s) in 1 object(s) allocated from',
7758-
'Direct leak of 1337 byte(s) in 1 object(s) allocated from',
7759-
'Direct leak of 42 byte(s) in 1 object(s) allocated from',
7760-
'in main',
7761-
'/src.cpp:6:21',
7762-
'/src.cpp:10:16',
7763-
'/src.cpp:12:3',
7764-
'/src.cpp:13:3',
7765-
])
7766-
7767-
@no_fastcomp('lsan not supported on fastcomp')
7768-
def test_lsan_no_leak(self):
7769-
self.emcc_args += ['-fsanitize=leak']
7770-
self.set_setting('ALLOW_MEMORY_GROWTH', 1)
7771-
self.do_run(open(path_from_root('tests', 'core', 'test_lsan_no_leak.c')).read(),
7772-
expected_output=[''])
7773-
77747740

77757741
# Generate tests for everything
77767742
def make_run(name, emcc_args, settings=None, env=None):

tests/test_other.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# noqa: E241
88

99
from __future__ import print_function
10+
from functools import wraps
1011
import difflib
1112
import filecmp
1213
import glob
@@ -64,6 +65,7 @@ def uses_canonical_tmp(func):
6465
This decorator takes care of cleaning the directory after the
6566
test to satisfy the leak detector.
6667
"""
68+
@wraps(func)
6769
def decorated(self):
6870
# Before running the test completely remove the canonical_tmp
6971
if os.path.exists(self.canonical_temp_dir):
@@ -134,6 +136,19 @@ def do_other_test(self, dirname, emcc_args=[], run_args=[]):
134136
seen = run_js('a.out.js', args=run_args, stderr=PIPE, full_output=True) + '\n'
135137
self.assertContained(expected, seen)
136138

139+
def do_smart_test(self, source, literals=[], regexes=[], emcc_args=[], run_args=[], assert_returncode=0):
140+
shutil.copyfile(source, 'test.cpp')
141+
run_process([PYTHON, EMCC, 'test.cpp'] + emcc_args)
142+
seen = run_js('a.out.js', args=run_args, stderr=PIPE, full_output=True,
143+
assert_returncode=assert_returncode) + '\n'
144+
145+
for literal in literals:
146+
self.assertContained([literal], seen)
147+
148+
for regex in regexes:
149+
if not re.search(regex, seen):
150+
self.fail('Expected regex "%s" to match on:\n%s' % (regex, seen))
151+
137152
def expect_fail(self, cmd, **args):
138153
"""Run a subprocess and assert that it returns non-zero.
139154
@@ -9233,3 +9248,35 @@ def test(code):
92339248
assert lf - 900 <= f <= lf - 500
92349249
# both is a little bigger still
92359250
assert both - 100 <= lf <= both - 50
9251+
9252+
@no_fastcomp('lsan not supported on fastcomp')
9253+
def test_lsan_leaks(self):
9254+
self.do_smart_test(path_from_root('tests', 'other', 'test_lsan_leaks.c'),
9255+
emcc_args=['-fsanitize=leak', '-s', 'ALLOW_MEMORY_GROWTH=1'],
9256+
assert_returncode=None, literals=[
9257+
'Direct leak of 2048 byte(s) in 1 object(s) allocated from',
9258+
'Direct leak of 1337 byte(s) in 1 object(s) allocated from',
9259+
'Direct leak of 42 byte(s) in 1 object(s) allocated from',
9260+
])
9261+
9262+
@no_fastcomp('lsan not supported on fastcomp')
9263+
def test_lsan_stack_trace(self):
9264+
self.do_smart_test(path_from_root('tests', 'other', 'test_lsan_leaks.c'),
9265+
emcc_args=['-fsanitize=leak', '-s', 'ALLOW_MEMORY_GROWTH=1', '-g4'],
9266+
assert_returncode=None, literals=[
9267+
'Direct leak of 2048 byte(s) in 1 object(s) allocated from',
9268+
'Direct leak of 1337 byte(s) in 1 object(s) allocated from',
9269+
'Direct leak of 42 byte(s) in 1 object(s) allocated from',
9270+
], regexes=[
9271+
r'(?m)in malloc.*wasm-function',
9272+
r'(?m)in f\(\) /.*/test\.cpp:6:21$',
9273+
r'(?m)in main /.*/test\.cpp:10:16$',
9274+
r'(?m)in main /.*/test\.cpp:12:3$',
9275+
r'(?m)in main /.*/test\.cpp:13:3$',
9276+
])
9277+
9278+
@no_fastcomp('lsan not supported on fastcomp')
9279+
def test_lsan_no_leak(self):
9280+
self.do_smart_test(path_from_root('tests', 'other', 'test_lsan_no_leak.c'),
9281+
emcc_args=['-fsanitize=leak', '-s', 'ALLOW_MEMORY_GROWTH=1'],
9282+
regexes=[r'^\s*$'])

0 commit comments

Comments
 (0)