1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

1154 Commits

Author SHA1 Message Date
Douglas Raillard
926aee1833 utils/android: Remove PATH manipulation
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.
2024-01-10 11:22:54 -08:00
Douglas Raillard
19c51547d1 utils/android: Cleanup android tool detection
* 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.
2024-01-10 11:22:54 -08:00
Douglas Raillard
52485fbaa5 setup.py: Re-add "future" PyPI package
Re-add the "future" PyPI package since it actually contains the "past"
Python package that devlib still uses.
2024-01-09 12:07:57 -08:00
Douglas Raillard
416e8ac40f devlib: Remove Python 2 dead code
Remove code that was used for Python 2 only.
2024-01-09 12:07:57 -08:00
Douglas Raillard
ea4eccf95d setup.py: Remove use of "imp" module
Python 3.12 removed the "imp" module, so replace its use in devlib.
2024-01-09 12:07:57 -08:00
Marc Bonnici
b8bf2abf3b AndroidTarget: Skip ungrantable Android permission
Don't throw an error if attempting to grant a permission that
is not manageable.
2024-01-09 12:06:59 -08:00
Douglas Raillard
9f71c818c4 android: Add adb_port connection setting
Allow specifying the port of the adb server in use.
2024-01-09 12:06:26 -08:00
Douglas Raillard
0579a814f1 android: Add a retry logic for background command PID detection
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.
2024-01-09 12:06:26 -08:00
Douglas Raillard
900531b417 android: Fix background command PID detection
Close the race between the background command and the detection of its
PID by freezing it while we detect the PID, then resuming it.
2024-01-09 12:06:26 -08:00
Metin Kaya
14b4e2069b target: Add helper function to check Android screen's locking state
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>
2024-01-09 07:39:56 -08:00
Metin Kaya
07294251c8 target: Handle dozing case in checking Android screen state
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>
2024-01-09 07:39:56 -08:00
Metin Kaya
2f48b84e6b target: Fix indentation of a misaligned line
Apparently the line has an extra leading space.

Signed-off-by: Metin Kaya <metin.kaya@arm.com>
2024-01-09 07:39:56 -08:00
Elif Topuz
5a1eb4a778 UIBenchJankTests:modification to support Android 12/14 versions
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.
2023-12-12 12:18:53 -08:00
Douglas Raillard
d7d1deedda collector/dmesg: Query systcl kernel.dmesg_restrict
Query systcl instead of checking CONFIG_SECURITY_DMESG_RESTRICT as that
option only provides a default value for the sysctl parameter.

