2019-02-27 12:59:00 +00:00
|
|
|
"""
|
|
|
|
Checks that no dynamic memory functions are used
|
|
|
|
"""
|
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
import pytest
|
2019-02-27 12:59:00 +00:00
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
import helpers
|
|
|
|
import pqclean
|
2019-02-27 12:59:00 +00:00
|
|
|
|
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'implementation,test_dir,impl_path, init, destr',
|
|
|
|
[(impl, *helpers.isolate_test_files(impl.path(), 'test_functest_'))
|
2019-09-06 11:01:44 +01:00
|
|
|
for impl in pqclean.Scheme.all_supported_implementations()],
|
|
|
|
ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
|
2019-07-29 09:38:25 +01:00
|
|
|
)
|
2019-03-04 14:12:38 +00:00
|
|
|
@helpers.skip_windows()
|
2019-07-29 09:38:25 +01:00
|
|
|
@helpers.filtered_test
|
|
|
|
def test_dynamic_memory(implementation, test_dir, impl_path, init, destr):
|
|
|
|
init()
|
2019-02-27 12:59:00 +00:00
|
|
|
# 'make' will take care of not rebuilding existing library files
|
2019-07-29 09:38:25 +01:00
|
|
|
helpers.make(working_dir=impl_path)
|
2019-03-01 12:18:41 +00:00
|
|
|
scheme_name = implementation.scheme.name
|
2019-02-27 12:59:00 +00:00
|
|
|
out = helpers.run_subprocess(
|
2019-03-01 12:18:41 +00:00
|
|
|
['nm', '-g', 'lib{}_{}.a'.format(scheme_name, implementation.name)],
|
2019-07-29 09:38:25 +01:00
|
|
|
impl_path,
|
2019-02-27 12:59:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
lines = out.strip().split("\n")
|
|
|
|
|
|
|
|
for line in lines:
|
2019-07-29 09:38:25 +01:00
|
|
|
for function in ['malloc', 'free', 'realloc', 'calloc']:
|
|
|
|
if line.endswith('U {}'.format(function)):
|
|
|
|
raise AssertionError(
|
|
|
|
"Illegal use of dynamic memory function "
|
|
|
|
"'{function}'".format(function=function))
|
|
|
|
|
|
|
|
destr()
|
2019-02-27 12:59:00 +00:00
|
|
|
|
2019-03-01 12:18:41 +00:00
|
|
|
|
2019-02-27 12:59:00 +00:00
|
|
|
if __name__ == '__main__':
|
2019-07-29 09:38:25 +01:00
|
|
|
import sys
|
|
|
|
pytest.main(sys.argv)
|