2019-02-28 13:05:55 +00:00
|
|
|
"""
|
|
|
|
Runs the test files under valgrind to detect memory problems
|
|
|
|
"""
|
|
|
|
|
2019-09-05 09:08:42 +01:00
|
|
|
import functools
|
2019-02-28 13:05:55 +00:00
|
|
|
import os
|
|
|
|
import platform
|
2019-09-05 09:08:42 +01:00
|
|
|
import re
|
2019-02-28 13:05:55 +00:00
|
|
|
import unittest
|
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
import pytest
|
2019-02-28 13:05:55 +00:00
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
import helpers
|
|
|
|
import pqclean
|
2019-02-28 13:05:55 +00:00
|
|
|
|
|
|
|
|
2019-09-05 09:08:42 +01:00
|
|
|
@functools.lru_cache()
|
|
|
|
def valgrind_supports_exit_early():
|
|
|
|
"""Checks if we support early exit from valgrind"""
|
|
|
|
version = helpers.run_subprocess(['valgrind', '--version'])
|
|
|
|
match = re.match(r'valgrind-(\d)\.(\d+).*', version)
|
|
|
|
if match:
|
|
|
|
return int(match.group(2)) >= 14
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'implementation,test_dir,impl_path, init, destr',
|
2019-12-09 08:59:28 +00:00
|
|
|
[(impl, *helpers.isolate_test_files(impl.path(), 'test_valgrind_'))
|
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-04-17 10:17:46 +01:00
|
|
|
@helpers.slow_test
|
2019-04-18 09:00:08 +01:00
|
|
|
@helpers.filtered_test
|
2019-07-29 09:38:25 +01:00
|
|
|
def test_valgrind(implementation: pqclean.Implementation, impl_path, test_dir,
|
|
|
|
init, destr):
|
2019-02-28 13:05:55 +00:00
|
|
|
if (platform.machine() not in ('i386', 'x86_64') or
|
|
|
|
platform.system() != 'Linux'):
|
|
|
|
raise unittest.SkipTest()
|
2019-07-29 09:38:25 +01:00
|
|
|
init()
|
|
|
|
|
|
|
|
dest_dir = os.path.join(test_dir, 'bin')
|
2019-02-28 13:05:55 +00:00
|
|
|
|
|
|
|
helpers.make(TYPE=implementation.scheme.type,
|
|
|
|
SCHEME=implementation.scheme.name,
|
2019-07-29 09:38:25 +01:00
|
|
|
SCHEME_DIR=os.path.abspath(impl_path),
|
2019-02-28 13:05:55 +00:00
|
|
|
IMPLEMENTATION=implementation.name,
|
2019-07-29 09:38:25 +01:00
|
|
|
DEST_DIR=dest_dir,
|
2020-02-11 10:15:14 +00:00
|
|
|
EXTRAFLAGS="-g3",
|
2019-07-29 14:25:41 +01:00
|
|
|
NTESTS=1,
|
2019-07-29 09:38:25 +01:00
|
|
|
working_dir=os.path.join(test_dir, 'test'))
|
2019-02-28 13:05:55 +00:00
|
|
|
functest_name = './functest_{}_{}'.format(implementation.scheme.name,
|
|
|
|
implementation.name)
|
2019-09-05 09:08:42 +01:00
|
|
|
helpers.run_subprocess(
|
|
|
|
['valgrind',
|
|
|
|
'--error-exitcode=1',
|
2020-02-19 20:44:02 +00:00
|
|
|
'--leak-check=yes',
|
2019-09-05 09:08:42 +01:00
|
|
|
*(['--exit-on-first-error=yes']
|
|
|
|
if valgrind_supports_exit_early()
|
|
|
|
else []),
|
|
|
|
'--max-stackframe=20933064',
|
2019-09-10 10:45:01 +01:00
|
|
|
'--vex-guest-max-insns=25',
|
2019-09-05 09:08:42 +01:00
|
|
|
functest_name],
|
|
|
|
dest_dir)
|
2019-07-29 09:38:25 +01:00
|
|
|
destr()
|
2019-02-28 13:05:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-07-29 09:38:25 +01:00
|
|
|
import sys
|
|
|
|
pytest.main(sys.argv)
|