Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

63 linhas
1.8 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. if sys.platform not in ['linux', 'darwin']:
  11. raise unittest.SkipTest()
  12. for scheme in pqclean.Scheme.all_schemes():
  13. for implementation in scheme.implementations:
  14. yield check_symbol_namespace, scheme.name, implementation.name
  15. def check_symbol_namespace(scheme_name, implementation_name):
  16. implementation = pqclean.Implementation.by_name(
  17. scheme_name, implementation_name)
  18. helpers.run_subprocess(
  19. ['make'],
  20. implementation.path()
  21. )
  22. out = helpers.run_subprocess(
  23. ['nm', '-g', 'lib{}_{}.a'.format(scheme_name, implementation_name)],
  24. implementation.path()
  25. )
  26. lines = out.strip().split("\n")
  27. symbols = []
  28. for line in lines:
  29. if ' T ' in line or ' D ' in line or ' S ' in line:
  30. symbols.append(line)
  31. namespace = implementation.namespace_prefix()
  32. non_namespaced = []
  33. for symbolstr in symbols:
  34. *_, symtype, symbol = symbolstr.split()
  35. if symtype in 'TR':
  36. if (not symbol.startswith(namespace) and
  37. # weird things on i386
  38. not symbol.startswith('__x86.get_pc_thunk.') and
  39. not symbol.startswith('_' + namespace)):
  40. non_namespaced.append(symbol)
  41. if non_namespaced:
  42. print("Missing namespace literal {}".format(namespace))
  43. for symbol in non_namespaced:
  44. print("\ttype: {}, symbol: {}".format(symtype, symbol))
  45. assert(False)
  46. if __name__ == '__main__':
  47. try:
  48. import nose2
  49. nose2.main()
  50. except ImportError:
  51. import nose
  52. nose.runmodule()