def ParseArgs(args=None): defaults = parser.get_default_values() for k, v in defaults.__dict__.items(): if k in self.__dict__ and self.__dict__[k] != None: continue self.__dict__[k] = v ret = real_parse(args, self) # pylint: disable=E1121 if self.verbosity >= 2: logging.getLogger().setLevel(logging.DEBUG) elif self.verbosity: logging.getLogger().setLevel(logging.INFO) else: logging.getLogger().setLevel(logging.WARNING) logging.basicConfig( format='%(levelname)s:%(name)s:%(asctime)s:%(message)s') if self.device == 'list': devices = device_finder.GetDevicesMatchingOptions(self) print 'Available devices:' for device in devices: print ' ', device.name sys.exit(0) if self.browser_executable and not self.browser_type: self.browser_type = 'exact' if self.browser_type == 'list': devices = device_finder.GetDevicesMatchingOptions(self) if not devices: sys.exit(0) browser_types = {} for device in devices: try: possible_browsers = browser_finder.GetAllAvailableBrowsers( self, device) browser_types[device.name] = sorted([ browser.browser_type for browser in possible_browsers ]) except browser_finder_exceptions.BrowserFinderException as ex: print >> sys.stderr, 'ERROR: ', ex sys.exit(1) print 'Available browsers:' if len(browser_types) == 0: print ' No devices were found.' for device_name in sorted(browser_types.keys()): print ' ', device_name for browser_type in browser_types[device_name]: print ' ', browser_type sys.exit(0) # Parse browser options. self.browser_options.UpdateFromParseResults(self) return ret
def Run(self, args): possible_browser = browser_finder.FindBrowser(args) runner = typ.Runner() if self.stream: runner.host.stdout = self.stream # Telemetry seems to overload the system if we run one test per core, # so we scale things back a fair amount. Many of the telemetry tests # are long-running, so there's a limit to how much parallelism we # can effectively use for now anyway. # # It should be possible to handle multiple devices if we adjust the # browser_finder code properly, but for now we only handle one on ChromeOS. if possible_browser.platform.GetOSName() == 'chromeos': runner.args.jobs = 1 elif possible_browser.platform.GetOSName() == 'android': runner.args.jobs = len( device_finder.GetDevicesMatchingOptions(args)) print 'Running tests with %d Android device(s).' % runner.args.jobs elif possible_browser.platform.GetOSVersionName() == 'xp': # For an undiagnosed reason, XP falls over with more parallelism. # See crbug.com/388256 runner.args.jobs = max(int(args.jobs) // 4, 1) else: runner.args.jobs = max(int(args.jobs) // 2, 1) runner.args.metadata = args.metadata runner.args.passthrough = args.passthrough runner.args.path = args.path runner.args.retry_limit = args.retry_limit runner.args.test_results_server = args.test_results_server runner.args.test_type = args.test_type # Always print out test's timing info. runner.args.timing = True runner.args.top_level_dir = args.top_level_dir runner.args.verbose = args.verbosity runner.args.write_full_results_to = args.write_full_results_to runner.args.write_trace_to = args.write_trace_to runner.args.path.append(util.GetUnittestDataDir()) runner.classifier = GetClassifier(args, possible_browser) runner.context = args runner.setup_fn = _SetUpProcess runner.teardown_fn = _TearDownProcess runner.win_multiprocessing = typ.WinMultiprocessing.importable try: ret, _, _ = runner.run() except KeyboardInterrupt: print >> sys.stderr, "interrupted, exiting" ret = 130 return ret
def GetAllAvailableBrowserTypes(options): """Returns a list of available browser types. Args: options: A BrowserOptions object. Returns: A list of browser type strings. Raises: BrowserFinderException: Options are improperly set, or an error occurred. """ devices = device_finder.GetDevicesMatchingOptions(options) possible_browsers = [] for device in devices: possible_browsers.extend(GetAllAvailableBrowsers(options, device)) type_list = set([browser.browser_type for browser in possible_browsers]) type_list = list(type_list) type_list.sort() return type_list
def FindBrowser(options): """Finds the best PossibleBrowser object given a BrowserOptions object. Args: A BrowserOptions object. Returns: A PossibleBrowser object. Raises: BrowserFinderException: Options improperly set, or an error occurred. """ if options.browser_type == 'exact' and options.browser_executable == None: raise browser_finder_exceptions.BrowserFinderException( '--browser=exact requires --browser-executable to be set.') if options.browser_type != 'exact' and options.browser_executable != None: raise browser_finder_exceptions.BrowserFinderException( '--browser-executable requires --browser=exact.') if options.browser_type == 'cros-chrome' and options.cros_remote == None: raise browser_finder_exceptions.BrowserFinderException( 'browser_type=cros-chrome requires cros_remote be set.') if (options.browser_type != 'cros-chrome' and options.browser_type != 'cros-chrome-guest' and options.cros_remote != None): raise browser_finder_exceptions.BrowserFinderException( '--remote requires --browser=cros-chrome or cros-chrome-guest.') devices = device_finder.GetDevicesMatchingOptions(options) browsers = [] default_browsers = [] for device in devices: for finder in BROWSER_FINDERS: if(options.browser_type and options.browser_type != 'any' and options.browser_type not in finder.FindAllBrowserTypes(options)): continue curr_browsers = finder.FindAllAvailableBrowsers(options, device) new_default_browser = finder.SelectDefaultBrowser(curr_browsers) if new_default_browser: default_browsers.append(new_default_browser) browsers.extend(curr_browsers) if options.browser_type == None: if default_browsers: default_browser = sorted(default_browsers, key=lambda b: b.last_modification_time())[-1] logging.warning('--browser omitted. Using most recent local build: %s' % default_browser.browser_type) default_browser.UpdateExecutableIfNeeded() return default_browser if len(browsers) == 1: logging.warning('--browser omitted. Using only available browser: %s' % browsers[0].browser_type) browsers[0].UpdateExecutableIfNeeded() return browsers[0] raise browser_finder_exceptions.BrowserTypeRequiredException( '--browser must be specified. Available browsers:\n%s' % '\n'.join(sorted(set([b.browser_type for b in browsers])))) if options.browser_type == 'any': types = FindAllBrowserTypes(options) def CompareBrowsersOnTypePriority(x, y): x_idx = types.index(x.browser_type) y_idx = types.index(y.browser_type) return x_idx - y_idx browsers.sort(CompareBrowsersOnTypePriority) if len(browsers) >= 1: browsers[0].UpdateExecutableIfNeeded() return browsers[0] else: return None matching_browsers = [b for b in browsers if b.browser_type == options.browser_type and b.SupportsOptions(options)] chosen_browser = None if len(matching_browsers) == 1: chosen_browser = matching_browsers[0] elif len(matching_browsers) > 1: logging.warning('Multiple browsers of the same type found: %s' % ( repr(matching_browsers))) chosen_browser = sorted(matching_browsers, key=lambda b: b.last_modification_time())[-1] if chosen_browser: logging.info('Chose browser: %s' % (repr(chosen_browser))) chosen_browser.UpdateExecutableIfNeeded() return chosen_browser
def _SetUpProcess(child, context): # pylint: disable=W0613 args = context if args.device and args.device == 'android': android_devices = device_finder.GetDevicesMatchingOptions(args) args.device = android_devices[child.worker_num-1].guid options_for_unittests.Push(args)