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

Side by Side Diff: gm/rebaseline_server/compare_rendered_pictures_test.py

Issue 274623002: make compare_rendered_pictures_test.py run end-to-end test (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use subprocess.check_output() Created 6 years, 7 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 """ 3 """
4 Copyright 2014 Google Inc. 4 Copyright 2014 Google Inc.
5 5
6 Use of this source code is governed by a BSD-style license that can be 6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file. 7 found in the LICENSE file.
8 8
9 Test compare_rendered_pictures.py 9 Test compare_rendered_pictures.py
10 10
11 TODO(epoger): Create a command to update the expected results (in 11 TODO(epoger): Create a command to update the expected results (in
12 self._output_dir_expected) when appropriate. For now, you should: 12 self._output_dir_expected) when appropriate. For now, you should:
13 1. examine the results in self._output_dir_actual and make sure they are ok 13 1. examine the results in self._output_dir_actual and make sure they are ok
14 2. rm -rf self._output_dir_expected 14 2. rm -rf self._output_dir_expected
15 3. mv self._output_dir_actual self._output_dir_expected 15 3. mv self._output_dir_actual self._output_dir_expected
16 Although, if you're using an SVN checkout, this will blow away .svn directories 16 Although, if you're using an SVN checkout, this will blow away .svn directories
17 within self._output_dir_expected, which wouldn't be good... 17 within self._output_dir_expected, which wouldn't be good...
18 18
19 """ 19 """
20 20
21 import os 21 import os
22 import subprocess
22 import sys 23 import sys
23 24
24 # Imports from within Skia 25 # Imports from within Skia
25 import base_unittest 26 import base_unittest
26 import compare_rendered_pictures 27 import compare_rendered_pictures
27 import results 28 import results
28 import gm_json # must import results first, so that gm_json will be in sys.path 29 import gm_json # must import results first, so that gm_json will be in sys.path
29 30
30 31
31 class CompareRenderedPicturesTest(base_unittest.TestCase): 32 class CompareRenderedPicturesTest(base_unittest.TestCase):
32 33
33 def test_endToEnd(self): 34 def test_endToEnd(self):
34 """Compare results of two render_pictures runs.""" 35 """Generate two sets of SKPs, run render_pictures over both, and compare
35 # TODO(epoger): Specify image_base_url pointing at the directory on local 36 the results."""
36 # disk containing our test images, so that we can actually compute pixel 37 self._generate_skps_and_run_render_pictures(
37 # diffs. For now, this test attempts to download images from 38 subdir='before_patch', skpdict={
38 # DEFAULT_IMAGE_BASE_URL, and there aren't any there yet. 39 'changed.skp': 200,
40 'unchanged.skp': 100,
41 'only-in-before.skp': 128,
42 })
43 self._generate_skps_and_run_render_pictures(
44 subdir='after_patch', skpdict={
45 'changed.skp': 201,
46 'unchanged.skp': 100,
47 'only-in-after.skp': 128,
48 })
49
39 results_obj = compare_rendered_pictures.RenderedPicturesComparisons( 50 results_obj = compare_rendered_pictures.RenderedPicturesComparisons(
40 actuals_root=os.path.join(self._input_dir, 'render_pictures_output'), 51 actuals_root=self._temp_dir,
41 subdirs=('before_patch', 'after_patch'), 52 subdirs=('before_patch', 'after_patch'),
42 generated_images_root=self._temp_dir, 53 generated_images_root=self._temp_dir,
43 diff_base_url='/static/generated-images') 54 diff_base_url='/static/generated-images')
44 results_obj.get_timestamp = mock_get_timestamp 55 results_obj.get_timestamp = mock_get_timestamp
56
45 gm_json.WriteToFile( 57 gm_json.WriteToFile(
46 results_obj.get_packaged_results_of_type( 58 results_obj.get_packaged_results_of_type(
47 results.KEY__HEADER__RESULTS_ALL), 59 results.KEY__HEADER__RESULTS_ALL),
48 os.path.join(self._output_dir_actual, 'compare_rendered_pictures.json')) 60 os.path.join(self._output_dir_actual, 'compare_rendered_pictures.json'))
49 61
62 def _generate_skps_and_run_render_pictures(self, subdir, skpdict):
63 """Generate SKPs and run render_pictures on them.
64
65 Args:
66 subdir: subdirectory (within self._temp_dir) to write all files into
67 skpdict: {skpname: redvalue} dictionary describing the SKP files to render
68 """
69 out_path = os.path.join(self._temp_dir, subdir)
70 os.makedirs(out_path)
71 for skpname, redvalue in skpdict.iteritems():
72 self._run_skpmaker(
73 output_path=os.path.join(out_path, skpname), red=redvalue)
74
75 # TODO(epoger): Add --mode tile 256 256 --writeWholeImage to the unittest,
76 # and fix its result! (imageURLs within whole-image entries are wrong when
77 # I tried adding that)
78 binary = self.find_path_to_program('render_pictures')
79 return subprocess.check_output([
80 binary,
81 '--clone', '1',
82 '--config', '8888',
83 '-r', out_path,
84 '--writeChecksumBasedFilenames',
85 '--writeJsonSummaryPath', os.path.join(out_path, 'summary.json'),
86 '--writePath', out_path])
87
88 def _run_skpmaker(self, output_path, red=0, green=0, blue=0,
89 width=640, height=400):
90 """Runs the skpmaker binary to generate SKP with known characteristics.
91
92 Args:
93 output_path: Filepath to write the SKP into.
94 red: Value of red color channel in image, 0-255.
95 green: Value of green color channel in image, 0-255.
96 blue: Value of blue color channel in image, 0-255.
97 width: Width of canvas to create.
98 height: Height of canvas to create.
99 """
100 binary = self.find_path_to_program('skpmaker')
101 return subprocess.check_output([
102 binary,
103 '--red', str(red),
104 '--green', str(green),
105 '--blue', str(blue),
106 '--width', str(width),
107 '--height', str(height),
108 '--writePath', str(output_path)])
50 109
51 def mock_get_timestamp(): 110 def mock_get_timestamp():
52 """Mock version of BaseComparisons.get_timestamp() for testing.""" 111 """Mock version of BaseComparisons.get_timestamp() for testing."""
53 return 12345678 112 return 12345678
54 113
55 114
56 def main(): 115 def main():
57 base_unittest.main(CompareRenderedPicturesTest) 116 base_unittest.main(CompareRenderedPicturesTest)
58 117
59 118
60 if __name__ == '__main__': 119 if __name__ == '__main__':
61 main() 120 main()
OLDNEW
« no previous file with comments | « gm/rebaseline_server/base_unittest.py ('k') | gm/rebaseline_server/testdata/inputs/render_pictures_output/.gitattributes » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698