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 03656808ac5526b721c98a07dcbaaad76369e684..5fd1bbe0d53902d344764c1e17caf07a693dfdc7 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 |
@@ -15,21 +15,21 @@ from devil.android import crash_handler |
from devil.android import device_errors |
from devil.android import device_temp_file |
from devil.android import flag_changer |
+from devil.android import logcat_monitor |
from devil.android.tools import system_app |
from devil.utils import reraiser_thread |
from pylib import valgrind_tools |
-from pylib.android import logdog_logcat_monitor |
from pylib.base import base_test_result |
+from pylib.base import output_manager |
from pylib.constants import host_paths |
from pylib.instrumentation import instrumentation_test_instance |
from pylib.local.device import local_device_environment |
from pylib.local.device import local_device_test_run |
-from pylib.utils import google_storage_helper |
-from pylib.utils import logdog_helper |
+ |
from pylib.utils import shared_preference_utils |
+ |
from py_trace_event import trace_event |
from py_utils import contextlib_ext |
-from py_utils import tempfile_ext |
import tombstones |
with host_paths.SysPath( |
@@ -112,7 +112,8 @@ _CURRENT_FOCUS_CRASH_RE = re.compile( |
class LocalDeviceInstrumentationTestRun( |
local_device_test_run.LocalDeviceTestRun): |
def __init__(self, env, test_instance): |
- super(LocalDeviceInstrumentationTestRun, self).__init__(env, test_instance) |
+ super(LocalDeviceInstrumentationTestRun, self).__init__( |
+ env, test_instance) |
self._flag_changers = {} |
self._ui_capture_dir = dict() |
self._replace_package_contextmanager = None |
@@ -332,12 +333,9 @@ class LocalDeviceInstrumentationTestRun( |
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 |
- 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()) |
- extras[EXTRA_SCREENSHOT_FILE] = screenshot_device_file.name |
+ screenshot_device_file = device_temp_file.DeviceTempFile( |
+ device.adb, suffix='.png', dir=device.GetExternalStoragePath()) |
+ extras[EXTRA_SCREENSHOT_FILE] = screenshot_device_file.name |
extras[EXTRA_UI_CAPTURE_DIR] = self._ui_capture_dir[device] |
@@ -410,19 +408,23 @@ class LocalDeviceInstrumentationTestRun( |
test_name.replace('#', '.'), |
time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()), |
device.serial) |
- logmon = logdog_logcat_monitor.LogdogLogcatMonitor( |
- device.adb, stream_name, filter_specs=LOGCAT_FILTERS) |
- |
- with contextlib_ext.Optional( |
- logmon, self._test_instance.should_save_logcat): |
- with _LogTestEndpoints(device, test_name): |
- with contextlib_ext.Optional( |
- trace_event.trace(test_name), |
- self._env.trace_output): |
- output = device.StartInstrumentation( |
- target, raw=True, extras=extras, timeout=timeout, retries=0) |
- |
- logcat_url = logmon.GetLogcatURL() |
+ |
+ try: |
jbudorick
2017/07/19 22:45:09
It would be nice if we could make ArchiveAndDelete
mikecase (-- gone --)
2017/07/26 21:21:37
This is what I wanted, unfortunatly it didnt work
|
+ logcat_file = tempfile.NamedTemporaryFile(delete=False) |
+ with logcat_monitor.LogcatMonitor( |
+ device.adb, filter_specs=LOGCAT_FILTERS, |
+ output_file=logcat_file.name) as logmon: |
+ with _LogTestEndpoints(device, test_name): |
+ with contextlib_ext.Optional( |
+ trace_event.trace(test_name), |
+ self._env.trace_output): |
+ output = device.StartInstrumentation( |
+ target, raw=True, extras=extras, timeout=timeout, retries=0) |
+ logmon.Close() |
+ finally: |
+ logcat_url = self._env.output_manager.ArchiveAndDeleteFile( |
+ logcat_file.name, stream_name, 'logcat') |
+ |
duration_ms = time_ms() - start_ms |
if flags_to_add or flags_to_remove: |
self._flag_changers[str(device)].Restore() |
@@ -478,15 +480,8 @@ class LocalDeviceInstrumentationTestRun( |
if any(r.GetType() not in (base_test_result.ResultType.PASS, |
base_test_result.ResultType.SKIP) |
for r in results): |
- with contextlib_ext.Optional( |
- tempfile_ext.NamedTemporaryDirectory(), |
- self._test_instance.screenshot_dir is None and |
- self._test_instance.gs_results_bucket) as screenshot_host_dir: |
- screenshot_host_dir = ( |
- self._test_instance.screenshot_dir or screenshot_host_dir) |
- self._SaveScreenshot(device, screenshot_host_dir, |
- screenshot_device_file, test_display_name, |
- results) |
+ self._SaveScreenshot(device, screenshot_device_file, test_display_name, |
+ results) |
logging.info('detected failure in %s. raw output:', test_display_name) |
for l in output: |
@@ -519,49 +514,40 @@ class LocalDeviceInstrumentationTestRun( |
resolve_all_tombstones=True, |
include_stack_symbols=False, |
wipe_tombstones=True) |
- stream_name = 'tombstones_%s_%s' % ( |
- time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()), |
- device.serial) |
- tombstones_url = logdog_helper.text( |
- stream_name, '\n'.join(resolved_tombstones)) |
- result.SetLink('tombstones', tombstones_url) |
+ try: |
+ tombstone_file = tempfile.NamedTemporaryFile(delete=False) |
+ tombstone_filename = 'tombstones_%s_%s' % ( |
+ time.strftime('%Y%m%dT%H%M%S-UTC', time.gmtime()), |
+ device.serial) |
+ tombstone_file.write('\n'.join(resolved_tombstones)) |
+ tombstone_file.flush() |
+ finally: |
+ tombstones_url = self._env.output_manager.ArchiveAndDeleteFile( |
+ tombstone_file.name, tombstone_filename, 'tombstones') |
+ 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()))) |
+ def _SaveScreenshot(self, device, screenshot_device_file, test_name, results): |
+ screenshot_filename = '%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) |
+ screenshot_host_file = tempfile.NamedTemporaryFile(delete=False) |
+ try: |
+ device.PullFile(screenshot_device_file.name, |
+ screenshot_host_file.name) |
+ finally: |
+ screenshot_device_file.close() |
+ screenshot_host_file.flush() |
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)) |
+ screenshot_url = self._env.output_manager.ArchiveAndDeleteFile( |
+ screenshot_host_file.name, screenshot_filename, |
+ 'screenshot', output_manager.Datatype.IMAGE) |
for result in results: |
- result.SetLink('post_test_screenshot', link) |
+ result.SetLink('post_test_screenshot', screenshot_url) |
def _ProcessRenderTestResults( |
self, device, render_tests_device_output_dir, results): |
- # If GS results bucket is specified, will archive render result images. |
- # If render image dir is specified, will pull the render result image from |
- # the device and leave in the directory. |
- if not (bool(self._test_instance.gs_results_bucket) or |
- bool(self._test_instance.render_results_dir)): |
- return |
failure_images_device_dir = posixpath.join( |
render_tests_device_output_dir, 'failures') |
@@ -574,83 +560,69 @@ class LocalDeviceInstrumentationTestRun( |
golden_images_device_dir = posixpath.join( |
render_tests_device_output_dir, 'goldens') |
- with contextlib_ext.Optional( |
- tempfile_ext.NamedTemporaryDirectory(), |
- not bool(self._test_instance.render_results_dir)) as render_temp_dir: |
- render_host_dir = ( |
- self._test_instance.render_results_dir or render_temp_dir) |
- |
- if not os.path.exists(render_host_dir): |
- os.makedirs(render_host_dir) |
- |
- # Pull all render test results from device. |
- device.PullFile(failure_images_device_dir, render_host_dir) |
+ for failure_filename in device.ListDirectory(failure_images_device_dir): |
- if device.FileExists(diff_images_device_dir): |
- device.PullFile(diff_images_device_dir, render_host_dir) |
- else: |
- logging.error('Diff images not found on device.') |
+ try: |
+ failure_image_host_file = tempfile.NamedTemporaryFile(delete=False) |
+ device.PullFile( |
+ posixpath.join(failure_images_device_dir, failure_filename), |
+ failure_image_host_file) |
+ failure_image_host_file.flush() |
+ finally: |
+ failure_link = self._env.output_manager.ArchiveAndDeleteFile( |
+ failure_image_host_file.name, 'fail_%s' % failure_filename, |
+ 'render_tests', output_manager.Datatype.IMAGE) |
- if device.FileExists(golden_images_device_dir): |
- device.PullFile(golden_images_device_dir, render_host_dir) |
- else: |
- logging.error('Golden images not found on device.') |
- |
- # Upload results to Google Storage. |
- if self._test_instance.gs_results_bucket: |
- self._UploadRenderTestResults(render_host_dir, results) |
- |
- def _UploadRenderTestResults(self, render_host_dir, results): |
- render_tests_bucket = ( |
- self._test_instance.gs_results_bucket + '/render_tests') |
- |
- for failure_filename in os.listdir( |
- os.path.join(render_host_dir, 'failures')): |
- m = RE_RENDER_IMAGE_NAME.match(failure_filename) |
- if not m: |
- logging.warning('Unexpected file in render test failures: %s', |
- failure_filename) |
- continue |
- |
- failure_filepath = os.path.join( |
- render_host_dir, 'failures', failure_filename) |
- failure_link = google_storage_helper.upload_content_addressed( |
- failure_filepath, bucket=render_tests_bucket) |
- |
- golden_filepath = os.path.join( |
- render_host_dir, 'goldens', failure_filename) |
- if os.path.exists(golden_filepath): |
- golden_link = google_storage_helper.upload_content_addressed( |
- golden_filepath, bucket=render_tests_bucket) |
+ if device.PathExists( |
+ posixpath.join(golden_images_device_dir, failure_filename)): |
+ try: |
+ golden_image_host_file = tempfile.NamedTemporaryFile(delete=False) |
+ device.PullFile( |
+ posixpath.join(golden_images_device_dir, failure_filename), |
+ golden_image_host_file) |
+ golden_image_host_file.flush() |
+ finally: |
+ golden_link = self._env.output_manager.ArchiveAndDeleteFile( |
+ golden_image_host_file.name, 'golden_%s' % failure_filename, |
+ 'render_tests', output_manager.Datatype.IMAGE) |
else: |
golden_link = '' |
- diff_filepath = os.path.join( |
- render_host_dir, 'diffs', failure_filename) |
- if os.path.exists(diff_filepath): |
- diff_link = google_storage_helper.upload_content_addressed( |
- diff_filepath, bucket=render_tests_bucket) |
+ if device.PathExists( |
+ posixpath.join(diff_images_device_dir, failure_filename)): |
+ try: |
+ diff_image_host_file = tempfile.NamedTemporaryFile(delete=False) |
+ device.PullFile( |
+ posixpath.join(diff_images_device_dir, failure_filename), |
+ diff_image_host_file) |
+ diff_image_host_file.flush() |
+ finally: |
+ diff_link = self._env.output_manager.ArchiveAndDeleteFile( |
+ diff_image_host_file.name, 'diff_%s' % failure_filename, |
+ 'render_tests', output_manager.Datatype.IMAGE) |
else: |
diff_link = '' |
- with tempfile.NamedTemporaryFile(suffix='.html') as temp_html: |
- jinja2_env = jinja2.Environment( |
- loader=jinja2.FileSystemLoader(_JINJA_TEMPLATE_DIR), |
- trim_blocks=True) |
- template = jinja2_env.get_template(_JINJA_TEMPLATE_FILENAME) |
- # pylint: disable=no-member |
- processed_template_output = template.render( |
- test_name=failure_filename, |
- failure_link=failure_link, |
- golden_link=golden_link, |
- diff_link=diff_link) |
- |
- temp_html.write(processed_template_output) |
- temp_html.flush() |
- html_results_link = google_storage_helper.upload_content_addressed( |
- temp_html.name, |
- bucket=render_tests_bucket, |
- content_type='text/html') |
+ jinja2_env = jinja2.Environment( |
+ loader=jinja2.FileSystemLoader(_JINJA_TEMPLATE_DIR), |
+ trim_blocks=True) |
+ template = jinja2_env.get_template(_JINJA_TEMPLATE_FILENAME) |
+ # pylint: disable=no-member |
+ processed_template_output = template.render( |
+ test_name=failure_filename, |
+ failure_link=failure_link, |
+ golden_link=golden_link, |
+ diff_link=diff_link) |
+ |
+ try: |
+ html_results = tempfile.NamedTemporaryFile(delete=False) |
+ html_results.write(processed_template_output) |
+ html_results.flush() |
+ finally: |
+ html_results_link = self._env.output_manager.ArchiveAndDeleteFile( |
+ html_results.name, |
+ '%s.html' % failure_filename, 'render_tests', |
+ output_manager.Datatype.HTML) |
for result in results: |
result.SetLink(failure_filename, html_results_link) |