Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

44 rader
1.2 KiB

  1. """
  2. Checks that no dynamic memory functions are used
  3. """
  4. import pytest
  5. import helpers
  6. import pqclean
  7. @pytest.mark.parametrize(
  8. 'implementation,test_dir,impl_path, init, destr',
  9. [(impl, *helpers.isolate_test_files(impl.path(), 'test_functest_'))
  10. for impl in pqclean.Scheme.all_supported_implementations()],
  11. ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
  12. )
  13. @helpers.skip_windows()
  14. @helpers.filtered_test
  15. def test_dynamic_memory(implementation, test_dir, impl_path, init, destr):
  16. init()
  17. # 'make' will take care of not rebuilding existing library files
  18. helpers.make(working_dir=impl_path)
  19. scheme_name = implementation.scheme.name
  20. out = helpers.run_subprocess(
  21. ['nm', '-g', 'lib{}_{}.a'.format(scheme_name, implementation.name)],
  22. impl_path,
  23. )
  24. lines = out.strip().split("\n")
  25. for line in lines:
  26. for function in ['malloc', 'free', 'realloc', 'calloc']:
  27. if line.endswith('U {}'.format(function)):
  28. raise AssertionError(
  29. "Illegal use of dynamic memory function "
  30. "'{function}'".format(function=function))
  31. destr()
  32. if __name__ == '__main__':
  33. import sys
  34. pytest.main(sys.argv)