2019-02-14 16:29:49 +00:00
|
|
|
"""
|
2019-02-18 12:04:59 +00:00
|
|
|
Checks that the all exported symbols are properly namespaced, i.e., all
|
|
|
|
start with "PQCLEAN_SCHEMENAME_".
|
2019-02-14 16:29:49 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import pqclean
|
|
|
|
import helpers
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
2019-02-18 12:04:59 +00:00
|
|
|
|
2019-02-14 16:29:49 +00:00
|
|
|
def test_symbol_namespace():
|
|
|
|
for scheme in pqclean.Scheme.all_schemes():
|
|
|
|
for implementation in scheme.implementations:
|
2019-03-01 12:18:41 +00:00
|
|
|
yield check_symbol_namespace, implementation
|
2019-02-14 16:29:49 +00:00
|
|
|
|
2019-02-18 12:04:59 +00:00
|
|
|
|
2019-03-01 12:18:41 +00:00
|
|
|
def check_symbol_namespace(implementation):
|
2019-03-04 15:56:40 +00:00
|
|
|
if sys.platform not in ['linux', 'darwin']:
|
|
|
|
raise unittest.SkipTest("Unsupported platform")
|
2019-03-01 12:18:41 +00:00
|
|
|
helpers.make(working_dir=implementation.path())
|
2019-02-14 16:29:49 +00:00
|
|
|
out = helpers.run_subprocess(
|
2019-03-04 15:56:40 +00:00
|
|
|
['nm', '-g', implementation.libname()],
|
2019-02-18 12:04:59 +00:00
|
|
|
implementation.path()
|
2019-02-14 16:29:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
lines = out.strip().split("\n")
|
|
|
|
symbols = []
|
|
|
|
for line in lines:
|
|
|
|
if ' T ' in line or ' D ' in line or ' S ' in line:
|
|
|
|
symbols.append(line)
|
|
|
|
|
2019-02-26 16:27:32 +00:00
|
|
|
namespace = implementation.namespace_prefix()
|
2019-02-14 16:29:49 +00:00
|
|
|
non_namespaced = []
|
|
|
|
for symbolstr in symbols:
|
|
|
|
*_, symtype, symbol = symbolstr.split()
|
|
|
|
if symtype in 'TR':
|
2019-02-18 12:04:59 +00:00
|
|
|
if (not symbol.startswith(namespace) and
|
2019-02-27 16:36:19 +00:00
|
|
|
# weird things on i386
|
2019-02-27 17:09:46 +00:00
|
|
|
not symbol.startswith('__x86.get_pc_thunk.') and
|
2019-02-18 12:04:59 +00:00
|
|
|
not symbol.startswith('_' + namespace)):
|
2019-02-14 16:29:49 +00:00
|
|
|
non_namespaced.append(symbol)
|
|
|
|
|
|
|
|
if non_namespaced:
|
|
|
|
print("Missing namespace literal {}".format(namespace))
|
|
|
|
for symbol in non_namespaced:
|
|
|
|
print("\ttype: {}, symbol: {}".format(symtype, symbol))
|
|
|
|
assert(False)
|
2019-02-18 12:39:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-02-18 12:51:01 +00:00
|
|
|
try:
|
|
|
|
import nose2
|
|
|
|
nose2.main()
|
|
|
|
except ImportError:
|
|
|
|
import nose
|
|
|
|
nose.runmodule()
|