Fix tests on Windows

This commit is contained in:
Thom Wiggers 2019-03-04 16:56:05 +01:00
父節點 dc1f7e204a
當前提交 13867ab7b4
沒有發現已知的金鑰在資料庫的簽署中
GPG Key ID: 001BB0A7CE26E363
共有 3 個文件被更改,包括 62 次插入24 次删除

查看文件

@ -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())