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 import subprocess | |
12 import uuid | |
11 | 13 |
12 from devil.android import device_blacklist | 14 from devil.android import device_blacklist |
13 from devil.android import device_errors | 15 from devil.android import device_errors |
14 from devil.android import device_list | 16 from devil.android import device_list |
15 from devil.android import device_utils | 17 from devil.android import device_utils |
16 from devil.android import logcat_monitor | 18 from devil.android import logcat_monitor |
17 from devil.utils import file_utils | 19 from devil.utils import file_utils |
18 from devil.utils import parallelizer | 20 from devil.utils import parallelizer |
19 from pylib import constants | 21 from pylib import constants |
20 from pylib.base import environment | 22 from pylib.base import environment |
(...skipping 16 matching lines...) Expand all Loading... | |
37 self._devices = [] | 39 self._devices = [] |
38 self._concurrent_adb = args.enable_concurrent_adb | 40 self._concurrent_adb = args.enable_concurrent_adb |
39 self._enable_device_cache = args.enable_device_cache | 41 self._enable_device_cache = args.enable_device_cache |
40 self._logcat_monitors = [] | 42 self._logcat_monitors = [] |
41 self._logcat_output_dir = args.logcat_output_dir | 43 self._logcat_output_dir = args.logcat_output_dir |
42 self._logcat_output_file = args.logcat_output_file | 44 self._logcat_output_file = args.logcat_output_file |
43 self._max_tries = 1 + args.num_retries | 45 self._max_tries = 1 + args.num_retries |
44 self._skip_clear_data = args.skip_clear_data | 46 self._skip_clear_data = args.skip_clear_data |
45 self._target_devices_file = args.target_devices_file | 47 self._target_devices_file = args.target_devices_file |
46 self._tool_name = args.tool | 48 self._tool_name = args.tool |
49 self._logdog_butler_dir = args.logdog_butler_dir | |
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 113 |
111 @property | 114 @property |
112 def tool(self): | 115 def tool(self): |
113 return self._tool_name | 116 return self._tool_name |
114 | 117 |
115 #override | 118 #override |
116 def TearDown(self): | 119 def TearDown(self): |
117 # Write the cache even when not using it so that it will be ready the first | 120 # Write the cache even when not using it so that it will be ready the first |
118 # time that it is enabled. Writing it every time is also necessary so that | 121 # time that it is enabled. Writing it every time is also necessary so that |
119 # an invalid cache can be flushed just by disabling it for one run. | 122 # an invalid cache can be flushed just by disabling it for one run. |
123 | |
jbudorick
2016/07/08 02:50:40
?
| |
120 for d in self._devices: | 124 for d in self._devices: |
121 cache_path = _DeviceCachePath(d) | 125 cache_path = _DeviceCachePath(d) |
122 with open(cache_path, 'w') as f: | 126 with open(cache_path, 'w') as f: |
123 f.write(d.DumpCacheData()) | 127 f.write(d.DumpCacheData()) |
124 logging.info('Wrote device cache: %s', cache_path) | 128 logging.info('Wrote device cache: %s', cache_path) |
125 for m in self._logcat_monitors: | 129 for m in self._logcat_monitors: |
126 m.Stop() | 130 m.Stop() |
127 m.Close() | 131 m.Close() |
132 #Might be redundant with usage of logdog | |
jbudorick
2016/07/08 02:50:40
Remove this.
| |
128 if self._logcat_output_file: | 133 if self._logcat_output_file: |
129 file_utils.MergeFiles( | 134 file_utils.MergeFiles( |
130 self._logcat_output_file, | 135 self._logcat_output_file, |
131 [m.output_file for m in self._logcat_monitors]) | 136 [m.output_file for m in self._logcat_monitors]) |
132 shutil.rmtree(self._logcat_output_dir) | 137 shutil.rmtree(self._logcat_output_dir) |
133 | 138 |
139 #if the logdog_butler is pushed onto the swarming slave, | |
140 #use it to output the device logcats in a unified view | |
141 elif self._logcat_output_dir and self._logdog_butler_dir: | |
142 temp_dir = tempfile.mkdtemp() | |
143 temp_file = os.path.join(temp_dir, 'logcat') | |
144 # add device serial to each line of logcat output | |
145 for m in self._logcat_monitors: | |
jbudorick
2016/07/08 02:50:40
Can we run this in parallel? https://codesearch.ch
| |
146 device_serial = (m._adb).__str__() | |
jbudorick
2016/07/08 02:50:41
1) The linter should have been unhappy about this,
| |
147 add_device_args = ['sed', '-i', '-e', | |
jbudorick
2016/07/08 02:50:40
Do this in-process rather than calling out to sed.
| |
148 's/^/device({0}) /'.format(device_serial), | |
149 m.output_file] | |
150 subprocess.check_call(add_device_args) | |
jbudorick
2016/07/08 02:50:40
Use cmd_helper instead of subprocess: https://code
| |
151 file_utils.MergeFiles(temp_file, | |
152 [m.output_file for m in self._logcat_monitors]) | |
153 butler_location = os.path.join(self._logdog_butler_dir, 'logdog_butler') | |
154 prefix = str(uuid.uuid4()) | |
155 # will be used once recipes are intergrated | |
jbudorick
2016/07/08 02:50:40
1) Commented-out code shouldn't be here.
2) What i
| |
156 # prefix = "/".join(["swarming", | |
157 # os.environ['SWARMING_TASK_ID']]) | |
158 name = temp_file | |
159 project = 'chromium' | |
160 logdog_args = [butler_location, '-log-level', 'debug', '-project', | |
jbudorick
2016/07/08 02:50:41
This knows way too much about logdog and how to ru
| |
161 project, '-prefix', prefix, | |
162 '-output', 'logdog,host=luci-logdog-dev.appspot.com', | |
163 'stream', "-source", os.path.abspath(temp_file), | |
164 '-stream', 'name=testing1234'] | |
165 | |
166 def url_constructor(project, prefix, name): | |
167 # Constucts and returns the url of where the logcats will | |
168 # be stored once logdog has streamed them to | |
169 # luci-logdog.appspot.com | |
170 | |
171 def construct_prefix(prefix): | |
172 # Constructs the logdog prefix in URL form | |
173 return prefix.replace('/', '%2F') | |
174 | |
175 def construct_name(name): | |
176 # Constructs the logdog streamname in URL form | |
177 return 'file:{0}'.format(name.replace('/', '_', 20)) | |
178 | |
179 return 'luci-logdog-dev.appspot.com/v/?s={0}%2F{1}%2F%2B%2F{2}'.format( | |
180 project, construct_prefix(prefix), construct_name(name)) | |
181 | |
182 #surpress logdog output to not clutter stdout | |
183 FNULL = open(os.devnull, 'w') | |
184 subprocess.check_call(logdog_args, stdout=FNULL, stderr=subprocess.STDOUT) | |
185 | |
186 print 'Logcats are located at {0}'.format(url_constructor(project, prefix, name)) | |
jbudorick
2016/07/08 02:50:40
No prints, please. If you want to log something, u
| |
187 shutil.rmtree(temp_dir) | |
188 | |
134 def BlacklistDevice(self, device, reason='local_device_failure'): | 189 def BlacklistDevice(self, device, reason='local_device_failure'): |
135 device_serial = device.adb.GetDeviceSerial() | 190 device_serial = device.adb.GetDeviceSerial() |
136 if self._blacklist: | 191 if self._blacklist: |
137 self._blacklist.Extend([device_serial], reason=reason) | 192 self._blacklist.Extend([device_serial], reason=reason) |
138 with self._devices_lock: | 193 with self._devices_lock: |
139 self._devices = [d for d in self._devices if str(d) != device_serial] | 194 self._devices = [d for d in self._devices if str(d) != device_serial] |
140 | 195 |
OLD | NEW |