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

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

Issue 2010363002: Update Maps pixel test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove debugging prints from presubmit script. Created 4 years, 6 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 | content/test/gpu/gpu_tests/maps.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 logging
8 import os 9 import os
9 import re 10 import re
10 import tempfile 11 import tempfile
11 12
12 from catapult_base import cloud_storage 13 from catapult_base import cloud_storage
13 from telemetry.page import page_test 14 from telemetry.page import page_test
14 from telemetry.util import image_util 15 from telemetry.util import image_util
15 from telemetry.util import rgba_color 16 from telemetry.util import rgba_color
16 17
17 from gpu_tests import gpu_test_base 18 from gpu_tests import gpu_test_base
18 19
19 test_data_dir = os.path.abspath(os.path.join( 20 test_data_dir = os.path.abspath(os.path.join(
20 os.path.dirname(__file__), '..', '..', 'data', 'gpu')) 21 os.path.dirname(__file__), '..', '..', 'data', 'gpu'))
21 22
22 default_generated_data_dir = os.path.join(test_data_dir, 'generated') 23 default_generated_data_dir = os.path.join(test_data_dir, 'generated')
23 24
24 error_image_cloud_storage_bucket = 'chromium-browser-gpu-tests' 25 error_image_cloud_storage_bucket = 'chromium-browser-gpu-tests'
25 26
26 def _CompareScreenshotSamples(screenshot, expectations, device_pixel_ratio): 27 def _CompareScreenshotSamples(screenshot, expectations, device_pixel_ratio,
28 test_machine_name):
29 # First scan through the expectations and see if there are any scale
30 # factor overrides that would preempt the device pixel ratio. This
31 # is mainly a workaround for complex tests like the Maps test.
32 if test_machine_name:
33 for expectation in expectations:
34 if "scale_factor_overrides" in expectation:
35 for override in expectation["scale_factor_overrides"]:
36 if override["machine_name"] in test_machine_name:
37 logging.warning('Overriding device_pixel_ratio ' +
38 str(device_pixel_ratio) + ' with scale factor ' +
39 str(override["scale_factor"]))
40 device_pixel_ratio = override["scale_factor"]
41 break
42 break
27 for expectation in expectations: 43 for expectation in expectations:
44 if "scale_factor_overrides" in expectation:
45 continue
28 location = expectation["location"] 46 location = expectation["location"]
29 size = expectation["size"] 47 size = expectation["size"]
30 x0 = int(location[0] * device_pixel_ratio) 48 x0 = int(location[0] * device_pixel_ratio)
31 x1 = int((location[0] + size[0]) * device_pixel_ratio) 49 x1 = int((location[0] + size[0]) * device_pixel_ratio)
32 y0 = int(location[1] * device_pixel_ratio) 50 y0 = int(location[1] * device_pixel_ratio)
33 y1 = int((location[1] + size[1]) * device_pixel_ratio) 51 y1 = int((location[1] + size[1]) * device_pixel_ratio)
34 for x in range(x0, x1): 52 for x in range(x0, x1):
35 for y in range(y0, y1): 53 for y in range(y0, y1):
36 if (x < 0 or y < 0 or x >= image_util.Width(screenshot) or 54 if (x < 0 or y < 0 or x >= image_util.Width(screenshot) or
37 y >= image_util.Height(screenshot)): 55 y >= image_util.Height(screenshot)):
38 raise page_test.Failure( 56 raise page_test.Failure(
39 ('Expected pixel location [%d, %d] is out of range on ' + 57 ('Expected pixel location [%d, %d] is out of range on ' +
40 '[%d, %d] image') % 58 '[%d, %d] image') %
41 (x, y, image_util.Width(screenshot), 59 (x, y, image_util.Width(screenshot),
42 image_util.Height(screenshot))) 60 image_util.Height(screenshot)))
43 61
44 actual_color = image_util.GetPixelColor(screenshot, x, y) 62 actual_color = image_util.GetPixelColor(screenshot, x, y)
45 expected_color = rgba_color.RgbaColor( 63 expected_color = rgba_color.RgbaColor(
46 expectation["color"][0], 64 expectation["color"][0],
47 expectation["color"][1], 65 expectation["color"][1],
48 expectation["color"][2]) 66 expectation["color"][2])
49 if not actual_color.IsEqual(expected_color, expectation["tolerance"]): 67 if not actual_color.IsEqual(expected_color, expectation["tolerance"]):
50 raise page_test.Failure('Expected pixel at ' + str(location) + 68 raise page_test.Failure('Expected pixel at ' + str(location) +
69 ' (actual pixel (' + str(x) + ', ' + str(y) + ')) ' +
51 ' to be ' + 70 ' to be ' +
52 str(expectation["color"]) + " but got [" + 71 str(expectation["color"]) + " but got [" +
53 str(actual_color.r) + ", " + 72 str(actual_color.r) + ", " +
54 str(actual_color.g) + ", " + 73 str(actual_color.g) + ", " +
55 str(actual_color.b) + "]") 74 str(actual_color.b) + "]")
56 75
57 class ValidatorBase(gpu_test_base.ValidatorBase): 76 class ValidatorBase(gpu_test_base.ValidatorBase):
58 def __init__(self): 77 def __init__(self):
59 super(ValidatorBase, self).__init__() 78 super(ValidatorBase, self).__init__()
60 # Parameters for cloud storage reference images. 79 # Parameters for cloud storage reference images.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 error_image_cloud_storage_bucket, upload_dir) 231 error_image_cloud_storage_bucket, upload_dir)
213 232
214 def _ValidateScreenshotSamples(self, url, 233 def _ValidateScreenshotSamples(self, url,
215 screenshot, expectations, device_pixel_ratio): 234 screenshot, expectations, device_pixel_ratio):
216 """Samples the given screenshot and verifies pixel color values. 235 """Samples the given screenshot and verifies pixel color values.
217 The sample locations and expected color values are given in expectations. 236 The sample locations and expected color values are given in expectations.
218 In case any of the samples do not match the expected color, it raises 237 In case any of the samples do not match the expected color, it raises
219 a Failure and dumps the screenshot locally or cloud storage depending on 238 a Failure and dumps the screenshot locally or cloud storage depending on
220 what machine the test is being run.""" 239 what machine the test is being run."""
221 try: 240 try:
222 _CompareScreenshotSamples(screenshot, expectations, device_pixel_ratio) 241 _CompareScreenshotSamples(screenshot, expectations, device_pixel_ratio,
242 self.options.test_machine_name)
223 except page_test.Failure: 243 except page_test.Failure:
224 image_name = self._UrlToImageName(url) 244 image_name = self._UrlToImageName(url)
225 if self.options.test_machine_name: 245 if self.options.test_machine_name:
226 self._UploadErrorImagesToCloudStorage(image_name, screenshot, None) 246 self._UploadErrorImagesToCloudStorage(image_name, screenshot, None)
227 else: 247 else:
228 self._WriteErrorImages(self.options.generated_dir, image_name, 248 self._WriteErrorImages(self.options.generated_dir, image_name,
229 screenshot, None) 249 screenshot, None)
230 raise 250 raise
231 251
232 252
(...skipping 25 matching lines...) Expand all
258 default='') 278 default='')
259 group.add_option('--test-machine-name', 279 group.add_option('--test-machine-name',
260 help='Name of the test machine. Specifying this argument causes this ' 280 help='Name of the test machine. Specifying this argument causes this '
261 'script to upload failure images and diffs to cloud storage directly, ' 281 'script to upload failure images and diffs to cloud storage directly, '
262 'instead of relying on the archive_gpu_pixel_test_results.py script.', 282 'instead of relying on the archive_gpu_pixel_test_results.py script.',
263 default='') 283 default='')
264 group.add_option('--generated-dir', 284 group.add_option('--generated-dir',
265 help='Overrides the default on-disk location for generated test images ' 285 help='Overrides the default on-disk location for generated test images '
266 '(only used for local testing without a cloud storage account)', 286 '(only used for local testing without a cloud storage account)',
267 default=default_generated_data_dir) 287 default=default_generated_data_dir)
OLDNEW
« no previous file with comments | « no previous file | content/test/gpu/gpu_tests/maps.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698