From b2ef82e2daa1848203d3ac46ec4233bbaeadc60d Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Tue, 9 Apr 2019 16:49:43 +0200 Subject: [PATCH 1/3] Remove duplicate namespace_prefix --- test/pqclean.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/pqclean.py b/test/pqclean.py index d11b1bce..12e1d61d 100644 --- a/test/pqclean.py +++ b/test/pqclean.py @@ -70,7 +70,7 @@ class Implementation: def __init__(self, scheme, name): self.scheme = scheme self.name = name - + def metadata(self): for i in self.scheme.metadata()['implementations']: if i['name'] == self.name: @@ -79,9 +79,6 @@ class Implementation: def path(self, base='..') -> str: return os.path.join(self.scheme.path(), self.name) - def namespace_prefix(self): - return 'PQCLEAN_{}_{}_'.format(self.scheme.name.upper(), self.name.upper()).replace('-', '') - def libname(self) -> str: if os.name == 'nt': return "lib{}_{}.lib".format(self.scheme.name, self.name) From 5b0174d282a0528c1c938143c0c5d6dfe35da827 Mon Sep 17 00:00:00 2001 From: Thom Wiggers Date: Thu, 11 Apr 2019 19:22:50 +0200 Subject: [PATCH 2/3] 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__": From 0bc19b36334d9d0f5c23bd6bc2a5dbcbf5a6e388 Mon Sep 17 00:00:00 2001 From: Douglas Stebila Date: Thu, 11 Apr 2019 13:47:53 -0400 Subject: [PATCH 3/3] Fix a few nits (#107) * Minor changes * Gracefully degrade if clang-tidy segfaults * Typo on returncode --- .../clean/thash_shake256_simple.c | 2 +- crypto_sign/sphincs-shake256-128f-simple/clean/wots.c | 2 +- test/helpers.py | 4 +++- test/test_common.py | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crypto_sign/sphincs-shake256-128f-simple/clean/thash_shake256_simple.c b/crypto_sign/sphincs-shake256-128f-simple/clean/thash_shake256_simple.c index 7c2cdb63..341c6fd3 100644 --- a/crypto_sign/sphincs-shake256-128f-simple/clean/thash_shake256_simple.c +++ b/crypto_sign/sphincs-shake256-128f-simple/clean/thash_shake256_simple.c @@ -1,9 +1,9 @@ #include #include -#include "thash.h" #include "address.h" #include "params.h" +#include "thash.h" #include "fips202.h" diff --git a/crypto_sign/sphincs-shake256-128f-simple/clean/wots.c b/crypto_sign/sphincs-shake256-128f-simple/clean/wots.c index a6a8ada6..4431986d 100644 --- a/crypto_sign/sphincs-shake256-128f-simple/clean/wots.c +++ b/crypto_sign/sphincs-shake256-128f-simple/clean/wots.c @@ -1,11 +1,11 @@ #include #include -#include "utils.h" #include "address.h" #include "hash.h" #include "params.h" #include "thash.h" +#include "utils.h" #include "wots.h" // TODO clarify address expectations, and make them more uniform. diff --git a/test/helpers.py b/test/helpers.py index 62e0b2f5..18ac1e4f 100644 --- a/test/helpers.py +++ b/test/helpers.py @@ -114,8 +114,10 @@ def permit_test(testname, thing, **args): if isinstance(thing, pqclean.Implementation): scheme = thing.scheme - else: + elif isinstance(thing, pqclean.Scheme): scheme = thing + else: + return True if 'PQCLEAN_ONLY_TYPES' in os.environ: if not(scheme.type.lower() in os.environ['PQCLEAN_ONLY_TYPES'].lower().split(',')): diff --git a/test/test_common.py b/test/test_common.py index 3640bb3f..e4c89939 100644 --- a/test/test_common.py +++ b/test/test_common.py @@ -12,7 +12,7 @@ import helpers def test_common(): for d in os.listdir('common'): primitive = re.sub(r"\.c$", "", d) - yield check_common, primitive + if helpers.permit_test('common', None): yield check_common, primitive def check_common(primitive):