mirror of
https://github.com/ARM-software/devlib.git
synced 2025-09-02 01:51:53 +01:00
target: Implement target runner classes
Add support for launching emulated targets on QEMU. The base class ``TargetRunner`` has groundwork for target runners like ``QEMUTargetRunner``. ``TargetRunner`` is a contextmanager which starts runner process (e.g., QEMU), makes sure the target is accessible over SSH (if ``connect=True``), and terminates the runner process once it's done. The other newly introduced ``QEMUTargetRunner`` class: - performs sanity checks to ensure QEMU executable, kernel, and initrd images exist, - builds QEMU parameters properly, - creates ``Target`` object, - and lets ``TargetRunner`` manage the QEMU instance. Also add a new test case in ``tests/test_target.py`` to ensure devlib can run a QEMU target and execute some basic commands on it. While we are in neighborhood, fix a typo in ``Target.setup()``. Signed-off-by: Metin Kaya <metin.kaya@arm.com>
This commit is contained in:
@@ -15,3 +15,16 @@ LocalLinuxTarget:
|
||||
connection_settings:
|
||||
unrooted: True
|
||||
|
||||
QEMUTargetRunner:
|
||||
entry-0:
|
||||
qemu_settings:
|
||||
kernel_image: '/path/to/devlib/tools/buildroot/buildroot-v2023.11.1-aarch64/output/images/Image'
|
||||
|
||||
entry-1:
|
||||
connection_settings:
|
||||
port : 8023
|
||||
|
||||
qemu_settings:
|
||||
kernel_image: '/path/to/devlib/tools/buildroot/buildroot-v2023.11.1-x86_64/output/images/bzImage'
|
||||
arch: 'x86_64'
|
||||
cmdline: 'console=ttyS0'
|
||||
|
@@ -20,7 +20,7 @@ import os
|
||||
from pprint import pp
|
||||
import pytest
|
||||
|
||||
from devlib import AndroidTarget, LinuxTarget, LocalLinuxTarget
|
||||
from devlib import AndroidTarget, LinuxTarget, LocalLinuxTarget, QEMUTargetRunner
|
||||
from devlib.utils.android import AdbConnection
|
||||
from devlib.utils.misc import load_struct_from_yaml
|
||||
|
||||
@@ -44,32 +44,49 @@ def build_targets():
|
||||
connection_settings=entry['connection_settings'],
|
||||
conn_cls=lambda **kwargs: AdbConnection(adb_as_root=True, **kwargs),
|
||||
)
|
||||
targets.append(a_target)
|
||||
targets.append((a_target, None))
|
||||
|
||||
if target_configs.get('LinuxTarget') is not None:
|
||||
print('> Linux targets:')
|
||||
for entry in target_configs['LinuxTarget'].values():
|
||||
pp(entry)
|
||||
l_target = LinuxTarget(connection_settings=entry['connection_settings'])
|
||||
targets.append(l_target)
|
||||
targets.append((l_target, None))
|
||||
|
||||
if target_configs.get('LocalLinuxTarget') is not None:
|
||||
print('> LocalLinux targets:')
|
||||
for entry in target_configs['LocalLinuxTarget'].values():
|
||||
pp(entry)
|
||||
ll_target = LocalLinuxTarget(connection_settings=entry['connection_settings'])
|
||||
targets.append(ll_target)
|
||||
targets.append((ll_target, None))
|
||||
|
||||
if target_configs.get('QEMUTargetRunner') is not None:
|
||||
print('> QEMU target runners:')
|
||||
for entry in target_configs['QEMUTargetRunner'].values():
|
||||
pp(entry)
|
||||
qemu_settings = entry.get('qemu_settings') and entry['qemu_settings']
|
||||
connection_settings = entry.get(
|
||||
'connection_settings') and entry['connection_settings']
|
||||
|
||||
qemu_runner = QEMUTargetRunner(
|
||||
qemu_settings=qemu_settings,
|
||||
connection_settings=connection_settings,
|
||||
)
|
||||
targets.append((qemu_runner.target, qemu_runner))
|
||||
|
||||
return targets
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target", build_targets())
|
||||
def test_read_multiline_values(target):
|
||||
@pytest.mark.parametrize("target, target_runner", build_targets())
|
||||
def test_read_multiline_values(target, target_runner):
|
||||
"""
|
||||
Test Target.read_tree_values_flat()
|
||||
|
||||
:param target: Type of target per :class:`Target` based classes.
|
||||
:type target: Target
|
||||
|
||||
:param target_runner: Target runner object to terminate target (if necessary).
|
||||
:type target: TargetRunner
|
||||
"""
|
||||
|
||||
data = {
|
||||
@@ -96,4 +113,8 @@ def test_read_multiline_values(target):
|
||||
print(f'Removing {target.working_directory}...')
|
||||
target.remove(target.working_directory)
|
||||
|
||||
if target_runner is not None:
|
||||
print('Terminating target runner...')
|
||||
target_runner.terminate()
|
||||
|
||||
assert {k: v.strip() for k, v in data.items()} == result
|
||||
|
Reference in New Issue
Block a user