Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/test_core_mutants.py # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / test_core_mutants.py` 76 lines · 3630 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 """Recompile seven semantic Omega mutants; compilation failure is not a kill.""" 4 import argparse 5 import hashlib 6 import os 7 from pathlib import Path 8 import shlex 9 import subprocess 10 import tempfile 11 12 ROOT = Path(__file__).resolve().parents[1] 13 MUTANTS = ( 14 ("initial-state", "putle c 0 4 `1779033703`", "putle c 0 4 `1779033702`"), 15 ("round-constant", "t = add x add get w 0 `1116352408`", "t = add x add get w 0 `1116352409`"), 16 ("padding-marker", "put c add 40 bi 128", "put c add 40 bi 129"), 17 ("two-block-padding", "zbuf c add bi 1 64\nif ge bi 56", "zbuf c add bi 1 64\nif ge bi 57"), 18 ("message-bit-count", "bits = mul cnt 8", "bits = mul cnt 7"), 19 ("length-byte-order", "sh = mul sub 7 i 8", "sh = mul i 8"), 20 ("one-shot-two-block", "if ge r 56", "if ge r 57"), 21 ) 22 23 24 def run(command, log, env=None): 25 result = subprocess.run(command, cwd=ROOT, env=env, stdout=subprocess.PIPE, 26 stderr=subprocess.STDOUT, text=True, timeout=300) 27 log.write("$ " + shlex.join(map(str, command)) + "\n" + result.stdout) 28 log.write(f"rc={result.returncode}\n") 29 log.flush() 30 return result 31 32 33 def require(condition, detail): 34 if not condition: 35 raise RuntimeError(detail) 36 37 38 def main(): 39 parser = argparse.ArgumentParser() 40 parser.add_argument("--out-dir", default="build") 41 parser.add_argument("--receipt", required=True) 42 args = parser.parse_args() 43 receipt = ROOT / args.receipt 44 receipt.mkdir(parents=True, exist_ok=True) 45 out_dir = ROOT / args.out_dir 46 source = (ROOT / "om/core/sha256.om").read_text() 47 with (receipt / "baseline.log").open("w") as log: 48 require(run([str(out_dir / "test-core-util"), "--quick"], log).returncode == 0, "baseline") 49 for name, before, after in MUTANTS: 50 require(source.count(before) == 1, (name, "mutation site is not unique")) 51 changed = source.replace(before, after) 52 with tempfile.TemporaryDirectory(prefix="core-util-mutant-") as temp: 53 temp = Path(temp) 54 om = temp / "mutant.om" 55 om.write_text(changed) 56 env = dict(os.environ, OMEGA_UNITS=f"core_sha={om}", OMEGA_UNITS_DEST=str(temp)) 57 with (receipt / (name + ".log")).open("w") as log: 58 log.write(f"source-sha256={hashlib.sha256(changed.encode()).hexdigest()}\n") 59 log.write(f"replace {before!r} -> {after!r}\n") 60 require(run(["sh", "om/units.sh"], log, env).returncode == 0, (name, "generation")) 61 command = shlex.split(os.environ.get("CC", "cc")) + [ 62 "-std=gnu11", "-D_GNU_SOURCE", "-O2", "-Wall", "-Wextra", "-Werror", 63 "-Isrc", "tests/test_core_util.c", "src/sha256.c", 64 str(out_dir / "core-util-sha-ref.o"), str(temp / "cudapp_om_core_sha.c"), 65 "-lpthread", "-o", str(temp / "test-mutant")] 66 require(run(command, log).returncode == 0, (name, "compilation")) 67 result = run([str(temp / "test-mutant"), "--quick"], log) 68 require(result.returncode == 1 and "SHA vector length " in result.stdout, (name, "not killed by digest comparison")) 69 (receipt / (name + ".ident")).write_text((temp / "cudapp_om_core_sha.ident").read_text()) 70 log.write("KILLED: compiled mutant disagrees with FIPS digest\n") 71 print(f"CORE-UTIL mutant {name} KILLED", flush=True) 72 print(f"CORE-UTIL mutants PASS: {len(MUTANTS)} recompiled semantic mutants killed") 73 74 75 if __name__ == "__main__": 76 main()