Fix tests on Windows

This commit is contained in:
Thom Wiggers 2019-03-04 16:56:05 +01:00
parent dc1f7e204a
commit 13867ab7b4
No known key found for this signature in database
GPG Key ID: 001BB0A7CE26E363
3 changed files with 62 additions and 24 deletions

View File

@ -1,4 +1,5 @@
import os import os
import glob
import yaml import yaml
@ -73,8 +74,20 @@ class Implementation:
return os.path.join(self.scheme.path(), self.name) return os.path.join(self.scheme.path(), self.name)
def libname(self) -> str: 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) 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 @staticmethod
def by_name(scheme_name, implementation_name): def by_name(scheme_name, implementation_name):
scheme = Scheme.by_name(scheme_name) scheme = Scheme.by_name(scheme_name)

View File

@ -19,41 +19,62 @@ def test_makefile_dependencies():
# test case for each candidate file # test case for each candidate file
cfiles = glob.glob(os.path.join(implementation.path(), '*.c')) cfiles = glob.glob(os.path.join(implementation.path(), '*.c'))
hfiles = glob.glob(os.path.join(implementation.path(), '*.h')) 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) 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): def check_makefile_dependencies(implementation, file):
cfiles = glob.glob(os.path.join(implementation.path(), '*.c')) cfiles = implementation.cfiles()
hfiles = glob.glob(os.path.join(implementation.path(), '*.h')) hfiles = implementation.hfiles()
ofiles = glob.glob(os.path.join(implementation.path(), '*.o')) ofiles = implementation.ofiles()
libfile = os.path.join(implementation.path(), implementation.libname()) libfile = os.path.join(implementation.path(), implementation.libname())
# modification time-based calculations is tricky on a sub-second basis # modification time-based calculations is tricky on a sub-second basis
# so we reset all the modification times to a known and "sensible" order # so we reset all the modification times to a known and "sensible" order
now = datetime.datetime.now() now = datetime.datetime.now() - datetime.timedelta(seconds=10)
ago15 = now - datetime.timedelta(seconds=15) ago15 = now - datetime.timedelta(minutes=15)
ago10 = now - datetime.timedelta(seconds=10) ago10 = now - datetime.timedelta(minutes=10)
ago5 = now - datetime.timedelta(seconds=5) ago5 = now - datetime.timedelta(minutes=5)
formatstring = "%Y%m%d%H%M.%S"
helpers.run_subprocess( touch(ago15, *cfiles, *hfiles)
['touch', '-t', ago15.strftime(formatstring)] + cfiles + hfiles) touch(ago10, *ofiles)
helpers.run_subprocess( touch(ago5, libfile)
['touch', '-t', ago10.strftime(formatstring)] + ofiles)
helpers.run_subprocess(
['touch', '-t', ago5.strftime(formatstring), libfile])
# Sanity check: the scheme is up to date # Sanity check: the scheme is up to date
helpers.run_subprocess(['make', '-q'], implementation.path(), make_check(implementation.path())
expected_returncode=0)
# touch the candidate .c / .h file # 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 # check if it needs to be rebuilt using make -q
helpers.run_subprocess(['make', '-q'], implementation.path(), make_check(implementation.path(), expect_error=True)
expected_returncode=1)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -16,15 +16,19 @@ def test_testvectors():
def check_vectors(implementation): def check_vectors(implementation):
helpers.make(TYPE=implementation.scheme.type, helpers.make('testvectors',
TYPE=implementation.scheme.type,
SCHEME=implementation.scheme.name, SCHEME=implementation.scheme.name,
IMPLEMENTATION=implementation.name, IMPLEMENTATION=implementation.name,
working_dir=os.path.join('..', 'test')) working_dir=os.path.join('..', 'test'))
out = helpers.run_subprocess( out = helpers.run_subprocess(
['./testvectors_{}_{}'.format(implementation.scheme.name, [os.path.join('..', 'bin', 'testvectors_{}_{}{}'.format(
implementation.name)], implementation.scheme.name,
implementation.name,
'.exe' if os.name == 'nt' else ''
))],
os.path.join('..', 'bin'), os.path.join('..', 'bin'),
) ).replace('\r', '')
assert(implementation.scheme.metadata()['testvectors-sha256'].lower() assert(implementation.scheme.metadata()['testvectors-sha256'].lower()
== hashlib.sha256(out.encode('utf-8')).hexdigest().lower()) == hashlib.sha256(out.encode('utf-8')).hexdigest().lower())