Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: build/android/pylib/local/device/local_device_instrumentation_test_run.py

Issue 2451523002: Insert logcat as part of test result for android instrumentation tests. (Closed)
Patch Set: change from logcat snippet to logcat url Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
15 from pylib.base import base_test_result 16 from pylib.base import base_test_result
16 from pylib.instrumentation import instrumentation_test_instance 17 from pylib.instrumentation import instrumentation_test_instance
17 from pylib.local.device import local_device_environment 18 from pylib.local.device import local_device_environment
18 from pylib.local.device import local_device_test_run 19 from pylib.local.device import local_device_test_run
19 import tombstones 20 import tombstones
20 21
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
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
248 time_ms = lambda: int(time.time() * 1e3) 249 time_ms = lambda: int(time.time() * 1e3)
249 start_ms = time_ms() 250 start_ms = time_ms()
250 output = device.StartInstrumentation( 251 if self._test_instance.json_results_file:
251 target, raw=True, extras=extras, timeout=timeout, retries=0) 252 with logdog_logcat_monitor.LogdogLogcatMonitor(
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 logmon.Close()
259 else:
260 output = device.StartInstrumentation(
261 target, raw=True, extras=extras, timeout=timeout, retries=0)
252 finally: 262 finally:
253 device.RunShellCommand( 263 device.RunShellCommand(
254 ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name], 264 ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name],
255 check_return=True) 265 check_return=True)
256 duration_ms = time_ms() - start_ms 266 duration_ms = time_ms() - start_ms
257 if flags: 267 if flags:
258 self._flag_changers[str(device)].Restore() 268 self._flag_changers[str(device)].Restore()
259 if test_timeout_scale: 269 if test_timeout_scale:
260 valgrind_tools.SetChromeTimeoutScale( 270 valgrind_tools.SetChromeTimeoutScale(
261 device, self._test_instance.timeout_scale) 271 device, self._test_instance.timeout_scale)
262 272
263 # TODO(jbudorick): Make instrumentation tests output a JSON so this 273 # TODO(jbudorick): Make instrumentation tests output a JSON so this
264 # doesn't have to parse the output. 274 # doesn't have to parse the output.
265 result_code, result_bundle, statuses = ( 275 result_code, result_bundle, statuses = (
266 self._test_instance.ParseAmInstrumentRawOutput(output)) 276 self._test_instance.ParseAmInstrumentRawOutput(output))
267 results = self._test_instance.GenerateTestResults( 277 results = self._test_instance.GenerateTestResults(
268 result_code, result_bundle, statuses, start_ms, duration_ms) 278 result_code, result_bundle, statuses, start_ms, duration_ms)
279 for result in results:
280 result.SetLogcatUrl(logcat_url)
269 281
270 # Update the result name if the test used flags. 282 # Update the result name if the test used flags.
271 if flags: 283 if flags:
272 for r in results: 284 for r in results:
273 if r.GetName() == test_name: 285 if r.GetName() == test_name:
274 r.SetName(test_display_name) 286 r.SetName(test_display_name)
275 287
276 # Add UNKNOWN results for any missing tests. 288 # Add UNKNOWN results for any missing tests.
277 iterable_test = test if isinstance(test, list) else [test] 289 iterable_test = test if isinstance(test, list) else [test]
278 test_names = set(self._GetUniqueTestName(t) for t in iterable_test) 290 test_names = set(self._GetUniqueTestName(t) for t in iterable_test)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 timeout = v 378 timeout = v
367 break 379 break
368 else: 380 else:
369 logging.warning('Using default 1 minute timeout for %s', test_name) 381 logging.warning('Using default 1 minute timeout for %s', test_name)
370 timeout = 60 382 timeout = 60
371 383
372 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) 384 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations)
373 385
374 return timeout 386 return timeout
375 387
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698