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

POC: use of adb_client in xtask/daemon.rs #184

Merged
merged 5 commits into from
Jan 15, 2025
Merged

POC: use of adb_client in xtask/daemon.rs #184

merged 5 commits into from
Jan 15, 2025

Conversation

Mr-Kanister
Copy link
Contributor

@Mr-Kanister Mr-Kanister commented Dec 21, 2024

This regards #166.

The goal of the issue is to replace the current Python script for pushing and running the binaries on the emulator with a more robust Rust implementation.

My current knowledge is not sufficient to continue working on the task, so for now it remains a proof of concept.

With the current changes, the daemon gets pushed and ran on the client via the newly added crate adb_client. I have encountered several problems:

adb_client::ADBServerDevice::shell_command blocks until the respective shell command is finished. This means that background execution of the daemon is only possible via thread. However, standard threads are difficult to terminate, pkill is suboptimal.

An alternative is adb_client::ADBServerDevice::shell, this gets a reader and a writer, which could then be used to terminate the daemon. However, I do not (yet) know how to use it.

Another possibility might be to create a grpc endpoint which can send a death pill to the daemon and thus terminate it cleanly.

There is also another crate that might be interesting: https://docs.rs/adb-client-tokio/latest/adb_client_tokio/

Usage

  • cargo xtask integration-test: broken because of issues above
  • cargo xtask daemon --android: working without background flag.
  • cargo xtask daemon: starting, but daemon not killed after pressing Ctrl+C.
  • cargo xtask client: Unchanged.

Thanks @fhilgers for the many attempts to help.

@Mr-Kanister Mr-Kanister self-assigned this Dec 21, 2024
@Mr-Kanister Mr-Kanister changed the title POC: implement adb_client for xtask/daemon.rs POC: use of adb_client in xtask/daemon.rs Dec 21, 2024
@fhilgers
Copy link
Collaborator

fhilgers commented Jan 8, 2025

State:

cargo xtask integration-test: launches the daemon, waits a second, launches the tests and stops the daemon gracefully
cargo xtask daemon --android: launches the daemon, exits gracefully on ctrl-c or newline
cargo xtask client --android: launches the client, exits gracefully on ctrl-c or newline

@fhilgers fhilgers marked this pull request as ready for review January 8, 2025 04:28
@fhilgers fhilgers self-assigned this Jan 8, 2025
@fhilgers fhilgers linked an issue Jan 8, 2025 that may be closed by this pull request
Mr-Kanister and others added 4 commits January 15, 2025 09:38
The commit implements both a server and a client process communicating over stdin and stdout.
Adb is the established way of launching and controlling processes on an android machine.
Stdin and Stdout is chosen, because thats the way to communicate over an adb shell.

The server process on android is started with a json request that specifies what process it should run:

```json
{
  "command": "/data/local/tmp/backend-daemon",
  "args": [],
  "env": { "RUST_LOG": "trace" },
  "root": true
}
```

It sends the logs over stdout in the following format:

{
  "Stdin": "...",
  "Stderr": "...",
  "InternalError": "..."
}

The server exits when the process stops, or when the client on the host sends `"Exit"` over stdin.

The client/host process requires a specification in the following format:

```json
{
  "runner_path": "./target/x86_64-android-linux/release/runner-server",
  "args": [],
  "env": { "RUST_LOG": "trace" },
  "root": true
}

Also, it takes a path to the executable as last argument, to be compatible with `cargo run` and `cargo test`.

The client connects to the android device via adb, pushes the executable and the server.
Afterwards it executes the server over adb with the appropriate request.

Signed-off-by: Felix Hilgers <[email protected]>
Signed-off-by: Felix Hilgers <[email protected]>
Signed-off-by: Felix Hilgers <[email protected]>
@fhilgers fhilgers merged commit 02f6c77 into dev Jan 15, 2025
8 checks passed
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.

Integration Testing 2
2 participants