Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

test_makefile_dependencies.py 2.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """
  2. Checks that every .c and .h file in an implementation is present as a
  3. dependency of that scheme's Makefile.
  4. """
  5. import os
  6. import pqclean
  7. import helpers
  8. import glob
  9. import datetime
  10. def test_makefile_dependencies():
  11. for scheme in pqclean.Scheme.all_schemes():
  12. for implementation in scheme.implementations:
  13. # initial build - want to have *all* files in place at beginning
  14. helpers.run_subprocess(['make', 'clean'], implementation.path())
  15. helpers.run_subprocess(['make'], implementation.path())
  16. # test case for each candidate file
  17. cfiles = glob.glob(os.path.join(implementation.path(), '*.c'))
  18. hfiles = glob.glob(os.path.join(implementation.path(), '*.h'))
  19. for file in cfiles + hfiles:
  20. yield (check_makefile_dependencies, scheme.name,
  21. implementation.name, file)
  22. def check_makefile_dependencies(scheme_name, implementation_name, file):
  23. implementation = pqclean.Implementation.by_name(scheme_name,
  24. implementation_name)
  25. cfiles = glob.glob(os.path.join(implementation.path(), '*.c'))
  26. hfiles = glob.glob(os.path.join(implementation.path(), '*.h'))
  27. ofiles = glob.glob(os.path.join(implementation.path(), '*.o'))
  28. libfile = os.path.join(implementation.path(), implementation.libname())
  29. # modification time-based calculations is tricky on a sub-second basis
  30. # so we reset all the modification times to a known and "sensible" order
  31. now = datetime.datetime.now()
  32. ago15 = now - datetime.timedelta(seconds=15)
  33. ago10 = now - datetime.timedelta(seconds=10)
  34. ago5 = now - datetime.timedelta(seconds=5)
  35. formatstring = "%Y%m%d%H%M.%S"
  36. helpers.run_subprocess(
  37. ['touch', '-t', ago15.strftime(formatstring)] + cfiles + hfiles)
  38. helpers.run_subprocess(
  39. ['touch', '-t', ago10.strftime(formatstring)] + ofiles)
  40. helpers.run_subprocess(
  41. ['touch', '-t', ago5.strftime(formatstring), libfile])
  42. # Sanity check: the scheme is up to date
  43. helpers.run_subprocess(['make', '-q'], implementation.path(),
  44. expected_returncode=0)
  45. # touch the candidate .c / .h file
  46. helpers.run_subprocess(['touch', '-t', now.strftime(formatstring), file])
  47. # check if it needs to be rebuilt using make -q
  48. helpers.run_subprocess(['make', '-q'], implementation.path(),
  49. expected_returncode=1)
  50. if __name__ == '__main__':
  51. try:
  52. import nose2
  53. nose2.main()
  54. except ImportError:
  55. import nose
  56. nose.runmodule()