Skip to content

Commit

Permalink
Attempt GCC-analyzer (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomwiggers committed Apr 28, 2023
1 parent c1b19a8 commit 45a0635
Showing 1 changed file with 68 additions and 45 deletions.
113 changes: 68 additions & 45 deletions test/test_functest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import os
import platform
import sys
import unittest

import pytest
Expand All @@ -14,45 +15,57 @@


@pytest.mark.parametrize(
'implementation,test_dir,impl_path, init, destr',
[(impl, *helpers.isolate_test_files(impl.path(), 'test_functest_'))
for impl in pqclean.Scheme.all_supported_implementations()],
"implementation,test_dir,impl_path, init, destr",
[
(impl, *helpers.isolate_test_files(impl.path(), "test_functest_"))
for impl in pqclean.Scheme.all_supported_implementations()
],
ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
)
@helpers.filtered_test
def test_functest(implementation, impl_path, test_dir,
init, destr):
def test_functest(implementation, impl_path, test_dir, init, destr):
init()
dest_dir = os.path.join(test_dir, 'bin')
helpers.make('functest',
TYPE=implementation.scheme.type,
SCHEME=implementation.scheme.name,
IMPLEMENTATION=implementation.name,
SCHEME_DIR=impl_path,
DEST_DIR=dest_dir,
working_dir=os.path.join(test_dir, 'test'))
flags = ""
if os.environ.get("CC", "gcc") == "gcc" and sys.platform == "linux":
flags = "-fanalyzer"
dest_dir = os.path.join(test_dir, "bin")
helpers.make(
"functest",
TYPE=implementation.scheme.type,
SCHEME=implementation.scheme.name,
IMPLEMENTATION=implementation.name,
SCHEME_DIR=impl_path,
DEST_DIR=dest_dir,
EXTRAFLAGS=flags,
working_dir=os.path.join(test_dir, "test"),
)
helpers.run_subprocess(
[os.path.join(dest_dir, 'functest_{}_{}{}'.format(
implementation.scheme.name,
implementation.name,
'.exe' if os.name == 'nt' else ''
))],
[
os.path.join(
dest_dir,
"functest_{}_{}{}".format(
implementation.scheme.name,
implementation.name,
".exe" if os.name == "nt" else "",
),
)
],
)
destr()


@pytest.mark.parametrize(
'implementation,test_dir,impl_path, init, destr',
[(impl,
*helpers.isolate_test_files(impl.path(), 'test_functest_sanitizers_'))
for impl in pqclean.Scheme.all_supported_implementations()],
"implementation,test_dir,impl_path, init, destr",
[
(impl, *helpers.isolate_test_files(impl.path(), "test_functest_sanitizers_"))
for impl in pqclean.Scheme.all_supported_implementations()
],
ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
)
@helpers.skip_windows()
@helpers.filtered_test
def test_functest_sanitizers(implementation, impl_path, test_dir,
init, destr):
dest_dir = os.path.join(test_dir, 'bin')
def test_functest_sanitizers(implementation, impl_path, test_dir, init, destr):
dest_dir = os.path.join(test_dir, "bin")
env = None
if platform.machine() == 'ppc' and 'clang' in os.environ.get('CC', 'gcc'):
raise unittest.SkipTest("Clang does not support ASAN on ppc")
Expand All @@ -69,31 +82,41 @@ def test_functest_sanitizers(implementation, impl_path, test_dir,

init()

helpers.make('clean-scheme', 'functest',
TYPE=implementation.scheme.type,
SCHEME=implementation.scheme.name,
IMPLEMENTATION=implementation.name,
EXTRAFLAGS=(
'-g -fsanitize=address,undefined '
'-fno-sanitize-recover=undefined '
# TODO(JMS) Remove explicit -latomic if/when gcc fixes:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358
'-Wno-unused-command-line-argument -latomic'),
SCHEME_DIR=impl_path,
DEST_DIR=dest_dir,
working_dir=os.path.join(test_dir, 'test'),
env=env)
helpers.make(
"clean-scheme",
"functest",
TYPE=implementation.scheme.type,
SCHEME=implementation.scheme.name,
IMPLEMENTATION=implementation.name,
EXTRAFLAGS=(
"-g -fsanitize=address,undefined "
"-fno-sanitize-recover=undefined "
# TODO(JMS) Remove explicit -latomic if/when gcc fixes:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358
"-Wno-unused-command-line-argument -latomic"
),
SCHEME_DIR=impl_path,
DEST_DIR=dest_dir,
working_dir=os.path.join(test_dir, "test"),
env=env,
)
helpers.run_subprocess(
[os.path.join(dest_dir, 'functest_{}_{}{}'.format(
implementation.scheme.name,
implementation.name,
'.exe' if os.name == 'nt' else ''
))],
[
os.path.join(
dest_dir,
"functest_{}_{}{}".format(
implementation.scheme.name,
implementation.name,
".exe" if os.name == "nt" else "",
),
)
],
env=env,
)
destr()


if __name__ == '__main__':
if __name__ == "__main__":
import sys

pytest.main(sys.argv)

0 comments on commit 45a0635

Please sign in to comment.