Skip to content

Commit

Permalink
Fixed use of ASAN. libstd++ must be loaded with it
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjosegarciaripoll committed Nov 27, 2024
1 parent 79a0cc3 commit b36c477
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions scripts/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand All @@ -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:
Expand Down Expand Up @@ -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"],
],
Expand All @@ -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)
Expand All @@ -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":
Expand All @@ -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}")

0 comments on commit b36c477

Please sign in to comment.