1
0
mirror of https://github.com/ARM-software/devlib.git synced 2024-10-05 18:30:50 +01:00
Commit Graph

1170 Commits

Author SHA1 Message Date
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
Ibrahim Hassan
e012b175c6 module/cgroups2: Added utilisation of the 'LinuxTarget' interface.
Replaced all references to devlib.Target with devlib.LinuxTarget to correctly
utilise appropriate interface.
Also added relevant functionality to corectly
create the root directories of the CGroup hierarchies, handling any error that
occurs in that case.
2023-02-03 12:04:34 +00:00
Ibrahim Hassan
5ea63490a9 module/cgroups2: Replaced references to 'lisa' to 'devlib' 2023-02-03 12:04:34 +00:00
Ibrahim Hassan
d7b38e471d module/cgroups2: Add new CGroups management module
Handles both V1 and V2 CGroups transparently with an API matching
CGroup V2 semantics.

Also handles the CGroup delegation API provided by systemd.
2023-02-03 12:04:34 +00:00
Marc Bonnici
7f778e767d target: Ensure max_async is used during connect method
The value for `max_async` when creating a target was being ignored
if a connection was not established as part of the __init__ method.
Save this value for use via `connect` if called directly.
2023-02-03 12:04:01 +00:00
Douglas Raillard
93ada9762d devlib: Remove "future"
Remove the "future" dependency as devlib does not support Python 2
anymore.

