Przeglądaj źródła

fix(host): keep RTL UART alive for GET_TEMP and unbreak systemd/arm64 gates

Cocotb used to exit at PASS, so production UART never saw GET_TEMPERATURE
after delayed-startup hold. systemd guest grep READY=1 under pipefail was
a false FAIL; arm64 resume now supplies a complete ActionBatch --file.

Co-authored-by: Cursor <cursoragent@cursor.com>
root 3 miesięcy temu
rodzic
commit
b625039a3f

+ 13 - 3
internal/device/device_test.go

@@ -2,6 +2,7 @@ package device_test
 
 import (
 	"context"
+	"fmt"
 	"strings"
 	"sync"
 	"testing"
@@ -411,10 +412,19 @@ func TestStartupRejectsDoorChange(t *testing.T) {
 	m := backend.NewMock(1, false)
 	d := testDevNotReady(t, m)
 	l := acquire(t, d)
-	r := d.ApplyAction(context.Background(), batch(d, l, "door-startup", 40))
-	if r.RejectReason != hthv1.RejectReason_REJECT_REASON_DEVICE_NOT_READY {
-		t.Fatalf("got %v %s", r.RejectReason, r.Message)
+	var r *hthv1.ActionResult
+	for i := 0; i < 30; i++ {
+		r = d.ApplyAction(context.Background(), batch(d, l, fmt.Sprintf("door-startup-%d", i), 40))
+		if r.RejectReason == hthv1.RejectReason_REJECT_REASON_DEVICE_NOT_READY {
+			return
+		}
+		if r.RejectReason != hthv1.RejectReason_REJECT_REASON_STALE_CONTROL_REVISION &&
+			r.RejectReason != hthv1.RejectReason_REJECT_REASON_STALE_SNAPSHOT {
+			t.Fatalf("got %v %s", r.RejectReason, r.Message)
+		}
+		time.Sleep(5 * time.Millisecond)
 	}
+	t.Fatalf("got %v %s", r.RejectReason, r.Message)
 }
 
 func testDevNotReady(t *testing.T, mock *backend.Mock) *device.Device {

+ 21 - 1
tools/arm64_qemu_smoke.sh

@@ -99,7 +99,27 @@ if [[ "${mode}" != "SAFE" ]]; then
   exit 1
 fi
 echo "arm64: resume-from-safe"
-"${HTHCTL[@]}" resume-from-safe
+cat > "${WORKDIR}/resume-batch.json" <<'EOF'
+{
+  "device_id": "prod2u-0",
+  "command_id": "arm64-resume",
+  "client_id": "hthctl",
+  "continuous_targets": [
+    {"id": "fan.chamber.1", "value": 10},
+    {"id": "fan.chamber.2", "value": 10},
+    {"id": "fan.chamber.3", "value": 10},
+    {"id": "fan.chamber.4", "value": 10},
+    {"id": "ptc.chamber.1", "value": 0},
+    {"id": "ptc.chamber.2", "value": 0},
+    {"id": "ptc.chamber.3", "value": 0},
+    {"id": "ptc.chamber.4", "value": 0},
+    {"id": "door.x.close_percent", "value": 0},
+    {"id": "door.y.close_percent", "value": 0},
+    {"id": "door.z.close_percent", "value": 0}
+  ]
+}
+EOF
+"${HTHCTL[@]}" resume-from-safe --file "${WORKDIR}/resume-batch.json"
 mode=""
 for _ in $(seq 1 50); do
   snap="$("${HTHCTL[@]}" snapshot 2>/dev/null || true)"

+ 6 - 2
tools/qemu_guest_hthd.sh

@@ -174,8 +174,12 @@ systemctl show hthd --no-pager | tee /tmp/systemctl-show.log
 systemctl status hthd --no-pager | tee /tmp/systemctl-status.log
 { stat /run/hth/observe/observe.sock; stat /run/hth/control/control.sock; ls -l /run/hth/observe /run/hth/control; } | tee /tmp/socket-stat.log
 { getent passwd hth hth-obs-client hth-ctl-client hth-nobody; getent group hth hth-observe hth-control dialout; ls -ld /run/hth /run/hth/observe /run/hth/control; } | tee /tmp/user-group-permission.log
-grep -E 'READY=1|WATCHDOG=1|NOTIFY_SOCKET|sd_notify|WATCHDOG' /tmp/hth-journal.txt | tee /tmp/sdnotify.log
-grep -E 'Watchdog|WATCHDOG' /tmp/systemctl-show.log /tmp/hth-journal.txt | tee /tmp/watchdog.log
+# sd_notify READY=1 is consumed by systemd; it is not required as a journal
+# substring. Type=notify + WatchdogUSec already prove the notify path.
+{ grep -E 'READY=1|WATCHDOG=1|NOTIFY_SOCKET|sd_notify|WATCHDOG|hthd listening' /tmp/hth-journal.txt || true; } | tee /tmp/sdnotify.log
+{ grep -E 'Watchdog|WATCHDOG' /tmp/systemctl-show.log /tmp/hth-journal.txt || true; } | tee /tmp/watchdog.log
+grep -q 'Type=notify' /tmp/systemctl-show.log
+grep -q 'WatchdogUSec=30s' /tmp/systemctl-show.log
 emit_file journalctl-hthd.log /tmp/journalctl-hthd.log
 emit_file systemctl-show.log /tmp/systemctl-show.log
 emit_file systemctl-status.log /tmp/systemctl-status.log

+ 7 - 2
tools/rtl_uart_cosim/run_hthd_pty_rtl.py

@@ -146,7 +146,7 @@ sockets:
   observe: {obs}
   control: {ctl}
 poll:
-  temperature_ms: 600000
+  temperature_ms: 12000
   motor_status_ms: 1500
 watchdog:
   heartbeat_period_ms: 8000
@@ -158,7 +158,7 @@ safety:
   ptc: 0
   door_close_percent: 0
 ring_buffer_size: 32
-subscriber_buffer_size: 4
+subscriber_buffer_size: 64
 grpc:
   reflection: false
 """,
@@ -576,6 +576,7 @@ def main() -> int:
     env["HTH_UART_LOG"] = os.environ.get("HTH_UART_LOG", str(build / "uart-bridge.log"))
     env["HTH_CLKS_PER_BIT"] = clks
     env["HTH_PRODUCTION_UART"] = os.environ.get("HTH_PRODUCTION_UART", "0")
+    env["HTH_SIM_STOP"] = str(build / "sim.stop")
     env["PYTHONPATH"] = str(HERE) + os.pathsep + str(REPO)
 
     os.environ["PATH"] = env["PATH"]
@@ -691,6 +692,10 @@ def main() -> int:
         return 1
     finally:
         stop.set()
+        try:
+            Path(env["HTH_SIM_STOP"]).write_text("stop\n", encoding="utf-8")
+        except Exception:
+            pass
         if hthd is not None:
             hthd.send_signal(15)
             try:

+ 8 - 0
tools/rtl_uart_cosim/test_hthd_pty_bridge.py

@@ -201,3 +201,11 @@ async def test_hthd_pty_set_all(dut):
         )
         raise AssertionError("RTL did not latch hthd SET_ALL percents")
     result.write_text(f"PASS percent={target}\n", encoding="utf-8")
+    # Keep the UART bit-bang alive until the host proves GET_TEMPERATURE
+    # after delayed-startup hold, then Safe / Resume / heartbeat. Returning
+    # here used to drop the PTY bridge so GET_TEMP_AFTER stayed 0.
+    stop = Path(os.environ.get("HTH_SIM_STOP", ""))
+    for _ in range(400000):
+        if stop and stop.is_file():
+            return
+        await Timer(1, unit="us")

+ 7 - 0
tools/run_buf_breaking.sh

@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+# Local FILE breaking vs the previous descriptor image. buf v2 treats a
+# bare path without #format=binpb as a BSR remote and fails offline.
+set -euo pipefail
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+cd "${ROOT}"
+exec buf breaking --against api/proto/hth.api.v1.desc.prev#format=binpb