Fix inadequate use of module-level __getattr__ (it is not used by the
global variable lookup path). Instead, detect all tools lazily in the
same fashion as with _AndroidEnv()
Module-level __getattr__ is not called on the global variable lookup
path, rendering it useless for what we want to do here.
Instead, use the _AndroidEnvironment class and make it lazy so that we
will not raise an exception by just importing the module.
Android tools detection was manipulating os.environ['PATH'] which has
an impact beyond devlib (and even beyond the current process as it will
be inherited by any child).
Remove that hack and instead use global variables to get adb and
fastboot paths. These tools are now detected by _AndroidEnvironment()
like the others.
* Use lazy global var init using module-level __getattr__() and remove
all the _check_env() calls.
* Cleanup the code by removing unnecessary statefullness. While doing so,
prune paths that can never happen.
* Encapsulate all the logic in _AndroidEnvironment() instead of mutating
it using standalone functions.
* Set "adb" and "fastboot" global variables to None as fastboot was
always set to None, and adb was set to None on the path with
ANDROID_HOME env var set.
PID detection can sometimes fail for unknown reason. Maybe there is a
latency between the process being started and "ps" being able to see it
that can sometimes be high enough that we look for the process before
it's exposed.
In order to remedy that, add a retry logic to avoid plain failures.
Introduce is_screen_locked() which returns true if device screen is
locked and false otherwise.
This will be useful to automate unlocking the screen [1].
Also fix a typo in is_screen_on()'s documentation.
[1] https://github.com/ARM-software/workload-automation/pull/1246
Signed-off-by: Metin Kaya <metin.kaya@arm.com>
is_screen_on() should also check if the screen is in 'Dozing' state. If
the device is dozing, then is_screen_on() should return false.
Without this patch, is_screen_on() throws 'Could not establish screen
state' exception if the device is idling (screen is completely off).
Signed-off-by: Metin Kaya <metin.kaya@arm.com>
dex file search is modified. It collects all the available methods under the package name. Tested with other benchmarks (geekbench,pcmark,jankbench in Android 12) as well.
Android GKI kernels have versions such as:
5.15.110-android14-11-ga6d7915820a0-ab10726252
Update the parsing regex to include:
* gki_abi: 10726252 in this example
* android_version: 14 in this example
This also allows parsing the git sha1 correctly, which otherwise is
broken on a version like that.
Fixes https://github.com/ARM-software/devlib/issues/654
Adding thermal zones and trip points are only done at thermal module
initialization. There is no need for these functions to be public.
Signed-off-by: Morten Rasmussen <morten.rasmussen@arm.com>
The thermal module currently only reads thermal zone ids and allow
temperature reading. The mandatory thermal zone 'type' describes
what the zone is and is therefore quite useful information. This
commit also adds support for reading the current thermal zone
policy and available policies along with a few other properties.
This commit also adds async support to the thermal module.
Signed-off-by: Morten Rasmussen <morten.rasmussen@arm.com>
The sysfs documentation mentions that the value written
to buffer_size_kb ftrace field may be rounded up.
So skip the verify loop on this field.
The case we are worried about, a requested buffer
size that the target cannot fulfill is caught anyway,
as the sysfs write returns with an error that is caught.
Signed-off-by: Christian Loehle <christian.loehle@arm.com>
Using SSHConnection(use_scp=True) lead to an exception:
UnboundLocalError: local variable 'handle' referenced before assignment
This is cause by some (false) cyclic dependency between initialization
of SSHTransferHandle and creation of the SCPClient. We can fix that by
adding a level of indirection to tie together both objects.
Add a Collector for accessing Google's Perfetto tracing infrastructure.
The Collector takes a path to an on-device config file, starts tracing
in the background using the perfetto binary and then stops by killing
the tracing process.
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
Add the "is_running" function that can be used to check if a given
process is running on the target device. It will return True if a
process matching the name is found and Falsa otherwise.
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
Update busybox to version 1.36.1 with defconfig and uniformly built on
Alpine v3.18, statically linked to musl libc.
Binaries were built using lisa-build-asset from LISA project:
lisa-build-asset busybox --native-build
Since we now set the top buffer size to be the same as the devlib buffer
size, this effectively halves the maximum available buffer size that can
be set while using devlib. Whatever size is passed as `buffer_size` will
be allocated twice, even if the top buffer is hardly used at all.
This commit separates them into `buffer_size` and `top_buffer_size`. If
the latter is not passed, the behaviour will not change compared to now.
Fixes: e0c53d09990b5501e493d048a5dce067d8990281
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
Installing busybox sometimes fails with:
cp: /data/local/tmp/bin/busybox: Text file busy
This happens when trying to modify a binary file while a process is
still running (e.g. unclean previous disconnection).
Fix that by using the -f option, which will remove the destination file
first and retry the copy in case of failure.
Only run the minimal amount of commands, as executing a command can be
costly.
In the sequence reset() -> start(), we only need to get the output of
dmesg upon start() to know what part of the log will be ignored
(everything before the call to start()). There is no need to perform
that upon reset() since the sequence:
reset() -> start() -> stop() -> start() -> stop()
\______1________/ \______2________/
is anyway equivalent to:
reset() -> start() -> stop()
\______2________/
So reset() can essentially be a no-op and the actual reset logic lives
in start().
Change the SurfaceFlingerFrameCollector to match activities by prefix
instead of looking for an exact match. This will allow to account for
activities with variable suffixes.
Raise an error if more than one activity matches the provided view.
Show a warning if no activities match the provided view in order to
avoid silently failing.
Suggested-by: Andriani Mappoura <andriani.mappoura@arm.com>
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
FEATURE
Add a convenience property for AndroidTarget to expose Android's
external storage app directory path.
This path is used for some applications (such as Unity games) to
store persistent application data instead of '/data/data'.
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
Lack of return statement in wait() was making it return None instead of
the exit code. Add appropriate return statement in wait() and other
function to ensure return value is not lost.
* Split TransferManager and TransferHandle:
* TransferManager deals with the generic monitoring. To abort a
transfer, it simply cancels the transfer and raises an exception
from manage().
* TransferHandle provides a way for the manager to query the state
of the transfer and cancel it. It is backend-specific.
* Remove most of the state in TransferManager, along with the associated
background command leak etc
* Use a daemonic monitor thread to behave as excpected on interpreter
shutdown.
* Ensure a transfer manager _always_ exists. When no management is
desired, a noop object is used. This avoids using a None sentinel,
which is invariably mishandled by some code leading to crashes.
* Try to merge more paths in the code to uncover as many issues as
possible in testing.
* Fix percentage for SSHTransferHandle (transferred / (remaining +
transferred) instead of transferred / remaining)
* Rename total_timeout TransferManager parameter and attribute to
total_transfer_timeout to match the connection name parameter.
Make BackgroundCommand.__init__() poll all current BackgroundCommands on
the associated connection so they deregister themselves if they are
completed.
This ensures that a BackgroundCommand-heavy application that also does
not close them properly will not accumulate useless instances forever
and leak associated resources like Popen objects.
Instead of loosely tracking the current BackgroundCommand for a
connection in _current_bg_cmds WeakSet attribute, use a normal set and
make the BackgroundCommand deregister itself upon termination.
This allows canceling any outstanding BackgroundCommand when the
connection is closed. Currently, destroying a BackgroundCommand will not
cancel the command but devlib will simply loose track of it, and some
threads will likely fail in the background if they try to use the now
broken connection.
kick_off() implementation had a number of issue:
* Target specific implementation making testing more difficult.
* Not wrapping the command in sh -c lead to blocking behavior if the
command had multiple parts, e.g. "sleep 42; echo foo"
* nohup sometimes writes to stdout, breaking return code parsing in
adb_shell().
These issues are fixed by a generic implementing of kick_off() that
simply delegates to Target.background().
Fixes https://github.com/ARM-software/devlib/issues/623