Skip to content

Commit

Permalink
Run code under sanitizers in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesyringa committed Jun 20, 2024
1 parent 8657a6d commit 56e25ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 libubsan1:i386
- uses: actions/setup-python@v5
with:
python-version: "3.10"
Expand Down
46 changes: 29 additions & 17 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,46 @@
else:
bench = False

if len(sys.argv) >= 2 and sys.argv[1] == "--cross":
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":
disable_sanitizers = bench

def compile(source, target, blazingio):
subprocess.run(
gcc
+ [source, "-o", target, "-iquote", ".", f"-DBLAZINGIO=\"{blazingio}\"", "-std=c++17", "-O2", "-Wall", "-Werror"]
+ ([] if disable_sanitizers 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}-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"]
disable_sanitizers = True
elif len(sys.argv) >= 2 and sys.argv[1] == "--msvc":
arch = sys.argv[2]
def compile(source, target, blazingio):
subprocess.run([f"cl", source, "/I.", f"/DBLAZINGIO=\"{blazingio}\"", f"/Fe{target}", "/std:c++17", "/O2", "/EHsc", "/nologo", "/W2", "/WX"], check=True)
subprocess.run(
[f"cl", source, "/I.", f"/DBLAZINGIO=\"{blazingio}\"", f"/Fe{target}", "/std:c++17", "/O2", "/EHsc", "/nologo", "/W2", "/WX"]
+ ([] if disable_sanitizers else ["/fsanitize=address"]),
check=True
)
if "GITHUB_RUN_ID" in os.environ:
os.environ["CPP"] = "msys2 -c \"exec cpp $*\" cpp"
else:
os.environ["CPP"] = "C:\\msys64\\usr\\bin\\bash.exe -l -c \"exec cpp $*\" cpp"
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++"]
if platform.system() == "Windows":
disable_sanitizers = True


def iterate_config(config, props = []):
Expand Down

0 comments on commit 56e25ef

Please sign in to comment.