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) if self.chromium_output_dir: os.environ['CHROMIUM_OUTPUT_DIR'] = self.chromium_output_dir if self.device == 'list': if binary_manager.NeedsInit(): binary_manager.InitDependencyManager(None) 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': if binary_manager.NeedsInit(): binary_manager.InitDependencyManager(None) 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 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 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]) # The reference build should be available for mac, linux and win, but the # desktop browser finder won't return it in the list of browsers. for browser in possible_browsers: if (browser.target_os == 'darwin' or browser.target_os.startswith('linux') or browser.target_os.startswith('win')): type_list.add('reference') break return sorted(list(type_list))
def Run(self, args): runner = typ.Runner() if self.stream: runner.host.stdout = self.stream if args.no_browser: possible_browser = None platform = platform_module.GetHostPlatform() else: possible_browser = browser_finder.FindBrowser(args) platform = possible_browser.platform # 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 platform.GetOSName() == 'chromeos': runner.args.jobs = 1 elif platform.GetOSName() == 'android': runner.args.jobs = len(device_finder.GetDevicesMatchingOptions(args)) print 'Running tests with %d Android device(s).' % runner.args.jobs elif 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 runner.args.top_level_dir = args.top_level_dir runner.args.write_full_results_to = args.write_full_results_to runner.args.write_trace_to = args.write_trace_to runner.args.list_only = args.list_only runner.args.path.append(util.GetUnittestDataDir()) # Always print out these info for the ease of debugging. runner.args.timing = True runner.args.verbose = 3 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 _SetUpProcess(child, context): # pylint: disable=W0613 ps_util.EnableListingStrayProcessesUponExitHook() if binary_manager.NeedsInit(): # Typ doesn't keep the DependencyManager initialization in the child # processes. binary_manager.InitDependencyManager(context.client_config) # We need to reset the handlers in case some other parts of telemetry already # set it to make this work. logging.getLogger().handlers = [] logging.basicConfig( level=logging.INFO, format='(%(levelname)s) %(asctime)s %(module)s.%(funcName)s:%(lineno)d ' '%(message)s') args = context if not args.disable_logging_config: logging.getLogger().handlers = [] logging.basicConfig( level=logging.INFO, format='(%(levelname)s) %(asctime)s %(module)s.%(funcName)s:%(lineno)d' ' %(message)s') 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)
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.chromium_output_dir: os.environ['CHROMIUM_OUTPUT_DIR'] = self.chromium_output_dir # Parse remote platform options. self.BuildRemotePlatformOptions() if self.remote_platform_options.device == 'list': if binary_manager.NeedsInit(): binary_manager.InitDependencyManager([]) 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': if binary_manager.NeedsInit(): binary_manager.InitDependencyManager([]) 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 if len(browser_types[device_name]) == 0: print ' No browsers found for this device' sys.exit(0) # Profiling other periods along with the story_run period leads to running # multiple profiling processes at the same time. The effects of performing # muliple CPU profiling at the same time is unclear and may generate # incorrect profiles so this will not be supported. if (len(self.interval_profiling_periods) > 1 and 'story_run' in self.interval_profiling_periods): print 'Cannot specify other periods along with the story_run period.' sys.exit(1) self.interval_profiler_options = shlex.split( self.interval_profiler_options) # Parse browser options. self.browser_options.UpdateFromParseResults(self) return ret
def FindBrowser(options): """Finds the best PossibleBrowser object given a BrowserOptions object. Args: A BrowserFinderOptions object. Returns: A PossibleBrowser object. None if browser does not exist in DUT. Raises: BrowserFinderException: Options improperly set, or an error occurred. """ if options.__class__.__name__ == '_FakeBrowserFinderOptions': return options.fake_possible_browser if options.browser_type == 'exact' and options.browser_executable is 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 is 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 = [] browser_finders = _GetBrowserFinders(options.target_platforms) 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()): 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 not browsers: return None if options.browser_type is None: if default_browsers: default_browser = max(default_browsers, key=lambda b: b.last_modification_time) 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])))) chosen_browser = None if options.browser_type == 'any': types = FindAllBrowserTypes(browser_finders) chosen_browser = min(browsers, key=lambda b: types.index(b.browser_type)) else: matching_browsers = [ b for b in browsers if b.browser_type == options.browser_type and b.SupportsOptions(options.browser_options)] if not matching_browsers: logging.warning('Cannot find any matched browser') return None if len(matching_browsers) > 1: logging.warning('Multiple browsers of the same type found: %r', matching_browsers) chosen_browser = max(matching_browsers, key=lambda b: b.last_modification_time) if chosen_browser: logging.info('Chose browser: %r', chosen_browser) chosen_browser.UpdateExecutableIfNeeded() return chosen_browser
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.__class__.__name__ == '_FakeBrowserFinderOptions': return options.fake_possible_browser 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.browser_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 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.chromium_output_dir: os.environ['CHROMIUM_OUTPUT_DIR'] = self.chromium_output_dir # Set up Android emulator if necessary. self.ParseAndroidEmulatorOptions() # Parse remote platform options. self.BuildRemotePlatformOptions() if self.remote_platform_options.device == 'list': if binary_manager.NeedsInit(): binary_manager.InitDependencyManager([]) 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': if binary_manager.NeedsInit(): binary_manager.InitDependencyManager([]) 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 if len(browser_types[device_name]) == 0: print ' No browsers found for this device' sys.exit(0) if ((self.browser_type == 'cros-chrome' or self.browser_type == 'lacros-chrome') and self.cros_remote and (self.cros_remote_ssh_port < 0)): try: self.cros_remote_ssh_port = socket.getservbyname('ssh') except OSError as e: raise RuntimeError( 'Running a CrOS test in remote mode, but failed to retrieve port ' 'used by SSH service. This likely means SSH is not installed on ' 'the system. Original error: %s' % e) # Profiling other periods along with the story_run period leads to running # multiple profiling processes at the same time. The effects of performing # muliple CPU profiling at the same time is unclear and may generate # incorrect profiles so this will not be supported. if (len(self.interval_profiling_periods) > 1 and 'story_run' in self.interval_profiling_periods): print 'Cannot specify other periods along with the story_run period.' sys.exit(1) self.interval_profiler_options = shlex.split( self.interval_profiler_options, posix=(not _IsWin())) # Parse browser options. self.browser_options.UpdateFromParseResults(self) return ret
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)