def Dispatch(options): attached_devices = [] if 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.') test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(), options.build_type) options.test_suite = os.path.join( test_suite_dir, 'apks', constants.BROWSERTEST_SUITE_NAME + '.apk') # 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.BROWSERTEST_TEST_PACKAGE_NAME, constants.BROWSERTEST_TEST_ACTIVITY_NAME, constants.BROWSERTEST_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_enabled = gtest_dispatch.GetAllEnabledTests( RunnerFactory, attached_devices) all_tests = _FilterTests(all_enabled) # Run tests. # TODO(nileshagrawal): remove this abnormally long setup timeout once fewer # files are pushed to the devices for content_browsertests: crbug.com/138275 setup_timeout = 20 * 60 # 20 minutes test_results = shard.ShardAndRunTests(RunnerFactory, attached_devices, all_tests, options.build_type, setup_timeout=setup_timeout, test_timeout=None, num_retries=options.num_retries) report_results.LogFull(results=test_results, test_type='Unit test', test_package=constants.BROWSERTEST_SUITE_NAME, build_type=options.build_type, flakiness_server=options.flakiness_dashboard_server) report_results.PrintAnnotation(test_results)
def Dispatch(options): attached_devices = [] if 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.') test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(), options.build_type) options.test_suite = os.path.join(test_suite_dir, 'apks', CONTENT_BROWSERTEST_SUITENAME + '.apk') options.test_arguments = '--single_process %s' % options.test_arguments # Constructs a new TestRunner with the current options. def RunnerFactory(device): 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.BROWSERTEST_TEST_PACKAGE_NAME, constants.BROWSERTEST_TEST_ACTIVITY_NAME, constants.BROWSERTEST_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 = gtest_dispatch.GetAllEnabledTests(RunnerFactory, attached_devices) # Run tests. test_results = shard.ShardAndRunTests(RunnerFactory, attached_devices, all_tests, options.build_type) test_results.LogFull(test_type='Unit test', test_package=CONTENT_BROWSERTEST_SUITENAME, build_type=options.build_type, flakiness_server=options.flakiness_dashboard_server) test_results.PrintAnnotation()
def Dispatch(options): """Dispatches instrumentation tests onto connected device(s). If possible, this method will attempt to shard the tests to all connected devices. Otherwise, dispatch and run tests on one device. Args: options: Command line options. Returns: A TestRunResults object holding the results of the Java tests. Raises: Exception: when there are no attached devices. """ test_pkg = test_package.TestPackage(options.test_apk_path, options.test_apk_jar_path) tests = test_pkg._GetAllMatchingTests(options.annotations, options.exclude_annotations, options.test_filter) if not tests: logging.warning('No instrumentation tests to run with current args.') return base_test_result.TestRunResults() attached_devices = android_commands.GetAttachedDevices() if not attached_devices: raise Exception('There are no devices online.') if options.device: assert options.device in attached_devices attached_devices = [options.device] if len(attached_devices) > 1 and options.wait_for_debugger: logging.warning( 'Debugger can not be sharded, using first available device') attached_devices = attached_devices[:1] def TestRunnerFactory(device, shard_index): return test_runner.TestRunner(options, device, shard_index, test_pkg, []) return shard.ShardAndRunTests(TestRunnerFactory, attached_devices, tests, options.build_type, test_timeout=None, num_retries=options.num_retries)
def Dispatch(options): """Dispatches uiautomator tests onto connected device(s). If possible, this method will attempt to shard the tests to all connected devices. Otherwise, dispatch and run tests on one device. Args: options: Command line options. Returns: A TestRunResults object holding the results of the Java tests. Raises: Exception: when there are no attached devices. """ test_pkg = test_package.TestPackage(options.uiautomator_jar, options.uiautomator_info_jar) tests = test_pkg._GetAllMatchingTests(options.annotations, options.exclude_annotations, options.test_filter) if not tests: logging.warning('No uiautomator tests to run with current args.') return base_test_result.TestRunResults() attached_devices = android_commands.GetAttachedDevices() if not attached_devices: raise Exception('There are no devices online.') if options.device: assert options.device in attached_devices attached_devices = [options.device] def TestRunnerFactory(device, shard_index): return test_runner.TestRunner(options, device, shard_index, test_pkg, []) return shard.ShardAndRunTests(TestRunnerFactory, attached_devices, tests, options.build_type)
def Dispatch(options): """Dispatches instrumentation tests onto connected device(s). If possible, this method will attempt to shard the tests to all connected devices. Otherwise, dispatch and run tests on one device. Args: options: Command line options. Returns: A TestRunResults object holding the results of the Java tests. Raises: Exception: when there are no attached devices. """ is_uiautomator_test = False if hasattr(options, 'uiautomator_jar'): test_pkg = uiautomator_package.TestPackage( options.uiautomator_jar, options.uiautomator_info_jar) is_uiautomator_test = True else: test_pkg = test_package.TestPackage(options.test_apk_path, options.test_apk_jar_path) # The default annotation for tests which do not have any sizes annotation. default_size_annotation = 'SmallTest' def _GetTestsMissingAnnotation(test_pkg): test_size_annotations = frozenset(['Smoke', 'SmallTest', 'MediumTest', 'LargeTest', 'EnormousTest', 'FlakyTest', 'DisabledTest', 'Manual', 'PerfTest']) tests_missing_annotations = [] for test_method in test_pkg.GetTestMethods(): annotations = frozenset(test_pkg.GetTestAnnotations(test_method)) if (annotations.isdisjoint(test_size_annotations) and not test_pkg.IsPythonDrivenTest(test_method)): tests_missing_annotations.append(test_method) return sorted(tests_missing_annotations) if options.annotation: available_tests = test_pkg.GetAnnotatedTests(options.annotation) if options.annotation.count(default_size_annotation) > 0: tests_missing_annotations = _GetTestsMissingAnnotation(test_pkg) if tests_missing_annotations: logging.warning('The following tests do not contain any annotation. ' 'Assuming "%s":\n%s', default_size_annotation, '\n'.join(tests_missing_annotations)) available_tests += tests_missing_annotations else: available_tests = [m for m in test_pkg.GetTestMethods() if not test_pkg.IsPythonDrivenTest(m)] tests = [] if options.test_filter: # |available_tests| are in adb instrument format: package.path.class#test. filter_without_hash = options.test_filter.replace('#', '.') tests = [t for t in available_tests if filter_without_hash in t.replace('#', '.')] else: tests = available_tests if not tests: logging.warning('No instrumentation tests to run with current args.') return base_test_result.TestRunResults() tests *= options.number_of_runs attached_devices = android_commands.GetAttachedDevices() if not attached_devices: raise Exception('There are no devices online.') if options.device: attached_devices = [options.device] logging.info('Will run: %s', str(tests)) if len(attached_devices) > 1 and options.wait_for_debugger: logging.warning('Debugger can not be sharded, using first available device') attached_devices = attached_devices[:1] def TestRunnerFactory(device, shard_index): return test_runner.TestRunner( options, device, shard_index, test_pkg, [], is_uiautomator_test) return shard.ShardAndRunTests(TestRunnerFactory, attached_devices, tests, options.build_type)
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())