Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ def decorated(self):
# Before running the test completely remove the canonical_tmp
if os.path.exists(self.canonical_temp_dir):
shutil.rmtree(self.canonical_temp_dir)
func(self)
# Make sure the test isn't lying about the fact that it uses
# canonical_tmp
self.assertTrue(os.path.exists(self.canonical_temp_dir))
shutil.rmtree(self.canonical_temp_dir)
try:
func(self)
finally:
# Make sure the test isn't lying about the fact that it uses
# canonical_tmp
self.assertTrue(os.path.exists(self.canonical_temp_dir))
# Remove the temp dir in a try-finally, as otherwise if the
# test fails we would not clean it up, and if leak detection
# is set we will show that error instead of the actual one.
shutil.rmtree(self.canonical_temp_dir)

return decorated

Expand Down Expand Up @@ -2338,7 +2343,7 @@ def test_debuginfo(self):
else:
self.assertNotIn(' -g ', finalize)
else:
opts = '\n'.join([l for l in lines if 'LLVM opts:' in l])
opts = '\n'.join([l for l in lines if os.path.sep + 'opt' in l])
if expect_debug:
self.assertNotIn('strip-debug', opts)
else:
Expand Down Expand Up @@ -3551,11 +3556,11 @@ def test_fs_after_main(self):
def test_os_oz(self):
with env_modify({'EMCC_DEBUG': '1'}):
for args, expect in [
(['-O1'], 'LLVM opts: -O1'),
(['-O2'], 'LLVM opts: -O3'),
(['-Os'], 'LLVM opts: -Os'),
(['-Oz'], 'LLVM opts: -Oz'),
(['-O3'], 'LLVM opts: -O3'),
(['-O1'], '-O1'),
(['-O2'], '-O3'),
(['-Os'], '-Os'),
(['-Oz'], '-Oz'),
(['-O3'], '-O3'),
]:
print(args, expect)
err = run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp')] + args, stdout=PIPE, stderr=PIPE).stderr
Expand Down Expand Up @@ -5871,7 +5876,8 @@ def test(args, llvm_opts=None):

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

Expand Down
11 changes: 6 additions & 5 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ def check_returncode(self):
def run_process(cmd, check=True, input=None, universal_newlines=True, *args, **kw):
kw.setdefault('universal_newlines', True)

debug_text = '%sexecuted %s' % ('successfully ' if check else '', ' '.join(cmd))

if hasattr(subprocess, "run"):
return subprocess.run(cmd, check=check, input=input, *args, **kw)
ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
logger.debug(debug_text)
return ret

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


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

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