Merge pull request #68 from PQClean/test-cleanup

Clean up tests
This commit is contained in:
Joost Rijneveld 2019-03-05 11:22:16 +01:00 提交者 GitHub
當前提交 26ee50ef46
沒有發現已知的金鑰在資料庫的簽署中
GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 10 個檔案被更改,包括 56 行新增85 行删除

查看文件

@ -59,6 +59,9 @@ class Scheme:
print("Can't open {}: {}".format(metafile, e))
return None
def __repr__(self):
return "<{}({})>".format(self.type.title(), self.name)
class Implementation:
@ -96,7 +99,7 @@ class Implementation:
return "{} implementation of {}".format(self.name, self.scheme.name)
def __repr__(self):
return "<Implementation({}, {})>".format(self.name, self.scheme.name)
return "<Implementation({}, {})>".format(self.scheme.name, self.name)
class KEM(Scheme):

查看文件

@ -10,20 +10,11 @@ import helpers
def test_compile_lib():
for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations:
yield check_compile_lib, scheme.name, implementation.name
yield check_compile_lib, implementation
def check_compile_lib(scheme_name, implementation_name):
implementation = pqclean.Implementation.by_name(
scheme_name, implementation_name)
helpers.run_subprocess(
['make', 'clean'],
implementation.path()
)
helpers.run_subprocess(
['make'],
implementation.path()
)
def check_compile_lib(implementation):
helpers.make(working_dir=implementation.path())
if __name__ == '__main__':

查看文件

@ -15,21 +15,15 @@ def test_dynamic_memory():
for implementation in scheme.implementations:
# Keep this loop outside, to allow multiple assertions
for function in ['malloc', 'free', 'realloc', 'calloc']:
yield (check_dynamic_memory,
scheme.name, implementation.name, function)
yield (check_dynamic_memory, implementation, function)
def check_dynamic_memory(scheme_name, implementation_name, function):
implementation = pqclean.Implementation.by_name(
scheme_name, implementation_name)
def check_dynamic_memory(implementation, function):
# 'make' will take care of not rebuilding existing library files
helpers.run_subprocess(
['make'],
implementation.path()
)
helpers.make(working_dir=implementation.path())
scheme_name = implementation.scheme.name
out = helpers.run_subprocess(
['nm', '-g', 'lib{}_{}.a'.format(scheme_name,
implementation_name)],
['nm', '-g', 'lib{}_{}.a'.format(scheme_name, implementation.name)],
implementation.path()
)
@ -40,6 +34,7 @@ def check_dynamic_memory(scheme_name, implementation_name, function):
raise AssertionError(
"Illegal use of dynamic memory function '{}'".format(function))
if __name__ == '__main__':
try:
import nose2

查看文件

@ -14,32 +14,28 @@ import helpers
def test_functest():
for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations:
yield check_functest, scheme.name, implementation.name
yield check_functest, implementation
def test_functest_sanitizers():
for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations:
yield check_functest_sanitizers, scheme.name, implementation.name
yield check_functest_sanitizers, implementation
def check_functest(scheme_name, implementation_name):
implementation = pqclean.Implementation.by_name(
scheme_name, implementation_name)
def check_functest(implementation):
helpers.make(TYPE=implementation.scheme.type,
SCHEME=implementation.scheme.name,
IMPLEMENTATION=implementation.name,
working_dir=os.path.join('..', 'test'))
helpers.run_subprocess(
['make',
'TYPE={}'.format(implementation.scheme.type),
'SCHEME={}'.format(scheme_name),
'IMPLEMENTATION={}'.format(implementation_name)],
os.path.join('..', 'test')
)
helpers.run_subprocess(
['./functest_{}_{}'.format(scheme_name, implementation_name)],
['./functest_{}_{}'.format(implementation.scheme.name,
implementation.name)],
os.path.join('..', 'bin'),
)
def check_functest_sanitizers(scheme_name, implementation_name):
def check_functest_sanitizers(implementation):
env = None
if platform.machine() == 'ppc' and os.environ.get('CC', 'gcc') == 'clang':
raise unittest.SkipTest()
@ -47,25 +43,24 @@ def check_functest_sanitizers(scheme_name, implementation_name):
env = {'ASAN_OPTIONS': 'detect_leaks=0'}
else:
print("Supported platform: {}".format(platform.machine()))
implementation = pqclean.Implementation.by_name(
scheme_name, implementation_name)
helpers.make('clean-scheme', 'functest',
TYPE=implementation.scheme.type,
SCHEME=scheme_name,
IMPLEMENTATION=implementation_name,
SCHEME=implementation.scheme.name,
IMPLEMENTATION=implementation.name,
EXTRAFLAGS='-fsanitize=address,undefined',
working_dir=os.path.join('..', 'test'),
env=env)
helpers.run_subprocess(
['./functest_{}_{}'.format(scheme_name, implementation_name)],
['./functest_{}_{}'.format(implementation.scheme.name,
implementation.name)],
os.path.join('..', 'bin'),
env=env,
)
# Remove files with ASAN library compiled in
helpers.make('clean-scheme',
TYPE=implementation.scheme.type,
SCHEME=scheme_name,
IMPLEMENTATION=implementation_name,
SCHEME=implementation.scheme.name,
IMPLEMENTATION=implementation.name,
working_dir=os.path.join('..', 'test'))

