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

Side by Side Diff: content/test/gpu/gpu_tests/cloud_storage_test_base.py

Issue 865653004: Document and test that image_util.WritePngFile requires path end in 'png'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review feedback from sullivan. Created 5 years, 11 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
« no previous file with comments | « no previous file | tools/telemetry/telemetry/image_processing/image_util.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 """Base classes for a test and validator which upload results 5 """Base classes for a test and validator which upload results
6 (reference images, error images) to cloud storage.""" 6 (reference images, error images) to cloud storage."""
7 7
8 import os 8 import os
9 import re 9 import re
10 import tempfile 10 import tempfile
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return '%s_v%s_%s.png' % ( 136 return '%s_v%s_%s.png' % (
137 img_name, 137 img_name,
138 page.revision, 138 page.revision,
139 self._FormatGpuInfo(tab)) 139 self._FormatGpuInfo(tab))
140 140
141 def _UploadBitmapToCloudStorage(self, bucket, name, bitmap, public=False): 141 def _UploadBitmapToCloudStorage(self, bucket, name, bitmap, public=False):
142 # This sequence of steps works on all platforms to write a temporary 142 # This sequence of steps works on all platforms to write a temporary
143 # PNG to disk, following the pattern in bitmap_unittest.py. The key to 143 # PNG to disk, following the pattern in bitmap_unittest.py. The key to
144 # avoiding PermissionErrors seems to be to not actually try to write to 144 # avoiding PermissionErrors seems to be to not actually try to write to
145 # the temporary file object, but to re-open its name for all operations. 145 # the temporary file object, but to re-open its name for all operations.
146 temp_file = tempfile.NamedTemporaryFile().name 146 temp_file = tempfile.NamedTemporaryFile(suffix='.png').name
147 image_util.WritePngFile(bitmap, temp_file) 147 image_util.WritePngFile(bitmap, temp_file)
148 cloud_storage.Insert(bucket, name, temp_file, publicly_readable=public) 148 cloud_storage.Insert(bucket, name, temp_file, publicly_readable=public)
149 149
150 def _ConditionallyUploadToCloudStorage(self, img_name, page, tab, screenshot): 150 def _ConditionallyUploadToCloudStorage(self, img_name, page, tab, screenshot):
151 """Uploads the screenshot to cloud storage as the reference image 151 """Uploads the screenshot to cloud storage as the reference image
152 for this test, unless it already exists. Returns True if the 152 for this test, unless it already exists. Returns True if the
153 upload was actually performed.""" 153 upload was actually performed."""
154 if not self.options.refimg_cloud_storage_bucket: 154 if not self.options.refimg_cloud_storage_bucket:
155 raise Exception('--refimg-cloud-storage-bucket argument is required') 155 raise Exception('--refimg-cloud-storage-bucket argument is required')
156 cloud_name = self._FormatReferenceImageName(img_name, page, tab) 156 cloud_name = self._FormatReferenceImageName(img_name, page, tab)
157 if not cloud_storage.Exists(self.options.refimg_cloud_storage_bucket, 157 if not cloud_storage.Exists(self.options.refimg_cloud_storage_bucket,
158 cloud_name): 158 cloud_name):
159 self._UploadBitmapToCloudStorage(self.options.refimg_cloud_storage_bucket, 159 self._UploadBitmapToCloudStorage(self.options.refimg_cloud_storage_bucket,
160 cloud_name, 160 cloud_name,
161 screenshot) 161 screenshot)
162 return True 162 return True
163 return False 163 return False
164 164
165 def _DownloadFromCloudStorage(self, img_name, page, tab): 165 def _DownloadFromCloudStorage(self, img_name, page, tab):
166 """Downloads the reference image for the given test from cloud 166 """Downloads the reference image for the given test from cloud
167 storage, returning it as a Telemetry Bitmap object.""" 167 storage, returning it as a Telemetry Bitmap object."""
168 # TODO(kbr): there's a race condition between the deletion of the 168 # TODO(kbr): there's a race condition between the deletion of the
169 # temporary file and gsutil's overwriting it. 169 # temporary file and gsutil's overwriting it.
170 if not self.options.refimg_cloud_storage_bucket: 170 if not self.options.refimg_cloud_storage_bucket:
171 raise Exception('--refimg-cloud-storage-bucket argument is required') 171 raise Exception('--refimg-cloud-storage-bucket argument is required')
172 temp_file = tempfile.NamedTemporaryFile().name 172 temp_file = tempfile.NamedTemporaryFile(suffix='.png').name
173 cloud_storage.Get(self.options.refimg_cloud_storage_bucket, 173 cloud_storage.Get(self.options.refimg_cloud_storage_bucket,
174 self._FormatReferenceImageName(img_name, page, tab), 174 self._FormatReferenceImageName(img_name, page, tab),
175 temp_file) 175 temp_file)
176 return image_util.FromPngFile(temp_file) 176 return image_util.FromPngFile(temp_file)
177 177
178 def _UploadErrorImagesToCloudStorage(self, image_name, screenshot, ref_img): 178 def _UploadErrorImagesToCloudStorage(self, image_name, screenshot, ref_img):
179 """For a failing run, uploads the failing image, reference image (if 179 """For a failing run, uploads the failing image, reference image (if
180 supplied), and diff image (if reference image was supplied) to cloud 180 supplied), and diff image (if reference image was supplied) to cloud
181 storage. This subsumes the functionality of the 181 storage. This subsumes the functionality of the
182 archive_gpu_pixel_test_results.py script.""" 182 archive_gpu_pixel_test_results.py script."""
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 default='') 246 default='')
247 group.add_option('--test-machine-name', 247 group.add_option('--test-machine-name',
248 help='Name of the test machine. Specifying this argument causes this ' 248 help='Name of the test machine. Specifying this argument causes this '
249 'script to upload failure images and diffs to cloud storage directly, ' 249 'script to upload failure images and diffs to cloud storage directly, '
250 'instead of relying on the archive_gpu_pixel_test_results.py script.', 250 'instead of relying on the archive_gpu_pixel_test_results.py script.',
251 default='') 251 default='')
252 group.add_option('--generated-dir', 252 group.add_option('--generated-dir',
253 help='Overrides the default on-disk location for generated test images ' 253 help='Overrides the default on-disk location for generated test images '
254 '(only used for local testing without a cloud storage account)', 254 '(only used for local testing without a cloud storage account)',
255 default=default_generated_data_dir) 255 default=default_generated_data_dir)
OLDNEW
« no previous file with comments | « no previous file | tools/telemetry/telemetry/image_processing/image_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698