Allow multiple sources for duplicate consistency checks; break into multiple unit test to improve output

This commit is contained in:
Douglas Stebila 2019-04-10 12:07:49 -04:00
parent e9427afeb2
commit 395f14a2f6
4 changed files with 46 additions and 42 deletions

View File

@ -1,9 +1,10 @@
source: consistency_checks:
scheme: frodokem640shake - source:
implementation: clean scheme: frodokem640shake
files: implementation: clean
- common.h files:
- kem.c - common.h
- matrix_shake.c - kem.c
- noise.c - matrix_shake.c
- util.c - noise.c
- util.c

View File

@ -1,9 +1,10 @@
source: consistency_checks:
scheme: frodokem640shake - source:
implementation: clean scheme: frodokem640shake
files: implementation: clean
- common.h files:
- params.h - common.h
- kem.c - params.h
- noise.c - kem.c
- util.c - noise.c
- util.c

View File

@ -1,9 +1,10 @@
source: consistency_checks:
scheme: frodokem640shake - source:
implementation: clean scheme: frodokem640shake
files: implementation: clean
- common.h files:
- kem.c - common.h
- matrix_shake.c - kem.c
- noise.c - matrix_shake.c
- util.c - noise.c
- util.c

View File

@ -9,29 +9,30 @@ import unittest
import yaml import yaml
def test_duplicate_consistency(): def test_duplicate_consistency():
helpers.skip_windows()
for scheme in pqclean.Scheme.all_schemes(): for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations: for implementation in scheme.implementations:
if os.path.isfile(os.path.join('duplicate_consistency', '{}_{}.yml'.format(scheme.name, implementation.name))): 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): def file_get_contents(filename):
with open(filename) as f: with open(filename) as f:
return f.read() return f.read()
def check_duplicate_consistency(implementation): def check_duplicate_consistency(implementation, source, file):
helpers.skip_windows() transformed_src = helpers.run_subprocess(
metafile = os.path.join('duplicate_consistency', '{}_{}.yml'.format(implementation.scheme.name, implementation.name)) ['sed', '-e', 's/{}/{}/g'.format(source.namespace_prefix(), implementation.namespace_prefix()), os.path.join(source.path(), file)]
with open(metafile, encoding='utf-8') as f: )
metadata = yaml.load(f.read()) this_src = file_get_contents(os.path.join(implementation.path(), file))
source = pqclean.Implementation.by_name(metadata['source']['scheme'], metadata['source']['implementation']) print(os.path.join(implementation.path(), file))
for file in metadata['files']: print(this_src)
transformed_src = helpers.run_subprocess( assert(transformed_src == this_src)
['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__': if __name__ == '__main__':
try: try: