diff options
| author | Lena <lena@omega> | 2026-01-01 00:00:00 +0000 |
|---|---|---|
| committer | Lena <lena@omega> | 2026-06-24 22:14:50 +0300 |
| commit | eb0c8951196c637e44daf3c0617b131b997d5d2c (patch) | |
| tree | 2f83b6a41cee745467e53fc401942b82cea286ea /test | |
| download | scrcpy-android-eb0c8951196c637e44daf3c0617b131b997d5d2c.tar.gz | |
scrcpy-android: mirror an Android device over wireless ADB0.1
Native Java app for Android 12+ that mirrors another Android
device over wireless ADB, forwarding video, audio, touch input,
and clipboard. Bundles a pinned scrcpy-server.jar and the
vendored libadb-android stack. Supports h264/h265/av1 video and
raw/opus audio with in-app codec selection. No NDK, no Kotlin.
Includes JVM unit tests and a Docker-based emulator e2e rig.
Diffstat (limited to 'test')
| -rwxr-xr-x | test | 90 |
1 files changed, 90 insertions, 0 deletions
@@ -0,0 +1,90 @@ +#!/bin/sh +# Run scrcpy-android tests inside the project-local Docker image. +# +# ./test unit tests (JVM only, no KVM) +# ./test unit same +# ./test e2e single-emulator self-mirror E2E (needs /dev/kvm) +# ./test all unit + e2e +# ./test record boot emulator, run a Mirror session, inject events, +# capture screen recording to ./output.mp4 (needs /dev/kvm) +# ./test apk build a signed release APK with a throwaway keystore +# (exercises scripts/build-apk end-to-end, no KVM) +# +# The image is built on first run and cached as $IMG. +# /dev/kvm must be readable by the invoking user for `./test e2e` and `record`. + +set -eu + +ROOT="$(cd "$(dirname "$0")" && pwd)" +# Bump the tag suffix whenever test-rig/Dockerfile or sdk-packages.txt +# changes; otherwise a stale cached image keeps being used. +IMG="scrcpy-android-test:5" + +cmd="${1:-unit}" +case "$cmd" in + unit|e2e|all|record|apk) ;; + -h|--help) + sed -n '2,14p' "$0" >&2 + exit 0 ;; + *) + echo "usage: $0 [unit|e2e|all|record|apk]" >&2 + exit 2 ;; +esac + +# Cheap supply-chain check: the gradle wrapper jar is a small binary +# we check into the tree; verify its sha before letting it run. +"$ROOT/scripts/check-wrapper" + +# Build the image if needed. --network=host so RUN apt/curl can reach +# the outside on hosts where the default docker bridge has no DNS. +if ! docker image inspect "$IMG" >/dev/null 2>&1; then + echo "test: building $IMG (first run, ~10 min)" >&2 + # Cheap pre-flight: warn the user up-front if the host can't resolve + # the docker registry, so they don't watch an apt step time out. + if ! getent hosts registry-1.docker.io >/dev/null 2>&1; then + echo "test: WARNING - registry-1.docker.io did not resolve via /etc/resolv.conf." >&2 + echo " Build will likely fail. Fix the host DNS (e.g." >&2 + echo " append 'nameserver 1.1.1.1' to /etc/resolv.conf) and retry." >&2 + fi + docker build --network=host -t "$IMG" "$ROOT/test-rig" +fi + +# KVM check for tiers that boot the emulator. +needs_kvm= +case "$cmd" in + e2e|all|record) needs_kvm=1 ;; +esac + +kvm_args= +if [ -n "$needs_kvm" ]; then + if [ ! -e /dev/kvm ]; then + echo "test: /dev/kvm not present on this host - e2e cannot run." >&2 + exit 3 + fi + if [ ! -r /dev/kvm ] || [ ! -w /dev/kvm ]; then + echo "test: /dev/kvm exists but is not rw for uid $(id -u)." >&2 + echo " one-time fix:" >&2 + echo " sudo chmod 666 /dev/kvm" >&2 + echo " or add yourself to the kvm group and re-login:" >&2 + echo " sudo usermod -aG kvm $(id -un)" >&2 + exit 3 + fi + # Pass through the host's kvm gid so the container user (mapped to + # host uid:gid) can actually open /dev/kvm. + kvm_gid=$(getent group kvm | awk -F: '{print $3}') + kvm_args="--device /dev/kvm --group-add ${kvm_gid:-kvm}" +fi + +# Forward Ctrl-C cleanly, run as the host user so files in .tools/ stay +# owned by the invoker (avoids root-owned gradle cache on the host). +# --network=host so the gradle wrapper can fetch the distribution and +# maven deps in environments where the docker bridge DNS misbehaves. +exec docker run --rm -i \ + --network=host \ + $kvm_args \ + -u "$(id -u):$(id -g)" \ + -v "$ROOT":/work \ + -w /work \ + -e HOME=/work/.tools/home \ + "$IMG" \ + /work/test-rig/run.sh "$cmd" |