From 611eceb062c0df535584aabefae702d1c2d02e91 Mon Sep 17 00:00:00 2001 From: Alisa Sireneva Date: Thu, 20 Jun 2024 11:55:03 +0300 Subject: [PATCH] Run code under sanitizers in tests --- .github/workflows/test.yml | 2 +- test.py | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 69bdc81..8c20b23 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: - run: | sudo dpkg --add-architecture i386 sudo apt-get update - sudo apt-get install g++-i686-linux-gnu + sudo apt-get install g++-i686-linux-gnu libasan6-i386-cross - uses: actions/setup-python@v5 with: python-version: "3.10" diff --git a/test.py b/test.py index 2840739..824604d 100644 --- a/test.py +++ b/test.py @@ -25,14 +25,22 @@ else: bench = False -if len(sys.argv) >= 2 and sys.argv[1] == "--cross": +def compile(source, target, blazingio): + if bench: + subprocess.run( + gcc + + [source, "-o", target, "-iquote", ".", f"-DBLAZINGIO=\"{blazingio}\"", "-std=c++17", "-O2", "-Wall", "-Werror"] + + ([] if bench else ["-fsanitize=address,pointer-compare,pointer-subtract,undefined"]), + check=True + ) + +if len(sys.argv) >= 2 and sys.argv[1] in ("--cross", "--cross-windows"): arch = sys.argv[2] - def compile(source, target, blazingio): - subprocess.run([f"{gcc_arch}-linux-gnu-g++", source, "-o", target, "-iquote", ".", f"-DBLAZINGIO=\"{blazingio}\"", "-std=c++17", "-O2", "-Wall", "-Werror"], check=True) -elif len(sys.argv) >= 2 and sys.argv[1] == "--cross-windows": - arch = sys.argv[2] - def compile(source, target, blazingio): - subprocess.run([f"{gcc_arch}-w64-mingw32-g++", "-static", source, "-o", target, "-iquote", ".", f"-DBLAZINGIO=\"{blazingio}\"", "-std=c++17", "-O2", "-Wall", "-Werror"], check=True) + gcc_arch = "i686" if arch == "i386" else arch + if sys.argv[1] == "--cross": + gcc = [f"{gcc_arch}-linux-gnu-g++"] + else: + gcc = [f"{gcc_arch}-w64-mingw32-g++", "-static"] elif len(sys.argv) >= 2 and sys.argv[1] == "--msvc": arch = sys.argv[2] def compile(source, target, blazingio): @@ -44,15 +52,11 @@ def compile(source, target, blazingio): os.environ["MSYSTEM"] = "UCRT64" else: arch = platform.machine() - def compile(source, target, blazingio): - subprocess.run(["g++", source, "-o", target, "-iquote", ".", f"-DBLAZINGIO=\"{blazingio}\"", "-std=c++17", "-O2", "-Wall", "-Werror"], check=True) - -if arch == "AMD64": - arch = "x86_64" -elif arch == "arm64": - arch = "aarch64" - -gcc_arch = "i686" if arch == "i386" else arch + if arch == "AMD64": + arch = "x86_64" + elif arch == "arm64": + arch = "aarch64" + gcc = ["g++"] def iterate_config(config, props = []):