feat: serial expect/send automation sequences#343
Open
llogen wants to merge 3 commits into
Open
Conversation
golang.org/x/net/http2/h2c is deprecated; unencrypted HTTP/2 is now supported directly by net/http via the Protocols field (Go 1.24+). - servers: replace h2c.NewHandler with an http.Server configured via Server.Protocols (HTTP/1 + unencrypted HTTP/2) - clients: replace http2.Transport (AllowHTTP/DialTLS) with http.Transport configured via Transport.Protocols - add ReadHeaderTimeout to the servers to mitigate Slowloris (gosec G112), removing the previous //nolint:gosec - drop the now-unused golang.org/x/net direct dependency (moved to indirect) Signed-off-by: Jens Topp <jens.topp@blindspot.software>
Signed-off-by: Fabian Wienand <fabian.wienand@blindspot.software>
The serial module gains expect-send and arbitrarily ordered tagged expect:/send: sequences, so a test can drive a DUT hands-off — wait for a prompt, send input, in any order. Matching uses a rolling window (so prompts without a trailing newline match immediately) and non-SGR terminal escape sequences are stripped from the output. Signed-off-by: llogen <christoph.lange@blindspot.software>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds hands-off serial automation to the
serialdutagent module: wait for prompts and send input, scripted end-to-end on the agent. This is what FirmwareCI/contest automation needs (login flows, running commands over the DUT console) — no human-interactive console required.It replaces
main's read-only single-expect serial module with an expect / expect-send / sequence implementation, a rolling-window matcher, terminal-escape filtering, and a configurable inter-send delay.What's new
Argument modes
All matching and input happen server-side on the dutagent.
<regex><regex> <resp> …(even count)expect:<regex>/send:<data>tags, any orderTagged sequence (headline feature)
serial send:'\n' expect:'login:' send:'root\n' expect:'Password:' send:'secret\n' expect:'# '
Unlike expect-send pairs (which must start with an expect and strictly alternate), a sequence can begin with a
send(e.g. an Enter to wake the console) and chain sends/expects in any order — including two sends in a row.-tdeadline.sendsupports C-style escapes:\n \r \t \\ \xHH.expectis an RE2 regular expression.delaymodule optionA
with:option that paces input — a pause applied before every send:Default 50ms. It covers two timing problems that bite real consoles:
login: shows can drop the first characters),
Expect-gating (waiting for the prompt/echo) is still the primary, deterministic
mechanism; the delay is a safety net for consoles that signal readiness early or
give nothing to expect on. Set delay: "0s" to send immediately.
Key behaviors
bounded) re-checked on every read, so a prompt without a trailing newline
(login:) matches immediately instead of waiting for the next line.
and ANSI string sequences (DCS/OSC/SOS/PM/APC capability responses) are
stripped from the output; SGR colour is preserved.
Explicitly not in this PR (deferred to a follow-up)
These are a separate concern from automation and will land in a follow-up PR.
Backward compatibility
matcher, so it also catches prompts that arrive without a trailing newline.
Examples
dutctl serial # monitor output
dutctl serial 'login:' # wait for a prompt
dutctl serial 'login:' 'root\n' # expect-send pair
dutctl serial send:'\n' expect:'login:'
send:'root\n' expect:'# ' # sequence (any order)
Testing
argument parsing (legacy + tagged sequence), Init (port/baud/delay defaults
and parsing), and Run behavior (single expect, expect-send pairs, sequence:
leading-send / send-only / ends-on-expect, timeout, CSI stripping, match
spanning reads, context cancel, pre-send delay). go test -race and
golangci-lint clean.
real HPE DL320 OpenBMC serial console (login → run command → reboot, the
trailing-send drain, and timeout behavior).
Files changed
Related (separate repos, companion PRs)
renders into these tagged arguments.
🤖 Generated with Claude Code