Avoid clang tidy segfault (#106)

* Gracefully degrade if clang-tidy segfaults

* Typo on returncode
This commit is contained in:
Thom Wiggers 2019-04-11 19:22:50 +02:00 committed by Douglas Stebila
parent b2ef82e2da
commit 5b0174d282
2 changed files with 25 additions and 13 deletions

View File

@ -30,8 +30,11 @@ def run_subprocess(command, working_dir='.', env=None, expected_returncode=0):
env=env, env=env,
) )
print(result.stdout.decode('utf-8')) print(result.stdout.decode('utf-8'))
assert result.returncode == expected_returncode, \ if expected_returncode is not None:
"Got unexpected return code {}".format(result.returncode) assert result.returncode == expected_returncode, \
"Got unexpected return code {}".format(result.returncode)
else:
return (result.returncode, result.stdout.decode('utf-8'))
return result.stdout.decode('utf-8') return result.stdout.decode('utf-8')

View File

@ -1,6 +1,7 @@
import os import os
from glob import glob from glob import glob
import sys import sys
import unittest
import pqclean import pqclean
import helpers import helpers
@ -17,18 +18,26 @@ def test_clang_tidy():
def check_tidy(implementation: pqclean.Implementation): def check_tidy(implementation: pqclean.Implementation):
helpers.ensure_available('clang-tidy') helpers.ensure_available('clang-tidy')
cfiles = glob(os.path.join(implementation.path(), '*.c')) cfiles = implementation.cfiles()
common_files = glob(os.path.join('..', 'common', '*.c')) common_files = glob(os.path.join('..', 'common', '*.c'))
helpers.run_subprocess(['clang-tidy', (returncode, _) = helpers.run_subprocess(
'-quiet', ['clang-tidy',
'-header-filter=.*'] + '-quiet',
additional_flags + '-header-filter=.*',
[*cfiles, *additional_flags,
*common_files, *cfiles,
'--', *common_files,
'-iquote', os.path.join('..', 'common'), '--',
'-iquote', implementation.path(), '-iquote', os.path.join('..', 'common'),
]) '-iquote', implementation.path()],
expected_returncode=None,
)
# Detect and gracefully avoid segfaults
if returncode == -11:
raise unittest.SkipTest("clang-tidy segfaulted")
else:
assert returncode == 0, "Clang-tidy returned %d" % returncode
if __name__ == "__main__": if __name__ == "__main__":