Installation
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install developer-device-platform-device-run@skills-hub
Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled).
Plugin developer-device-platform-device-run v1.0.0 follows the Agent Plugins spec.
gh skills-hub install developer-device-platform-device-run Don't have the extension? Run gh extension install samueltauil/skills-hub first.
Download and extract to your repository:
.github/skills/developer-device-platform-device-run/ Extract the ZIP to .github/skills/ in your repo. The folder name must match developer-device-platform-device-run for Copilot to auto-discover it.
Skill Files (9)
SKILL.md 11.2 KB
---
name: developer-device-platform-device-run
description: >-
Runs automated, non-interactive jobs on remote Android devices with Developer
Device Platform (DDP) Device Run using `gcloud beta device-run sessions`:
native Android executables or shell scripts (for example CLI tools, custom
runners, test harnesses or benchmarks) and
Android instrumentation tests, on one or many devices, then waits for
completion and collects per-device outputs and logs. Use when running a
binary or test suite on remote devices without an interactive connection.
Don't use it for interactive device reservations, adb tunnels or screen
streaming (use developer-device-platform-basics), or for local devices.
metadata:
version: "1.0.0"
category: CloudInfrastructureAndServices
---
# Developer Device Platform: Device Run
Device Run executes a job on remote DDP devices and returns its artifacts (logs,
pulled files) to a Cloud Storage bucket. One session fans out to one job per
requested device.
> [!WARNING]
> Developer Device Platform (DDP) is currently in Preview. The
> `gcloud beta device-run` commands might change without notice.
## When to use this skill
The user wants to... | Use
:--------------------------------------------------------- | :--
Run a native binary or shell script on remote devices | This skill (`android-executable`)
Run an Android instrumentation test APK on remote devices | This skill (`instrumentation`)
Reserve a device, connect with adb, stream the screen | `developer-device-platform-basics`
Extend or cancel an interactive device lease | `developer-device-platform-basics`
Work with a device connected over USB | Neither (not DDP)
The setup below is complete; this skill doesn't depend on another skill for
authentication, project selection or API enablement.
### Requests this skill does not handle
For interactive use (reserve a device, adb, screen streaming, leases):
* **If `developer-device-platform-basics` is installed:** do not submit a
Device Run session; switch to `developer-device-platform-basics`, and note
that interactive reservations are also billed to the active project.
* **If `developer-device-platform-basics` is not installed:** reply in a
single message **without calling any tools** (no commands, searches, file
reads or scheduling), then stop:
1. Say that Device Run is for non-interactive batch jobs, so you will not
submit a Device Run session.
2. Point the user to an interactive Device Streaming reservation with the
`developer-device-platform-basics` skill (or
https://docs.cloud.google.com/device-streaming/docs/overview.md.txt),
and suggest installing the skill.
3. Warn that an interactive reservation is also billed to the active
Google Cloud project.
### Keep answers fast
Prefer this skill and `gcloud beta device-run ... --help` over broad web
searches for Device Run syntax. If `gcloud` or the `beta` component is not
installed, fall back to the official documentation at
https://docs.cloud.google.com/developer-device-platform/device-run.md.txt and
https://docs.cloud.google.com/sdk/gcloud/reference/beta/device-run. For dry
runs, show the commands instead of running them.
## Usage Attribution
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
MUST read and follow the instructions in
[Usage Attribution](references/attribution.md).
## Setup
Run these checks once per environment. Do not assume tools are installed, and
do not install or update software without the user's approval.
1. **gcloud CLI**: Check that gcloud is installed and has Device Run commands:
```bash
gcloud --version
gcloud beta device-run sessions submit android-executable --help >/dev/null
```
If gcloud is missing, point the user to
https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt. If the `beta`
component or the Device Run commands are missing, **ask the user** before
running `gcloud components install beta` or `gcloud components update`.
2. **Authentication**: Check the active account. On a Compute Engine or other
remote VM, the active account may be the VM's default service account
(`...@...iam.gserviceaccount.com`), which often lacks the scopes Device Run
and billing calls need (`No service account scopes specified`). If there is
no active account, or only such a service account, ask the user to sign in.
`--update-adc` also updates Application Default Credentials in the same
flow; add `--no-launch-browser` in SSH or remote terminals:
```bash
gcloud auth list --filter=status:ACTIVE --format="value(account)"
gcloud auth login --update-adc
```
3. **Project**: Use the user's active project, or the one they name. Never
hardcode a project, and don't change the active project without asking.
```bash
export PROJECT_ID=$(gcloud config get project)
# Only if the user asks to switch:
gcloud config set project PROJECT_ID
```
4. **Billing**: Device Run is billed to the project. Check that billing is
enabled; if it isn't, stop and tell the user.
```bash
gcloud billing projects describe "${PROJECT_ID}" \
--format="value(billingEnabled)"
```
5. **Enable the Device Run API** (if not already enabled; ask first):
```bash
gcloud services enable devicerun.googleapis.com --project="${PROJECT_ID}"
```
6. **IAM roles**: The user needs `roles/devicerun.admin`,
`roles/serviceusage.serviceUsageConsumer` and `roles/viewer` on the
project. To read inputs from a bucket in another project, grant the DDP
service agent `roles/storage.objectViewer` on that bucket (see
https://docs.cloud.google.com/developer-device-platform/device-run/share-storage.md.txt).
7. **Bucket**: Sessions store inputs and outputs in Cloud Storage. Without
`--bucket-name`, gcloud uses or creates `gs://${PROJECT_ID}-devicerun`.
For project IDs that contain `:`, `.` or `google`, gcloud replaces them
(with `-`, `-` and `elgoog`) before adding `-devicerun`; read the actual
bucket from the `Result files` URI printed by `submit` or `describe`. A
bucket named explicitly with `--bucket-name` MUST already exist. Pass the
bucket name only (no `gs://`, no path). Inputs and outputs under
`gs://<bucket>/automation/` are kept until you delete them or a Cloud
Storage lifecycle rule expires them, and storage is billed meanwhile.
## Core workflow
1. **Pick devices.** Users usually name devices the way they are sold ("Pixel
10", "Galaxy S22"), while `--device` needs a catalog ID such as
`frankel-36` (codename + Android API level). Resolve names to IDs from the
live catalog with
[device_selection.md](references/device_selection.md); never guess an ID
from memory. If a device is offered on several Android versions and the
user didn't name one, list the versions, recommend one, and let the user
pick one, several (one job each) or all; never pick silently. Before
submitting, show the user the resolved ID, the device name and the Android
version, and call out any other choice you made for them (physical vs
virtual, variant).
2. **Stage inputs.** `--executable`, `--test`, `--target-app` and the source
side of `--other-files-to-push` accept `gs://` paths or local paths. Local
files are uploaded automatically into a fresh
`automation/inputs/<timestamp>/` folder, so prefer local paths for files
that change between runs (scripts, freshly built binaries). Upload large,
reused files (models, datasets) to the bucket once and reference them by
`gs://` path.
3. **Confirm cost.** **Explicit user confirmation required.** Device Run
sessions are billed to the active Google Cloud project. Before submitting,
tell the user the project (`${PROJECT_ID}`), the devices, the number of
jobs, and the timeout, warn that this incurs charges, and STOP until they
approve. Include this billing warning in **every** answer that shows a
submit command, even when you only explain the steps or the user will run
the command themselves.
4. **Submit.** Pick the submit type:
* Native executable or shell script: see
[android_executable.md](references/android_executable.md).
* Instrumentation test APK: see
[instrumentation.md](references/instrumentation.md).
* Same binary with several configurations (different flags, inputs or
environment variables) per device: see
[multi_config_runs.md](references/multi_config_runs.md).
5. **Wait.** For runs longer than a few minutes, submit with `--async` and
follow [session_lifecycle.md](references/session_lifecycle.md).
6. **Collect results.** Download and map artifacts to devices with
[results.md](references/results.md).
7. **Report** one row per device: device ID, job folder (`job-NNN`), result,
key outputs, and the `gs://` path of the session folder. Call out failed,
timed-out or cancelled jobs explicitly instead of dropping them.
## Rules
* **Always set the timeout.** `--executable-timeout` (or
`--instrumentation-timeout`) defaults to `5m`; the valid range is `1m` to
`3h`. Estimate the run time and set it explicitly.
* **Arguments are comma-separated.** Each element of `--executable-args`
becomes one argument. Rewrite space-separated command lines. If a value
contains a comma, use the `^SEP^` prefix (see
[android_executable.md](references/android_executable.md)).
* **No shell in the direct call.** With a binary as `--executable` there is no
shell: set environment variables with `--executable-env-vars`, not `export`.
* **Do not overwrite shared inputs.** DDP fetches inputs when a job starts.
Never overwrite a `gs://` script or binary that a pending session uses; use
local paths (auto-uploaded) or a unique `gs://` path per run.
* **Label sessions** with `--labels` (for example `purpose=smoke,build=1234`)
so they are easy to find later.
* **Poll politely.** Never poll in a tight loop; poll every 30 to 60 seconds
and report progress (see
[session_lifecycle.md](references/session_lifecycle.md)).
* **Cancel on request.** If the user wants to stop, cancel the session (see
[session_lifecycle.md](references/session_lifecycle.md)) and tell the
user it was cancelled.
* **Do not use the Device Streaming API** (`devicestreaming.googleapis.com`,
`deviceSessions`) to run batch jobs; that is for interactive leases.
## Reference index
* [device_selection.md](references/device_selection.md): map device names
such as "Pixel 10" to catalog IDs, OS versions, physical vs virtual.
* [android_executable.md](references/android_executable.md): flags, direct
call, shared libraries, script as executable.
* [instrumentation.md](references/instrumentation.md): APK tests, sharding,
test targets.
* [session_lifecycle.md](references/session_lifecycle.md): sync vs async,
wait, describe, cancel, status and result types.
* [results.md](references/results.md): bucket layout, job-to-device mapping,
logs.
* [multi_config_runs.md](references/multi_config_runs.md): run
the same binary with several configurations per device.
* [troubleshooting.md](references/troubleshooting.md): common failures.
android_executable.md 3.8 KB
# Android executable sessions
`gcloud beta device-run sessions submit android-executable` runs a native
Android executable (or a `/system/bin/sh` script) on one or more devices. A job
is created for each device passed to `--device`.
## Flags
For the full, current flag list see
https://docs.cloud.google.com/developer-device-platform/device-run/android-executable.md.txt
and `gcloud beta device-run sessions submit android-executable --help`. The
flags you need most often:
* `--device=ID[,ID...]` (required): catalog IDs; one job per device.
* `--executable=PATH` (required): binary or script, `gs://` or local path.
* `--executable-args=ARG,...`: comma-separated; each element is one argument.
* `--executable-env-vars=K=V,...`: environment variables for the process.
* `--executable-timeout=DURATION`: `1m` to `3h`, **default `5m`**.
* `--other-files-to-push=SRC=DEST,...` and `--paths-to-pull=PATH,...`.
## Direct call (binary as the executable)
Use this when every device runs one configuration.
```bash
gcloud beta device-run sessions submit android-executable \
--project="${PROJECT_ID}" --location=global \
--device="pa3q-35,m2q-36" \
--executable=gs://my-bucket/bin/my_runner \
--executable-args="--input=/data/local/tmp/input.dat,--threads=4,--out=/data/local/tmp/out.json" \
--other-files-to-push="gs://my-bucket/data/input.dat=/data/local/tmp/input.dat" \
--paths-to-pull="/data/local/tmp/out.json" \
--executable-timeout=30m \
--labels=purpose=smoke \
--async
```
Notes:
* Push files under `/data/local/tmp`, and have the binary write outputs there
so `--paths-to-pull` can collect them.
* `--executable-args` applies to the whole session: every device gets the same
arguments. For several configurations, submit several sessions or use a
wrapper script ([multi_config_runs.md](multi_config_runs.md)).
### Arguments containing commas
Prefix the value with `^SEP^` to choose another separator:
```bash
--executable-args="^;^--shape=1,224,224,3;--threads=4"
```
### Shared libraries
Push `.so` dependencies next to the binary and point the loader at them. In a
direct call DDP starts the binary itself, not through a shell, so `export
LD_LIBRARY_PATH=...` (or any shell syntax) cannot be used. Set the variable
with a flag instead:
```bash
--other-files-to-push="gs://my-bucket/lib/libfoo.so=/data/local/tmp/libfoo.so" \
--executable-env-vars="LD_LIBRARY_PATH=/data/local/tmp"
```
Libraries opened at runtime with `dlopen` (for example GPU delegates) also need
`LD_LIBRARY_PATH`, even though the binary starts without them. If one is
missing, the binary often falls back silently (for example from GPU to CPU)
instead of failing. After the run, confirm the library actually loaded by
searching the job's `output.log` (if present), a pulled stdout log file, or
`logcat.txt` for the library name or the log line it prints when it
initializes, and tell the user how you checked. (During Preview, `output.log`
may be missing; see [results.md](results.md).)
When answering a shared-library question, always tell the user:
1. Which `.so` files are pushed and where (`--other-files-to-push`).
2. That `LD_LIBRARY_PATH` is set with `--executable-env-vars` **because a
direct call has no shell, so `export` does not work**. (Inside a wrapper
script, `export` is fine.)
3. How to confirm any `dlopen`-loaded library was really used.
## Script as the executable
Pass a `/system/bin/sh` script as `--executable` when the run needs several
steps (several configurations, setup, device info, custom output layout). Push
the real binary with `--other-files-to-push`, and in the script:
* `chmod 755` the pushed binary before running it.
* `export` environment variables (the script has a shell).
* Write all outputs into one directory and pull that directory.
See [multi_config_runs.md](multi_config_runs.md) for a template.
attribution.md 1.9 KB
# Usage Attribution
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command with
this skill, follow these usage attribution instructions. Tag every command you
execute directly in the terminal so usage can be attributed. The tag identifies
only the skill and its version; it carries no user data.
- **`gcloud` CLI Commands**: Prefix every `gcloud` invocation, whatever the
subcommand, with the metrics environment variable. Set it inline on each
command because shell state may not persist between commands:
```bash
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:developer-device-platform-device-run)" \
gcloud <command> [flags]
```
Do not use `gcloud config set` for this: it would persist beyond the current
task and mislabel unrelated usage.
- **Direct HTTP, REST, and MCP Requests**: On direct HTTP calls to Google
Cloud APIs (for example with `curl`) or HTTP requests to a remote MCP
server, include
`agent-skills/1.0 (skill:developer-device-platform-device-run)` in the
`User-Agent` header. If a `User-Agent` header is already specified, append
this string to the end of it rather than overwriting existing `User-Agent`
data — the collection pipeline parses the `agent-skills/<version>` and
`skill:<name>` tokens, so any rewording breaks attribution:
```
User-Agent: <existing_user_agent> agent-skills/1.0 (skill:developer-device-platform-device-run)
```
- **Constraint for Generated Code**: The tracking prefix is strictly for
commands you execute directly in the terminal. Do NOT include this tracking
prefix in generated scripts, Terraform templates, or code provided to the
user for their own repositories.
- **User Opt-Out**: If the user asks to disable or remove tracking or
attribution tags, omit the `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION` variable
and custom `User-Agent` suffix from all commands.
device_selection.md 5.1 KB
# Device selection
- [List the catalog](#list-the-catalog): Lines 20-29
- [Resolve a name to an ID](#resolve-a-name-to-an-id): Lines 30-52
- [Several OS versions](#several-os-versions-of-the-same-device): Lines 53-81
- [Other choices](#other-choices-when-several-devices-match): Lines 82-93
- [No match](#no-match): Lines 94-99
- [Confirm before submitting](#confirm-before-submitting): Lines 100-105
- [Details for one device](#details-for-one-device): Lines 106-114
`--device` takes catalog IDs such as `frankel-36`: a device codename plus the
Android API level. Users usually ask for a device by the name it is sold under
("Pixel 10", "Galaxy S22"). Always resolve the name against the live catalog;
the catalog changes, so never rely on a remembered mapping.
For what the catalog contains and its columns, see
https://docs.cloud.google.com/developer-device-platform/device-catalog.md.txt
and `gcloud beta device-run devices list --help`. This page covers choosing.
## List the catalog
```bash
gcloud beta device-run devices list --project="${PROJECT_ID}" --location=global
```
Only devices whose `PRODUCTS` include `Automation` can run Device Run sessions.
Availability shows as `HIGH`, `MEDIUM`, `LOW` or `NONE` in the default table,
and as `AVAILABILITY_HIGH` and so on in the raw `availability.available` field.
## Resolve a name to an ID
Filter on the display name, then pick the **exact** match. A substring filter
for "Pixel 9" also returns "Pixel 9 Pro", "Pixel 9 Pro XL" and "Pixel 9 Pro
Fold", so compare the full name before choosing.
```bash
gcloud beta device-run devices list --project="${PROJECT_ID}" --location=global \
--filter="platform=ANDROID AND supportedProducts:automation AND displayName~'Pixel 10'" \
--format="table(name.basename():label=ID,displayName,osVersion,hardwareType,availability.available)"
```
Example output (illustrative; always check the live catalog):
```
ID NAME OS_VERSION HARDWARE_TYPE AVAILABLE
frankel-36 Pixel 10 36 PHYSICAL AVAILABILITY_HIGH
blazer-36 Pixel 10 Pro 36 PHYSICAL AVAILABILITY_LOW
mustang-36 Pixel 10 Pro XL 36 PHYSICAL AVAILABILITY_MEDIUM
```
Here "Pixel 10" resolves to `frankel-36`.
## Several OS versions of the same device
One device model is often listed once per Android version, for example
`shiba-34`, `shiba-35` and `shiba-36` for a Pixel 8. The OS version can change
the result of a run, so never pick one silently.
* **User named a version** ("Pixel 8 on Android 15", "API 35"): use that ID.
If it is not offered, say so, list the versions that are, and ask.
* **User did not name a version and more than one exists**: show every
version you found, with its availability, and recommend one (usually the
newest with good availability). Ask the user to pick one, several, or all
before submitting. For example (illustrative; use the live catalog):
```
Pixel 8 is available on several Android versions:
shiba-34 Android 14 (API 34) AVAILABILITY_HIGH
shiba-35 Android 15 (API 35) AVAILABILITY_MEDIUM
shiba-36 Android 16 (API 36) AVAILABILITY_HIGH <- recommended
Which should I use? You can also pick several; each becomes its own job.
```
* **Running on several versions**: pass all chosen IDs to `--device` (for
example `--device="shiba-34,shiba-36"`). One session runs one job per ID, so
this is the easiest way to compare behavior across Android versions.
* **Only one version exists**: use it, and still state the version in the
confirmation.
* **Dry runs or no chance to ask**: use the recommended version in the
command, and list the other versions next to it so the user can swap the ID.
## Other choices when several devices match
* **Family names** ("a Pixel 9", "recent Pixels"): list the exact matches and
their variants, and ask the user, or pick the base model and say so.
* **Physical vs virtual**: prefer `PHYSICAL` for performance, hardware or
GPU-dependent work. `VIRTUAL` devices (for example `mediumphone-arm-36`)
suit quick functional checks and usually have high availability.
* **Availability**: `AVAILABILITY_LOW` or `AVAILABILITY_NONE` can mean long
queue times. Warn the user and suggest an alternative.
* **Variants** with suffixes such as `(Camera-enabled)` or `(16K page size)`
are different devices; only choose them when the user needs that feature.
## No match
If nothing matches the name (or the requested OS version is not offered), say
so, show the closest options from the catalog, and ask the user to choose. Never
invent an ID.
## Confirm before submitting
State the mapping you used in the confirmation, for example: "Pixel 10 →
`frankel-36` (Android 16, API 36, physical)". This makes job folders
(`job-000`, `job-001`, ...) easy to read later; see [results.md](results.md).
## Details for one device
```bash
gcloud beta device-run devices describe DEVICE_ID \
--project="${PROJECT_ID}" --location=global
```
The output includes the supported ABIs (for example `arm64-v8a`); make sure
your executable was built for one of them.
instrumentation.md 1.6 KB
# Instrumentation sessions
`gcloud beta device-run sessions submit instrumentation` installs app APKs and
runs an instrumentation test APK on one or more devices (one job per device).
For the full, current flag list (sharding, orchestrator, retries, helper apps)
see https://docs.cloud.google.com/developer-device-platform/device-run.md.txt,
https://docs.cloud.google.com/sdk/gcloud/reference/beta/device-run and
`gcloud beta device-run sessions submit instrumentation --help`.
## Minimal example
```bash
gcloud beta device-run sessions submit instrumentation \
--project="${PROJECT_ID}" --location=global \
--device="pa3q-35" \
--target-app=./app-debug.apk \
--test=./app-debug-androidTest.apk \
--test-targets="class com.example.LoginTest" \
--instrumentation-timeout=20m \
--async
```
`--test-targets` values use a space between the key and the value
(`class com.example.LoginTest`), never `=` (`class=com.example.LoginTest`).
`--instrumentation-timeout` defaults to `5m` (range `1m` to `3h`).
### Older gcloud versions
Prefer `--target-app`. Older gcloud releases don't have it: check
`gcloud beta device-run sessions submit instrumentation --help`. If `--help`
lists only `--apps`, or gcloud reports `unrecognized arguments: --target-app`,
use `--apps=./app-debug.apk` instead and tell the user that `--apps` is
deprecated in newer releases; suggest updating gcloud (ask before running
`gcloud components update`).
## Results
Each execution folder contains `junit.xml`; each job folder contains a merged
`junit.xml` (older runs: `test_results_merged.xml`). See
[results.md](results.md).
multi_config_runs.md 5.3 KB
# Running a binary with several configurations
- [Choose an approach](#choose-an-approach): Lines 12-23
- [Wrapper script](#wrapper-script): Lines 24-128
- [Optional variations](#optional-variations): Lines 129-142
A direct call runs the binary once, with the same arguments on every device. To
run the same binary several times per device with different configurations
(different flags, inputs or environment variables), choose one of two
approaches.
## Choose an approach
Approach | Use when
:-------------------------------------- | :-------
**One session per configuration** | Configurations are independent, you want a separate job status and result for each one, and they don't need to run on the same physical device.
**Wrapper script, one session** | Configurations should run one after another on the same device allocation, later steps depend on earlier ones, or you want a single submission.
For one session per configuration, submit the direct call (see
[android_executable.md](android_executable.md)) once per configuration, with a
distinct `--labels` value (for example `config=a`) on each session. The rest of
this page covers the wrapper script.
## Wrapper script
Pass a `/system/bin/sh` script as `--executable`, push the real binary with
`--other-files-to-push`, and run the binary once per configuration inside the
script.
### Output contract
The script writes one folder per configuration under a single output directory,
which is then pulled with `--paths-to-pull`:
```
/data/local/tmp/out/
├── _device.txt # device model, from getprop
└── <tag>/ # one folder per configuration
├── config.txt # the env vars and args used
├── output.log # stdout and stderr of the binary
├── exit_code # exit code of the binary
└── ... # any files the binary writes to $RUN_OUT_DIR
```
### Template
Adapt `BIN` and the `run` lines. Keep the output contract.
```sh
#!/system/bin/sh
WORK="/data/local/tmp"
BIN="$WORK/my_binary"
OUT="$WORK/out"
# Only needed if the binary uses .so files pushed next to it.
export LD_LIBRARY_PATH="$WORK"
chmod 755 "$BIN"
rm -rf "$OUT" && mkdir -p "$OUT"
# Job folders are only numbered; record the hardware.
getprop ro.product.model > "$OUT/_device.txt"
FAILED=0
# run <tag> [VAR=value ...] -- <args...>
# Runs the binary once and records its config, output and exit code.
run() {
tag="$1"; shift
dir="$OUT/$tag"
mkdir -p "$dir"
envs=""
while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do
envs="$envs $1"; shift
done
[ "$1" = "--" ] && shift
echo "env:$envs args: $*" > "$dir/config.txt"
env $envs RUN_OUT_DIR="$dir" "$BIN" "$@" >"$dir/output.log" 2>&1
code=$?
echo "$code" > "$dir/exit_code"
[ "$code" -ne 0 ] && FAILED=1
}
run default -- --input="$WORK/input.dat"
run strict -- --input="$WORK/input.dat" --strict
run feature_on FEATURE_X=1 -- --input="$WORK/input.dat"
echo "ALL DONE"
exit "$FAILED"
```
Notes:
* The script does not stop at the first failure: every configuration runs and
records its own exit code. It exits non-zero at the end if any configuration
failed, so the failure is not hidden behind a successful script exit.
* Environment variable values and arguments must not contain spaces in this
template. Use a separate `run` line or a pushed config file if they do.
* `RUN_OUT_DIR` is optional. Use it if your binary can write extra output
files there (for example via an `--output_dir="$RUN_OUT_DIR"` flag of your
own); otherwise ignore it.
### Submit
Pass the script as a local path so each run uploads a fresh copy:
```bash
gcloud beta device-run sessions submit android-executable \
--project="${PROJECT_ID}" --location=global \
--device="pa3q-35,m2q-36" \
--executable=./run_all.sh \
--other-files-to-push="gs://my-bucket/bin/my_binary=/data/local/tmp/my_binary,gs://my-bucket/data/input.dat=/data/local/tmp/input.dat" \
--paths-to-pull="/data/local/tmp/out" \
--executable-timeout=60m \
--labels=purpose=multi-config \
--async
```
`--executable-timeout` covers the whole script. Size it for all configurations
together, not for a single run.
### Read results
After downloading (see [results.md](results.md)), search recursively for every
`**/out/*/exit_code` file under each job folder (pulled files are stored under
`execution-NNN/artifacts/data/local/tmp/out/`). For each configuration, report
the tag, `config.txt`, the exit code, and any outputs the user cares about from
`output.log` or the configuration folder. Label rows with `_device.txt` (fall
back to the job folder name). Report non-zero exit codes explicitly.
## Optional variations
Add these only when the task needs them:
* **Repeat a configuration** several times (for flaky or noisy runs): call
`run` in a loop with tags such as `strict_1`, `strict_2`.
* **Setup or discarded runs**: run preparation steps, or a run whose output
you don't keep (for example a warm-up), before the recorded runs. Send
their output to a separate folder or `/dev/null` so it isn't reported.
* **Pause between configurations** (`sleep N`) when one run can affect the
next.
* **Per-configuration time limit**: if one configuration can stop
responding, wrap the call in `timeout <seconds>` (if available on the
device) so it does not use up the whole session timeout.
results.md 2.3 KB
# Results
## Bucket layout
```
gs://BUCKET/automation/
├── inputs/
│ └── <timestamp>/ # auto-uploaded local inputs
└── sessions/
└── SESSION_ID/
├── job-000/ # first device in --device
│ ├── execution-000/
│ │ ├── logcat.txt
│ │ ├── output.log # may be missing in Preview; see below
│ │ ├── artifacts/ # --paths-to-pull, device path preserved
│ │ │ └── data/local/tmp/...
│ │ └── ... # junit.xml, ...
│ ├── execution-000-rerun-000/ # retry, if --flaky-test-attempts > 1
│ └── junit.xml # instrumentation: merged job-level report
└── job-001/ # second device in --device
```
* **`output.log`**: stdout and stderr of your executable only. During
Preview, `android-executable` runs may not export it. If stdout matters,
use a wrapper script that redirects it to a file under `/data/local/tmp`
and pull that file. Check `output.log` if present, then the pulled log,
then `logcat.txt`.
* **`logcat.txt`**: device-wide Android system log; collected for every job.
* **`execution-NNN/`**: one folder per shard. Retries (when
`--flaky-test-attempts` is greater than 1) appear as
`execution-NNN-rerun-MMM/`. Report which attempt passed.
* **Instrumentation**: `junit.xml` per execution, and a merged `junit.xml`
(older runs: `test_results_merged.xml`) directly under `job-NNN/`.
## Download
```bash
mkdir -p ./ddp_results
gcloud storage cp -r "gs://BUCKET/automation/sessions/SESSION_ID/" ./ddp_results/
```
Find pulled files by searching recursively under each job folder rather than
assuming an exact subpath.
## Mapping jobs to devices
Job folders are numbered `job-000`, `job-001`, ... in the order devices were
passed to `--device`. Keep that list with the session ID so rows can be labeled.
For extra safety in script runs, record the device model on the device (`getprop
ro.product.model`) into an output file.
## Reporting
Summarize per device: device ID, job folder, result, the outputs the user cares
about, and the `gs://` session path. List failed or missing jobs explicitly; a
missing output file usually means the run failed, so check `output.log` (if
present) or a pulled stdout log first, then `logcat.txt`.
session_lifecycle.md 2.4 KB
# Session lifecycle
## Synchronous vs asynchronous
* **Default (synchronous):** `sessions submit ...` blocks until the session
finishes. Fine for short runs.
* **`--async`:** returns right after submission. Use it for anything longer
than a few minutes, and for agents that should keep the user informed.
The submit output contains the session ID in the form `Creating session
[SESSION_ID]`. Capture it; every later command needs it.
## Waiting
Option A, block until done (streams a progress tracker to stderr and prints the
result table on completion):
```bash
gcloud beta device-run sessions wait SESSION_ID \
--project="${PROJECT_ID}" --location=global
```
Option B, poll and report progress (preferred for agents):
```bash
gcloud beta device-run sessions describe SESSION_ID \
--project="${PROJECT_ID}" --location=global
```
* Poll every 30 to 60 seconds. Never poll in a tight loop.
* While `PENDING` or `RUNNING`, `describe` writes only the status summary
(and latest progress message) to stderr. Once `DONE`, it writes the
summary to stderr and the per-job result table to stdout; capture both.
* Add `--full` (optionally `--format=json`) for full session details,
including per-job status while a session is still running.
* If your environment has a native scheduling or background-task mechanism,
you may use it instead of sleeping in the foreground.
## Status and result
A session and each of its jobs report a **status** and, once done, a **result**:
Status | Meaning
:---------- | :---------------------------------------------
`PENDING` | Waiting for a device.
`RUNNING` | Executing.
`DONE` | Finished; read the result.
`SUSPENDED` | Paused, typically due to quota. Tell the user.
Result | Meaning
:---------- | :-----------------------------------------------------
`PASSED` | Completed successfully.
`FAILED` | The executable or tests failed.
`ERROR` | Infrastructure or setup error; investigate the cause with `sessions describe SESSION_ID --full`.
`TIMED_OUT` | Exceeded the timeout; consider a longer timeout.
`CANCELLED` | Cancelled by the user or system.
The session is finished when its status is `DONE`. Do not wait for states such
as `ACTIVE` or `SUCCEEDED`; those are not Device Run states (`ACTIVE` belongs to
interactive Device Streaming leases).
## Cancel
```bash
gcloud beta device-run sessions cancel SESSION_ID \
--project="${PROJECT_ID}" --location=global
```
troubleshooting.md 2.9 KB
# Troubleshooting
Symptom | Likely cause | Fix
:-------------------------------------------------------- | :------------------------------------------------------------------------------------ | :--
`sessions submit android-executable` not found | Old gcloud or missing beta component | Ask the user, then run `gcloud components install beta` or `gcloud components update`.
Bucket error on submit | `--bucket-name` points to a bucket that does not exist, or includes `gs://` or a path | Create the bucket first, or omit the flag to use `PROJECT_ID-devicerun`. Pass the name only.
Job `TIMED_OUT` | Default timeout is `5m` | Set `--executable-timeout` / `--instrumentation-timeout` (max `3h`).
`CANNOT LINK EXECUTABLE` / library not found | Shared library not pushed or not on the loader path | Push the `.so` with `--other-files-to-push` and set `LD_LIBRARY_PATH` via `--executable-env-vars` (direct call) or `export` (script).
Feature silently falls back (for example GPU to CPU) | Runtime-loaded (`dlopen`) library missing | Same as above; confirm in `output.log` (if present), a pulled stdout log, or `logcat.txt` that the library loaded.
Binary receives one mangled argument | Space-separated args passed as one element | Rewrite as comma-separated `--executable-args`; use `^SEP^` for values with commas.
`Permission denied` running a pushed binary from a script | Pushed file is not executable | `chmod 755` it in the script before running.
Output file missing | Run failed before writing it, or wrong `--paths-to-pull` path | Check `output.log` (may be missing in Preview) or a pulled stdout log, then `logcat.txt`; write outputs under `/data/local/tmp`.
Session `SUSPENDED` | Quota | Tell the user; wait or cancel.
Job `ERROR` with your own bucket | Setup or permission problem | Inspect the result cause with `sessions describe SESSION_ID --full`; verify the bucket exists and is in the same project.
Pending session ran an unexpected script version | Shared `gs://` script was overwritten after submission | Use local paths (auto-uploaded per run) or a unique `gs://` path per run.
License (Apache-2.0)
View full license text
Licensed under the Apache License, Version 2.0. See https://github.com/google/skills/blob/main/LICENSE