Also remove the "from __future__ import division" as this is the default
in Python 3.
2023-01-19 11:38:11 +00:00
setrofim
111aa327ce Import quote() form shlex rather than pipes
pipes module is deprecated since 3.11, and quote() has been available in
shlex since 3.3.
2022-11-24 10:55:22 +00:00
setrofim
cc3498d315 Mitigate CVE-2007-4995
Prevent potential directory path traversal attacks (see
https://www.trellix.com/en-us/about/newsroom/stories/research/tarfile-exploiting-the-world.html)
2022-11-18 11:57:41 +00:00
Douglas Raillard
678822f9e4 utils/misc: Cleanup check_output()
* Remove check_output_lock as the issue has been fixed in Python 3.4
* Use Popen process as a context manager. Technically,
  Popen.communicate() already achieves those but the context manager
  will ensure this is done even if an exception happens at any point.
2022-08-22 09:32:11 +01:00
Douglas Raillard
be734140b3 utils/android: Make AdbConnection.active_connections thread safe
Add a lock to serialize access to the dictionary.
2022-08-22 09:32:11 +01:00
Douglas Raillard
b988e245d9 utils/android: Fix AdbConnection.adb_root()
adb_root() restarts the server, leading to aborting commands ran by
other connections and also apparently leading to command hanging in some
situations.

Therefore, only allow adb_root() when there is only one connection
active. That should not be a big issue as this is typically called by
the first connection ever made when the Target is created.
2022-08-22 09:32:11 +01:00
Douglas Raillard
b7ef2dc2e0 devlib.target: Fix AndroidTarget unpickle
Fix __setstate__ to call super().__setstate__ in order to handle the
generic part of the deserialization.
2022-08-17 10:53:43 +01:00
Douglas Raillard
492284f46d module/cpufreq: Fix typo
Fix per-cpu/global cpufreq governor tunable setting by replacing a
"pass" into a "continue".

Also name some futures to improve error reporting.
2022-08-09 14:02:17 +01:00
Douglas Raillard
fefdf29ed8 utils/asyn: Add memoize_method() decorator
Add a memoize_method decorator that works for async methods. It will not
leak memory since the memoization cache is held in the instance
__dict__, and it does not rely on hacks to hash unhashable data.
2022-07-28 14:40:15 +01:00
Douglas Raillard
0ea9c73ec0 module/cpufreq: Fix async use_governor()
use_governor() was trying to set concurrently both per-cpu and global tunables for
each governor, which lead to a write conflict.

Split the work into the per-governor global tunables and the per-cpu
tunables, and do all that in concurrently. Each task is therefore
responsible of a distinct set of files and all is well.

Also remove @memoized on async functions. It will be reintroduced in a
later commit when there is a safe alternative for async functions.
2022-07-28 14:40:15 +01:00
Douglas Raillard
2c4b16f280 devlib: Use async Target API
Make use of the new async API to speedup other parts of devlib.
2022-07-28 14:40:15 +01:00
Douglas Raillard
18ab9f80b0 target: Expose Target(max_async=50) parameter
Allow the user to set a maximum number of conrruent connections used to
dispatch non-blocking commands when using the async API.
2022-07-28 14:40:15 +01:00
Douglas Raillard
92f58e4e7a target: Enable async methods
Add async variants of Target methods.
2022-07-28 14:40:15 +01:00
Douglas Raillard
bdf8b88ac7 utils/async: Add new utils.async module
Home for async-related utilities.
2022-07-28 14:40:15 +01:00
Douglas Raillard
1da174a438 setup.py: Require Python >= 3.7
Require Python >= 3.7 in order to have access to a fully fledged asyncio
module.
2022-07-28 14:40:15 +01:00
Douglas Raillard
3c9804a45b setup.py: cleanup dependencies in setup.py
Remove dependencies that are ruled out due to the current Python minimal
version requirement.
2022-07-28 14:40:15 +01:00
Douglas Raillard
3fe105ffb7 target: Make __getstate__ more future-proof
Remove all the tls_property from the state, as they will be recreated
automatically.
2022-07-28 14:40:15 +01:00
Douglas Raillard
9bd76fd8af target: Fix Target.get_connection()'s busybox
The conncetion returned by Target.get_connection() does not have its
.busybox attribute initialized. This is expected for the first
connection, but connections created for new threads should have busybox
set.
2022-07-28 14:40:15 +01:00
Douglas Raillard
ef9384d161 utils.misc: Make nullcontext work with asyncio
Implement __aenter__ and __aexit__ on nullcontext so it can be used as
an asynchronous context manager.
2022-07-28 14:40:15 +01:00
Kajetan Puchalski
ff2268b715 module/cpuidle: Add listing & setting governors
Add support for listing the currently available idle governors and
setting the currently used one through sysfs.
2022-07-19 09:33:36 +01:00
Kajetan Puchalski
5042f474c2 module/cgroups: Skip disabled cgroup controllers
Currently the cgroups module will pull all available controllers from
/proc/cgroups and then try to mount them, including the disabled ones.
This will result in the entire mount failing.

Lines in /proc/cgroups ending in 0 correspond to disabled controllers.
Filtering those out solves the issue.
2022-07-19 09:33:23 +01:00
Marc Bonnici
a585426924 android: Don't error if ADB is already running as root
With recent versions of adb, adb root can fail if the
daemon is already running as root.

Check the raised error message for this case and avoid
raising an error in this scenario.
2022-06-22 11:23:15 +01:00
Marc Bonnici
1196e336a5 version: bump minor version number
Re-bump the minor version to prepare for dropping
Python < 3.7 support.
2022-05-24 17:50:01 +01:00
Marc Bonnici
f525374fbb version: perform additional revision release
Revert the minor version number to allow release of additional
revision release to fix some bugs that made it into the previous
release.
2022-05-24 17:50:01 +01:00
Douglas Raillard
42e62aed57 target: Fix AndroidTarget pickling
Avoid pickling the "clear_logcat_lock". Instead, discard the attribute
and re-initialize it anew.
2022-05-24 10:39:31 +01:00
Douglas Raillard
f5cfcafb08 shutils: Remove shebang
Since shutils should be run using busybox shell anyway, remove the
shebang.
2022-05-24 10:37:17 +01:00
Douglas Raillard
7853d2c85c target: Run shutils.in in busybox
Ensure shutils.in runs in a busybox shell.
2022-05-24 10:37:17 +01:00
Douglas Raillard
a9fcc75f60 collector/dmesg: Fix dmesg_out property
When no entry has been recorded by the collector, return an empty string
rather than returning the full dmesg log.

Also fix get_data() that would fail try to add None + '\n' if dmesg_out
property returns None.
2022-05-18 15:21:18 +01:00
Douglas Raillard
cd8720b901 module/cgroups: Fix move_tasks()/move_all_tasks_to()
Both move_all_tasks_to() and move_tasks() take a list of grep patterns
to exclude.

It turned out that move_all_tasks_to() was calling move_tasks() with a
string instead of a list, leading to broken quoting.

Fix that by passing the pattern list to move_tasks() and let
move_tasks() add the "-e" option in front of it. Also add a
DeprecationWarning in move_tasks() if someone passes a string instead of
an iterable of strings.
2022-05-17 19:04:29 +01:00
Marc Bonnici
03569fb01f version: Bump minor version number
This next release will drop support for Python < 3.7
therefore bump to a dev tag of the next minor version.
2022-04-29 19:38:50 +01:00