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 / check / nextfuzz.sh

49 lines · 3742 bytes Raw Blame History
1#!/bin/sh
2# nextfuzz.sh N REF [OTHER] -- the next-word fuzz over the om4 words (decision 22, OMEGESE.md section 9).
3# N random programs from nextgen.awk (seeds 1..N): REF must accept each. Then each program cut after every
4# word, and each program with one word replaced by a word from the vocabulary (one per word place): REF
5# must answer every input with exit 0 or an error number on stderr, never a crash (a signal, exit >= 128);
6# with OTHER given, OTHER must give the same bytes, exit status and error number (prefix om4/omc aside).
7# The vocabulary's one over-long name has 64 bytes: om4 refuses names over 8 bytes and omc names over 63
8# (error 13 from both), so the 9..63-byte names omc accepts beyond om4 are not fuzzed here (gate5 section 3 lists them).
9# The vocabulary carries enlarge and * (run-time pools, OMEGESE 9.15; om4 knows global NAME T *, get, put, len and
10# r = enlarge P n), so a changed word can make a pool or an enlarge anywhere.
11# envcnt and envread too (om4 learned them for the OMC_MEMORY_MAX reader of omc.om).
12set -eu
13N=$1; REF=$2; OTH=${3:-}; D=$(dirname "$0"); W=${NFW:-/tmp/nextfuzz.$$}; mkdir -p $W
14V="fn to end enlarge * envcnt envread if else while bound for ret exit put get len read write new global text view edit true false note neg not add sub mul div rem and or xor shl shr eq ne lt le gt ge ( ) = bool uchar ushort uint ulong byte short int long void main 0 1 -1 255 18446744073709551615 9223372036854775808 x zz abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl 123456789012345678901 1x \"s\" \"q\\\\x\""
15acc=0; inputs=0; bad=0; codes=""
16one() { # file -> checks it
17 inputs=$((inputs + 1))
18 set +e; $REF < $1 > $W/a 2> $W/ae; ra=$?; set -e
19 if [ $ra -ge 128 ] || { [ $ra != 0 ] && ! grep -q "line [0-9]*: error $ra\$" $W/ae; }; then bad=$((bad + 1)); echo "CRASH or no error number: exit $ra on $(cp $1 $W/bad$bad.om; echo $W/bad$bad.om)"; fi
20 codes="$codes $ra"
21 if [ -n "$OTH" ]; then
22 set +e; $OTH < $1 > $W/b 2> $W/be; rb=$?; set -e
23 sed -i 's/^om[4c]:/X:/' $W/ae $W/be
24 { [ $ra = $rb ] && cmp -s $W/a $W/b && cmp -s $W/ae $W/be; } || { bad=$((bad + 1)); echo "DIFFER: exit $ra / $rb on $(cp $1 $W/bad$bad.om; echo $W/bad$bad.om)"; }
25 fi
26}
27s=1
28while [ $s -le $N ]; do
29 awk -v seed=$s -f $D/nextgen.awk > $W/p.om
30 set +e; $REF < $W/p.om > /dev/null 2> $W/pe; r=$?; set -e
31 if [ $r = 0 ]; then acc=$((acc + 1)); elif [ $r = 12 ]; then :; else bad=$((bad + 1)); echo "REFUSED generated program seed $s: $(cat $W/pe)"; fi
32 rm -f $W/v.*
33 awk -v seed=$s -v V="$V" -v W=$W 'BEGIN { srand(seed + 7919); nv = split(V, voc, " ") }
34 { L[NR] = $0 } END {
35 n = 0; for (i = 1; i <= NR; i++) { m = split(L[i], w, /[ \t]+/); for (j = 1; j <= m; j++) if (w[j] != "") { n++; wl[n] = i; wj[n] = j } }
36 for (k = 1; k <= n; k++) {
37 f = W "/v.c" k; for (i = 1; i < wl[k]; i++) print L[i] > f
38 m = split(L[wl[k]], w, /[ \t]+/); s = ""; c = 0; for (j = 1; j <= m; j++) if (w[j] != "") { c++; s = s (c > 1 ? " " : "") w[j]; if (j == wj[k]) break }
39 printf "%s", s > f; close(f)
40 f = W "/v.m" k; for (i = 1; i <= NR; i++) { if (i != wl[k]) { print L[i] > f; continue }
41 m = split(L[i], w, /[ \t]+/); s = ""; c = 0; for (j = 1; j <= m; j++) if (w[j] != "") { c++; s = s (c > 1 ? " " : "") (j == wj[k] ? voc[int(rand() * nv) + 1] : w[j]) }
42 print s > f }
43 close(f) } }' $W/p.om
44 for f in $W/v.*; do one $f; done
45 s=$((s + 1))
46done
47echo "$codes" | tr ' ' '\n' | grep . | sort -n | uniq -c | awk '{printf "%s:%s ", $2, $1} END {print ""}' > $W/codes
48echo "nextfuzz: $N programs ($acc accepted, $((N - acc)) out of registers, error 12), $inputs cut or changed inputs, $bad bad; exit codes $(cat $W/codes)"
49[ $bad = 0 ]