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,
)
print(result.stdout.decode('utf-8'))
assert result.returncode == expected_returncode, \
"Got unexpected return code {}".format(result.returncode)
if expected_returncode is not None:
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')

View File

@ -1,6 +1,7 @@
import os
from glob import glob
import sys
import unittest
import pqclean
import helpers
@ -17,18 +18,26 @@ def test_clang_tidy():
def check_tidy(implementation: pqclean.Implementation):
helpers.ensure_available('clang-tidy')
cfiles = glob(os.path.join(implementation.path(), '*.c'))
cfiles = implementation.cfiles()
common_files = glob(os.path.join('..', 'common', '*.c'))
helpers.run_subprocess(['clang-tidy',
'-quiet',
'-header-filter=.*'] +
additional_flags +
[*cfiles,
*common_files,
'--',
'-iquote', os.path.join('..', 'common'),
'-iquote', implementation.path(),
])
(returncode, _) = helpers.run_subprocess(
['clang-tidy',
'-quiet',
'-header-filter=.*',
*additional_flags,
*cfiles,
*common_files,
'--',
'-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__":