interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tests / api_shells_mutants.py

80 lines · 2718 bytes Raw Blame History
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3"""Recompile one semantic mutant at a time. Each must make the differential fail."""
4import os
5import subprocess
6import sys
7import tempfile
8
9ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
10MUTANTS = [
11 ("om/api/apish_shp.om",
12 "if eq rem k 512 0\nret ulong 16\n",
13 "if eq rem k 512 0\nret ulong 8\n",
14 "lane-16-to-8"),
15 ("om/api/apish_shp.om",
16 "if eq and lo mask 0\nret ulong 1\n",
17 "if eq and lo 0 0\nret ulong 1\n",
18 "alignok-always"),
19 ("om/api/apish_pack.om",
20 "ret 2143289344\n",
21 "ret 0\n",
22 "refb-nan-zero"),
23 ("om/api/apish_slot.om",
24 "bump rec 10\nret -6\nend\nput rec 0 1\n",
25 "bump rec 10\nret 0\nend\nput rec 0 1\n",
26 "slot-busy-ok"),
27 ("om/api/apish_shp.om",
28 "if eq ww 16\nret ulong 128\nend\nret ulong 64\n",
29 "if eq ww 16\nret ulong 128\nend\nret ulong 32\n",
30 "tgbm-64-to-32"),
31 ("om/api/apish_shp.om",
32 "ret ulong mul div add n 7 8 8\n",
33 "ret ulong n\n",
34 "pad8-no-round"),
35 ("om/api/apish_shp.om",
36 "if ne rem p 256 0\nret ulong 1\n",
37 "if ne rem p 256 0\nret ulong 0\n",
38 "dsplit-bad-align-ok"),
39 ("om/api/apish_shp.om",
40 "if gt m 32768\nret ulong 1\n",
41 "if gt m 32769\nret ulong 1\n",
42 "pa256-bound-off-by-one"),
43]
44
45
46def main() -> int:
47 script = os.path.join(ROOT, "tests", "api_shells_run.sh")
48 killed = 0
49 for path, old, new, name in MUTANTS:
50 full = os.path.join(ROOT, path)
51 with open(full) as fh:
52 src = fh.read()
53 count = src.count(old)
54 if count != 1:
55 print(f"FAIL mutant {name}: site count {count}")
56 return 1
57 with tempfile.TemporaryDirectory(prefix="api-shells-mutant-") as out:
58 mutant = os.path.join(out, os.path.basename(path))
59 with open(mutant, "w") as fh:
60 fh.write(src.replace(old, new, 1))
61 env = dict(os.environ, OUT_DIR=out, API_SHELLS_MUTANT=mutant)
62 r = subprocess.run(
63 ["bash", script, "regen"], cwd=ROOT, env=env,
64 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,
65 )
66 if r.returncode != 1 or "FAIL api-shells checks=" not in r.stdout:
67 print(f"FAIL mutant {name}: expected a differential mismatch, "
68 f"got rc={r.returncode}\n{r.stdout[-400:]}")
69 return 1
70 print(f"KILLED {name} rc={r.returncode}")
71 killed += 1
72 if killed < 6:
73 print(f"FAIL only {killed} mutants")
74 return 1
75 print(f"PASS mutants killed={killed}")
76 return 0
77
78
79if __name__ == "__main__":
80 sys.exit(main())