interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / store / tests / rust_crosscheck.sh

104 lines · 5052 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# C -> Rust cross-check: the Rust aienos-store-tool works on images written
18# by the C Store engine, and the C engine classifies images the Rust tool has
19# changed the same way the Rust engine does.
20#
21# rust_crosscheck.sh XCHECK_BIN OUT_DIR
22#
23# The Rust tool is found at $RUST_STORE_TOOL, else <repo>/target/release/
24# aienos-store-tool. If it is missing the verdict is NOT_RUN (never PASS).
25# Rust -> C: no Rust-written image is used here; that direction is covered by
26# the golden vectors (byte-exact) and by the Rust-rechecksummed bytes that
27# "inject" writes into C images.
28set -u
29xc=$1
30out=$2
31here=$(cd "$(dirname "$0")/../../.." && pwd)
32tool=${RUST_STORE_TOOL:-$here/target/release/aienos-store-tool}
33if [ ! -x "$tool" ]; then
34 echo "rust cross-check: Rust store tool not found at $tool"
35 echo "STORE_RUST_CROSSCHECK: NOT_RUN"
36 exit 2
37fi
38echo "rust cross-check: tool $tool"
39fail=0
40n=0
41units=64
42expect() { # name got want
43 n=$((n + 1))
44 if [ "$2" = "$3" ]; then echo " ok $1: $2"; else echo " FAIL $1: got [$2] want [$3]"; fail=1; fi
45}
46# Rust's own opinion of an image: corrupt-kind with a kind no image holds
47# mounts (Rust Store::open) and then stops without writing.
48rust_mount() { # img off
49 r=$("$tool" corrupt-kind "$1" "$2" $units 999 2>&1)
50 case "$r" in
51 *"no catalog object of kind 999"*) echo MOUNT ;;
52 *"store does not mount: "*) echo "REFUSE MountError::${r##*store does not mount: }" ;;
53 *) echo "UNEXPECTED $r" ;;
54 esac
55}
56c_mount() { "$xc" classify "$1" "$bs" "$base" $units | sed 's/^MOUNT .*/MOUNT/'; }
57
58for bs in 512 4096; do
59 base=$((2 * 4096 / bs)) # store starts 2 units into the device
60 off=$((base * bs))
61 d=$out/xcheck_$bs
62 rm -rf "$d"; mkdir -p "$d"
63 echo "geometry $bs-byte blocks, store at byte $off:"
64 "$xc" mkpair "$d/old.img" "$d/new.img" $bs $base $units >/dev/null || { echo " FAIL C image build"; fail=1; continue; }
65 expect "C reads its own gen 3" "$("$xc" classify "$d/new.img" $bs $base $units)" "MOUNT state=Valid peer=Valid gen=3 objects_ok=3/3"
66 expect "Rust mounts the C image" "$(rust_mount "$d/new.img" $off)" "MOUNT"
67 for sector in 512 4096; do
68 r=$("$tool" tear-closure "$d/old.img" "$d/new.img" $off $sector 2>&1)
69 echo " $r"
70 case "$r" in STORE_ROOT_TEAR_CLOSURE:\ PASS*) expect "tear-closure sector $sector" PASS PASS ;;
71 *) expect "tear-closure sector $sector" FAIL PASS ;; esac
72 done
73 # corrupt-kind on an object both roots hold: both refuse the same way
74 cp "$d/new.img" "$d/c7.img"
75 r=$("$tool" corrupt-kind "$d/c7.img" $off $units 7 2>&1); echo " $r"
76 expect "corrupt kind 7 (both roots): C" "$("$xc" classify "$d/c7.img" $bs $base $units)" "REFUSE MountError::CorruptRecoveryRequired"
77 expect "corrupt kind 7 (both roots): Rust" "$(rust_mount "$d/c7.img" $off)" "REFUSE MountError::CorruptRecoveryRequired"
78 # corrupt-kind on an object only the newest root holds: both mount the older root
79 cp "$d/new.img" "$d/c9.img"
80 r=$("$tool" corrupt-kind "$d/c9.img" $off $units 9 2>&1); echo " $r"
81 expect "corrupt kind 9 (newest only): C" "$("$xc" classify "$d/c9.img" $bs $base $units)" "MOUNT state=DegradedRecovery peer=GraphBadNewer gen=2 objects_ok=2/2"
82 expect "corrupt kind 9 (newest only): Rust" "$(rust_mount "$d/c9.img" $off)" "MOUNT"
83 # inject into the inactive slot (slot 1 holds gen 2; slot 0 holds gen 3)
84 cp "$d/new.img" "$d/gen4.img"
85 "$xc" advance "$d/gen4.img" $bs $base $units >/dev/null
86 for case in bad_crc wrong_magic nonzero_reserved wrong_slot_id region_mismatch unsupported_version seeded_garbage new_root; do
87 img=$d/inj_$case.img
88 cp "$d/new.img" "$img"
89 src=$d/new.img
90 [ $case = new_root ] && src=$d/gen4.img
91 r=$("$tool" inject "$img" $off inactive $case "$src" 2>&1); echo " $r"
92 case $case in
93 unsupported_version) want="REFUSE MountError::UnsupportedVersion" ;;
94 new_root) want="MOUNT state=DegradedRecovery peer=GraphBadNewer gen=3 objects_ok=3/3" ;;
95 *) want="MOUNT state=DegradedRecovery peer=Malformed gen=3 objects_ok=3/3" ;;
96 esac
97 got=$("$xc" classify "$img" $bs $base $units)
98 expect "inject $case: C" "$got" "$want"
99 rw=$(echo "$want" | sed 's/^MOUNT .*/MOUNT/')
100 expect "inject $case: Rust agrees" "$(rust_mount "$img" $off)" "$rw"
101 done
102done
103echo "rust cross-check: $n checks"
104if [ $fail -eq 0 ]; then echo "STORE_RUST_CROSSCHECK: PASS"; else echo "STORE_RUST_CROSSCHECK: FAIL"; exit 1; fi