#!/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 -- # 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 # LELEKA_TEST_COPY_SOURCE=1 ... # copy the repo into the container instead of bind-mounting it (CI) # # 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 and/or -- )" >&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 /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). # # LELEKA_TEST_COPY_SOURCE=1 (the CI job): when this script itself runs inside a container (a Gitea or GitHub # runner job) and talks to the host's Docker daemon, "$repo" is a path of the job container and does not exist on # the daemon's host. A bind mount then yields an empty read-only /src, and Docker cannot create the /src/target # mount point in it ("read-only file system"). The source is therefore streamed into a fresh container with # `docker cp` (tar, without target/.git/models/garbage) and runs on its writable layer; no bind mount or /src/target # tmpfs is involved. Persistent caches stay in the two named volumes, which the daemon owns. copy_source="${LELEKA_TEST_COPY_SOURCE:-}" if [[ -z "$copy_source" ]]; then mkdir -p "$repo/target" fi 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() { if [[ -n "$copy_source" ]]; then local cid status cid="$(docker create --platform linux/amd64 -v "$cargo_vol:/cargo-cache" -v "$target_vol:/target" --tmpfs /tmp:exec,size=2g -e RUST_TEST_THREADS="${RUST_TEST_THREADS:-4}" -e CARGO_BUILD_JOBS="${CARGO_BUILD_JOBS:-6}" "$image" "$@")" || return 125 if ! tar -C "$repo" --exclude=./target --exclude=./.git --exclude=./models --exclude=./garbage --exclude=./dist -cf - . | docker cp - "$cid:/src"; then docker rm -f "$cid" >/dev/null 2>&1 return 125 fi docker start -a "$cid" status=$? docker rm -f "$cid" >/dev/null 2>&1 return "$status" fi 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