interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / trace / gate.sh

60 lines · 3005 bytes Raw Blame History
1#!/bin/sh
2# seed/trace/gate.sh -- host gate for the local trace segment (omega-mv #608).
3# Run from anywhere: sh seed/trace/gate.sh
4# Compiles segment.om + segment-test.om with seed/out/omc (sha checked against seed/out/omc.sha256), runs
5# the test in a fresh scratch directory and requires exit 0 and stdout equal to expected.txt byte for byte.
6# The expected values (sizes, offsets, CRC check value, flags) were computed in Wolfram Language; see
7# README.md. Then each source mutant (a literal swap of a line that must occur exactly once in segment.om)
8# must compile, exit 1, and fail on its own check label:
9# crc record CRC no longer compared -> crc-reason FAIL
10# torn partial tail not reported as torn -> torn-reason FAIL
11# align append ignores a misaligned tail -> torn-append-refused FAIL
12# excl create opens with O_TRUNC, not O_EXCL -> create-again-refused FAIL
13# Prints PASS trace and exits 0, or FAIL and exits 1.
14set -eu
15R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
16cd "$R"
17D=seed/trace
18B=build/seed/trace
19rm -rf "$B"
20mkdir -p "$B"
21bad() { printf 'FAIL trace: %s\n' "$*" >&2; exit 1; }
22
23want=$(cut -c1-64 seed/out/omc.sha256)
24have=$(sha256sum < seed/out/omc | cut -c1-64)
25[ "$want" = "$have" ] || bad "seed/out/omc is $have, omc.sha256 says $want"
26OMC="$R/seed/out/omc"
27
28# run NAME SRC: compile SRC to $B/NAME/t, run it inside $B/NAME, stdout to $B/NAME/out.txt, sets rc
29run() {
30 mkdir -p "$B/$1"
31 "$OMC" < "$2" > "$B/$1/t" || bad "omc refused $2"
32 chmod 700 "$B/$1/t"
33 rc=0
34 (cd "$B/$1" && ./t > out.txt) || rc=$?
35}
36
37cat "$D/segment.om" "$D/segment-test.om" > "$B/test.om"
38run main "$B/test.om"
39printf 'omc %s\nsegment-test %s\n' "$have" "$(sha256sum < "$B/main/t" | cut -c1-64)"
40[ "$rc" -eq 0 ] || { cat "$B/main/out.txt" >&2; bad "segment-test exited $rc"; }
41cmp -s "$B/main/out.txt" "$D/expected.txt" || { diff "$D/expected.txt" "$B/main/out.txt" >&2 || true; bad "output differs from expected.txt"; }
42
43n=0
44mutant() { # NAME SITE REPLACEMENT LABEL
45 c=$(grep -c -x -F "$2" "$D/segment.om" || true)
46 [ "$c" = 1 ] || bad "mutant $1: site found $c times"
47 awk -v s="$2" -v r="$3" '$0 == s { print r; next } { print }' "$D/segment.om" > "$B/$1.om"
48 cmp -s "$B/$1.om" "$D/segment.om" && bad "mutant $1: source unchanged"
49 cat "$B/$1.om" "$D/segment-test.om" > "$B/$1-test.om"
50 run "$1" "$B/$1-test.om"
51 [ "$rc" -eq 1 ] || bad "mutant $1 exited $rc, need 1"
52 grep -q "^$4 [0-9]* FAIL want=" "$B/$1/out.txt" || bad "mutant $1 did not fail $4"
53 echo "mutant $1: exit 1, $4 FAIL"
54 n=$((n + 1))
55}
56mutant crc 'if ne want segcrc 60' 'if ne want want' crc-reason
57mutant torn 'put sreason 0 1' 'put sreason 0 0' torn-reason
58mutant align 'if ne rem r 64 0' 'if ne rem r 1 0' torn-append-refused
59mutant excl 'fd = fopen tpath 0 get tlen 0 32961 384' 'fd = fopen tpath 0 get tlen 0 33345 384' create-again-refused
60printf 'PASS trace %s checks, %s/4 mutants caught\n' "$(sed -n 's/^segment-test checks=\([0-9]*\) fails=0$/\1/p' "$B/main/out.txt")" "$n"