From b36c4779a45281aa82899519e4ba46b8fd405b40 Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia-Ripoll Date: Wed, 27 Nov 2024 08:35:26 +0100 Subject: [PATCH] Fixed use of ASAN. libstd++ must be loaded with it --- scripts/make.py | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/scripts/make.py b/scripts/make.py index 873fa05..4fdeade 100644 --- a/scripts/make.py +++ b/scripts/make.py @@ -6,6 +6,7 @@ import subprocess incremental: bool = True +debug: bool = False use_sanitizer: str = "no" if "SANITIZE" not in os.environ else os.environ["SANITIZE"] ld_preload: str = "" valgrind: list[str] = [] @@ -30,6 +31,19 @@ def asan_library() -> str: ) +def cpp_library() -> str: + if sys.platform in ["win32", "cygwin"]: + return "" + else: + return run_output( + [ + "/bin/sh", + "-c", + r"ldconfig -p |grep stdc++ | sed 's/^\(.*=> \)\(.*\)$/\2/g' | sed '/^[[:space:]]*$/d'", + ] + ) + + def run_many(commands: list[list[str]], *args, chain: bool = True, **kwdargs) -> bool: ok = True for c in commands: @@ -75,13 +89,15 @@ def clean() -> None: delete_files([r".*\.so", r".*\.pyd", r".*\.pyc"]) -def check() -> bool: +def check(verbose=False) -> bool: env = os.environ.copy() if use_sanitizer != "no": - env["LD_PRELOAD"] = asan_library() + env["LD_PRELOAD"] = asan_library() + " " + cpp_library() + print(f"LD_PRELOAD={env['LD_PRELOAD']}") return run_many( [ - valgrind + [python, "-m", "unittest", "discover", "-f"], + valgrind + + [python, "-m", "unittest", "discover", "-fv" if verbose else "-f"], ["mypy", "src/seemps"], ["ruff", "check", "src"], ], @@ -94,6 +110,8 @@ def build() -> bool: extra = [] if use_sanitizer != "no": env["SANITIZE"] = use_sanitizer + if debug: + env["SEEMPS2DEBUG"] = "ON" if incremental: extra = ["--no-build-isolation", "-ve"] + extra return run(["pip", "install"] + extra + ["."], env=env) @@ -105,10 +123,24 @@ def install() -> bool: for option in sys.argv[1:]: match option: + case "debug": + debug = True case "here": incremental = True case "leak": use_sanitizer = "leak" + debug = True + case "memcheck": + valgrind = [ + "valgrind", + "--leak-check=full", + "--show-leak-kinds=all", + "--track-origins=yes", + "--verbose", + "--log-file=valgrind-out.txt", + ] + if not check(): + raise Exception("Tests failed") case "asan": use_sanitizer = "address" case "clean": @@ -122,5 +154,8 @@ def install() -> bool: case "check": if not check(): raise Exception("Tests failed") + case "vcheck": + if not check(True): + raise Exception("Tests failed") case _: raise Exception(f"Unknown option: {option}")