@@ -461,7 +461,9 @@ def _get_apple_test_log(bundle_id, app_path, device_id):
461
461
return None
462
462
463
463
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
465
467
466
468
467
469
def _read_file (path ):
@@ -501,12 +503,9 @@ def _setup_android(platform_version, build_tool_version, sdk_id):
501
503
logging .info ("Install packages: %s" , " " .join (args ))
502
504
subprocess .run (args = args , check = True )
503
505
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 )
510
509
511
510
args = ["sdkmanager" , sdk_id ]
512
511
logging .info ("Download an emulator: %s" , " " .join (args ))
@@ -521,25 +520,24 @@ def _shutdown_emulator():
521
520
command = "adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done"
522
521
logging .info ("Kill all running emulator: %s" , command )
523
522
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
+
524
529
525
530
def _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 )
536
536
537
537
args = ["adb" , "start-server" ]
538
538
logging .info ("Start adb server: %s" , " " .join (args ))
539
539
subprocess .run (args = args , check = True )
540
540
541
- _shutdown_emulator ()
542
-
543
541
if not FLAGS .ci :
544
542
command = "$ANDROID_HOME/emulator/emulator -avd test_emulator &"
545
543
else :
@@ -550,14 +548,30 @@ def _create_and_boot_emulator(sdk_id):
550
548
args = ["adb" , "wait-for-device" ]
551
549
logging .info ("Wait for emulator to boot: %s" , " " .join (args ))
552
550
subprocess .run (args = args , check = True )
553
-
554
551
if FLAGS .ci :
555
552
# wait extra 90 seconds to ensure emulator booted.
556
553
time .sleep (90 )
557
554
else :
558
555
time .sleep (45 )
559
556
560
557
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
+
561
575
def _get_package_name (app_path ):
562
576
command = "aapt dump badging %s | awk -v FS=\" '\" '/package: name=/{print $2}'" % app_path
563
577
logging .info ("Get package_name: %s" , command )
@@ -597,6 +611,11 @@ def _uninstall_android_app(package_name):
597
611
598
612
def _install_android_gameloop_app (gameloop_project ):
599
613
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 )
600
619
args = ["./gradlew" , "installDebug" , "installDebugAndroidTest" ]
601
620
logging .info ("Installing game-loop app and test: %s" , " " .join (args ))
602
621
subprocess .run (args = args , check = True )
@@ -609,7 +628,8 @@ def _run_instrumented_test():
609
628
args = ["adb" , "shell" , "am" , "instrument" ,
610
629
"-w" , "%s.test/androidx.test.runner.AndroidJUnitRunner" % _GAMELOOP_PACKAGE ]
611
630
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 )
613
633
614
634
615
635
def _get_android_test_log (test_package ):
@@ -619,6 +639,7 @@ def _get_android_test_log(test_package):
619
639
args = ["adb" , "shell" , "su" , "0" , "cat" , path ]
620
640
logging .info ("Get android test result: %s" , " " .join (args ))
621
641
result = subprocess .run (args = args , capture_output = True , text = True , check = False )
642
+ logging .info ("Android test result: %s" , result .stdout )
622
643
return result .stdout
623
644
624
645
0 commit comments