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 / tools / omegese / test_omegese.sh
| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # tools/omegese/test_omegese.sh <omegese> <omega_emit> <checker2> -- Omegese checks (docs/one_layer/OMEGESE.md). |
| 18 | # 0. with OMEGESE_SANITIZED=1 (an ASan and UBSan build): canary negative controls, then every sanitizer |
| 19 | # exit fails the run; |
| 20 | # 1. every public dev program (tests/one_layer/omegese/dev) -> omegese emit -> omega_emit emit -> checker2 |
| 21 | # ACCEPT; 1a nested and trial-2 programs; 1b coverage programs; 1c omegese next on fixed prefixes; |
| 22 | # 2. refusals: each bad program is refused by omegese with its expected reason, and a control (the |
| 23 | # same program with the defect fixed) is accepted; |
| 24 | # 3. loop guard negative control: the dev04 op list with the hidden loop counter increment removed |
| 25 | # still passes omega_emit, and checker2 must REJECT it as C2-LOOP-UNBOUNDED; |
| 26 | # 4. tokenizer gate (only when OMEGESE_TOKCOUNT and OMEGESE_TOKENIZER are set): every fixed word of |
| 27 | # the language, with its leading space, is exactly one token; |
| 28 | # 5. next oracle: every word of every accepted program is legal where it is written; |
| 29 | # 6. completeness: single-word mutants (OMEGESE_MUTANTS per program): emit accepts iff every word legal; |
| 30 | # 7. soundness fuzz (OMEGESE_WALKS walks of OMEGESE_STEPS items) closed by omegese complete; then the |
| 31 | # checker2 residual (OMEGESE_RESIDUAL_WALKS walks from each of two starts, closed by complete, through |
| 32 | # omega_emit and checker2; at most OMEGESE_RESIDUAL_MAX, default 0, rejected there); then the |
| 33 | # truncation fuzz: every byte prefix through emit, next and next --machine answers, never crashes, |
| 34 | # allows the byte that follows, and is finished by complete. |
| 35 | set -euo pipefail |
| 36 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 37 | ROOT="$(cd "$HERE/../.." && pwd)" |
| 38 | [ $# -eq 3 ] || { echo "usage: test_omegese.sh <omegese> <omega_emit> <checker2>" >&2; exit 2; } |
| 39 | G="$1" OME="$2" C2="$3" |
| 40 | T="$(mktemp -d "${TMPDIR:-/tmp}/omegese-test.XXXXXXXX")"; trap 'rm -rf "$T"' EXIT |
| 41 | fails=0 |
| 42 | bad() { echo "FAIL $*"; fails=$((fails + 1)); } |
| 43 | |
| 44 | # 0. sanitized run (OMEGESE_SANITIZED=1: <omegese> is built with ASan and UBSan, which exit 86 on a |
| 45 | # finding; omegese itself only exits 0, 1 or 2). <omegese> is wrapped so that every exit 86 is logged |
| 46 | # with its report and fails the run at the end, wherever the test reads the exit code. Negative control |
| 47 | # first: each binary in OMEGESE_CANARIES (built with -DOMEGESE_CANARY=1, a read after free, or =2, a |
| 48 | # signed overflow) must be caught, so a sanitizer that is silently off cannot pass. |
| 49 | if [ "${OMEGESE_SANITIZED:-0}" = 1 ]; then |
| 50 | export ASAN_OPTIONS="exitcode=86" UBSAN_OPTIONS="halt_on_error=1:print_stacktrace=1:exitcode=86" |
| 51 | nc=0 |
| 52 | for c in ${OMEGESE_CANARIES:-}; do |
| 53 | rc=0; "$c" emit "$ROOT/tests/one_layer/omegese/dev/dev01.omegese" "$T/canary.json" > /dev/null 2> "$T/canary.err" || rc=$? |
| 54 | if [ "$rc" -eq 86 ] && grep -qE 'heap-use-after-free|signed integer overflow' "$T/canary.err"; then nc=$((nc + 1)) |
| 55 | else bad "sanitizer negative control $(basename "$c"): not caught (exit $rc)"; fi |
| 56 | done |
| 57 | [ "$nc" -eq 2 ] || bad "sanitizer negative control: $nc canaries caught, want 2 (set OMEGESE_CANARIES)" |
| 58 | echo "sanitizers: $nc/2 canaries caught (read after free, signed overflow)" |
| 59 | printf '%s\n' '#!/usr/bin/env bash' "e=\"\$(mktemp)\"; rc=0; '$G' \"\$@\" 2> \"\$e\" || rc=\$?" \ |
| 60 | "[ \$rc -ne 86 ] || { echo \"== \$*\"; cat \"\$e\"; } >> '$T/san.log'" 'cat "$e" >&2; rm -f "$e"; exit $rc' > "$T/gsan" |
| 61 | chmod +x "$T/gsan"; G="$T/gsan" |
| 62 | fi |
| 63 | |
| 64 | # 1. dev programs |
| 65 | n=0 |
| 66 | for f in "$ROOT"/tests/one_layer/omegese/dev/dev*.omegese; do |
| 67 | id="$(basename "$f" .omegese)" |
| 68 | if ! "$G" emit "$f" "$T/$id.json" > "$T/$id.out"; then bad "$id omegese: $(cat "$T/$id.out")"; continue; fi |
| 69 | if ! "$OME" emit "$T/$id.json" "$T/$id.oscir" > "$T/$id.out"; then bad "$id omega_emit: $(cat "$T/$id.out")"; continue; fi |
| 70 | v="$("$C2" check "$T/$id.oscir" 2>&1 | head -1 || true)" |
| 71 | case "$v" in checker2=ACCEPT*) n=$((n + 1)) ;; *) bad "$id checker2: $v" ;; esac |
| 72 | done |
| 73 | [ "$n" -eq 10 ] || bad "dev programs accepted $n/10" |
| 74 | echo "dev: $n/10 omegese -> omega_emit -> checker2 ACCEPT" |
| 75 | |
| 76 | # 1a. nested values: tests/one_layer/omegese/nested (dev tasks rewritten with nested values and |
| 77 | # brackets) and tests/one_layer/omegese/trial2 (the model's own answers from phase-2 trial 2, |
| 78 | # verbatim, that v0 refused for nesting or brackets): omegese -> omega_emit -> checker2 ACCEPT. |
| 79 | # trial2/dev07 has a real extra value and must stay refused, at its line, for that reason. |
| 80 | accept() { # <file> <id>: omegese -> omega_emit -> checker2 ACCEPT |
| 81 | if ! "$G" emit "$1" "$T/$2.json" > "$T/$2.out"; then bad "$2 omegese: $(cat "$T/$2.out")"; return 1; fi |
| 82 | if ! "$OME" emit "$T/$2.json" "$T/$2.oscir" > "$T/$2.out"; then bad "$2 omega_emit: $(cat "$T/$2.out")"; return 1; fi |
| 83 | local v; v="$("$C2" check "$T/$2.oscir" 2>&1 | head -1 || true)" |
| 84 | case "$v" in checker2=ACCEPT*) return 0 ;; *) bad "$2 checker2: $v"; return 1 ;; esac |
| 85 | } |
| 86 | nn=0 nt=0 |
| 87 | for f in "$ROOT"/tests/one_layer/omegese/nested/*.omegese; do accept "$f" "nested-$(basename "$f" .omegese)" && nn=$((nn + 1)); done |
| 88 | for f in "$ROOT"/tests/one_layer/omegese/trial2/*.omegese; do |
| 89 | id="$(basename "$f" .omegese)" |
| 90 | if [ "$id" = dev07 ]; then |
| 91 | out="$("$G" emit "$f" "$T/x.json" || true)" |
| 92 | [ "$out" = "REFUSED omegese: line 3: le has 3 values after it; it takes 2" ] || bad "trial2 dev07 (extra value) must be refused: got '$out'" |
| 93 | else accept "$f" "trial2-$id" && nt=$((nt + 1)); fi |
| 94 | done |
| 95 | [ "$nn" -eq 6 ] && [ "$nt" -eq 5 ] || bad "nested $nn/6, trial2 $nt/5" |
| 96 | echo "nested: $nn/6 rewritten dev programs and $nt/5 trial-2 model answers ACCEPT; trial-2 dev07 refused for its extra value" |
| 97 | |
| 98 | # 1a'. review fixes: a conversion of a typed number of another type must convert (not reuse the |
| 99 | # number's register under the wrong type); brackets around a for count change nothing |
| 100 | printf 'fn f to long\nret long int 5\nend\n' > "$T/s1.omegese" |
| 101 | accept "$T/s1.omegese" stacked-ret || true |
| 102 | printf 'fn f x ulong to ulong\nret shl x uchar int 300\nend\n' > "$T/s2.omegese" |
| 103 | accept "$T/s2.omegese" stacked-shift || true |
| 104 | grep -q '"op": "cast"' "$T/stacked-shift.json" 2>/dev/null || bad "uchar int 300 must emit a cast (trap 5), not reuse the int const" |
| 105 | printf 'fn f to uint\ns = uint 0\nfor i ulong %s\ns = add s 1\nend\nret s\nend\n' 8 > "$T/f1.omegese" |
| 106 | printf 'fn f to uint\ns = uint 0\nfor i ulong %s\ns = add s 1\nend\nret s\nend\n' '( ( 8 ) )' > "$T/f2.omegese" |
| 107 | "$G" emit "$T/f1.omegese" "$T/f1.json" > /dev/null && "$G" emit "$T/f2.omegese" "$T/f2.json" > /dev/null \ |
| 108 | && cmp -s "$T/f1.json" "$T/f2.json" || bad "for i ulong ( ( 8 ) ) must lower exactly as for i ulong 8" |
| 109 | printf 'fn f to uint\ns = uint 0\nfor i ulong ( 2000000 )\ns = add s 1\nend\nret s\nend\n' > "$T/f3.omegese" |
| 110 | out="$("$G" emit "$T/f3.omegese" "$T/f3.json" || true)" |
| 111 | [ "$out" = "REFUSED omegese: line 3: count '2000000' must be 0..1000000" ] || bad "bracketed count over the limit: got '$out'" |
| 112 | echo "review fixes: stacked conversions convert; brackets around a for count change nothing" |
| 113 | |
| 114 | # 1b. coverage programs (break, nested loops, else-if, a for with a name as the count, arrays and |
| 115 | # calls across functions): omegese -> omega_emit -> checker2 ACCEPT |
| 116 | cov=0 |
| 117 | awk -v d="$T" '/^== / { k++; f = d "/c" k ".omegese"; next } { print > f }' <<'EOF' |
| 118 | == break and nested loops |
| 119 | fn f n uint to uint |
| 120 | s = uint 0 |
| 121 | for i uint n |
| 122 | for j uint 8 |
| 123 | if gt j i |
| 124 | break |
| 125 | end |
| 126 | s = add s j |
| 127 | end |
| 128 | end |
| 129 | ret s |
| 130 | end |
| 131 | == else-if chain |
| 132 | fn sign a int to int |
| 133 | if lt a 0 |
| 134 | ret -1 |
| 135 | else |
| 136 | if gt a 0 |
| 137 | ret 1 |
| 138 | end |
| 139 | end |
| 140 | ret 0 |
| 141 | end |
| 142 | == arrays and calls |
| 143 | fn sum4 v view uint 4 to uint |
| 144 | s = uint 0 |
| 145 | for i uint 4 |
| 146 | x = get v i |
| 147 | s = add s x |
| 148 | end |
| 149 | ret s |
| 150 | end |
| 151 | fn fill e edit uint 4 to void |
| 152 | for i uint 4 |
| 153 | put e i i |
| 154 | end |
| 155 | end |
| 156 | fn f to uint |
| 157 | a = new uint 4 0 |
| 158 | m = edit a |
| 159 | fill m |
| 160 | s = sum4 a |
| 161 | free a |
| 162 | ret s |
| 163 | end |
| 164 | == IR type names as written in the task signature |
| 165 | fn clamp_add a u8 b u8 to u8 |
| 166 | s = add a b |
| 167 | if lt s a |
| 168 | ret u8 255 |
| 169 | end |
| 170 | ret s |
| 171 | end |
| 172 | == calls without values, a bool function as a condition |
| 173 | fn seven to uint |
| 174 | ret 7 |
| 175 | end |
| 176 | fn odd a uint to bool |
| 177 | b = and a 1 |
| 178 | ret ne b 0 |
| 179 | end |
| 180 | fn f a uint to uint |
| 181 | x = seven |
| 182 | if odd a |
| 183 | ret x |
| 184 | end |
| 185 | ret a |
| 186 | end |
| 187 | == nested values in every place a value goes: call args, get index, put index and value, for count, ret, conversions, brackets |
| 188 | fn sq a uint to uint |
| 189 | ret mul a a |
| 190 | end |
| 191 | fn f v view uint 4 n uint to uint |
| 192 | s = uint 0 |
| 193 | for i uint sub n 1 |
| 194 | s = add s sq get v rem i 4 |
| 195 | end |
| 196 | w = new uint 4 0 |
| 197 | put w rem add s 2 4 mul s 2 |
| 198 | for j uint (4) |
| 199 | s = add s get w j |
| 200 | end |
| 201 | free w |
| 202 | ret uint ulong add (s) 0 |
| 203 | end |
| 204 | == a number first takes the type of the other value; shifts; neg and not nested; a call with no values nested |
| 205 | fn seven to int |
| 206 | ret 7 |
| 207 | end |
| 208 | fn g a int b ulong to bool |
| 209 | x = sub 100 neg a |
| 210 | y = shl 1 and b 7 |
| 211 | z = add seven x |
| 212 | if and not eq z 0 gt y 3 |
| 213 | ret true |
| 214 | end |
| 215 | ret ne (rem 10 z) 0 |
| 216 | end |
| 217 | == a while condition with nested values; trap ends a path; borrows as call arguments |
| 218 | fn total v view uint 4 to uint |
| 219 | ret add add get v 0 get v 1 add get v 2 get v 3 |
| 220 | end |
| 221 | fn h a uint to uint |
| 222 | while lt mul a a 1000 bound 64 |
| 223 | a = add a 1 |
| 224 | end |
| 225 | if gt a 100 |
| 226 | trap 1 |
| 227 | else |
| 228 | if eq a 7 |
| 229 | trap 2 |
| 230 | end |
| 231 | end |
| 232 | b = new uint 4 a |
| 233 | c = total view b |
| 234 | free b |
| 235 | ret c |
| 236 | end |
| 237 | EOF |
| 238 | for f in "$T"/c*.omegese; do |
| 239 | if "$G" emit "$f" "$T/c.json" > "$T/c.out" && "$OME" emit "$T/c.json" "$T/c.oscir" > "$T/c.out"; then |
| 240 | v="$("$C2" check "$T/c.oscir" 2>&1 | head -1 || true)" |
| 241 | case "$v" in checker2=ACCEPT*) cov=$((cov + 1)) ;; *) bad "coverage $(basename "$f") checker2: $v" ;; esac |
| 242 | else bad "coverage $(basename "$f"): $(cat "$T/c.out")"; fi |
| 243 | done |
| 244 | echo "coverage: $cov/$(ls "$T"/c*.omegese | wc -l) accepted" |
| 245 | |
| 246 | # 1c. omegese next: what may come next after a prefix, exactly (docs/one_layer/OMEGESE.md section 6). |
| 247 | # At a line start: "words:" (statement words and functions to call), "assign:" (names that may |
| 248 | # be assigned), "new-name:"; elsewhere: "names:", "number: lo..hi" (the numbers that may stand |
| 249 | # there), "new-name:" and "words:" (fixed words, functions, brackets, "(space)" inside a word, |
| 250 | # "(newline)", "(end of input)"). Only what can still end in a program emit accepts is offered. |
| 251 | nx() { printf '%b' "$1" > "$T/p"; "$G" next "$T/p" || true; } |
| 252 | nxk=0 |
| 253 | nxeq() { # <prefix> <expected output> |
| 254 | nxk=$((nxk + 1)) |
| 255 | local got; got="$(nx "$1")" |
| 256 | [ "$got" = "$(printf '%b' "$2")" ] || bad "next after '$1': got '$got'" |
| 257 | } |
| 258 | nxcase() { # <prefix> <glob the output must match> <what> |
| 259 | nxk=$((nxk + 1)) |
| 260 | local got; got="$(nx "$1")" |
| 261 | # shellcheck disable=SC2254 |
| 262 | case "$got" in $2) ;; *) bad "next $3: got '$got'" ;; esac |
| 263 | } |
| 264 | nxeq 'fn f a uint to uint\nret a\n' 'words: end' |
| 265 | nxeq 'fn f a uint b ulong to uint\nx = add a ' 'names: a\nnumber: 0..4294967295\nwords: add sub mul div rem and or xor shl shr not uint u32 (' |
| 266 | nxeq 'fn f a uint to uint\nfor i uint 4\n' 'assign: a\nnew-name: any name not in use\nwords: if while for ret trap break end' |
| 267 | nxcase 'fn f a uint to uint\nret a\nret ' 'REFUSED omegese: *path already ended*' 'after a dead line: not refused' |
| 268 | nxcase 'x = add ' 'REFUSED omegese: *outside a function*' 'before fn: not refused' |
| 269 | nxeq 'fn odd a uint to bool\nret true\nend\nfn f a uint fl view bool 4 to uint\nif ' 'words: true false and or xor eq ne lt le gt ge not get bool odd (' |
| 270 | # nesting: a stack of open operand slots, each with the type it needs |
| 271 | nxeq 'fn f r uint q ulong c bool to uint\nx = add mul r ' 'names: r\nnumber: 0..4294967295\nwords: add sub mul div rem and or xor shl shr not uint u32 (' |
| 272 | nxeq 'fn f r uint q ulong c bool to uint\nx = add mul r r ' 'names: r\nnumber: 0..4294967295\nwords: add sub mul div rem and or xor shl shr not uint u32 (' |
| 273 | nxeq 'fn f r uint q ulong c bool to uint\nret sub ' 'names: r\nnumber: 0..4294967295\nwords: add sub mul div rem and or xor shl shr not uint u32 (' |
| 274 | nxeq 'fn f p short to short\nif lt p short ' 'names: p\nnumber: -32768..32767\nwords: add sub mul div rem and or xor shl shr neg not uchar ushort uint ulong byte short int long u8 u16 u32 u64 i8 i16 i32 i64 (' |
| 275 | # the type is still open: every whole-number name (bool and arrays excluded for add) and any number |
| 276 | # some whole-number type holds; after a bare number, no second bare number, and only names it fits |
| 277 | nxeq 'fn f r uint q ulong c bool to uint\nx = add ' 'names: r q\nnumber: -9223372036854775808..18446744073709551615\nwords: add sub mul div rem and or xor shl shr neg not uchar ushort uint ulong byte short int long u8 u16 u32 u64 i8 i16 i32 i64 (' |
| 278 | nxeq 'fn f r uint q ulong c bool to uint\nx = add 1 ' 'names: r q\nwords: add sub mul div rem and or xor shl shr neg not uchar ushort uint ulong byte short int long u8 u16 u32 u64 i8 i16 i32 i64 (' |
| 279 | nxeq 'fn f a uchar b uint to uint\nx = add 300 ' 'names: b\nwords: add sub mul div rem and or xor shl shr neg not ushort uint ulong short int long u16 u32 u64 i16 i32 i64 (' |
| 280 | # brackets, the end of a value, arrays, trap |
| 281 | nxeq 'fn f r uint q ulong c bool to uint\nx = (add r r ' 'words: )' |
| 282 | nxeq 'fn f r uint x uint to uint\nwhile le add mul r r 4 r ' 'words: bound (newline)' |
| 283 | nxeq 'fn f r uint x uint to uint\nret add r (r) ' 'words: (newline)' |
| 284 | nxeq 'fn f v view uint 4 e edit uint 4 to uint\nput ' 'names: e' |
| 285 | nxeq 'fn g v view uint 4 to uint\nret 1\nend\nfn f a own uint 4 to uint\nx = g ' 'names: a\nwords: own edit view (' |
| 286 | nxeq 'fn f p short c bool to short\nif c\ntrap 1\n' 'words: else end' |
| 287 | nxcase 'fn f r uint to uint\nx = add r r r ' 'REFUSED omegese: line 2: add has 3 values after it; it takes 2' 'after an extra value: not refused' |
| 288 | nxcase 'fn f r uint to uint\nx = add 1 2 ' 'REFUSED omegese: *two numbers*' 'after two numbers: not refused' |
| 289 | nxcase 'fn f r uint to uint\nx = add r ) ' 'REFUSED omegese: *no matching*' 'after a stray ): not refused' |
| 290 | # never offer a word that leads to a dead end: no end before ret, no trap while b is unread, no put |
| 291 | # or free without an array |
| 292 | nxeq 'fn f a uint to uint\nb = add a 1\n' 'assign: a b\nnew-name: any name not in use\nwords: if while for ret' |
| 293 | nxcase 'fn f a uint to uint\nb = add a 1\nend\n' 'REFUSED omegese: *without ret*' 'end before ret: not refused' |
| 294 | nxcase 'fn f a uint to uint\nelse\n' 'REFUSED omegese: line 2: else without an open if' 'stray else: not refused' |
| 295 | nxcase 'fn f a uint to uint\nbreak\n' 'REFUSED omegese: line 2: break outside a loop' 'stray break: not refused' |
| 296 | nxcase 'fn f a uint to uint\nb = add a 1\ntrap 1\n' "REFUSED omegese: line 4: *'b' is written but never read*" 'a trap that leaves b unread: not refused' |
| 297 | # ret must read every name the ended path leaves unread: b only (no bare number, no a alone); a bool |
| 298 | # with no function to turn it into a number cannot be read by a number; inside an if, only the |
| 299 | # names of the if |
| 300 | nxeq 'fn f a uint to uint\nb = add a 1\nret ' 'names: b\nwords: add sub mul div rem and or xor shl shr not uint u32 (' |
| 301 | nxcase 'fn f a uint to uint\nb = gt a 1\nret ' "REFUSED omegese: *'b' is written but never read*" 'an unreadable bool before ret: not refused' |
| 302 | nxeq 'fn h c bool to ulong\nret ulong 0\nend\nfn f a uint to uint\nb = gt a 1\nret add a ' 'words: add sub mul div rem and or xor shl shr not uint u32 (' |
| 303 | nxeq 'fn f a uint v view bool 4 to bool\nx = view v\nret eq ' 'words: true false and or xor eq ne lt le gt ge not get bool (' |
| 304 | nxeq 'fn f a uint v view uint 4 to uint\nx = view v\nif gt a 2\ny = add a 1\nret ' 'names: y\nwords: add sub mul div rem and or xor shl shr not get uint u32 (' |
| 305 | # inside a word: the words that extend it, a name not in use, and what may end it |
| 306 | nxeq 'fn f a uint to uint\nb = add a 1\nen' 'new-name: any name not in use\nwords: ( (space)' |
| 307 | nxeq 'fn f a uint to uint\nb = add a 1\nre' 'new-name: any name not in use\nwords: ret ( (space)' |
| 308 | nxeq 'fn f a uint to uint\nx = new uint 4 0\nfree x\nx = new uint ' 'number: 4..4' |
| 309 | nxeq 'fn f a uint to uint\nx = new uint 4 0\nfree x\nx = new uint 4' 'number: 4..4\nwords: ( (space)' |
| 310 | nxcase 'fn f a uint to uint\nx = new uint 4 0\nfree x\nx = new uint 1' 'REFUSED omegese: line 4: *own uint 1 but the name holds own uint 4*' 'a length no number extends: not refused' |
| 311 | # ownership (checker2's C2-OWN rules, OMEGESE.md 6.4): no ret while an own array holds its array on |
| 312 | # some path, no second free; at a line start ret is left out until the array is freed; after a loop |
| 313 | # that frees and refills it the array still holds one on some path, so complete frees it |
| 314 | nxcase 'fn f a own uint 4 to uint\nret ' "REFUSED omegese: line 2: no text after this prefix*'a' still holds its array*" 'ret while an own array holds its array: not refused' |
| 315 | nxcase 'fn f a own uint 4 to uint\nfree a\nfree ' "REFUSED omegese: line 3: *freed or moved on every path*" 'a second free: not refused' |
| 316 | nxk=$((nxk + 1)); got="$(printf 'fn f a own uint 4 to uint\n' > "$T/p"; "$G" next --machine "$T/p")" |
| 317 | [ "$got" = "$(printf 'word if\nword while\nword for\nword put\nword free\nword trap\nword a\nnewname a f\nspace\nnewline')" ] || bad "next --machine with an own array that must be freed: got '$got'" |
| 318 | nxk=$((nxk + 1)); got="$(printf 'fn f a own uint 4 n uint to uint\nwhile gt n 0\nfree a\na = new uint 4 n\nn = sub n 1\nend\n' > "$T/p"; "$G" complete "$T/p")" |
| 319 | [ "$got" = "$(printf 'free a\nret 0\nend')" ] || bad "complete after a loop that refills an own array: got '$got'" |
| 320 | # a loop's state at its head is known at its end line: a use of an array freed before the loop is |
| 321 | # refused there unless the body gives it a new one, so end is left out and complete writes those lines |
| 322 | # (free first: the array may hold the one an earlier pass gave it) |
| 323 | nxeq 'fn f a own uint 4 n uint to uint\nfree a\nwhile gt get a 0 n\nn = add n 1\n' 'assign: a n\nnew-name: any name not in use\nwords: if while for put free' |
| 324 | nxcase 'fn f a own uint 4 n uint to uint\nfree a\nwhile gt get a 0 n\nn = add n 1\nend\n' "REFUSED omegese: line 5: 'a' holds no array at line 3 on every path, once this loop is closed*" 'end of a loop whose head uses a freed array: not refused' |
| 325 | nxk=$((nxk + 1)); got="$(printf 'fn f a own uint 4 n uint to uint\nfree a\nwhile gt get a 0 n\nn = add n 1\n' > "$T/p"; "$G" complete "$T/p")" |
| 326 | [ "$got" = "$(printf 'free a\na = new uint 4 0\nend\nfree a\nret 0\nend')" ] || bad "complete in a loop whose head uses a freed array: got '$got'" |
| 327 | # a loop that gives an array a second one while it still holds the first leaks on its first pass: no |
| 328 | # line after it repairs that, so no completion exists |
| 329 | nxcase 'fn f n uint to void\nx = new uint 4 n\nwhile gt n 0\nx = new uint 4 n\n' "REFUSED omegese: line 5: no text after this prefix*'x' still holds an array at line 4 on some path*" 'a loop that gives an array a second one: not refused' |
| 330 | # a loop opened at the nesting limit is refused before its head state is set up (no shift past bit 63) |
| 331 | { echo 'fn f n uint to uint'; for ((i = 0; i < 63; i++)); do echo "if gt n $i"; done; echo 'while gt n 0'; } > "$T/deep.omegese" |
| 332 | nxk=$((nxk + 1)); got="$("$G" emit "$T/deep.omegese" "$T/x.json" 2>&1 || true)" |
| 333 | case "$got" in "REFUSED omegese: line 65: more than 64 nested blocks"*) ;; *) bad "a loop at the nesting limit: got '$got'" ;; esac |
| 334 | # 300 uses of one array inside a loop wait as one check (the same state): accepted, as checker2 does |
| 335 | { echo 'fn f a own uint 4 n uint to uint'; echo 'for i uint 3'; for ((i = 0; i < 300; i++)); do echo 'n = get a 0'; done; echo 'end'; echo 'free a'; echo 'ret n'; echo 'end'; } > "$T/many.omegese" |
| 336 | nxk=$((nxk + 1)); accept "$T/many.omegese" many-uses-in-a-loop || true |
| 337 | nxeq 'fn f a short to short\nret add a -' 'number: -32768..32767' |
| 338 | nxeq 'fn f a short to short\nret add a -0' 'REFUSED omegese: line 2: no text after this prefix makes a program emit accepts ('"'"'-0'"'"' is not a number (digits, an optional minus sign, no leading zeros, no -0))' |
| 339 | # the number ranges each slot allows: every scalar type, a minus sign where none fits, and the fixed |
| 340 | # limits (trap codes, array lengths, loop bounds and counts) |
| 341 | nxnum() { # <prefix> <lo..hi> <what>: the number line is exactly that interval |
| 342 | nxk=$((nxk + 1)) |
| 343 | local got; got="$(nx "$1")"$'\n' |
| 344 | [[ $got == *"number: $2"$'\n'* ]] || bad "next $3: got '$got'" |
| 345 | } |
| 346 | for tr in uchar:0..255 ushort:0..65535 uint:0..4294967295 ulong:0..18446744073709551615 byte:-128..127 \ |
| 347 | short:-32768..32767 int:-2147483648..2147483647 long:-9223372036854775808..9223372036854775807; do |
| 348 | nxnum "fn f a ${tr%%:*} to ${tr%%:*}\\nret add a " "${tr#*:}" "range of ${tr%%:*}" |
| 349 | done |
| 350 | nxcase 'fn f a uint to uint\nret add a -' 'REFUSED omegese: line 2: no text after this prefix*' 'a minus sign in an unsigned slot: not refused' |
| 351 | nxnum 'fn f a uint to uint\ntrap ' '1..14' 'trap codes' |
| 352 | nxnum 'fn f a uint to uint\nx = new uint ' '1..64' 'array lengths' |
| 353 | nxnum 'fn f a uint to uint\nwhile lt a 3 bound ' '1..1000000' 'loop bounds' |
| 354 | nxnum 'fn f a uint to uint\nfor i uint ' '0..1000000' 'loop counts' |
| 355 | # the machine form: one item per line |
| 356 | nxm() { printf '%b' "$1" > "$T/p"; "$G" next --machine "$T/p" || true; } |
| 357 | nxk=$((nxk + 1)); got="$(nxm 'fn f a uint to uint\nb = add a 1\nre')" |
| 358 | [ "$got" = "$(printf 'word ret\nnewname\n(\nspace')" ] || bad "next --machine after 're': got '$got'" |
| 359 | nxk=$((nxk + 1)); got="$(nxm 'fn f a uint b ulong to uint\nret a\nend\n')" |
| 360 | [ "$got" = "$(printf 'word fn\nspace\nnewline\neof')" ] || bad "next --machine after a function: got '$got'" |
| 361 | nxk=$((nxk + 1)); got="$(nxm 'fn f a uint b ulong to uint\nx = add a')" |
| 362 | [ "$got" = "$(printf 'word add\nword and\nword a\n(\nspace')" ] || bad "next --machine inside a name: got '$got'" |
| 363 | nxk=$((nxk + 1)); got="$(nxm 'fn f a uint to uint\n')" |
| 364 | [ "$got" = "$(printf 'word if\nword while\nword for\nword ret\nword trap\nword a\nnewname a f\nspace\nnewline')" ] || bad "next --machine at a line start (OMEGESE.md 6.2): got '$got'" |
| 365 | nxk=$((nxk + 1)); got="$(nxm 'fn f ab uint b uint to uint\nfor abc uint 3\nx = add abc a')" |
| 366 | [ "$got" = "$(printf 'word add\nword and\nword ab\nword abc')" ] || bad "next --machine, names that extend the word: got '$got'" |
| 367 | nxk=$((nxk + 1)); got="$(nxm 'fn f ab uint b uint to uint\nfor abc uint 3\na')" |
| 368 | [ "$got" = "$(printf 'word ab\nnewname ab abc\n(\nspace')" ] || bad "next --machine, a new name that extends names in use: got '$got'" |
| 369 | # complete: the witness text, which emit accepts after the prefix |
| 370 | nxk=$((nxk + 1)); got="$(printf 'fn f a uint v view uint 4 to uint\nx = view v\nif gt a 2\ny = add a 1\nret ' > "$T/p"; "$G" complete "$T/p")" |
| 371 | [ "$got" = "$(printf ' y\nend\nx = x\nret 0\nend')" ] || bad "complete inside an if: got '$got'" |
| 372 | echo "next: $nxk prefixes give the expected words" |
| 373 | |
| 374 | # 2. refusals: "== <expected reason substring>", the bad program, "-- control", the fixed program |
| 375 | r=0 |
| 376 | awk -v d="$T" ' |
| 377 | /^== / { k++; sub(/^== /, ""); print > (d "/r" k ".want"); f = d "/r" k ".bad"; next } |
| 378 | /^-- control$/ { f = d "/r" k ".ok"; next } |
| 379 | { print > f }' <<'EOF' |
| 380 | == needs two values of one type |
| 381 | fn f a uint b ulong to uint |
| 382 | x = add a b |
| 383 | ret a |
| 384 | end |
| 385 | -- control |
| 386 | fn f a uint b uint to uint |
| 387 | x = add a b |
| 388 | ret x |
| 389 | end |
| 390 | == is not a name in scope here |
| 391 | fn f a uint to uint |
| 392 | if gt a 1 |
| 393 | y = add a 1 |
| 394 | a = y |
| 395 | end |
| 396 | ret y |
| 397 | end |
| 398 | -- control |
| 399 | fn f a uint to uint |
| 400 | y = a |
| 401 | if gt a 1 |
| 402 | y = add a 1 |
| 403 | end |
| 404 | ret y |
| 405 | end |
| 406 | == can reach its end without ret |
| 407 | fn f a uint to uint |
| 408 | if gt a 1 |
| 409 | ret a |
| 410 | end |
| 411 | end |
| 412 | -- control |
| 413 | fn f a uint to uint |
| 414 | if gt a 1 |
| 415 | ret a |
| 416 | end |
| 417 | ret 0 |
| 418 | end |
| 419 | == can never run |
| 420 | fn f a uint to uint |
| 421 | ret a |
| 422 | b = add a 1 |
| 423 | end |
| 424 | -- control |
| 425 | fn f a uint to uint |
| 426 | b = add a 1 |
| 427 | ret b |
| 428 | end |
| 429 | == does not fit uchar |
| 430 | fn f to uchar |
| 431 | x = uchar 300 |
| 432 | ret x |
| 433 | end |
| 434 | -- control |
| 435 | fn f to uchar |
| 436 | x = uchar 255 |
| 437 | ret x |
| 438 | end |
| 439 | == two numbers |
| 440 | fn f to uint |
| 441 | x = add 1 2 |
| 442 | ret x |
| 443 | end |
| 444 | -- control |
| 445 | fn f to uint |
| 446 | x = uint 1 |
| 447 | y = add x 2 |
| 448 | ret y |
| 449 | end |
| 450 | == the type of this number is unknown |
| 451 | fn f to uint |
| 452 | x = 5 |
| 453 | ret x |
| 454 | end |
| 455 | -- control |
| 456 | fn f to uint |
| 457 | x = uint 5 |
| 458 | ret x |
| 459 | end |
| 460 | == a condition must be a bool |
| 461 | fn f a uint to uint |
| 462 | if a |
| 463 | ret 1 |
| 464 | end |
| 465 | ret 0 |
| 466 | end |
| 467 | -- control |
| 468 | fn f a uint to uint |
| 469 | if ne a 0 |
| 470 | ret 1 |
| 471 | end |
| 472 | ret 0 |
| 473 | end |
| 474 | == must be 1..1000000 |
| 475 | fn f a uint to uint |
| 476 | while ne a 0 bound 2000000 |
| 477 | a = shr a 1 |
| 478 | end |
| 479 | ret a |
| 480 | end |
| 481 | -- control |
| 482 | fn f a uint to uint |
| 483 | while ne a 0 bound 64 |
| 484 | a = shr a 1 |
| 485 | end |
| 486 | ret a |
| 487 | end |
| 488 | == else without an open if |
| 489 | fn f a uint to uint |
| 490 | else |
| 491 | ret a |
| 492 | end |
| 493 | -- control |
| 494 | fn f a uint to uint |
| 495 | ret a |
| 496 | end |
| 497 | == is the loop counter |
| 498 | fn f to uint |
| 499 | s = uint 0 |
| 500 | for i uint 4 |
| 501 | i = add i 1 |
| 502 | end |
| 503 | ret s |
| 504 | end |
| 505 | -- control |
| 506 | fn f to uint |
| 507 | s = uint 0 |
| 508 | for i uint 4 |
| 509 | s = add s i |
| 510 | end |
| 511 | ret s |
| 512 | end |
| 513 | == is not part of Omegese |
| 514 | fn f a uint b uint to uint |
| 515 | x = add a, b |
| 516 | ret x |
| 517 | end |
| 518 | -- control |
| 519 | fn f a uint b uint to uint |
| 520 | x = add a b |
| 521 | ret x |
| 522 | end |
| 523 | == put needs an own or edit array |
| 524 | fn f to uint |
| 525 | a = new uint 4 0 |
| 526 | v = view a |
| 527 | put v 0 1 |
| 528 | free a |
| 529 | ret 0 |
| 530 | end |
| 531 | -- control |
| 532 | fn f to uint |
| 533 | a = new uint 4 0 |
| 534 | put a 0 1 |
| 535 | x = get a 0 |
| 536 | free a |
| 537 | ret x |
| 538 | end |
| 539 | == nor an op, a type or a function |
| 540 | fn f a uint to uint |
| 541 | x = g a |
| 542 | ret x |
| 543 | end |
| 544 | -- control |
| 545 | fn g a uint to uint |
| 546 | ret a |
| 547 | end |
| 548 | fn f a uint to uint |
| 549 | x = g a |
| 550 | ret x |
| 551 | end |
| 552 | == neg needs a signed number |
| 553 | fn f a uint to uint |
| 554 | ret neg a |
| 555 | end |
| 556 | -- control |
| 557 | fn f a int to int |
| 558 | ret neg a |
| 559 | end |
| 560 | == g takes uint there |
| 561 | fn g a uint to uint |
| 562 | ret a |
| 563 | end |
| 564 | fn f b ulong to uint |
| 565 | x = g b |
| 566 | ret x |
| 567 | end |
| 568 | -- control |
| 569 | fn g a uint to uint |
| 570 | ret a |
| 571 | end |
| 572 | fn f b ulong to uint |
| 573 | c = uint b |
| 574 | x = g c |
| 575 | ret x |
| 576 | end |
| 577 | == cannot call itself |
| 578 | fn f a uint to uint |
| 579 | x = f a |
| 580 | ret x |
| 581 | end |
| 582 | -- control |
| 583 | fn f a uint to uint |
| 584 | ret a |
| 585 | end |
| 586 | == is named twice |
| 587 | fn f a uint a ulong to ulong |
| 588 | ret a |
| 589 | end |
| 590 | -- control |
| 591 | fn f a uint b ulong to ulong |
| 592 | ret b |
| 593 | end |
| 594 | == is written but never read |
| 595 | fn f a uint to uint |
| 596 | x = add a 1 |
| 597 | rte x |
| 598 | ret x |
| 599 | end |
| 600 | -- control |
| 601 | fn f a uint to uint |
| 602 | x = add a 1 |
| 603 | ret x |
| 604 | end |
| 605 | == is already a name here |
| 606 | fn f to uint |
| 607 | i = uint 0 |
| 608 | for i uint 10 |
| 609 | end |
| 610 | ret i |
| 611 | end |
| 612 | -- control |
| 613 | fn f to uint |
| 614 | i = uint 0 |
| 615 | for k uint 10 |
| 616 | i = add i k |
| 617 | end |
| 618 | ret i |
| 619 | end |
| 620 | == is a word of the language, not a name |
| 621 | fn f bound uint to uint |
| 622 | ret bound |
| 623 | end |
| 624 | -- control |
| 625 | fn f n uint to uint |
| 626 | ret n |
| 627 | end |
| 628 | == ( ... ) must hold exactly one value; 'b' is extra |
| 629 | fn f a uint b uint to uint |
| 630 | x = add (a b) a |
| 631 | ret x |
| 632 | end |
| 633 | -- control |
| 634 | fn f a uint b uint to uint |
| 635 | x = add (a) b |
| 636 | ret x |
| 637 | end |
| 638 | == ')' has no matching '(' |
| 639 | fn f a uint b uint to uint |
| 640 | x = add a b) |
| 641 | ret x |
| 642 | end |
| 643 | -- control |
| 644 | fn f a uint b uint to uint |
| 645 | x = (add a b) |
| 646 | ret x |
| 647 | end |
| 648 | == '(' has no matching ')' |
| 649 | fn f a uint b uint to uint |
| 650 | x = (add a b |
| 651 | ret x |
| 652 | end |
| 653 | -- control |
| 654 | fn f a uint b uint to uint |
| 655 | x = (add a (b)) |
| 656 | ret x |
| 657 | end |
| 658 | == ( ) holds no value |
| 659 | fn f a uint b uint to uint |
| 660 | x = add () a |
| 661 | ret x |
| 662 | end |
| 663 | -- control |
| 664 | fn f a uint b uint to uint |
| 665 | x = add (b) a |
| 666 | ret x |
| 667 | end |
| 668 | == line 2: add has 3 values after it; it takes 2 |
| 669 | fn f a uint b uint to uint |
| 670 | x = add a b a |
| 671 | ret x |
| 672 | end |
| 673 | -- control |
| 674 | fn f a uint b uint to uint |
| 675 | x = add add a b a |
| 676 | ret x |
| 677 | end |
| 678 | == line 2: sub has 1 value after it; it takes 2 |
| 679 | fn f a uint b uint to uint |
| 680 | x = sub mul a b |
| 681 | ret x |
| 682 | end |
| 683 | -- control |
| 684 | fn f a uint b uint to uint |
| 685 | x = sub mul a b a |
| 686 | ret x |
| 687 | end |
| 688 | == line 2: le has 3 values after it; it takes 2 |
| 689 | fn f a uint b uint to uint |
| 690 | while le add a 1 b a bound 8 |
| 691 | a = add a 1 |
| 692 | end |
| 693 | ret a |
| 694 | end |
| 695 | -- control |
| 696 | fn f a uint b uint to uint |
| 697 | while le add a 1 b bound 8 |
| 698 | a = add a 1 |
| 699 | end |
| 700 | ret a |
| 701 | end |
| 702 | == line 2: extra words at the end of the line: 'b' |
| 703 | fn f a uint b uint to uint |
| 704 | ret a b |
| 705 | end |
| 706 | -- control |
| 707 | fn f a uint b uint to uint |
| 708 | ret a |
| 709 | end |
| 710 | == mul 2 3: two numbers |
| 711 | fn f a uint to uint |
| 712 | x = add a mul 2 3 |
| 713 | ret x |
| 714 | end |
| 715 | -- control |
| 716 | fn f a uint to uint |
| 717 | x = add a mul a 3 |
| 718 | ret x |
| 719 | end |
| 720 | == add needs two values of one type: 'a' is uint, '(ulong b)' is ulong |
| 721 | fn f a uint b uint to uint |
| 722 | x = add a (ulong b) |
| 723 | ret x |
| 724 | end |
| 725 | -- control |
| 726 | fn f a uint b uint to uint |
| 727 | x = add a (uint b) |
| 728 | ret x |
| 729 | end |
| 730 | == g has 1 value after it; it takes 2 |
| 731 | fn g a uint b uint to uint |
| 732 | ret add a b |
| 733 | end |
| 734 | fn f a uint to uint |
| 735 | ret g a |
| 736 | end |
| 737 | -- control |
| 738 | fn g a uint b uint to uint |
| 739 | ret add a b |
| 740 | end |
| 741 | fn f a uint to uint |
| 742 | ret g a mul a 2 |
| 743 | end |
| 744 | == the path already ended (ret, trap or break) |
| 745 | fn f a uint to uint |
| 746 | trap 1 |
| 747 | x = add a 1 |
| 748 | ret x |
| 749 | end |
| 750 | -- control |
| 751 | fn f a uint to uint |
| 752 | if gt a 9 |
| 753 | trap 1 |
| 754 | end |
| 755 | x = add a 1 |
| 756 | ret x |
| 757 | end |
| 758 | == new makes an array for a name |
| 759 | fn total v view uint 4 to uint |
| 760 | ret get v 0 |
| 761 | end |
| 762 | fn f a uint to uint |
| 763 | x = total new uint 4 a |
| 764 | ret x |
| 765 | end |
| 766 | -- control |
| 767 | fn total v view uint 4 to uint |
| 768 | ret get v 0 |
| 769 | end |
| 770 | fn f a uint to uint |
| 771 | w = new uint 4 a |
| 772 | x = total w |
| 773 | free w |
| 774 | ret x |
| 775 | end |
| 776 | == still holds its array at this return on some path |
| 777 | fn f a own uint 4 to uint |
| 778 | ret 1 |
| 779 | end |
| 780 | -- control |
| 781 | fn f a own uint 4 to uint |
| 782 | free a |
| 783 | ret 1 |
| 784 | end |
| 785 | == still holds its array at this return on some path |
| 786 | fn f n uint to void |
| 787 | x = new uint 4 n |
| 788 | put x 0 n |
| 789 | end |
| 790 | -- control |
| 791 | fn f n uint to void |
| 792 | x = new uint 4 n |
| 793 | put x 0 n |
| 794 | free x |
| 795 | end |
| 796 | == was already freed or moved on every path |
| 797 | fn f a own uint 4 to void |
| 798 | free a |
| 799 | free a |
| 800 | end |
| 801 | -- control |
| 802 | fn f a own uint 4 n uint to void |
| 803 | while gt n 0 |
| 804 | free a |
| 805 | a = new uint 4 n |
| 806 | n = sub n 1 |
| 807 | end |
| 808 | free a |
| 809 | end |
| 810 | == was freed or moved on every path to this line |
| 811 | fn g b own uint 4 to void |
| 812 | free b |
| 813 | end |
| 814 | fn f a own uint 4 to uint |
| 815 | g own a |
| 816 | x = get a 0 |
| 817 | ret x |
| 818 | end |
| 819 | -- control |
| 820 | fn g b own uint 4 to void |
| 821 | free b |
| 822 | end |
| 823 | fn f a own uint 4 to uint |
| 824 | x = get a 0 |
| 825 | g own a |
| 826 | ret x |
| 827 | end |
| 828 | == still holds an array on some path to this line |
| 829 | fn f n uint to uint |
| 830 | x = new uint 4 n |
| 831 | x = new uint 4 0 |
| 832 | y = get x 0 |
| 833 | free x |
| 834 | ret y |
| 835 | end |
| 836 | -- control |
| 837 | fn f n uint to uint |
| 838 | x = new uint 4 n |
| 839 | free x |
| 840 | x = new uint 4 0 |
| 841 | y = get x 0 |
| 842 | free x |
| 843 | ret y |
| 844 | end |
| 845 | == still holds its array at this return on some path |
| 846 | fn f n uint to uint |
| 847 | x = new uint 4 n |
| 848 | if gt n 3 |
| 849 | ret 0 |
| 850 | end |
| 851 | free x |
| 852 | ret 1 |
| 853 | end |
| 854 | -- control |
| 855 | fn f n uint to uint |
| 856 | x = new uint 4 n |
| 857 | if gt n 3 |
| 858 | free x |
| 859 | end |
| 860 | free x |
| 861 | ret 1 |
| 862 | end |
| 863 | == out of scope here still holds its data on some path to this return |
| 864 | fn f n uint to uint |
| 865 | if gt n 3 |
| 866 | y = new uint 4 n |
| 867 | put y 0 n |
| 868 | else |
| 869 | trap 1 |
| 870 | end |
| 871 | ret 0 |
| 872 | end |
| 873 | -- control |
| 874 | fn f n uint to uint |
| 875 | if gt n 3 |
| 876 | y = new uint 4 n |
| 877 | put y 0 n |
| 878 | free y |
| 879 | end |
| 880 | ret 0 |
| 881 | end |
| 882 | == 'a' holds no array at line 3 on every path, once this loop is closed |
| 883 | fn f a own uint 4 n uint to uint |
| 884 | free a |
| 885 | while gt get a 0 n |
| 886 | n = add n 1 |
| 887 | end |
| 888 | ret n |
| 889 | end |
| 890 | -- control |
| 891 | fn f a own uint 4 n uint to uint |
| 892 | free a |
| 893 | while gt get a 0 n |
| 894 | free a |
| 895 | a = new uint 4 n |
| 896 | n = add n 1 |
| 897 | end |
| 898 | free a |
| 899 | ret n |
| 900 | end |
| 901 | == 'a' holds no array at line 4 on every path, once this loop is closed |
| 902 | fn f a own uint 4 n uint to void |
| 903 | free a |
| 904 | while gt n 0 |
| 905 | free a |
| 906 | n = sub n 1 |
| 907 | end |
| 908 | end |
| 909 | -- control |
| 910 | fn f a own uint 4 n uint to void |
| 911 | free a |
| 912 | while gt n 0 |
| 913 | free a |
| 914 | a = new uint 4 n |
| 915 | n = sub n 1 |
| 916 | end |
| 917 | free a |
| 918 | end |
| 919 | == 'x' still holds an array at line 4 on some path, once this loop is closed |
| 920 | fn f n uint to void |
| 921 | x = new uint 4 n |
| 922 | while gt n 0 |
| 923 | x = new uint 4 n |
| 924 | n = sub n 1 |
| 925 | end |
| 926 | free x |
| 927 | end |
| 928 | -- control |
| 929 | fn f n uint to void |
| 930 | x = new uint 4 n |
| 931 | while gt n 0 |
| 932 | free x |
| 933 | x = new uint 4 n |
| 934 | n = sub n 1 |
| 935 | end |
| 936 | free x |
| 937 | end |
| 938 | == 'x' still holds its array at the return on line 4 on some path, once this loop is closed |
| 939 | fn f n uint to uint |
| 940 | x = new uint 4 n |
| 941 | while gt n 0 |
| 942 | ret n |
| 943 | end |
| 944 | free x |
| 945 | ret 0 |
| 946 | end |
| 947 | -- control |
| 948 | fn f n uint to uint |
| 949 | x = new uint 4 n |
| 950 | while gt n 0 |
| 951 | free x |
| 952 | ret n |
| 953 | end |
| 954 | free x |
| 955 | ret 0 |
| 956 | end |
| 957 | == 'a' holds no array at line 5 on every path, once this loop is closed |
| 958 | fn f a own uint 4 n uint to void |
| 959 | free a |
| 960 | while gt n 0 |
| 961 | while gt n 1 |
| 962 | x = get a 0 |
| 963 | n = sub n x |
| 964 | end |
| 965 | n = sub n 1 |
| 966 | end |
| 967 | end |
| 968 | -- control |
| 969 | fn f a own uint 4 n uint to void |
| 970 | free a |
| 971 | while gt n 0 |
| 972 | while gt n 1 |
| 973 | x = get a 0 |
| 974 | n = sub n x |
| 975 | end |
| 976 | free a |
| 977 | a = new uint 4 n |
| 978 | n = sub n 1 |
| 979 | end |
| 980 | free a |
| 981 | end |
| 982 | EOF |
| 983 | for want in "$T"/r*.want; do |
| 984 | k="${want%.want}" |
| 985 | w="$(cat "$want")" |
| 986 | out="$("$G" emit "$k.bad" "$T/x.json" || true)" |
| 987 | case "$out" in "REFUSED omegese: "*"$w"*) r=$((r + 1)) ;; *) bad "refusal '$w': got '$out'" ;; esac |
| 988 | if ! "$G" emit "$k.ok" "$T/x.json" > "$T/x.out" || ! "$OME" emit "$T/x.json" "$T/x.oscir" > "$T/x.out"; then |
| 989 | bad "control for '$w': $(cat "$T/x.out")" |
| 990 | else |
| 991 | v="$("$C2" check "$T/x.oscir" 2>&1 | head -1 || true)" |
| 992 | case "$v" in checker2=ACCEPT*) ;; *) bad "control for '$w' checker2: $v" ;; esac |
| 993 | fi |
| 994 | done |
| 995 | echo "refusals: $r/$(ls "$T"/r*.want | wc -l) refused with the expected reason, every control accepted" |
| 996 | |
| 997 | # 3. loop guard negative control |
| 998 | ctr="$(grep -o '"op": "ge", "dst": [0-9]*, "a": [0-9]*' "$T/dev04.json" | head -1 | sed 's/.*"a": //')" |
| 999 | sed -E "s/\{\"op\": \"add\", \"dst\": $ctr, \"a\": $ctr, \"b\": [0-9]+\}, //" "$T/dev04.json" > "$T/m.json" |
| 1000 | if cmp -s "$T/dev04.json" "$T/m.json"; then bad "loop mutant: the counter increment was not found"; fi |
| 1001 | if "$OME" emit "$T/m.json" "$T/m.oscir" > "$T/m.out"; then |
| 1002 | v="$("$C2" check "$T/m.oscir" 2>&1 | head -1 || true)" |
| 1003 | case "$v" in *"rule=C2-LOOP-UNBOUNDED"*) echo "loop guard: mutant without the counter increment REJECTED (C2-LOOP-UNBOUNDED)" ;; |
| 1004 | *) bad "loop mutant not rejected: $v" ;; esac |
| 1005 | else bad "loop mutant refused earlier than checker2: $(cat "$T/m.out")"; fi |
| 1006 | |
| 1007 | # 4. tokenizer gate |
| 1008 | if [ -n "${OMEGESE_TOKCOUNT:-}" ] && [ -n "${OMEGESE_TOKENIZER:-}" ]; then |
| 1009 | multi="$("$OMEGESE_TOKCOUNT" "$OMEGESE_TOKENIZER" words $("$G" words) bound | awk '$1 != 1 {print $3}')" |
| 1010 | if [ -n "$multi" ]; then bad "words that are not one token: $multi"; else echo "tokenizer gate: every fixed word is one token"; fi |
| 1011 | else |
| 1012 | echo "tokenizer gate: SKIPPED (set OMEGESE_TOKCOUNT and OMEGESE_TOKENIZER)" |
| 1013 | fi |
| 1014 | |
| 1015 | |
| 1016 | # 5. next is exact (docs/one_layer/OMEGESE.md section 6). `next --machine` prints the legal items, one |
| 1017 | # per line: word <w>, newname <excluded>..., number <lo> <hi>, (, ), space, newline, eof. |
| 1018 | # Oracle: at every word boundary of every accepted program (dev, nested, trial-2, coverage, refusal |
| 1019 | # controls) the word that follows is legal, and eof is legal at the end. Truncation fuzz: every |
| 1020 | # byte prefix of the nested, trial-2 and coverage programs goes through emit and next and ends with |
| 1021 | # exit 0 or 1 (no crash; the suite also runs on an ASan/UBSan build); for accepted programs next |
| 1022 | # must also allow the byte that follows, and complete must finish the prefix into an accepted program. |
| 1023 | FIXEDW=" $("$G" words | tr '\n' ' ')u8 u16 u32 u64 i8 i16 i32 i64 " |
| 1024 | dec_le() { # <a> <b>: a <= b, for canonical decimal integers of any size |
| 1025 | local a="$1" b="$2" x y |
| 1026 | if [[ $a == -* ]]; then |
| 1027 | [[ $b == -* ]] || return 0 |
| 1028 | x="${a#-}" y="${b#-}" |
| 1029 | [ ${#x} -ne ${#y} ] && { [ ${#x} -gt ${#y} ]; return; } |
| 1030 | [[ ! $x < $y ]]; return |
| 1031 | fi |
| 1032 | [[ $b == -* ]] && return 1 |
| 1033 | [ ${#a} -ne ${#b} ] && { [ ${#a} -lt ${#b} ]; return; } |
| 1034 | [[ ! $a > $b ]] |
| 1035 | } |
| 1036 | mallowed() { # <items> <word>: do the items allow the whole word (NL a newline, EOF the end of input) |
| 1037 | local items="$1" w="$2" k lo hi rest |
| 1038 | local it=$'\n'"$items"$'\n' |
| 1039 | case "$items" in REFUSED*|"") return 1 ;; esac |
| 1040 | case "$w" in |
| 1041 | NL) [[ $it == *$'\nnewline\n'* ]]; return ;; |
| 1042 | EOF) [[ $it == *$'\neof\n'* ]]; return ;; |
| 1043 | "("|")") [[ $it == *$'\n'"$w"$'\n'* ]]; return ;; |
| 1044 | esac |
| 1045 | [[ $it == *$'\n'"word $w"$'\n'* ]] && return 0 |
| 1046 | if [[ $w =~ ^(0|-?[1-9][0-9]*)$ ]]; then |
| 1047 | while read -r k lo hi; do [ "$k" = number ] && dec_le "$lo" "$w" && dec_le "$w" "$hi" && return 0; done <<< "$items" |
| 1048 | return 1 |
| 1049 | fi |
| 1050 | [[ $w =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] && [ ${#w} -le 63 ] && [[ $FIXEDW != *" $w "* ]] || return 1 |
| 1051 | while read -r k rest; do |
| 1052 | [ "$k" = newname ] || continue |
| 1053 | [[ " $rest " == *" $w "* ]] && return 1 |
| 1054 | return 0 |
| 1055 | done <<< "$items" |
| 1056 | return 1 |
| 1057 | } |
| 1058 | toks() { # <text>: TO[] the byte offset and TW[] the text of every word (NL for a newline) |
| 1059 | local s="$1" i=0 n=${#1} j c |
| 1060 | TO=() TW=() |
| 1061 | while ((i < n)); do |
| 1062 | c="${s:i:1}" |
| 1063 | case "$c" in |
| 1064 | " "|$'\t'|$'\r') i=$((i + 1)) ;; |
| 1065 | $'\n') TO+=("$i"); TW+=(NL); i=$((i + 1)) ;; |
| 1066 | "("|")") TO+=("$i"); TW+=("$c"); i=$((i + 1)) ;; |
| 1067 | *) j=$i |
| 1068 | while ((j < n)); do case "${s:j:1}" in " "|$'\t'|$'\r'|$'\n'|"("|")") break ;; esac; j=$((j + 1)); done |
| 1069 | TO+=("$i"); TW+=("${s:i:j-i}"); i=$j ;; |
| 1070 | esac |
| 1071 | done |
| 1072 | } |
| 1073 | mnext() { printf '%s' "$1" > "$T/p"; "$G" next --machine "$T/p" 2>&1 || true; } |
| 1074 | NB=0 |
| 1075 | walk_in() { # <text>: every word is legal at its position and eof at the end; else WHERE says where not |
| 1076 | local s="$1" k items |
| 1077 | toks "$s" |
| 1078 | for ((k = 0; k < ${#TW[@]}; k++)); do |
| 1079 | items="$(mnext "${s:0:TO[k]}")" |
| 1080 | NB=$((NB + 1)) |
| 1081 | mallowed "$items" "${TW[k]}" || { WHERE="'${TW[k]}' at byte ${TO[k]}: $(head -3 <<< "$items" | tr '\n' '|')"; return 1; } |
| 1082 | done |
| 1083 | items="$(mnext "$s")" |
| 1084 | mallowed "$items" EOF || { WHERE="the end of input: $(head -3 <<< "$items" | tr '\n' '|')"; return 1; } |
| 1085 | } |
| 1086 | progs=("$ROOT"/tests/one_layer/omegese/dev/*.omegese "$ROOT"/tests/one_layer/omegese/nested/*.omegese "$T"/c*.omegese "$T"/r*.ok) |
| 1087 | for f in "$ROOT"/tests/one_layer/omegese/trial2/*.omegese; do [ "$(basename "$f")" = dev07.omegese ] || progs+=("$f"); done |
| 1088 | for f in "${progs[@]}"; do |
| 1089 | s="$(cat "$f")"$'\n' |
| 1090 | walk_in "$s" || bad "next blocks $WHERE of $(basename "$f")" |
| 1091 | done |
| 1092 | echo "next oracle: every word and the end of input legal at all $NB word boundaries of ${#progs[@]} accepted programs" |
| 1093 | |
| 1094 | # 6. completeness and soundness against emit: single-word mutants of every accepted program (a word |
| 1095 | # deleted, doubled or replaced by a fixed word, a name of the program, a number or a fresh name). |
| 1096 | # emit accepts a mutant iff every word of it was legal at its position and eof at its end. |
| 1097 | RANDOM=445 |
| 1098 | NUMS=(0 1 -1 7 14 15 64 65 127 128 255 256 -128 -129 1000000 1000001 4294967295 4294967296 -0 007) |
| 1099 | read -ra FIXA <<< "$FIXEDW" |
| 1100 | nmut=0 nacc=0 NB=0 |
| 1101 | for f in "${progs[@]}"; do |
| 1102 | s="$(cat "$f")"$'\n' |
| 1103 | toks "$s" |
| 1104 | ow=("${TW[@]}") |
| 1105 | ids=() |
| 1106 | for w in "${ow[@]}"; do [[ $w =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] && [[ $FIXEDW != *" $w "* ]] && ids+=("$w"); done |
| 1107 | for ((m = 0; m < ${OMEGESE_MUTANTS:-2}; m++)); do |
| 1108 | n=${#ow[@]} k=$((RANDOM % ${#ow[@]})) how=$((RANDOM % 6)) |
| 1109 | case $how in |
| 1110 | 0) rep=() ;; |
| 1111 | 1) rep=("${ow[k]}" "${ow[k]}") ;; |
| 1112 | 2) rep=("${NUMS[RANDOM % ${#NUMS[@]}]}") ;; |
| 1113 | 3) rep=("${ids[RANDOM % ${#ids[@]}]}") ;; |
| 1114 | 4) rep=("zq$m") ;; |
| 1115 | *) rep=("${FIXA[RANDOM % ${#FIXA[@]}]}") ;; |
| 1116 | esac |
| 1117 | out="" prev=NL |
| 1118 | for ((q = 0; q < n; q++)); do |
| 1119 | if ((q == k)); then set -- "${rep[@]}"; else set -- "${ow[q]}"; fi |
| 1120 | for w in "$@"; do |
| 1121 | if [ "$w" = NL ]; then out+=$'\n'; else [ "$prev" = NL ] || out+=" "; out+="$w"; fi |
| 1122 | prev="$w" |
| 1123 | done |
| 1124 | done |
| 1125 | printf '%s' "$out" > "$T/mut.omegese" |
| 1126 | acc=0; "$G" emit "$T/mut.omegese" "$T/mut.json" > /dev/null 2>&1 && acc=1 |
| 1127 | in=0; walk_in "$out" && in=1 |
| 1128 | nmut=$((nmut + 1)) nacc=$((nacc + acc)) |
| 1129 | [ "$acc" = "$in" ] || bad "mutant of $(basename "$f") (word $k -> '${rep[*]}'): emit accepts=$acc, every word legal=$in (${WHERE:-})" |
| 1130 | done |
| 1131 | done |
| 1132 | echo "completeness: $nmut single-word mutants ($nacc accepted by emit): emit accepts iff every word was legal ($NB word boundaries)" |
| 1133 | |
| 1134 | # 7. soundness fuzz: from random accepted prefixes, pick random legal items and extend; the legal set is |
| 1135 | # never empty, a word picked is still legal after any of its first characters, and `omegese |
| 1136 | # complete` (close everything) finishes the walk into a program emit accepts, in a bounded number of |
| 1137 | # lines (at most the words of the prefix plus 3). |
| 1138 | RANDOM=4452 |
| 1139 | nwalk=0 nstep=0 |
| 1140 | # walk_items <steps>: extend P by up to <steps> random legal items (stops at eof); every set must be |
| 1141 | # nonempty and a word picked must stay legal after each of its first characters. Returns 1 (and counts a |
| 1142 | # failure) when not. |
| 1143 | walk_items() { |
| 1144 | local st items it x lo hi v q d j c |
| 1145 | for ((st = 0; st < $1; st++)); do |
| 1146 | items="$(mnext "$P")" |
| 1147 | if [ -z "$items" ] || [[ $items == REFUSED* ]]; then bad "soundness: no legal item after $(printf '%s' "$P" | tail -c 70 | tr '\n' '|') ($items)"; return 1; fi |
| 1148 | mapfile -t IT <<< "$items" |
| 1149 | it="${IT[RANDOM % ${#IT[@]}]}" x="" |
| 1150 | nstep=$((nstep + 1)) |
| 1151 | case "$it" in |
| 1152 | eof) return 0 ;; |
| 1153 | newline) P+=$'\n' ;; |
| 1154 | space) P+=" " ;; |
| 1155 | "("|")") P+="$it" ;; |
| 1156 | "word "*) x="${it#word }" ;; |
| 1157 | newname*) for ((q = 0; q < 9; q++)); do x="n$RANDOM"; mallowed "$items" "$x" && break; done ;; |
| 1158 | number*) read -r _ lo hi <<< "$it"; c=() |
| 1159 | for v in "$lo" "$hi" 0 1 -1 9 100; do dec_le "$lo" "$v" && dec_le "$v" "$hi" && c+=("$v"); done |
| 1160 | # and a random value inside: by arithmetic when the interval fits, else random digits |
| 1161 | if [ ${#lo} -le 17 ] && [ ${#hi} -le 17 ]; then |
| 1162 | c+=("$((lo + (RANDOM << 30 | RANDOM << 15 | RANDOM) % (hi - lo + 1)))") |
| 1163 | else |
| 1164 | for ((q = 0; q < 9; q++)); do |
| 1165 | v=$((1 + RANDOM % 9)); for ((d = RANDOM % 20; d > 0; d--)); do v+=$((RANDOM % 10)); done |
| 1166 | [[ $lo == -* ]] && ((RANDOM % 2)) && v="-$v" |
| 1167 | dec_le "$lo" "$v" && dec_le "$v" "$hi" && { c+=("$v"); break; } |
| 1168 | done |
| 1169 | fi |
| 1170 | x="${c[RANDOM % ${#c[@]}]}" ;; |
| 1171 | *) bad "soundness: unknown item '$it'"; return 1 ;; |
| 1172 | esac |
| 1173 | [ -n "$x" ] || continue |
| 1174 | if [ ${#x} -ge 2 ]; then |
| 1175 | j=$((1 + RANDOM % (${#x} - 1))) |
| 1176 | mallowed "$(mnext "$P${x:0:j}")" "$x" || { bad "soundness: '$x' legal, but not after its first $j characters: $(printf '%s' "$P" | tail -c 50 | tr '\n' '|')"; return 1; } |
| 1177 | fi |
| 1178 | P+="$x " |
| 1179 | done |
| 1180 | } |
| 1181 | # close_walk <out file>: `omegese complete` finishes P; the whole text goes to <out file>, which emit must |
| 1182 | # accept (returns 1 and counts a failure when complete refuses or emit refuses the result) |
| 1183 | close_walk() { |
| 1184 | printf '%s' "$P" > "$T/w.omegese" |
| 1185 | if ! "$G" complete "$T/w.omegese" > "$T/w.tail" 2> "$T/w.err"; then bad "soundness: complete refused after a legal walk: $(cat "$T/w.tail" "$T/w.err" | head -2)"; return 1; fi |
| 1186 | cat "$T/w.omegese" "$T/w.tail" > "$1" |
| 1187 | "$G" emit "$1" "$T/w2.json" > "$T/w2.out" || { bad "soundness: walk + completion refused: $(cat "$T/w2.out")"; return 1; } |
| 1188 | } |
| 1189 | for ((wk = 0; wk < ${OMEGESE_WALKS:-40}; wk++)); do |
| 1190 | f="${progs[RANDOM % ${#progs[@]}]}" |
| 1191 | s="$(cat "$f")"$'\n' |
| 1192 | toks "$s" |
| 1193 | P="${s:0:TO[RANDOM % ${#TO[@]}]}" |
| 1194 | case "${P: -1}" in ""|" "|$'\n'|"("|")") ;; *) P+=" " ;; esac # start at a word boundary |
| 1195 | walk_items "${OMEGESE_STEPS:-25}" || continue |
| 1196 | close_walk "$T/w2.omegese" || continue |
| 1197 | toks "$P" |
| 1198 | lines=$(grep -c '' "$T/w.tail" || true) |
| 1199 | [ "$lines" -le $((${#TW[@]} + 3)) ] || bad "soundness: completion of $lines lines for a prefix of ${#TW[@]} words" |
| 1200 | nwalk=$((nwalk + 1)) |
| 1201 | done |
| 1202 | echo "soundness fuzz: $nwalk/${OMEGESE_WALKS:-40} random walks ($nstep legal items picked) never met an empty set and closed into accepted programs" |
| 1203 | # 8. checker2 residual (OMEGESE.md 6.4): `omegese next` is exact relative to emit, not to omega_emit and |
| 1204 | # checker2. Random walks from the empty prefix (whole programs) and from cut points of the suite's |
| 1205 | # programs, each closed by `omegese complete` (so emit accepts it, checked), then omega_emit and |
| 1206 | # checker2: every rejection after emit is counted by stage and reason. The suite's own programs are |
| 1207 | # the zero line (all accepted, sections 1 and 1a). OMEGESE_RESIDUAL_WALKS sets the number of walks |
| 1208 | # of each kind; OMEGESE_RESIDUAL_MAX the rejections allowed (default 0: none is known after the |
| 1209 | # rules folded into the oracle; a measured rate is printed either way). |
| 1210 | declare -A RES=() |
| 1211 | chain_after_emit() { # <program> -> "" when omega_emit and checker2 accept, else "<stage> <reason>" |
| 1212 | "$G" emit "$1" "$T/r.json" > "$T/r.out" 2>&1 || { echo "emit $(head -c 80 "$T/r.out")"; return; } |
| 1213 | if ! "$OME" emit "$T/r.json" "$T/r.oscir" > "$T/r.out" 2>&1; then |
| 1214 | echo "omega_emit $(head -n 1 "$T/r.out" | sed -E "s/'[^']*'/X/g; s/[0-9]+/N/g" | cut -c1-70)"; return |
| 1215 | fi |
| 1216 | local v; v="$("$C2" check "$T/r.oscir" 2>&1 | head -n 1 || true)" |
| 1217 | case "$v" in checker2=ACCEPT*) ;; *) echo "checker2 $(grep -oE 'C2-[A-Z0-9-]+' <<< "$v" | head -n 1)" ;; esac |
| 1218 | } |
| 1219 | nres=0 nrej=0 |
| 1220 | RANDOM=4453 |
| 1221 | for ((wk = 0; wk < ${OMEGESE_RESIDUAL_WALKS:-40}; wk++)); do |
| 1222 | for start in empty cut; do |
| 1223 | if [ "$start" = empty ]; then P="" |
| 1224 | else |
| 1225 | f="${progs[RANDOM % ${#progs[@]}]}"; s="$(cat "$f")"$'\n'; toks "$s" |
| 1226 | P="${s:0:TO[RANDOM % ${#TO[@]}]}" |
| 1227 | case "${P: -1}" in ""|" "|$'\n'|"("|")") ;; *) P+=" " ;; esac |
| 1228 | fi |
| 1229 | walk_items "${OMEGESE_STEPS:-25}" || continue |
| 1230 | close_walk "$T/res.omegese" || continue |
| 1231 | nres=$((nres + 1)) |
| 1232 | why="$(chain_after_emit "$T/res.omegese")" |
| 1233 | [ -n "$why" ] || continue |
| 1234 | nrej=$((nrej + 1)); RES[$why]=$((${RES[$why]:-0} + 1)) |
| 1235 | [ -n "${OMEGESE_RESIDUAL_KEEP:-}" ] && cp "$T/res.omegese" "$OMEGESE_RESIDUAL_KEEP/rej-$nrej.omegese" |
| 1236 | done |
| 1237 | done |
| 1238 | for k in "${!RES[@]}"; do echo " residual: ${RES[$k]} x $k"; done | LC_ALL=C sort |
| 1239 | echo "checker2 residual: $nrej of $nres completed walks that emit accepts are rejected later (omega_emit or checker2)" |
| 1240 | [ "$nres" -gt 0 ] || bad "residual: no completed walk" |
| 1241 | [ "$nrej" -le "${OMEGESE_RESIDUAL_MAX:-0}" ] || bad "residual: $nrej walks pass emit and are rejected later (allowed ${OMEGESE_RESIDUAL_MAX:-0})" |
| 1242 | nf=0 nfs=0 |
| 1243 | WC=$'[^ \t\r\n()]' |
| 1244 | for f in "$ROOT"/tests/one_layer/omegese/nested/*.omegese "$ROOT"/tests/one_layer/omegese/trial2/*.omegese "$T"/c*.omegese; do |
| 1245 | s="$(cat "$f")"$'\n' |
| 1246 | # an accepted program: every byte prefix must also be open (next exit 0), allow the byte that |
| 1247 | # follows (the whole word it belongs to, a space, a newline, a bracket or the end), and be finished |
| 1248 | # by `omegese complete` into a program emit accepts. A refused one (trial2/dev07): no crash only. |
| 1249 | full=0; printf '%s' "$s" > "$T/p"; "$G" emit "$T/p" "$T/p.json" > /dev/null 2>&1 && full=1 |
| 1250 | for ((i = 0; i <= ${#s}; i++)); do |
| 1251 | printf '%s' "${s:0:i}" > "$T/p" |
| 1252 | rc=0; "$G" emit "$T/p" "$T/p.json" > /dev/null 2>&1 || rc=$? |
| 1253 | [ "$rc" -le 1 ] || { bad "emit exit $rc on byte prefix $i of $(basename "$f")"; break; } |
| 1254 | rc=0; "$G" next "$T/p" > /dev/null 2>&1 || rc=$? |
| 1255 | [ "$rc" -le 1 ] || { bad "next exit $rc on byte prefix $i of $(basename "$f")"; break; } |
| 1256 | rc=0; items="$("$G" next --machine "$T/p" 2>&1)" || rc=$? |
| 1257 | [ "$rc" -le 1 ] || { bad "next --machine exit $rc on byte prefix $i of $(basename "$f")"; break; } |
| 1258 | nf=$((nf + 1)) |
| 1259 | [ "$full" = 1 ] || continue |
| 1260 | [ "$rc" -eq 0 ] || { bad "byte prefix $i of $(basename "$f") refused: $items"; break; } |
| 1261 | c="${s:i:1}" |
| 1262 | case "$c" in |
| 1263 | "") w=EOF ;; |
| 1264 | " "|$'\t') w=space ;; |
| 1265 | $'\n') w=NL ;; |
| 1266 | "("|")") w="$c" ;; |
| 1267 | *) [[ ${s:0:i} =~ ($WC*)$ ]]; w="${BASH_REMATCH[1]}"; [[ ${s:i} =~ ^($WC*) ]]; w+="${BASH_REMATCH[1]}" ;; |
| 1268 | esac |
| 1269 | if [ "$w" = space ]; then [[ $'\n'"$items"$'\n' == *$'\nspace\n'* ]] |
| 1270 | else mallowed "$items" "$w"; fi || { bad "byte prefix $i of $(basename "$f"): the next byte ('$w') is not allowed"; break; } |
| 1271 | rc=0; "$G" complete "$T/p" > "$T/p.c" 2>&1 || rc=$? |
| 1272 | { [ "$rc" -eq 0 ] && cat "$T/p" "$T/p.c" > "$T/pc.omegese" && "$G" emit "$T/pc.omegese" "$T/p.json" > /dev/null 2>&1; } \ |
| 1273 | || { bad "byte prefix $i of $(basename "$f"): complete does not finish it into an accepted program"; break; } |
| 1274 | nfs=$((nfs + 1)) |
| 1275 | done |
| 1276 | done |
| 1277 | echo "truncation fuzz: $nf byte prefixes through emit, next and next --machine, exit 0 or 1; at the $nfs prefixes of accepted programs, next allows the byte that follows and complete finishes into a program emit accepts" |
| 1278 | if [ "${OMEGESE_SANITIZED:-0}" = 1 ]; then |
| 1279 | if [ -s "$T/san.log" ]; then bad "sanitizer reports: $(grep -m3 -E '^==|ERROR|runtime error' "$T/san.log")" |
| 1280 | else echo "sanitizers: no ASan or UBSan report in the whole run"; fi |
| 1281 | fi |
| 1282 | [ "$fails" -eq 0 ] || { echo "test-omegese: $fails failure(s)"; exit 1; } |
| 1283 | echo "test-omegese: PASS" |