From e244f11972e0252a2431c99347bdc90144c21d7f Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Wed, 18 Nov 2026 20:22:39 -0600 Subject: [PATCH] USB console: a log line right after the prompt ends the reply Firmware up to 3.10.12 prints '[sig] SPI1 link at ... for gateware 58' from the hw task on every status; it can land after the '> ' prompt, and _read_until_prompt then timed out (test_e2e_usb::test_network_only_features_fail_fast flaked about 1 in 3 runs on 3.10.12). A prompt followed only by complete [tag] lines now ends the reply. Co-Authored-By: Claude Opus 5.5 --- packages/embeddedci/CHANGELOG.md | 7 ++++ .../embeddedci/benchpod/transport/serial.py | 11 ++++++- .../tests/test_serial_text_console.py | 32 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/embeddedci/CHANGELOG.md b/packages/embeddedci/CHANGELOG.md index e783755..9da753e 100644 --- a/packages/embeddedci/CHANGELOG.md +++ b/packages/embeddedci/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog — `embeddedci` +## Unreleased + +- USB console: a firmware log line printed right after the prompt (`[sig] SPI1 link at ... for + gateware 58`, on every `status` up to firmware 3.10.12) no longer makes the serial transport + time out waiting for the prompt. A prompt followed only by complete `[tag] ...` lines ends the + reply. + ## 3.0.3 - The preset of the default pins is now `Wiring.preset("embeddedci-default")` (also the default of diff --git a/packages/embeddedci/src/embeddedci/benchpod/transport/serial.py b/packages/embeddedci/src/embeddedci/benchpod/transport/serial.py index f2fdc9d..990a9f6 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/transport/serial.py +++ b/packages/embeddedci/src/embeddedci/benchpod/transport/serial.py @@ -54,6 +54,8 @@ DAP_LEAVE = b"\x00\x00" # zero-length frame — leaves the console DAP passthrough UART_READY = "uart ready" # console prints "uart ready (press Ctrl-] to exit)" CTRL_RBRACKET = b"\x1d" # Ctrl-] — leaves the console UART proxy +# The prompt followed only by complete firmware log lines ("[sig] ...\r\n"): see _read_until_prompt. +_PROMPT_THEN_LOG = re.compile(r"(?:^|\n)>[ \t]*(?P(?:\[[A-Za-z0-9_.:-]+\][^\r\n]*\r?\n)+)\Z") _CLEAR_LINE = b"\x08" * 128 # backspaces to clear any partial input line _RAW_READ_TIMEOUT = 0.1 # poll interval while bridging raw CMSIS-DAP bytes UNKNOWN_COMMAND = "unknown command" @@ -429,7 +431,11 @@ def _write_line(self, line: str) -> None: self._port.flush() def _read_until_prompt(self, deadline: float) -> str: - """Accumulate output until the trailing ``"> "`` prompt or timeout.""" + """Accumulate output until the trailing ``"> "`` prompt or timeout. + + Firmware log lines (``[sig] SPI1 link at ...``) are printed from other tasks and can land + right after the prompt, so the reply no longer ends with it. A prompt followed only by + complete ``[tag] ...`` lines ends the reply too; those lines are dropped.""" buf = bytearray() while time.monotonic() < deadline: chunk = self._port.read(256) @@ -438,6 +444,9 @@ def _read_until_prompt(self, deadline: float) -> str: text = buf.decode("utf-8", errors="replace") if text.rstrip(" \t").endswith(">"): return text + trailing = _PROMPT_THEN_LOG.search(text) + if trailing: + return text[:trailing.start("log")] raise TransportTimeout( f"timed out waiting for console prompt; got: " f"{buf.decode('utf-8', errors='replace')!r}" diff --git a/packages/embeddedci/tests/test_serial_text_console.py b/packages/embeddedci/tests/test_serial_text_console.py index 6dd1216..6625990 100644 --- a/packages/embeddedci/tests/test_serial_text_console.py +++ b/packages/embeddedci/tests/test_serial_text_console.py @@ -193,3 +193,35 @@ def test_a_silent_console_is_a_timeout(): t._port._process = lambda line: None # the pod stops answering with pytest.raises(TransportTimeout): t.ping() + + +class LogAfterPromptPort(TextConsolePort): + """Firmware up to 3.10.12 printed its SPI1 link rate from the hw task on every `status`; the + line could land after the prompt, so the reply ended "> [sig] ...\\r\\n" with no new prompt.""" + + LOG = "[sig] SPI1 link at 3906250 Hz (/64) for gateware 58\r\n" + + def _reply(self, text: str) -> None: + super()._reply(text) + self._in.extend(self.LOG.encode()) + + +def test_a_log_line_after_the_prompt_ends_the_reply(): + t = SerialTransport(port=LogAfterPromptPort(), timeout=1) + start = time.monotonic() + st = t.status() + assert time.monotonic() - start < 0.5 + assert st["device"] == "benchpod" + assert t.status()["device"] == "benchpod" # the next command is not thrown off either + + +def test_a_log_line_inside_the_reply_is_not_a_prompt(): + from embeddedci.benchpod.transport.serial import _PROMPT_THEN_LOG + + # Real status output: the log line arrives mid-reply, before the prompt. No early return. + mid = "status\r\n device : benchpod\r\n[sig] SPI1 link at 3906250 Hz (/64) for gateware 58\r\n" + assert _PROMPT_THEN_LOG.search(mid) is None + # A partial log line after the prompt: wait for the rest. + assert _PROMPT_THEN_LOG.search("x\r\n> [sig] SPI1 li") is None + m = _PROMPT_THEN_LOG.search("x\r\n> [sig] SPI1 link\r\n[c3] up\r\n") + assert m and "x\r\n> [sig] SPI1 link\r\n[c3] up\r\n"[:m.start("log")] == "x\r\n> "