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 / share / mutants.sh

71 lines · 3303 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Mutation check for native/share/share.om. Each mutant replaces one exact span that must occur
4# exactly once ("\n" in a span is a newline). The host suite must fail on every mutant; a
5# surviving mutant fails this script. Called by run-share-host.sh with OMEGA_OMC set and pinned.
6set -eu
7: "${OMEGA_OMC:?set the pinned seeded compiler}"
8OUT=${ZERO_COPY_OUT:-build/zero-copy}
9mkdir -p "$OUT/mutants"
10test -s "$OUT/abi.om"
11
12# name|search|replace
13cat > "$OUT/mutants/list" <<'EOF'
14ro-dma-flag|fl = 33041|fl = 33040
15ro-uvm-type|kind = 3|kind = 1
16ro-cpu-access|r = mapbind m int fd 0 1|r = mapbind m int fd 0 3
17rw-cpu-access|r = mapbind m int fd 0 3|r = mapbind m int fd 0 1
18ro-map-flag|npput 44 1|npput 44 0
19probe-skipped|st = nvshmap obj size 4096 ro fd|st = long 32
20limit-not-erange|if eq st 46|if eq st 47
21larger-accepted|if eq st 0\nst = neg long 34|if eq st 1\nst = neg long 34
22dup-kept-on-refusal|if nvmrel slot\nput nverr 0 e\nend|put nverr 0 e
23dup-source-swapped|npput 12 nvshget 8\nnpput 16 nvshget 12|npput 12 nvshget 12\nnpput 16 nvshget 8
24share-mask-zero|npput 12 1\nnpput 16 2|npput 12 0\nnpput 16 2
25share-type-wrong|npput 12 1\nnpput 16 2|npput 12 1\nnpput 16 1
26want-unchecked|if ne size want|if ne size size
27reexport-allowed|if eq get nvshobj slot h|if ne h h
28unaligned-accepted|if ne and size 4095 0|if ne and size 0 0
29bound-raised|gt size 68719476736|gt size 137438953472
30magic-unchecked|if or ne nvshget 0 1129991503 ne nvshget 4 1|if ne nvshget 4 1
31record-size-page|nvshp64 16 get nvmlen slot|nvshp64 16 4096
32range-fault-dropped|r = uvmctl get nvfd 2 uint 73 nvpar 0 24\nif not nvos r npget 16\nput nvfault 0 1|r = uvmctl get nvfd 2 uint 73 nvpar 0 24\nif not nvos r npget 16
33gpu-skipped|if not nvshgpu slot ro\nret neg long 1\nend|put nvmflag slot 15
34EOF
35
36total=0
37caught=0
38while IFS='|' read -r name search replace; do
39 total=$((total + 1))
40 python3 - native/share/share.om "$OUT/mutants/$name.om" "$search" "$replace" <<'PY'
41import sys
42src, dst, search, replace = sys.argv[1:5]
43search = search.replace("\\n", "\n")
44replace = replace.replace("\\n", "\n")
45text = open(src).read()
46n = text.count(search)
47if n != 1:
48 sys.exit("mutant site found %d times: %r" % (n, search))
49open(dst, "w").write(text.replace(search, replace))
50PY
51 if cmp -s native/share/share.om "$OUT/mutants/$name.om"; then
52 echo "zero-copy mutant $name: FAIL identical to source" >&2
53 exit 1
54 fi
55 ZERO_COPY_OUT="$OUT/mutants/$name.d" ZERO_COPY_SHARE_SRC="$OUT/mutants/$name.om" \
56 ZERO_COPY_ABI="$OUT/abi.om" sh tests/share/run-share-host.sh --suite-only \
57 > "$OUT/mutants/$name.log" 2>&1 < /dev/null && rc=0 || rc=$?
58 if test "$rc" = 0; then
59 echo "zero-copy mutant $name: SURVIVED" >&2
60 exit 1
61 fi
62 # A mutant that does not compile proves nothing about the suite.
63 if ! grep -qx 'zero-copy: compiled' "$OUT/mutants/$name.log"; then
64 echo "zero-copy mutant $name: FAIL did not compile, see $OUT/mutants/$name.log" >&2
65 exit 1
66 fi
67 caught=$((caught + 1))
68 echo "zero-copy mutant $name: caught (rc $rc) $(grep -m1 FAIL "$OUT/mutants/$name.log" || true)"
69done < "$OUT/mutants/list"
70echo "zero-copy mutants: $caught/$total caught"
71test "$caught" = "$total"