From 395f14a2f6ecbaf1869d90b4e623c99eaa28e939 Mon Sep 17 00:00:00 2001 From: Douglas Stebila Date: Wed, 10 Apr 2019 12:07:49 -0400 Subject: [PATCH] Allow multiple sources for duplicate consistency checks; break into multiple unit test to improve output --- .../frodokem1344shake_clean.yml | 19 ++++++------ .../frodokem640aes_clean.yml | 19 ++++++------ .../frodokem976shake_clean.yml | 19 ++++++------ test/test_duplicate_consistency.py | 31 ++++++++++--------- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/test/duplicate_consistency/frodokem1344shake_clean.yml b/test/duplicate_consistency/frodokem1344shake_clean.yml index fb1fb3de..ee44e1ab 100644 --- a/test/duplicate_consistency/frodokem1344shake_clean.yml +++ b/test/duplicate_consistency/frodokem1344shake_clean.yml @@ -1,9 +1,10 @@ -source: - scheme: frodokem640shake - implementation: clean -files: - - common.h - - kem.c - - matrix_shake.c - - noise.c - - util.c +consistency_checks: +- source: + scheme: frodokem640shake + implementation: clean + files: + - common.h + - kem.c + - matrix_shake.c + - noise.c + - util.c diff --git a/test/duplicate_consistency/frodokem640aes_clean.yml b/test/duplicate_consistency/frodokem640aes_clean.yml index dd50d9ca..19c945d0 100644 --- a/test/duplicate_consistency/frodokem640aes_clean.yml +++ b/test/duplicate_consistency/frodokem640aes_clean.yml @@ -1,9 +1,10 @@ -source: - scheme: frodokem640shake - implementation: clean -files: - - common.h - - params.h - - kem.c - - noise.c - - util.c +consistency_checks: +- source: + scheme: frodokem640shake + implementation: clean + files: + - common.h + - params.h + - kem.c + - noise.c + - util.c diff --git a/test/duplicate_consistency/frodokem976shake_clean.yml b/test/duplicate_consistency/frodokem976shake_clean.yml index fb1fb3de..ee44e1ab 100644 --- a/test/duplicate_consistency/frodokem976shake_clean.yml +++ b/test/duplicate_consistency/frodokem976shake_clean.yml @@ -1,9 +1,10 @@ -source: - scheme: frodokem640shake - implementation: clean -files: - - common.h - - kem.c - - matrix_shake.c - - noise.c - - util.c +consistency_checks: +- source: + scheme: frodokem640shake + implementation: clean + files: + - common.h + - kem.c + - matrix_shake.c + - noise.c + - util.c diff --git a/test/test_duplicate_consistency.py b/test/test_duplicate_consistency.py index 52755a3b..6ee7c7e0 100644 --- a/test/test_duplicate_consistency.py +++ b/test/test_duplicate_consistency.py @@ -9,29 +9,30 @@ import unittest import yaml def test_duplicate_consistency(): + helpers.skip_windows() for scheme in pqclean.Scheme.all_schemes(): for implementation in scheme.implementations: if os.path.isfile(os.path.join('duplicate_consistency', '{}_{}.yml'.format(scheme.name, implementation.name))): - yield check_duplicate_consistency, implementation + metafile = os.path.join('duplicate_consistency', '{}_{}.yml'.format(implementation.scheme.name, implementation.name)) + with open(metafile, encoding='utf-8') as f: + metadata = yaml.load(f.read()) + for group in metadata['consistency_checks']: + source = pqclean.Implementation.by_name(group['source']['scheme'], group['source']['implementation']) + for file in group['files']: + yield check_duplicate_consistency, implementation, source, file def file_get_contents(filename): with open(filename) as f: return f.read() -def check_duplicate_consistency(implementation): - helpers.skip_windows() - metafile = os.path.join('duplicate_consistency', '{}_{}.yml'.format(implementation.scheme.name, implementation.name)) - with open(metafile, encoding='utf-8') as f: - metadata = yaml.load(f.read()) - source = pqclean.Implementation.by_name(metadata['source']['scheme'], metadata['source']['implementation']) - for file in metadata['files']: - transformed_src = helpers.run_subprocess( - ['sed', '-e', 's/{}/{}/g'.format(source.namespace_prefix(), implementation.namespace_prefix()), os.path.join(source.path(), file)] - ) - this_src = file_get_contents(os.path.join(implementation.path(), file)) - print(os.path.join(implementation.path(), file)) - print(this_src) - assert(transformed_src == this_src) +def check_duplicate_consistency(implementation, source, file): + transformed_src = helpers.run_subprocess( + ['sed', '-e', 's/{}/{}/g'.format(source.namespace_prefix(), implementation.namespace_prefix()), os.path.join(source.path(), file)] + ) + this_src = file_get_contents(os.path.join(implementation.path(), file)) + print(os.path.join(implementation.path(), file)) + print(this_src) + assert(transformed_src == this_src) if __name__ == '__main__': try: