blob: 9c61080feca14cf9ccde4cc1e6f8d4b2e35e3a42 [file] [log] [blame]
dsinclair2a8a20c2016-04-25 09:46:17 -07001#!/usr/bin/env python
2# Copyright 2016 The PDFium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
dsinclair849284d2016-05-17 06:13:36 -07006import functools
7import multiprocessing
dsinclair2a8a20c2016-04-25 09:46:17 -07008import optparse
9import os
10import re
dsinclair849284d2016-05-17 06:13:36 -070011import shutil
dsinclair2a8a20c2016-04-25 09:46:17 -070012import subprocess
13import sys
14
15import common
stephanafa05e972017-01-02 06:19:41 -080016import gold
dsinclair2a8a20c2016-04-25 09:46:17 -070017import pngdiffer
18import suppressor
19
Ryan Harrison70cca362018-08-10 18:55:46 +000020# Arbitrary timestamp, expressed in seconds since the epoch, used to make sure
21# that tests that depend on the current time are stable. Happens to be the
22# timestamp of the first commit to repo, 2014/5/9 17:48:50.
23TEST_SEED_TIME = "1399672130"
24
Lei Zhangfe3ab672019-11-19 19:09:40 +000025# List of test types that should run text tests instead of pixel tests.
26TEXT_TESTS = ['javascript']
27
Lei Zhang30543372019-11-19 19:02:30 +000028
29class KeyboardInterruptError(Exception):
30 pass
31
dsinclair849284d2016-05-17 06:13:36 -070032
dsinclair2a8a20c2016-04-25 09:46:17 -070033# Nomenclature:
34# x_root - "x"
35# x_filename - "x.ext"
36# x_path - "path/to/a/b/c/x.ext"
37# c_dir - "path/to/a/b/c"
38
Lei Zhang30543372019-11-19 19:02:30 +000039
dsinclair849284d2016-05-17 06:13:36 -070040def TestOneFileParallel(this, test_case):
41 """Wrapper to call GenerateAndTest() and redirect output to stdout."""
42 try:
43 input_filename, source_dir = test_case
Lei Zhang30543372019-11-19 19:02:30 +000044 result = this.GenerateAndTest(input_filename, source_dir)
dsinclair849284d2016-05-17 06:13:36 -070045 return (result, input_filename, source_dir)
46 except KeyboardInterrupt:
47 raise KeyboardInterruptError()
48
49
Lei Zhang5767aca2018-12-05 19:57:46 +000050def DeleteFiles(files):
51 """Utility function to delete a list of files"""
52 for f in files:
53 if os.path.exists(f):
54 os.remove(f)
55
56
dsinclair2a8a20c2016-04-25 09:46:17 -070057class TestRunner:
Lei Zhang30543372019-11-19 19:02:30 +000058
dsinclair2a8a20c2016-04-25 09:46:17 -070059 def __init__(self, dirname):
Ryan Harrison80302c72018-05-10 18:27:25 +000060 # Currently the only used directories are corpus, javascript, and pixel,
61 # which all correspond directly to the type for the test being run. In the
62 # future if there are tests that don't have this clean correspondence, then
63 # an argument for the type will need to be added.
dsinclair2a8a20c2016-04-25 09:46:17 -070064 self.test_dir = dirname
Ryan Harrison80302c72018-05-10 18:27:25 +000065 self.test_type = dirname
Lei Zhang5767aca2018-12-05 19:57:46 +000066 self.delete_output_on_success = False
Henrique Nakashima3bcabf32017-06-27 09:48:24 -040067 self.enforce_expected_images = False
Dan Sinclairaeadad12017-07-18 16:43:41 -040068 self.oneshot_renderer = False
dsinclair2a8a20c2016-04-25 09:46:17 -070069
stephanafa05e972017-01-02 06:19:41 -080070 # GenerateAndTest returns a tuple <success, outputfiles> where
71 # success is a boolean indicating whether the tests passed comparison
72 # tests and outputfiles is a list tuples:
73 # (path_to_image, md5_hash_of_pixelbuffer)
dsinclair2a8a20c2016-04-25 09:46:17 -070074 def GenerateAndTest(self, input_filename, source_dir):
75 input_root, _ = os.path.splitext(input_filename)
dsinclair2a8a20c2016-04-25 09:46:17 -070076 pdf_path = os.path.join(self.working_dir, input_root + '.pdf')
77
78 # Remove any existing generated images from previous runs.
79 actual_images = self.image_differ.GetActualFiles(input_filename, source_dir,
80 self.working_dir)
Lei Zhang5767aca2018-12-05 19:57:46 +000081 DeleteFiles(actual_images)
dsinclair2a8a20c2016-04-25 09:46:17 -070082
83 sys.stdout.flush()
84
85 raised_exception = self.Generate(source_dir, input_filename, input_root,
86 pdf_path)
87
Henrique Nakashima3bcabf32017-06-27 09:48:24 -040088 if raised_exception is not None:
89 print 'FAILURE: %s; %s' % (input_filename, raised_exception)
stephanafa05e972017-01-02 06:19:41 -080090 return False, []
dsinclair2a8a20c2016-04-25 09:46:17 -070091
stephanafa05e972017-01-02 06:19:41 -080092 results = []
Lei Zhangfe3ab672019-11-19 19:09:40 +000093 if self.test_type in TEXT_TESTS:
94 expected_txt_path = os.path.join(source_dir, input_root + '_expected.txt')
dsinclair2a8a20c2016-04-25 09:46:17 -070095 raised_exception = self.TestText(input_root, expected_txt_path, pdf_path)
96 else:
Lei Zhangfe3ab672019-11-19 19:09:40 +000097 use_ahem = 'use_ahem' in source_dir
Ryan Harrison1118a662018-05-31 19:26:52 +000098 raised_exception, results = self.TestPixel(input_root, pdf_path, use_ahem)
dsinclair2a8a20c2016-04-25 09:46:17 -070099
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400100 if raised_exception is not None:
101 print 'FAILURE: %s; %s' % (input_filename, raised_exception)
stephanafa05e972017-01-02 06:19:41 -0800102 return False, results
dsinclair2a8a20c2016-04-25 09:46:17 -0700103
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400104 if actual_images:
dsinclair2a8a20c2016-04-25 09:46:17 -0700105 if self.image_differ.HasDifferences(input_filename, source_dir,
106 self.working_dir):
Henrique Nakashima15bc9742018-04-26 15:55:07 +0000107 self.RegenerateIfNeeded_(input_filename, source_dir)
stephanafa05e972017-01-02 06:19:41 -0800108 return False, results
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400109 else:
Lei Zhang30543372019-11-19 19:02:30 +0000110 if (self.enforce_expected_images and
111 not self.test_suppressor.IsImageDiffSuppressed(input_filename)):
Henrique Nakashima15bc9742018-04-26 15:55:07 +0000112 self.RegenerateIfNeeded_(input_filename, source_dir)
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400113 print 'FAILURE: %s; Missing expected images' % input_filename
114 return False, results
115
Lei Zhang5767aca2018-12-05 19:57:46 +0000116 if self.delete_output_on_success:
117 DeleteFiles(actual_images)
stephanafa05e972017-01-02 06:19:41 -0800118 return True, results
dsinclair2a8a20c2016-04-25 09:46:17 -0700119
Henrique Nakashima15bc9742018-04-26 15:55:07 +0000120 def RegenerateIfNeeded_(self, input_filename, source_dir):
Lei Zhang30543372019-11-19 19:02:30 +0000121 if (not self.options.regenerate_expected or
122 self.test_suppressor.IsResultSuppressed(input_filename) or
123 self.test_suppressor.IsImageDiffSuppressed(input_filename)):
Henrique Nakashima15bc9742018-04-26 15:55:07 +0000124 return
125
126 platform_only = (self.options.regenerate_expected == 'platform')
Lei Zhang30543372019-11-19 19:02:30 +0000127 self.image_differ.Regenerate(input_filename, source_dir, self.working_dir,
128 platform_only)
Henrique Nakashima15bc9742018-04-26 15:55:07 +0000129
dsinclair2a8a20c2016-04-25 09:46:17 -0700130 def Generate(self, source_dir, input_filename, input_root, pdf_path):
131 original_path = os.path.join(source_dir, input_filename)
132 input_path = os.path.join(source_dir, input_root + '.in')
133
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400134 input_event_path = os.path.join(source_dir, input_root + '.evt')
dsinclair849284d2016-05-17 06:13:36 -0700135 if os.path.exists(input_event_path):
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400136 output_event_path = os.path.splitext(pdf_path)[0] + '.evt'
dsinclair849284d2016-05-17 06:13:36 -0700137 shutil.copyfile(input_event_path, output_event_path)
138
dsinclair2a8a20c2016-04-25 09:46:17 -0700139 if not os.path.exists(input_path):
140 if os.path.exists(original_path):
141 shutil.copyfile(original_path, pdf_path)
142 return None
143
144 sys.stdout.flush()
dsinclair849284d2016-05-17 06:13:36 -0700145
Lei Zhang30543372019-11-19 19:02:30 +0000146 return common.RunCommand([
147 sys.executable, self.fixup_path, '--output-dir=' + self.working_dir,
148 input_path
149 ])
dsinclair2a8a20c2016-04-25 09:46:17 -0700150
dsinclair2a8a20c2016-04-25 09:46:17 -0700151 def TestText(self, input_root, expected_txt_path, pdf_path):
152 txt_path = os.path.join(self.working_dir, input_root + '.txt')
153
154 with open(txt_path, 'w') as outfile:
Lei Zhang30543372019-11-19 19:02:30 +0000155 cmd_to_run = [
156 self.pdfium_test_path, '--send-events', '--time=' + TEST_SEED_TIME,
157 pdf_path
158 ]
dsinclair2a8a20c2016-04-25 09:46:17 -0700159 subprocess.check_call(cmd_to_run, stdout=outfile)
160
Lei Zhangfe3ab672019-11-19 19:09:40 +0000161 if not os.path.exists(expected_txt_path):
162 return self._VerifyEmptyText(txt_path)
163
dsinclair2a8a20c2016-04-25 09:46:17 -0700164 cmd = [sys.executable, self.text_diff_path, expected_txt_path, txt_path]
165 return common.RunCommand(cmd)
166
Lei Zhangfe3ab672019-11-19 19:09:40 +0000167 def _VerifyEmptyText(self, txt_path):
168 try:
169 with open(txt_path, "r") as txt_file:
170 txt_data = txt_file.readlines()
171 if not len(txt_data):
172 return None
173 sys.stdout.write('Unexpected output:\n')
174 for line in txt_data:
175 sys.stdout.write(line)
176 raise Exception('%s should be empty.' % txt_path)
177 except Exception as e:
178 return e
179
Ryan Harrison1118a662018-05-31 19:26:52 +0000180 def TestPixel(self, input_root, pdf_path, use_ahem):
Lei Zhang30543372019-11-19 19:02:30 +0000181 cmd_to_run = [
182 self.pdfium_test_path, '--send-events', '--png', '--md5',
183 '--time=' + TEST_SEED_TIME
184 ]
Ryan Harrison1118a662018-05-31 19:26:52 +0000185
Dan Sinclairaeadad12017-07-18 16:43:41 -0400186 if self.oneshot_renderer:
187 cmd_to_run.append('--render-oneshot')
Ryan Harrison1118a662018-05-31 19:26:52 +0000188
189 if use_ahem:
190 cmd_to_run.append('--font-dir=%s' % self.font_dir)
191
stephanafa05e972017-01-02 06:19:41 -0800192 cmd_to_run.append(pdf_path)
193 return common.RunCommandExtractHashedFiles(cmd_to_run)
dsinclair2a8a20c2016-04-25 09:46:17 -0700194
195 def HandleResult(self, input_filename, input_path, result):
dan sinclair00d40642017-01-30 19:48:54 -0800196 success, image_paths = result
Henrique Nakashimaea4a56d2017-11-29 19:34:19 +0000197
198 if image_paths:
199 for img_path, md5_hash in image_paths:
200 # The output filename without image extension becomes the test name.
201 # For example, "/path/to/.../testing/corpus/example_005.pdf.0.png"
202 # becomes "example_005.pdf.0".
203 test_name = os.path.splitext(os.path.split(img_path)[1])[0]
204
Stephan Altmuellerbcd66f52018-06-21 14:45:44 +0000205 matched = "suppressed"
Henrique Nakashimaea4a56d2017-11-29 19:34:19 +0000206 if not self.test_suppressor.IsResultSuppressed(input_filename):
207 matched = self.gold_baseline.MatchLocalResult(test_name, md5_hash)
208 if matched == gold.GoldBaseline.MISMATCH:
209 print 'Skia Gold hash mismatch for test case: %s' % test_name
Lei Zhang30543372019-11-19 19:02:30 +0000210 elif matched == gold.GoldBaseline.NO_BASELINE:
Henrique Nakashimaea4a56d2017-11-29 19:34:19 +0000211 print 'No Skia Gold baseline found for test case: %s' % test_name
212
213 if self.gold_results:
Lei Zhang30543372019-11-19 19:02:30 +0000214 self.gold_results.AddTestResult(test_name, md5_hash, img_path,
215 matched)
stephanafa05e972017-01-02 06:19:41 -0800216
dsinclair2a8a20c2016-04-25 09:46:17 -0700217 if self.test_suppressor.IsResultSuppressed(input_filename):
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400218 self.result_suppressed_cases.append(input_filename)
dan sinclair00d40642017-01-30 19:48:54 -0800219 if success:
dsinclair2a8a20c2016-04-25 09:46:17 -0700220 self.surprises.append(input_path)
221 else:
dan sinclair00d40642017-01-30 19:48:54 -0800222 if not success:
dsinclair2a8a20c2016-04-25 09:46:17 -0700223 self.failures.append(input_path)
224
dsinclair2a8a20c2016-04-25 09:46:17 -0700225 def Run(self):
226 parser = optparse.OptionParser()
stephanafa05e972017-01-02 06:19:41 -0800227
Lei Zhang30543372019-11-19 19:02:30 +0000228 parser.add_option(
229 '--build-dir',
230 default=os.path.join('out', 'Debug'),
231 help='relative path from the base source directory')
stephanafa05e972017-01-02 06:19:41 -0800232
Lei Zhang30543372019-11-19 19:02:30 +0000233 parser.add_option(
234 '-j',
235 default=multiprocessing.cpu_count(),
236 dest='num_workers',
237 type='int',
238 help='run NUM_WORKERS jobs in parallel')
stephanafa05e972017-01-02 06:19:41 -0800239
Lei Zhang30543372019-11-19 19:02:30 +0000240 parser.add_option(
241 '--gold_properties',
242 default='',
243 dest="gold_properties",
244 help='Key value pairs that are written to the top level '
245 'of the JSON file that is ingested by Gold.')
stephanafa05e972017-01-02 06:19:41 -0800246
Lei Zhang30543372019-11-19 19:02:30 +0000247 parser.add_option(
248 '--gold_key',
249 default='',
250 dest="gold_key",
251 help='Key value pairs that are added to the "key" field '
252 'of the JSON file that is ingested by Gold.')
stephanafa05e972017-01-02 06:19:41 -0800253
Lei Zhang30543372019-11-19 19:02:30 +0000254 parser.add_option(
255 '--gold_output_dir',
256 default='',
257 dest="gold_output_dir",
258 help='Path of where to write the JSON output to be '
259 'uploaded to Gold.')
stephanafa05e972017-01-02 06:19:41 -0800260
Lei Zhang30543372019-11-19 19:02:30 +0000261 parser.add_option(
262 '--gold_ignore_hashes',
263 default='',
264 dest="gold_ignore_hashes",
265 help='Path to a file with MD5 hashes we wish to ignore.')
stephanad5320362017-01-26 15:18:54 -0800266
Lei Zhang30543372019-11-19 19:02:30 +0000267 parser.add_option(
268 '--regenerate_expected',
269 default='',
270 dest="regenerate_expected",
271 help='Regenerates expected images. Valid values are '
272 '"all" to regenerate all expected pngs, and '
273 '"platform" to regenerate only platform-specific '
274 'expected pngs.')
Henrique Nakashima06673ed2017-10-25 17:31:13 -0400275
Lei Zhang30543372019-11-19 19:02:30 +0000276 parser.add_option(
277 '--ignore_errors',
278 action="store_true",
279 dest="ignore_errors",
280 help='Prevents the return value from being non-zero '
281 'when image comparison fails.')
stephanafa05e972017-01-02 06:19:41 -0800282
Henrique Nakashima06673ed2017-10-25 17:31:13 -0400283 self.options, self.args = parser.parse_args()
dsinclair2a8a20c2016-04-25 09:46:17 -0700284
Lei Zhang30543372019-11-19 19:02:30 +0000285 if (self.options.regenerate_expected and
286 self.options.regenerate_expected not in ['all', 'platform']):
Henrique Nakashima352e2512017-10-26 11:22:52 -0400287 print 'FAILURE: --regenerate_expected must be "all" or "platform"'
288 return 1
289
Henrique Nakashima06673ed2017-10-25 17:31:13 -0400290 finder = common.DirectoryFinder(self.options.build_dir)
dsinclair2a8a20c2016-04-25 09:46:17 -0700291 self.fixup_path = finder.ScriptPath('fixup_pdf_template.py')
292 self.text_diff_path = finder.ScriptPath('text_diff.py')
Ryan Harrison1118a662018-05-31 19:26:52 +0000293 self.font_dir = os.path.join(finder.TestingDir(), 'resources', 'fonts')
dsinclair2a8a20c2016-04-25 09:46:17 -0700294
dsinclair2a8a20c2016-04-25 09:46:17 -0700295 self.source_dir = finder.TestingDir()
dsinclair849284d2016-05-17 06:13:36 -0700296 if self.test_dir != 'corpus':
297 test_dir = finder.TestingDir(os.path.join('resources', self.test_dir))
298 else:
299 test_dir = finder.TestingDir(self.test_dir)
300
dsinclair2a8a20c2016-04-25 09:46:17 -0700301 self.pdfium_test_path = finder.ExecutablePath('pdfium_test')
302 if not os.path.exists(self.pdfium_test_path):
303 print "FAILURE: Can't find test executable '%s'" % self.pdfium_test_path
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400304 print 'Use --build-dir to specify its location.'
dsinclair2a8a20c2016-04-25 09:46:17 -0700305 return 1
306
307 self.working_dir = finder.WorkingDir(os.path.join('testing', self.test_dir))
Lei Zhang96eff7c2019-09-19 21:08:58 +0000308 shutil.rmtree(self.working_dir, ignore_errors=True)
309 os.makedirs(self.working_dir)
dsinclair2a8a20c2016-04-25 09:46:17 -0700310
Lei Zhang30543372019-11-19 19:02:30 +0000311 self.feature_string = subprocess.check_output(
312 [self.pdfium_test_path, '--show-config'])
dsinclair2a8a20c2016-04-25 09:46:17 -0700313 self.test_suppressor = suppressor.Suppressor(finder, self.feature_string)
314 self.image_differ = pngdiffer.PNGDiffer(finder)
Henrique Nakashima40be5052018-10-10 23:18:14 +0000315 error_message = self.image_differ.CheckMissingTools(
316 self.options.regenerate_expected)
317 if error_message:
318 print "FAILURE: %s" % error_message
319 return 1
dsinclair2a8a20c2016-04-25 09:46:17 -0700320
Henrique Nakashimaea4a56d2017-11-29 19:34:19 +0000321 self.gold_baseline = gold.GoldBaseline(self.options.gold_properties)
322
Lei Zhang30543372019-11-19 19:02:30 +0000323 walk_from_dir = finder.TestingDir(test_dir)
dsinclair2a8a20c2016-04-25 09:46:17 -0700324
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400325 self.test_cases = []
326 self.execution_suppressed_cases = []
Henrique Nakashima62d50762017-06-27 13:06:23 -0400327 input_file_re = re.compile('^.+[.](in|pdf)$')
Henrique Nakashima06673ed2017-10-25 17:31:13 -0400328 if self.args:
329 for file_name in self.args:
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400330 file_name.replace('.pdf', '.in')
dsinclair2a8a20c2016-04-25 09:46:17 -0700331 input_path = os.path.join(walk_from_dir, file_name)
332 if not os.path.isfile(input_path):
333 print "Can't find test file '%s'" % file_name
334 return 1
335
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400336 self.test_cases.append((os.path.basename(input_path),
Lei Zhang30543372019-11-19 19:02:30 +0000337 os.path.dirname(input_path)))
dsinclair2a8a20c2016-04-25 09:46:17 -0700338 else:
339 for file_dir, _, filename_list in os.walk(walk_from_dir):
340 for input_filename in filename_list:
341 if input_file_re.match(input_filename):
342 input_path = os.path.join(file_dir, input_filename)
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400343 if self.test_suppressor.IsExecutionSuppressed(input_path):
344 self.execution_suppressed_cases.append(input_path)
345 else:
dsinclair2a8a20c2016-04-25 09:46:17 -0700346 if os.path.isfile(input_path):
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400347 self.test_cases.append((input_filename, file_dir))
dsinclair2a8a20c2016-04-25 09:46:17 -0700348
Lei Zhang1ee96012018-04-09 17:31:14 +0000349 self.test_cases.sort()
dsinclair2a8a20c2016-04-25 09:46:17 -0700350 self.failures = []
351 self.surprises = []
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400352 self.result_suppressed_cases = []
dsinclair2a8a20c2016-04-25 09:46:17 -0700353
stephanafa05e972017-01-02 06:19:41 -0800354 # Collect Gold results if an output directory was named.
355 self.gold_results = None
Henrique Nakashima06673ed2017-10-25 17:31:13 -0400356 if self.options.gold_output_dir:
Lei Zhang30543372019-11-19 19:02:30 +0000357 self.gold_results = gold.GoldResults(
358 self.test_type, self.options.gold_output_dir,
359 self.options.gold_properties, self.options.gold_key,
360 self.options.gold_ignore_hashes)
stephanafa05e972017-01-02 06:19:41 -0800361
Henrique Nakashima06673ed2017-10-25 17:31:13 -0400362 if self.options.num_workers > 1 and len(self.test_cases) > 1:
dsinclair849284d2016-05-17 06:13:36 -0700363 try:
Henrique Nakashima06673ed2017-10-25 17:31:13 -0400364 pool = multiprocessing.Pool(self.options.num_workers)
dsinclair849284d2016-05-17 06:13:36 -0700365 worker_func = functools.partial(TestOneFileParallel, self)
366
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400367 worker_results = pool.imap(worker_func, self.test_cases)
dsinclair849284d2016-05-17 06:13:36 -0700368 for worker_result in worker_results:
369 result, input_filename, source_dir = worker_result
370 input_path = os.path.join(source_dir, input_filename)
371
372 self.HandleResult(input_filename, input_path, result)
373
374 except KeyboardInterrupt:
375 pool.terminate()
376 finally:
377 pool.close()
378 pool.join()
379 else:
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400380 for test_case in self.test_cases:
dsinclair849284d2016-05-17 06:13:36 -0700381 input_filename, input_file_dir = test_case
382 result = self.GenerateAndTest(input_filename, input_file_dir)
383 self.HandleResult(input_filename,
384 os.path.join(input_file_dir, input_filename), result)
dsinclair2a8a20c2016-04-25 09:46:17 -0700385
stephanafa05e972017-01-02 06:19:41 -0800386 if self.gold_results:
387 self.gold_results.WriteResults()
388
dsinclair2a8a20c2016-04-25 09:46:17 -0700389 if self.surprises:
390 self.surprises.sort()
391 print '\n\nUnexpected Successes:'
392 for surprise in self.surprises:
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400393 print surprise
dsinclair2a8a20c2016-04-25 09:46:17 -0700394
395 if self.failures:
396 self.failures.sort()
397 print '\n\nSummary of Failures:'
398 for failure in self.failures:
399 print failure
dan sinclair00d40642017-01-30 19:48:54 -0800400
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400401 self._PrintSummary()
402
403 if self.failures:
Henrique Nakashima06673ed2017-10-25 17:31:13 -0400404 if not self.options.ignore_errors:
dan sinclair00d40642017-01-30 19:48:54 -0800405 return 1
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400406
dsinclair2a8a20c2016-04-25 09:46:17 -0700407 return 0
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400408
409 def _PrintSummary(self):
410 number_test_cases = len(self.test_cases)
411 number_failures = len(self.failures)
412 number_suppressed = len(self.result_suppressed_cases)
413 number_successes = number_test_cases - number_failures - number_suppressed
414 number_surprises = len(self.surprises)
415 print
416 print 'Test cases executed: %d' % number_test_cases
417 print ' Successes: %d' % number_successes
418 print ' Suppressed: %d' % number_suppressed
419 print ' Surprises: %d' % number_surprises
420 print ' Failures: %d' % number_failures
421 print
422 print 'Test cases not executed: %d' % len(self.execution_suppressed_cases)
423
Lei Zhang5767aca2018-12-05 19:57:46 +0000424 def SetDeleteOutputOnSuccess(self, new_value):
425 """Set whether to delete generated output if the test passes."""
426 self.delete_output_on_success = new_value
427
Henrique Nakashima3bcabf32017-06-27 09:48:24 -0400428 def SetEnforceExpectedImages(self, new_value):
429 """Set whether to enforce that each test case provide an expected image."""
430 self.enforce_expected_images = new_value
Dan Sinclairaeadad12017-07-18 16:43:41 -0400431
432 def SetOneShotRenderer(self, new_value):
433 """Set whether to use the oneshot renderer. """
434 self.oneshot_renderer = new_value