Process: add wait_line and fix delta_only buffer offset - #4654
Process: add wait_line and fix delta_only buffer offset#4654mcgov (mcgov) wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a line-oriented waiting helper to Process and adjusts wait_output(delta_only=...) offset bookkeeping to better support incremental consumption of process output (used by the DPDK SRIOV hot-plug test rework).
Changes:
- Added
Process.wait_line(...)to consume captured output by complete lines and evaluate a caller-supplied predicate per line. - Updated
Process.wait_output(...)delta_onlyoffset advancement to move to the end of the matched keyword (and track the last searched buffer length for timeouts).
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
AI Test Case SelectionSelected 1 test case(s): smoke_test Marketplace image: Result: Succeeded |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lisa/util/process.py:646
wait_outputcallsself.log_buffer.getvalue()twice per loop iteration (once forfind()and once forlen()). If new output is appended between those calls,last_search_lencan become longer than the buffer that was actually searched, so on timeoutlog_buffer_offsetmay skip over output that was never searched (reintroducing the delta_only bug this PR is trying to fix). Capture the buffer once and use it for both operations.
find_pos = self.log_buffer_offset if delta_only else 0
buffer = self.log_buffer.getvalue()
found_at_index = buffer.find(keyword, find_pos)
lisa/util/process.py:611
wait_lineonly evaluates complete newline-terminated lines. If the process exits without emitting a trailing newline, any remaining output after the last\nis never checked against the predicate, so a valid final line can be missed. Consider treating the remaining buffered text as a final line once the process is no longer running.
if not is_running:
# the process ended, and its remaining output is consumed.
break
AI Test Case SelectionSelected 1 test case(s): smoke_test Marketplace image: Result: Succeeded |
ed1d741 to
900ceb2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
lisa/util/process.py:611
- Major: wait_line() only evaluates lines that end with "\n". If the process exits with a final line that does not include a trailing newline (common for some commands), that last line is never passed to predicate() and will be missed even though it is present in the captured output. Consider treating the trailing partial line as the final line when the process is no longer running.
if not is_running:
# the process ended, and its remaining output is consumed.
break
Add Process.wait_line, which consumes captured output line by line and hands each complete line to a caller supplied predicate. This allows matching on structured content (for example all key=value pairs of a uevent line) instead of the single substring search wait_output does. Also fix wait_output's delta_only bookkeeping: the offset was advanced to the end of the buffer on a match, so output that arrived after the matched keyword was skipped by the next call. Advance it to the end of the matched keyword instead, and on timeout use the length of the last buffer that was actually searched. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5d5f58ad-b9df-4420-ad37-22caee78e925
Add log line change for stdout -> 'output' Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: mcgov <6216084+mcgov@users.noreply.github.com>
900ceb2 to
b6eb640
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
lisa/util/process.py:613
wait_line()only processes newline-terminated lines. If the process exits (or output ends) with a final line that lacks a trailing\n, the comment says the remaining output is consumed but that tail is never passed topredicate, which can cause false timeouts. Consider treating the remaining tail as the final line when the process has ended, and advancelog_buffer_offsetto the end of the buffer so subsequent calls don’t re-process it.
if not is_running:
# the process ended, and its remaining output is consumed.
break
if time.time() - start_time >= timeout:
break
lisa/util/process.py:602
- When
delta_only=True,positionstarts fromlog_buffer_offset, butlog_buffer_offsetmay point into the middle of a line (e.g. after a priorwait_output()match). In that case, this loop can hand a truncated line fragment (from the middle to the next\n) topredicate, even though the docstring says it waits for a complete output line. Consider skipping forward to the next newline when starting mid-line so only full lines are evaluated.
buffer = self.log_buffer.getvalue()
while True:
line_end = buffer.find("\n", position)
if line_end < 0:
break
lisa/util/process.py:636
last_search_lenis initialized to 0, so if the loop body doesn’t execute (e.g.timeout<=0), the timeout path will resetlog_buffer_offsetto 0 rather than preserving the prior behavior of advancing to the end of the current buffer. Initializinglast_search_lenfrom the current buffer length avoids regressing this edge case.
last_search_len = 0
start_time = time.time()
AI Test Case SelectionSelected 1 test case(s): smoke_test Marketplace image: Result: Succeeded |
Part 1 of 9 of a stacked series that reworks the DPDK SRIOV hot plug tests. This one only touches
lisa/util/process.py.Process.wait_line, which consumes captured output line by line and hands each complete line to a caller supplied predicate, so tests can match on structured content (for example allkey=valuepairs of a uevent line) instead of the single substring searchwait_outputdoes.wait_output'sdelta_onlybookkeeping. The offset was advanced to the end of the whole buffer on a match, so any output that arrived after the matched keyword was skipped by the next call. It now advances to the end of the matched keyword, and on timeout uses the length of the last buffer that was actually searched.Key Test Cases:
verify_dpdk_sriov_rescind_failover_send_only|verify_dpdk_build_netvsc|smoke_test
Impacted LISA Features:
Sriov, NetworkInterface, SerialConsole
Tested Azure Marketplace Images:
canonical 0001-com-ubuntu-server-jammy 22_04-lts latest