Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for testing ChromeOS targets #673

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions devlib/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -2939,7 +2939,7 @@ def _get_part_name(section):
variant = section.get('CPU variant', '0x0')
name = get_cpu_name(*list(map(integer, [implementer, part, variant])))
if name is None:
name = '{}/{}/{}'.format(implementer, part, variant)
name = f'{implementer}/{part}/{variant}'
return name


Expand Down Expand Up @@ -2973,10 +2973,13 @@ def process_node(node, path, value):


class ChromeOsTarget(LinuxTarget):
"""
Class for interacting with ChromeOS targets.
"""

os = 'chromeos'

# pylint: disable=too-many-locals
# pylint: disable=too-many-locals,too-many-arguments
def __init__(self,
connection_settings=None,
platform=None,
Expand Down Expand Up @@ -3009,17 +3012,17 @@ def __init__(self,
if key in ssh_conn_params
)

super(ChromeOsTarget, self).__init__(connection_settings=self.ssh_connection_settings,
platform=platform,
working_directory=working_directory,
executables_directory=executables_directory,
connect=False,
modules=modules,
load_default_modules=load_default_modules,
shell_prompt=shell_prompt,
conn_cls=SshConnection,
is_container=is_container,
max_async=max_async)
super().__init__(connection_settings=self.ssh_connection_settings,
platform=platform,
working_directory=working_directory,
executables_directory=executables_directory,
connect=False,
modules=modules,
load_default_modules=load_default_modules,
shell_prompt=shell_prompt,
conn_cls=SshConnection,
is_container=is_container,
max_async=max_async)

# We can't determine if the target supports android until connected to the linux host so
# create unconditionally.
Expand All @@ -3037,16 +3040,15 @@ def __init__(self,
self.android_connection_settings['device'] = connection_settings.get('host', None)

self.android_container = AndroidTarget(connection_settings=self.android_connection_settings,
platform=platform,
working_directory=android_working_directory,
executables_directory=android_executables_directory,
connect=False,
modules=[], # Only use modules with linux target
load_default_modules=False,
shell_prompt=shell_prompt,
conn_cls=AdbConnection,
package_data_directory=package_data_directory,
is_container=True)
platform=platform,
working_directory=android_working_directory,
executables_directory=android_executables_directory,
connect=False,
load_default_modules=False,
shell_prompt=shell_prompt,
conn_cls=AdbConnection,
package_data_directory=package_data_directory,
is_container=True)
if connect:
self.connect()

Expand All @@ -3056,15 +3058,15 @@ def __getattr__(self, attr):
if not present, use android implementation if available.
"""
try:
return super(ChromeOsTarget, self).__getattribute__(attr)
return super().__getattribute__(attr)
except AttributeError:
if hasattr(self.android_container, attr):
return getattr(self.android_container, attr)
else:
raise
raise

def connect(self, timeout=30, check_boot_completed=True, max_async=None):
super(ChromeOsTarget, self).connect(
@asyn.asyncf
async def connect(self, timeout=30, check_boot_completed=True, max_async=None):
super().connect(
timeout=timeout,
check_boot_completed=check_boot_completed,
max_async=max_async,
Expand Down
8 changes: 8 additions & 0 deletions tests/target_configs.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ AndroidTarget:
connection_settings:
device: 'emulator-5554'

ChromeOsTarget:
entry-0:
connection_settings:
device: 'emulator-5556'
host: 'example.com'
username: 'username'
password: 'password'

LinuxTarget:
entry-0:
connection_settings:
Expand Down
31 changes: 29 additions & 2 deletions tests/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pprint import pp
import pytest

from devlib import AndroidTarget, LinuxTarget, LocalLinuxTarget, QEMUTargetRunner
from devlib import AndroidTarget, ChromeOsTarget, LinuxTarget, LocalLinuxTarget, QEMUTargetRunner
from devlib.utils.android import AdbConnection
from devlib.utils.misc import load_struct_from_yaml

Expand Down Expand Up @@ -53,6 +53,16 @@ def build_targets():
l_target = LinuxTarget(connection_settings=entry['connection_settings'])
targets.append((l_target, None))

if target_configs.get('ChromeOsTarget') is not None:
print('> ChromeOS targets:')
for entry in target_configs['ChromeOsTarget'].values():
pp(entry)
c_target = ChromeOsTarget(
connection_settings=entry['connection_settings'],
working_directory='/tmp/devlib-target',
)
targets.append((c_target, None))

if target_configs.get('LocalLinuxTarget') is not None:
print('> LocalLinux targets:')
for entry in target_configs['LocalLinuxTarget'].values():
Expand All @@ -72,7 +82,24 @@ def build_targets():
qemu_settings=qemu_settings,
connection_settings=connection_settings,
)
targets.append((qemu_runner.target, qemu_runner))

if entry.get('ChromeOsTarget') is None:
targets.append((qemu_runner.target, qemu_runner))
continue

# Leave termination of QEMU runner to ChromeOS target.
targets.append((qemu_runner.target, None))

print('> ChromeOS targets:')
pp(entry['ChromeOsTarget'])
c_target = ChromeOsTarget(
connection_settings={
**entry['ChromeOsTarget']['connection_settings'],
**qemu_runner.target.connection_settings,
},
working_directory='/tmp/devlib-target',
)
targets.append((c_target, qemu_runner))

return targets

Expand Down