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.
 
 
 

66 line
2.1 KiB

  1. """
  2. Checks that the all exported symbols are properly namespaced, i.e., all
  3. start with "PQCLEAN_SCHEMENAME_".
  4. """
  5. import sys
  6. import unittest
  7. import pytest
  8. import helpers
  9. import pqclean
  10. @pytest.mark.parametrize(
  11. 'implementation,test_dir,impl_path,init,destr',
  12. [(impl,
  13. *helpers.isolate_test_files(impl.path(), 'test_symbol_ns_'))
  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_symbol_namespaces(implementation, impl_path, test_dir, init, destr):
  19. if sys.platform not in ['linux', 'darwin']:
  20. raise unittest.SkipTest("Unsupported platform")
  21. init()
  22. helpers.make(working_dir=impl_path)
  23. out = helpers.run_subprocess(
  24. ['nm', '-g', implementation.libname()],
  25. impl_path,
  26. )
  27. lines = out.strip().split("\n")
  28. symbols = []
  29. for line in lines:
  30. if ' T ' in line or ' D ' in line or ' S ' in line:
  31. symbols.append(line)
  32. namespace = implementation.namespace_prefix()
  33. non_namespaced = []
  34. for symbolstr in symbols:
  35. *_, symtype, symbol = symbolstr.split()
  36. if symtype in 'TR':
  37. if not (symbol.startswith(namespace) or
  38. symbol.startswith('_' + namespace) or
  39. # KeccakP-1600 for AVX2
  40. symbol.startswith('KeccakF1600times4') or
  41. symbol.startswith('_KeccakF1600times4') or # MacOS
  42. symbol.startswith('KeccakP1600times4') or
  43. symbol.startswith('_KeccakP1600times4') or # MacOS
  44. # weird things on i386
  45. symbol.startswith('__x86.get_pc_thunk.')):
  46. non_namespaced.append(symbol)
  47. if non_namespaced:
  48. print("Missing namespace literal {}".format(namespace))
  49. for symbol in non_namespaced:
  50. print("\ttype: {}, symbol: {}".format(symtype, symbol))
  51. assert not non_namespaced, "Literals with missing namespaces"
  52. destr()
  53. if __name__ == '__main__':
  54. pytest.main(sys.argv)