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 / tools / numeric_oracle_mutations.sh

94 lines · 6136 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# numeric_oracle_mutations.sh -- proves the Gate 5 CPU tier is not vacuous.
18# Each mutation below changes one piece of arithmetic (or the exit-status rule)
19# in a scratch copy, rebuilds the CPU-only Gate 5 test and runs it. The run
20# must exit nonzero and report the named test ID as FAIL. Before the
21# independent oracle existed, the EXP/LOG and host-instruction mutations
22# passed every test because reference and CPU tier shared the same code.
23# Host only: opens no device, writes only under a temporary directory.
24# Run: make test-numeric-sweep (runs this after the CHECK sweep), or this file.
25#
26# This file is a thin adapter over tools/mutation_runner.sh. The mutant set is
27# the table below (id~file~edit~test ID that must FAIL, edit kind "replace":
28# R:<exact text>@>@<replacement>, @NL@ = newline). The runner takes ONE test
29# command per call, and this sweep needs a different named FAIL id per mutant,
30# so the adapter calls the runner once per row (ONLY=<id>) and maps the runner's
31# stderr line back to the legacy [KILLED]/[SURVIVED]/[BROKEN] lines. The judge
32# script exits nonzero (KILLED) only if the test binary exited nonzero AND the
33# named id is reported; it records the binary's exit status for the legacy line.
34set -u
35HERE=$(cd -P "$(dirname "$0")/.." && pwd)
36TMP=$(mktemp -d)
37trap 'rm -rf "$TMP"' EXIT
38# One line on purpose: $SRCS is interpolated into the runner's -b string, which
39# the runner executes with sh -c, so a newline here would split the gcc command.
40SRCS="tests/test_omega_numeric.c src/omega_numeric.c src/omega_numeric_provenance.c src/omega_numeric_divsqrt_gb10.c src/omega_blackwell_encoder.c src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_om_units.c"
41
42# id ~ file ~ edit ~ test ID that must FAIL (or UNDECLARED_SKIP)
43cat > "$TMP/rows" <<'ROWS_EOF'
44exp_coefficient~src/omega_numeric.c~R:const float c5 = 0.0083333338f;@>@const float c5 = 0.0093333338f;~CPU_TIER_INDEPENDENT_ORACLE
45exp_drop_ln2_lo~src/omega_numeric.c~R:float r = (x - fk * LN2_HI) - fk * LN2_LO;@>@float r = (x - fk * LN2_HI) - fk * 0.0f * LN2_LO;~CPU_TIER_INDEPENDENT_ORACLE
46log_coefficient~src/omega_numeric.c~R:const float c1 = 0.333333343f;@>@const float c1 = 0.343333343f;~CPU_TIER_INDEPENDENT_ORACLE
47cpu_fadd_is_fsub~src/omega_numeric.c~R:case OMEGA_NOP_FADD: __asm__ volatile("fadd@>@case OMEGA_NOP_FADD: __asm__ volatile("fsub~CPU_TIER_INDEPENDENT_ORACLE
48ref_fmul_rounds_twice~src/omega_numeric.c~R:float omega_ref_fmul(float a, float b) { return a * b; }@>@float omega_ref_fmul(float a, float b) { return (float)((double)a * (double)b * (1.0 + 0x1p-40)); }~CPU_TIER_INDEPENDENT_ORACLE
49ref_ffma_is_fmsub~src/omega_numeric.c~R:__asm__("fmadd %s0@>@__asm__("fmsub %s0~CPU_TIER_INDEPENDENT_ORACLE
50cpu_i2f_unsigned~src/omega_numeric.c~R:"scvtf %s0, %w1"@>@"ucvtf %s0, %w1"~CPU_TIER_INDEPENDENT_ORACLE
51cpu_rcp_is_fmul~src/omega_numeric.c~R:case OMEGA_NOP_MUFU_RCP: __asm__ volatile("fdiv@>@case OMEGA_NOP_MUFU_RCP: __asm__ volatile("fmul~CPU_TIER_INDEPENDENT_ORACLE
52ref_lds_identity~src/omega_numeric.c~R:r = a[i ^ (OMEGA_NUMERIC_CTA_THREADS - 1u)];@>@r = a[i];~CPU_TIER_INDEPENDENT_ORACLE
53ref_rni_ties_away~src/omega_numeric.c~R:default: if (frac == 3@>@default: if (frac >= 2) mag++; else if (frac == 3~E1_SCALAR_INDEPENDENT_ORACLE
54cpu_gtu_is_gt~src/omega_numeric.c~R:CPU_SEL("hi")@>@CPU_SEL("gt")~E1_SCALAR_INDEPENDENT_ORACLE
55ref_ffma_int_no_sticky~src/omega_numeric.c~R:(lost ? 1U : 0U)@>@(lost ? 0U : 0U)~E1_SCALAR_BOUNDARY_VALUES
56undeclared_skip~tests/test_omega_numeric.c~R: printf("\nGate 5 Results:@>@ skip("NOT_A_CHIP_ONLY_ID", "mutation");@NL@ printf("\nGate 5 Results:~UNDECLARED_SKIP
57ROWS_EOF
58
59cat > "$TMP/judge.sh" <<'JUDGE_EOF'
60#!/bin/sh
61# usage: judge.sh <tmpdir> <test id that must FAIL>
62"$1/t" > "$1/run.log" 2>&1; rc=$?
63echo "$rc" > "$1/rc"
64if [ "$rc" -ne 0 ] && { grep -qx "\[FAIL\] $2" "$1/run.log" || grep -q "^Gate 5 Verdict: $2 " "$1/run.log"; }; then exit 1; fi
65exit 0
66JUDGE_EOF
67
68total=0 killed=0 survived=0 broken=0
69while IFS='~' read -r name file edit want; do
70 [ -n "$name" ] || continue
71 total=$((total + 1))
72 rm -f "$TMP/rc" "$TMP/build.log"
73 printf '%s~%s~%s~%s\n' "$name" "$file" "$edit" "$want" > "$TMP/row"
74 # shellcheck disable=SC2086
75 ONLY=$name "$HERE/tools/mutation_runner.sh" -k table -m "$TMP/row" \
76 -d "$HERE" -c "src tests/test_omega_numeric.c tests/numeric_oracle.h" \
77 -b "gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -Isrc -DOMEGA_NUMERIC_CPU_ONLY -o $TMP/t $SRCS > $TMP/build.log 2>&1" \
78 -t "sh $TMP/judge.sh $TMP $want" -o "$TMP/out.json" > /dev/null 2> "$TMP/runner.err" < /dev/null
79 status=$(sed -n "s/^$name \([A-Z_]*\) .*/\1/p" "$TMP/runner.err" | head -1)
80 rc=$(cat "$TMP/rc" 2>/dev/null)
81 case $status in
82 KILLED) echo " [KILLED] $name: exit $rc, $want"; killed=$((killed + 1));;
83 SURVIVED) echo " [SURVIVED] $name: exit $rc, $want not reported"; survived=$((survived + 1));;
84 *)
85 if grep -q "^$name ERROR .*(build failed" "$TMP/runner.err"; then
86 echo " [BROKEN] $name: scratch copy does not build"; head -5 "$TMP/build.log"
87 else
88 echo " [BROKEN] $name: text not found exactly once in $file"
89 fi
90 broken=$((broken + 1));;
91 esac
92done < "$TMP/rows"
93echo "oracle mutations: $total, $killed caught, $survived survived, $broken broken"
94[ "$total" -gt 0 ] && [ "$killed" -eq "$total" ]