59
59
Device Information is stored in TEST_DEVICES in print_matrix_configuration.py
60
60
Example:
61
61
sdk id "system-images;android-29;google_apis;x86":
62
- --android_sdk "system-images;android-29;google_apis;x86" --build_tools_version "28 .0.3 "
62
+ --android_sdk "system-images;android-29;google_apis;x86" --build_tools_version "29 .0.2 "
63
63
64
64
Alternatively, to set an Android device, use the one of the values below:
65
65
[emulator_min, emulator_target, emulator_latest]
66
66
Example:
67
- --android_device "emulator_target" --build_tools_version "28 .0.3 "
67
+ --android_device "emulator_target" --build_tools_version "29 .0.2 "
68
68
69
69
Returns:
70
70
1: No iOS/Android integration_test apps found
92
92
_GAMELOOP_PACKAGE = "com.google.firebase.gameloop"
93
93
_RESULT_FILE = "Results1.json"
94
94
_TEST_RETRY = 3
95
+ _CMD_TIMEOUT = 300
96
+
97
+ _DEVICE_NONE = "None"
98
+ _DEVICE_ANDROID = "Android"
99
+ _DEVICE_APPLE = "Apple"
100
+
101
+ _RESET_TYPE_REBOOT = 1
102
+ _RESET_TYPE_WIPE_REBOOT = 2
95
103
96
104
FLAGS = flags .FLAGS
97
105
129
137
"android_sdk" , "system-images;android-29;google_apis;x86" ,
130
138
"See module docstring for details on how to set and get this id." )
131
139
flags .DEFINE_string (
132
- "build_tools_version" , "28 .0.3 " ,
140
+ "build_tools_version" , "29 .0.2 " ,
133
141
"android build_tools_version" )
134
142
flags .DEFINE_string (
135
143
"logfile_name" , "simulator-test" ,
@@ -501,19 +509,19 @@ def _setup_android(platform_version, build_tool_version, sdk_id):
501
509
"platforms;%s" % platform_version ,
502
510
"build-tools;%s" % build_tool_version ]
503
511
logging .info ("Install packages: %s" , " " .join (args ))
504
- subprocess . run (args = args , check = True )
512
+ _run_with_retry (args )
505
513
506
514
command = "yes | sdkmanager --licenses"
507
515
logging .info ("Accept all licenses: %s" , command )
508
- subprocess . run (command , shell = True , check = False )
516
+ _run_with_retry (command , shell = True , check = False )
509
517
510
518
args = ["sdkmanager" , sdk_id ]
511
519
logging .info ("Download an emulator: %s" , " " .join (args ))
512
- subprocess . run (args = args , check = True )
520
+ _run_with_retry (args )
513
521
514
522
args = ["sdkmanager" , "--update" ]
515
523
logging .info ("Update all installed packages: %s" , " " .join (args ))
516
- subprocess . run (args = args , check = True )
524
+ _run_with_retry (args , check = False )
517
525
518
526
519
527
def _shutdown_emulator ():
@@ -549,27 +557,43 @@ def _create_and_boot_emulator(sdk_id):
549
557
logging .info ("Wait for emulator to boot: %s" , " " .join (args ))
550
558
subprocess .run (args = args , check = True )
551
559
if FLAGS .ci :
552
- # wait extra 90 seconds to ensure emulator fully booted.
553
- time .sleep (180 )
560
+ # wait extra 210 seconds to ensure emulator fully booted.
561
+ time .sleep (210 )
554
562
else :
555
563
time .sleep (45 )
556
564
565
+ def _run_with_retry (args , shell = False , check = True , timeout = _CMD_TIMEOUT , retry_time = _TEST_RETRY , device = _DEVICE_NONE , type = _RESET_TYPE_REBOOT ):
566
+ if retry_time > 1 :
567
+ try :
568
+ subprocess .run (args , shell = shell , check = check , timeout = timeout )
569
+ except :
570
+ if device == _DEVICE_ANDROID :
571
+ _reset_emulator_on_error (type )
572
+ _run_with_retry (args , shell , check , timeout , retry_time - 1 , device , type )
573
+ else :
574
+ subprocess .run (args , shell = shell , check = check , timeout = timeout )
575
+
557
576
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 ))
577
+ def _reset_emulator_on_error (type = _RESET_TYPE_REBOOT ):
578
+ if type == _RESET_TYPE_WIPE_REBOOT :
579
+ # wipe emulator data
580
+ args = ["adb" , "shell" , "recovery" , "--wipe_data" ]
581
+ logging .info ("Erase my Emulator: %s" , " " .join (args ))
567
582
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 )
583
+
584
+ # reboot emulator: _RESET_TYPE_WIPE_REBOOT, _RESET_TYPE_REBOOT
585
+ logging .info ("game-loop test error!!! reboot emualtor..." )
586
+ args = ["adb" , "-e" , "reboot" ]
587
+ logging .info ("Reboot android emulator: %s" , " " .join (args ))
588
+ subprocess .run (args = args , check = True )
589
+ args = ["adb" , "wait-for-device" ]
590
+ logging .info ("Wait for emulator to boot: %s" , " " .join (args ))
591
+ subprocess .run (args = args , check = True )
592
+ if FLAGS .ci :
593
+ # wait extra 210 seconds to ensure emulator booted.
594
+ time .sleep (210 )
595
+ else :
596
+ time .sleep (45 )
573
597
574
598
575
599
def _get_package_name (app_path ):
@@ -599,26 +623,29 @@ def _install_android_app(app_path):
599
623
"""Install integration_test app into the emulator."""
600
624
args = ["adb" , "install" , app_path ]
601
625
logging .info ("Install testapp: %s" , " " .join (args ))
602
- subprocess . run (args = args , check = False )
626
+ _run_with_retry (args , device = _DEVICE_ANDROID , type = _RESET_TYPE_WIPE_REBOOT )
603
627
604
628
605
629
def _uninstall_android_app (package_name ):
606
630
"""Uninstall integration_test app from the emulator."""
607
631
args = ["adb" , "uninstall" , package_name ]
608
632
logging .info ("Uninstall testapp: %s" , " " .join (args ))
609
- subprocess . run (args = args , check = False )
633
+ _run_with_retry (args , device = _DEVICE_ANDROID , type = _RESET_TYPE_REBOOT )
610
634
611
635
612
636
def _install_android_gameloop_app (gameloop_project ):
613
637
os .chdir (gameloop_project )
614
- logging .info ("CD to gameloop_project: %s" , gameloop_project )
615
- _uninstall_android_app ("com.google.firebase.gameloop" )
638
+ logging .info ("cd to gameloop_project: %s" , gameloop_project )
639
+ args = ["adb" , "uninstall" , "com.google.firebase.gameloop" ]
640
+ _run_with_retry (args , check = False , device = _DEVICE_ANDROID , type = _RESET_TYPE_REBOOT )
641
+
616
642
args = ["./gradlew" , "clean" ]
617
643
logging .info ("Clean game-loop cache: %s" , " " .join (args ))
618
- subprocess .run (args = args , check = False )
644
+ _run_with_retry (args , check = False , device = _DEVICE_ANDROID , type = _RESET_TYPE_REBOOT )
645
+
619
646
args = ["./gradlew" , "installDebug" , "installDebugAndroidTest" ]
620
647
logging .info ("Installing game-loop app and test: %s" , " " .join (args ))
621
- subprocess . run (args = args , check = True )
648
+ _run_with_retry (args , device = _DEVICE_ANDROID , type = _RESET_TYPE_REBOOT )
622
649
623
650
624
651
def _run_instrumented_test ():
@@ -629,7 +656,8 @@ def _run_instrumented_test():
629
656
"-w" , "%s.test/androidx.test.runner.AndroidJUnitRunner" % _GAMELOOP_PACKAGE ]
630
657
logging .info ("Running game-loop test: %s" , " " .join (args ))
631
658
result = subprocess .run (args = args , capture_output = True , text = True , check = False )
632
- _reset_emulator_on_error (result .stdout )
659
+ if "FAILURES!!!" in result .stdout :
660
+ _reset_emulator_on_error (_RESET_TYPE_REBOOT )
633
661
634
662
635
663
def _get_android_test_log (test_package ):
0 commit comments