run_host_verify.sh 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #!/usr/bin/env bash
  2. # Official host verification entry. Usage: run_host_verify.sh [fast|standard|full]
  3. # Authoritative on Linux. Records logs into $HTH_RUN_DIR.
  4. set -uo pipefail
  5. MODE="${1:-standard}"
  6. if [[ "${MODE}" == "fast" || "${MODE}" == "standard" || "${MODE}" == "full" ]]; then
  7. if [[ $# -gt 0 ]]; then
  8. shift
  9. fi
  10. else
  11. MODE="standard"
  12. fi
  13. 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}"
  14. export GOROOT="${GOROOT:-/data/prod2u/opt/go1.25.13}"
  15. export GOTOOLCHAIN="${GOTOOLCHAIN:-local}"
  16. export GOFLAGS="${GOFLAGS:-}"
  17. if [[ -z "${PYTHON:-}" ]]; then
  18. if [[ -x /data/prod2u/venvs/hth-verify/bin/python ]]; then
  19. export PYTHON=/data/prod2u/venvs/hth-verify/bin/python
  20. elif [[ -x /usr/bin/python3 ]]; then
  21. export PYTHON=/usr/bin/python3
  22. else
  23. export PYTHON=python3
  24. fi
  25. fi
  26. SRC="${HTH_SRC:-$(cd "$(dirname "$0")/../.." && pwd)}"
  27. if [[ -z "${HTH_SKIP_LINUX_WORKTREE:-}" && -d /data/prod2u && -n "$(git -C "${SRC}" rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
  28. SHORT_HINT="$(git -C "${SRC}" rev-parse --short HEAD 2>/dev/null || echo host)"
  29. WT="${HTH_LINUX_WORKTREE:-/data/prod2u/worktrees/hth-host-${SHORT_HINT}}"
  30. if [[ ! -e "${WT}/.git" ]]; then
  31. mkdir -p "$(dirname "${WT}")"
  32. git -C "${SRC}" worktree add --detach "${WT}" HEAD || true
  33. fi
  34. if git -C "${WT}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
  35. SRC="${WT}"
  36. fi
  37. fi
  38. cd "${SRC}"
  39. export HTH_GIT_ROOT="${SRC}"
  40. export HTH_GIT_SCOPE=host
  41. if [[ -z "${HTH_GIT_COMMIT:-}" ]]; then
  42. HTH_GIT_COMMIT="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
  43. fi
  44. if [[ -z "${HTH_GIT_TREE:-}" ]]; then
  45. HTH_GIT_TREE="$(git rev-parse 'HEAD^{tree}' 2>/dev/null || echo unknown)"
  46. fi
  47. export HTH_GIT_COMMIT HTH_GIT_TREE
  48. COMMIT="${HTH_GIT_COMMIT}"
  49. TREE="${HTH_GIT_TREE}"
  50. export HTH_GIT_DIRTY="${HTH_GIT_DIRTY:-clean}"
  51. STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
  52. export HTH_RUN_ID="${HTH_RUN_ID:-hth-host-${MODE}-${STAMP}}"
  53. if [[ -z "${SOURCE_DATE_EPOCH:-}" ]]; then
  54. SOURCE_DATE_EPOCH="$(git log -1 --format=%ct 2>/dev/null || date -u +%s)"
  55. fi
  56. export SOURCE_DATE_EPOCH
  57. RUN="${HTH_RUN_DIR:-/data/prod2u/hth-runs/${HTH_RUN_ID}}"
  58. if [[ ! -d /data/prod2u/hth-runs ]]; then
  59. RUN="${HTH_RUN_DIR:-${SRC}/.hth-runs/${HTH_RUN_ID}}"
  60. fi
  61. export HTH_RUN_DIR="${RUN}"
  62. mkdir -p "${RUN}/reviews"
  63. PKG_DIR="${HTH_PACKAGE_DIR:-/tmp}"
  64. mkdir -p "${PKG_DIR}"
  65. export HTH_PACKAGE_DIR="${PKG_DIR}"
  66. REC="${SRC}/host/tools/record_cmd.sh"
  67. fail=0
  68. rec() {
  69. local name="$1"
  70. shift
  71. "${REC}" "${name}" "$@"
  72. local rc=$?
  73. if [[ "${rc}" -eq 1 ]]; then
  74. fail=1
  75. fi
  76. return 0
  77. }
  78. rec_optional() {
  79. local name="$1"
  80. shift
  81. "${REC}" "${name}" "$@" || true
  82. }
  83. record_not_run() {
  84. local name="$1"
  85. local reason="$2"
  86. "${PYTHON}" - "$name" "$reason" <<'PY'
  87. import hashlib, os, sys
  88. from datetime import datetime, timezone
  89. from pathlib import Path
  90. name, reason = sys.argv[1], sys.argv[2]
  91. run = Path(os.environ["HTH_RUN_DIR"])
  92. now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
  93. log = run / f"{name}.log"
  94. log.write_text(reason + "\n", encoding="utf-8")
  95. sha = hashlib.sha256((reason + "\n").encode()).hexdigest()
  96. (run / f"{name}.meta").write_text(
  97. "\n".join([
  98. f"run_id={os.environ.get('HTH_RUN_ID','')}",
  99. f"commit={os.environ.get('HTH_GIT_COMMIT','')}",
  100. f"tree={os.environ.get('HTH_GIT_TREE','')}",
  101. "dirty=clean",
  102. f"start_utc={now}",
  103. f"end_utc={now}",
  104. f"command={reason}",
  105. "exit=2",
  106. "status=NOT RUN",
  107. f"reason={reason}",
  108. f"not_run_reason_sha256={hashlib.sha256(reason.encode()).hexdigest()}",
  109. f"log_sha256={sha}",
  110. f"recorded_utc={now}",
  111. ]) + "\n",
  112. encoding="utf-8",
  113. )
  114. print(f"{name} status=NOT RUN")
  115. PY
  116. }
  117. echo "HOST_VERIFY mode=${MODE} commit=${COMMIT} tree=${TREE} run=${HTH_RUN_ID} dir=${RUN}" | tee "${RUN}/gates-start.txt"
  118. cd "${SRC}/host"
  119. SOAK_PID=""
  120. if [[ "${MODE}" == "full" ]]; then
  121. rec soak-2h env HTH_SOAK_2H=1 go test ./internal/device -run '^TestIntegrationSoak2h$' -count=1 -timeout 150m &
  122. SOAK_PID=$!
  123. fi
  124. rec gofmt bash -c 'out=$(gofmt -l .); if [[ -n "$out" ]]; then echo "$out"; exit 1; fi'
  125. rec go-test go test ./... -count=1 -timeout 25m
  126. rec vet go vet ./...
  127. 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
  128. if command -v buf >/dev/null 2>&1; then
  129. rec buf-lint buf lint
  130. else
  131. rec buf-lint bash -c 'echo "buf missing"; exit 2'
  132. fi
  133. if [[ "${MODE}" != "fast" ]]; then
  134. rec race env CGO_ENABLED=1 go test -race ./... -count=1 -timeout 40m
  135. if command -v staticcheck >/dev/null 2>&1; then
  136. rec staticcheck staticcheck ./...
  137. else
  138. rec staticcheck bash -c 'echo "staticcheck missing"; exit 2'
  139. fi
  140. if command -v govulncheck >/dev/null 2>&1; then
  141. rec govulncheck govulncheck ./...
  142. else
  143. rec govulncheck bash -c 'echo "govulncheck missing"; exit 2'
  144. fi
  145. if command -v buf >/dev/null 2>&1; then
  146. rec buf-breaking bash "${SRC}/host/tools/run_buf_breaking.sh"
  147. else
  148. rec buf-breaking bash -c 'echo "buf missing"; exit 2'
  149. fi
  150. rec python-matrix bash "${SRC}/host/tools/sdk_wheel_matrix.sh"
  151. rec algorithm-gates bash "${SRC}/host/tools/run_algorithm_gates.sh"
  152. rec pty go test ./tests -count=1 -timeout 25m -run 'PTY|Pty|Capture|Sigterm|UDS|NoTCP'
  153. rec soak-pr-5m env HTH_SOAK_SECONDS=300 go test ./tests -run '^TestPRSoakMock$' -count=1 -timeout 10m
  154. if [[ -f "${SRC}/host/tools/rtl_uart_cosim/run_hthd_pty_rtl.py" ]]; then
  155. rec rtl-sim-uart "${PYTHON}" "${SRC}/host/tools/rtl_uart_cosim/run_hthd_pty_rtl.py"
  156. else
  157. rec rtl-sim-uart bash -c 'echo "rtl harness missing"; exit 2'
  158. fi
  159. fi
  160. if [[ "${MODE}" == "full" ]]; then
  161. if [[ -f "${SRC}/host/tools/rtl_uart_cosim/run_hthd_pty_rtl.py" ]]; then
  162. rec_optional rtl-production-uart env HTH_PRODUCTION_UART=1 "${PYTHON}" "${SRC}/host/tools/rtl_uart_cosim/run_hthd_pty_rtl.py"
  163. else
  164. record_not_run rtl-production-uart "rtl harness missing"
  165. fi
  166. if [[ -x "${SRC}/host/tools/qemu_systemd_vm.sh" ]]; then
  167. rec systemd-qemu-vm bash "${SRC}/host/tools/qemu_systemd_vm.sh"
  168. else
  169. record_not_run systemd-qemu-vm "qemu script missing"
  170. fi
  171. rec fuzz-15m bash "${SRC}/host/tools/run_fuzz_15m.sh"
  172. fi
  173. if [[ "${MODE}" == "fast" ]]; then
  174. record_not_run race "fast mode skipped"
  175. record_not_run staticcheck "fast mode skipped"
  176. record_not_run govulncheck "fast mode skipped"
  177. record_not_run buf-breaking "fast mode skipped"
  178. record_not_run python-matrix "fast mode skipped"
  179. record_not_run algorithm-kit "fast mode skipped"
  180. record_not_run pty "fast mode skipped"
  181. record_not_run soak-pr-5m "fast mode skipped"
  182. record_not_run rtl-sim-uart "fast mode skipped"
  183. fi
  184. if [[ "${MODE}" != "full" ]]; then
  185. record_not_run rtl-production-uart "${MODE} mode skipped; production 217 clocks/bit is full-only"
  186. record_not_run systemd-qemu-vm "${MODE} mode skipped"
  187. record_not_run fuzz-15m "${MODE} mode skipped"
  188. record_not_run soak-2h "${MODE} mode skipped"
  189. fi
  190. record_not_run soak-24h "24h soak NOT RUN this run; blocks release_candidate_readiness only"
  191. record_not_run hardware-validation "Hardware validation NOT RUN; no COM/JTAG/real actuators"
  192. record_not_run real-actuator-validation "Real actuator validation NOT RUN"
  193. if [[ -n "${SOAK_PID}" ]]; then
  194. echo "waiting soak-2h pid=${SOAK_PID}"
  195. wait "${SOAK_PID}" || fail=1
  196. fi
  197. if [[ "${MODE}" != "fast" ]]; then
  198. "${PYTHON}" "${SRC}/host/tools/gen_run_manifest.py" "${RUN}" || fail=1
  199. "${PYTHON}" "${SRC}/host/tools/evaluate_gates.py" || fail=1
  200. cd "${SRC}/host/tools"
  201. rec package-review "${PYTHON}" package_hth_review.py
  202. ZIP="$(ls -1t "${PKG_DIR}"/hth-platform-safety-closure-*.zip "${PKG_DIR}"/hth-engineering-review-*.zip 2>/dev/null | head -n1 || true)"
  203. if [[ -n "${ZIP}" ]]; then
  204. STAGE="${RUN}/unzip-offline"
  205. rm -rf "${STAGE}"
  206. mkdir -p "${STAGE}"
  207. "${PYTHON}" -c "import sys; from pathlib import Path; sys.path.insert(0, r'''${SRC}/host/tools'''); from zip_unix_modes import extract_zip_with_unix_modes; extract_zip_with_unix_modes(Path(r'''${ZIP}'''), Path(r'''${STAGE}'''))"
  208. ROOTDIR="$(find "${STAGE}" -maxdepth 1 -type d \( -name 'hth-platform-r6' -o -name 'hth-platform' \) | head -n1)"
  209. if [[ -n "${ROOTDIR}" ]]; then
  210. rec package-offline "${PYTHON}" "${SRC}/host/tools/verify_review_package.py" "${ROOTDIR}" --mode offline
  211. else
  212. rec package-offline bash -c 'echo "unzipped package root missing"; exit 1'
  213. fi
  214. else
  215. rec package-review bash -c 'echo "review zip missing"; exit 1'
  216. fi
  217. "${PYTHON}" "${SRC}/host/tools/gen_run_manifest.py" "${RUN}" || fail=1
  218. "${PYTHON}" "${SRC}/host/tools/evaluate_gates.py" || fail=1
  219. fi
  220. echo "HOST_VERIFY_DONE mode=${MODE} fail=${fail} run=${HTH_RUN_ID}" | tee "${RUN}/GATES_DONE"
  221. exit "${fail}"