Files
LithosAnanke/scripts/test_capsule_ram_blocks.sh
T
Claude 6f9900f805 Capsule blocks step 1: the RAM block count is a build knob, BLK_RAM_USER_BLOCKS
Captain Bob ruled that the offset is the RAM block count, not a literal
2048.
- v3/include/blk_layout.h defines it, 2048 by default. block_subsystem.h
  derives BLK_RAM_BLOCKS (2080) and BLK_DISK_START from it.
- Kconfig.kernel has the symbol. kernel/Makefile passes it to the
  kernel's C code and builds mkcapsule and mkartemis with it.
- mkcapsule's two literal 2048s are now the knob.

The default value is unchanged, so the layout and the media are as before.

Test first: scripts/test_capsule_ram_blocks.sh, 8 checks.
- The before-run failed 4: the knob did not exist and mkcapsule ignored
  it. Its three Makefile checks also hit a SIGPIPE flaw in the test,
  fixed before the after-run.
- After: all 8 pass.

The amd64 build and mkartemis build clean. All 40 capsules lint. The
mesh boot passes 109 checks with POST 990/990. test_host_blocks,
test_host_quit, test_host_unit and test-32 pass.

Logs are in logs/20261118-ram-blocks-knob.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-18 17:35:15 +00:00

60 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-License-Identifier: LicenseRef-Starship-1.0
# Copyright (c) 2023-2026 Robert A. James
# test_capsule_ram_blocks.sh -- the tests of the RAM block count as a build knob
# (docs/v4.0.0/plans/2026-11-18-capsule-blocks.md, ruling 3 and step 1).
#
# What is checked:
# - the knob, BLK_RAM_USER_BLOCKS, is the VM's user RAM block count (2048 by default), and
# block_subsystem.h derives BLK_RAM_BLOCKS from it (2080 = 2048 + 32 reserved, as before);
# - mkcapsule's floor is the knob, not a literal 2048: built with the knob at 4096 it refuses a page
# at 3000 and takes one at 4096; built with the default it refuses 2047 and takes 2048;
# - kernel/Makefile gives the knob to the kernel's C code, to mkcapsule and to mkartemis.
#
# 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; }
SRC="$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"
INC="-I$ROOT/v3/include -I$ROOT/kernel/include -I$ROOT/tools"
build() { # build <out> [knob]
cc -std=c99 -O2 $INC ${2:+-DBLK_RAM_USER_BLOCKS=$2} -o "$1" $SRC 2> "$T/cc-$(basename "$1").log"
}
capsule() { # capsule <dir> <block>: a one-page capsule
mkdir -p "$1"; printf 'Block %s\n( one page )\n' "$2" > "$1/one.4th"
}
# the knob, as C sees it
cat > "$T/layout.c" <<'EOF'
#include "block_subsystem.h"
#include <stdio.h>
int main(void) { printf("%u %u %u\n", (unsigned)BLK_RAM_USER_BLOCKS, (unsigned)BLK_RAM_BLOCKS, (unsigned)BLK_DISK_START); return 0; }
EOF
cc -std=c99 $INC -o "$T/layout" "$T/layout.c" 2> "$T/cc-layout.log"
check "the knob's default is 2048, and BLK_RAM_BLOCKS and BLK_DISK_START are 2080 as before" \
'[ "$("$T/layout" 2>/dev/null)" = "2048 2080 2080" ]'
# mkcapsule's floor is the knob
build "$T/mk-default"
build "$T/mk-4096" 4096
capsule "$T/c2047" 2047; capsule "$T/c2048" 2048; capsule "$T/c3000" 3000; capsule "$T/c4096" 4096
check "default build: a page at 2047 is refused" '! "$T/mk-default" --lint "$T/c2047" > /dev/null 2>&1'
check "default build: a page at 2048 is taken" '"$T/mk-default" --lint "$T/c2048" > /dev/null 2>&1'
check "knob 4096: a page at 3000 is refused" '! "$T/mk-4096" --lint "$T/c3000" > /dev/null 2>&1'
check "knob 4096: a page at 4096 is taken" '"$T/mk-4096" --lint "$T/c4096" > /dev/null 2>&1'
# kernel/Makefile hands the knob on (a here-string, not a pipe: grep -q would end a printf with SIGPIPE under pipefail)
DB=$(cd "$ROOT" && make -s -pn -f kernel/Makefile ARCH=amd64 BLK_RAM_USER_BLOCKS=4096 2>/dev/null)
check "kernel/Makefile: the kernel's C flags carry it" 'grep -q -- "-DBLK_RAM_USER_BLOCKS=4096" <<< "$DB"'
check "kernel/Makefile: mkcapsule is built with it" 'grep -q -- "^MKCAPSULE_DEFS *:\?= *-DBLK_RAM_USER_BLOCKS=4096" <<< "$DB"'
check "kernel/Makefile: mkartemis is built with it" 'grep -q -- "^MKARTEMIS_DEFS *:\?= *-DBLK_RAM_USER_BLOCKS=4096" <<< "$DB"'
if [ $ok = 1 ]; then echo "RESULT: PASS"; else echo "RESULT: FAIL"; fi
[ $ok = 1 ]