Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

77 linhas
2.4 KiB

  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. if helpers.permit_test('makefile_dependencies', implementation):
  14. # initial build - want to have *all* files in place at beginning
  15. helpers.make('clean', working_dir=implementation.path())
  16. helpers.make(working_dir=implementation.path())
  17. # test case for each candidate file
  18. cfiles = glob.glob(os.path.join(implementation.path(), '*.c'))
  19. hfiles = glob.glob(os.path.join(implementation.path(), '*.h'))
  20. for file in (cfiles + hfiles):
  21. yield (check_makefile_dependencies, implementation, file)
  22. def touch(time, *files):
  23. for path in files:
  24. times = (time.timestamp(), time.timestamp())
  25. os.utime(path, times)
  26. def make_check(path, expect_error=False):
  27. makeflag = '-q' if os.name != 'nt' else '/Q'
  28. expected_returncode = 0
  29. if expect_error:
  30. expected_returncode = 1 if os.name != 'nt' else 255
  31. helpers.make(makeflag, working_dir=path,
  32. expected_returncode=expected_returncode)
  33. def check_makefile_dependencies(implementation, file):
  34. cfiles = implementation.cfiles()
  35. hfiles = implementation.hfiles()
  36. ofiles = implementation.ofiles()
  37. libfile = os.path.join(implementation.path(), implementation.libname())
  38. # modification time-based calculations is tricky on a sub-second basis
  39. # so we reset all the modification times to a known and "sensible" order
  40. now = datetime.datetime.now() - datetime.timedelta(seconds=10)
  41. ago15 = now - datetime.timedelta(minutes=15)
  42. ago10 = now - datetime.timedelta(minutes=10)
  43. ago5 = now - datetime.timedelta(minutes=5)
  44. touch(ago15, *cfiles, *hfiles)
  45. touch(ago10, *ofiles)
  46. touch(ago5, libfile)
  47. # Sanity check: the scheme is up to date
  48. make_check(implementation.path())
  49. # touch the candidate .c / .h file
  50. touch(now, file)
  51. # check if it needs to be rebuilt using make -q
  52. make_check(implementation.path(), expect_error=True)
  53. if __name__ == '__main__':
  54. try:
  55. import nose2
  56. nose2.main()
  57. except ImportError:
  58. import nose
  59. nose.runmodule()