def main(argv): # ANDROID_SDK_ROOT needs to be set to the location of the SDK used to launch # the emulator to find the system images upon launch. emulator_sdk = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk') os.environ['ANDROID_SDK_ROOT'] = emulator_sdk opt_parser = optparse.OptionParser(description='AVD script.') opt_parser.add_option('-n', '--num', dest='emulator_count', help='Number of emulators to launch (default is 1).', type='int', default='1') opt_parser.add_option( '--abi', default='x86', help='Platform of emulators to launch (x86 default).') opt_parser.add_option( '--api-level', dest='api_level', help='API level for the image, e.g. 19 for Android 4.4', type='int', default=constants.ANDROID_SDK_VERSION) options, _ = opt_parser.parse_args(argv[1:]) logging.basicConfig(level=logging.INFO, format='# %(asctime)-15s: %(message)s') logging.root.setLevel(logging.INFO) # Check if KVM is enabled for x86 AVD's and check for x86 system images. # TODO(andrewhayden) Since we can fix all of these with install_emulator_deps # why don't we just run it? if options.abi == 'x86': if not install_emulator_deps.CheckKVM(): logging.critical( 'ERROR: KVM must be enabled in BIOS, and installed. ' 'Enable KVM in BIOS and run install_emulator_deps.py') return 1 elif not install_emulator_deps.CheckX86Image(options.api_level): logging.critical( 'ERROR: System image for x86 AVD not installed. Run ' 'install_emulator_deps.py') return 1 if not install_emulator_deps.CheckSDK(): logging.critical('ERROR: Emulator SDK not installed. Run ' 'install_emulator_deps.py.') return 1 if not install_emulator_deps.CheckSDKPlatform(options.api_level): logging.critical( 'ERROR: Emulator SDK missing required target for API %d. ' 'Run install_emulator_deps.py.') return 1 emulator.LaunchEmulators(options.emulator_count, options.abi, options.api_level, True)
def _RunATestSuite(options, suite_name): """Run a single test suite. Helper for Dispatch() to allow stop/restart of the emulator across test bundles. If using the emulator, we start it on entry and stop it on exit. Args: options: options for running the tests. suite_name: name of the test suite being run. Returns: 0 if successful, number of failing tests otherwise. """ step_name = os.path.basename(options.test_suite).replace('-debug.apk', '') attached_devices = [] buildbot_emulators = [] if options.use_emulator: buildbot_emulators = emulator.LaunchEmulators(options.emulator_count, wait_for_boot=True) attached_devices = [e.device for e in buildbot_emulators] elif options.test_device: attached_devices = [options.test_device] else: attached_devices = android_commands.GetAttachedDevices() if not attached_devices: logging.critical('A device must be attached and online.') return 1 # Reset the test port allocation. It's important to do it before starting # to dispatch any tests. if not ports.ResetTestServerPortAllocation(): raise Exception('Failed to reset test server port.') if options.gtest_filter: logging.warning('Sharding is not possible with these configurations.') attached_devices = [attached_devices[0]] sharder = test_sharder.TestSharder(attached_devices, options.test_suite, options.gtest_filter, options.test_arguments, options.timeout, options.cleanup_test_files, options.tool, options.build_type, options.webkit) test_results = sharder.RunShardedTests() test_results.LogFull(test_type='Unit test', test_package=suite_name, build_type=options.build_type, flakiness_server=options.flakiness_dashboard_server) test_results.PrintAnnotation() for buildbot_emulator in buildbot_emulators: buildbot_emulator.Shutdown() return len(test_results.GetAllBroken())
def main(argv): option_parser = optparse.OptionParser() option_parser.add_option('-n', '--num', dest='emulator_count', help='Number of emulators to launch.', type='int', default=1) option_parser.add_option('-w', '--wait', dest='wait_for_boot', action='store_true', help='If set, wait for the emulators to boot.') options, args = option_parser.parse_args(argv) emulator.LaunchEmulators(options.emulator_count, options.wait_for_boot)
def main(argv): # ANDROID_SDK_ROOT needs to be set to the location of the SDK used to launch # the emulator to find the system images upon launch. emulator_sdk = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk') os.environ['ANDROID_SDK_ROOT'] = emulator_sdk opt_parser = optparse.OptionParser(description='AVD script.') opt_parser.add_option('-n', '--num', dest='emulator_count', help='Number of emulators to launch (default is 1).', type='int', default='1') opt_parser.add_option( '--abi', default='x86', help='Platform of emulators to launch (x86 default).') options, _ = opt_parser.parse_args(argv[1:]) logging.basicConfig(level=logging.INFO, format='# %(asctime)-15s: %(message)s') logging.root.setLevel(logging.INFO) # Check if KVM is enabled for x86 AVD's and check for x86 system images. if options.abi == 'x86': if not install_emulator_deps.CheckKVM(): logging.critical( 'ERROR: KVM must be enabled in BIOS, and installed. ' 'Enable KVM in BIOS and run install_emulator_deps.py') return 1 elif not install_emulator_deps.CheckX86Image(): logging.critical( 'ERROR: System image for x86 AVD not installed. Run ' 'install_emulator_deps.py') return 1 if not install_emulator_deps.CheckSDK(): logging.critical('ERROR: Emulator SDK not installed. Run ' 'install_emulator_deps.py.') return 1 emulator.LaunchEmulators(options.emulator_count, options.abi, True)
def _RunATestSuite(options, suite_name): """Run a single test suite. Helper for Dispatch() to allow stop/restart of the emulator across test bundles. If using the emulator, we start it on entry and stop it on exit. Args: options: options for running the tests. suite_name: name of the test suite being run. Returns: 0 if successful, number of failing tests otherwise. """ step_name = os.path.basename(options.test_suite).replace('-debug.apk', '') attached_devices = [] buildbot_emulators = [] if options.use_emulator: buildbot_emulators = emulator.LaunchEmulators(options.emulator_count, options.abi, wait_for_boot=True) attached_devices = [e.device for e in buildbot_emulators] elif options.test_device: attached_devices = [options.test_device] else: attached_devices = android_commands.GetAttachedDevices() if not attached_devices: logging.critical('A device must be attached and online.') return 1 # Reset the test port allocation. It's important to do it before starting # to dispatch any tests. if not ports.ResetTestServerPortAllocation(): raise Exception('Failed to reset test server port.') # Constructs a new TestRunner with the current options. def RunnerFactory(device, shard_index): return test_runner.TestRunner(device, options.test_suite, options.test_arguments, options.timeout, options.cleanup_test_files, options.tool, options.build_type, options.webkit, constants.GTEST_TEST_PACKAGE_NAME, constants.GTEST_TEST_ACTIVITY_NAME, constants.GTEST_COMMAND_LINE_FILE) # Get tests and split them up based on the number of devices. if options.gtest_filter: all_tests = [t for t in options.gtest_filter.split(':') if t] else: all_tests = GetAllEnabledTests(RunnerFactory, attached_devices) num_devices = len(attached_devices) tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)] tests = [t for t in tests if t] # Run tests. test_results = shard.ShardAndRunTests(RunnerFactory, attached_devices, tests, options.build_type, test_timeout=None, num_retries=options.num_retries) report_results.LogFull(results=test_results, test_type='Unit test', test_package=suite_name, build_type=options.build_type, flakiness_server=options.flakiness_dashboard_server) report_results.PrintAnnotation(test_results) for buildbot_emulator in buildbot_emulators: buildbot_emulator.Shutdown() return len(test_results.GetNotPass())