blob: b2397c4ddafca7bbe44732639ea5653e68d9fad2 [file] [log] [blame]
junov@chromium.org777442d2012-06-12 14:56:36 +00001'''
2Compares the rendererings of serialized SkPictures to expected images.
3
4Launch with --help to see more information.
5
6
7Copyright 2012 Google Inc.
8
9Use of this source code is governed by a BSD-style license that can be
10found in the LICENSE file.
11'''
12# common Python modules
13import os
14import optparse
15import sys
16import shutil
17import tempfile
18
edisonn@google.comc2c49812012-10-10 15:08:12 +000019# modules declared within this same directory
20import test_rendering
21
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +000022USAGE_STRING = 'Usage: %s input... expectedDir'
junov@chromium.org777442d2012-06-12 14:56:36 +000023HELP_STRING = '''
24
edisonn@google.comc2c49812012-10-10 15:08:12 +000025Takes input SkPicture files and renders them as PNG files, and then compares
26those resulting PNG files against PNG files found in expectedDir.
27
28Each instance of "input" can be either a file (name must end in .skp), or a
29directory (in which case this script will process all .skp files within the
30directory).
junov@chromium.org777442d2012-06-12 14:56:36 +000031'''
32
keyar@chromium.orge599ab72012-08-23 21:51:11 +000033def ModeParse(option, opt_str, value, parser):
34 """Parses the --mode option of the commandline.
35
36 The --mode option will either take in three parameters (if tile or
37 pow2tile) or a single parameter (otherwise).
38 """
39 result = [value]
40 if value == "tile":
41 if (len(parser.rargs) < 2):
42 raise optparse.OptionValueError(("--mode tile mising width"
43 " and/or height parameters"))
44 result.extend(parser.rargs[:2])
45 del parser.rargs[:2]
46 elif value == "pow2tile":
47 if (len(parser.rargs) < 2):
48 raise optparse.OptionValueError(("--mode pow2tile mising minWidth"
49 " and/or height parameters"))
50 result.extend(parser.rargs[:2])
51 del parser.rargs[:2]
52
53 setattr(parser.values, option.dest, result)
54
55
junov@chromium.org777442d2012-06-12 14:56:36 +000056def Main(args):
57 """Allow other scripts to call this script with fake command-line args.
58
59 @param The commandline argument list
60 """
61 parser = optparse.OptionParser(USAGE_STRING % '%prog' + HELP_STRING)
62 parser.add_option('--render_dir', dest='render_dir',
63 help = ("specify the location to output the rendered files."
64 " Default is a temp directory."))
65 parser.add_option('--diff_dir', dest='diff_dir',
66 help = ("specify the location to output the diff files."
67 " Default is a temp directory."))
keyar@chromium.orge599ab72012-08-23 21:51:11 +000068 parser.add_option('--mode', dest='mode', type='string',
69 action="callback", callback=ModeParse,
70 help = ("specify how rendering is to be done."))
71 parser.add_option('--device', dest='device',
72 help = ("specify the device to render to."))
junov@chromium.org777442d2012-06-12 14:56:36 +000073
74 options, arguments = parser.parse_args(args)
75
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +000076 if (len(arguments) < 3):
77 print("Expected at least one input and one ouput folder.")
78 parser.print_help()
79 sys.exit(-1)
80
81 inputs = arguments[1:-1]
82 expected_dir = arguments[-1]
junov@chromium.org777442d2012-06-12 14:56:36 +000083
edisonn@google.comc2c49812012-10-10 15:08:12 +000084 extra_args = ''
junov@chromium.org777442d2012-06-12 14:56:36 +000085
edisonn@google.comc2c49812012-10-10 15:08:12 +000086 if (options.mode is not None):
87 extra_args += ' --mode %s' % ' '.join(options.mode)
junov@chromium.org777442d2012-06-12 14:56:36 +000088
edisonn@google.comc2c49812012-10-10 15:08:12 +000089 if (options.device is not None):
90 extra_args += ' --device %s' % options.device
91
92 test_rendering.TestRenderSkps(inputs, expected_dir, options.render_dir,
93 options.diff_dir, 'render_pictures',
94 extra_args)
junov@chromium.org777442d2012-06-12 14:56:36 +000095
96if __name__ == '__main__':
97 Main(sys.argv)