Reference implementations of PQC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
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.filtered_test
  27. def test_valgrind(implementation: pqclean.Implementation, impl_path, test_dir,
  28. init, destr):
  29. if (platform.machine() not in ('i386', 'x86_64') or
  30. platform.system() != 'Linux'):
  31. raise unittest.SkipTest()
  32. init()
  33. dest_dir = os.path.join(test_dir, 'bin')
  34. helpers.make(TYPE=implementation.scheme.type,
  35. SCHEME=implementation.scheme.name,
  36. SCHEME_DIR=os.path.abspath(impl_path),
  37. IMPLEMENTATION=implementation.name,
  38. DEST_DIR=dest_dir,
  39. EXTRAFLAGS="-g3",
  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. '--leak-check=yes',
  48. *(['--exit-on-first-error=yes']
  49. if valgrind_supports_exit_early()
  50. else []),
  51. '--max-stackframe=20933064',
  52. '--vex-guest-max-insns=25',
  53. functest_name],
  54. dest_dir)
  55. destr()
  56. if __name__ == '__main__':
  57. import sys
  58. pytest.main(sys.argv)