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/tests/runtime/rx_emergency_mutants.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 / tests / runtime / rx_emergency_mutants.sh` 77 lines ยท 5750 bytes Raw Blame History 1 #!/bin/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 # R16 G6 operator emergency stop: each guard is load-bearing. Every mutant below 18 # removes one guard from a temporary copy of the runtime; tests/runtime/rx_emergency.c 19 # must FAIL against each one (and PASS against the unmutated copy). A mutant whose 20 # pattern no longer matches is a failure of this script, never a silent skip. 21 set -u 22 HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd) 23 W=$(mktemp -d "${TMPDIR:-/tmp}/rx-estop-mut.XXXXXX") 24 trap 'rm -rf "$W"' EXIT 25 CC=${CC:-cc} 26 SRCS="src/runtime/rx_caproot.c src/runtime/rx_world.c src/runtime/rx_coherent.c src/runtime/rx_generation.c src/omega_om_units.c tests/runtime/rx_emergency.c" 27 28 # name|file|perl substitution (applied with -0, must match exactly once) 29 MUTANTS='M1 run_one publishes under a stop|src/runtime/rx_world.c|s/(on resume, against the state then \(rearm keeps its admission path\)\. \*\/\n )if \(w->halted\) \{/${1}if (0) {/ 30 M2 workers take work under a stop|src/runtime/rx_world.c|s/\(w->halted \|\| !pop_ready\(w, &rid\)\)/(!pop_ready(w, \&rid))/ 31 M3 outside publication under a stop|src/runtime/rx_world.c|s/if \(w->halted\) \{( +)\/\* R16 G6: nothing outside publishes \*\//if (0) {$1\/* R16 G6: nothing outside publishes *\// 32 M4 caller check ignores the stop|src/runtime/rx_world.c|s/if \(w->halted\) \{\n pthread_mutex_unlock\(&w->callers_mu\);\n return RX_CALLER_ERR_HALTED;/if (0) {\n pthread_mutex_unlock(\&w->callers_mu);\n return RX_CALLER_ERR_HALTED;/ 33 M5 a reaction subject may stop the world|src/runtime/rx_world.c|s/if \(w->reactions\[i\]\.desc\.subject == subject\) return RX_ERR_AUTHORITY;/(void)i;/ 34 M6 store ignores the durable mark|src/runtime/rx_generation.c|s/(static int halt_marked\(const RxGenStore \*store\) \{\n)/$1 if (store) return 0;\n/ 35 M7 a restarted world ignores the mark|src/runtime/rx_world.c|s/\} else if \(rc != 0 && !w->halted\) \{/} else if (0) {/ 36 M8 resume deletes the mark without keeping the record|src/runtime/rx_world.c|s/if \(rc == RX_OK && durable_write\(w->halt_dir, name, buf, \(size_t\)n, true\) != 0\)/if (0)/ 37 M9 the stop is not in force until the disk write returns|src/runtime/rx_world.c|s/( w->halted = true; \/\* in force before any disk work \*\/\n)( w->halt\.durable = halt_mark_write\(w\);\n)/$2 if (w->halt.durable != 1) w->halted = false; else w->halted = true;\n/ 38 M10 a refused activation spends the episode budget|src/runtime/rx_world.c|s/ if \(r->episode_activations\) r->episode_activations--;\n r->rearm = true;\n end_activation\(w, rid\);/ r->rearm = true;\n end_activation(w, rid);/ 39 M11 object create under a stop|src/runtime/rx_world.c|s/(RxObjRef \*out\) \{\n pthread_mutex_lock\(&w->mu\);\n )if \(w->halted\)/${1}if (0)/ 40 M12 object retire under a stop|src/runtime/rx_world.c|s/(int rx_world_retire\(RxWorld \*w, RxObjRef ref\) \{\n pthread_mutex_lock\(&w->mu\);\n )if \(w->halted\)/${1}if (0)/ 41 M13 a symlink mark reads as absent|src/runtime/rx_world.c|s/errno == ELOOP \? RX_ERR_TORN : RX_ERR_IO/errno == ELOOP ? 0 : RX_ERR_IO/' 42 43 build_run() { # dir -> exit status of the test 44 (cd "$1" && $CC -std=gnu11 -Wall -Wextra -D_GNU_SOURCE -O2 -Isrc -pthread -o t $SRCS) >"$1/build.log" 2>&1 || { echo "build failed:"; tail -5 "$1/build.log"; return 99; } 45 (cd "$1" && timeout 300 ./t) >"$1/run.log" 2>&1 46 } 47 48 copy() { mkdir -p "$1"; (cd "$HERE" && tar -cf - src tests/runtime/rx_emergency.c) | tar -xf - -C "$1"; } 49 50 fails=0 51 copy "$W/base" 52 build_run "$W/base"; rc=$? 53 if [ $rc = 0 ]; then echo "ok unmutated: PASS"; else echo "FAIL unmutated: exit $rc"; tail -5 "$W/base/run.log"; fails=$((fails + 1)); fi 54 while IFS='|' read -r name file sub; do 55 [ -n "$name" ] || continue 56 d="$W/m${name%% *}" 57 copy "$d" 58 # Count with the same pattern applied globally (s///g returns the number of 59 # matches); apply the mutant only when it matches exactly once. 60 n=$(perl -0 -e 'my $s = do { local $/; }; my $c = eval "\$s =~ $ARGV[0]g"; die $@ if $@; print $c ? $c + 0 : 0' "$sub" < "$d/$file") 61 if [ "$n" != 1 ]; then 62 echo "FAIL $name: pattern matched ${n:-?} times (must be 1)"; fails=$((fails + 1)); continue 63 fi 64 perl -0pi -e "$sub" "$d/$file" 65 if cmp -s "$d/$file" "$HERE/$file"; then 66 echo "FAIL $name: substitution changed nothing"; fails=$((fails + 1)); continue 67 fi 68 build_run "$d"; rc=$? 69 # Killed means the test ran and at least one check failed; a crash or a 70 # timeout without a failed check is not counted as a kill. 71 nf=$(grep -c '^\[-\]' "$d/run.log" 2>/dev/null); nf=${nf:-0} 72 if [ $rc = 99 ]; then echo "FAIL $name: mutant did not build"; fails=$((fails + 1)) 73 elif [ $rc != 0 ] && [ "$nf" -gt 0 ]; then echo "ok $name: killed ($nf checks failed)" 74 elif [ $rc != 0 ]; then echo "FAIL $name: exit $rc with no failed check (crash or timeout)"; fails=$((fails + 1)) 75 else echo "FAIL $name: SURVIVED"; fails=$((fails + 1)); fi 76 done <<< "$MUTANTS" 77 if [ $fails = 0 ]; then echo "RX_EMERGENCY_MUTANTS: PASS"; else echo "RX_EMERGENCY_MUTANTS: FAIL ($fails)"; exit 1; fi