edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 1 | ''' |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 2 | Copyright 2012 Google Inc. |
| 3 | |
| 4 | Use of this source code is governed by a BSD-style license that can be |
| 5 | found in the LICENSE file. |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 6 | |
| 7 | Compares the rendererings of serialized SkPictures to expected result. |
| 8 | |
commit-bot@chromium.org | 30d4f83 | 2014-01-14 17:01:28 +0000 | [diff] [blame] | 9 | TODO(epoger): We believe this script is no longer used, so we have disabled it |
| 10 | and will remove it on 1 Feb 2014 if nobody objects. |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 11 | See https://code.google.com/p/skia/issues/detail?id=1943#c2 |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 12 | ''' |
| 13 | # common Python modules |
| 14 | import os |
| 15 | import optparse |
| 16 | import sys |
| 17 | import shutil |
| 18 | import tempfile |
| 19 | |
| 20 | USAGE_STRING = 'Usage: %s input... expectedDir render_app [reander_app_args]' |
| 21 | HELP_STRING = ''' |
| 22 | |
| 23 | Compares the renderings of serialized SkPicture files and directories specified |
| 24 | by input with the files in expectedDir. Note, files in directoriers are |
| 25 | expected to end with .skp. |
| 26 | ''' |
| 27 | |
commit-bot@chromium.org | 30d4f83 | 2014-01-14 17:01:28 +0000 | [diff] [blame] | 28 | def _DieBecauseDeprecated(): |
| 29 | print ('We believe this script is no longer used, so we have disabled it ' |
| 30 | 'and will remove it on 1 Feb 2014 if nobody objects. See ' |
| 31 | 'https://code.google.com/p/skia/issues/detail?id=1943#c2') |
| 32 | sys.exit(-1) |
| 33 | |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 34 | def RunCommand(command): |
| 35 | """Run a command. |
| 36 | |
| 37 | @param command the command as a single string |
| 38 | """ |
commit-bot@chromium.org | 30d4f83 | 2014-01-14 17:01:28 +0000 | [diff] [blame] | 39 | _DieBecauseDeprecated() |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 40 | print 'running command [%s]...' % command |
| 41 | os.system(command) |
| 42 | |
| 43 | |
| 44 | def FindPathToProgram(program): |
| 45 | """Return path to an existing program binary, or raise an exception if we |
| 46 | cannot find one. |
| 47 | |
| 48 | @param program the name of the program that is being looked for |
| 49 | """ |
commit-bot@chromium.org | 30d4f83 | 2014-01-14 17:01:28 +0000 | [diff] [blame] | 50 | _DieBecauseDeprecated() |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 51 | trunk_path = os.path.abspath(os.path.join(os.path.dirname(__file__), |
| 52 | os.pardir)) |
| 53 | possible_paths = [os.path.join(trunk_path, 'out', 'Release', program), |
| 54 | os.path.join(trunk_path, 'out', 'Debug', program), |
| 55 | os.path.join(trunk_path, 'out', 'Release', |
| 56 | program + ".exe"), |
| 57 | os.path.join(trunk_path, 'out', 'Debug', |
| 58 | program + ".exe")] |
| 59 | for try_path in possible_paths: |
| 60 | if os.path.isfile(try_path): |
| 61 | return try_path |
| 62 | raise Exception('cannot find %s in paths %s; maybe you need to ' |
| 63 | 'build %s?' % (program, possible_paths, program)) |
| 64 | |
| 65 | |
| 66 | def RenderSkps(inputs, render_dir, render_app, args): |
| 67 | """Renders the serialized SkPictures. |
| 68 | |
| 69 | Uses the render_pictures program to do the rendering. |
| 70 | |
| 71 | @param inputs the location(s) to read the serlialized SkPictures |
| 72 | @param render_dir the location to write out the rendered images |
| 73 | """ |
commit-bot@chromium.org | 30d4f83 | 2014-01-14 17:01:28 +0000 | [diff] [blame] | 74 | _DieBecauseDeprecated() |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 75 | renderer_path = FindPathToProgram(render_app) |
| 76 | inputs_as_string = " ".join(inputs) |
| 77 | command = '%s %s %s' % (renderer_path, inputs_as_string, render_dir) |
| 78 | |
| 79 | command += args |
| 80 | |
| 81 | RunCommand(command) |
| 82 | |
| 83 | |
| 84 | def DiffRenderings(expected_dir, comparison_dir, diff_dir): |
| 85 | """Diffs the rendered SkPicture files with the baseline files. |
| 86 | |
| 87 | Uses the skdiff program to do the diffing. |
| 88 | |
| 89 | @param expected_dir the location of the baseline images. |
| 90 | @param comparison_dir the location of the images to comapre with the |
| 91 | baseline |
| 92 | @param diff_dir the location to write out the diff results |
| 93 | """ |
commit-bot@chromium.org | 30d4f83 | 2014-01-14 17:01:28 +0000 | [diff] [blame] | 94 | _DieBecauseDeprecated() |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 95 | skdiff_path = FindPathToProgram('skdiff') |
| 96 | RunCommand('%s %s %s %s %s' % |
| 97 | (skdiff_path, expected_dir, comparison_dir, diff_dir, |
| 98 | '--noprintdirs')) |
| 99 | |
| 100 | |
| 101 | def Cleanup(render_dir_option, diff_dir_option, render_dir, diff_dir): |
| 102 | """Deletes any temporary folders and files created. |
| 103 | |
| 104 | @param foo_option The OptionParser parsed render_dir or diff_dir vars. |
| 105 | If these variables are not passed by user we ended up creating |
| 106 | temporary directories (render_dir, diff_dir) which we will remove. |
| 107 | @param render_dir the directory where the rendered images were written |
| 108 | @param diff_dir the directory where the diff results were written |
| 109 | """ |
commit-bot@chromium.org | 30d4f83 | 2014-01-14 17:01:28 +0000 | [diff] [blame] | 110 | _DieBecauseDeprecated() |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 111 | if (not render_dir_option): |
| 112 | if (os.path.isdir(render_dir)): |
| 113 | shutil.rmtree(render_dir) |
| 114 | if (not diff_dir_option): |
| 115 | if (os.path.isdir(diff_dir)): |
| 116 | shutil.rmtree(diff_dir) |
| 117 | |
| 118 | def TestRenderSkps(inputs, expected_dir, render_dir_option, diff_dir_option, |
| 119 | render_app, render_args): |
commit-bot@chromium.org | 30d4f83 | 2014-01-14 17:01:28 +0000 | [diff] [blame] | 120 | _DieBecauseDeprecated() |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 121 | if (render_dir_option): |
| 122 | render_dir = render_dir_option |
| 123 | else: |
| 124 | render_dir = tempfile.mkdtemp() |
| 125 | |
| 126 | if (diff_dir_option): |
| 127 | diff_dir = diff_dir_option |
| 128 | else: |
| 129 | diff_dir = tempfile.mkdtemp() |
| 130 | try: |
| 131 | RenderSkps(inputs, render_dir, render_app, render_args) |
| 132 | DiffRenderings(expected_dir, render_dir, diff_dir) |
| 133 | finally: |
| 134 | Cleanup(render_dir_option, diff_dir_option, render_dir, diff_dir) |