Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Fix BackgroundCommand.send_signal() and add trace-cmd record support #689

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

douglas-raillard-arm
Copy link
Collaborator

@douglas-raillard-arm douglas-raillard-arm commented May 30, 2024

Fixes #645
Supersedes #643

TODO:

  • Add/update docstrings
  • Figure out if moving some init logic for the various subclasses of BackgroundCommand inside the class would simplify the code and avoid BackgroundCommand.from_factory() layer.

@douglas-raillard-arm douglas-raillard-arm changed the title [draft] Fix BackgroundCommand.send_signal() and add trace-cmd record support [Draft] Fix BackgroundCommand.send_signal() and add trace-cmd record support May 30, 2024
@douglas-raillard-arm
Copy link
Collaborator Author

Upon deeper inspection, the from_factory() solution is still better than moving the code from <subclass of Target>._background() to their associated BackgroundCommand subclass, as it typically requires using a bunch of private function/method from the connection type.

@douglas-raillard-arm
Copy link
Collaborator Author

PR rebased

Support sending any signal to background commands, instead of only
supporting properly SIGKILL/SIGTERM/SIGQUIT.

The main issue is figuring out what PID to send the signal to, as the
devlib API allows running a whole snippet of shell script that typically
is wrapped under many layers of sh -c and sudo calls. In order to lift
the ambiguity, the user has access to a "devlib-signal-target" command
that points devlib at what process should be the target of signals:

    # Run a "setup" command, then the main command that will receive the
    # signals
    cmd = 'echo setup; devlib-signal-target echo hello world'
    with target.background(cmd) as bg:
	bg.communicate()

The devlib-signal-target script can only be used once per background
command, so that it is never ambiguous what process is targeted, and so
that the Python code can cache the target PID.  Subsequent invocations
of devlib-signal-target will fail.
Allow using trace-cmd record that continuously dump the trace to disk,
allowing to overcome the buffer size limitations when recording for
extended periods of time.
@douglas-raillard-arm
Copy link
Collaborator Author

@marcbonnici Updated with rework of temp folder management, so it works on old versions of android as well.

I can split that in a separate PR if needed but left it on top for now to ease testing of the combination.

* Make use of Target.make_temp() in Target._xfer_cache_path() to
  deduplicate temp folder creation code

* Introduce Target.tmp_directory attribute for the root of temporary
  files.

* Make Target.tempfile() use Target.tmp_directory

* Rework the Target._resolve_paths() implementations:
    * Target.tmp_directory is set to a default returned by "mktemp -d".
      This way, if "mktemp -d" works out of of the box, all devlib
      temporary files will be located in the expected location for the
      that operating system.

    * Target._resolve_paths() must set Target.working_directory and that
      is checked with an assert. Other directories have defaults based
      on this if _resolve_paths() does not set them.
Also avoid a "None" prefix when no prefix is asked for, and set None as
the default prefix value.

Remove the "devlib-test" default value as make_temp() has nothing to do
with tests.
Align the parameters between the 2 methods:
* Use "None" as default value
* Do not add suffix or prefix if not asked for.
* Separate components with "-" instead of "_"
… keyword-only

Prevent Target argument soup and allow future non-breaking evolutions of the Target
API by restricting what parameters can be positional. Only
"connection_settings", "platform" and "working_directory" can now be
passed positionally, all the other ones must be passed as keyword
arguments.
@douglas-raillard-arm
Copy link
Collaborator Author

Updated with a fix to AndroidTarget._resolve_path() (removed the async code outside of an async function)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BackgroundCommand signals don't propagate through some shell setups
2 participants