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

1030 Commits

Author SHA1 Message Date
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
Marc Bonnici
22f53f117e version: Bump revision number 2022-04-29 19:38:50 +01:00
Douglas Raillard
e0abb9db48 collector/dmesg.py: Allow nesting DmesgCollector
Rather than systematically clearing the buffer on reset(), record the
timestamp of the last entry and use it to filter-out old entries in
DmesgCollector.entries property.

This also allows detecting if the ring buffer has ran out of memory, or
if something has cleared the buffer while collecting, leading to missing
entries.
2022-04-29 13:59:24 +01:00
Vincent Donnefort
c29d386e81 target: Allow relative path for for push/pull
Currently, it is not possible to push/pull files with a relative path when
the destination doesn't exist. This is due to the basename resolution. Fix
this behaviour.
2022-04-28 13:22:25 +01:00
Douglas Raillard
adad59fdba target: Add Target.makedirs(as_root=False) parameter
Add as_root parameter to Target.makedirs()
2022-04-28 12:55:23 +01:00
Douglas Raillard
48329b7891 target: Add exception message when module fails to load
Log the exception message when a target module fails to load.
2022-04-28 12:55:23 +01:00
Douglas Raillard
728b59ad7e utils/ssh.py: Make SshConnection._background() more robust
Raise a better exception when e.g. sudo command is not found.
2022-04-28 12:55:23 +01:00
Douglas Raillard
2b38548463 connection: Use -- in kill command
Separate options and PGIDS with -- in kill commands as otherwise, kill
seems to be confused.
2022-04-28 12:55:23 +01:00
Douglas Raillard
bdb04aa8d0 ftrace: Detect tracefs mount point
Change default FtraceCollector(tracing_path=...) to None, and
auto-detect mount point when None is given.

Also expose an FtraceCollector.find_tracing_path() method so that user
code can also access this path without having to instantiate an
FtraceCollector.
2022-04-22 18:29:53 +01:00
Douglas Raillard
8f80d8a5ee shutils.in: De-hardcode tracefs location
Detect tracefs mount point rather than hardcoding its path.
2022-04-22 18:29:53 +01:00
Douglas Raillard
ff599dfbb6 shutils.in: Simplify the dispatcher
Check that the function exists and then run it, to avoid endless
copy-pasting.

Also call it with "$@", which will achieve proper CLI params forwarding
unlike "$*" which will not.
2022-04-22 18:29:53 +01:00
Douglas Raillard
00a5bcb377 shutils.in: Add get_fs_mount_point() function
Allow getting the mount point of a given filesystem. This is useful to
detect the location of e.g. tracefs
2022-04-22 18:29:53 +01:00
Marc Bonnici
fffa040792 target/xfer: Fix detection of files with restricted permissions
The command used to detect the presence of a filepath can return
the wrong value if only accessible by the superuser.
Pass the `as_root` parameter to the detection function to ensure
that files that are to be pulled with elevated permissions are
also queried with elevated permission.
2022-04-06 18:41:09 +01:00
Vincent Donnefort
7d6ed2dd8a utils.android: force as_root=False when connected_as_root
Some Android devices do not have 'su'. But if they are already
rooted, there's no reason to fail. Circumvent this scenario by never
using 'su' for device already rooted.
2022-04-05 12:55:20 +01:00
Douglas Raillard
f6bbd2c187 modules/sched: Use correct permissions to read debugfs
Use target.list_directory(as_root=target.is_rooted) instead of doing it
as a normal user for paths in /sys/kernel/debug. Since this
list_directory() call can be used with multiple path, we do not force
as_root=True but we increase the chance of it working.
2022-04-05 12:54:59 +01:00
Douglas Raillard
a65189f028 target: Replace Target.__copy__ by __getstate__
__getstate__ is also used by the copy module, but allows pickling the
class as well. This is useful when using the multiprocessing API, which
requires pickling the Target object to send it to the new process.
2021-11-03 10:56:09 +00:00
Marc Bonnici
77f0b1f06d docs: Add readthedocs config and requirements.txt
The default versions used for sphinx and docuilts on
readthedocs are no longer compatible. Explicitly list
the package versions that should be used when building
the documentation.
2021-10-28 11:03:08 +01:00
Douglas Raillard
b4c76007c8 ftrace: Do not memoize FtraceCollector.available_events
ftrace events can be added and removed dynamically by kernel modules, so
they cannot be memoized.
2021-10-27 11:56:23 +01:00
Douglas Raillard
3f92d92a3f ssh: Reduce number of opened channels
SSH servers seem to have a maximum number of opened channels, after
which paramiko will raise an exception:

    Could not open an SSH channel: ChannelException(2, 'Connect failed')

Memoizing the SFTPClient object based on the timeout setting leads to
many opened sessions, since the timeout is typically adjusted, e.g. to
match the size of the file when pulling an ftrace trace.dat file.

Solve that by memoizing the SFTPClient based only on the connection
object, with a maximum number of 1 cached object, and update its timeout
setting inplace.
2021-10-15 16:10:02 +01:00
Douglas Raillard
0e0417c6b3 target: Fix undefined function
Remove references to non-existent dst_path_exists() function in
target.py
2021-10-11 14:42:25 +01:00
Douglas Raillard
e979bafb50 target: Speedup Target.write_value()
Avoid an execute() by doing the check in the same command. This also
allows to return early if the write is fast, and to extend for longer if
the write is slow. The speed at which you can observe a write in sysfs
depends on the backing kernel handlers, so there is a wide variety of
situations.

