Skip to content

Commit 6ec7813

Browse files
committed
qemudriver: Support optional pre-start hook before spinning of the instance.
Signed-off-by: Joschka Seydell <[email protected]>
1 parent b77d6c9 commit 6ec7813

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

doc/configuration.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,6 +2858,10 @@ The QEMUDriver also requires the specification of:
28582858
specify the build device tree
28592859
- a path key, this is the path to the rootfs
28602860

2861+
To allow interactions with the prepared, not yet started QEMU instance, the ``on()``
2862+
method can take an optional ``pre_start_hook`` callable which is executed right before
2863+
the CPU(s) are released.
2864+
28612865
SigrokDriver
28622866
~~~~~~~~~~~~
28632867
The :any:`SigrokDriver` uses a `SigrokDevice`_ resource to record samples and provides

labgrid/driver/qemudriver.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ def on_deactivate(self):
259259
shutil.rmtree(self._tempdir)
260260

261261
@step()
262-
def on(self):
263-
"""Start the QEMU subprocess, accept the unix socket connection and
264-
afterwards start the emulator using a QMP Command"""
262+
def on(self, pre_start_hook=None):
263+
"""Start the QEMU subprocess, accept the unix socket connection, run the
264+
pre_start_hook if applicable and start the emulator using a QMP Command"""
265265
if self.status:
266266
return
267267
self.logger.debug("Starting with: %s", self._cmd)
@@ -289,6 +289,9 @@ def on(self):
289289
for v in self._forwarded_ports.values():
290290
self._add_port_forward(*v)
291291

292+
if pre_start_hook:
293+
pre_start_hook()
294+
292295
self.monitor_command("cont")
293296

294297
@step()

tests/test_qemudriver.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ def test_qemu_on_off(qemu_target, qemu_driver, qemu_mock, qemu_version_mock):
9191

9292
qemu_target.deactivate(qemu_driver)
9393

94+
def test_qemu_on_pre_start_hook(qemu_target, qemu_driver, qemu_mock, qemu_version_mock):
95+
qemu_target.activate(qemu_driver)
96+
97+
called = False
98+
def _hook():
99+
nonlocal called
100+
qemu_driver.monitor_command("info")
101+
called = True
102+
103+
qemu_driver.on(pre_start_hook=_hook)
104+
assert called
105+
94106
def test_qemu_read_write(qemu_target, qemu_driver, qemu_mock, qemu_version_mock):
95107
qemu_target.activate(qemu_driver)
96108

0 commit comments

Comments
 (0)