-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ci: Run x86_64-linux-android tests on Cuttlefish virtual devices #5269
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -eux | ||
|
|
||
| # Fetch and boot a Cuttlefish Android virtual device, heavily inspired by | ||
| # Mesa's CI: | ||
| # https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/.gitlab-ci/cuttlefish-runner.sh | ||
| # | ||
| # Runs unprivileged (cvd refuses to run as root) inside the test container, | ||
| # invoked by cuttlefish-entrypoint.sh after it has prepared the devices, | ||
| # networking and groups (see ci/docker/x86_64-linux-android/). | ||
| build="${CUTTLEFISH_BUILD:-15660610}" | ||
| target="${CUTTLEFISH_TARGET:-aosp_cf_x86_64_only_phone-userdebug}" | ||
| cf_dir="${CUTTLEFISH_DIR:-$HOME/cuttlefish}" | ||
|
|
||
| mkdir -p "$cf_dir" | ||
| cvd fetch --default_build="${build}/${target}" --target_directory="$cf_dir" | ||
|
|
||
| cd "$cf_dir" | ||
|
|
||
| # -daemon exits only once the guest has fully booted. | ||
| # -enable_sandbox=false is needed because crosvm's minijail device sandbox | ||
| # (auto-enabled when /var/empty exists) requires unprivileged user | ||
| # namespaces, which Ubuntu 24.04+ blocks via AppArmor by default. | ||
| HOME="$cf_dir" timeout 10m ./bin/launch_cvd \ | ||
| -daemon \ | ||
| -enable_sandbox=false \ | ||
| -verbosity=INFO \ | ||
| -file_verbosity=DEBUG \ | ||
| -enable_audio=false \ | ||
| -enable_bootanimation=false \ | ||
| -enable_minimal_mode=true \ | ||
| -enable_modem_simulator=false \ | ||
| -enable_wifi=false \ | ||
| -report_anonymous_usage_stats=no \ | ||
| -cpus=2 \ | ||
| -memory_mb=4096 | ||
|
|
||
| # Check the guest's adbd is reachable on the port the test runner uses, | ||
| # and log the Android version actually being tested. | ||
| HOME="$cf_dir" ./bin/adb connect 127.0.0.1:6520 | ||
| HOME="$cf_dir" ./bin/adb -s 127.0.0.1:6520 wait-for-device | ||
| HOME="$cf_dir" ./bin/adb devices | ||
| HOME="$cf_dir" ./bin/adb -s 127.0.0.1:6520 shell \ | ||
| getprop ro.build.version.release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,38 @@ | ||
| FROM ubuntu:26.04 | ||
|
|
||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| adb \ | ||
| ca-certificates \ | ||
| curl \ | ||
| gcc \ | ||
| libc-dev \ | ||
| python3 \ | ||
| unzip \ | ||
| wget | ||
|
|
||
| # Cuttlefish host packages: the virtual device the tests run on boots | ||
| # inside this container (see cuttlefish-entrypoint.sh for the docker run | ||
| # flags this needs). | ||
| RUN curl -fsSL https://us-apt.pkg.dev/doc/repo-signing-key.gpg \ | ||
| -o /etc/apt/trusted.gpg.d/artifact-registry.asc \ | ||
| && echo "deb https://us-apt.pkg.dev/projects/android-cuttlefish-artifacts android-cuttlefish main" \ | ||
| >/etc/apt/sources.list.d/artifact-registry.list \ | ||
| && apt-get update && apt-get install -y cuttlefish-base cuttlefish-user | ||
|
|
||
| WORKDIR /android/ | ||
| ENV ANDROID_ARCH=x86_64 | ||
| COPY android-install-ndk.sh /android/ | ||
| RUN /android/android-install-ndk.sh | ||
|
|
||
| # We do not run x86_64-linux-android tests on an android emulator. | ||
| # See ci/android-sysimage.sh for information about how tests are run. | ||
| COPY android-sysimage.sh /android/ | ||
| RUN /android/android-sysimage.sh x86_64 x86_64-24_r07.zip | ||
|
|
||
| ENV PATH=$PATH:/rust/bin:/android/linux-x86_64/bin \ | ||
| ANDROID_SERIAL=127.0.0.1:6520 \ | ||
| CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=x86_64-linux-android28-clang \ | ||
| CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER=/tmp/runtest \ | ||
| CC_x86_64_linux_android=x86_64-linux-android28-clang \ | ||
| CXX_x86_64_linux_android=x86_64-linux-android28-clang++ \ | ||
| AR_x86_64_linux_android=llvm-ar \ | ||
| HOME=/tmp | ||
|
|
||
| ADD runtest-android.rs /tmp/runtest.rs | ||
| COPY cuttlefish-setup.sh docker/x86_64-linux-android/cuttlefish-entrypoint.sh /android/ | ||
| ENTRYPOINT ["/android/cuttlefish-entrypoint.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -eux | ||
|
|
||
| # Boot a Cuttlefish virtual device inside this container, then run the | ||
| # tests against it as an unprivileged user (cvd refuses to run as root). | ||
| # | ||
| # The container needs only /dev/kvm, /dev/net/tun, /dev/vhost-net, | ||
| # /dev/vhost-vsock and CAP_NET_ADMIN, passed by ci/run-docker.sh. It's | ||
| # the same set upstream uses for its own containerized Cuttlefish CI: | ||
| # https://github.com/google/android-cuttlefish/blob/main/.github/workflows/presubmit.yaml | ||
|
|
||
| # The device nodes come in with their host-side ownership: open them up | ||
| # for the unprivileged user (container-local, doesn't affect the host). | ||
| chmod 666 /dev/kvm /dev/net/tun /dev/vhost-net /dev/vhost-vsock | ||
|
|
||
| # Create the bridges, taps and dnsmasq instances backing the device's | ||
| # virtio-net, inside this container's own network namespace. The deb ships | ||
| # a sysv script for this, usable without systemd, which is also how | ||
| # upstream's container image starts it. | ||
| service cuttlefish-host-resources start | ||
|
|
||
| # cvd requires the current process to be in these groups. The groups are | ||
| # normally created by the deb postinst, -f covers any it didn't create. | ||
| for g in kvm cvdnetwork render; do | ||
| groupadd -f "$g" | ||
| done | ||
| # Match the invoking user's uid so writes to the bind-mounted target/ | ||
| # directory stay owned by the host user. | ||
| useradd -m -u "${HOST_UID:?}" -G kvm,cvdnetwork,render cf | ||
|
|
||
| run_as_cf() { | ||
| runuser -u cf -- env PATH="$PATH" HOME=/tmp "$@" | ||
| } | ||
|
|
||
| # Keep the device under target/ (bind-mounted from the host) so its logs | ||
| # survive the container for ci/create-artifacts.py to pick up. | ||
| export CUTTLEFISH_DIR=/checkout/target/cuttlefish | ||
|
|
||
| run_as_cf /android/cuttlefish-setup.sh | ||
|
|
||
| # The test runner (runtest-android.rs) drives the device with the | ||
| # container's adb via $ANDROID_SERIAL. Connect its server to the device | ||
| # (this may replace the server started by the fetched adb during boot). | ||
| run_as_cf adb connect "$ANDROID_SERIAL" | ||
| run_as_cf adb wait-for-device | ||
|
|
||
| run_as_cf rustc /tmp/runtest.rs -o /tmp/runtest | ||
|
|
||
| rc=0 | ||
| run_as_cf "$@" || rc=$? | ||
|
|
||
| # Stop the device so its logs are flushed for ci/create-artifacts.py. | ||
| run_as_cf env HOME="$CUTTLEFISH_DIR" \ | ||
| "$CUTTLEFISH_DIR/bin/stop_cvd" -wait_for_launcher=40 || true | ||
|
|
||
| exit "$rc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.