OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 logging | 5 import logging |
6 import os | 6 import os |
7 import posixpath | 7 import posixpath |
8 import re | 8 import re |
9 import sys | 9 import sys |
10 import tempfile | 10 import tempfile |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 ('LargeTest', 5 * 60), | 48 ('LargeTest', 5 * 60), |
49 ('MediumTest', 3 * 60), | 49 ('MediumTest', 3 * 60), |
50 ('SmallTest', 1 * 60), | 50 ('SmallTest', 1 * 60), |
51 ] | 51 ] |
52 | 52 |
53 LOGCAT_FILTERS = ['*:e', 'chromium:v', 'cr_*:v', 'DEBUG:I'] | 53 LOGCAT_FILTERS = ['*:e', 'chromium:v', 'cr_*:v', 'DEBUG:I'] |
54 | 54 |
55 EXTRA_SCREENSHOT_FILE = ( | 55 EXTRA_SCREENSHOT_FILE = ( |
56 'org.chromium.base.test.ScreenshotOnFailureStatement.ScreenshotFile') | 56 'org.chromium.base.test.ScreenshotOnFailureStatement.ScreenshotFile') |
57 | 57 |
| 58 EXTRA_UI_CAPTURE_DIR = ( |
| 59 'org.chromium.base.test.util.Screenshooter.ScreenshotDir') |
| 60 |
| 61 UI_CAPTURE_DIRS = ['chromium_tests_root', 'UiCapture'] |
| 62 |
58 FEATURE_ANNOTATION = 'Feature' | 63 FEATURE_ANNOTATION = 'Feature' |
59 RENDER_TEST_FEATURE_ANNOTATION = 'RenderTest' | 64 RENDER_TEST_FEATURE_ANNOTATION = 'RenderTest' |
60 | 65 |
61 # This needs to be kept in sync with formatting in |RenderUtils.imageName| | 66 # This needs to be kept in sync with formatting in |RenderUtils.imageName| |
62 RE_RENDER_IMAGE_NAME = re.compile( | 67 RE_RENDER_IMAGE_NAME = re.compile( |
63 r'(?P<test_class>\w+)\.' | 68 r'(?P<test_class>\w+)\.' |
64 r'(?P<description>\w+)\.' | 69 r'(?P<description>\w+)\.' |
65 r'(?P<device_model>\w+)\.' | 70 r'(?P<device_model>\w+)\.' |
66 r'(?P<orientation>port|land)\.png') | 71 r'(?P<orientation>port|land)\.png') |
67 | 72 |
(...skipping 17 matching lines...) Expand all Loading... |
85 | 90 |
86 _CURRENT_FOCUS_CRASH_RE = re.compile( | 91 _CURRENT_FOCUS_CRASH_RE = re.compile( |
87 r'\s*mCurrentFocus.*Application (Error|Not Responding): (\S+)}') | 92 r'\s*mCurrentFocus.*Application (Error|Not Responding): (\S+)}') |
88 | 93 |
89 | 94 |
90 class LocalDeviceInstrumentationTestRun( | 95 class LocalDeviceInstrumentationTestRun( |
91 local_device_test_run.LocalDeviceTestRun): | 96 local_device_test_run.LocalDeviceTestRun): |
92 def __init__(self, env, test_instance): | 97 def __init__(self, env, test_instance): |
93 super(LocalDeviceInstrumentationTestRun, self).__init__(env, test_instance) | 98 super(LocalDeviceInstrumentationTestRun, self).__init__(env, test_instance) |
94 self._flag_changers = {} | 99 self._flag_changers = {} |
| 100 self._ui_capture_dir = dict() |
95 | 101 |
96 #override | 102 #override |
97 def TestPackage(self): | 103 def TestPackage(self): |
98 return self._test_instance.suite | 104 return self._test_instance.suite |
99 | 105 |
100 #override | 106 #override |
101 def SetUp(self): | 107 def SetUp(self): |
102 @local_device_environment.handle_shard_failures_with( | 108 @local_device_environment.handle_shard_failures_with( |
103 self._env.BlacklistDevice) | 109 self._env.BlacklistDevice) |
104 @trace_event.traced | 110 @trace_event.traced |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 logging.error("Couldn't set flags: no cmdline_file") | 215 logging.error("Couldn't set flags: no cmdline_file") |
210 else: | 216 else: |
211 self._CreateFlagChangerIfNeeded(dev) | 217 self._CreateFlagChangerIfNeeded(dev) |
212 logging.debug('Attempting to set flags: %r', | 218 logging.debug('Attempting to set flags: %r', |
213 self._test_instance.flags) | 219 self._test_instance.flags) |
214 self._flag_changers[str(dev)].AddFlags(self._test_instance.flags) | 220 self._flag_changers[str(dev)].AddFlags(self._test_instance.flags) |
215 | 221 |
216 valgrind_tools.SetChromeTimeoutScale( | 222 valgrind_tools.SetChromeTimeoutScale( |
217 dev, self._test_instance.timeout_scale) | 223 dev, self._test_instance.timeout_scale) |
218 | 224 |
| 225 @trace_event.traced |
| 226 def setup_ui_capture_dir(): |
| 227 # Make sure the UI capture directory exists and is empty by deleting |
| 228 # and recreating it. |
| 229 # TODO (aberent) once DeviceTempDir exists use it here. |
| 230 self._ui_capture_dir[dev] = posixpath.join(dev.GetExternalStoragePath(), |
| 231 *UI_CAPTURE_DIRS) |
| 232 |
| 233 if dev.PathExists(self._ui_capture_dir[dev]): |
| 234 dev.RunShellCommand(['rm', '-rf', self._ui_capture_dir[dev]]) |
| 235 dev.RunShellCommand(['mkdir', self._ui_capture_dir[dev]]) |
| 236 |
219 steps += [set_debug_app, edit_shared_prefs, push_test_data, | 237 steps += [set_debug_app, edit_shared_prefs, push_test_data, |
220 create_flag_changer] | 238 create_flag_changer, setup_ui_capture_dir] |
221 if self._env.concurrent_adb: | 239 if self._env.concurrent_adb: |
222 reraiser_thread.RunAsync(steps) | 240 reraiser_thread.RunAsync(steps) |
223 else: | 241 else: |
224 for step in steps: | 242 for step in steps: |
225 step() | 243 step() |
226 if self._test_instance.store_tombstones: | 244 if self._test_instance.store_tombstones: |
227 tombstones.ClearAllTombstones(dev) | 245 tombstones.ClearAllTombstones(dev) |
228 | 246 |
229 self._env.parallel_devices.pMap( | 247 self._env.parallel_devices.pMap( |
230 individual_device_set_up, | 248 individual_device_set_up, |
231 self._test_instance.GetDataDependencies()) | 249 self._test_instance.GetDataDependencies()) |
232 | 250 |
233 #override | 251 #override |
234 def TearDown(self): | 252 def TearDown(self): |
235 @local_device_environment.handle_shard_failures_with( | 253 @local_device_environment.handle_shard_failures_with( |
236 self._env.BlacklistDevice) | 254 self._env.BlacklistDevice) |
237 @trace_event.traced | 255 @trace_event.traced |
238 def individual_device_tear_down(dev): | 256 def individual_device_tear_down(dev): |
239 if str(dev) in self._flag_changers: | 257 if str(dev) in self._flag_changers: |
240 self._flag_changers[str(dev)].Restore() | 258 self._flag_changers[str(dev)].Restore() |
241 | 259 |
242 # Remove package-specific configuration | 260 # Remove package-specific configuration |
243 dev.RunShellCommand(['am', 'clear-debug-app'], check_return=True) | 261 dev.RunShellCommand(['am', 'clear-debug-app'], check_return=True) |
244 | 262 |
245 valgrind_tools.SetChromeTimeoutScale(dev, None) | 263 valgrind_tools.SetChromeTimeoutScale(dev, None) |
246 | 264 |
| 265 if self._test_instance.ui_screenshot_dir: |
| 266 pull_ui_screen_captures(dev) |
| 267 |
| 268 @trace_event.traced |
| 269 def pull_ui_screen_captures(dev): |
| 270 file_names = dev.ListDirectory(self._ui_capture_dir[dev]) |
| 271 target_path = self._test_instance.ui_screenshot_dir |
| 272 if not os.path.exists(target_path): |
| 273 os.makedirs(target_path) |
| 274 |
| 275 for file_name in file_names: |
| 276 dev.PullFile(posixpath.join(self._ui_capture_dir[dev], file_name), |
| 277 target_path) |
| 278 |
247 self._env.parallel_devices.pMap(individual_device_tear_down) | 279 self._env.parallel_devices.pMap(individual_device_tear_down) |
248 | 280 |
249 def _CreateFlagChangerIfNeeded(self, device): | 281 def _CreateFlagChangerIfNeeded(self, device): |
250 if not str(device) in self._flag_changers: | 282 if not str(device) in self._flag_changers: |
251 self._flag_changers[str(device)] = flag_changer.FlagChanger( | 283 self._flag_changers[str(device)] = flag_changer.FlagChanger( |
252 device, self._test_instance.package_info.cmdline_file) | 284 device, self._test_instance.package_info.cmdline_file) |
253 | 285 |
254 #override | 286 #override |
255 def _CreateShards(self, tests): | 287 def _CreateShards(self, tests): |
256 return tests | 288 return tests |
(...skipping 28 matching lines...) Expand all Loading... |
285 extras['coverageFile'] = coverage_device_file | 317 extras['coverageFile'] = coverage_device_file |
286 # Save screenshot if screenshot dir is specified (save locally) or if | 318 # Save screenshot if screenshot dir is specified (save locally) or if |
287 # a GS bucket is passed (save in cloud). | 319 # a GS bucket is passed (save in cloud). |
288 screenshot_device_file = None | 320 screenshot_device_file = None |
289 if (self._test_instance.screenshot_dir or | 321 if (self._test_instance.screenshot_dir or |
290 self._test_instance.gs_results_bucket): | 322 self._test_instance.gs_results_bucket): |
291 screenshot_device_file = device_temp_file.DeviceTempFile( | 323 screenshot_device_file = device_temp_file.DeviceTempFile( |
292 device.adb, suffix='.png', dir=device.GetExternalStoragePath()) | 324 device.adb, suffix='.png', dir=device.GetExternalStoragePath()) |
293 extras[EXTRA_SCREENSHOT_FILE] = screenshot_device_file.name | 325 extras[EXTRA_SCREENSHOT_FILE] = screenshot_device_file.name |
294 | 326 |
| 327 extras[EXTRA_UI_CAPTURE_DIR] = self._ui_capture_dir[device] |
| 328 |
295 if isinstance(test, list): | 329 if isinstance(test, list): |
296 if not self._test_instance.driver_apk: | 330 if not self._test_instance.driver_apk: |
297 raise Exception('driver_apk does not exist. ' | 331 raise Exception('driver_apk does not exist. ' |
298 'Please build it and try again.') | 332 'Please build it and try again.') |
299 if any(t.get('is_junit4') for t in test): | 333 if any(t.get('is_junit4') for t in test): |
300 raise Exception('driver apk does not support JUnit4 tests') | 334 raise Exception('driver apk does not support JUnit4 tests') |
301 | 335 |
302 def name_and_timeout(t): | 336 def name_and_timeout(t): |
303 n = instrumentation_test_instance.GetTestName(t) | 337 n = instrumentation_test_instance.GetTestName(t) |
304 i = self._GetTimeoutFromAnnotations(t['annotations'], n) | 338 i = self._GetTimeoutFromAnnotations(t['annotations'], n) |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) | 661 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) |
628 | 662 |
629 return timeout | 663 return timeout |
630 | 664 |
631 def _IsRenderTest(test): | 665 def _IsRenderTest(test): |
632 """Determines if a test or list of tests has a RenderTest amongst them.""" | 666 """Determines if a test or list of tests has a RenderTest amongst them.""" |
633 if not isinstance(test, list): | 667 if not isinstance(test, list): |
634 test = [test] | 668 test = [test] |
635 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( | 669 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( |
636 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) | 670 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) |
OLD | NEW |