Skip to content

Add QEMUDriver.interact() and qemu-run.py example#1892

Merged
Emantor merged 2 commits into
labgrid-project:masterfrom
Bastian-Krause:bst/qemu-interact
Jun 10, 2026
Merged

Add QEMUDriver.interact() and qemu-run.py example#1892
Emantor merged 2 commits into
labgrid-project:masterfrom
Bastian-Krause:bst/qemu-interact

Conversation

@Bastian-Krause

Copy link
Copy Markdown
Member

Description
Since the QEMUDriver can't be used with labgrid-client (because it does not use labgrid's remote infrastructue), there is currently no good way of accessing its console interactively, e.g. for debugging.

Add a QEMUDriver.interact() method that creates a PTY, let microcom open it and relay the QEMUDriver's input and output to that PTY.

Add an example helper to run QEMU, either by activating the QEMUDriver directly or by transitioning into a strategy state first, then start an interactive console.

Checklist

  • PR has been tested

@Bastian-Krause Bastian-Krause changed the title Bst/qemu interact Add QEMUDriver.interact() and qemu-run.py example Jun 9, 2026
Since the QEMUDriver can't be used with labgrid-client (because it does
not use labgrid's remote infrastructue), there is currently no good way
of accessing its console interactively, e.g. for debugging.

Add a QEMUDriver.interact() method that creates a PTY, let microcom open
it and relay the QEMUDriver's input and output to that PTY.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
The QEMUDriver can't be used with labgrid-client, because it does not
use labgrid's remote infrastructure.

Add an example helper to run QEMU, either by activating the QEMUDriver
directly or by transitioning into a strategy state first, then start an
interactive console.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.00000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.9%. Comparing base (3466688) to head (11e0ffb).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/driver/qemudriver.py 16.0% 21 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1892     +/-   ##
========================================
- Coverage    46.0%   45.9%   -0.1%     
========================================
  Files         180     180             
  Lines       14471   14496     +25     
========================================
+ Hits         6662    6666      +4     
- Misses       7809    7830     +21     
Flag Coverage Δ
3.10 45.9% <16.0%> (-0.1%) ⬇️
3.11 45.9% <16.0%> (-0.1%) ⬇️
3.12 45.9% <16.0%> (-0.1%) ⬇️
3.13 45.9% <16.0%> (-0.1%) ⬇️
3.14 45.9% <16.0%> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@Emantor Emantor merged commit d3c08b1 into labgrid-project:master Jun 10, 2026
8 of 10 checks passed
@a3f

a3f commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

I just gave it a try and wondering if there is a good way to terminate microcom when qemu exits?
Also, it's not possible to just spawn qemu with this, unless pytest has been called with -s in the first place. Could that be solved somehow? FWIW, here is what I did before:

cmd = self.qemu.get_qemu_base_args()

with open("/dev/tty", "r+b", buffering=0) as tty:
    tty.write(bytes("Run manually with: \n{} -serial mon:stdio\n".format(quote_cmd(cmd)), "UTF-8"))
    if state == "qemu_dry_run":
        pytest.exit('Dry run. Terminating.')
    subprocess.run(cmd, stdin=tty, stdout=tty, stderr=tty)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants