Reference implementations of PQC
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

98 строки
3.3 KiB

  1. """
  2. Checks that the functional test program (functest) can be successfully built
  3. and executed for every scheme/implementation.
  4. """
  5. import os
  6. import platform
  7. import unittest
  8. import pytest
  9. import helpers
  10. import pqclean
  11. @pytest.mark.parametrize(
  12. 'implementation,test_dir,impl_path, init, destr',
  13. [(impl, *helpers.isolate_test_files(impl.path(), 'test_functest_'))
  14. for impl in pqclean.Scheme.all_supported_implementations()],
  15. ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
  16. )
  17. @helpers.filtered_test
  18. def test_functest(implementation, impl_path, test_dir,
  19. init, destr):
  20. init()
  21. dest_dir = os.path.join(test_dir, 'bin')
  22. helpers.make('functest',
  23. TYPE=implementation.scheme.type,
  24. SCHEME=implementation.scheme.name,
  25. IMPLEMENTATION=implementation.name,
  26. SCHEME_DIR=impl_path,
  27. DEST_DIR=dest_dir,
  28. working_dir=os.path.join(test_dir, 'test'))
  29. helpers.run_subprocess(
  30. [os.path.join(dest_dir, 'functest_{}_{}{}'.format(
  31. implementation.scheme.name,
  32. implementation.name,
  33. '.exe' if os.name == 'nt' else ''
  34. ))],
  35. )
  36. destr()
  37. @pytest.mark.parametrize(
  38. 'implementation,test_dir,impl_path, init, destr',
  39. [(impl,
  40. *helpers.isolate_test_files(impl.path(), 'test_functest_sanitizers_'))
  41. for impl in pqclean.Scheme.all_supported_implementations()],
  42. ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
  43. )
  44. @helpers.skip_windows()
  45. @helpers.filtered_test
  46. def test_functest_sanitizers(implementation, impl_path, test_dir,
  47. init, destr):
  48. dest_dir = os.path.join(test_dir, 'bin')
  49. env = None
  50. if (implementation.scheme.name == "sphincs-sha256-192s-robust"
  51. and 'CI' in os.environ
  52. and implementation.name == "clean"
  53. and 'clang' in os.environ.get('CC', '')):
  54. raise unittest.SkipTest("Clang makes this test use too much RAM")
  55. if platform.machine() == 'ppc' and 'clang' in os.environ.get('CC', 'gcc'):
  56. raise unittest.SkipTest("Clang does not support ASAN on ppc")
  57. elif platform.machine() in ['armv7l', 'aarch64']:
  58. env = {'ASAN_OPTIONS': 'detect_leaks=0'}
  59. elif platform.system() == 'Darwin':
  60. raise unittest.SkipTest('ASAN is not reliable on OSX')
  61. else:
  62. print("Supported platform: {}".format(platform.machine()))
  63. init()
  64. helpers.make('clean-scheme', 'functest',
  65. TYPE=implementation.scheme.type,
  66. SCHEME=implementation.scheme.name,
  67. IMPLEMENTATION=implementation.name,
  68. EXTRAFLAGS=(
  69. '-g -fsanitize=address,undefined '
  70. '-fno-sanitize-recover=undefined'),
  71. SCHEME_DIR=impl_path,
  72. DEST_DIR=dest_dir,
  73. working_dir=os.path.join(test_dir, 'test'),
  74. env=env)
  75. helpers.run_subprocess(
  76. [os.path.join(dest_dir, 'functest_{}_{}{}'.format(
  77. implementation.scheme.name,
  78. implementation.name,
  79. '.exe' if os.name == 'nt' else ''
  80. ))],
  81. env=env,
  82. )
  83. destr()
  84. if __name__ == '__main__':
  85. import sys
  86. pytest.main(sys.argv)