#!/bin/sh # Which lines of the Rust the tests reach (#390), inside the limits builds are held to. # # sh scripts/coverage.sh all three crates, then the report # sh scripts/coverage.sh ipx-feed one crate's tests, then the report of what has run # # A coverage build instruments every crate, dependencies included, in a target of its own: a whole # rebuild, the kind that took Tower down on 2026-11-04. So it runs in a container under the same # cap as scripts/build-image.sh's builder (6 GB, six threads), past which the kernel kills it and # production is left alone; and, as CLAUDE.md asks of tests, one crate at a time. If the cap kills # it, say so and leave the cap be. # # The report: target/coverage/summary.txt (a line a file), target/coverage/lcov.info, and # target/coverage/html/index.html. set -eu MEM=6g CPUS=0-5 NEED_KB=$((9 * 1024 * 1024)) MAX_LOAD=12 IMAGE=192.168.1.130:5000/ipx-coverage:latest # The Docker daemon is Tower's, so its paths are Tower's: this tree is /mnt/user/vscode/ipx there, # and target/ is a link to target-real on /mnt/fast (builds through /mnt/user's FUSE took the load # to 248, CLAUDE.md). SRC=/mnt/user/vscode/ipx TARGET=/mnt/fast/vscode/ipx/target-real REGISTRY=$TARGET/coverage-registry cd "$(dirname "$0")/.." crates=${1:-ipx-feed ipx-directory ipx} room() { avail=$(awk '/^MemAvailable:/ {print $2}' /proc/meminfo) load=$(cut -d' ' -f1 /proc/loadavg) echo "MemAvailable $((avail / 1024)) MB, load $load" if [ "$avail" -lt "$NEED_KB" ]; then echo "refusing: under $((NEED_KB / 1024 / 1024)) GB available. Wait, or find what is using it." >&2 exit 1 fi if awk -v l="$load" -v m="$MAX_LOAD" 'BEGIN { exit !(l > m) }'; then echo "refusing: load over $MAX_LOAD. Wait for it to come down." >&2 exit 1 fi } run() { # The source read only: nothing in the tree is the coverage run's to change. The registry is # kept between runs, so the crates are downloaded once. docker run --rm --memory "$MEM" --memory-swap "$MEM" --cpuset-cpus "$CPUS" \ -v "$SRC:/work:ro" -v "$TARGET:/target" -v "$REGISTRY:/usr/local/cargo/registry" \ -e CARGO_TARGET_DIR=/target/llvm-cov-target -e CARGO_LLVM_COV_TARGET_DIR=/target/llvm-cov-target \ "$IMAGE" "$@" || { code=$? [ "$code" -eq 137 ] && echo "killed at the ${MEM} memory cap: tell the user, do not raise it" >&2 exit "$code" } } docker pull -q "$IMAGE" >/dev/null mkdir -p "$REGISTRY" # A whole run starts from nothing; one crate adds to what has run. [ $# -eq 0 ] && run cargo llvm-cov clean --workspace for c in $crates; do room echo "== $c" run cargo llvm-cov --no-report --locked -p "$c" done room mkdir -p "$TARGET/coverage" run sh -c 'cargo llvm-cov report --lcov --output-path /target/coverage/lcov.info \ && cargo llvm-cov report --html --output-dir /target/coverage \ && cargo llvm-cov report --summary-only > /target/coverage/summary.txt' # The paths inside the container are /work/...; the tree's own, from here. sed -i 's#/work/##' "$TARGET/coverage/summary.txt" "$TARGET/coverage/lcov.info" tail -1 "$TARGET/coverage/summary.txt"