@@ -46,8 +46,8 @@ abort_on_error() {
4646
4747# Exit with code 1 and message
4848abort () {
49- error " $1 . Aborting."
50- exit 1
49+ error " $1 . Aborting."
50+ exit 1
5151}
5252
5353# Parse command line options
@@ -96,7 +96,7 @@ echo ""
9696highlight " Installing APK..."
9797adb kill-server 2> /dev/null
9898for i in $( seq 1 $INSTALL_RETRIES ) ; do
99- msg " Waiting for Android device..."
99+ msg " Waiting for Android device..."
100100 if adb wait-for-device && adb install -r ./exports/android.apk; then
101101 break
102102 elif [ $i -eq $INSTALL_RETRIES ]; then
@@ -114,95 +114,117 @@ fi
114114
115115# Run tests on device
116116run_tests () {
117- local tests=$1
118-
119- # Wait for device lockscreen to be unlocked
120- for i in $( seq 1 $LOCKSCREEN_RETRIES ) ; do
121- local lock_state=$( adb shell dumpsys window | grep mDreamingLockscreen)
122- if echo " $lock_state " | grep -q " mDreamingLockscreen=false" ; then
123- msg " Device lockscreen is unlocked and ready"
124- break
125- elif [ $i -eq $LOCKSCREEN_RETRIES ]; then
126- abort " Device lockscreen still active after $LOCKSCREEN_RETRIES attempts"
127- fi
128- warning " Device lockscreen is active, please unlock it..."
129- sleep 2
130- done
131-
132- highlight " Launching APK..."
133- for i in $( seq 1 $LAUNCH_RETRIES ) ; do
134- adb shell am start -n io.sentry.godot.project/com.godot.game.GodotApp --es SENTRY_TEST 1 --es SENTRY_TEST_INCLUDE " $tests "
135- if [ $? -eq 0 ]; then
136- # Success
137- break
138- elif [ $i -eq $LAUNCH_RETRIES ]; then
139- abort " Failed to launch APK after $LAUNCH_RETRIES attempts"
140- else
141- error " Launch attempt $i failed, retrying..."
142- sleep 1
143- fi
144- done
145-
146- # Get PID
147- local pid=" "
148- for i in $( seq 1 $PID_RETRIES ) ; do
149- pid=$( adb shell pidof io.sentry.godot.project)
150- if [ -n " $pid " ]; then
151- break
152- fi
153- sleep 1
154- done
155-
156- if [ -z " $pid " ]; then
157- error " Failed to get PID of the app"
158- return 3
159- fi
160-
161- # Start logcat, streaming to stdout and monitoring for completion
162- highlight " Reading logs..."
163-
164- local exit_code=1 # Default general failure
165- local clean_exit=0
166-
167- # Process logcat output
168- while IFS= read -r line; do
169- echo " $line "
170-
171- # Check for test run completion
172- if echo " $line " | grep -q " >>> Test run complete with code:" ; then
173- exit_code=$( echo " $line " | sed ' s/.*>>> Test run complete with code: \([0-9]*\).*/\1/' )
174- # Not quitting yet -- waiting for Godot to terminate.
175- fi
176-
177- # Check Godot exit condition
178- if echo " $line " | grep -q " OnGodotTerminating" ; then
179- clean_exit=1
180- timeout 2 cat || true # Continue reading for a bit in case there are remaining logs
181- break
182- fi
183- done < <( timeout $TEST_TIMEOUT adb logcat --pid=$pid -s $LOGCAT_FILTERS )
184-
185- # Check if never finished
186- if [ $exit_code -eq 1 ]; then
187- error " Test run was interrupted or failed to complete properly!"
188- fi
117+ local tests=$1
118+
119+ # Wait for device lockscreen to be unlocked
120+ for i in $( seq 1 $LOCKSCREEN_RETRIES ) ; do
121+ local lock_state=$( adb shell dumpsys window | grep mDreamingLockscreen)
122+ if echo " $lock_state " | grep -q " mDreamingLockscreen=false" ; then
123+ msg " Device lockscreen is unlocked and ready"
124+ break
125+ elif [ $i -eq $LOCKSCREEN_RETRIES ]; then
126+ abort " Device lockscreen still active after $LOCKSCREEN_RETRIES attempts"
127+ fi
128+ warning " Device lockscreen is active, please unlock it..."
129+ sleep 2
130+ done
131+
132+ highlight " Launching APK..."
133+ for i in $( seq 1 $LAUNCH_RETRIES ) ; do
134+ adb shell am start -n io.sentry.godot.project/com.godot.game.GodotApp --es SENTRY_TEST 1 --es SENTRY_TEST_INCLUDE " $tests "
135+ if [ $? -eq 0 ]; then
136+ # Success
137+ break
138+ elif [ $i -eq $LAUNCH_RETRIES ]; then
139+ abort " Failed to launch APK after $LAUNCH_RETRIES attempts"
140+ else
141+ error " Launch attempt $i failed, retrying..."
142+ sleep 1
143+ fi
144+ done
145+
146+ # Get PID
147+ local pid=" "
148+ for i in $( seq 1 $PID_RETRIES ) ; do
149+ pid=$( adb shell pidof io.sentry.godot.project)
150+ if [ -n " $pid " ]; then
151+ break
152+ fi
153+ sleep 1
154+ done
155+
156+ if [ -z " $pid " ]; then
157+ error " Failed to get PID of the app"
158+ return 3
159+ fi
160+
161+ # Start logcat, streaming to stdout and monitoring for completion
162+ highlight " Reading logs..."
163+ local exit_code=1 # Default general failure
164+ local clean_exit=0
165+ local logcat_cmd=" timeout $TEST_TIMEOUT adb logcat --pid=$pid -s $LOGCAT_FILTERS "
166+
167+ # Function to monitor Android app process and kill logcat if it dies
168+ monitor_app () {
169+ while true ; do
170+ local app_pid=$( adb shell pidof io.sentry.godot.project 2> /dev/null || echo " " )
171+ if [ -z " $app_pid " ]; then
172+ # App died, kill logcat
173+ pkill --full " $logcat_cmd " 2> /dev/null || true
174+ break
175+ fi
176+ sleep 1
177+ done
178+ }
179+
180+ # Start monitoring in background
181+ monitor_app &
182+ local monitor_pid=$!
183+
184+ # Process logcat output
185+ while IFS= read -r line; do
186+ echo " $line "
187+
188+ case " $line " in
189+ # Check for test run completion
190+ * " >>> Test run complete with code:" * )
191+ exit_code=$( echo " $line " | sed ' s/.*>>> Test run complete with code: \([0-9]*\).*/\1/' )
192+ # Not quitting yet -- waiting for Godot to terminate.
193+ ;;
194+ # Check Godot exit condition
195+ * " OnGodotTerminating" * )
196+ clean_exit=1
197+ timeout 2 cat || true # Continue reading for a bit in case there are remaining logs
198+ break
199+ ;;
200+ esac
201+ done < <( $logcat_cmd )
202+
203+ # Check if never finished
204+ if [ $exit_code -eq 1 ]; then
205+ error " Test run was interrupted or failed to complete properly!"
206+ fi
207+
208+ # Kill app monitor
209+ kill $monitor_pid 2> /dev/null || true
210+ wait $monitor_pid 2> /dev/null || true
189211
190212 # Check if process still running
191213 local current_pid=$( adb shell pidof io.sentry.godot.project 2> /dev/null || echo " " )
192214 if [ -n " $current_pid " ]; then
193- if [ $exit_code -eq 0 ]; then
194- exit_code=88
195- fi
215+ if [ $exit_code -eq 0 ]; then
216+ exit_code=88
217+ fi
196218 error " Godot app process still running"
197219 adb shell am force-stop io.sentry.godot.project
198220 # Check if not exited cleanly
199- elif [ $clean_exit -eq 0 ]; then
200- warning " Unclean exit detected. Godot possibly crashed."
221+ elif [ $clean_exit -eq 0 ]; then
222+ warning " Unclean exit detected. Godot possibly crashed."
201223 fi
202224
203- msg " Test run finished with code: $exit_code "
225+ msg " Test run finished with code: $exit_code "
204226
205- return $exit_code
227+ return $exit_code
206228}
207229
208230
0 commit comments