blob: 7ccb3b87315d7d34fa71a657373cc7972270a730 [file] [log] [blame]
junov@chromium.org777442d2012-06-12 14:56:36 +00001'''
junov@chromium.org777442d2012-06-12 14:56:36 +00002Copyright 2012 Google Inc.
3
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
commit-bot@chromium.org11f15622014-01-07 17:03:40 +00006
7Compares the rendererings of serialized SkPictures to expected images.
8
9Launch with --help to see more information.
10
11TODO(epoger): Combine with overlapping tools/tests/render_pictures_test.py .
12See https://code.google.com/p/skia/issues/detail?id=1943#c2
junov@chromium.org777442d2012-06-12 14:56:36 +000013'''
14# common Python modules
15import os
16import optparse
17import sys
18import shutil
19import tempfile
20
edisonn@google.comc2c49812012-10-10 15:08:12 +000021# modules declared within this same directory
22import test_rendering
23
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +000024USAGE_STRING = 'Usage: %s input... expectedDir'
junov@chromium.org777442d2012-06-12 14:56:36 +000025HELP_STRING = '''
26
edisonn@google.comc2c49812012-10-10 15:08:12 +000027Takes input SkPicture files and renders them as PNG files, and then compares
28those resulting PNG files against PNG files found in expectedDir.
29
30Each instance of "input" can be either a file (name must end in .skp), or a
31directory (in which case this script will process all .skp files within the
32directory).
junov@chromium.org777442d2012-06-12 14:56:36 +000033'''
34
keyar@chromium.orge599ab72012-08-23 21:51:11 +000035def ModeParse(option, opt_str, value, parser):
36 """Parses the --mode option of the commandline.
37
38 The --mode option will either take in three parameters (if tile or
39 pow2tile) or a single parameter (otherwise).
40 """
41 result = [value]
42 if value == "tile":
43 if (len(parser.rargs) < 2):
44 raise optparse.OptionValueError(("--mode tile mising width"
45 " and/or height parameters"))
46 result.extend(parser.rargs[:2])
47 del parser.rargs[:2]
48 elif value == "pow2tile":
49 if (len(parser.rargs) < 2):
50 raise optparse.OptionValueError(("--mode pow2tile mising minWidth"
51 " and/or height parameters"))
52 result.extend(parser.rargs[:2])
53 del parser.rargs[:2]
54
55 setattr(parser.values, option.dest, result)
56
57
junov@chromium.org777442d2012-06-12 14:56:36 +000058def Main(args):
59 """Allow other scripts to call this script with fake command-line args.
60
61 @param The commandline argument list
62 """
63 parser = optparse.OptionParser(USAGE_STRING % '%prog' + HELP_STRING)
64 parser.add_option('--render_dir', dest='render_dir',
65 help = ("specify the location to output the rendered files."
66 " Default is a temp directory."))
67 parser.add_option('--diff_dir', dest='diff_dir',
68 help = ("specify the location to output the diff files."
69 " Default is a temp directory."))
keyar@chromium.orge599ab72012-08-23 21:51:11 +000070 parser.add_option('--mode', dest='mode', type='string',
71 action="callback", callback=ModeParse,
72 help = ("specify how rendering is to be done."))
73 parser.add_option('--device', dest='device',
74 help = ("specify the device to render to."))
junov@chromium.org777442d2012-06-12 14:56:36 +000075
76 options, arguments = parser.parse_args(args)
77
keyar@chromium.orgd1dc9202012-07-09 18:32:08 +000078 if (len(arguments) < 3):
79 print("Expected at least one input and one ouput folder.")
80 parser.print_help()
81 sys.exit(-1)
82
83 inputs = arguments[1:-1]
84 expected_dir = arguments[-1]
junov@chromium.org777442d2012-06-12 14:56:36 +000085
edisonn@google.comc2c49812012-10-10 15:08:12 +000086 extra_args = ''
junov@chromium.org777442d2012-06-12 14:56:36 +000087
edisonn@google.comc2c49812012-10-10 15:08:12 +000088 if (options.mode is not None):
89 extra_args += ' --mode %s' % ' '.join(options.mode)
junov@chromium.org777442d2012-06-12 14:56:36 +000090
edisonn@google.comc2c49812012-10-10 15:08:12 +000091 if (options.device is not None):
92 extra_args += ' --device %s' % options.device
93
94 test_rendering.TestRenderSkps(inputs, expected_dir, options.render_dir,
95 options.diff_dir, 'render_pictures',
96 extra_args)
junov@chromium.org777442d2012-06-12 14:56:36 +000097
98if __name__ == '__main__':
99 Main(sys.argv)