Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import datetime | 5 import datetime |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import shutil | 8 import shutil |
| 9 import tempfile | 9 import tempfile |
| 10 import threading | 10 import threading |
| 11 | 11 |
| 12 from devil.android import device_blacklist | 12 from devil.android import device_blacklist |
| 13 from devil.android import device_errors | 13 from devil.android import device_errors |
| 14 from devil.android import device_list | 14 from devil.android import device_list |
| 15 from devil.android import device_utils | 15 from devil.android import device_utils |
| 16 from devil.android import logcat_monitor | 16 from devil.android import logcat_monitor |
| 17 from devil.utils import cmd_helper | |
| 17 from devil.utils import file_utils | 18 from devil.utils import file_utils |
| 18 from devil.utils import parallelizer | 19 from devil.utils import parallelizer |
| 19 from pylib import constants | 20 from pylib import constants |
| 20 from pylib.base import environment | 21 from pylib.base import environment |
| 21 | 22 |
| 22 | 23 |
| 23 def _DeviceCachePath(device): | 24 def _DeviceCachePath(device): |
| 24 file_name = 'device_cache_%s.json' % device.adb.GetDeviceSerial() | 25 file_name = 'device_cache_%s.json' % device.adb.GetDeviceSerial() |
| 25 return os.path.join(constants.GetOutDirectory(), file_name) | 26 return os.path.join(constants.GetOutDirectory(), file_name) |
| 26 | 27 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 37 self._devices = [] | 38 self._devices = [] |
| 38 self._concurrent_adb = args.enable_concurrent_adb | 39 self._concurrent_adb = args.enable_concurrent_adb |
| 39 self._enable_device_cache = args.enable_device_cache | 40 self._enable_device_cache = args.enable_device_cache |
| 40 self._logcat_monitors = [] | 41 self._logcat_monitors = [] |
| 41 self._logcat_output_dir = args.logcat_output_dir | 42 self._logcat_output_dir = args.logcat_output_dir |
| 42 self._logcat_output_file = args.logcat_output_file | 43 self._logcat_output_file = args.logcat_output_file |
| 43 self._max_tries = 1 + args.num_retries | 44 self._max_tries = 1 + args.num_retries |
| 44 self._skip_clear_data = args.skip_clear_data | 45 self._skip_clear_data = args.skip_clear_data |
| 45 self._target_devices_file = args.target_devices_file | 46 self._target_devices_file = args.target_devices_file |
| 46 self._tool_name = args.tool | 47 self._tool_name = args.tool |
| 48 self._logdog_command = args.logdog_command.split() | |
| 49 self._logdog_stream = args.logdog_stream.split() | |
| 47 | 50 |
| 48 #override | 51 #override |
| 49 def SetUp(self): | 52 def SetUp(self): |
| 50 device_arg = 'default' | 53 device_arg = 'default' |
| 51 if self._target_devices_file: | 54 if self._target_devices_file: |
| 52 device_arg = device_list.GetPersistentDeviceList( | 55 device_arg = device_list.GetPersistentDeviceList( |
| 53 self._target_devices_file) | 56 self._target_devices_file) |
| 54 if not device_arg: | 57 if not device_arg: |
| 55 logging.warning('No target devices specified. Falling back to ' | 58 logging.warning('No target devices specified. Falling back to ' |
| 56 'running on all available devices.') | 59 'running on all available devices.') |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 #override | 121 #override |
| 119 def TearDown(self): | 122 def TearDown(self): |
| 120 # Write the cache even when not using it so that it will be ready the first | 123 # Write the cache even when not using it so that it will be ready the first |
| 121 # time that it is enabled. Writing it every time is also necessary so that | 124 # time that it is enabled. Writing it every time is also necessary so that |
| 122 # an invalid cache can be flushed just by disabling it for one run. | 125 # an invalid cache can be flushed just by disabling it for one run. |
| 123 for d in self._devices: | 126 for d in self._devices: |
| 124 cache_path = _DeviceCachePath(d) | 127 cache_path = _DeviceCachePath(d) |
| 125 with open(cache_path, 'w') as f: | 128 with open(cache_path, 'w') as f: |
| 126 f.write(d.DumpCacheData()) | 129 f.write(d.DumpCacheData()) |
| 127 logging.info('Wrote device cache: %s', cache_path) | 130 logging.info('Wrote device cache: %s', cache_path) |
| 131 logging.info('Adding device serials to logcats') | |
| 128 for m in self._logcat_monitors: | 132 for m in self._logcat_monitors: |
| 129 m.Stop() | 133 m.Stop() |
| 130 m.Close() | 134 m.Close() |
| 135 add_device_args = ['sed', '-i', '-e', | |
| 136 's/^/device({0}) /'. | |
| 137 format(m._adb.GetDeviceSerial()), | |
|
nicholaslin
2016/07/20 03:04:13
I'll change this to m.get_device_serial or somethi
| |
| 138 m.output_file] | |
| 139 cmd_helper.RunCmd(add_device_args) | |
| 131 if self._logcat_output_file: | 140 if self._logcat_output_file: |
| 132 file_utils.MergeFiles( | 141 file_utils.MergeFiles( |
| 133 self._logcat_output_file, | 142 self._logcat_output_file, |
| 134 [m.output_file for m in self._logcat_monitors]) | 143 [m.output_file for m in self._logcat_monitors]) |
| 135 shutil.rmtree(self._logcat_output_dir) | 144 shutil.rmtree(self._logcat_output_dir) |
| 145 if self._logdog_command and self._logdog_stream: | |
|
nicholaslin
2016/07/20 03:04:13
As of right now I don't have a good way to make lo
| |
| 146 logging.info('NOTE: outputs below are specific to logdog.') | |
| 147 task = str(os.environ['SWARMING_TASK_ID']) | |
| 148 prefix = ['-prefix', 'swarming/{0}/logcats'.format(task)] | |
| 149 cmd = self._logdog_command + prefix + self._logdog_stream | |
| 150 cmd_helper.RunCmd(cmd) | |
| 151 url_prefix = prefix[1].replace('/', '%2F') | |
| 152 suffix = self._logdog_stream[-1] | |
| 153 url_suffix = 'file:{0}'.format(suffix.replace('/', '_')) | |
| 154 url = 'https://luci-logdog.appspot.com/v/?s=chromium%2F{0}%2F%2B%2F{1}'.fo rmat(url_prefix, url_suffix) | |
| 155 logging.info('Logcats are at %s', url) | |
| 136 | 156 |
| 137 def BlacklistDevice(self, device, reason='local_device_failure'): | 157 def BlacklistDevice(self, device, reason='local_device_failure'): |
| 138 device_serial = device.adb.GetDeviceSerial() | 158 device_serial = device.adb.GetDeviceSerial() |
| 139 if self._blacklist: | 159 if self._blacklist: |
| 140 self._blacklist.Extend([device_serial], reason=reason) | 160 self._blacklist.Extend([device_serial], reason=reason) |
| 141 with self._devices_lock: | 161 with self._devices_lock: |
| 142 self._devices = [d for d in self._devices if str(d) != device_serial] | 162 self._devices = [d for d in self._devices if str(d) != device_serial] |
| 143 | 163 |
| OLD | NEW |