Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

69 rindas
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_functest_'))
  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. NTESTS=1,
  41. working_dir=os.path.join(test_dir, 'test'))
  42. functest_name = './functest_{}_{}'.format(implementation.scheme.name,
  43. implementation.name)
  44. helpers.run_subprocess(
  45. ['valgrind',
  46. '--error-exitcode=1',
  47. *(['--exit-on-first-error=yes']
  48. if valgrind_supports_exit_early()
  49. else []),
  50. '--max-stackframe=20933064',
  51. '--vex-guest-max-insns=25',
  52. functest_name],
  53. dest_dir)
  54. destr()
  55. if __name__ == '__main__':
  56. import sys
  57. pytest.main(sys.argv)