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/omega-mv/blob/main/seed/trace/cli-gate.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / trace / cli-gate.sh` 169 lines ยท 6513 bytes Raw Blame History 1 #!/bin/sh 2 # seed/trace/cli-gate.sh: omega-mv #610 offline trace CLI. 3 # Run from the repository root: sh seed/trace/cli-gate.sh 4 # Checks seed/out/omc against seed/out/omc.sha256, compiles tracegen and tracecli, 5 # regenerates fixtures and pins their SHA-256, runs cli.cases against cli-golden, 6 # refuses a mode-0000 segment, and requires four source mutants to fail their own 7 # checks. The read-only mutant (ropen flags 32768 -> 32770) is caught by a literal 8 # scan of the exact return line in tracecli.om. An O_RDWR open of a mode-0400 file 9 # is not a reliable refusal for the owner, and verify uses segment.om's own open, 10 # so a functional open check would not catch that mutant. 11 set -eu 12 cd "$(dirname "$0")/../.." 13 14 bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } 15 16 sha256sum -c seed/out/omc.sha256 >/dev/null || bad "omc sha256" 17 [ "$(id -u)" != 0 ] || bad "mode-0000 check is meaningless as root" 18 19 ROPEN='ret fopen tpath 0 get tlen 0 32768 0' 20 ROPEN_MUT='ret fopen tpath 0 get tlen 0 32770 0' 21 scan_ropen() { 22 c=$(grep -c -x -F "$ROPEN" "$1" || true) 23 [ "$c" = 1 ] 24 } 25 scan_ropen seed/trace/tracecli.om || bad "ropen flags constant is not 32768 exactly once" 26 if grep -q -x -F "$ROPEN_MUT" seed/trace/tracecli.om; then 27 bad "ropen flags 32770 present in the good source" 28 fi 29 [ "$(grep -c -x 'ret 3' seed/trace/tracecli.om || true)" = 1 ] || bad "partial site not unique" 30 [ "$(grep -c -x 'ret same' seed/trace/tracecli.om || true)" = 1 ] || bad "same site not unique" 31 [ "$(grep -c -x -F 'if and ne get qtype 0 65536 ne t get qtype 0' seed/trace/tracecli.om || true)" = 1 ] || bad "qtype site not unique" 32 33 if [ -n "${OUT_DIR:-}" ]; then 34 B="$(pwd)/$OUT_DIR/trace-cli" 35 else 36 B="$(pwd)/build/seed/trace-cli" 37 fi 38 mkdir -p "$B" 39 compile() { 40 cat seed/trace/segment.om seed/trace/tsha.om "$1" | seed/out/omc > "$2" 41 [ "$(od -An -tx1 -N4 "$2" | tr -d ' ')" = `7f454c46` ] || bad "compile did not emit ELF: $1" 42 chmod 700 "$2" 43 } 44 compile seed/trace/tracegen.om "$B/tracegen" 45 compile seed/trace/tracecli.om "$B/tracecli" 46 47 ROOT=$(pwd) 48 D=$(mktemp -d "${TMPDIR:-/tmp}/trace-cli.XXXXXX") 49 cleanup() { 50 chmod -R u+rwx "$D" 2>/dev/null || true 51 rm -rf "$D" 52 } 53 trap cleanup EXIT 54 55 ( cd "$D" && "$B/tracegen" ) || bad "tracegen failed" 56 if ! ( cd "$D" && sha256sum -c "$ROOT/seed/trace/fixtures.sha256" > "$D/sha.out" ); then 57 cat "$D/sha.out" >&2 58 bad "fixture sha" 59 fi 60 [ "$(readlink "$D/fx/link.seg")" = a.seg ] || bad "link target" 61 for f in a b c crc torn magic; do 62 m=$(stat -c %a "$D/fx/$f.seg") 63 [ "$m" = 400 ] || bad "fixture $f mode $m want 400" 64 done 65 66 n=0 67 while IFS= read -r line || [ -n "$line" ]; do 68 case "$line" in ''|\#*) continue ;; esac 69 set -f 70 # shellcheck disable=SC2086 71 set -- $line 72 set +f 73 name=$1 74 want=$2 75 shift 2 76 out="$D/case.out" 77 err="$D/case.err" 78 set +e 79 ( cd "$D" && "$B/tracecli" "$@" ) > "$out" 2>"$err" 80 rc=$? 81 set -e 82 [ ! -s "$err" ] || { cat "$err" >&2; bad "case $name wrote stderr"; } 83 cmp -s "$out" "seed/trace/cli-golden/$name.txt" || bad "case $name stdout" 84 [ "$rc" = "$want" ] || bad "case $name exit $rc want $want" 85 n=$((n + 1)) 86 done < seed/trace/cli.cases 87 [ "$n" = 28 ] || bad "ran $n cases, need 28" 88 89 ( cd "$D" && "$B/tracecli" export fx/a.seg ) > "$D/export.out" 90 got=$(sha256sum "$D/fx/a.seg" | cut -d' ' -f1) 91 grep -q -F "# source sha256=$got " "$D/export.out" || bad "export hash != sha256sum" 92 93 cp "$D/fx/a.seg" "$D/fx/zero.seg" 94 chmod 000 "$D/fx/zero.seg" 95 for cmd in verify show events stats export; do 96 set +e 97 ( cd "$D" && "$B/tracecli" "$cmd" fx/zero.seg ) > "$D/zero.out" 2>"$D/zero.err" 98 rc=$? 99 set -e 100 [ ! -s "$D/zero.err" ] || bad "mode-0000 $cmd wrote stderr" 101 [ "$rc" = 4 ] || bad "mode-0000 $cmd exit $rc want 4" 102 cmp -s "$D/zero.out" seed/trace/cli-golden/zero-read.txt || bad "mode-0000 $cmd stdout" 103 done 104 chmod 644 "$D/fx/zero.seg" 105 rm -f "$D/fx/zero.seg" 106 printf 'mode-0000 refused by verify show events stats export\n' 107 108 # $1 dest $2 exact old line $3 exact new line. The old line must occur once 109 # and be gone afterwards. The new line may already occur; its count must rise by 1. 110 mut_swap() { 111 cp seed/trace/tracecli.om "$1" 112 o=$(grep -c -x -F "$2" "$1" || true) 113 before=$(grep -c -x -F "$3" "$1" || true) 114 [ "$o" = 1 ] || bad "mutant site count $o for: $2" 115 awk -v old="$2" -v new="$3" '($0 == old) { print new; next } { print }' "$1" > "$1.tmp" 116 mv "$1.tmp" "$1" 117 o=$(grep -c -x -F "$2" "$1" || true) 118 nn=$(grep -c -x -F "$3" "$1" || true) 119 [ "$o" = 0 ] || bad "mutant site survived: $2" 120 [ "$nn" = "$((before + 1))" ] || bad "mutant replacement count $nn want $((before + 1)) for: $3" 121 } 122 123 mut_swap "$D/mut-partial.om" 'ret 3' 'ret 0' 124 compile "$D/mut-partial.om" "$B/mut-partial" 125 set +e 126 ( cd "$D" && "$B/mut-partial" verify fx/crc.seg ) > "$D/mut.out" 2>"$D/mut.err" 127 rc=$? 128 set -e 129 [ ! -s "$D/mut.err" ] || bad "partial mutant wrote stderr" 130 cmp -s "$D/mut.out" seed/trace/cli-golden/verify-crc.txt || bad "partial mutant stdout" 131 [ "$rc" = 0 ] || bad "partial mutant exit $rc want 0" 132 printf 'caught mutant partial: verify crc exit 0 (need 3)\n' 133 134 mut_swap "$D/mut-same.om" 'ret same' 'ret true' 135 compile "$D/mut-same.om" "$B/mut-same" 136 set +e 137 ( cd "$D" && "$B/mut-same" compare fx/a.seg fx/b.seg ) > "$D/mut.out" 2>"$D/mut.err" 138 rc=$? 139 set -e 140 [ ! -s "$D/mut.err" ] || bad "same mutant wrote stderr" 141 grep -q -F 'compare differ at=0' "$D/mut.out" || bad "same mutant did not differ at 0" 142 if grep -q -F 'compare differ at=17' "$D/mut.out"; then 143 bad "same mutant still differs at 17" 144 fi 145 [ "$rc" = 1 ] || bad "same mutant exit $rc want 1" 146 printf 'caught mutant same: compare a b differ at=0 (need 17)\n' 147 148 mut_swap "$D/mut-qtype.om" 'if and ne get qtype 0 65536 ne t get qtype 0' 'if and ne get qtype 0 65536 eq t get qtype 0' 149 compile "$D/mut-qtype.om" "$B/mut-qtype" 150 set +e 151 ( cd "$D" && "$B/mut-qtype" events fx/a.seg --type 7 ) > "$D/mut.out" 2>"$D/mut.err" 152 rc=$? 153 set -e 154 [ ! -s "$D/mut.err" ] || bad "qtype mutant wrote stderr" 155 grep -q -F 'matched=40 of=40' "$D/mut.out" || bad "qtype mutant did not match all" 156 if grep -q -F 'matched=0 of=40' "$D/mut.out"; then 157 bad "qtype mutant still matched none" 158 fi 159 [ "$rc" = 0 ] || bad "qtype mutant exit $rc want 0" 160 printf 'caught mutant qtype: events --type 7 matched=40 (need 0)\n' 161 162 mut_swap "$D/mut-ropen.om" "$ROPEN" "$ROPEN_MUT" 163 compile "$D/mut-ropen.om" "$B/mut-ropen" 164 if scan_ropen "$D/mut-ropen.om"; then 165 bad "ropen mutant was not caught by the flag scan" 166 fi 167 printf 'caught mutant ropen: flag scan rejected 32770\n' 168 169 printf 'PASS tracecli %s cases, mode-0000 refused, 4 mutants caught\n' "$n"