omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / omc / sitecov.sh
| 1 | #!/bin/sh |
| 2 | # sitecov.sh -- which omc error sites does some refused input in the repository actually reach? |
| 3 | # (ROADMAP-1.0 RM8: "a coverage check lists any emitting site without a fixture".) |
| 4 | # Method (mutation, no instrumentation): every whole line "fail N", "nfail N" or "unkfail N" in |
| 5 | # seed/omc/omc.om is one site. For each site, a copy of omc.om with only that line's code changed to |
| 6 | # 97 (no real code) is compiled by seed/out/omc. The inputs are every tracked .om file and every gate15 |
| 7 | # case that seed/out/omc refuses. A site is reached when some input that the real omc refuses with code |
| 8 | # N makes the mutant exit 97. Only inputs refused with N are tried for a site of code N: an input stops |
| 9 | # at the first site it reaches, so one that exits with another code cannot reach this one. |
| 10 | # Sound for "reached" (the mutant's own exit proves it); a site listed as unreached may still be |
| 11 | # reachable by a program the repository does not contain. |
| 12 | # Lines whose code is a name (fail code in nfail/unkfail, fail eolc in lenval) are not sites: nfail and |
| 13 | # unkfail callers are counted as their own lines, but lenval's end-of-line refusal (16 or 4) is not counted. |
| 14 | # Usage: sh seed/omc/sitecov.sh [check] [OUT_DIR] (from the repository root; default build/seed/sitecov) |
| 15 | # With "check", it also fails when fewer sites are reached than seed/omc/sitecov.floor records, so a |
| 16 | # deleted fixture or a site moved out of reach is seen; raise the floor when new fixtures land. |
| 17 | # Writes OUT/sites.tsv (line, function, word, code, reached-by input or "-") and prints |
| 18 | # SITECOV sites=S reached=R unreached=U inputs=I |
| 19 | set -eu |
| 20 | ck=0; [ "${1:-}" = check ] && { ck=1; shift; } |
| 21 | R=$(pwd); S=$R/seed/out/omc; O=${1:-$R/build/seed/sitecov} |
| 22 | [ -x "$S" ] || { echo "sitecov: $S missing; run sh seed/omega-from-seed.sh" >&2; exit 2; } |
| 23 | rm -rf "$O"; mkdir -p "$O/in" "$O/m" |
| 24 | bad() { echo "SITECOV FAIL $*" >&2; exit 1; } |
| 25 | # inputs: tracked .om files and gate15 cases the real compiler refuses, filed by exit code |
| 26 | i=0 |
| 27 | add() { # add FILE ORIGIN |
| 28 | set +e; "$S" < "$1" > /dev/null 2>&1; rc=$?; set -e |
| 29 | [ "$rc" -gt 0 ] && [ "$rc" -lt 97 ] || return 0 |
| 30 | i=$((i + 1)); mkdir -p "$O/in/$rc"; cp "$1" "$O/in/$rc/$i.om"; printf '%s\t%s\n' "$i" "$2" >> "$O/inputs.tsv" |
| 31 | } |
| 32 | : > "$O/inputs.tsv" |
| 33 | git ls-files '*.om' > "$O/files" |
| 34 | while read -r f; do add "$f" "$f"; done < "$O/files" |
| 35 | awk "/<<'CASES'/{f=1;next} /^CASES\$/{f=0} f" seed/omc/gate15.sh > "$O/g15" |
| 36 | [ "$(grep -c '|' "$O/g15")" -ge 20 ] || bad "read too few gate15 cases" |
| 37 | while IFS='|' read -r name want line src; do |
| 38 | [ -n "$name" ] || continue |
| 39 | printf '%b\n' "$src" > "$O/g.om"; add "$O/g.om" "gate15:$name" |
| 40 | done < "$O/g15" |
| 41 | # sites |
| 42 | awk '/^fn /{fn=$2} /^(fail|nfail|unkfail) [0-9]+$/{print NR "\t" fn "\t" $1 "\t" $2}' seed/omc/omc.om > "$O/sitelist" |
| 43 | [ -s "$O/sitelist" ] || bad "no sites found" |
| 44 | : > "$O/sites.tsv" |
| 45 | while IFS=' ' read -r ln fn w code; do |
| 46 | by=- |
| 47 | if [ -d "$O/in/$code" ]; then |
| 48 | awk -v L="$ln" -v W="$w" 'NR == L { print W " 97"; next } { print }' seed/omc/omc.om > "$O/m.om" |
| 49 | "$S" < "$O/m.om" > "$O/m/omc" 2> "$O/m.err" || bad "mutant at line $ln does not compile: $(cat "$O/m.err")" |
| 50 | chmod +x "$O/m/omc" |
| 51 | for x in "$O/in/$code"/*.om; do |
| 52 | set +e; "$O/m/omc" < "$x" > /dev/null 2>&1; rc=$?; set -e |
| 53 | if [ "$rc" = 97 ]; then by=$(basename "$x" .om); break; fi |
| 54 | done |
| 55 | fi |
| 56 | [ "$by" = - ] || by=$(awk -F'\t' -v k="$by" '$1 == k { print $2 }' "$O/inputs.tsv") |
| 57 | printf '%s\t%s\t%s\t%s\t%s\n' "$ln" "$fn" "$w" "$code" "$by" >> "$O/sites.tsv" |
| 58 | done < "$O/sitelist" |
| 59 | s=$(grep -c '' "$O/sites.tsv"); u=$(awk -F'\t' '$5 == "-"' "$O/sites.tsv" | grep -c '') || u=0 |
| 60 | printf 'SITECOV sites=%s reached=%s unreached=%s inputs=%s\n' "$s" $((s - u)) "$u" "$i" |
| 61 | if [ "$ck" = 1 ]; then |
| 62 | fl=$(cat "$R/seed/omc/sitecov.floor") |
| 63 | [ $((s - u)) -ge "$fl" ] || bad "reached $((s - u)) is below the floor $fl (seed/omc/sitecov.floor)" |
| 64 | printf 'SITECOV PASS reached=%s floor=%s\n' $((s - u)) "$fl" |
| 65 | fi |