| 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 time | 9 import time |
| 10 | 10 |
| 11 from devil.android import device_errors | 11 from devil.android import device_errors |
| 12 from devil.android import flag_changer | 12 from devil.android import flag_changer |
| 13 from devil.utils import reraiser_thread | 13 from devil.utils import reraiser_thread |
| 14 from pylib import valgrind_tools | 14 from pylib import valgrind_tools |
| 15 from pylib.android import logdog_logcat_monitor | |
| 16 from pylib.base import base_test_result | 15 from pylib.base import base_test_result |
| 17 from pylib.instrumentation import instrumentation_test_instance | 16 from pylib.instrumentation import instrumentation_test_instance |
| 18 from pylib.local.device import local_device_environment | 17 from pylib.local.device import local_device_environment |
| 19 from pylib.local.device import local_device_test_run | 18 from pylib.local.device import local_device_test_run |
| 20 import tombstones | 19 import tombstones |
| 21 | 20 |
| 21 |
| 22 _TAG = 'test_runner_py' | 22 _TAG = 'test_runner_py' |
| 23 | 23 |
| 24 TIMEOUT_ANNOTATIONS = [ | 24 TIMEOUT_ANNOTATIONS = [ |
| 25 ('Manual', 10 * 60 * 60), | 25 ('Manual', 10 * 60 * 60), |
| 26 ('IntegrationTest', 30 * 60), | 26 ('IntegrationTest', 30 * 60), |
| 27 ('External', 10 * 60), | 27 ('External', 10 * 60), |
| 28 ('EnormousTest', 10 * 60), | 28 ('EnormousTest', 10 * 60), |
| 29 ('LargeTest', 5 * 60), | 29 ('LargeTest', 5 * 60), |
| 30 ('MediumTest', 3 * 60), | 30 ('MediumTest', 3 * 60), |
| 31 ('SmallTest', 1 * 60), | 31 ('SmallTest', 1 * 60), |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 if flags: | 239 if flags: |
| 240 self._CreateFlagChangerIfNeeded(device) | 240 self._CreateFlagChangerIfNeeded(device) |
| 241 self._flag_changers[str(device)].PushFlags( | 241 self._flag_changers[str(device)].PushFlags( |
| 242 add=flags.add, remove=flags.remove) | 242 add=flags.add, remove=flags.remove) |
| 243 | 243 |
| 244 try: | 244 try: |
| 245 device.RunShellCommand( | 245 device.RunShellCommand( |
| 246 ['log', '-p', 'i', '-t', _TAG, 'START %s' % test_name], | 246 ['log', '-p', 'i', '-t', _TAG, 'START %s' % test_name], |
| 247 check_return=True) | 247 check_return=True) |
| 248 logcat_url = None | |
| 249 time_ms = lambda: int(time.time() * 1e3) | 248 time_ms = lambda: int(time.time() * 1e3) |
| 250 start_ms = time_ms() | 249 start_ms = time_ms() |
| 251 if self._test_instance.should_save_logcat: | 250 output = device.StartInstrumentation( |
| 252 with logdog_logcat_monitor.LogdogLogcatMonitor( | 251 target, raw=True, extras=extras, timeout=timeout, retries=0) |
| 253 device.adb, | |
| 254 'logcat_%s' % test_name.replace('#', '.')) as logmon: | |
| 255 output = device.StartInstrumentation( | |
| 256 target, raw=True, extras=extras, timeout=timeout, retries=0) | |
| 257 logcat_url = logmon.GetLogcatURL() | |
| 258 else: | |
| 259 output = device.StartInstrumentation( | |
| 260 target, raw=True, extras=extras, timeout=timeout, retries=0) | |
| 261 finally: | 252 finally: |
| 262 device.RunShellCommand( | 253 device.RunShellCommand( |
| 263 ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name], | 254 ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name], |
| 264 check_return=True) | 255 check_return=True) |
| 265 duration_ms = time_ms() - start_ms | 256 duration_ms = time_ms() - start_ms |
| 266 if flags: | 257 if flags: |
| 267 self._flag_changers[str(device)].Restore() | 258 self._flag_changers[str(device)].Restore() |
| 268 if test_timeout_scale: | 259 if test_timeout_scale: |
| 269 valgrind_tools.SetChromeTimeoutScale( | 260 valgrind_tools.SetChromeTimeoutScale( |
| 270 device, self._test_instance.timeout_scale) | 261 device, self._test_instance.timeout_scale) |
| 271 | 262 |
| 272 # TODO(jbudorick): Make instrumentation tests output a JSON so this | 263 # TODO(jbudorick): Make instrumentation tests output a JSON so this |
| 273 # doesn't have to parse the output. | 264 # doesn't have to parse the output. |
| 274 result_code, result_bundle, statuses = ( | 265 result_code, result_bundle, statuses = ( |
| 275 self._test_instance.ParseAmInstrumentRawOutput(output)) | 266 self._test_instance.ParseAmInstrumentRawOutput(output)) |
| 276 results = self._test_instance.GenerateTestResults( | 267 results = self._test_instance.GenerateTestResults( |
| 277 result_code, result_bundle, statuses, start_ms, duration_ms) | 268 result_code, result_bundle, statuses, start_ms, duration_ms) |
| 278 for result in results: | |
| 279 result.SetLogcatUrl(logcat_url) | |
| 280 | 269 |
| 281 # Update the result name if the test used flags. | 270 # Update the result name if the test used flags. |
| 282 if flags: | 271 if flags: |
| 283 for r in results: | 272 for r in results: |
| 284 if r.GetName() == test_name: | 273 if r.GetName() == test_name: |
| 285 r.SetName(test_display_name) | 274 r.SetName(test_display_name) |
| 286 | 275 |
| 287 # Add UNKNOWN results for any missing tests. | 276 # Add UNKNOWN results for any missing tests. |
| 288 iterable_test = test if isinstance(test, list) else [test] | 277 iterable_test = test if isinstance(test, list) else [test] |
| 289 test_names = set(self._GetUniqueTestName(t) for t in iterable_test) | 278 test_names = set(self._GetUniqueTestName(t) for t in iterable_test) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 timeout = v | 366 timeout = v |
| 378 break | 367 break |
| 379 else: | 368 else: |
| 380 logging.warning('Using default 1 minute timeout for %s', test_name) | 369 logging.warning('Using default 1 minute timeout for %s', test_name) |
| 381 timeout = 60 | 370 timeout = 60 |
| 382 | 371 |
| 383 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) | 372 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) |
| 384 | 373 |
| 385 return timeout | 374 return timeout |
| 386 | 375 |
| OLD | NEW |