Skip to content

Commit 8dc20c1

Browse files
authored
Fix LlamaDemo Android instrumentation CI reliability (#153)
- Fix emulator configuration to use 16GB RAM properly with both `ram-size` and `-memory` flags - Add robust `adb push` with timeout, retry, and file size verification
1 parent 5b9154f commit 8dc20c1

3 files changed

Lines changed: 55 additions & 26 deletions

File tree

.github/workflows/llm-android.yml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ jobs:
4242
env:
4343
API_LEVEL: 34
4444
ARCH: x86_64
45-
EMULATOR_OPTIONS: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
46-
RAM_SIZE: 16384
4745

4846
name: Instrumentation Test LlamaDemo
4947
steps:
@@ -83,35 +81,22 @@ jobs:
8381
path: |
8482
~/.android/avd/*
8583
~/.android/adb*
86-
key: avd-${{ env.API_LEVEL }}-${{ env.ARCH }}-ram${{ env.RAM_SIZE }}-disk16G
84+
key: avd-${{ env.API_LEVEL }}-${{ env.ARCH }}-ram16G-disk16G-v5
8785

8886
- name: Create AVD and generate snapshot for caching
8987
if: steps.avd-cache.outputs.cache-hit != 'true'
9088
uses: reactivecircus/android-emulator-runner@v2
9189
with:
9290
api-level: ${{ env.API_LEVEL }}
9391
arch: ${{ env.ARCH }}
92+
ram-size: 16384M
93+
disk-size: 16384M
9494
force-avd-creation: true
95-
emulator-options: ${{ env.EMULATOR_OPTIONS }}
95+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-snapshot-save -memory 16384
9696
disable-animations: false
9797
working-directory: llm/android/LlamaDemo
9898
script: echo "Generated AVD snapshot for caching."
9999

100-
- name: Configure AVD RAM and disk
101-
run: |
102-
AVD_DIR="$HOME/.android/avd"
103-
for config in "$AVD_DIR"/*.avd/config.ini; do
104-
if [ -f "$config" ]; then
105-
echo "Updating config in $config"
106-
# Update RAM
107-
sed -i 's/hw.ramSize=.*/hw.ramSize=${{ env.RAM_SIZE }}/' "$config" || true
108-
grep -q "hw.ramSize" "$config" || echo "hw.ramSize=${{ env.RAM_SIZE }}" >> "$config"
109-
# Update disk size to 16GB for large models
110-
sed -i 's/disk.dataPartition.size=.*/disk.dataPartition.size=16G/' "$config" || true
111-
grep -q "disk.dataPartition.size" "$config" || echo "disk.dataPartition.size=16G" >> "$config"
112-
fi
113-
done
114-
115100
- name: Download model files
116101
env:
117102
MODEL_PRESET: ${{ inputs.model_preset || 'stories' }}
@@ -163,8 +148,10 @@ jobs:
163148
with:
164149
api-level: ${{ env.API_LEVEL }}
165150
arch: ${{ env.ARCH }}
166-
force-avd-creation: false
167-
emulator-options: -no-snapshot-save ${{ env.EMULATOR_OPTIONS }}
151+
ram-size: 16384M
152+
disk-size: 16384M
153+
force-avd-creation: true
154+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-snapshot-save -memory 16384
168155
disable-animations: true
169156
working-directory: llm/android/LlamaDemo
170157
script: bash ./scripts/run-ci-tests.sh "$MODEL_PRESET" "$MODEL_FILE" "$TOKENIZER_FILE"

llm/android/LlamaDemo/app/src/androidTest/java/com/example/executorchllamademo/UIWorkflowTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ public void testSendMessageAndReceiveResponse() throws Exception {
199199
onView(withId(R.id.sendButton)).perform(click());
200200

201201
// --- Wait for response and validate ---
202-
// Wait 5 seconds for model to generate response
203-
Thread.sleep(5000);
202+
// Wait 50 seconds for model to generate response
203+
Thread.sleep(50000);
204204

205205
// Extract all messages from the list
206206
AtomicInteger messageCount = new AtomicInteger(0);

llm/android/LlamaDemo/scripts/run-ci-tests.sh

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,59 @@ echo "TOKENIZER_FILE: $TOKENIZER_FILE"
2525
echo "=== Emulator Memory Info ==="
2626
adb shell cat /proc/meminfo | head -5
2727

28+
echo "=== Emulator Disk Space ==="
29+
adb shell df -h /data
30+
2831
# Clean and prepare device directory
2932
adb shell rm -rf /data/local/tmp/llama
3033
adb shell mkdir -p /data/local/tmp/llama
3134

32-
# Push pre-downloaded model files to device
35+
# Push pre-downloaded model files to device with timeout and retry
3336
echo "=== Pushing pre-downloaded model files to device ==="
3437
for file in /tmp/llama_models/*; do
35-
echo "Pushing $(basename "$file")..."
36-
adb push "$file" /data/local/tmp/llama/
38+
filename=$(basename "$file")
39+
filesize=$(stat -c%s "$file" 2>/dev/null || stat -f%z "$file" 2>/dev/null || echo "0")
40+
# Calculate timeout: 30 seconds base + 1 second per 50MB
41+
timeout_secs=$((30 + filesize / 50000000))
42+
echo "Pushing $filename (size: $((filesize / 1024 / 1024))MB, timeout: ${timeout_secs}s)..."
43+
44+
max_retries=3
45+
retry=0
46+
success=false
47+
48+
while [ $retry -lt $max_retries ] && [ "$success" = "false" ]; do
49+
# Run push (ignore exit code, verify by checking file on device)
50+
timeout $timeout_secs adb push "$file" /data/local/tmp/llama/ || true
51+
52+
# Verify file was pushed by checking it exists and has correct size
53+
device_size=$(adb shell "stat -c%s /data/local/tmp/llama/$filename 2>/dev/null || echo 0" | tr -d '\r')
54+
if [ "$device_size" = "$filesize" ]; then
55+
success=true
56+
echo "Successfully pushed $filename (verified size: $device_size bytes)"
57+
else
58+
retry=$((retry + 1))
59+
echo "Push failed or incomplete (attempt $retry/$max_retries, expected $filesize bytes, got $device_size bytes)"
60+
if [ $retry -lt $max_retries ]; then
61+
echo "Waiting 5 seconds before retry..."
62+
sleep 5
63+
echo "Checking if emulator is still responsive..."
64+
adb shell getprop ro.build.version.sdk || echo "WARNING: Emulator may be unresponsive"
65+
fi
66+
fi
67+
done
68+
69+
if [ "$success" = "false" ]; then
70+
echo "ERROR: Failed to push $filename after $max_retries attempts"
71+
exit 1
72+
fi
73+
74+
echo "Checking emulator responsiveness..."
75+
adb shell getprop ro.build.version.sdk || echo "WARNING: Emulator may be unresponsive"
3776
done
3877

78+
echo "=== Syncing filesystem ==="
79+
adb shell sync
80+
3981
echo "=== Model directory contents ==="
4082
adb shell ls -la /data/local/tmp/llama/
4183

0 commit comments

Comments
 (0)