Skip to content

Commit 04f1aaf

Browse files
committed
add cuttlefish test
1 parent 01ab3d8 commit 04f1aaf

File tree

2 files changed

+125
-3
lines changed

2 files changed

+125
-3
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+
export PATH="$PATH:$ANDROID_HOME/platform-tools"
4+
sdk="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
5+
cvd_args="-daemon -enable_sandbox=false -memory_mb=8192 -report_anonymous_usage_stats=n"
6+
7+
cleanup() {
8+
print_error "! An error occurred"
9+
run_cvd_bin stop_cvd || true
10+
}
11+
12+
run_cvd_bin() {
13+
local exe=$1
14+
shift
15+
HOME=$CF_HOME $CF_HOME/bin/$exe "$@"
16+
}
17+
18+
setup_env() {
19+
curl -LO hhttps://github.com/user-attachments/files/18728876/cuttlefish-base_1.2.0_amd64.zip
20+
sudo dpkg -i ./cuttlefish-base_*_*64.zip || sudo apt-get install -f
21+
rm cuttlefish-base_*_*64.zip
22+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
23+
sudo udevadm control --reload-rules
24+
sudo udevadm trigger
25+
sudo usermod -aG kvm,cvdnetwork,render $USER
26+
yes | "$sdk" --licenses > /dev/null
27+
"$sdk" --channel=3 platform-tools
28+
}
29+
30+
download_cf() {
31+
local branch=$1
32+
local device=$2
33+
34+
if [ -z $branch ]; then
35+
branch='aosp-main'
36+
fi
37+
if [ -z $device ]; then
38+
device='aosp_cf_x86_64_phone'
39+
fi
40+
local target="${device}-trunk_staging-userdebug"
41+
42+
local build_id=$(curl -sL https://ci.android.com/builds/branches/${branch}/status.json | \
43+
jq -r ".targets[] | select(.name == \"$target\") | .last_known_good_build")
44+
local sys_img_url="https://ci.android.com/builds/submitted/${build_id}/${target}/latest/raw/${device}-img-${build_id}.zip"
45+
local host_pkg_url="https://ci.android.com/builds/submitted/${build_id}/${target}/latest/raw/cvd-host_package.tar.gz"
46+
47+
print_title "* Download $target ($build_id) images"
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

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

0 commit comments

Comments
 (0)