dymokomi/luce-compress
Source of release 0.9.0
#!/usr/bin/env python3
"""Run the native API and complete independent oracle with ASan and UBSan."""
import argparse
import os
from pathlib import Path
import subprocess
from check_codecs import check
from check_stream import check as check_stream
from check_git import check as check_git
from check_encode import check as check_encode
from check_work import check as check_work
from check_stress import check as check_stress
from check_fuzz import check as check_fuzz
from check_large import check as check_large
from check_brotli import check as check_brotli
from check_gzip import check as check_gzip
ROOT = Path(__file__).resolve().parents[1]
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--base", type=Path, default=ROOT / "build/toolchain/luce-base")
args = parser.parse_args()
output = ROOT / "build/sanitize"
output.mkdir(parents=True, exist_ok=True)
runtime = ROOT.parent / "luce-base/runtime"
os.environ.setdefault("LUCE_STD", str(ROOT.parent / "luce-base/src/std"))
os.environ.setdefault("LUCE_CACHE", str(ROOT / "build/cache"))
os.environ["ASAN_OPTIONS"] = "halt_on_error=1:abort_on_error=1"
os.environ["UBSAN_OPTIONS"] = "halt_on_error=1:print_stacktrace=1"
def run(command):
subprocess.run([str(arg) for arg in command], cwd=ROOT, check=True, timeout=180)
for source, name in [(ROOT / "src/native_tests.lucb", "native"), (ROOT / "tests/driver.lucb", "driver"),
(ROOT / "src/stream_tests.lucb", "stream-tests"), (ROOT / "tests/stream_driver.lucb", "stream-driver"),
(ROOT / "src/encoder_tests.lucb", "encoder-tests"), (ROOT / "tests/encode_driver.lucb", "encode-driver"),
(ROOT / "src/failure_tests.lucb", "failure-tests"),
(ROOT / "src/work_tests.lucb", "work-tests"),
(ROOT / "tests/stress_driver.lucb", "stress-driver"),
(ROOT / "src/fuzz_tests.lucb", "fuzz-driver"),
(ROOT / "tests/file_driver.lucb", "file-driver"),
(ROOT / "tools/codec_tool.lucb", "codec-tool")]:
generated, executable = output / f"{name}.c", output / name
run([args.base.resolve(), "build", source, "--emit=c", "-o", generated])
run([os.environ.get("CC", "cc"), "-std=gnu11", "-O1", "-g", "-w", "-fno-strict-aliasing",
"-fsanitize=address,undefined", "-fno-omit-frame-pointer", "-I", runtime,
generated, runtime / "lucb_rt.c", "-pthread", "-lm", "-o", executable])
if name in ["native", "stream-tests", "encoder-tests", "failure-tests", "work-tests"]:
run([executable])
elif name == "driver":
check(executable)
elif name == "stream-driver":
check_stream(executable)
check_git(executable)
elif name == "encode-driver":
check_encode(executable)
elif name == "stress-driver":
check_stress(executable, instrumented=True)
elif name == "fuzz-driver":
check_fuzz(executable)
elif name == "codec-tool":
check_brotli(executable)
check_gzip(executable)
else:
check_large(executable)
check_work(output / "stream-driver", output / "encode-driver")
print("PASS AddressSanitizer + UndefinedBehaviorSanitizer", flush=True)
if __name__ == "__main__":
main()