Skip to content

Commit 98de98e

Browse files
committed
Testing: update Android GitHub workflow to run tests on emulator
1 parent 50c3d9c commit 98de98e

File tree

2 files changed

+81
-41
lines changed

2 files changed

+81
-41
lines changed
Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
name: Android Gradle Build test logic
1+
name: Android Gradle Build and Test
22

33
on:
4-
workflow_call:
5-
inputs:
6-
os:
7-
required: true
8-
type: string
9-
jdk_distro:
10-
required: true
11-
type: string
12-
jdk_version:
13-
required: true
14-
type: string
4+
push:
5+
branches: [ 'master', 'main', 'release/**' ]
6+
pull_request:
7+
branches: [ 'master' ]
8+
9+
concurrency:
10+
group: android-${{ github.head_ref || github.ref }}
11+
cancel-in-progress: true
1512

1613
jobs:
17-
build_wolfssljni:
18-
runs-on: ${{ inputs.os }}
14+
build_wolfcryptjni:
15+
runs-on: ubuntu-latest
1916
steps:
2017
- name: Clone wolfcrypt-jni
2118
uses: actions/checkout@v4
@@ -31,22 +28,80 @@ jobs:
3128
- name: Create blank options.h
3229
run: cp IDE/Android/app/src/main/cpp/wolfssl/wolfssl/options.h.in IDE/Android/app/src/main/cpp/wolfssl/wolfssl/options.h
3330

34-
# Setup Java
31+
# Setup Java with Gradle caching
3532
- name: Setup java
3633
uses: actions/setup-java@v4
3734
with:
38-
distribution: ${{ inputs.jdk_distro }}
39-
java-version: ${{ inputs.jdk_version }}
35+
distribution: 'zulu'
36+
java-version: '21'
37+
cache: 'gradle'
38+
39+
# Build all targets in single Gradle invocation
40+
- name: Gradle Build
41+
run: cd IDE/Android && ./gradlew --build-cache assembleDebug assembleDebugUnitTest assembleDebugAndroidTest
4042

41-
# Gradle assembleDebug
42-
- name: Gradle assembleDebug
43-
run: cd IDE/Android && ls && ./gradlew assembleDebug
43+
# Enable KVM for hardware acceleration (required for emulator)
44+
- name: Enable KVM
45+
run: |
46+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
47+
sudo udevadm control --reload-rules
48+
sudo udevadm trigger --name-match=kvm
4449
45-
# Gradle assembleDebugUnitTest
46-
- name: Gradle assembleDebugUnitTest
47-
run: cd IDE/Android && ls && ./gradlew assembleDebugUnitTest
50+
# Cache AVD snapshot for faster emulator boot
51+
- name: AVD cache
52+
uses: actions/cache@v4
53+
id: avd-cache
54+
with:
55+
path: |
56+
~/.android/avd/*
57+
~/.android/adb*
58+
key: avd-wolfcryptjni-30-x86_64-atd-v1
4859

49-
# Gradle assembleDebugAndroidTest
50-
- name: Gradle assembleDebugAndroidTest
51-
run: cd IDE/Android && ls && ./gradlew assembleDebugAndroidTest
60+
# Create AVD and generate snapshot for caching
61+
- name: Create AVD and generate snapshot
62+
if: steps.avd-cache.outputs.cache-hit != 'true'
63+
uses: reactivecircus/android-emulator-runner@v2
64+
with:
65+
api-level: 30
66+
arch: x86_64
67+
target: aosp_atd
68+
force-avd-creation: false
69+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
70+
disable-animations: true
71+
script: echo "Generated AVD snapshot for caching"
5272

73+
# Run instrumented tests on Android emulator
74+
- name: Run Android Instrumented Tests
75+
uses: reactivecircus/android-emulator-runner@v2
76+
timeout-minutes: 15
77+
with:
78+
api-level: 30
79+
arch: x86_64
80+
target: aosp_atd
81+
force-avd-creation: false
82+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
83+
disable-animations: true
84+
script: |
85+
adb wait-for-device
86+
adb shell mkdir -p /data/local/tmp/examples/certs/intermediate
87+
adb shell mkdir -p /data/local/tmp/examples/certs/rsapss
88+
adb shell mkdir -p /data/local/tmp/examples/certs/crl
89+
adb push ./examples/certs/ /data/local/tmp/examples/
90+
adb logcat -c
91+
cd IDE/Android && ./gradlew connectedDebugAndroidTest --no-daemon --no-watch-fs || { adb logcat -d > /tmp/logcat.txt 2>&1; echo "=== LOGCAT (errors) ==="; grep -i "exception\|error\|fatal" /tmp/logcat.txt || true; exit 1; }
92+
adb logcat -d > /tmp/logcat.txt 2>&1 || true
93+
pgrep -f '[q]emu-system' | xargs -r kill -9 2>/dev/null || true
94+
pgrep -f '[c]rashpad' | xargs -r kill -9 2>/dev/null || true
95+
sleep 2
96+
97+
# Upload test reports even on failure
98+
- name: Upload Test Reports
99+
uses: actions/upload-artifact@v4
100+
if: always()
101+
timeout-minutes: 5
102+
with:
103+
name: android-test-reports
104+
path: |
105+
IDE/Android/app/build/reports/androidTests/
106+
/tmp/logcat.txt
107+
retention-days: 14

.github/workflows/main.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,6 @@ jobs:
139139
jdk_version: ${{ matrix.jdk_version }}
140140
wolfssl_configure: ${{ matrix.wolfssl_configure }}
141141

142-
# ----------------------- Android Gradle build ------------------------
143-
# Run Android gradle build over PR code, only running on Linux with one
144-
# JDK/version for now.
145-
android-gradle:
146-
strategy:
147-
matrix:
148-
os: [ 'ubuntu-latest' ]
149-
jdk_version: [ '21' ]
150-
name: Android Gradle (${{ matrix.os }} Zulu JDK ${{ matrix.jdk_version }})
151-
uses: ./.github/workflows/android_gradle.yml
152-
with:
153-
os: ${{ matrix.os }}
154-
jdk_distro: "zulu"
155-
jdk_version: ${{ matrix.jdk_version }}
156-
157142
# --------------------- Maven build - test pom.xml --------------------
158143
# Run Maven build over PR code, running on Linux and Mac with only one
159144
# JDK/version for now.

0 commit comments

Comments
 (0)