@@ -461,7 +461,9 @@ def _get_apple_test_log(bundle_id, app_path, device_id):
461461 return None
462462
463463 log_path = os .path .join (result .stdout .strip (), "Documents" , "GameLoopResults" , _RESULT_FILE )
464- return _read_file (log_path )
464+ log = _read_file (log_path )
465+ logging .info ("Apple test result: %s" , log )
466+ return log
465467
466468
467469def _read_file (path ):
@@ -501,12 +503,9 @@ def _setup_android(platform_version, build_tool_version, sdk_id):
501503 logging .info ("Install packages: %s" , " " .join (args ))
502504 subprocess .run (args = args , check = True )
503505
504- args = ["sdkmanager" , "--licenses" ]
505- logging .info ("Accept all licenses: %s" , " " .join (args ))
506- p_yes = subprocess .Popen (["echo" , "yes" ], stdout = subprocess .PIPE )
507- proc = subprocess .Popen (args , stdin = p_yes .stdout , stdout = subprocess .PIPE )
508- p_yes .stdout .close ()
509- proc .communicate ()
506+ command = "yes | sdkmanager --licenses"
507+ logging .info ("Accept all licenses: %s" , command )
508+ subprocess .run (command , shell = True , check = False )
510509
511510 args = ["sdkmanager" , sdk_id ]
512511 logging .info ("Download an emulator: %s" , " " .join (args ))
@@ -521,25 +520,24 @@ def _shutdown_emulator():
521520 command = "adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done"
522521 logging .info ("Kill all running emulator: %s" , command )
523522 subprocess .Popen (command , universal_newlines = True , shell = True , stdout = subprocess .PIPE )
523+ time .sleep (5 )
524+ args = ["adb" , "kill-server" ]
525+ logging .info ("Kill adb server: %s" , " " .join (args ))
526+ subprocess .run (args = args , check = False )
527+ time .sleep (5 )
528+
524529
525530def _create_and_boot_emulator (sdk_id ):
526- args = ["avdmanager" , "-s" ,
527- "create" , "avd" ,
528- "-n" , "test_emulator" ,
529- "-k" , sdk_id ,
530- "-f" ]
531- logging .info ("Create an emulator: %s" , " " .join (args ))
532- p_no = subprocess .Popen (["echo" , "no" ], stdout = subprocess .PIPE )
533- proc = subprocess .Popen (args , stdin = p_no .stdout , stdout = subprocess .PIPE )
534- p_no .stdout .close ()
535- proc .communicate ()
531+ _shutdown_emulator ()
532+
533+ command = "echo no | avdmanager -s create avd -n test_emulator -k '%s' -f" % sdk_id
534+ logging .info ("Create an emulator: %s" , command )
535+ subprocess .run (command , shell = True , check = True )
536536
537537 args = ["adb" , "start-server" ]
538538 logging .info ("Start adb server: %s" , " " .join (args ))
539539 subprocess .run (args = args , check = True )
540540
541- _shutdown_emulator ()
542-
543541 if not FLAGS .ci :
544542 command = "$ANDROID_HOME/emulator/emulator -avd test_emulator &"
545543 else :
@@ -550,14 +548,30 @@ def _create_and_boot_emulator(sdk_id):
550548 args = ["adb" , "wait-for-device" ]
551549 logging .info ("Wait for emulator to boot: %s" , " " .join (args ))
552550 subprocess .run (args = args , check = True )
553-
554551 if FLAGS .ci :
555552 # wait extra 90 seconds to ensure emulator booted.
556553 time .sleep (90 )
557554 else :
558555 time .sleep (45 )
559556
560557
558+ def _reset_emulator_on_error (instrumented_test_result ):
559+ logging .info ("game-loop test result: %s" , instrumented_test_result )
560+ if "FAILURES!!!" in instrumented_test_result :
561+ logging .info ("game-loop test error!!! reboot emualtor..." )
562+ args = ["adb" , "-e" , "reboot" ]
563+ logging .info ("Reboot android emulator: %s" , " " .join (args ))
564+ subprocess .run (args = args , check = True )
565+ args = ["adb" , "wait-for-device" ]
566+ logging .info ("Wait for emulator to boot: %s" , " " .join (args ))
567+ subprocess .run (args = args , check = True )
568+ if FLAGS .ci :
569+ # wait extra 90 seconds to ensure emulator booted.
570+ time .sleep (90 )
571+ else :
572+ time .sleep (45 )
573+
574+
561575def _get_package_name (app_path ):
562576 command = "aapt dump badging %s | awk -v FS=\" '\" '/package: name=/{print $2}'" % app_path
563577 logging .info ("Get package_name: %s" , command )
@@ -597,6 +611,11 @@ def _uninstall_android_app(package_name):
597611
598612def _install_android_gameloop_app (gameloop_project ):
599613 os .chdir (gameloop_project )
614+ logging .info ("CD to gameloop_project: %s" , gameloop_project )
615+ _uninstall_android_app ("com.google.firebase.gameloop" )
616+ args = ["./gradlew" , "clean" ]
617+ logging .info ("Clean game-loop cache: %s" , " " .join (args ))
618+ subprocess .run (args = args , check = False )
600619 args = ["./gradlew" , "installDebug" , "installDebugAndroidTest" ]
601620 logging .info ("Installing game-loop app and test: %s" , " " .join (args ))
602621 subprocess .run (args = args , check = True )
@@ -609,7 +628,8 @@ def _run_instrumented_test():
609628 args = ["adb" , "shell" , "am" , "instrument" ,
610629 "-w" , "%s.test/androidx.test.runner.AndroidJUnitRunner" % _GAMELOOP_PACKAGE ]
611630 logging .info ("Running game-loop test: %s" , " " .join (args ))
612- subprocess .run (args = args , check = False )
631+ result = subprocess .run (args = args , capture_output = True , text = True , check = False )
632+ _reset_emulator_on_error (result .stdout )
613633
614634
615635def _get_android_test_log (test_package ):
@@ -619,6 +639,7 @@ def _get_android_test_log(test_package):
619639 args = ["adb" , "shell" , "su" , "0" , "cat" , path ]
620640 logging .info ("Get android test result: %s" , " " .join (args ))
621641 result = subprocess .run (args = args , capture_output = True , text = True , check = False )
642+ logging .info ("Android test result: %s" , result .stdout )
622643 return result .stdout
623644
624645
0 commit comments