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 / tests / runtime / rx_operator_mutants_evidence_test.sh

68 lines · 3849 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# Host self-test for the evidence rules of tests/runtime/rx_operator_mutants.sh (omega #313 item 2, #314).
18# Runs the script inside a fake tree with a stub compiler and a stub operator test; no real build, no chip.
19# 1. a failing run keeps its logs outside the work folder (RX_OP_MUT_KEEP);
20# 2. mutant programs run in their own folder: their build/qual-runs is not the fake tree's;
21# 3. a mutant program that does write under the real build/qual-runs makes the script FAIL.
22set -u
23HERE=$(cd "$(dirname "$0")/../.." && pwd)
24T=$(mktemp -d "${TMPDIR:-/tmp}/rxopmut.XXXXXX"); trap 'rm -rf "$T"' EXIT
25FAILS=0
26check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; FAILS=$((FAILS + 1)); fi; }
27F=$T/tree
28mkdir -p "$F/tests/runtime" "$F/src" "$F/tests/fabric" "$F/tools" "$F/build/qual-runs/existing"
29cp "$HERE/tests/runtime/rx_operator_mutants.sh" "$F/tests/runtime/"
30# Stub of the operator test: runs the built program once (as the real test does) and reports one failed check.
31printf '#!/bin/bash\n"$2" > /dev/null 2>&1 < /dev/null\necho "[-] stub check failed"\nexit 1\n' > "$F/tests/runtime/rx_operator_host.sh"
32echo keep > "$F/build/qual-runs/existing/sentinel"
33printf '#!/bin/sh\n:\n' > "$T/cli"; chmod +x "$T/cli"
34# Stub compiler: the "program" it builds writes a receipt relative to its working folder, and, when
35# STUB_REAL is set, also straight into the real build/qual-runs.
36cat > "$T/cc" <<'STUB'
37#!/bin/bash
38while [ $# -gt 0 ]; do [ "$1" = -o ] && { out=$2; break; }; shift; done
39cat > "$out" <<PROG
40#!/bin/bash
41mkdir -p build/qual-runs/stub && echo receipt > build/qual-runs/stub/r.json
42[ -n "${STUB_REAL:-}" ] && { mkdir -p "$STUB_REAL/build/qual-runs/leak"; echo x > "$STUB_REAL/build/qual-runs/leak/r.json"; }
43exit 1
44PROG
45chmod +x "$out"
46STUB
47chmod +x "$T/cc"
48run() { # keepdir, extra env...
49 local keep=$1; shift
50 env "$@" CC="$T/cc" CFLAGS= RX_PROD_ARGUS_FLAGS= RX_R13_SRCS=x RX_PROD_ARGUS_SRCS=y AIENOS_CAP_LIB= \
51 RX_OP_MUT_KEEP="$keep" bash "$F/tests/runtime/rx_operator_mutants.sh" "$T/cli" 2>&1
52}
53before=$(find "$F/build/qual-runs" | LC_ALL=C sort)
54out=$(run "$T/kept1" X=1); rc=$?
55check "failing run exits non-zero" '[ $rc != 0 ]'
56check "failing run keeps its logs" '[ -s "$T/kept1/base/run.log" ] && [ -s "$T/kept1/base/build.log" -o -e "$T/kept1/base/build.log" ]'
57check "failing run says where the logs are" 'echo "$out" | grep -q "logs kept in $T/kept1"'
58check "kept logs include the mutant receipt folder" '[ -s "$T/kept1/base/qual-runs/stub/r.json" ]'
59check "mutant receipt did not land in the real build/qual-runs" '[ "$(find "$F/build/qual-runs" | LC_ALL=C sort)" = "$before" ]'
60check "no leak reported when nothing leaked" '! echo "$out" | grep -q "wrote under the real"'
61out=$(run "$T/kept2" STUB_REAL="$F"); rc=$?
62check "a program writing under the real build/qual-runs is reported" 'echo "$out" | grep -q "FAIL mutant runs wrote under the real"'
63check "that run exits non-zero" '[ $rc != 0 ]'
64mkdir -p "$T/kept3"
65out=$(run "$T/kept3" X=1)
66check "an existing keep folder is not overwritten" 'echo "$out" | grep -q "not keeping logs" && [ -z "$(ls -A "$T/kept3")" ]'
67echo "rx_operator_mutants_evidence_test: $FAILS failures"
68[ "$FAILS" = 0 ]