Skip to content

Commit c45433c

Browse files
kripkenjuj
authored andcommitted
Ignore leaks in canonical temp and test dirs (#7971)
* fix regression from 50d1dc2 * temp * fix logging * fix python3 logging * remove redundant logging, and test updates
1 parent b9bdb67 commit c45433c

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

tests/test_other.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ def decorated(self):
6868
# Before running the test completely remove the canonical_tmp
6969
if os.path.exists(self.canonical_temp_dir):
7070
shutil.rmtree(self.canonical_temp_dir)
71-
func(self)
72-
# Make sure the test isn't lying about the fact that it uses
73-
# canonical_tmp
74-
self.assertTrue(os.path.exists(self.canonical_temp_dir))
75-
shutil.rmtree(self.canonical_temp_dir)
71+
try:
72+
func(self)
73+
finally:
74+
# Make sure the test isn't lying about the fact that it uses
75+
# canonical_tmp
76+
self.assertTrue(os.path.exists(self.canonical_temp_dir))
77+
# Remove the temp dir in a try-finally, as otherwise if the
78+
# test fails we would not clean it up, and if leak detection
79+
# is set we will show that error instead of the actual one.
80+
shutil.rmtree(self.canonical_temp_dir)
7681

7782
return decorated
7883

@@ -2338,7 +2343,7 @@ def test_debuginfo(self):
23382343
else:
23392344
self.assertNotIn(' -g ', finalize)
23402345
else:
2341-
opts = '\n'.join([l for l in lines if 'LLVM opts:' in l])
2346+
opts = '\n'.join([l for l in lines if os.path.sep + 'opt' in l])
23422347
if expect_debug:
23432348
self.assertNotIn('strip-debug', opts)
23442349
else:
@@ -3551,11 +3556,11 @@ def test_fs_after_main(self):
35513556
def test_os_oz(self):
35523557
with env_modify({'EMCC_DEBUG': '1'}):
35533558
for args, expect in [
3554-
(['-O1'], 'LLVM opts: -O1'),
3555-
(['-O2'], 'LLVM opts: -O3'),
3556-
(['-Os'], 'LLVM opts: -Os'),
3557-
(['-Oz'], 'LLVM opts: -Oz'),
3558-
(['-O3'], 'LLVM opts: -O3'),
3559+
(['-O1'], '-O1'),
3560+
(['-O2'], '-O3'),
3561+
(['-Os'], '-Os'),
3562+
(['-Oz'], '-Oz'),
3563+
(['-O3'], '-O3'),
35593564
]:
35603565
print(args, expect)
35613566
err = run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp')] + args, stdout=PIPE, stderr=PIPE).stderr
@@ -5871,7 +5876,8 @@ def test(args, llvm_opts=None):
58715876

58725877
if args:
58735878
assert err.count(VECTORIZE) == 2, err # specified twice, once per file
5874-
assert err.count('emcc: LLVM opts: ' + llvm_opts) == 2, err # corresponding to exactly once per invocation of optimizer
5879+
# corresponding to exactly once per invocation of optimizer
5880+
assert err.count(os.path.sep + 'opt') == 2, err
58755881
else:
58765882
assert err.count(VECTORIZE) == 0, err # no optimizations
58775883

tools/shared.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ def check_returncode(self):
153153
def run_process(cmd, check=True, input=None, universal_newlines=True, *args, **kw):
154154
kw.setdefault('universal_newlines', True)
155155

156+
debug_text = '%sexecuted %s' % ('successfully ' if check else '', ' '.join(cmd))
157+
156158
if hasattr(subprocess, "run"):
157-
return subprocess.run(cmd, check=check, input=input, *args, **kw)
159+
ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
160+
logger.debug(debug_text)
161+
return ret
158162

159163
# Python 2 compatibility: Introduce Python 3 subprocess.run-like behavior
160164
if input is not None:
@@ -164,9 +168,7 @@ def run_process(cmd, check=True, input=None, universal_newlines=True, *args, **k
164168
result = Py2CompletedProcess(cmd, proc.returncode, stdout, stderr)
165169
if check:
166170
result.check_returncode()
167-
logger.debug('Successfully executed %s' % ' '.join(cmd))
168-
else:
169-
logger.debug('Executed %s' % ' '.join(cmd))
171+
logger.debug(debug_text)
170172
return result
171173

172174

@@ -2127,7 +2129,6 @@ def llvm_opt(filename, opts, out=None):
21272129
else:
21282130
opts += ['-force-vector-width=4']
21292131

2130-
logger.debug('emcc: LLVM opts: ' + ' '.join(opts) + ' [num inputs: ' + str(len(inputs)) + ']')
21312132
target = out or (filename + '.opt.bc')
21322133
try:
21332134
run_process([LLVM_OPT] + inputs + opts + ['-o', target], stdout=PIPE)

0 commit comments

Comments
 (0)