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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/local/device/local_device_instrumentation_test_run.py
diff --git a/build/android/pylib/local/device/local_device_instrumentation_test_run.py b/build/android/pylib/local/device/local_device_instrumentation_test_run.py
index c95fe6d6e9bf81d10465469fd425d253e45a56a7..a7b2d6f095cd694fa89d22efb2b5e920c4374a89 100644
--- a/build/android/pylib/local/device/local_device_instrumentation_test_run.py
+++ b/build/android/pylib/local/device/local_device_instrumentation_test_run.py
@@ -9,6 +9,7 @@ import re
import time
from devil.android import device_errors
+from devil.android import device_temp_file
from devil.android import flag_changer
from devil.android.sdk import shared_prefs
from devil.utils import reraiser_thread
@@ -132,7 +133,7 @@ class LocalDeviceInstrumentationTestRun(
logging.error("Couldn't set debug app: no package defined")
else:
dev.RunShellCommand(['am', 'set-debug-app', '--persistent',
- self._test_instance.package_info.package],
+ self._test_instance.package_info.package],
check_return=True)
@trace_event.traced
def edit_shared_prefs():
@@ -246,7 +247,8 @@ class LocalDeviceInstrumentationTestRun(
def _RunTest(self, device, test):
extras = {}
- flags = None
+ flags_to_add = []
+ flags_to_remove = []
test_timeout_scale = None
if self._test_instance.coverage_directory:
coverage_basename = '%s.ec' % ('%s_group' % test[0]['method']
@@ -257,6 +259,14 @@ class LocalDeviceInstrumentationTestRun(
coverage_device_file = os.path.join(
coverage_directory, coverage_basename)
extras['coverageFile'] = coverage_device_file
+ # Save screenshot if screenshot dir is specified (save locally) or if
+ # a GS bucket is passed (save in cloud).
+ screenshot_device_file = None
jbudorick 2017/05/08 22:32:06 optional nit: could do something here similar to w
+ if (self._test_instance.screenshot_dir or
+ self._test_instance.gs_results_bucket):
+ screenshot_device_file = device_temp_file.DeviceTempFile(
+ device.adb, suffix='.png', dir=device.GetExternalStoragePath())
+ flags_to_add.append('--screenshot-file=%s' % screenshot_device_file.name)
if isinstance(test, list):
if not self._test_instance.driver_apk:
@@ -293,7 +303,8 @@ class LocalDeviceInstrumentationTestRun(
self._test_instance.test_package, self._test_instance.test_runner)
extras['class'] = test_name
if 'flags' in test:
- flags = test['flags']
+ flags_to_add.extend(test['flags'].add)
+ flags_to_remove.extend(test['flags'].remove)
timeout = self._GetTimeoutFromAnnotations(
test['annotations'], test_display_name)
@@ -305,10 +316,10 @@ class LocalDeviceInstrumentationTestRun(
logging.info('preparing to run %s: %s', test_display_name, test)
- if flags:
+ if flags_to_add or flags_to_remove:
self._CreateFlagChangerIfNeeded(device)
self._flag_changers[str(device)].PushFlags(
- add=flags.add, remove=flags.remove)
+ add=flags_to_add, remove=flags_to_remove)
try:
device.RunShellCommand(
@@ -337,7 +348,7 @@ class LocalDeviceInstrumentationTestRun(
['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name],
check_return=True)
duration_ms = time_ms() - start_ms
- if flags:
+ if flags_to_add or flags_to_remove:
self._flag_changers[str(device)].Restore()
if test_timeout_scale:
valgrind_tools.SetChromeTimeoutScale(
@@ -354,7 +365,7 @@ class LocalDeviceInstrumentationTestRun(
result.SetLink('logcat', logcat_url)
# Update the result name if the test used flags.
- if flags:
+ if flags_to_add or flags_to_remove:
for r in results:
if r.GetName() == test_name:
r.SetName(test_display_name)
@@ -386,22 +397,9 @@ class LocalDeviceInstrumentationTestRun(
self._test_instance.gs_results_bucket) as screenshot_host_dir:
screenshot_host_dir = (
self._test_instance.screenshot_dir or screenshot_host_dir)
- if screenshot_host_dir:
- file_name = '%s-%s.png' % (
- test_display_name,
- time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()))
- screenshot_file = device.TakeScreenshot(
- os.path.join(screenshot_host_dir, file_name))
- logging.info(
- 'Saved screenshot for %s to %s.',
- test_display_name, screenshot_file)
- if self._test_instance.gs_results_bucket:
- link = google_storage_helper.upload(
- google_storage_helper.unique_name('screenshot', device=device),
- screenshot_file,
- bucket=self._test_instance.gs_results_bucket + '/screenshots')
- for result in results:
- result.SetLink('post_test_screenshot', link)
+ self._SaveScreenshot(device, screenshot_host_dir,
+ screenshot_device_file, test_display_name,
+ results)
logging.info('detected failure in %s. raw output:', test_display_name)
for l in output:
@@ -442,6 +440,33 @@ class LocalDeviceInstrumentationTestRun(
result.SetLink('tombstones', tombstones_url)
return results, None
+ def _SaveScreenshot(self, device, screenshot_host_dir, screenshot_device_file,
+ test_name, results):
+ if screenshot_host_dir:
+ screenshot_host_file = os.path.join(
+ screenshot_host_dir,
+ '%s-%s.png' % (
+ test_name,
+ time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime())))
+ if device.FileExists(screenshot_device_file.name):
+ try:
+ device.PullFile(screenshot_device_file.name, screenshot_host_file)
+ finally:
+ screenshot_device_file.close()
+
+ logging.info(
+ 'Saved screenshot for %s to %s.',
+ test_name, screenshot_host_file)
+ if self._test_instance.gs_results_bucket:
+ link = google_storage_helper.upload(
+ google_storage_helper.unique_name(
+ 'screenshot', device=device),
+ screenshot_host_file,
+ bucket=('%s/screenshots' %
+ self._test_instance.gs_results_bucket))
+ for result in results:
+ result.SetLink('post_test_screenshot', link)
+
#override
def _ShouldRetry(self, test):
if 'RetryOnFailure' in test.get('annotations', {}):

Powered by Google App Engine
This is Rietveld 408576698