您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

71 行
2.0 KiB

  1. """
  2. Runs the test files under valgrind to detect memory problems
  3. """
  4. import functools
  5. import os
  6. import platform
  7. import re
  8. import unittest
  9. import pytest
  10. import helpers
  11. import pqclean
  12. @functools.lru_cache()
  13. def valgrind_supports_exit_early():
  14. """Checks if we support early exit from valgrind"""
  15. version = helpers.run_subprocess(['valgrind', '--version'])
  16. match = re.match(r'valgrind-(\d)\.(\d+).*', version)
  17. if match:
  18. return int(match.group(2)) >= 14
  19. return False
  20. @pytest.mark.parametrize(
  21. 'implementation,test_dir,impl_path, init, destr',
  22. [(impl, *helpers.isolate_test_files(impl.path(), 'test_valgrind_'))
  23. for impl in pqclean.Scheme.all_supported_implementations()],
  24. ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
  25. )
  26. @helpers.slow_test
  27. @helpers.filtered_test
  28. def test_valgrind(implementation: pqclean.Implementation, impl_path, test_dir,
  29. init, destr):
  30. if (platform.machine() not in ('i386', 'x86_64') or
  31. platform.system() != 'Linux'):
  32. raise unittest.SkipTest()
  33. init()
  34. dest_dir = os.path.join(test_dir, 'bin')
  35. helpers.make(TYPE=implementation.scheme.type,
  36. SCHEME=implementation.scheme.name,
  37. SCHEME_DIR=os.path.abspath(impl_path),
  38. IMPLEMENTATION=implementation.name,
  39. DEST_DIR=dest_dir,
  40. EXTRAFLAGS="-g3",
  41. NTESTS=1,
  42. working_dir=os.path.join(test_dir, 'test'))
  43. functest_name = './functest_{}_{}'.format(implementation.scheme.name,
  44. implementation.name)
  45. helpers.run_subprocess(
  46. ['valgrind',
  47. '--error-exitcode=1',
  48. '--leak-check=yes',
  49. *(['--exit-on-first-error=yes']
  50. if valgrind_supports_exit_early()
  51. else []),
  52. '--max-stackframe=20933064',
  53. '--vex-guest-max-insns=25',
  54. functest_name],
  55. dest_dir)
  56. destr()
  57. if __name__ == '__main__':
  58. import sys
  59. pytest.main(sys.argv)