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

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

Issue 2889663003: Add --render-results-dir arg to store render results locally. (Closed)
Patch Set: 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 sys 9 import sys
10 import tempfile 10 import tempfile
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 google_storage_helper.unique_name( 506 google_storage_helper.unique_name(
507 'screenshot', device=device), 507 'screenshot', device=device),
508 screenshot_host_file, 508 screenshot_host_file,
509 bucket=('%s/screenshots' % 509 bucket=('%s/screenshots' %
510 self._test_instance.gs_results_bucket)) 510 self._test_instance.gs_results_bucket))
511 for result in results: 511 for result in results:
512 result.SetLink('post_test_screenshot', link) 512 result.SetLink('post_test_screenshot', link)
513 513
514 def _ProcessRenderTestResults( 514 def _ProcessRenderTestResults(
515 self, device, render_tests_device_output_dir, results): 515 self, device, render_tests_device_output_dir, results):
516 # Will archive test images if we are given a GS bucket to store the results 516 # If GS results bucket is specified, will archive render result images.
517 # in and are given a results file to output the links to. 517 # If render image dir is specified, will pull the render result image from
518 if not bool(self._test_instance.gs_results_bucket): 518 # the device and leave in the directory.
519 if not (bool(self._test_instance.gs_results_bucket) or
520 bool(self._test_instance.render_results_dir)):
519 return 521 return
520 522
521 failure_images_device_dir = posixpath.join( 523 failure_images_device_dir = posixpath.join(
522 render_tests_device_output_dir, 'failures') 524 render_tests_device_output_dir, 'failures')
523
524 if not device.FileExists(failure_images_device_dir): 525 if not device.FileExists(failure_images_device_dir):
525 return 526 return
526 527
527 render_tests_bucket = ( 528 render_tests_bucket = (
528 self._test_instance.gs_results_bucket + '/render_tests') 529 self._test_instance.gs_results_bucket + '/render_tests')
529 530
530 diff_images_device_dir = posixpath.join( 531 diff_images_device_dir = posixpath.join(
531 render_tests_device_output_dir, 'diffs') 532 render_tests_device_output_dir, 'diffs')
532 533
533 golden_images_device_dir = posixpath.join( 534 golden_images_device_dir = posixpath.join(
534 render_tests_device_output_dir, 'goldens') 535 render_tests_device_output_dir, 'goldens')
535 536
536 with tempfile_ext.NamedTemporaryDirectory() as temp_dir: 537 with contextlib_ext.Optional(
537 device.PullFile(failure_images_device_dir, temp_dir) 538 tempfile_ext.NamedTemporaryDirectory(),
539 self._test_instance.render_results_dir is None) as render_host_dir:
540 render_host_dir = (
541 self._test_instance.render_results_dir or render_host_dir)
542
543 # Pull all render test results from device.
544 device.PullFile(failure_images_device_dir, render_host_dir)
538 545
539 if device.FileExists(diff_images_device_dir): 546 if device.FileExists(diff_images_device_dir):
540 device.PullFile(diff_images_device_dir, temp_dir) 547 device.PullFile(diff_images_device_dir, render_host_dir)
541 else: 548 else:
542 logging.error('Diff images not found on device.') 549 logging.error('Diff images not found on device.')
543 550
544 if device.FileExists(golden_images_device_dir): 551 if device.FileExists(golden_images_device_dir):
545 device.PullFile(golden_images_device_dir, temp_dir) 552 device.PullFile(golden_images_device_dir, render_host_dir)
546 else: 553 else:
547 logging.error('Golden images not found on device.') 554 logging.error('Golden images not found on device.')
548 555
549 for failure_filename in os.listdir(os.path.join(temp_dir, 'failures')): 556 # Upload results to Google Storage.
550 m = RE_RENDER_IMAGE_NAME.match(failure_filename) 557 if self._test_instance.gs_results_bucket:
PEConn 2017/05/17 08:34:34 Can you invert this if statement to reduce nesting
mikecase (-- gone --) 2017/05/17 21:10:29 Done
551 if not m: 558 for failure_filename in os.listdir(
552 logging.warning('Unexpected file in render test failures: %s', 559 os.path.join(render_host_dir, 'failures')):
553 failure_filename) 560 m = RE_RENDER_IMAGE_NAME.match(failure_filename)
554 continue 561 if not m:
562 logging.warning('Unexpected file in render test failures: %s',
563 failure_filename)
564 continue
555 565
556 failure_filepath = os.path.join(temp_dir, 'failures', failure_filename) 566 failure_filepath = os.path.join(
557 failure_link = google_storage_helper.upload_content_addressed( 567 render_host_dir, 'failures', failure_filename)
558 failure_filepath, bucket=render_tests_bucket) 568 failure_link = google_storage_helper.upload_content_addressed(
569 failure_filepath, bucket=render_tests_bucket)
559 570
560 golden_filepath = os.path.join(temp_dir, 'goldens', failure_filename) 571 golden_filepath = os.path.join(
561 if os.path.exists(golden_filepath): 572 render_host_dir, 'goldens', failure_filename)
562 golden_link = google_storage_helper.upload_content_addressed( 573 if os.path.exists(golden_filepath):
563 golden_filepath, bucket=render_tests_bucket) 574 golden_link = google_storage_helper.upload_content_addressed(
564 else: 575 golden_filepath, bucket=render_tests_bucket)
565 golden_link = '' 576 else:
577 golden_link = ''
566 578
567 diff_filepath = os.path.join(temp_dir, 'diffs', failure_filename) 579 diff_filepath = os.path.join(
568 if os.path.exists(diff_filepath): 580 render_host_dir, 'diffs', failure_filename)
569 diff_link = google_storage_helper.upload_content_addressed( 581 if os.path.exists(diff_filepath):
570 diff_filepath, bucket=render_tests_bucket) 582 diff_link = google_storage_helper.upload_content_addressed(
571 else: 583 diff_filepath, bucket=render_tests_bucket)
572 diff_link = '' 584 else:
585 diff_link = ''
573 586
574 with tempfile.NamedTemporaryFile(suffix='.html') as temp_html: 587 with tempfile.NamedTemporaryFile(suffix='.html') as temp_html:
575 jinja2_env = jinja2.Environment( 588 jinja2_env = jinja2.Environment(
576 loader=jinja2.FileSystemLoader(_JINJA_TEMPLATE_DIR), 589 loader=jinja2.FileSystemLoader(_JINJA_TEMPLATE_DIR),
577 trim_blocks=True) 590 trim_blocks=True)
578 template = jinja2_env.get_template(_JINJA_TEMPLATE_FILENAME) 591 template = jinja2_env.get_template(_JINJA_TEMPLATE_FILENAME)
579 # pylint: disable=no-member 592 # pylint: disable=no-member
580 processed_template_output = template.render( 593 processed_template_output = template.render(
581 test_name=failure_filename, 594 test_name=failure_filename,
582 failure_link=failure_link, 595 failure_link=failure_link,
583 golden_link=golden_link, 596 golden_link=golden_link,
584 diff_link=diff_link) 597 diff_link=diff_link)
585 598
586 temp_html.write(processed_template_output) 599 temp_html.write(processed_template_output)
587 temp_html.flush() 600 temp_html.flush()
588 html_results_link = google_storage_helper.upload_content_addressed( 601 html_results_link = google_storage_helper.upload_content_addressed(
589 temp_html.name, 602 temp_html.name,
590 bucket=render_tests_bucket, 603 bucket=render_tests_bucket,
591 content_type='text/html') 604 content_type='text/html')
592 for result in results: 605 for result in results:
593 result.SetLink(failure_filename, html_results_link) 606 result.SetLink(failure_filename, html_results_link)
594 607
595 #override 608 #override
596 def _ShouldRetry(self, test): 609 def _ShouldRetry(self, test):
597 if 'RetryOnFailure' in test.get('annotations', {}): 610 if 'RetryOnFailure' in test.get('annotations', {}):
598 return True 611 return True
599 612
600 # TODO(jbudorick): Remove this log message once @RetryOnFailure has been 613 # TODO(jbudorick): Remove this log message once @RetryOnFailure has been
601 # enabled for a while. See crbug.com/619055 for more details. 614 # enabled for a while. See crbug.com/619055 for more details.
602 logging.error('Default retries are being phased out. crbug.com/619055') 615 logging.error('Default retries are being phased out. crbug.com/619055')
603 return False 616 return False
(...skipping 23 matching lines...) Expand all
627 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) 640 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations)
628 641
629 return timeout 642 return timeout
630 643
631 def _IsRenderTest(test): 644 def _IsRenderTest(test):
632 """Determines if a test or list of tests has a RenderTest amongst them.""" 645 """Determines if a test or list of tests has a RenderTest amongst them."""
633 if not isinstance(test, list): 646 if not isinstance(test, list):
634 test = [test] 647 test = [test]
635 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( 648 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get(
636 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) 649 FEATURE_ANNOTATION, {}).get('value', ()) for t in test])
OLDNEW
« no previous file with comments | « build/android/pylib/instrumentation/instrumentation_test_instance.py ('k') | build/android/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698