From 5b0174d282a0528c1c938143c0c5d6dfe35da827 Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Thu, 11 Apr 2019 19:22:50 +0200 Subject: [PATCH] Avoid clang tidy segfault (#106) * Gracefully degrade if clang-tidy segfaults * Typo on returncode --- test/helpers.py | 7 +++++-- test/test_linter.py | 31 ++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/test/helpers.py b/test/helpers.py index 966510f1..62e0b2f5 100644 --- a/test/helpers.py +++ b/test/helpers.py @@ -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') diff --git a/test/test_linter.py b/test/test_linter.py index 07e01180..e73492d5 100644 --- a/test/test_linter.py +++ b/test/test_linter.py @@ -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__":