mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-26 09:21:28 +00:00
Fix tests on Windows
This commit is contained in:
parent
dc1f7e204a
commit
13867ab7b4
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import glob
|
||||
import yaml
|
||||
|
||||
|
||||
@ -73,8 +74,20 @@ class Implementation:
|
||||
return os.path.join(self.scheme.path(), self.name)
|
||||
|
||||
def libname(self) -> str:
|
||||
if os.name == 'nt':
|
||||
return "lib{}_{}.lib".format(self.scheme.name, self.name)
|
||||
return "lib{}_{}.a".format(self.scheme.name, self.name)
|
||||
|
||||
def cfiles(self) -> [str]:
|
||||
return glob.glob(os.path.join(self.path(), '*.c'))
|
||||
|
||||
def hfiles(self) -> [str]:
|
||||
return glob.glob(os.path.join(self.path(), '*.h'))
|
||||
|
||||
def ofiles(self) -> [str]:
|
||||
return glob.glob(os.path.join(self.path(),
|
||||
'*.o' if os.name != 'nt' else '*.obj'))
|
||||
|
||||
@staticmethod
|
||||
def by_name(scheme_name, implementation_name):
|
||||
scheme = Scheme.by_name(scheme_name)
|
||||
|
@ -19,41 +19,62 @@ def test_makefile_dependencies():
|
||||
# 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:
|
||||
for file in (cfiles + hfiles):
|
||||
yield (check_makefile_dependencies, implementation, file)
|
||||
|
||||
|
||||
def touch(time, *files):
|
||||
if not files:
|
||||
raise Exception("Please specify the files to update")
|
||||
if os.name == 'nt':
|
||||
formatstring = "Get-Date -year %Y -month %m -day %d -hour %H -minute %M -second %S"
|
||||
time = time.strftime(formatstring)
|
||||
commands = []
|
||||
for file in files:
|
||||
commands.append('(ls {}).LastWriteTime = {}'.format(file, time))
|
||||
|
||||
helpers.run_subprocess(['powershell', '; '.join(commands)])
|
||||
else:
|
||||
formatstring = "%Y%m%d%H%M.%S"
|
||||
time = time.strftime(formatstring)
|
||||
helpers.run_subprocess(['touch', '-t', time, *files])
|
||||
|
||||
|
||||
def make_check(path, expect_error=False):
|
||||
makeflag = '-q' if os.name != 'nt' else '/Q'
|
||||
expected_returncode = 0
|
||||
if expect_error:
|
||||
expected_returncode = 1 if os.name != 'nt' else 255
|
||||
helpers.make(makeflag, working_dir=path,
|
||||
expected_returncode=expected_returncode)
|
||||
|
||||
|
||||
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'))
|
||||
cfiles = implementation.cfiles()
|
||||
hfiles = implementation.hfiles()
|
||||
ofiles = implementation.ofiles()
|
||||
|
||||
libfile = os.path.join(implementation.path(), implementation.libname())
|
||||
|
||||
# modification time-based calculations is tricky on a sub-second basis
|
||||
# so we reset all the modification times to a known and "sensible" order
|
||||
now = datetime.datetime.now()
|
||||
ago15 = now - datetime.timedelta(seconds=15)
|
||||
ago10 = now - datetime.timedelta(seconds=10)
|
||||
ago5 = now - datetime.timedelta(seconds=5)
|
||||
formatstring = "%Y%m%d%H%M.%S"
|
||||
helpers.run_subprocess(
|
||||
['touch', '-t', ago15.strftime(formatstring)] + cfiles + hfiles)
|
||||
helpers.run_subprocess(
|
||||
['touch', '-t', ago10.strftime(formatstring)] + ofiles)
|
||||
helpers.run_subprocess(
|
||||
['touch', '-t', ago5.strftime(formatstring), libfile])
|
||||
now = datetime.datetime.now() - datetime.timedelta(seconds=10)
|
||||
ago15 = now - datetime.timedelta(minutes=15)
|
||||
ago10 = now - datetime.timedelta(minutes=10)
|
||||
ago5 = now - datetime.timedelta(minutes=5)
|
||||
|
||||
touch(ago15, *cfiles, *hfiles)
|
||||
touch(ago10, *ofiles)
|
||||
touch(ago5, libfile)
|
||||
|
||||
# Sanity check: the scheme is up to date
|
||||
helpers.run_subprocess(['make', '-q'], implementation.path(),
|
||||
expected_returncode=0)
|
||||
make_check(implementation.path())
|
||||
|
||||
# touch the candidate .c / .h file
|
||||
helpers.run_subprocess(['touch', '-t', now.strftime(formatstring), file])
|
||||
touch(now, file)
|
||||
|
||||
# check if it needs to be rebuilt using make -q
|
||||
helpers.run_subprocess(['make', '-q'], implementation.path(),
|
||||
expected_returncode=1)
|
||||
make_check(implementation.path(), expect_error=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -16,15 +16,19 @@ def test_testvectors():
|
||||
|
||||
|
||||
def check_vectors(implementation):
|
||||
helpers.make(TYPE=implementation.scheme.type,
|
||||
helpers.make('testvectors',
|
||||
TYPE=implementation.scheme.type,
|
||||
SCHEME=implementation.scheme.name,
|
||||
IMPLEMENTATION=implementation.name,
|
||||
working_dir=os.path.join('..', 'test'))
|
||||
out = helpers.run_subprocess(
|
||||
['./testvectors_{}_{}'.format(implementation.scheme.name,
|
||||
implementation.name)],
|
||||
[os.path.join('..', 'bin', 'testvectors_{}_{}{}'.format(
|
||||
implementation.scheme.name,
|
||||
implementation.name,
|
||||
'.exe' if os.name == 'nt' else ''
|
||||
))],
|
||||
os.path.join('..', 'bin'),
|
||||
)
|
||||
).replace('\r', '')
|
||||
assert(implementation.scheme.metadata()['testvectors-sha256'].lower()
|
||||
== hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user