liboqs/tests/test_namespace.py
Douglas Stebila a55b12eb25
Fix non-Dilithium-related execute failures on Alpine (#796)
* Increase stack size when using musl libc on Alpine

This is probably not the best way to do it in long run, but I'm not sure 
how to detect libc version at compile time.

* Fix free-check bug on Alpine

* Extra symbols in shared library on Alpine

* Activate Alpine builds

* Only increase stack size if musl is present on Alpine

This is not the most generic way to do it but hopefully will suffice

* Temporarily enable Alpine builds

* Simplify link option on Alpine
2020-07-24 09:18:19 -04:00

57 lines
1.7 KiB
Python

# SPDX-License-Identifier: MIT
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(use_liboqs_so):
if use_liboqs_so:
if sys.platform == "darwin":
out = helpers.run_subprocess(
['nm', '-g', 'build/lib/liboqs.dylib']
)
else:
out = helpers.run_subprocess(
['nm', '-D', 'build/lib/liboqs.so']
)
else:
out = helpers.run_subprocess(
['nm', '-g', 'build/lib/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']
namespaces = ['oqs', 'pqclean', 'keccak', 'pqcrystals', 'aligned_alloc', 'aligned_free', 'init', 'fini']
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)