Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 self._test_instance.gs_results_bucket + '/render_tests') | |
| 529 | |
| 530 diff_images_device_dir = posixpath.join( | 528 diff_images_device_dir = posixpath.join( |
| 531 render_tests_device_output_dir, 'diffs') | 529 render_tests_device_output_dir, 'diffs') |
| 532 | 530 |
| 533 golden_images_device_dir = posixpath.join( | 531 golden_images_device_dir = posixpath.join( |
| 534 render_tests_device_output_dir, 'goldens') | 532 render_tests_device_output_dir, 'goldens') |
| 535 | 533 |
| 536 with tempfile_ext.NamedTemporaryDirectory() as temp_dir: | 534 with contextlib_ext.Optional( |
| 537 device.PullFile(failure_images_device_dir, temp_dir) | 535 tempfile_ext.NamedTemporaryDirectory(), |
| 536 self._test_instance.render_results_dir is None) as render_host_dir: | |
|
jbudorick
2017/05/17 21:26:45
nit: Can you name the context manager something ot
mikecase (-- gone --)
2017/05/17 21:46:04
Done
| |
| 537 render_host_dir = ( | |
| 538 self._test_instance.render_results_dir or render_host_dir) | |
| 539 | |
| 540 if not os.path.exists(render_host_dir): | |
| 541 os.makedirs(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. |
|
jbudorick
2017/05/17 21:26:45
Since we no longer always do this, I think it'd be
mikecase (-- gone --)
2017/05/17 21:46:05
Done, added _UploadRenderTestResults function.
| |
| 557 if not self._test_instance.gs_results_bucket: | |
| 558 return | |
| 559 | |
| 560 render_tests_bucket = ( | |
| 561 self._test_instance.gs_results_bucket + '/render_tests') | |
| 562 | |
| 563 for failure_filename in os.listdir( | |
| 564 os.path.join(render_host_dir, 'failures')): | |
| 550 m = RE_RENDER_IMAGE_NAME.match(failure_filename) | 565 m = RE_RENDER_IMAGE_NAME.match(failure_filename) |
| 551 if not m: | 566 if not m: |
| 552 logging.warning('Unexpected file in render test failures: %s', | 567 logging.warning('Unexpected file in render test failures: %s', |
| 553 failure_filename) | 568 failure_filename) |
| 554 continue | 569 continue |
| 555 | 570 |
| 556 failure_filepath = os.path.join(temp_dir, 'failures', failure_filename) | 571 failure_filepath = os.path.join( |
| 572 render_host_dir, 'failures', failure_filename) | |
| 557 failure_link = google_storage_helper.upload_content_addressed( | 573 failure_link = google_storage_helper.upload_content_addressed( |
| 558 failure_filepath, bucket=render_tests_bucket) | 574 failure_filepath, bucket=render_tests_bucket) |
| 559 | 575 |
| 560 golden_filepath = os.path.join(temp_dir, 'goldens', failure_filename) | 576 golden_filepath = os.path.join( |
| 577 render_host_dir, 'goldens', failure_filename) | |
| 561 if os.path.exists(golden_filepath): | 578 if os.path.exists(golden_filepath): |
| 562 golden_link = google_storage_helper.upload_content_addressed( | 579 golden_link = google_storage_helper.upload_content_addressed( |
| 563 golden_filepath, bucket=render_tests_bucket) | 580 golden_filepath, bucket=render_tests_bucket) |
| 564 else: | 581 else: |
| 565 golden_link = '' | 582 golden_link = '' |
| 566 | 583 |
| 567 diff_filepath = os.path.join(temp_dir, 'diffs', failure_filename) | 584 diff_filepath = os.path.join( |
| 585 render_host_dir, 'diffs', failure_filename) | |
| 568 if os.path.exists(diff_filepath): | 586 if os.path.exists(diff_filepath): |
| 569 diff_link = google_storage_helper.upload_content_addressed( | 587 diff_link = google_storage_helper.upload_content_addressed( |
| 570 diff_filepath, bucket=render_tests_bucket) | 588 diff_filepath, bucket=render_tests_bucket) |
| 571 else: | 589 else: |
| 572 diff_link = '' | 590 diff_link = '' |
| 573 | 591 |
| 574 with tempfile.NamedTemporaryFile(suffix='.html') as temp_html: | 592 with tempfile.NamedTemporaryFile(suffix='.html') as temp_html: |
| 575 jinja2_env = jinja2.Environment( | 593 jinja2_env = jinja2.Environment( |
| 576 loader=jinja2.FileSystemLoader(_JINJA_TEMPLATE_DIR), | 594 loader=jinja2.FileSystemLoader(_JINJA_TEMPLATE_DIR), |
| 577 trim_blocks=True) | 595 trim_blocks=True) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) | 645 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) |
| 628 | 646 |
| 629 return timeout | 647 return timeout |
| 630 | 648 |
| 631 def _IsRenderTest(test): | 649 def _IsRenderTest(test): |
| 632 """Determines if a test or list of tests has a RenderTest amongst them.""" | 650 """Determines if a test or list of tests has a RenderTest amongst them.""" |
| 633 if not isinstance(test, list): | 651 if not isinstance(test, list): |
| 634 test = [test] | 652 test = [test] |
| 635 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( | 653 return any([RENDER_TEST_FEATURE_ANNOTATION in t['annotations'].get( |
| 636 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) | 654 FEATURE_ANNOTATION, {}).get('value', ()) for t in test]) |
| OLD | NEW |