run_host_verify.sh 9.4 KB

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