Also, make a more fine grained error detection by allowing the write
itself to fail, which can happen when writing invalid values to sysfs.
2021-10-08 18:22:04 +01:00
Douglas Raillard
0c1878786b Target.execute(): Add .returncode and .output exception attributes
Add Target{Stable,Transient}CalledProcessError exceptions, with an
.returncode and .output attributes, raised by Target.execute(),
mirroring subprocess.CalledProcessError.

This is very useful in client code that uses "exit N" to signal an
abnormal condition, and then inspects the output to find out more.
2021-10-08 18:22:04 +01:00
Douglas Raillard
ff57e785f8 exception: Deal with missing _message attribute
Allow subclasses of DevlibError to not have a _message attribute, in
which case it falls back on str(self), just as when _message is None.
2021-10-08 18:22:04 +01:00
Douglas Raillard
f1c8ca1a66 utils.android: Separate stdout and stderr by newline
Following what the other connections are doing, make the android
connection separate stdout and stderr by a newline.
2021-10-08 18:22:04 +01:00
Douglas Raillard
b719808ef2 target: Add Target.pull(via_temp=False) parameter
Allow pulling a file via a temporary location on the target, to
side-step performance issues when pulling big files from sysfs.
2021-10-08 13:14:42 +01:00
Douglas Raillard
477e82c444 target: Open the possiblity for optimizing multi-source push/pulls 2021-10-08 13:14:42 +01:00
Douglas Raillard
173df18f29 target: Factorize push/pull path resolution
Handle in one place the decision of what is the real destination of each
file in push/pull operations.

The following can now be assumed by the connection:

    * The destination does not exist.
    * The folder containing the destination does exist.

This ensures consistent errors and behaviors across all connection
types, at the cost of:

    * At least an extra execute() per source (up to 2 if the destination
      is a file that needs to be removed to make room).
    * For now, globbing will lead to a separate request for each file,
      rather than a merged one. This is because the destination of each
      source is prepared so that the connection will not have any
      interpretation work to do.
2021-10-08 13:14:42 +01:00
Douglas Raillard
79be8bc5ad ssh: Memoize the SshConnection._get_sftp()
Since we have the guarantee to have a different SshConnection per
thread, we can memoize paramiko's SFTPClient. This provides a great
performance boost.
2021-10-08 13:14:42 +01:00
Douglas Raillard
55d914bf93 target: Fix typo in Target._prepare_xfer 2021-10-08 13:14:42 +01:00
Douglas Raillard
528d3d4e0f target: Fix fallback path for kernel config loading
The main path is reading /proc/config.gz. If it does not exists, the
following paths are tested:
'/boot/config', '/boot/config-$(uname -r)'

Since the 2nd path contains a command to be executed, remove quoting of
the path when using "cat".
2021-09-30 13:20:33 +01:00
Peter Collingbourne
d6a2ed8247 Teach the script to understand "dumpsys power" output from newer Android versions.
Newer Android versions do not include any of the attributes that we're
currently looking for in the "dumpsys power" output. Instead they have
"mWakefulness" which can either be "Asleep" or "Awake". Adjust the regex to
look for that attribute as well.
2021-09-28 09:34:16 +01:00
Douglas Raillard
917800ffa6 collector: ftrace: Use trace-cmd start --cmdlines-size
Use --cmdlines-size option rather than setting the file manually.
2021-09-01 17:38:49 +01:00
Douglas Raillard
5671b49c2f collector: ftrace: Use trace-cmd start -C
Use -C to set the clock rather than writing manually to the file.
2021-09-01 17:38:49 +01:00
Douglas Raillard
27616813ea collector: ftrace: Use trace-cmd start -b
Avoid manually setting the buffer size since trace-cmd start can do it
directly.
2021-09-01 17:38:49 +01:00
Douglas Raillard
cdceba59ba bin: Update trace-cmd to 2.9.1
Build of commit 2191498dc35d629003591f727b604120fabbe02d, which is a few
commits after 2.9.1 release. This version has been in use in LISA for
months now so it should work well.
2021-09-01 17:38:49 +01:00
Douglas Raillard
301d43d140 module/cgroups: Fix exclude pattern quoting
Use shlex.quote() rather than "manual" quoting.
2021-08-19 18:32:46 +01:00
Douglas Raillard
8b92f5530a connection: Add BackgroundCommand.communicate()
Add a communicate() method in the style of Popen.communicate().

Unlike Popen.communicate, it will raise a CalledProcessError if the
command exit with non-zero code.
2021-08-19 18:32:33 +01:00
Douglas Raillard
ad5a97afcc connection: Add ParamikoBackgroundCommand.cmd attr for diagnostic
Add a "cmd" attribute for better exception messages.
2021-08-19 18:32:33 +01:00
Douglas Raillard
e231cb0849 host: Fix PopenBackgroundCommand stdin
The Popen object created for background command currently has no stdin
pipe, preventing the user from writing to it (it will be None instead of
being a file-like object).

Fix that by passing stdin=subprocess.PIPE to Popen constructor.
2021-08-18 16:52:48 +01:00
Douglas Raillard
47280f63da connection: Fix race in ParamikoBackgroundCommand API
When using an ssh background command, the data is read from paramiko as
it comes and stored in a buffering pipe by a thread. Currently, the
ParamikoBackgroundCommand API will report the command as having
completed as soon as paramiko reports it. This however does not
necessarily mean that the pipe-filling thread is finished copying the
streams, and the client will end up assuming there is no more data to
read even though it's not the case.

Fix that by ensuring that when poll() returns non-None, the output
streams are ready to be drained.
2021-08-18 16:52:18 +01:00
Douglas Raillard
a6dd4ddbce ssh: Flush writing end of pipes before closing
When running a background command, ensure the redirection thread flushes
the writing end of the pipe before closing it.
2021-08-18 16:52:18 +01:00