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

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

Issue 2854823007: Move screenshot capture to Java-side. (Closed)
Patch Set: Move screenshot capture to Java-side. Created 3 years, 7 months 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
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 def set_debug_app(): 125 def set_debug_app():
126 # Set debug app in order to enable reading command line flags on user 126 # Set debug app in order to enable reading command line flags on user
127 # builds 127 # builds
128 if self._test_instance.flags: 128 if self._test_instance.flags:
129 if not self._test_instance.package_info: 129 if not self._test_instance.package_info:
130 logging.error("Couldn't set debug app: no package info") 130 logging.error("Couldn't set debug app: no package info")
131 elif not self._test_instance.package_info.package: 131 elif not self._test_instance.package_info.package:
132 logging.error("Couldn't set debug app: no package defined") 132 logging.error("Couldn't set debug app: no package defined")
133 else: 133 else:
134 dev.RunShellCommand(['am', 'set-debug-app', '--persistent', 134 dev.RunShellCommand(['am', 'set-debug-app', '--persistent',
135 self._test_instance.package_info.package], 135 self._test_instance.package_info.package],
136 check_return=True) 136 check_return=True)
137 @trace_event.traced 137 @trace_event.traced
138 def edit_shared_prefs(): 138 def edit_shared_prefs():
139 for pref in self._test_instance.edit_shared_prefs: 139 for pref in self._test_instance.edit_shared_prefs:
140 prefs = shared_prefs.SharedPrefs(dev, pref['package'], 140 prefs = shared_prefs.SharedPrefs(dev, pref['package'],
141 pref['filename']) 141 pref['filename'])
142 prefs.Load() 142 prefs.Load()
143 for key in pref.get('remove', []): 143 for key in pref.get('remove', []):
144 try: 144 try:
145 prefs.Remove(key) 145 prefs.Remove(key)
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 if r.GetType() == base_test_result.ResultType.UNKNOWN: 373 if r.GetType() == base_test_result.ResultType.UNKNOWN:
374 r.SetType(base_test_result.ResultType.CRASH) 374 r.SetType(base_test_result.ResultType.CRASH)
375 375
376 # Handle failures by: 376 # Handle failures by:
377 # - optionally taking a screenshot 377 # - optionally taking a screenshot
378 # - logging the raw output at INFO level 378 # - logging the raw output at INFO level
379 # - clearing the application state while persisting permissions 379 # - clearing the application state while persisting permissions
380 if any(r.GetType() not in (base_test_result.ResultType.PASS, 380 if any(r.GetType() not in (base_test_result.ResultType.PASS,
381 base_test_result.ResultType.SKIP) 381 base_test_result.ResultType.SKIP)
382 for r in results): 382 for r in results):
383 with contextlib_ext.Optional( 383 with contextlib_ext.Optional(
jbudorick 2017/05/08 17:08:39 At this point, perhaps we should pull the screensh
mikecase (-- gone --) 2017/05/08 18:35:31 Done, moved screenshot logic into new function.
384 tempfile_ext.NamedTemporaryDirectory(), 384 tempfile_ext.NamedTemporaryDirectory(),
385 self._test_instance.screenshot_dir is None and 385 self._test_instance.screenshot_dir is None and
386 self._test_instance.gs_results_bucket) as screenshot_host_dir: 386 self._test_instance.gs_results_bucket) as screenshot_host_dir:
387 screenshot_host_dir = ( 387 screenshot_host_dir = (
388 self._test_instance.screenshot_dir or screenshot_host_dir) 388 self._test_instance.screenshot_dir or screenshot_host_dir)
389
389 if screenshot_host_dir: 390 if screenshot_host_dir:
390 file_name = '%s-%s.png' % ( 391 screenshot_device_file = posixpath.join(
391 test_display_name, 392 device.GetExternalStoragePath(),
392 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime())) 393 'chromium_tests_output_root',
393 screenshot_file = device.TakeScreenshot( 394 instrumentation_test_instance.FAILURE_SCREENSHOT_FILE)
394 os.path.join(screenshot_host_dir, file_name)) 395 screenshot_host_file = os.path.join(
395 logging.info( 396 screenshot_host_dir,
396 'Saved screenshot for %s to %s.', 397 '%s-%s.png' % (
397 test_display_name, screenshot_file) 398 test_display_name,
398 if self._test_instance.gs_results_bucket: 399 time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime())))
399 link = google_storage_helper.upload( 400 if device.FileExists(screenshot_device_file):
400 google_storage_helper.unique_name('screenshot', device=device), 401 try:
401 screenshot_file, 402 device.PullFile(screenshot_device_file, screenshot_host_file)
402 bucket=self._test_instance.gs_results_bucket + '/screenshots') 403 finally:
403 for result in results: 404 device.RemovePath(screenshot_device_file)
404 result.SetLink('post_test_screenshot', link) 405
406 logging.info(
407 'Saved screenshot for %s to %s.',
408 test_display_name, screenshot_host_file)
409 if self._test_instance.gs_results_bucket:
410 link = google_storage_helper.upload(
411 google_storage_helper.unique_name(
412 'screenshot', device=device),
413 screenshot_host_file,
414 bucket=('%s/screenshots' %
415 self._test_instance.gs_results_bucket))
416 for result in results:
417 result.SetLink('post_test_screenshot', link)
405 418
406 logging.info('detected failure in %s. raw output:', test_display_name) 419 logging.info('detected failure in %s. raw output:', test_display_name)
407 for l in output: 420 for l in output:
408 logging.info(' %s', l) 421 logging.info(' %s', l)
409 if (not self._env.skip_clear_data 422 if (not self._env.skip_clear_data
410 and self._test_instance.package_info): 423 and self._test_instance.package_info):
411 permissions = ( 424 permissions = (
412 self._test_instance.apk_under_test.GetPermissions() 425 self._test_instance.apk_under_test.GetPermissions()
413 if self._test_instance.apk_under_test 426 if self._test_instance.apk_under_test
414 else None) 427 else None)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 if k in annotations: 483 if k in annotations:
471 timeout = v 484 timeout = v
472 break 485 break
473 else: 486 else:
474 logging.warning('Using default 1 minute timeout for %s', test_name) 487 logging.warning('Using default 1 minute timeout for %s', test_name)
475 timeout = 60 488 timeout = 60
476 489
477 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) 490 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations)
478 491
479 return timeout 492 return timeout
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698