diff --git a/android/pylib/local/device/local_device_environment.py b/android/pylib/local/device/local_device_environment.py index fce1d2dfc..56e867862 100644 --- a/android/pylib/local/device/local_device_environment.py +++ b/android/pylib/local/device/local_device_environment.py @@ -11,6 +11,7 @@ import threading from devil.android import device_blacklist from devil.android import device_errors +from devil.android import device_list from devil.android import device_utils from devil.android import logcat_monitor from devil.utils import file_utils @@ -41,23 +42,27 @@ class LocalDeviceEnvironment(environment.Environment): self._logcat_output_file = args.logcat_output_file self._max_tries = 1 + args.num_retries self._skip_clear_data = args.skip_clear_data + self._target_devices_file = args.target_devices_file self._tool_name = args.tool #override def SetUp(self): - available_devices = device_utils.DeviceUtils.HealthyDevices( + device_arg = 'default' + if self._target_devices_file: + device_arg = device_list.GetPersistentDeviceList( + self._target_devices_file) + if not device_arg: + logging.warning('No target devices specified. Falling back to ' + 'running on all available devices.') + device_arg = 'default' + elif self._device_serial: + device_arg = self._device_serial + + self._devices = device_utils.DeviceUtils.HealthyDevices( self._blacklist, enable_device_files_cache=self._enable_device_cache, - default_retries=self._max_tries - 1) - if not available_devices: + default_retries=self._max_tries - 1, device_arg=device_arg) + if not self._devices: raise device_errors.NoDevicesError - if self._device_serial: - self._devices = [d for d in available_devices - if d.adb.GetDeviceSerial() == self._device_serial] - if not self._devices: - raise device_errors.DeviceUnreachableError( - 'Could not find device %r' % self._device_serial) - else: - self._devices = available_devices if self._enable_device_cache: for d in self._devices: diff --git a/android/test_runner.py b/android/test_runner.py index 8f0ac08ed..8ca3ed740 100755 --- a/android/test_runner.py +++ b/android/test_runner.py @@ -227,6 +227,10 @@ def AddDeviceOptions(parser): help='Do not wipe app data between tests. Use this to ' 'speed up local development and never on bots ' '(increases flakiness)') + group.add_argument('--target-devices-file', + help='Path to file with json list of device serials to ' + 'run tests on. When not specified, all available ' + 'devices are used.') def AddGTestOptions(parser):