mirror of
https://github.com/open-quantum-safe/liboqs.git
synced 2025-10-06 00:03:35 -04:00
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
import helpers
|
|
import pytest
|
|
import sys
|
|
|
|
# Check if liboqs contains any non-namespaced global symbols
|
|
# See https://github.com/open-quantum-safe/liboqs/wiki/Coding-conventions for function naming conventions
|
|
|
|
@helpers.filtered_test
|
|
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not needed on Windows")
|
|
def test_namespace():
|
|
out = helpers.run_subprocess(
|
|
['nm', '-g', '.libs/liboqs.a']
|
|
)
|
|
|
|
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)
|
|
|
|
# ideally this would be just ['oqs', 'pqclean'] but the Picnic implementation has a few more symbols
|
|
namespaces = ['oqs', 'pqclean', 'keccak', 'picnic', 'aligned_alloc', 'aligned_free']
|
|
non_namespaced = []
|
|
|
|
for symbolstr in symbols:
|
|
*_, symtype, symbol = symbolstr.split()
|
|
if symtype in 'TR':
|
|
is_namespaced = False
|
|
for namespace in namespaces:
|
|
if symbol.lower().startswith(namespace) or symbol.lower().startswith('_' + namespace):
|
|
is_namespaced = True
|
|
if not(is_namespaced):
|
|
non_namespaced.append(symbol)
|
|
|
|
if len(non_namespaced) > 0:
|
|
for symbol in non_namespaced:
|
|
print("Non-namespaced symbol: {}".format(symbol))
|
|
|
|
assert(len(non_namespaced) == 0)
|
|
|
|
if __name__ == "__main__":
|
|
import sys
|
|
pytest.main(sys.argv)
|
|
|