Skip to content

Commit 71aaad4

Browse files
authored
add cuttlefish test (#61)
1 parent 01ab3d8 commit 71aaad4

File tree

2 files changed

+128
-4
lines changed

2 files changed

+128
-4
lines changed

.github/cuttlefish.sh

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
3+
set -xe
4+
export PATH="$PATH:$ANDROID_HOME/platform-tools"
5+
sdk="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
6+
cvd_args="-daemon -enable_sandbox=false -memory_mb=8192 -report_anonymous_usage_stats=n"
7+
8+
cleanup() {
9+
print_error "! An error occurred"
10+
run_cvd_bin stop_cvd || true
11+
}
12+
13+
run_cvd_bin() {
14+
local exe=$1
15+
shift
16+
HOME=$CF_HOME $CF_HOME/bin/$exe "$@"
17+
}
18+
19+
setup_env() {
20+
curl -LO https://github.com/user-attachments/files/18728876/cuttlefish-base_1.2.0_amd64.zip
21+
sudo dpkg -i ./cuttlefish-base_*_*64.zip || sudo apt-get install -f
22+
rm cuttlefish-base_*_*64.zip
23+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
24+
sudo udevadm control --reload-rules
25+
sudo udevadm trigger
26+
sudo usermod -aG kvm,cvdnetwork,render $USER
27+
yes | "$sdk" --licenses > /dev/null
28+
"$sdk" --channel=3 platform-tools
29+
}
30+
31+
download_cf() {
32+
local branch=$1
33+
local device=$2
34+
35+
if [ -z $branch ]; then
36+
branch='aosp-main'
37+
fi
38+
if [ -z $device ]; then
39+
device='aosp_cf_x86_64_phone'
40+
fi
41+
local target="${device}-trunk_staging-userdebug"
42+
43+
local build_id=$(curl -sL https://ci.android.com/builds/branches/${branch}/status.json | \
44+
jq -r ".targets[] | select(.name == \"$target\") | .last_known_good_build")
45+
local sys_img_url="https://ci.android.com/builds/submitted/${build_id}/${target}/latest/raw/${device}-img-${build_id}.zip"
46+
local host_pkg_url="https://ci.android.com/builds/submitted/${build_id}/${target}/latest/raw/cvd-host_package.tar.gz"
47+
48+
curl -L $sys_img_url -o aosp_cf_phone-img.zip
49+
curl -LO $host_pkg_url
50+
rm -rf $CF_HOME
51+
mkdir -p $CF_HOME
52+
tar xvf cvd-host_package.tar.gz -C $CF_HOME
53+
unzip aosp_cf_phone-img.zip -d $CF_HOME
54+
rm -f cvd-host_package.tar.gz aosp_cf_phone-img.zip
55+
}
56+
57+
58+
test_main() {
59+
run_cvd_bin launch_cvd $cvd_args
60+
adb wait-for-device
61+
./gradlew connectedCheck
62+
run_cvd_bin stop_cvd || true
63+
}
64+
65+
if [ -z $CF_HOME ]; then
66+
print_error "! Environment variable CF_HOME is required"
67+
exit 1
68+
fi
69+
70+
case "$1" in
71+
setup )
72+
setup_env
73+
;;
74+
download )
75+
download_cf $2 $3
76+
;;
77+
test )
78+
trap cleanup EXIT
79+
export -f run_cvd_bin
80+
test_main
81+
trap - EXIT
82+
;;
83+
* )
84+
exit 1
85+
;;
86+
esac

.github/workflows/android.yml

+42-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Build
22

3-
on: [push, pull_request]
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- 'main'
48

59
jobs:
610
build:
@@ -81,9 +85,6 @@ jobs:
8185
- api-level: 34
8286
target: aosp_atd
8387
arch: x86_64
84-
- api-level: 34
85-
target: android-tv
86-
arch: x86
8788
- api-level: 35
8889
target: aosp_atd
8990
arch: x86_64
@@ -115,3 +116,40 @@ jobs:
115116
force-avd-creation: false
116117
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
117118
disable-animations: true
119+
120+
cf-test:
121+
name: Test ${{ matrix.device }}
122+
runs-on: ubuntu-24.04
123+
needs: build
124+
env:
125+
CF_HOME: /home/runner/aosp_cf_phone
126+
strategy:
127+
fail-fast: false
128+
matrix:
129+
include:
130+
- branch: "aosp-main"
131+
device: "aosp_cf_x86_64_phone"
132+
133+
steps:
134+
- name: Check out
135+
uses: actions/checkout@v4
136+
- name: Set up JDK 21
137+
uses: actions/setup-java@v4
138+
with:
139+
distribution: 'temurin'
140+
java-version: '21'
141+
- name: Setup Cuttlefish environment
142+
run: |
143+
.github/cuttlefish.sh setup
144+
.github/cuttlefish.sh download ${{ matrix.branch }} ${{ matrix.device }}
145+
- name: Run Cuttlefish test
146+
timeout-minutes: 10
147+
run: su $USER -c '.github/cuttlefish.sh test'
148+
- name: Upload logs on error
149+
if: ${{ failure() }}
150+
uses: actions/upload-artifact@v4
151+
with:
152+
name: "cvd-logs-${{ matrix.device }}"
153+
path: |
154+
/home/runner/aosp_cf_phone/cuttlefish/instances/cvd-1/logs
155+
/home/runner/aosp_cf_phone/cuttlefish/instances/cvd-1/cuttlefish_config.json

0 commit comments

Comments
 (0)