def _SetUpProcess(child, context): # pylint: disable=unused-argument ps_util.EnableListingStrayProcessesUponExitHook() # Make sure that we don't invokes cloud storage I/Os when we run the tests in # parallel. # TODO(nednguyen): always do this once telemetry tests in Chromium is updated # to prefetch files. # (https://github.com/catapult-project/catapult/issues/2192) args = context if args.disable_cloud_storage_io: os.environ[cloud_storage.DISABLE_CLOUD_STORAGE_IO] = '1' if binary_manager.NeedsInit(): # Typ doesn't keep the DependencyManager initialization in the child # processes. binary_manager.InitDependencyManager(context.client_configs) # We need to reset the handlers in case some other parts of telemetry already # set it to make this work. if not args.disable_logging_config: logging.getLogger().handlers = [] logging.basicConfig( level=logging.INFO, format='(%(levelname)s) %(asctime)s pid=%(process)d' ' %(module)s.%(funcName)s:%(lineno)d' ' %(message)s') if args.remote_platform_options.device == 'android': android_devices = android_device.FindAllAvailableDevices(args) if not android_devices: raise RuntimeError("No Android device found") android_devices.sort(key=lambda device: device.name) args.remote_platform_options.device = ( android_devices[child.worker_num - 1].guid) options_for_unittests.Push(args)
def _SetUpProcess(child, context): # pylint: disable=unused-argument 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 = android_device.FindAllAvailableDevices(args) if not android_devices: raise RuntimeError("No Android device found") android_devices.sort(key=lambda device: device.name) args.device = android_devices[child.worker_num - 1].guid options_for_unittests.Push(args)
def testAdbNoDeviceReturnsEmptyList(self, warning_mock): finder_options = browser_options.BrowserFinderOptions() with mock.patch('os.path.isabs', return_value=False): self._healthy_device_mock.return_value = [] devices = android_device.FindAllAvailableDevices(finder_options) self.assertEquals(warning_mock.call_count, 0) self.assertIsNotNone(devices) self.assertEquals(len(devices), 0)
def testAdbOneDeviceReturnsListWithOneDeviceInstance(self): finder_options = browser_options.BrowserFinderOptions() with mock.patch('os.path.isabs', return_value=False): self._healthy_device_mock.return_value = [ self._GetMockDeviceUtils('015d14fec128220c')] devices = android_device.FindAllAvailableDevices(finder_options) self.assertEquals([], self._android_device_stub.logging.warnings) self.assertIsNotNone(devices) self.assertEquals(len(devices), 1) self.assertEquals('015d14fec128220c', devices[0].device_id)
def GetDevicesMatchingOptions(options): """Returns a list of devices matching the options.""" devices = [] if not options.device or options.device == 'list': devices = _GetAllAvailableDevices(options) elif options.device == 'android': devices = android_device.FindAllAvailableDevices(options) else: devices = _GetAllAvailableDevices(options) devices = [d for d in devices if d.guid == options.device] devices.sort(key=lambda device: device.name) return devices
def _SetUpProcess(child, context): args = context.finder_options if binary_manager.NeedsInit(): # On windows, typ doesn't keep the DependencyManager initialization in the # child processes. binary_manager.InitDependencyManager(context.client_configs) if args.remote_platform_options.device == 'android': android_devices = android_device.FindAllAvailableDevices(args) if not android_devices: raise RuntimeError("No Android device found") android_devices.sort(key=lambda device: device.name) args.remote_platform_options.device = ( android_devices[child.worker_num - 1].guid) browser_test_context._global_test_context = context context.test_class.SetUpProcess()
def testAdbMultipleDevicesReturnsListWithAllDeviceInstances(self): finder_options = browser_options.BrowserFinderOptions() with mock.patch('os.path.isabs', return_value=False): self._healthy_device_mock.return_value = [ self._GetMockDeviceUtils('015d14fec128220c'), self._GetMockDeviceUtils('this0should0not0show', is_online=False), self._GetMockDeviceUtils('015d14fec128220d'), self._GetMockDeviceUtils('015d14fec128220e')] devices = android_device.FindAllAvailableDevices(finder_options) self.assertEquals([], self._android_device_stub.logging.warnings) self.assertIsNotNone(devices) self.assertEquals(len(devices), 3) self.assertEquals(devices[0].guid, '015d14fec128220c') self.assertEquals(devices[1].guid, '015d14fec128220d') self.assertEquals(devices[2].guid, '015d14fec128220e')
def testAdbMultipleDevicesReturnsListWithAllDeviceInstances( self, warning_mock): finder_options = browser_options.BrowserFinderOptions() with mock.patch('os.path.isabs', return_value=False): self._healthy_device_mock.return_value = [ self._GetMockDeviceUtils('015d14fec128220c'), self._GetMockDeviceUtils('015d14fec128220d'), self._GetMockDeviceUtils('015d14fec128220e') ] devices = android_device.FindAllAvailableDevices(finder_options) self.assertEquals(warning_mock.call_count, 0) self.assertIsNotNone(devices) self.assertEquals(len(devices), 3) self.assertEquals(devices[0].guid, '015d14fec128220c') self.assertEquals(devices[1].guid, '015d14fec128220d') self.assertEquals(devices[2].guid, '015d14fec128220e')
def GetDevicesMatchingOptions(options): """Returns a list of devices matching the options.""" devices = [] remote_platform_options = options.remote_platform_options if (not remote_platform_options.presentation.device or remote_platform_options.presentation.device == 'list'): devices = _GetAllAvailableDevices(options) elif remote_platform_options.presentation.device == 'android': devices = android_device.FindAllAvailableDevices(options) else: devices = _GetAllAvailableDevices(options) devices = [d for d in devices if d.guid == options.remote_platform_options.presentation.device] devices.sort(key=lambda presentation.device: presentation.device.name) return devices
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 fetch_reference_chrome_binary = False # Fetch all binaries needed by telemetry before we run the benchmark. if possible_browser and possible_browser.browser_type == 'reference': fetch_reference_chrome_binary = True binary_manager.FetchBinaryDependencies(platform, args.client_configs, fetch_reference_chrome_binary) # 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': android_devs = android_device.FindAllAvailableDevices(args) runner.args.jobs = len(android_devs) if runner.args.jobs == 0: raise RuntimeError("No Android device found") 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.skip = args.skip 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_dirs = args.top_level_dirs 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.shard_index = args.shard_index runner.args.total_shards = args.total_shards 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