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 / checker2 / mutants.sh

100 lines · 4961 bytes Raw Blame History
1#!/bin/sh
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# Negative controls for checker2 (omega#446): every line tagged GUARD:<name> in a checker2 source
18# is removed, one at a time, in a scratch copy; the matching test is rebuilt against that copy and
19# MUST fail. A mutant that survives means the test cannot see that check, and this script fails.
20# Also requires the unmutated build to pass first (otherwise "fails" proves nothing).
21# Usage: sh tests/checker2/mutants.sh <cc> <scratch-dir> <ir-dir from differential.sh> <work-dir from lrat.sh>
22set -u
23CC=${1:-cc}
24OUT=${2:-build/checker2/mutants}
25IRDIR=${3:-build/checker2/differential/ir}
26LRATDIR=${4:-build/checker2/lrat}
27CFLAGS="-std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O1 -Isrc -Isrc/checker2"
28SIG="src/searchtrace/sig/ed25519.c src/searchtrace/sig/sha512.c src/searchtrace/sig/ct.c"
29mkdir -p "$OUT"
30total=0
31tagged=0
32killed=0
33survived=""
34
35# run_family <source under test> <test .c> <other sources> <test args>
36run_family() {
37 src=$1; test_c=$2; others=$3; targs=$4
38 base="$OUT/$(basename "$src" .c)"
39 # shellcheck disable=SC2086
40 if ! $CC $CFLAGS -o "$base.orig" "$test_c" "$src" $others 2>"$base.orig.log"; then
41 echo "mutants: baseline build failed for $src"; cat "$base.orig.log"; exit 1
42 fi
43 # shellcheck disable=SC2086
44 if ! "$base.orig" $targs >/dev/null 2>&1; then
45 echo "mutants: baseline test fails for $src; negative controls are meaningless"; exit 1
46 fi
47 # every "GUARD:" occurrence must be exactly one well-formed, unique tag on its own line, so the
48 # number of mutants run equals the number of tags (an empty, malformed, repeated or doubled
49 # tag would otherwise be skipped silently)
50 occ=$(grep -o "GUARD:" "$src" | wc -l)
51 names=$(grep -o "GUARD:[a-z0-9-]*" "$src" | sed "s/GUARD://" | grep -c . )
52 uniq_names=$(grep -o "GUARD:[a-z0-9-]*" "$src" | sed "s/GUARD://" | grep . | sort -u | wc -l)
53 lines=$(grep -c "GUARD:" "$src")
54 if [ "$occ" -ne "$names" ] || [ "$names" -ne "$uniq_names" ] || [ "$names" -ne "$lines" ]; then
55 echo "mutants: $src has $occ GUARD: occurrences on $lines lines but $uniq_names distinct well-formed tags"
56 exit 1
57 fi
58 tagged=$((tagged + occ))
59 for name in $(grep -o "GUARD:[a-z0-9-]*" "$src" | sed "s/GUARD://" | sort -u); do
60 total=$((total + 1))
61 m="$base.$name.c"
62 # drop the tagged line; a tagged "if (...)" line without ";" also drops its one-line body
63 awk -v tag="GUARD:$name" '
64 skip { skip = 0; next }
65 index($0, tag) && substr($0, index($0, tag) + length(tag)) ~ /^([^a-z0-9-]|$)/ { if ($0 !~ /;/) skip = 1; next }
66 { print }' "$src" > "$m"
67 # shellcheck disable=SC2086
68 if ! $CC $CFLAGS -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable \
69 -Wno-error -o "$base.$name" "$test_c" "$m" $others 2>"$base.$name.log"; then
70 echo "mutants: $src GUARD:$name does not build (counts as killed)"
71 killed=$((killed + 1))
72 continue
73 fi
74 # shellcheck disable=SC2086
75 if timeout 120 "$base.$name" $targs >/dev/null 2>&1; then
76 survived="$survived $src:$name"
77 else
78 killed=$((killed + 1))
79 fi
80 done
81}
82
83run_family src/checker2/c2_receipt.c tests/checker2/test_c2_receipt.c "src/omega_om_units.c $SIG" tests/checker2/fixtures
84run_family src/checker2/c2_ir.c tests/checker2/test_c2_ir.c src/checker2/c2_check.c "$IRDIR"
85run_family src/checker2/c2_check.c tests/checker2/test_c2_ir.c src/checker2/c2_ir.c "$IRDIR"
86run_family src/checker2/c2_lrat.c tests/checker2/test_c2_lrat.c "" ""
87run_family src/checker2/c2_blast.c tests/checker2/test_c2_blast.c "src/checker2/c2_ir.c src/checker2/c2_check.c src/checker2/c2_lrat.c" "$IRDIR $LRATDIR"
88
89echo "checker2 mutants: $killed of $total killed"
90# every GUARD tag in the checker2 sources is covered by a family above (none silently skipped)
91all=$(cat src/checker2/*.c src/checker2/*.h | grep -o "GUARD:" | wc -l)
92if [ "$all" -ne "$total" ] || [ "$tagged" -ne "$total" ]; then
93 echo "mutants: $all GUARD tags in src/checker2 but $total mutants run"; exit 1
94fi
95if [ -n "$survived" ]; then
96 echo "SURVIVED (a test cannot see this check):$survived"
97 exit 1
98fi
99[ "$total" -gt 0 ] || { echo "mutants: no GUARD lines found"; exit 1; }
100exit 0