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 / mutation_runner_json_test.sh

49 lines · 2361 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Regression: tools/mutation_runner.sh must write a receipt that parses as JSON
6# and round-trips every string losslessly, including quotes, backslashes, tabs,
7# control bytes and a multi-line build-failure note. Before the fix the guards
8# text was inserted raw and the note had quotes/backslashes deleted.
9set -u
10here=$(cd "$(dirname "$0")/.." && pwd)
11t=$(mktemp -d "${TMPDIR:-/tmp}/mrjson.XXXXXX") || exit 1
12trap 'rm -rf "$t"' EXIT INT TERM
13mkdir -p "$t/src"
14printf 'value 1\n' > "$t/src/a.txt"
15tab=$(printf '\t'); esc=$(printf '\033'); bel=$(printf '\007')
16guards="checks \"q >= 1\" and back\\slash${tab}tab ${esc}[esc ${bel}bel"
17printf '%s\n' "M_KILL~a.txt~s/value 1/value 2/~$guards" "M_BUILD~a.txt~s/value 1/value 3/~build \"breaks\"" > "$t/rows"
18# The build fails only for mutant M_BUILD, with an error line holding quotes and a backslash.
19build='if grep -q "value 3" a.txt; then echo "x.c:1: error: bad \"tok\" \\ here"; exit 1; fi'
20sh "$here/tools/mutation_runner.sh" -k table -m "$t/rows" -d "$t/src" -b "$build" \
21 -t 'grep -q "value 1" a.txt' -o "$t/out.json" >"$t/log" 2>&1
22GUARDS=$guards python3 - "$t/out.json" <<'PY' || { echo "mutation runner JSON: FAIL"; exit 1; }
23import json, os, sys
24try:
25 d = json.load(open(sys.argv[1]))
26except ValueError as e:
27 print("receipt does not parse:", e); sys.exit(1)
28m = {r["id"]: r for r in d["mutants"]}
29want = {
30 ("M_KILL", "checks"): os.environ["GUARDS"],
31 ("M_KILL", "status"): "KILLED",
32 ("M_BUILD", "checks"): 'build "breaks"',
33 ("M_BUILD", "status"): "ERROR",
34 ("M_BUILD", "note"): 'build failed: x.c:1: error: bad "tok" \\ here',
35}
36bad = [(k, m.get(k[0], {}).get(k[1]), v) for k, v in want.items() if m.get(k[0], {}).get(k[1]) != v]
37for b in bad: print("mismatch", b)
38sys.exit(1 if bad else 0)
39PY
40# A receipt destination that cannot be opened must fail before running mutants.
41if sh "$here/tools/mutation_runner.sh" -k table -m "$t/rows" -d "$t/src" \
42 -t 'touch ran; exit 1' -o "$t/missing/out.json" >"$t/unwritable.log" 2>&1; then
43 echo "mutation runner JSON: FAIL (unwritable receipt accepted)"
44 exit 1
45else
46 rc=$?
47 [ "$rc" -eq 2 ] || { echo "mutation runner JSON: FAIL (receipt exit $rc)"; exit 1; }
48fi
49echo "mutation runner JSON: PASS"