CI: add more options for Android emulator launcher and help section

Allow the emulator launcher to take new options that are commonly
used:
 * --window: shows the emulator window instead of running headless
 * --avd: set the emulator name instead of using the env var, this
          can be more intuitive and more expected than the env var.
 * --help: to guide users how to use this script.

Also, the script now will print a list of available AVD names to
use instead of the less obvious error of no AVD name provided
which forces the user to manually find the names first.

This also, sets the COIN_CTEST_RESULTSDIR to CWD in case
it's not set, this is the case when running as a debug VM.

Pick-to: 6.8 6.5
Change-Id: Id90ca2fddda713645e9c1621e346d73f1dc85ea1
Reviewed-by: Dimitrios Apostolou <jimis@qt.io>
(cherry picked from commit 05f46d0e54)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Assam Boudjelthia
2025-09-05 15:17:04 +03:00
committed by Qt Cherry-pick Bot
parent f841bcf220
commit 3b502d8073

View File

@@ -7,15 +7,65 @@
set -e
function print_help {
echo "Usage: [ANDROID_EMULATOR=<name>] $0 [--avd <name>] [--window] [--help]"
echo ""
echo "This script launches the Android emulator on Qt CI."
echo ""
echo "Options:"
echo " --avd <name> Set the AVD name to launch (overrides ANDROID_EMULATOR env var)"
echo " --window Show the emulator window (default is headless via -no-window)"
echo " --help Show this help message"
echo ""
}
WINDOW_ARG="-no-window"
AVD_NAME_ARG=""
while [ $# -gt 0 ]; do
arg="$1"
case "$arg" in
--help)
print_help
exit 0
;;
--window)
WINDOW_ARG=""
shift
;;
--avd)
if [ -n "$2" ]; then
AVD_NAME_ARG="$2"
shift 2
else
echo "Error: --avd requires an argument"
exit 1
fi
;;
esac
done
EMULATOR_MAX_RETRIES=3
ADB_MAX_TIMEOUT=180
EMULATOR_EXEC="$ANDROID_SDK_ROOT/emulator/emulator"
ADB_EXEC="$ANDROID_SDK_ROOT/platform-tools/adb"
if [ -z "$COIN_CTEST_RESULTSDIR" ]; then
COIN_CTEST_RESULTSDIR="$(pwd)"
fi
LOGCAT_PATH="$COIN_CTEST_RESULTSDIR/emulator_logcat_%iter.txt"
EMULATOR_RUN_LOG_PATH="$COIN_CTEST_RESULTSDIR/emulator_run_log_%iter.txt"
if [ -z "${ANDROID_EMULATOR}" ]; then
echo "No AVD name provided via ANDROID_EMULATOR env variable. Aborting!"
if [ -n "$AVD_NAME_ARG" ]; then
AVD_NAME="$AVD_NAME_ARG"
else
AVD_NAME="$ANDROID_EMULATOR"
fi
if [ -z "${AVD_NAME}" ]; then
echo "No AVD name provided via --avd option or ANDROID_EMULATOR env variable. Aborting!"
echo "Available AVDs names:"
$EMULATOR_EXEC -list-avds | sed 's/^/ /'
exit 1
fi
@@ -59,10 +109,10 @@ do
LOGCAT_PATH=${LOGCAT_PATH//%iter/${counter}}
EMULATOR_RUN_LOG_PATH=${EMULATOR_RUN_LOG_PATH//%iter/${counter}}
echo "Starting emulator ${ANDROID_EMULATOR}, try ${counter}/${EMULATOR_MAX_RETRIES}" \
echo "Starting emulator ${AVD_NAME}, try ${counter}/${EMULATOR_MAX_RETRIES}" \
| tee "${EMULATOR_RUN_LOG_PATH}"
$EMULATOR_EXEC -avd "$ANDROID_EMULATOR" \
-gpu swiftshader_indirect -no-audio -no-window -no-boot-anim \
$EMULATOR_EXEC -avd "$AVD_NAME" \
-gpu swiftshader_indirect -no-audio $WINDOW_ARG -no-boot-anim \
-cores 4 -memory 16000 -partition-size 4096 \
-detect-image-hang -restart-when-stalled -no-snapshot-save \
-no-nested-warnings -logcat '*:v' -logcat-output "${LOGCAT_PATH}" \
@@ -70,7 +120,7 @@ do
emulator_pid=$!
disown $emulator_pid
echo "Waiting ${ADB_MAX_TIMEOUT} seconds for emulated device to appear..."
echo "Waiting ${ADB_MAX_TIMEOUT} seconds for emulated device to start..."
timeout ${ADB_MAX_TIMEOUT} "$ADB_EXEC" wait-for-device
# Due to some bug in Coin/Go, we can't have the emulator command stream