| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #!/usr/bin/env bash
- # Official host verification entry. Usage: run_host_verify.sh [fast|standard|full]
- # Authoritative on Linux. Records logs into $HTH_RUN_DIR.
- set -uo pipefail
- MODE="${1:-standard}"
- if [[ "${MODE}" == "fast" || "${MODE}" == "standard" || "${MODE}" == "full" ]]; then
- if [[ $# -gt 0 ]]; then
- shift
- fi
- else
- MODE="standard"
- fi
- export PATH="/usr/bin:/bin:/usr/local/bin:/opt/python-3.13/bin:/opt/python-3.12/bin:/opt/python-3.11/bin:/data/prod2u/opt/go1.25.13/bin:/root/go/bin:/data/prod2u/oss-cad-suite/latest/bin:${PATH}"
- if [[ -n "${GOROOT:-}" && ! -d "${GOROOT}" ]]; then
- unset GOROOT
- fi
- if [[ -z "${GOROOT:-}" && -d /data/prod2u/opt/go1.25.13 ]]; then
- export GOROOT=/data/prod2u/opt/go1.25.13
- fi
- export GOTOOLCHAIN="${GOTOOLCHAIN:-local}"
- export GOFLAGS="${GOFLAGS:-}"
- if [[ -z "${PYTHON:-}" ]]; then
- if [[ -x /data/prod2u/venvs/hth-verify/bin/python ]]; then
- export PYTHON=/data/prod2u/venvs/hth-verify/bin/python
- elif [[ -x /usr/bin/python3 ]]; then
- export PYTHON=/usr/bin/python3
- else
- export PYTHON=python3
- fi
- fi
- SRC="${HTH_SRC:-$(cd "$(dirname "$0")/.." && pwd)}"
- if [[ -z "${HTH_SKIP_LINUX_WORKTREE:-}" && -d /data/prod2u && -n "$(git -C "${SRC}" rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
- SOURCE_HEAD="$(git -C "${SRC}" rev-parse HEAD)"
- SHORT_HINT="$(git -C "${SRC}" rev-parse --short HEAD 2>/dev/null || echo host)"
- WT="${HTH_LINUX_WORKTREE:-/data/prod2u/worktrees/hth-verify-${SHORT_HINT}}"
- if [[ ! -e "${WT}/.git" ]]; then
- mkdir -p "$(dirname "${WT}")"
- git clone --quiet --no-hardlinks --no-checkout "${SRC}" "${WT}" || true
- git -C "${WT}" checkout --quiet --detach "${SOURCE_HEAD}" || true
- fi
- if git -C "${WT}" rev-parse --is-inside-work-tree >/dev/null 2>&1 \
- && [[ "$(git -C "${WT}" rev-parse HEAD)" == "${SOURCE_HEAD}" ]]; then
- SRC="${WT}"
- fi
- fi
- if [[ -z "${HTH_CPLD_ROOT:-}" && -d /workspace/cpld-temperature-control ]]; then
- export HTH_CPLD_ROOT=/workspace/cpld-temperature-control
- fi
- cd "${SRC}"
- export HTH_GIT_ROOT="${SRC}"
- export HTH_GIT_SCOPE=all
- if [[ -z "${HTH_GIT_COMMIT:-}" ]]; then
- HTH_GIT_COMMIT="$(git -C "${SRC}" rev-parse HEAD 2>/dev/null || echo unknown)"
- fi
- if [[ -z "${HTH_GIT_TREE:-}" ]]; then
- HTH_GIT_TREE="$(git -C "${SRC}" rev-parse 'HEAD^{tree}' 2>/dev/null || echo unknown)"
- fi
- export HTH_GIT_COMMIT HTH_GIT_TREE
- COMMIT="${HTH_GIT_COMMIT}"
- TREE="${HTH_GIT_TREE}"
- if [[ -z "${HTH_GIT_DIRTY:-}" ]]; then
- if [[ -n "$(git -C "${SRC}" status --porcelain 2>/dev/null)" ]]; then
- HTH_GIT_DIRTY=dirty
- else
- HTH_GIT_DIRTY=clean
- fi
- fi
- export HTH_GIT_DIRTY
- STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
- export HTH_RUN_ID="${HTH_RUN_ID:-hth-host-${MODE}-${STAMP}}"
- if [[ -z "${SOURCE_DATE_EPOCH:-}" ]]; then
- SOURCE_DATE_EPOCH="$(git -C "${SRC}" log -1 --format=%ct 2>/dev/null || date -u +%s)"
- fi
- export SOURCE_DATE_EPOCH
- RUN="${HTH_RUN_DIR:-/data/prod2u/hth-runs/${HTH_RUN_ID}}"
- if [[ ! -d /data/prod2u/hth-runs ]]; then
- RUN="${HTH_RUN_DIR:-${SRC}/.hth-runs/${HTH_RUN_ID}}"
- fi
- export HTH_RUN_DIR="${RUN}"
- mkdir -p "${RUN}/reviews"
- PKG_DIR="${HTH_PACKAGE_DIR:-/tmp}"
- mkdir -p "${PKG_DIR}"
- export HTH_PACKAGE_DIR="${PKG_DIR}"
- REC="${SRC}/tools/record_cmd.sh"
- fail=0
- rec() {
- local name="$1"
- shift
- bash "${REC}" "${name}" "$@"
- local rc=$?
- if [[ "${rc}" -ne 0 ]]; then
- fail=1
- fi
- return 0
- }
- rec_optional() {
- local name="$1"
- shift
- bash "${REC}" "${name}" "$@" || true
- }
- record_not_run() {
- local name="$1"
- local reason="$2"
- "${PYTHON}" - "$name" "$reason" <<'PY'
- import hashlib, os, sys
- from datetime import datetime, timezone
- from pathlib import Path
- name, reason = sys.argv[1], sys.argv[2]
- run = Path(os.environ["HTH_RUN_DIR"])
- now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
- log = run / f"{name}.log"
- log.write_text(reason + "\n", encoding="utf-8")
- sha = hashlib.sha256((reason + "\n").encode()).hexdigest()
- (run / f"{name}.meta").write_text(
- "\n".join([
- f"run_id={os.environ.get('HTH_RUN_ID','')}",
- f"commit={os.environ.get('HTH_GIT_COMMIT','')}",
- f"tree={os.environ.get('HTH_GIT_TREE','')}",
- f"dirty={os.environ.get('HTH_GIT_DIRTY','unknown')}",
- f"start_utc={now}",
- f"end_utc={now}",
- f"command={reason}",
- "exit=2",
- "status=NOT RUN",
- f"reason={reason}",
- f"not_run_reason_sha256={hashlib.sha256(reason.encode()).hexdigest()}",
- f"log_sha256={sha}",
- f"recorded_utc={now}",
- ]) + "\n",
- encoding="utf-8",
- )
- print(f"{name} status=NOT RUN")
- PY
- }
- echo "HOST_VERIFY mode=${MODE} commit=${COMMIT} tree=${TREE} run=${HTH_RUN_ID} dir=${RUN}" | tee "${RUN}/gates-start.txt"
- cd "${SRC}"
- SOAK_PID=""
- if [[ "${MODE}" == "full" ]]; then
- rec soak-2h env HTH_SOAK_2H=1 go test ./internal/device -run '^TestIntegrationSoak2h$' -count=1 -timeout 150m &
- SOAK_PID=$!
- fi
- rec gofmt bash -c 'out=$(gofmt -l .); if [[ -n "$out" ]]; then echo "$out"; exit 1; fi'
- rec go-test go test ./... -count=1 -timeout 25m
- rec vet go vet ./...
- rec python-sdk make python-sdk
- rec algorithm-facade "${PYTHON}" -m pytest sdk/python/tests/test_facade.py sdk/python/tests/test_import.py sdk/python/tests/test_mock_client.py sdk/python/tests/test_doctor.py sdk/python/tests/test_zip_unix_modes.py -q
- if command -v buf >/dev/null 2>&1; then
- rec buf-lint buf lint
- else
- rec buf-lint bash -c 'echo "buf missing"; exit 2'
- fi
- if [[ "${MODE}" != "fast" ]]; then
- rec race env CGO_ENABLED=1 go test -race ./... -count=1 -timeout 40m
- if command -v staticcheck >/dev/null 2>&1; then
- rec staticcheck staticcheck ./...
- else
- rec_optional staticcheck bash -c 'echo "staticcheck missing"; exit 2'
- fi
- if command -v govulncheck >/dev/null 2>&1; then
- rec govulncheck govulncheck ./...
- else
- rec_optional govulncheck bash -c 'echo "govulncheck missing"; exit 2'
- fi
- if command -v buf >/dev/null 2>&1; then
- rec buf-breaking bash "${SRC}/tools/run_buf_breaking.sh"
- else
- rec buf-breaking bash -c 'echo "buf missing"; exit 2'
- fi
- rec python-matrix bash "${SRC}/tools/sdk_wheel_matrix.sh"
- rec algorithm-gates bash "${SRC}/tools/run_algorithm_gates.sh"
- rec pty go test ./tests -count=1 -timeout 25m -run 'PTY|Pty|Capture|Sigterm|UDS|NoTCP'
- rec soak-pr-5m env HTH_SOAK_SECONDS=300 go test ./tests -run '^TestPRSoakMock$' -count=1 -timeout 10m
- if [[ -f "${SRC}/tools/rtl_uart_cosim/run_hthd_pty_rtl.py" ]]; then
- rec rtl-sim-uart "${PYTHON}" "${SRC}/tools/rtl_uart_cosim/run_hthd_pty_rtl.py"
- else
- rec rtl-sim-uart bash -c 'echo "rtl harness missing"; exit 2'
- fi
- fi
- if [[ "${MODE}" == "full" ]]; then
- if [[ -f "${SRC}/tools/rtl_uart_cosim/run_hthd_pty_rtl.py" ]]; then
- rec_optional rtl-production-uart env HTH_PRODUCTION_UART=1 "${PYTHON}" "${SRC}/tools/rtl_uart_cosim/run_hthd_pty_rtl.py"
- else
- record_not_run rtl-production-uart "rtl harness missing"
- fi
- if [[ -x "${SRC}/tools/qemu_systemd_vm.sh" ]]; then
- rec systemd-qemu-vm bash "${SRC}/tools/qemu_systemd_vm.sh"
- else
- record_not_run systemd-qemu-vm "qemu script missing"
- fi
- rec fuzz-15m bash "${SRC}/tools/run_fuzz_15m.sh"
- fi
- if [[ "${MODE}" == "fast" ]]; then
- record_not_run race "fast mode skipped"
- record_not_run staticcheck "fast mode skipped"
- record_not_run govulncheck "fast mode skipped"
- record_not_run buf-breaking "fast mode skipped"
- record_not_run python-matrix "fast mode skipped"
- record_not_run algorithm-kit "fast mode skipped"
- record_not_run pty "fast mode skipped"
- record_not_run soak-pr-5m "fast mode skipped"
- record_not_run rtl-sim-uart "fast mode skipped"
- fi
- if [[ "${MODE}" != "full" ]]; then
- record_not_run rtl-production-uart "${MODE} mode skipped; production 217 clocks/bit is full-only"
- record_not_run systemd-qemu-vm "${MODE} mode skipped"
- record_not_run fuzz-15m "${MODE} mode skipped"
- record_not_run soak-2h "${MODE} mode skipped"
- fi
- record_not_run soak-24h "24h soak NOT RUN this run; blocks release_candidate_readiness only"
- record_not_run hardware-validation "Hardware validation NOT RUN; no COM/JTAG/real actuators"
- record_not_run real-actuator-validation "Real actuator validation NOT RUN"
- if [[ -n "${SOAK_PID}" ]]; then
- echo "waiting soak-2h pid=${SOAK_PID}"
- wait "${SOAK_PID}" || fail=1
- fi
- if [[ "${MODE}" != "fast" ]]; then
- "${PYTHON}" "${SRC}/tools/gen_run_manifest.py" "${RUN}" || fail=1
- "${PYTHON}" "${SRC}/tools/evaluate_gates.py" || fail=1
- cd "${SRC}/tools"
- rec package-review "${PYTHON}" package_hth_review.py
- ZIP="$(ls -1t "${PKG_DIR}"/hth-platform-safety-closure-*.zip "${PKG_DIR}"/hth-engineering-review-*.zip 2>/dev/null | head -n1 || true)"
- if [[ -n "${ZIP}" ]]; then
- STAGE="${RUN}/unzip-offline"
- rm -rf "${STAGE}"
- mkdir -p "${STAGE}"
- "${PYTHON}" -c "import sys; from pathlib import Path; sys.path.insert(0, r'''${SRC}/tools'''); from zip_unix_modes import extract_zip_with_unix_modes; extract_zip_with_unix_modes(Path(r'''${ZIP}'''), Path(r'''${STAGE}'''))"
- ROOTDIR="$(find "${STAGE}" -maxdepth 1 -type d \( -name 'hth-platform-r6' -o -name 'hth-platform' \) | head -n1)"
- if [[ -n "${ROOTDIR}" ]]; then
- rec package-offline "${PYTHON}" "${SRC}/tools/verify_review_package.py" "${ROOTDIR}" --mode offline
- else
- rec package-offline bash -c 'echo "unzipped package root missing"; exit 1'
- fi
- else
- rec package-review bash -c 'echo "review zip missing"; exit 1'
- fi
- "${PYTHON}" "${SRC}/tools/gen_run_manifest.py" "${RUN}" || fail=1
- "${PYTHON}" "${SRC}/tools/evaluate_gates.py" || fail=1
- fi
- echo "HOST_VERIFY_DONE mode=${MODE} fail=${fail} run=${HTH_RUN_ID}" | tee "${RUN}/GATES_DONE"
- exit "${fail}"
|