Skip to content

Commit

Permalink
Test analyzer with asan and ubsan
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
mephi42 committed Aug 12, 2024
1 parent c2a2ebf commit ee9c5de
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
run: PATH=/usr/lib/ccache:$PATH ./ci
--skip-repair
-DVALGRIND_CONFIGURE_FLAGS=--disable-dependency-tracking
--sanitize

- name: Smoke test
run: python3 -m pip install --user dist/wheelhouse/*.whl &&
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
run: PATH=/usr/lib/ccache:$PATH ./ci
--skip-repair
-DVALGRIND_CONFIGURE_FLAGS=--disable-dependency-tracking
--sanitize

- name: Smoke test
run: python3 -m pip install --user dist/wheelhouse/*.whl &&
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ target_compile_options(
-Wconversion
-Wdate-time
-Wformat-security
-Wno-maybe-uninitialized
-pedantic
-Werror
-fstack-protector-strong
Expand Down
40 changes: 37 additions & 3 deletions ci
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def get_python_version(python):
)


def run_in_venv(venv, args):
def run_in_venv(venv, args, env=None):
subprocess.check_call(
[os.path.join(basedir, "run-in-venv"), venv, *args], cwd=basedir
[os.path.join(basedir, "run-in-venv"), venv, *args], cwd=basedir, env=env
)


Expand Down Expand Up @@ -142,6 +142,7 @@ def main():
"--wheel-dir",
default=os.path.join(basedir, "dist", "wheelhouse"),
)
parser.add_argument("--sanitize", action="store_true")
args, build_args = parser.parse_known_args()
if args.host != platform.machine():
build_args.extend(
Expand All @@ -150,6 +151,8 @@ def main():
f"-DCMAKE_SYSTEM_PROCESSOR={args.host}",
)
)
if args.sanitize:
build_args.append("-DCMAKE_CXX_FLAGS=-fsanitize=address,undefined")
build = os.path.join(basedir, "build", f"{platform.system()}-{args.host}")
build_prefix = "" if args.host_python is None else "build-"
cross_prefix = "" if args.host_python is None else "cross-"
Expand All @@ -166,7 +169,38 @@ def main():
*build_args,
],
)
run_in_venv(venv, ["python", "-m", "unittest", "discover"])
test_script = """\
from unittest.main import main
main(module=None, argv=["__main__.py", "discover"])
"""
if args.sanitize:
cc = os.environ.get("CC", "cc")
# https://github.com/google/sanitizers/issues/934
libstdcxx = (
subprocess.check_output([cc, "-print-file-name=libstdc++.so"])
.strip()
.decode()
)
libasan = (
subprocess.check_output([cc, "-print-file-name=libasan.so"])
.strip()
.decode()
)
test_env = {
**os.environ,
"ASAN_OPTIONS": "detect_leaks=0",
"LD_PRELOAD": os.pathsep.join((libasan, libstdcxx)),
}
test_script = (
"""\
import os
del os.environ["LD_PRELOAD"]
"""
+ test_script
)
else:
test_env = None
run_in_venv(venv, ["python", "-c", test_script], env=test_env)
build_wheel(
venv,
args.build_type,
Expand Down

0 comments on commit ee9c5de

Please sign in to comment.