11#! /bin/bash
2- #
32# Run unit tests on a local Android device.
4- #
5- # Prerequisites:
6- # - Godot Engine 4.5 or later with Android export templates installed
7- # - Android SDK with ADB (Android Debug Bridge) tools
8- # - Android device connected and authorized for debugging
93
104# Configuration
11- TEST_TIMEOUT=60 # seconds
5+ TEST_TIMEOUT=120 # seconds
126INSTALL_RETRIES=5
137LAUNCH_RETRIES=3
148LOCKSCREEN_RETRIES=20
9+ LOGCAT_FILTERS=" Godot,godot,sentry-godot,sentry-native"
1510
1611# Formatted output
1712highlight () { echo -e " \033[1;34m$1 \033[0m" ; }
@@ -35,6 +30,51 @@ abort() {
3530 exit 1
3631}
3732
33+ # Display usage information
34+ usage () {
35+ echo " Usage: $0 [OPTIONS]"
36+ echo " "
37+ echo " Run unit tests on a local Android device."
38+ echo " "
39+ echo " OPTIONS:"
40+ echo " -v, --verbose Enable additional output"
41+ echo " -h, --help Display this help message"
42+ echo " "
43+ echo " PREREQUISITES:"
44+ echo " - Godot Engine 4.5 or later with Android export templates installed"
45+ echo " - Android SDK with ADB (Android Debug Bridge) tools"
46+ echo " - Android device connected and authorized for debugging"
47+ echo " "
48+ echo " ENVIRONMENT VARIABLES:"
49+ echo " GODOT Path to Godot executable (if not in PATH)"
50+ }
51+
52+ # Parse command line options
53+ verbose=false
54+
55+ while [[ $# -gt 0 ]]; do
56+ case $1 in
57+ --verbose|-v)
58+ verbose=true
59+ shift
60+ ;;
61+ --help|-h)
62+ usage
63+ exit 0
64+ ;;
65+ -* )
66+ error " Unknown option: $1 "
67+ usage
68+ exit 1
69+ ;;
70+ * )
71+ error " Unexpected argument: $1 "
72+ usage
73+ exit 1
74+ ;;
75+ esac
76+ done
77+
3878highlight " Exporting project..."
3979
4080# Export project to "exports/android.apk".
@@ -61,6 +101,10 @@ for i in $(seq 1 $INSTALL_RETRIES); do
61101 fi
62102done
63103
104+ # Enable Sentry Android output if verbose
105+ if [ " $verbose " = true ]; then
106+ LOGCAT_FILTERS=" $LOGCAT_FILTERS ,Sentry"
107+ fi
64108
65109# Run tests on device
66110run_tests () {
@@ -105,7 +149,7 @@ run_tests() {
105149 highlight " Reading logs..."
106150
107151 local exit_code=1 # Default general failure
108- local clean_exit=0
152+ local clean_exit=false
109153
110154 # Process logcat output
111155 while IFS= read -r line; do
@@ -119,11 +163,11 @@ run_tests() {
119163
120164 # Check Godot exit condition
121165 if echo " $line " | grep -q " OnGodotTerminating" ; then
122- clean_exit=1
166+ clean_exit=true
123167 timeout 2 cat || true # Continue reading for a bit in case there are remaining logs
124168 break
125169 fi
126- done < <( timeout $TEST_TIMEOUT adb logcat --pid=$pid -s Godot,godot,sentry-godot,sentry-native )
170+ done < <( timeout $TEST_TIMEOUT adb logcat --pid=$pid -s $LOGCAT_FILTERS )
127171
128172 # Check if never finished
129173 if [ $exit_code -eq 1 ]; then
@@ -138,7 +182,7 @@ run_tests() {
138182 fi
139183 error " Godot app process still running"
140184 # Check if not exited cleanly
141- elif [ $clean_exit -eq 0 ]; then
185+ elif [ " $clean_exit " = false ]; then
142186 warning " Unclean exit detected. Godot possibly crashed."
143187 fi
144188
0 commit comments