Fixes https://github.com/ARM-software/devlib/issues/653
2023-11-06 08:57:13 -08:00
Douglas Raillard
18d2a343c7 target: Add Target.read_systcl()
Add a getter to query systcl values.
2023-11-06 08:57:13 -08:00
Douglas Raillard
5104002f1a target: Update kernel version parsing for Android GKI kernels
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
2023-11-06 08:54:44 -08:00
Morten Rasmussen
90973cac08 devlib: Make add_trip_point and add_thermal_zone private
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>
2023-10-11 16:30:16 -07:00
Morten Rasmussen
403a0faf93 devlib: Add ThermalZone type and policy support to thermal module
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>
2023-10-11 16:30:16 -07:00
Christian Loehle
9199d8884e ftrace: Do not read-verify buffer_size_kb value
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>
2023-09-21 08:54:50 -07:00
Douglas Raillard
14bb86efad collector/perfetto: Use busybox cat
Use busybox cat instead of system's cat.
2023-09-12 17:04:26 -05:00
Douglas Raillard
1c0223556f utils/ssh: Fix SSHTransferHandle when using SCP
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.
2023-09-12 17:02:09 -05:00
Kajetan Puchalski
9b15807c17 collector: Add PerfettoCollector
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>
2023-09-06 16:48:56 -05:00
Kajetan Puchalski
86fcc11ae1 target: Add is_running()
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>
2023-09-06 16:48:56 -05:00
Douglas Raillard
b5aa065f7b bin: Update busybox
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
2023-08-29 19:18:31 -05:00
Douglas Raillard
35e7288149 utils/android: Use LC_ALL for adb commands
Ensures that adb commands are executed with english locale since we
sometimes match on the output.
2023-08-29 16:55:21 -05:00
Kajetan Puchalski
6b09571859 ftrace: Separate top_buffer_size from buffer_size
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>
2023-08-15 17:47:10 -05:00
Douglas Raillard
1730f69461 target: Avoid intermittent error when installing binary
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.
2023-08-09 16:39:37 -05:00
Douglas Raillard
cf4d3b5f4c collector/dmesg: Avoid unnecessary dmesg command
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().
2023-08-09 16:39:21 -05:00
Douglas Raillard
eb2c7e488b devlib/utils/serial_port: Avoid use of deprecated disutils 2023-08-09 16:39:08 -05:00
Douglas Raillard
306fd0624c devlib/utils/ssh: Avoid using deprecated distutils 2023-08-09 16:39:08 -05:00
Douglas Raillard
fe28e086c2 devlib/host: Remove use of deprecated distutils 2023-08-09 16:39:08 -05:00
Kajetan Puchalski
59ff6100d8 utils.rendering: Fix activity matching
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>
2023-08-09 16:27:26 -05:00
Kajetan Puchalski
be988bb42b target: Expose Android external storage app dir
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>
2023-05-30 17:39:46 -05:00
Douglas Raillard
ac0c39e31a connection: Make BackgroundCommand.wait() return non-None
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.
2023-05-17 10:24:18 -05:00
Marc Bonnici
e6323fc8bf connection/bg_cmd: fix missing use of signal
The signal parameter was being ignored and instead always sending
the KILL signal instead.
2023-05-17 10:24:18 -05:00
Marc Bonnici
7e2399055b connection: update kill command format
The kill applet in the current busybox executable does not support
the `--` syntax therefore remove from the template command.
2023-05-17 10:24:18 -05:00
Douglas Raillard
ddaa2f1621 connection: Rework TransferManager
* 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.
2023-05-05 15:58:20 -05:00
Douglas Raillard
1c5412be2f connection: Remove dead code 2023-05-05 15:58:20 -05:00
Douglas Raillard
e0b1176757 connection: Cleanup TransferManager callback interface
Implement a sane interface avoiding variable positional arguments.
2023-05-05 15:58:20 -05:00
Douglas Raillard
45aebdaca9 connection: Ensure we don't leak too many BackgroundCommand
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.
2023-04-29 13:46:56 -05:00
Douglas Raillard
1239fd922e connection: Make BackgroundCommand deregister itself
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.
2023-04-29 13:46:56 -05:00
Douglas Raillard
069d2322f1 connection: Add BackgroundCommand.__init__(conn)
Add a constructor to BackgroundCommand so that the command knows the
connection it's tied to.
2023-04-29 13:46:56 -05:00
Douglas Raillard
7bdd6a0ade connection: Terminate background commands on close()
Ensure all background commands are terminated before we close the
connection.
2023-04-29 13:46:56 -05:00
Douglas Raillard
27fb0453a3 target: Fix and generalize Target.kick_off()
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
2023-04-29 13:46:46 -05:00
Douglas Raillard
9e0300b9f2 shutils: Fix broken redirections
Redirecting all output to /dev/null needs >/dev/null 2>&1 .

Fix cases where 2>&1 /dev/null was used, and also remove &> that is not
POSIX.
2023-04-29 13:46:46 -05:00
Douglas Raillard
e0c53d0999 ftrace: Set top-level buffer size
trace-cmd start -B devlib -b 42 will set the buffer size for the
"devlib" ftrace instance but will not set the buffer size of the
top-level buffer.

Unfortunately, some events still end up in the top-level buffer
regardless of any configuration such as the "print" event. This can lead
to lost events because the buffer size was too small.

Avoid that by using the buffer size for both top-level and devlib's
instance.
2023-04-18 18:12:26 -05:00
Douglas Raillard
0a910071f8 utils/android: Fix adb_root() exceptions
Ensure adb_root() always raises AdbRootError so that the caller can
catch it reliably. This is especially important since adb_root() failing
is ignored and simply triggers a fallback on using `su`. Android
production builds refuse adb root nowadays, so it's important that adb
root failures are handled well.
2023-04-06 11:05:23 -05:00
Douglas Raillard
4b13ee79eb ftrace: Avoid repeated available events query
FtraceCollector.available_events is not memoized anymore as the set of
events supported by the target can change dynamically (e.g. loading a
kernel module).

This means that calling self.available_events is somewhat expensive, so
avoid doing it in a loop. Instead, save the events in a variable and
reuse it in the function to save a substantial amount of time.
2023-04-06 11:05:04 -05:00
Douglas Raillard
fade6b4247 ftrace: Fix use of named buffer
trace-cmd extract needs -B devlib to be passed, otherwise an empty
buffer will be extracted.
2023-03-13 14:10:17 -05:00
Douglas Raillard
3d2cdd99c5 ftrace: Use named ftrace buffer
Use a buffer named "devlib" instead of using the top-level default
buffer. That will improve interop with other tools trying to collect a
trace at the same time as devlib.
2023-02-03 12:04:51 +00:00