Files
leleka/scripts/linux-tests/run.sh
T
Pavlo Ratushnyi 40896ba217 STRA-338 S24: peel the pure host-side models out of cuda-driver into leleka-cuda-model
New L1 crate crates/cuda-model (leleka-cuda-model, forbid(unsafe_code), depends on leleka-context only) holds:
Error/Result with Display, DenseFormat, RoutedFormat, ProjectionKind (+ layout/alignment/required_modes), ProjectionSpec,
the Bf16/Q5K/Q6K projection shapes, bringup_trace_enabled, and the modules serving_context, host_profile, command_profile,
original_mtp_loader, original_prefill_schedule, qsa_prompt_attention_select, original_expert_slots, native_flash_attn,
s_gemv_legacy, device_arena, mmq_original_prefill_misc (moved with git mv; code unchanged apart from pub visibility and
#[inline] on the tiny cached-switch readers, host_profile::add split into an inlined gate and a cold body).

leleka-cuda-driver re-exports every item at its old path, so no use path in the driver, engine-qwen35-cuda or
native-parity-bench changes. Tests moved with their modules; they read the .cu sources and oracle fixtures of the driver
through driver_source!; the one loader test that needs the driver's session geometry stays in the driver.

Housekeeping: workspace members/default-members, Cargo.lock, architecture.json (L1), hexagonal.md, ci-coverage.json,
check-local.sh, port.yml, linux-tests/run.sh, AGENTS.md. architecture-baseline.json: the source ratchets of the moved code
change crate key (dyn-trait driver 56 to 49 + model 3, env-read 72 to 67 + 5, process-global 110 to 99 + 11), regenerated
with --allow-increase for the new keys only; per-pattern totals do not rise. limits-baseline.json is unchanged: no moved
function is over a limit.
2026-11-07 17:40:24 +01:00

106 lines
5.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Run the Linux x86_64-gated CPU tests of the Rust port inside Docker.
#
# scripts/linux-tests/run.sh # all three crates, one shard each
# scripts/linux-tests/run.sh -p leleka-engine-qwen35-cuda # selected crate(s)
# scripts/linux-tests/run.sh -- <libtest args> # e.g. -- conversation::
# LELEKA_TEST_FILTER=conversation:: scripts/linux-tests/run.sh -p leleka-engine-qwen35-cuda
# scripts/linux-tests/run.sh --mocks # also run the CPU fake-libcuda #[ignore]d mock gates
# LELEKA_TEST_CLEAN=1 ... # wipe the cached target volume first
#
# Requirements: Docker; on Apple Silicon, x86_64 emulation (Docker Desktop
# Rosetta, or qemu binfmt). No GPU is needed or used: #[ignore]d tests stay
# ignored and no libcuda.so.1 exists in the image, so every non-ignored test must
# pass without a CUDA driver.
#
# Persistent state is kept in two named volumes (cargo registry/git cache and the
# cargo target dir). Remove with: docker volume rm leleka-linux-tests-cargo leleka-linux-tests-target
set -uo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo="$(cd "$here/../.." && pwd)"
rust_version="$(sed -n 's/^channel *= *"\([^"]*\)".*/\1/p' "$repo/rust-toolchain.toml")"
[[ -n "$rust_version" ]] || { echo "cannot read channel from rust-toolchain.toml" >&2; exit 2; }
image="leleka-linux-tests:rust-${rust_version}"
cargo_vol="${LELEKA_TEST_CARGO_VOLUME:-leleka-linux-tests-cargo}"
target_vol="${LELEKA_TEST_TARGET_VOLUME:-leleka-linux-tests-target}"
packages=()
extra=()
mocks=0
while (( $# )); do
case "$1" in
--mocks) mocks=1; shift ;;
-p|--package) packages+=("$2"); shift 2 ;;
--) shift; extra=("$@"); break ;;
*) echo "unknown argument: $1 (use -p <crate> and/or -- <libtest args>)" >&2; exit 2 ;;
esac
done
(( ${#packages[@]} )) || packages=(leleka-cuda-model leleka-cuda-driver leleka-engine-qwen35-cuda leleka-native-cpu-expert)
if [[ -n "${LELEKA_TEST_FILTER:-}" ]]; then extra=("$LELEKA_TEST_FILTER" ${extra[@]+"${extra[@]}"}); fi
command -v docker >/dev/null || { echo "docker not found" >&2; exit 2; }
if ! docker image inspect "$image" >/dev/null 2>&1 || [[ -n "${LELEKA_TEST_REBUILD:-}" ]]; then
echo "== building $image (linux/amd64)"
docker build --platform linux/amd64 --build-arg "RUST_VERSION=$rust_version" \
-t "$image" "$here" || exit 2
fi
if [[ -n "${LELEKA_TEST_CLEAN:-}" ]]; then docker volume rm -f "$target_vol" >/dev/null; fi
docker volume create "$cargo_vol" >/dev/null
docker volume create "$target_vol" >/dev/null
# Several tests write scratch fixtures under <repo>/target (reached through
# CARGO_MANIFEST_DIR/../../target). The repo is mounted read-only, so that path is
# a throw-away tmpfs inside the container; the mount point must exist on the host
# (target/ is gitignored).
mkdir -p "$repo/target"
mount_mode="ro"; [[ -n "${LELEKA_TEST_RW:-}" ]] && mount_mode="rw"
logdir="${LELEKA_TEST_LOGDIR:-${TMPDIR:-/tmp}/leleka-linux-tests}"
mkdir -p "$logdir"; rm -f "$logdir"/*.failed
docker_run() {
docker run --rm --platform linux/amd64 \
-v "$repo:/src:$mount_mode" -v "$cargo_vol:/cargo-cache" -v "$target_vol:/target" \
--tmpfs /tmp:exec,size=2g --tmpfs /src/target:exec,size=2g \
-e RUST_TEST_THREADS="${RUST_TEST_THREADS:-4}" \
-e CARGO_BUILD_JOBS="${CARGO_BUILD_JOBS:-6}" \
"$image" "$@"
}
if (( mocks )); then
# CPU-only fake-libcuda ELF protocol gates (the repo's #[ignore]d *_mock tests).
docker_run bash /src/scripts/linux-tests/mocks-inside.sh 2>&1 | tee "$logdir/mocks.log" | awk -v v="${LELEKA_TEST_VERBOSE:-}" 'v { print; next } /^warning/ { skip=1 } /^$/ { skip=0 } !skip { print }'
status=${PIPESTATUS[0]}
grep -E '^=== mock gate|^test result|^!!! FAILED' "$logdir/mocks.log" | cut -c1-160
(( status == 0 )) && echo "RESULT: PASS (mock gates)" || echo "RESULT: FAIL (mock gates)"
exit "$status"
fi
echo "== toolchain: $(docker_run rustc --version) ; arch: $(docker_run uname -m)"
echo "== (no GPU: #[ignore]d tests are skipped; libcuda.so.1 absent by design)"
summary=()
rc=0
for pkg in "${packages[@]}"; do
log="$logdir/$pkg.log"
start=$SECONDS
# --no-fail-fast: keep running every test binary even when one fails.
features=()
case "$pkg" in leleka-cuda-driver|leleka-engine-qwen35-cuda|leleka-native-cpu-expert) features=(--features leleka-cuda-driver/cuda-driver) ;; esac
docker_run cargo test --locked --no-fail-fast ${features[@]+"${features[@]}"} -p "$pkg" -- ${extra[@]+"${extra[@]}"} 2>&1 | tee "$log" | awk -v v="${LELEKA_TEST_VERBOSE:-}" 'v { print; next } /^warning/ { skip=1 } /^$/ { skip=0 } !skip { print }'
status=${PIPESTATUS[0]}
elapsed=$((SECONDS - start))
# Sum libtest "test result:" lines across all binaries of this package.
read -r passed failed ignored < <(awk '/^test result:/ { p+=$4; f+=$6; i+=$8 } END { print p+0, f+0, i+0 }' "$log")
built=ok; grep -qE '^error(\[E[0-9]+\])?: (could not compile|aborting)|^error\[E' "$log" && built=ERRORS
summary+=("$(printf '%-26s passed=%-5s failed=%-4s ignored=%-5s time=%4ss status=%s build=%s' "$pkg" "$passed" "$failed" "$ignored" "$elapsed" "$status" "$built")")
(( status == 0 )) || rc=1
grep -E '^test .* FAILED$' "$log" | sed "s/^/ [$pkg] /" > "$logdir/$pkg.failed" || true
done
echo
echo "================ linux-tests summary (logs: $logdir) ================"
printf '%s\n' "${summary[@]}"
if cat "$logdir"/*.failed 2>/dev/null | grep -q .; then echo "-- failed tests:"; cat "$logdir"/*.failed; fi
(( rc == 0 )) && echo "RESULT: PASS" || echo "RESULT: FAIL"
exit $rc