Skip to content

Commit 6b77e8a

Browse files
committed
enhance scripts: add KVM and Hypervisor.framework verification, diagnostics, and fallback logic for improved emulator setup
1 parent fcfd672 commit 6b77e8a

2 files changed

Lines changed: 66 additions & 13 deletions

File tree

tests/e2e/scripts/setup_hypervisor_macos.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ set -e
55

66
echo "Checking Hypervisor.framework for Android emulator on macOS..."
77

8-
# Hypervisor.framework is enabled by default on GitHub Actions macOS runners
9-
# Just verify it's available
10-
if sysctl -n kern.hv_support 2>/dev/null; then
11-
echo "Hypervisor.framework is available and enabled"
8+
# Check if Hypervisor.framework is available
9+
HV_SUPPORT=$(sysctl -n kern.hv_support 2>/dev/null || echo "0")
10+
11+
if [ "$HV_SUPPORT" = "1" ]; then
12+
echo "✓ Hypervisor.framework is available and enabled"
13+
echo " Hardware acceleration will be used for Android emulator"
1214
else
13-
echo "Hypervisor.framework not available"
14-
echo "Note: This may affect emulator performance"
15+
echo "⚠️ Hypervisor.framework is not available"
16+
echo " Note: The emulator will run without hardware acceleration (slower performance)"
17+
echo " This is unexpected on macOS runners and may indicate a configuration issue"
1518
fi
1619

20+
# Additional diagnostics for debugging
21+
echo ""
22+
echo "System information:"
23+
echo " Architecture: $(uname -m)"
24+
echo " macOS version: $(sw_vers -productVersion 2>/dev/null || echo 'unknown')"
25+
echo " Virtualization support: $HV_SUPPORT"
26+
27+
echo ""
1728
echo "Hypervisor.framework check completed"

tests/e2e/scripts/setup_kvm_linux.sh

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,54 @@ set -e
55

66
echo "Setting up KVM for Android emulator on Linux..."
77

8-
# Configure KVM permissions
9-
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | \
10-
sudo tee /etc/udev/rules.d/99-kvm4all.rules
8+
# Check if KVM is available
9+
if [ ! -e /dev/kvm ]; then
10+
echo "Warning: /dev/kvm not found. Checking CPU virtualization support..."
1111

12-
# Reload and apply udev rules
13-
sudo udevadm control --reload-rules
14-
sudo udevadm trigger --name-match=kvm
12+
# Check if virtualization is supported
13+
if grep -E 'vmx|svm' /proc/cpuinfo > /dev/null; then
14+
echo "CPU supports virtualization. Attempting to load KVM module..."
1515

16-
echo "KVM setup completed successfully"
16+
# Try to load KVM module based on CPU type
17+
if grep -E 'vmx' /proc/cpuinfo > /dev/null; then
18+
sudo modprobe kvm_intel || true
19+
elif grep -E 'svm' /proc/cpuinfo > /dev/null; then
20+
sudo modprobe kvm_amd || true
21+
fi
22+
23+
# For ARM systems
24+
if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then
25+
echo "ARM64 system detected. Loading KVM for ARM..."
26+
sudo modprobe kvm || true
27+
fi
28+
else
29+
echo "Warning: CPU does not support hardware virtualization"
30+
echo "Android emulator will run in software emulation mode (slower)"
31+
fi
32+
fi
33+
34+
# Only configure KVM if it exists
35+
if [ -e /dev/kvm ]; then
36+
echo "Configuring KVM permissions..."
37+
38+
# Configure KVM permissions
39+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | \
40+
sudo tee /etc/udev/rules.d/99-kvm4all.rules
41+
42+
# Reload and apply udev rules
43+
sudo udevadm control --reload-rules || true
44+
sudo udevadm trigger --name-match=kvm || true
45+
46+
# Verify KVM access
47+
if [ -r /dev/kvm ] && [ -w /dev/kvm ]; then
48+
echo "✓ KVM setup completed successfully"
49+
ls -la /dev/kvm
50+
else
51+
echo "Warning: KVM device exists but may not have correct permissions"
52+
ls -la /dev/kvm || true
53+
fi
54+
else
55+
echo "Warning: KVM not available. Emulator will use software acceleration."
56+
echo "This is expected on some CI environments and ARM systems."
57+
exit 0 # Don't fail the build
58+
fi

0 commit comments

Comments
 (0)