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