diff --git a/appium-tests/scripts/prepare-vm.sh b/appium-tests/scripts/prepare-vm.sh index 2216244..595f2ab 100755 --- a/appium-tests/scripts/prepare-vm.sh +++ b/appium-tests/scripts/prepare-vm.sh @@ -2,11 +2,8 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" - -BLISSOS_FILE="${BLISSOS_FILE:-Bliss-v16.9.7-x86_64-OFFICIAL-foss-20241011.iso}" -BLISSOS_URL="${BLISSOS_URL:-https://deac-riga.dl.sourceforge.net/project/blissos-x86/Official/BlissOS16/FOSS/Generic/}" -VM_DIR="${VM_DIR:-$PROJECT_ROOT/.appium-vm}" +# shellcheck source=appium-tests/scripts/vm-config.sh +source "$SCRIPT_DIR/vm-config.sh" # Check for required tools EXIT=0 @@ -20,7 +17,7 @@ done mkdir -p "$VM_DIR" -if [[ -f "$VM_DIR/kernel" && -f "$VM_DIR/initrd.img" && -f "$VM_DIR/system.efs" ]]; then +if [[ -f "$VM_KERNEL" && -f "$VM_INITRD" && -f "$VM_SYSTEM_EFS" ]]; then echo "Kernel, initrd, and system.efs already extracted to '$VM_DIR'. Skipping download and extraction." exit 0 fi @@ -48,10 +45,9 @@ echo "Extracting files from ISO..." 7z e -y -o"$VM_DIR" "$ISO_PATH" kernel initrd.img system.efs # Create virtual USB drive image -USB_IMAGE="$VM_DIR/usb-storage.qcow2" -if [[ ! -f "$USB_IMAGE" ]]; then +if [[ ! -f "$VM_USB_IMAGE" ]]; then echo "Creating virtual USB drive image..." - qemu-img create -f qcow2 "$USB_IMAGE" 2G + qemu-img create -f qcow2 "$VM_USB_IMAGE" 2G else echo "Virtual USB drive image already exists." fi diff --git a/appium-tests/scripts/run-vm.sh b/appium-tests/scripts/run-vm.sh index 8e2db75..09d68f2 100755 --- a/appium-tests/scripts/run-vm.sh +++ b/appium-tests/scripts/run-vm.sh @@ -1,18 +1,12 @@ #!/usr/bin/env bash set -euo pipefail -# Go to project root from appium-tests/scripts SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" -VM_DIR="$PROJECT_ROOT/.appium-vm" - -USB_IMAGE="$VM_DIR/usb-storage.qcow2" -SYSTEM_EFS="$VM_DIR/system.efs" -KERNEL="$VM_DIR/kernel" -INITRD="$VM_DIR/initrd.img" +# shellcheck source=appium-tests/scripts/vm-config.sh +source "$SCRIPT_DIR/vm-config.sh" # Check if files exist -for file in "$USB_IMAGE" "$SYSTEM_EFS" "$KERNEL" "$INITRD"; do +for file in "$VM_USB_IMAGE" "$VM_SYSTEM_EFS" "$VM_KERNEL" "$VM_INITRD"; do if [[ ! -f "$file" ]]; then echo "Error: $file not found. Please run appium-tests/scripts/prepare-vm.sh first." exit 1 @@ -27,20 +21,10 @@ qemu-system-x86_64 \ -cpu host \ -smp 2 \ -m 4096 \ - -kernel "$KERNEL" \ - -initrd "$INITRD" \ - -append 'root=/dev/ram0 androidboot.selinux=permissive console=ttyS0 FFMPEG_CODEC=1 FFMPEG_PREFER_C2=1' \ - -netdev user,id=network,hostfwd=tcp::5556-:5555 \ - -device virtio-net-pci,netdev=network \ + -kernel "$VM_KERNEL" \ + -initrd "$VM_INITRD" \ + -append "$VM_CMDLINE" \ -device virtio-vga-gl \ -display gtk,gl=on \ -serial stdio \ - -drive index=0,if=virtio,id=system,file="$SYSTEM_EFS",format=raw,readonly=on \ - -usb \ - -device usb-tablet,bus=usb-bus.0 \ - -device nec-usb-xhci,id=xhci \ - -device ich9-usb-uhci1,id=uhci \ - -drive if=none,id=usbstick,file="$USB_IMAGE",format=qcow2 \ - -device usb-storage,id=usbstick,bus=xhci.0,drive=usbstick,removable=on \ - -qmp unix:/tmp/qmp.sock,server=on,wait=off \ - -monitor unix:/tmp/qemu-monitor.sock,server=on,wait=off + "${VM_QEMU_FLAGS[@]}" diff --git a/appium-tests/scripts/vm-config.sh b/appium-tests/scripts/vm-config.sh new file mode 100644 index 0000000..8d338f7 --- /dev/null +++ b/appium-tests/scripts/vm-config.sh @@ -0,0 +1,44 @@ +# shellcheck shell=bash +# +# Single source of truth for the Appium e2e VM. Sourced, not executed: +# +# source "$(dirname "${BASH_SOURCE[0]}")/vm-config.sh" +# +# Used by prepare-vm.sh, run-vm.sh and the "Load VM config" step in +# .github/workflows/build-test-debug.yml, which re-exports these through $GITHUB_ENV. +# Every value can be overridden from the environment. + +BLISSOS_FILE="${BLISSOS_FILE:-Bliss-v16.9.7-x86_64-OFFICIAL-foss-20241011.iso}" +BLISSOS_URL="${BLISSOS_URL:-https://deac-riga.dl.sourceforge.net/project/blissos-x86/Official/BlissOS16/FOSS/Generic/}" + +VM_DIR="${VM_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/.appium-vm}" + +# Extracted from the ISO by prepare-vm.sh, plus the virtual USB drive it creates. +VM_KERNEL="$VM_DIR/kernel" +VM_INITRD="$VM_DIR/initrd.img" +VM_SYSTEM_EFS="$VM_DIR/system.efs" +VM_USB_IMAGE="$VM_DIR/usb-storage.qcow2" + +VM_CMDLINE='root=/dev/ram0 androidboot.selinux=permissive console=ttyS0 FFMPEG_CODEC=1 FFMPEG_PREFER_C2=1' + +# QEMU flags shared by the local and CI invocations, one argument per array element. +# Deliberately excluded because the two differ on purpose: the display backend, the serial +# routing, and -cpu/-smp/-m/-enable-kvm/-kernel/-initrd/-append (CI passes the last four as +# qemu-kvm-action inputs rather than raw flags). +# +# Both USB controllers are intentional: xhci is USB 3 (fast path), uhci is USB 1.1 (slow +# path). The tests pick between them via QEMU_USB_BUS / QEMU_USB_SLOW_BUS, see +# appium-tests/etchdroid/config.py. +VM_QEMU_FLAGS=( + -netdev user,id=network,hostfwd=tcp::5556-:5555 + -device virtio-net-pci,netdev=network + -drive "index=0,if=virtio,id=system,file=$VM_SYSTEM_EFS,format=raw,readonly=on" + -usb + -device usb-tablet,bus=usb-bus.0 + -device nec-usb-xhci,id=xhci + -device ich9-usb-uhci1,id=uhci + -drive "if=none,id=usbstick,file=$VM_USB_IMAGE,format=qcow2" + -device usb-storage,id=usbstick,bus=xhci.0,drive=usbstick,removable=on + -qmp unix:/tmp/qmp.sock,server=on,wait=off + -monitor unix:/tmp/qemu-monitor.sock,server=on,wait=off +)