#!/usr/bin/env bash # # jetson-test.sh — run the full `cargo test --workspace` on the # production-target Jetson via Docker (Dockerfile.test). # # Why this exists: the autopilot workspace depends on `opencv`, # `ffmpeg-next`, `tonic`/`prost`, and `libclang` at build time. The # macOS dev box does not always have native OpenCV / FFmpeg headers # installed, and the production target is a Jetson Orin Nano Super # running JetPack 6 (Ubuntu 22.04 aarch64). This script bridges the # two by rsync-ing the source to the Jetson and running tests inside # a container that mirrors the production environment exactly. # # Prerequisites: # - `ssh ` works passwordlessly (key-based auth). # - The remote user is in the `docker` group (no sudo for `docker`). # - `rsync` is available locally. # # Usage: # scripts/jetson-test.sh # full suite, default host # SSH_HOST=other-jetson scripts/jetson-test.sh # scripts/jetson-test.sh -p movement_detector -p semantic_analyzer # # Any args passed after the script name are forwarded to `cargo test` # inside the container (the default is the workspace suite). # # Exit code: forwarded from `cargo test` inside the container. set -euo pipefail SSH_HOST="${SSH_HOST:-jetson-e2e}" REMOTE_DIR="${REMOTE_DIR:-/home/jetson/autopilot}" IMAGE_TAG="${IMAGE_TAG:-autopilot-test}" DOCKERFILE="${DOCKERFILE:-Dockerfile.test}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" cd "${REPO_ROOT}" log() { printf '\n\033[1;34m[jetson-test]\033[0m %s\n' "$*" } log "Sync source to ${SSH_HOST}:${REMOTE_DIR} (excluding target/, .git/)" ssh "${SSH_HOST}" "mkdir -p '${REMOTE_DIR}'" rsync -az --delete \ --exclude='target/' \ --exclude='.git/' \ --exclude='.DS_Store' \ --exclude='*.swp' \ --exclude='node_modules/' \ ./ "${SSH_HOST}:${REMOTE_DIR}/" log "Build test image ${IMAGE_TAG} on ${SSH_HOST} (may take 10-20 min on first run)" ssh "${SSH_HOST}" "cd '${REMOTE_DIR}' && docker build --pull -t '${IMAGE_TAG}' -f '${DOCKERFILE}' ." if [[ $# -gt 0 ]]; then log "Running: cargo test $*" ssh "${SSH_HOST}" \ "cd '${REMOTE_DIR}' && docker run --rm \ -v '${REMOTE_DIR}:/workspace' \ -w /workspace \ '${IMAGE_TAG}' \ cargo test $*" else log "Running default: cargo test --workspace --no-fail-fast --color always" ssh "${SSH_HOST}" \ "cd '${REMOTE_DIR}' && docker run --rm \ -v '${REMOTE_DIR}:/workspace' \ -w /workspace \ '${IMAGE_TAG}'" fi