#!/usr/bin/env bash # SPDX-License-Identifier: LicenseRef-Starship-1.0 # Copyright (c) 2023-2026 Robert A. James # test_mkcapsule_overwrite.sh -- the tests of capsule blocks step 2 # (docs/v4.0.0/plans/2026-11-18-capsule-blocks.md). Captain Bob: "Overwrite. That's it. # Deterministic and final." -- within a capsule and across capsules, "consistent with VOCABULARY # FORGET & FENCE philosophy, not implementation"; and of what only prevents collisions: "All of it # goes". # # What is checked, mkcapsule run from the repository root (where it reads tools/): # - two capsules sharing a block number build; # - one capsule repeating a block number builds; # - a page in a range capsule-reserved.txt held builds, and that file is gone; # - --resolve is no longer a mode; # - the map says "Blocks used", and calls no number a conflict. # # No QEMU. Prints PASS:/FAIL: per check and RESULT:; exits 0 only if every check passes. set -uo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" T=$(mktemp -d) trap 'rm -rf "$T"' EXIT ok=1 check() { if eval "$2"; then echo "PASS: $1"; else echo "FAIL: $1"; ok=0; fi; } MK="$T/mkcapsule" cc -std=c99 -O2 -I"$ROOT/v3/include" -I"$ROOT/kernel/include" -I"$ROOT/tools" -o "$MK" \ "$ROOT/tools/mkcapsule.c" "$ROOT/tools/pkcs8_ed25519.c" "$ROOT/kernel/src/crypto/ed25519.c" \ "$ROOT/kernel/src/crypto/fe25519.c" "$ROOT/kernel/src/crypto/scalar25519.c" \ "$ROOT/kernel/src/crypto/sha512.c" "$ROOT/kernel/src/crypto/x509_ed25519.c" 2> "$T/cc.log" build() { (cd "$ROOT" && "$MK" "$1" "$T/out.c" > "$T/build.log" 2>&1); } # build mkdir -p "$T/shared" printf 'Block 3000\n( first capsule )\n' > "$T/shared/a.4th" printf 'Block 3000\n( second capsule, the same number )\n' > "$T/shared/b.4th" check "two capsules sharing a block number build" 'build "$T/shared"' mkdir -p "$T/repeat" printf 'Block 3000\n( once )\nBlock 3000\n( again )\n' > "$T/repeat/r.4th" check "one capsule repeating a block number builds" 'build "$T/repeat"' mkdir -p "$T/reserved" printf 'Block 4300\n( where process.4th was )\n' > "$T/reserved/p.4th" check "a page in a once-reserved range builds" 'build "$T/reserved"' check " and tools/capsule-reserved.txt is gone" '[ ! -e "$ROOT/tools/capsule-reserved.txt" ]' (cd "$ROOT" && "$MK" --resolve "$T/shared" < /dev/null > "$T/resolve.log" 2>&1) check "--resolve is no longer a mode: it is answered with the usage" 'grep -q "^Usage" "$T/resolve.log" && ! grep -q -i "conflict\|renumber" "$T/resolve.log"' check " and the tool has no such mode" '! grep -q -- "--resolve" "$ROOT/tools/mkcapsule.c"' (cd "$ROOT" && "$MK" --manifest "$T/shared" "$T/map.md" > /dev/null 2>&1) check "the map says Blocks used" 'grep -q "Blocks used" "$T/map.md" 2>/dev/null' check " and calls no number a conflict" '! grep -q -i "conflict\|claimed" "$T/map.md" 2>/dev/null' if [ $ok = 1 ]; then echo "RESULT: PASS"; else echo "RESULT: FAIL"; fi [ $ok = 1 ]