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 / test_autodiff_conversion_equiv.sh

64 lines · 3487 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# Proof that tools/autodiff_mutations.sh (now an adapter over
18# tools/mutation_runner.sh) behaves like the pinned legacy script. Host, CPU
19# only. Runs the OLD script (git show 2dc9dd8:tools/autodiff_mutations.sh,
20# placed under tools/ because it cds to dirname/..; removed by the trap) and
21# the NEW script on the same tree, then compares stdout and exit code, and the
22# per-mutant verdict list (name + KILLED/SURVIVED/ERROR, derived from the
23# legacy "MUTATION <name>: ..." lines). Nothing is normalised: both scripts'
24# stdout carries no paths or timings (scratch dirs are never printed on the
25# pass path). A negative check proves the comparison can fail.
26set -u
27root=$(cd "$(dirname "$0")/.." && pwd)
28cd "$root" || exit 2
29PIN=2dc9dd8
30old=tools/.autodiff_mutations_old.$$.sh
31tmp=$(mktemp -d "${TMPDIR:-/tmp}/autodiff-equiv.XXXXXX") || exit 2
32trap 'rm -rf "$tmp" "$root/$old"' EXIT INT TERM
33git show "$PIN:tools/autodiff_mutations.sh" > "$old" || { echo "FAIL cannot extract $PIN"; exit 1; }
34chmod +x "$old"
35sh "$old" > "$tmp/old.out" 2>/dev/null; echo $? > "$tmp/old.rc"
36sh tools/autodiff_mutations.sh > "$tmp/new.out" 2>/dev/null; echo $? > "$tmp/new.rc"
37
38verdicts() { # stdout file -> "name VERDICT" lines
39 sed -n 's/^MUTATION \([A-Z_0-9]*\): caught.*/\1 KILLED/p;
40 s/^MUTATION \([A-Z_0-9]*\): NOT CAUGHT.*/\1 SURVIVED/p;
41 s/^MUTATION \([A-Z_0-9]*\): \(NOT APPLIED\|does not build\).*/\1 ERROR/p' "$1"
42}
43verdicts "$tmp/old.out" > "$tmp/old.v"
44verdicts "$tmp/new.out" > "$tmp/new.v"
45count=$(wc -l < "$tmp/old.v")
46
47fails=0
48chk() { if [ "$2" = 0 ]; then echo "ok $1"; else echo "FAIL $1"; fails=$((fails + 1)); fi; }
49[ "$count" -ge 5 ]; chk "old script produced at least 5 mutant verdicts ($count)" $?
50cmp -s "$tmp/old.rc" "$tmp/new.rc"; chk "exit code identical (old $(cat "$tmp/old.rc"), new $(cat "$tmp/new.rc"))" $?
51cmp -s "$tmp/old.out" "$tmp/new.out"; chk "stdout byte-identical" $?
52cmp -s "$tmp/old.v" "$tmp/new.v"; chk "per-mutant verdict list identical" $?
53
54# Negative check: an altered verdict line must be reported as different.
55sed '1s/KILLED/SURVIVED/' "$tmp/new.v" > "$tmp/alt.v"
56if cmp -s "$tmp/old.v" "$tmp/alt.v"; then chk "negative: altered verdict is detected" 1; else chk "negative: altered verdict is detected" 0; fi
57sed '1s/^MUTATION/MUTATIONX/' "$tmp/new.out" > "$tmp/alt.out"
58if cmp -s "$tmp/old.out" "$tmp/alt.out"; then chk "negative: altered stdout is detected" 1; else chk "negative: altered stdout is detected" 0; fi
59echo $(( $(cat "$tmp/old.rc") + 1 )) > "$tmp/alt.rc"
60if cmp -s "$tmp/old.rc" "$tmp/alt.rc"; then chk "negative: altered exit code is detected" 1; else chk "negative: altered exit code is detected" 0; fi
61
62echo "compared $count mutants"
63if [ "$fails" -ne 0 ]; then echo "autodiff conversion equivalence: FAIL"; exit 1; fi
64echo "autodiff conversion equivalence: PASS"