Target
Introduction
Our Target
is a wrapper around
devlib.target.Target
. In short, it’s a device communication
abstraction library that gives us a simple Python interface for playing around
with a device (shell, file transfer…).
If you want to execute some command on a target, it’s as simple as this:
out = target.execute("ls -al .")
Have a look at the devlib documentation for more details. Our wrapper brings additionnal features which are documented below.
As a rule of thumb, if you want to add a feature to Target
,
chances are this should be contributed to devlib instead.
Connecting to a target
Connecting to a target means creating a Target
instance.
This can be as a simple as this:
target = Target(kind="linux", host="192.168.0.1", username="root", password="root")
For more convenience, you can also save the relevant connection information for
a given target in a configuration file, which would let you create a
Target
like so:
target = Target.from_one_conf("path/to/my/conf.yml")
See also
See the documentation of Target
and
TargetConf
more details.
Platform data
The main source of information for tests come from Trace
and PlatformInfo
. The latter gives access to
information autodetected from the devlib.target.Target
or filled in by
the user.
This information ranges from the current kernel version to the available platform frequencies.
See also
See the documentation of PlatformInfo
for more details.
API
Target
- class lisa.target.PasswordKeyDesc(name, help, classinfo, newtype=None, deepcopy_val=True)[source]
Bases:
KeyDesc
- class lisa.target.TargetConf(conf=None, src='user', add_default_src=True)[source]
Bases:
SimpleMultiSrcConf
,HideExekallID
Target connection settings.
Only keys defined below are allowed, with the given meaning and type:
target-conf: target connection settings
name (
str
): Board name, free-form value only used to embelish logs.kind (
Literal
): Target kind. Can be “linux” (ssh) or “android” (adb).host (
str
or None): Hostname or IP address of the SSH or ADB server.username (
str
or None): SSH username. On ADB connections, “root” username will root adb upon target connection.password (
str
or None): SSH password.port (
int
or None): SSH or ADB server port.device (
str
or None): ADB device.keyfile (
str
or None): SSH private key file.strict-host-check (
bool
or None): Equivalent to StrictHostKeyChecking option of OpenSSH.workdir (
str
): Remote target workdir.tools (
Sequence
): List of tools to install on the target.lazy-platinfo (
bool
): Lazily autodect the platform information to speed up the connection.kernel: kernel information
src (
str
or None): Path to kernel source tree matching the kernel running on the target used to build modules.modules: Kernel module build environment
build-env (
Literal
): Environment used to build modules. Can be any of “alpine” (Alpine Linux chroot, recommended) or “host” (command ran directly on host system).build-env-settings: build-env settings
host: Settings for host build-env
toolchain-path (
str
): Folder to prepend to PATH when executing toolchain command in the host build env.
alpine: Settings for Alpine linux build-env
version (None or
str
): Alpine linux version, e.g. 3.18.0.packages (None or
Sequence
): List of Alpine linux packages to install. If that is provided, then errors while installing the package list provided by LISA will not raise an exception, so that the user can provide their own replacement for them. This allows future-proofing hardcoded package names in LISA, as Alpine package names might evolve between versions..
overlay-backend (
str
): Backend to use for overlaying folders while building modules. Can be “overlayfs” (overlayfs filesystem, recommended and fastest) or “copy (plain folder copy).make-variables (
Dict
): Extra variables to pass to “make” command, such as “CC”.modules: modules settings
<module-name>: For each module. The module shipped by LISA is “lisa”
overlays (
Dict
): Overlays to apply to the sources of the given module.
wait-boot: Wait for the target to finish booting
devlib: devlib configuration
platform: devlib.platform.Platform subclass specification
An instance can be created by calling
TargetConf
with a dictionary. The top-level target-conf key is not needed here:TargetConf({ 'name': 'myboard', 'host': 192.0.2.1, 'kind': 'linux', 'username': 'foo', 'password': 'bar', })
Or alternatively, from a YAML configuration file:
Content of target_conf.yml:
# LISA Target configuration required by devlib to connect to a target. # # See the doc for available keys: # https://tooling.sites.arm.com/lisa/latest/target.html#lisa.target.TargetConf # target-conf: # Kind of platform # - linux : accessed via SSH connection # - android : accessed via ADB connection # - host : run on the local host # kind : android # Board # Optional board name used for better prettier logs # name: myboard # Target IP or domain name # host: 192.168.0.20 # Target Android device ID # device: 00b1346f0878ccb1 # Login username (has to be sudo enabled) # username: root # Login credentials # You can specify either a password or keyfile # password: "mypassword" # keyfile: /complete/path/of/your/keyfile # Optional kernel module configuration # kernel: # Path to the kernel sources. If left out, a kernel.org tarball will be # used (with varying degree of success) # src: /path/to/kernel/src/tree # Module compiling options # modules: # Variables passed to make command line while building modules. # make-variables: # Setting "LLVM: 1" is a good idea as clang is a cross # compiler by default. Just using "CC: clang" will still use # parts of the GNU toolchain. # LLVM: 1 # Either "host" or "alpine". If "alpine" is used, an Alpine chroot # will be used to build the kernel module in. Works best with # "LLVM: 1" for reproducible builds regardless of the build-env. # # build-env: host # It is possible to specify some parameters to build-env, such as # Alpine version: # build-env: # build-env: alpine # build-env-settings: # alpine: # version: 3.18 # packages: # - foobar # Usually not needed: "overlayfs" will overlay folders using # overlayfs. "copy" will use plain slow copies. # overlay-backend: overlayfs # Optional devlib configuration # devlib: # Devlib modules names to enable/disbale for all the experiment # excluded-modules: [] # # devlib Platform sublcass to use, with the keyword arguments to use it # platform: # Defaults to devlib.platform.Platform # class: devlib.platform.Platform # args: # arg1: foo # arg2: bar # Optional additional binary tools to install by default for all experiments # Currently available tools: # - binaries under ./tools/<ARCH>/ # where <ARCH> is one of the supported target # architectures # - shell scripts under './tools/scripts/ # tools: [] # # Ftrace collector configuration ftrace-conf: # Additional ftrace events and functions collected regardless of the # test configuration # events: [] # functions: [] # # ftrace buffer size # buffer-size: 42 # Platform information # # Various bits of information about the platform used by LISA # platform-info: # Include a preset platform-info file, instead of defining the keys directly here. # Note that you cannot use !include and define keys at the same time. # !include $LISA_HOME/lisa/platforms/juno_r0.yml # conf: # rtapp: # # Calibration mapping of CPU numbers to calibration value for rtapp # calib: {}
TargetConf.from_yaml_map('target_conf.yml')
The following special YAML tags can be used in the configuration file:
target-conf: # "!env:<type> ENV_VAR_NAME" can be used to reference an # environment variable. name: !env:str BOARD_NAME port: !env:int PORT
Note
Only load trusted YAML files as it can lead to abritrary code execution.
Note
That structure in a YAML file is allowed and will work:
file foo.yml:
target-conf: name: myboard
file bar.yml:
target-conf: !include foo.yml
This will result in that structure which would normally be invalid, but is handled as a special case:
target-conf: target-conf: name: myboard
Warning
Arbitrary code can be executed while loading an instance from a YAML or Pickle file. To include untrusted data in YAML, use the !untrusted tag along with a string
- STRUCTURE = <lisa.conf.TopLevelKeyDesc object>
- DEFAULT_SRC = {'devlib': {'excluded-modules': [], 'platform': {'class': 'devlib.platform.Platform'}}, 'kernel': {'modules': {'build-env-settings': {'alpine': {}, 'host': {}}, 'modules': {'<module-name>': {}}}}, 'lazy-platinfo': False, 'name': '<noname>', 'tools': [], 'wait-boot': {'enable': True, 'timeout': 10}}
Source added automatically using
add_src()
under the name ‘default’ when instances are built.
- class Device
Bases:
HideExekallID
ADB device
- class DevlibExcludedModules
Bases:
HideExekallID
List of devlib modules to not load
- class DevlibFileXfer
Bases:
HideExekallID
File transfer method. Can be “sftp” (default) or “scp”. (Only valid for linux targets)
- class DevlibMaxAsync
Bases:
HideExekallID
Maximum number of asynchronous commands in flight at any time
- class DevlibPlatformArgs
Bases:
HideExekallID
Keyword arguments to build the Platform object
- class DevlibPlatformClass
Bases:
HideExekallID
Name of the class to use
- class Host
Bases:
HideExekallID
Hostname or IP address of the SSH or ADB server
- class KernelModulesBuildEnv
Bases:
HideExekallID
Environment used to build modules. Can be any of “alpine” (Alpine Linux chroot, recommended) or “host” (command ran directly on host system)
- class KernelModulesBuildEnvSettingsAlpinePackages
Bases:
HideExekallID
List of Alpine linux packages to install. If that is provided, then errors while installing the package list provided by LISA will not raise an exception, so that the user can provide their own replacement for them. This allows future-proofing hardcoded package names in LISA, as Alpine package names might evolve between versions.
- class KernelModulesBuildEnvSettingsAlpineVersion
Bases:
HideExekallID
Alpine linux version, e.g. 3.18.0
- class KernelModulesBuildEnvSettingsHostToolchainPath
Bases:
HideExekallID
Folder to prepend to PATH when executing toolchain command in the host build env
- class KernelModulesMakeVariables
Bases:
HideExekallID
Extra variables to pass to “make” command, such as “CC”
- class KernelModulesModulesModuleNameOverlays
Bases:
HideExekallID
Overlays to apply to the sources of the given module
- class KernelModulesOverlayBackend
Bases:
HideExekallID
Backend to use for overlaying folders while building modules. Can be “overlayfs” (overlayfs filesystem, recommended and fastest) or “copy (plain folder copy)
- class KernelSrc
Bases:
HideExekallID
Path to kernel source tree matching the kernel running on the target used to build modules
- class Keyfile
Bases:
HideExekallID
SSH private key file
- class Kind
Bases:
HideExekallID
Target kind. Can be “linux” (ssh) or “android” (adb)
- class LazyPlatinfo
Bases:
HideExekallID
Lazily autodect the platform information to speed up the connection
- class Name
Bases:
HideExekallID
Board name, free-form value only used to embelish logs
- class Password
Bases:
HideExekallID
SSH password
- class Port
Bases:
HideExekallID
SSH or ADB server port
- class StrictHostCheck
Bases:
HideExekallID
Equivalent to StrictHostKeyChecking option of OpenSSH
- class Tools
Bases:
HideExekallID
List of tools to install on the target
- class Username
Bases:
HideExekallID
SSH username. On ADB connections, “root” username will root adb upon target connection
- class WaitBootEnable
Bases:
HideExekallID
Enable the boot check
- class WaitBootTimeout
Bases:
HideExekallID
Timeout of the boot check
- class Workdir
Bases:
HideExekallID
Remote target workdir
- class lisa.target.Target(kind, name='<noname>', tools=[], res_dir=None, plat_info=None, lazy_platinfo=False, workdir=None, device=None, host=None, port=None, username=None, password=None, keyfile=None, strict_host_check=None, devlib_platform=None, devlib_excluded_modules=[], devlib_file_xfer=None, wait_boot=True, wait_boot_timeout=10, kernel_src=None, kmod_build_env=None, kmod_make_vars=None, kmod_overlay_backend=None, devlib_max_async=None)[source]
Bases:
Loggable
,HideExekallID
,ExekallTaggable
,Configurable
Wrap
devlib.target.Target
to provide additional features on top of it.- Parameters:
kind (Literal) – Target kind. Can be “linux” (ssh) or “android” (adb)
name (str) – Board name, free-form value only used to embelish logs
tools (Sequence) – List of tools to install on the target
lazy_platinfo (bool) – Lazily autodect the platform information to speed up the connection
workdir (str) – Remote target workdir
device (str or None) – ADB device
host (str or None) – Hostname or IP address of the SSH or ADB server
port (int or None) – SSH or ADB server port
username (str or None) – SSH username. On ADB connections, “root” username will root adb upon target connection
password (str or None) – SSH password
keyfile (str or None) – SSH private key file
strict_host_check (bool or None) – Equivalent to StrictHostKeyChecking option of OpenSSH
wait_boot (bool) – Enable the boot check
devlib_excluded_modules (Sequence) – List of devlib modules to not load
devlib_file_xfer (Sequence) – File transfer method. Can be “sftp” (default) or “scp”. (Only valid for linux targets)
devlib_max_async (int or None) – Maximum number of asynchronous commands in flight at any time
wait_boot_timeout (int) – Timeout of the boot check
kernel_src (str or None) – Path to kernel source tree matching the kernel running on the target used to build modules
kmod_build_env (collections.abc.Mapping) – Kernel module build environment
devlib_platform (devlib.platform.Platform) – Instance of
devlib.platform.Platform
to use to build thedevlib.target.Target
plat_info (lisa.platforms.platinfo.PlatformInfo) – Platform information attached to this target, for the benefits of user code.
You need to provide the information needed to connect to the target. For SSH targets that means “host”, “username” and either “password” or “keyfile”. All other fields are optional if the relevant features aren’t needed.
Note
The wrapping of
devlib.target.Target
is done using composition, as opposed to inheritance. This allows swapping the exact class used under the hood, and avoids messing up withdevlib
internal members.- ADB_PORT_DEFAULT = 5037
- SSH_PORT_DEFAULT = 22
- CRITICAL_TASKS = {'android': ['sh', 'adbd', 'usb', 'transport', 'thermal-engine', 'watchdogd', 'rs.media.module'], 'linux': ['init', 'systemd[^-]', 'dbus', 'sh', 'ssh', 'rsyslogd', 'jbd2']}
Dictionary mapping OS name to list of task names that we can’t afford to freeze when using
freeze_userspace()
.
- CONF_CLASS
alias of
TargetConf
- INIT_KWARGS_KEY_MAP = {'device': ['device'], 'devlib_excluded_modules': ['devlib', 'excluded-modules'], 'devlib_file_xfer': ['devlib', 'file-xfer'], 'devlib_max_async': ['devlib', 'max-async'], 'host': ['host'], 'kernel_src': ['kernel', 'src'], 'keyfile': ['keyfile'], 'kind': ['kind'], 'kmod_build_env': ['kernel', 'modules'], 'lazy_platinfo': ['lazy-platinfo'], 'name': ['name'], 'password': ['password'], 'port': ['port'], 'strict_host_check': ['strict-host-check'], 'tools': ['tools'], 'username': ['username'], 'wait_boot': ['wait-boot', 'enable'], 'wait_boot_timeout': ['wait-boot', 'timeout'], 'workdir': ['workdir']}
- get_kmod(mod_cls=<class 'lisa._kmod.DynamicKmod'>, **kwargs)[source]
Build a
lisa._kmod.DynamicKmod
instance of the given subclass.- Parameters:
mod_cls (type) – Subclass of
lisa._kmod.DynamicKmod
used to build the module.- Variable keyword arguments:
Forwarded to the
from_target
class method ofmod_cls
.
- cached_pull(src, dst, **kwargs)[source]
Same as
lisa.target.Target.pull
but will cache the file in thetarget.res_dir
folder, based on the source path.- Variable keyword arguments:
Forwarded to
Target.pull
.
- is_module_available(module)[source]
Check if the given devlib module is available.
- Returns:
True
if module is available,False
otherwise.- Parameters:
module (str) – Devlib module to check.
Note
This will attempt to load the module if it’s not loaded already, and bail out if it fails to load.
- __getattr__(attr)[source]
Forward all non-overriden attributes/method accesses to the underlying
devlib.target.Target
.Note
That will not forward special methods like __str__, since the interpreter bypasses __getattr__ when looking them up.
Note
Devlib modules are loaded on demand when accessed.
- __dir__()[source]
List our attributes plus the ones from the underlying target, and the devlib modules that could be loaded on-demand.
- classmethod from_conf(conf: TargetConf, res_dir: ArtifactPath = None, plat_info: PlatformInfo = None, **kwargs) Target [source]
- classmethod from_default_conf()[source]
Create a
Target
from the YAML configuration file pointed byLISA_CONF
environment variable.Note
Only load trusted YAML files as it can lead to abritrary code execution.
- classmethod from_one_conf(path)[source]
Create a
Target
from a single YAML configuration file.This file will be used to provide a
TargetConf
andlisa.platforms.platinfo.PlatformInfo
instances.Note
Only load trusted YAML files as it can lead to abritrary code execution.
- classmethod from_cli(argv=None, params=None) Target [source]
Same as
from_custom_cli()
without the custom parameters capabilities.- Returns:
A connected
Target
- classmethod from_custom_cli(argv=None, params=None, description=None)[source]
Create a Target from command line arguments.
- Parameters:
argv (list(str)) – The list of arguments.
sys.argv[1:]
will be used if this isNone
.params (dict(str, dict)) – Dictionary of custom parameters to add to the parser. It is in the form of
{param_name: {dict of ArgumentParser.add_argument() options}}
.description (str or None) – Description passed to the argument parser. If
None
, a default one is provided.
- Returns:
A tuple
(args, target)
Note
This method should not be relied upon to implement long-term scripts, it’s more designed for quick scripting.
- get_res_dir(name=None, append_time=True, symlink=True)[source]
Returns a directory managed by LISA to store results.
Usage of that function is reserved to interactive use or simple scripts. Tests should not rely on that as the created folder will not be tracked by any external entity, which means the results will be lost in some automated environment.
- Parameters:
- install_tools(tools)[source]
Install tools additional to those specified in the test config ‘tools’ field
- freeze_userspace()[source]
Context manager that lets you freeze the userspace.
Note
A number of situations prevent from freezing anything. When that happens, a warning is logged but no exception is raised, so it’s a best-effort approach.
- execute_python(f, args, kwargs, **execute_kwargs)[source]
Executes the given Python function
f
with the provided positional and keyword arguments.The return value or any exception is pickled back and is returned/raised in the host caller.
- Variable keyword arguments:
Forwarded to
execute()
that will spawn the Python interpreter on the target
Note
Closure variables are supported, but mutating them will not be reflected in the caller’s context. Also, functions that are referred to will be:
bundled in the script if it is defined in the same module
referred to by name, assuming it comes from a module that is installed on the target and that this module is in scope. If that is not the case, a
NameError
will be raised.
Attention
Decorators are ignored and not applied.
- remote_func(**kwargs)[source]
Decorates a given function to execute remotely using
execute_python()
:target = Target(...) @target.remote_func(timeout=42) def foo(x, y): return x + y # Execute the function on the target transparently val = foo(1, y=2)
- Variable keyword arguments:
Forwarded to
execute()
that will spawn the Python interpreter on the target
- class lisa.target.Gem5SimulationPlatformWrapper(system, simulator, **kwargs)[source]
Bases:
Gem5SimulationPlatform
Platform Info
- lisa.platforms.platinfo.compute_capa_classes(conf)[source]
Derive the platform’s capacity classes from the given conf
This is intended for the creation of the
capacity-classes
key ofPlatformInfo
.
- lisa.platforms.platinfo.compute_rtapp_capacities(conf)[source]
Compute the capacities that will be used for rtapp.
If the CPU capacities are not writeable on the target, the orig capacities will be used, otherwise the capacities adjusted with rtapp calibration will be used.
- class lisa.platforms.platinfo.KernelConfigKeyDesc(name, help, classinfo, newtype=None, deepcopy_val=True)[source]
Bases:
KeyDesc
- class lisa.platforms.platinfo.KernelSymbolsAddress(name, help, classinfo, newtype=None, deepcopy_val=True)[source]
Bases:
KeyDesc
- class lisa.platforms.platinfo.PlatformInfo(conf=None, src='user', add_default_src=True)[source]
Bases:
MultiSrcConf
,HideExekallID
Platform-specific information made available to tests.
platform-info: Platform-specific information
rtapp: RTapp configuration
calib (
Dict
): RTapp calibration dictionary.
kernel: Kernel-related information
version (
KernelVersion
).config (
TypedKernelConfig
).symbols-address (
Dict
): Dictionary of addresses to symbol names extracted from /proc/kallsyms.
nrg-model (
EnergyModel
): Energy model object.cpu-capacities: Dictionaries of CPU ID to capacity value
writeable (
bool
): Whether the CPU capacities can be updated by writing in sysfs on this platform.orig (
Dict
): Default capacity value as exposed by the kernel.rtapp (
Dict
): (derived from platform-info/cpu-capacities/orig, platform- info/cpu-capacities/writeable, platform-info/rtapp/calib) CPU capacities adjusted with rtapp calibration values, for accurate duty cycle reproduction.
abi (
str
): ABI, e.g. “arm64”.os (
str
): OS being used, e.g. “linux”.name (
str
): Free-form name of the board.cpus-count (
int
): Number of CPUs.numa-nodes-count (
int
): Number of NUMA nodes.freq-domains (
Sequence
): Frequency domains modeled by a list of CPU IDs for each domain.freqs (
Dict
): Dictionnary of CPU ID to list of frequencies.capacity-classes (
Sequence
): (derived from platform-info/cpu-capacities/orig) Capacity classes modeled by a list of CPU IDs for each capacity, sorted by capacity.
- Example YAML:
platform-info: conf: cpu-capacities: {} kernel: {} rtapp: {}
Warning
Arbitrary code can be executed while loading an instance from a YAML or Pickle file. To include untrusted data in YAML, use the !untrusted tag along with a string
- STRUCTURE = <lisa.conf.TopLevelKeyDesc object>
Some keys have a reserved meaning with an associated type.
- add_target_src(target, rta_calib_res_dir, src='target', only_missing=True, **kwargs)[source]
Add source from a live
lisa.target.Target
.- Parameters:
target (lisa.target.Target) – Target to inspect.
rta_calib_res_dir (str) – Result directory for rt-app calibrations.
src (str) – Named of the added source.
only_missing (bool) – If
True
, only add values for the keys that are not already provided by another source. This allows speeding up the connection to target, at the expense of not being able to spot inconsistencies between user-provided values and autodetected values.
- Variable keyword arguments:
Forwarded to
lisa.conf.MultiSrcConf.add_src
.
- add_trace_src(trace, src='trace', only_reliable=True, only_missing=True, deferred=True, **kwargs)[source]
Add source from an instance of
lisa.trace.Trace
.- Parameters:
trace – Trace to exploit.
src (str) – Named of the added source.
only_missing (bool) – If
True
, only add values for the keys that are not already provided by another source.only_reliable (bool) – Only add the reliable information, and avoid using heuristics.
deferred (bool) – If
True
,lisa.conf.DeferredValue
will be used so that no expensive parsing will be immediately triggered, but only when needed.
- Variable keyword arguments:
Forwarded to
lisa.conf.MultiSrcConf.add_src
.
- class Abi
Bases:
HideExekallID
ABI, e.g. “arm64”
- class CapacityClasses
Bases:
HideExekallID
(derived from platform-info/cpu-capacities/orig) Capacity classes modeled by a list of CPU IDs for each capacity, sorted by capacity
- class CpuCapacitiesOrig
Bases:
HideExekallID
Default capacity value as exposed by the kernel
- class CpuCapacitiesRtapp
Bases:
HideExekallID
(derived from platform-info/cpu-capacities/orig, platform-info/cpu-capacities/writeable, platform-info/rtapp/calib) CPU capacities adjusted with rtapp calibration values, for accurate duty cycle reproduction
- class CpuCapacitiesWriteable
Bases:
HideExekallID
Whether the CPU capacities can be updated by writing in sysfs on this platform
- class CpusCount
Bases:
HideExekallID
Number of CPUs
- class FreqDomains
Bases:
HideExekallID
Frequency domains modeled by a list of CPU IDs for each domain
- class Freqs
Bases:
HideExekallID
Dictionnary of CPU ID to list of frequencies
- class KernelConfig
Bases:
HideExekallID
- class KernelSymbolsAddress
Bases:
HideExekallID
Dictionary of addresses to symbol names extracted from /proc/kallsyms
- class KernelVersion
Bases:
HideExekallID
- class Name
Bases:
HideExekallID
Free-form name of the board
- class NrgModel
Bases:
HideExekallID
Energy model object
- class NumaNodesCount
Bases:
HideExekallID
Number of NUMA nodes
- class Os
Bases:
HideExekallID
OS being used, e.g. “linux”
- class RtappCalib
Bases:
HideExekallID
RTapp calibration dictionary