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.
 
 
 

59 lines
1.7 KiB

  1. """
  2. Checks that the all exported symbols are properly namespaced, i.e., all
  3. start with "PQCLEAN_SCHEMENAME_".
  4. """
  5. import pqclean
  6. import helpers
  7. import sys
  8. import unittest
  9. def test_symbol_namespace():
  10. for scheme in pqclean.Scheme.all_schemes():
  11. for implementation in scheme.implementations:
  12. yield check_symbol_namespace, implementation
  13. @helpers.filtered_test
  14. def check_symbol_namespace(implementation):
  15. if sys.platform not in ['linux', 'darwin']:
  16. raise unittest.SkipTest("Unsupported platform")
  17. helpers.make(working_dir=implementation.path())
  18. out = helpers.run_subprocess(
  19. ['nm', '-g', implementation.libname()],
  20. implementation.path()
  21. )
  22. lines = out.strip().split("\n")
  23. symbols = []
  24. for line in lines:
  25. if ' T ' in line or ' D ' in line or ' S ' in line:
  26. symbols.append(line)
  27. namespace = implementation.namespace_prefix()
  28. non_namespaced = []
  29. for symbolstr in symbols:
  30. *_, symtype, symbol = symbolstr.split()
  31. if symtype in 'TR':
  32. if (not symbol.startswith(namespace) and
  33. # weird things on i386
  34. not symbol.startswith('__x86.get_pc_thunk.') and
  35. not symbol.startswith('_' + namespace)):
  36. non_namespaced.append(symbol)
  37. if non_namespaced:
  38. print("Missing namespace literal {}".format(namespace))
  39. for symbol in non_namespaced:
  40. print("\ttype: {}, symbol: {}".format(symtype, symbol))
  41. assert(False)
  42. if __name__ == '__main__':
  43. try:
  44. import nose2
  45. nose2.main()
  46. except ImportError:
  47. import nose
  48. nose.runmodule()