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

Unified Diff: gm/rebaseline_server/compare_rendered_pictures.py

Issue 424263005: teach rebaseline_server to generate diffs of rendered SKPs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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: gm/rebaseline_server/compare_rendered_pictures.py
diff --git a/gm/rebaseline_server/compare_rendered_pictures.py b/gm/rebaseline_server/compare_rendered_pictures.py
index a48d1c57637d58b93a2a227840b6ccbc45677ac6..f64bf9309c1fe15175d1b6a9a61ff38ea2ae9c67 100755
--- a/gm/rebaseline_server/compare_rendered_pictures.py
+++ b/gm/rebaseline_server/compare_rendered_pictures.py
@@ -7,11 +7,15 @@ Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
Compare results of two render_pictures runs.
+
+EPOGER: Rename this module, because it is more generally useful now... it can download and compare any types of images.
"""
# System-level imports
import logging
import os
+import shutil
+import tempfile
import time
# Must fix up PYTHONPATH before importing from within Skia
@@ -19,6 +23,7 @@ import fix_pythonpath # pylint: disable=W0611
# Imports from within Skia
from py.utils import url_utils
+import buildbot_globals
import gm_json
import imagediffdb
import imagepair
@@ -27,75 +32,84 @@ import results
# URL under which all render_pictures images can be found in Google Storage.
#
-# pylint: disable=C0301
-# TODO(epoger): Move this default value into
-# https://skia.googlesource.com/buildbot/+/master/site_config/global_variables.json
-# pylint: enable=C0301
-DEFAULT_IMAGE_BASE_URL = (
- 'http://chromium-skia-gm.commondatastorage.googleapis.com/'
- 'render_pictures/images')
+# EPOGER: In order to allow live-view of GMs and other images, read this from the input summary files, or allow the caller to set it within the GET_live_results call?
+DEFAULT_IMAGE_BASE_GS_URL = 'gs://' + buildbot_globals.Get('skp_images_bucket')
class RenderedPicturesComparisons(results.BaseComparisons):
- """Loads results from two different render_pictures runs into an ImagePairSet.
+ """Loads results from multiple render_pictures runs into an ImagePairSet.
"""
- def __init__(self, subdirs, actuals_root,
- generated_images_root=results.DEFAULT_GENERATED_IMAGES_ROOT,
- image_base_url=DEFAULT_IMAGE_BASE_URL,
- diff_base_url=None):
+ def __init__(self, actuals_dirs, expectations_dirs, image_diff_db,
+ image_base_gs_url=DEFAULT_IMAGE_BASE_GS_URL,
+ diff_base_url=None, actuals_label='actuals',
+ expectations_label='expectations'):
"""
Args:
- actuals_root: root directory containing all render_pictures-generated
- JSON files
- subdirs: (string, string) tuple; pair of subdirectories within
- actuals_root to compare
- generated_images_root: directory within which to create all pixel diffs;
- if this directory does not yet exist, it will be created
- image_base_url: URL under which all render_pictures result images can
+ actuals_dirs: list of root directories to copy all JSON summaries from,
+ and to use as actual results
+ expectations_dirs: list of root directories to copy all JSON summaries
+ from, and to use as expected results
+ image_diff_db: ImageDiffDB instance
+ image_base_gs_url: "gs://" URL pointing at the Google Storage bucket/dir
+ under which all render_pictures result images can
be found; this will be used to read images for comparison within
- this code, and included in the ImagePairSet so its consumers know
- where to download the images from
+ this code, and included in the ImagePairSet (as an HTTP URL) so its
+ consumers know where to download the images from
diff_base_url: base URL within which the client should look for diff
images; if not specified, defaults to a "file:///" URL representation
- of generated_images_root
+ of image_diff_db's storage_root
+ actuals_label: description to use for actual results
+ expectations_label: description to use for expected results
"""
- time_start = int(time.time())
- self._image_diff_db = imagediffdb.ImageDiffDB(generated_images_root)
- self._image_base_url = image_base_url
+ self._image_diff_db = image_diff_db
+ self._image_base_gs_url = image_base_gs_url
self._diff_base_url = (
diff_base_url or
- url_utils.create_filepath_url(generated_images_root))
- self._load_result_pairs(actuals_root, subdirs)
- self._timestamp = int(time.time())
- logging.info('Results complete; took %d seconds.' %
- (self._timestamp - time_start))
+ url_utils.create_filepath_url(image_diff_db.storage_root))
+ self._actuals_label = actuals_label
+ self._expectations_label = expectations_label
- def _load_result_pairs(self, actuals_root, subdirs):
- """Loads all JSON files found within two subdirs in actuals_root,
- compares across those two subdirs, and stores the summary in self._results.
+ tempdir = tempfile.mkdtemp()
+ try:
+ actuals_root = os.path.join(tempdir, 'actuals')
+ expectations_root = os.path.join(tempdir, 'expectations')
+ # Copy all summary files into actuals_root and expectations_root
+ # EPOGER: this won't work when *_dirs have more than one entry
+ for dir in actuals_dirs:
+ shutil.copytree(dir, actuals_root)
+ for dir in expectations_dirs:
+ shutil.copytree(dir, expectations_root)
+
+ time_start = int(time.time())
+ self._load_result_pairs(actuals_root, expectations_root)
+ self._timestamp = int(time.time())
+ logging.info('Results complete; took %d seconds.' %
+ (self._timestamp - time_start))
+ finally:
+ shutil.rmtree(tempdir)
+
+ def _load_result_pairs(self, actuals_root, expectations_root):
+ """Loads all JSON image summaries from 2 directory trees and compares them.
+
+ The summary of all image diff results is stored in in self._results.
+ EPOGER: we don't want to store the results in self._results anymore... now, we just want to return them
Args:
- actuals_root: root directory containing all render_pictures-generated
- JSON files
- subdirs: (string, string) tuple; pair of subdirectories within
- actuals_root to compare
+ actuals_root: root directory containing JSON summaries of actual results
+ expectations_root: root dir containing JSON summaries of expected results
"""
- logging.info(
- 'Reading actual-results JSON files from %s subdirs within %s...' % (
- subdirs, actuals_root))
- subdirA, subdirB = subdirs
- subdirA_dicts = self._read_dicts_from_root(
- os.path.join(actuals_root, subdirA))
- subdirB_dicts = self._read_dicts_from_root(
- os.path.join(actuals_root, subdirB))
- logging.info('Comparing subdirs %s and %s...' % (subdirA, subdirB))
+ logging.info('Reading JSON image summaries from dirs %s and %s...' % (
+ actuals_root, expectations_root))
+ actuals_dicts = self._read_dicts_from_root(actuals_root)
+ expectations_dicts = self._read_dicts_from_root(expectations_root)
+ logging.info('Comparing summary dicts...')
all_image_pairs = imagepairset.ImagePairSet(
- descriptions=subdirs,
+ descriptions=(self._actuals_label, self._expectations_label),
diff_base_url=self._diff_base_url)
failing_image_pairs = imagepairset.ImagePairSet(
- descriptions=subdirs,
+ descriptions=(self._actuals_label, self._expectations_label),
diff_base_url=self._diff_base_url)
all_image_pairs.ensure_extra_column_values_in_summary(
@@ -110,15 +124,23 @@ class RenderedPicturesComparisons(results.BaseComparisons):
results.KEY__RESULT_TYPE__NOCOMPARISON,
])
- common_dict_paths = sorted(set(subdirA_dicts.keys() + subdirB_dicts.keys()))
+ # Every actuals_dict should be paired up with a corresponding
+ # expectations_dict.
+ actuals_dict_paths = sorted(actuals_dicts.keys())
+ expectations_dict_paths = sorted(expectations_dicts.keys())
+ if actuals_dict_paths != expectations_dict_paths:
+ raise Exception('actuals_dict_paths %s != expectations_dict_paths %s' % (
+ actuals_dict_paths, expectations_dict_paths))
+ common_dict_paths = actuals_dict_paths
+
num_common_dict_paths = len(common_dict_paths)
dict_num = 0
for dict_path in common_dict_paths:
dict_num += 1
logging.info('Generating pixel diffs for dict #%d of %d, "%s"...' %
(dict_num, num_common_dict_paths, dict_path))
- dictA = subdirA_dicts[dict_path]
- dictB = subdirB_dicts[dict_path]
+ dictA = actuals_dicts[dict_path]
+ dictB = expectations_dicts[dict_path]
self._validate_dict_version(dictA)
self._validate_dict_version(dictB)
dictA_results = dictA[gm_json.JSONKEY_ACTUALRESULTS]
@@ -235,7 +257,7 @@ class RenderedPicturesComparisons(results.BaseComparisons):
try:
return imagepair.ImagePair(
image_diff_db=self._image_diff_db,
- base_url=self._image_base_url,
+ base_url=self._image_base_gs_url,
imageA_relative_url=imageA_relative_url,
imageB_relative_url=imageB_relative_url,
extra_columns=extra_columns_dict)
@@ -245,6 +267,3 @@ class RenderedPicturesComparisons(results.BaseComparisons):
' test="%s", config="%s", urlPair=("%s","%s")' % (
test, config, imageA_relative_url, imageB_relative_url))
return None
-
-
-# TODO(epoger): Add main() so this can be called by vm_run_skia_try.sh

Powered by Google App Engine
This is Rietveld 408576698