查看文件

@ -10,12 +10,10 @@ import pqclean
def test_license():
for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations:
yield check_license, scheme.name, implementation.name
yield check_license, implementation
def check_license(scheme_name, implementation_name):
implementation = pqclean.Implementation.by_name(
scheme_name, implementation_name)
def check_license(implementation):
p1 = os.path.join(implementation.path(), 'LICENSE')
p2 = os.path.join(implementation.path(), 'LICENSE.txt')
assert(os.path.isfile(p1) or os.path.isfile(p2))

查看文件

@ -14,20 +14,16 @@ def test_makefile_dependencies():
for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations:
# initial build - want to have *all* files in place at beginning
helpers.run_subprocess(['make', 'clean'], implementation.path())
helpers.run_subprocess(['make'], implementation.path())
helpers.make('clean', working_dir=implementation.path())
helpers.make(working_dir=implementation.path())
# test case for each candidate file
cfiles = glob.glob(os.path.join(implementation.path(), '*.c'))
hfiles = glob.glob(os.path.join(implementation.path(), '*.h'))
for file in cfiles + hfiles:
yield (check_makefile_dependencies, scheme.name,
implementation.name, file)
yield (check_makefile_dependencies, implementation, file)
def check_makefile_dependencies(scheme_name, implementation_name, file):
implementation = pqclean.Implementation.by_name(scheme_name,
implementation_name)
def check_makefile_dependencies(implementation, file):
cfiles = glob.glob(os.path.join(implementation.path(), '*.c'))
hfiles = glob.glob(os.path.join(implementation.path(), '*.h'))
ofiles = glob.glob(os.path.join(implementation.path(), '*.o'))

查看文件

@ -9,11 +9,10 @@ import pqclean
def test_metadata():
for scheme in pqclean.Scheme.all_schemes():
yield check_metadata, scheme.name
yield check_metadata, scheme
def check_metadata(scheme_name):
scheme = pqclean.Scheme.by_name(scheme_name)
def check_metadata(scheme):
metadata = scheme.metadata()
specification = EXPECTED_FIELDS.items()

查看文件

@ -4,17 +4,15 @@ Checks that no implementation makes use of symbolic links.
import os
import pqclean
import sys
def test_no_symlinks():
for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations:
yield check_no_symlinks, scheme.name, implementation.name
yield check_no_symlinks, implementation
def check_no_symlinks(scheme_name, implementation_name):
implementation = pqclean.Implementation.by_name(
scheme_name, implementation_name)
def check_no_symlinks(implementation):
for file in os.listdir(implementation.path()):
fpath = os.path.join(implementation.path(), file)
if os.path.islink(fpath):

查看文件

@ -14,18 +14,14 @@ def test_symbol_namespace():
raise unittest.SkipTest()
for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations:
yield check_symbol_namespace, scheme.name, implementation.name
yield check_symbol_namespace, implementation
def check_symbol_namespace(scheme_name, implementation_name):
implementation = pqclean.Implementation.by_name(
scheme_name, implementation_name)
helpers.run_subprocess(
['make'],
implementation.path()
)
def check_symbol_namespace(implementation):
helpers.make(working_dir=implementation.path())
out = helpers.run_subprocess(
['nm', '-g', 'lib{}_{}.a'.format(scheme_name, implementation_name)],
['nm', '-g', 'lib{}_{}.a'.format(implementation.scheme.name,
implementation.name)],
implementation.path()
)

查看文件

@ -7,26 +7,26 @@ import hashlib
import os
import pqclean
import helpers
import subprocess
def test_testvectors():
for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations:
yield check_vectors, scheme.name, implementation.name
yield check_vectors, implementation
def check_vectors(scheme_name, implementation_name):
scheme = pqclean.Scheme.by_name(scheme_name)
implementation = pqclean.Implementation.by_name(scheme_name, implementation_name)
helpers.run_subprocess(
['make', 'TYPE=' + implementation.scheme.type, 'SCHEME=' + scheme_name, 'IMPLEMENTATION=' + implementation_name],
os.path.join('..', 'test')
)
def check_vectors(implementation):
helpers.make(TYPE=implementation.scheme.type,
SCHEME=implementation.scheme.name,
IMPLEMENTATION=implementation.name,
working_dir=os.path.join('..', 'test'))
out = helpers.run_subprocess(
['./testvectors_{}_{}'.format(scheme_name, implementation_name)],
['./testvectors_{}_{}'.format(implementation.scheme.name,
implementation.name)],
os.path.join('..', 'bin'),
)
assert(scheme.metadata()['testvectors-sha256'].lower() == hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
assert(implementation.scheme.metadata()['testvectors-sha256'].lower()
== hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
if __name__ == '__main__':