def _generate_pixel_diffs_if_needed(self, test, expected_image, actual_image): """If expected_image and actual_image both exist but are different, add the image pair to self._image_diff_db and generate pixel diffs. Args: test: string; name of test expected_image: (hashType, hashDigest) tuple describing the expected image actual_image: (hashType, hashDigest) tuple describing the actual image """ if expected_image == actual_image: return (expected_hashtype, expected_hashdigest) = expected_image (actual_hashtype, actual_hashdigest) = actual_image if None in [ expected_hashtype, expected_hashdigest, actual_hashtype, actual_hashdigest ]: return expected_url = gm_json.CreateGmActualUrl( test_name=test, hash_type=expected_hashtype, hash_digest=expected_hashdigest) actual_url = gm_json.CreateGmActualUrl(test_name=test, hash_type=actual_hashtype, hash_digest=actual_hashdigest) self._image_diff_db.add_image_pair( expected_image_locator=expected_hashdigest, expected_image_url=expected_url, actual_image_locator=actual_hashdigest, actual_image_url=actual_url)
def fetch(self, builder_name, dest_dir): """ Downloads actual GM results for a particular builder. Args: builder_name: which builder to download results of dest_dir: path to directory where the image files will be written; if the directory does not exist yet, it will be created TODO(epoger): Display progress info. Right now, it can take a long time to download all of the results, and there is no indication of progress. TODO(epoger): Download multiple images in parallel to speed things up. """ json_url = posixpath.join(self._actuals_base_url, builder_name, self._json_filename) json_contents = urllib2.urlopen(json_url).read() results_dict = gm_json.LoadFromString(json_contents) actual_results_dict = results_dict[gm_json.JSONKEY_ACTUALRESULTS] for result_type in sorted(actual_results_dict.keys()): results_of_this_type = actual_results_dict[result_type] if not results_of_this_type: continue for image_name in sorted(results_of_this_type.keys()): (test, config) = self._image_filename_re.match(image_name).groups() (hash_type, hash_digest) = results_of_this_type[image_name] source_url = gm_json.CreateGmActualUrl( test_name=test, hash_type=hash_type, hash_digest=hash_digest, gm_actuals_root_url=self._gm_actuals_root_url) dest_path = os.path.join(dest_dir, config, test + '.png') url_utils.copy_contents(source_url=source_url, dest_path=dest_path, create_subdirs_if_needed=True)
def _CreateGSUrl(imagename, hash_type, hash_digest): """Return the HTTP URL we can use to download this particular version of the actually-generated GM image with this imagename. imagename: name of the test image, e.g. 'perlinnoise_msaa4.png' hash_type: string indicating the hash type used to generate hash_digest, e.g. gm_json.JSONKEY_HASHTYPE_BITMAP_64BITMD5 hash_digest: the hash digest of the image to retrieve """ return gm_json.CreateGmActualUrl( test_name=IMAGE_FILENAME_RE.match(imagename).group(1), hash_type=hash_type, hash_digest=hash_digest)
def download_gm_image(image_name, image_path, hash_val): """Download the gm result into the given path. @param image_name The GM file name, for example imageblur_gpu.png. @param image_path Path to place the image. @param hash_val The hash value of the image. """ if hash_val is None: return # Separate the test name from a image name image_match = IMAGE_FILENAME_RE.match(image_name) test_name = image_match.group(1) # Calculate the URL of the requested image image_url = gm_json.CreateGmActualUrl( test_name, gm_json.JSONKEY_HASHTYPE_BITMAP_64BITMD5, hash_val) # Download the image as requested download_file(image_url, image_path)