dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 1 | #!/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 | |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 6 | import cStringIO |
| 7 | import functools |
| 8 | import multiprocessing |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 9 | import optparse |
| 10 | import os |
| 11 | import re |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 12 | import shutil |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 13 | import subprocess |
| 14 | import sys |
| 15 | |
| 16 | import common |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 17 | import gold |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 18 | import pngdiffer |
| 19 | import suppressor |
| 20 | |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 21 | class KeyboardInterruptError(Exception): pass |
| 22 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 23 | # Nomenclature: |
| 24 | # x_root - "x" |
| 25 | # x_filename - "x.ext" |
| 26 | # x_path - "path/to/a/b/c/x.ext" |
| 27 | # c_dir - "path/to/a/b/c" |
| 28 | |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 29 | def TestOneFileParallel(this, test_case): |
| 30 | """Wrapper to call GenerateAndTest() and redirect output to stdout.""" |
| 31 | try: |
| 32 | input_filename, source_dir = test_case |
| 33 | result = this.GenerateAndTest(input_filename, source_dir); |
| 34 | return (result, input_filename, source_dir) |
| 35 | except KeyboardInterrupt: |
| 36 | raise KeyboardInterruptError() |
| 37 | |
| 38 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 39 | class TestRunner: |
| 40 | def __init__(self, dirname): |
| 41 | self.test_dir = dirname |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 42 | self.enforce_expected_images = False |
Dan Sinclair | aeadad1 | 2017-07-18 16:43:41 -0400 | [diff] [blame] | 43 | self.oneshot_renderer = False |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 44 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 45 | # GenerateAndTest returns a tuple <success, outputfiles> where |
| 46 | # success is a boolean indicating whether the tests passed comparison |
| 47 | # tests and outputfiles is a list tuples: |
| 48 | # (path_to_image, md5_hash_of_pixelbuffer) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 49 | def GenerateAndTest(self, input_filename, source_dir): |
| 50 | input_root, _ = os.path.splitext(input_filename) |
| 51 | expected_txt_path = os.path.join(source_dir, input_root + '_expected.txt') |
| 52 | |
| 53 | pdf_path = os.path.join(self.working_dir, input_root + '.pdf') |
| 54 | |
| 55 | # Remove any existing generated images from previous runs. |
| 56 | actual_images = self.image_differ.GetActualFiles(input_filename, source_dir, |
| 57 | self.working_dir) |
| 58 | for image in actual_images: |
| 59 | if os.path.exists(image): |
| 60 | os.remove(image) |
| 61 | |
| 62 | sys.stdout.flush() |
| 63 | |
| 64 | raised_exception = self.Generate(source_dir, input_filename, input_root, |
| 65 | pdf_path) |
| 66 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 67 | if raised_exception is not None: |
| 68 | print 'FAILURE: %s; %s' % (input_filename, raised_exception) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 69 | return False, [] |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 70 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 71 | results = [] |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 72 | if os.path.exists(expected_txt_path): |
| 73 | raised_exception = self.TestText(input_root, expected_txt_path, pdf_path) |
| 74 | else: |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 75 | raised_exception, results = self.TestPixel(input_root, pdf_path) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 76 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 77 | if raised_exception is not None: |
| 78 | print 'FAILURE: %s; %s' % (input_filename, raised_exception) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 79 | return False, results |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 80 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 81 | if actual_images: |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 82 | if self.image_differ.HasDifferences(input_filename, source_dir, |
| 83 | self.working_dir): |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 84 | if (self.options.regenerate_expected |
| 85 | and not self.test_suppressor.IsResultSuppressed(input_filename) |
| 86 | and not self.test_suppressor.IsImageDiffSuppressed(input_filename)): |
Henrique Nakashima | 352e251 | 2017-10-26 11:22:52 -0400 | [diff] [blame^] | 87 | platform_only = (self.options.regenerate_expected == 'platform') |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 88 | self.image_differ.Regenerate(input_filename, source_dir, |
Henrique Nakashima | 352e251 | 2017-10-26 11:22:52 -0400 | [diff] [blame^] | 89 | self.working_dir, platform_only) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 90 | return False, results |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 91 | else: |
| 92 | if (self.enforce_expected_images |
Henrique Nakashima | 6fac27d | 2017-06-27 15:52:45 -0400 | [diff] [blame] | 93 | and not self.test_suppressor.IsImageDiffSuppressed(input_filename)): |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 94 | print 'FAILURE: %s; Missing expected images' % input_filename |
| 95 | return False, results |
| 96 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 97 | return True, results |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 98 | |
| 99 | def Generate(self, source_dir, input_filename, input_root, pdf_path): |
| 100 | original_path = os.path.join(source_dir, input_filename) |
| 101 | input_path = os.path.join(source_dir, input_root + '.in') |
| 102 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 103 | input_event_path = os.path.join(source_dir, input_root + '.evt') |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 104 | if os.path.exists(input_event_path): |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 105 | output_event_path = os.path.splitext(pdf_path)[0] + '.evt' |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 106 | shutil.copyfile(input_event_path, output_event_path) |
| 107 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 108 | if not os.path.exists(input_path): |
| 109 | if os.path.exists(original_path): |
| 110 | shutil.copyfile(original_path, pdf_path) |
| 111 | return None |
| 112 | |
| 113 | sys.stdout.flush() |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 114 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 115 | return common.RunCommand( |
| 116 | [sys.executable, self.fixup_path, '--output-dir=' + self.working_dir, |
| 117 | input_path]) |
| 118 | |
| 119 | |
| 120 | def TestText(self, input_root, expected_txt_path, pdf_path): |
| 121 | txt_path = os.path.join(self.working_dir, input_root + '.txt') |
| 122 | |
| 123 | with open(txt_path, 'w') as outfile: |
Lei Zhang | 63b0126 | 2017-08-31 08:54:46 -0700 | [diff] [blame] | 124 | cmd_to_run = [self.pdfium_test_path, '--send-events', pdf_path] |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 125 | subprocess.check_call(cmd_to_run, stdout=outfile) |
| 126 | |
| 127 | cmd = [sys.executable, self.text_diff_path, expected_txt_path, txt_path] |
| 128 | return common.RunCommand(cmd) |
| 129 | |
| 130 | |
| 131 | def TestPixel(self, input_root, pdf_path): |
dan sinclair | 5c19c35 | 2017-02-01 09:46:52 -0800 | [diff] [blame] | 132 | cmd_to_run = [self.pdfium_test_path, '--send-events', '--png'] |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 133 | if self.gold_results: |
| 134 | cmd_to_run.append('--md5') |
Dan Sinclair | aeadad1 | 2017-07-18 16:43:41 -0400 | [diff] [blame] | 135 | if self.oneshot_renderer: |
| 136 | cmd_to_run.append('--render-oneshot') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 137 | cmd_to_run.append(pdf_path) |
| 138 | return common.RunCommandExtractHashedFiles(cmd_to_run) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 139 | |
| 140 | def HandleResult(self, input_filename, input_path, result): |
dan sinclair | 00d4064 | 2017-01-30 19:48:54 -0800 | [diff] [blame] | 141 | success, image_paths = result |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 142 | if self.gold_results: |
stephana | 38c2705 | 2017-01-13 13:16:40 -0800 | [diff] [blame] | 143 | if image_paths: |
| 144 | for img_path, md5_hash in image_paths: |
| 145 | # the output filename (without extension becomes the test name) |
| 146 | test_name = os.path.splitext(os.path.split(img_path)[1])[0] |
| 147 | self.gold_results.AddTestResult(test_name, md5_hash, img_path) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 148 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 149 | if self.test_suppressor.IsResultSuppressed(input_filename): |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 150 | self.result_suppressed_cases.append(input_filename) |
dan sinclair | 00d4064 | 2017-01-30 19:48:54 -0800 | [diff] [blame] | 151 | if success: |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 152 | self.surprises.append(input_path) |
| 153 | else: |
dan sinclair | 00d4064 | 2017-01-30 19:48:54 -0800 | [diff] [blame] | 154 | if not success: |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 155 | self.failures.append(input_path) |
| 156 | |
| 157 | |
| 158 | def Run(self): |
| 159 | parser = optparse.OptionParser() |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 160 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 161 | parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), |
| 162 | help='relative path from the base source directory') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 163 | |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 164 | parser.add_option('-j', default=multiprocessing.cpu_count(), |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 165 | dest='num_workers', type='int', |
| 166 | help='run NUM_WORKERS jobs in parallel') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 167 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 168 | parser.add_option('--gold_properties', default='', dest="gold_properties", |
Henrique Nakashima | 352e251 | 2017-10-26 11:22:52 -0400 | [diff] [blame^] | 169 | help='Key value pairs that are written to the top level ' |
| 170 | 'of the JSON file that is ingested by Gold.') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 171 | |
| 172 | parser.add_option('--gold_key', default='', dest="gold_key", |
Henrique Nakashima | 352e251 | 2017-10-26 11:22:52 -0400 | [diff] [blame^] | 173 | help='Key value pairs that are added to the "key" field ' |
| 174 | 'of the JSON file that is ingested by Gold.') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 175 | |
| 176 | parser.add_option('--gold_output_dir', default='', dest="gold_output_dir", |
Henrique Nakashima | 352e251 | 2017-10-26 11:22:52 -0400 | [diff] [blame^] | 177 | help='Path of where to write the JSON output to be ' |
| 178 | 'uploaded to Gold.') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 179 | |
Henrique Nakashima | 352e251 | 2017-10-26 11:22:52 -0400 | [diff] [blame^] | 180 | parser.add_option('--gold_ignore_hashes', default='', |
| 181 | dest="gold_ignore_hashes", |
stephana | d532036 | 2017-01-26 15:18:54 -0800 | [diff] [blame] | 182 | help='Path to a file with MD5 hashes we wish to ignore.') |
| 183 | |
Henrique Nakashima | 352e251 | 2017-10-26 11:22:52 -0400 | [diff] [blame^] | 184 | parser.add_option('--regenerate_expected', default='', |
| 185 | dest="regenerate_expected", |
| 186 | help='Regenerates expected images. Valid values are ' |
| 187 | '"all" to regenerate all expected pngs, and ' |
| 188 | '"platform" to regenerate only platform-specific ' |
| 189 | 'expected pngs.') |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 190 | |
Henrique Nakashima | 352e251 | 2017-10-26 11:22:52 -0400 | [diff] [blame^] | 191 | parser.add_option('--ignore_errors', action="store_true", |
| 192 | dest="ignore_errors", |
| 193 | help='Prevents the return value from being non-zero ' |
| 194 | 'when image comparison fails.') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 195 | |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 196 | self.options, self.args = parser.parse_args() |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 197 | |
Henrique Nakashima | 352e251 | 2017-10-26 11:22:52 -0400 | [diff] [blame^] | 198 | if (self.options.regenerate_expected |
| 199 | and self.options.regenerate_expected not in ['all', 'platform']) : |
| 200 | print 'FAILURE: --regenerate_expected must be "all" or "platform"' |
| 201 | return 1 |
| 202 | |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 203 | finder = common.DirectoryFinder(self.options.build_dir) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 204 | self.fixup_path = finder.ScriptPath('fixup_pdf_template.py') |
| 205 | self.text_diff_path = finder.ScriptPath('text_diff.py') |
| 206 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 207 | self.source_dir = finder.TestingDir() |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 208 | if self.test_dir != 'corpus': |
| 209 | test_dir = finder.TestingDir(os.path.join('resources', self.test_dir)) |
| 210 | else: |
| 211 | test_dir = finder.TestingDir(self.test_dir) |
| 212 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 213 | self.pdfium_test_path = finder.ExecutablePath('pdfium_test') |
| 214 | if not os.path.exists(self.pdfium_test_path): |
| 215 | print "FAILURE: Can't find test executable '%s'" % self.pdfium_test_path |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 216 | print 'Use --build-dir to specify its location.' |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 217 | return 1 |
| 218 | |
| 219 | self.working_dir = finder.WorkingDir(os.path.join('testing', self.test_dir)) |
| 220 | if not os.path.exists(self.working_dir): |
| 221 | os.makedirs(self.working_dir) |
| 222 | |
| 223 | self.feature_string = subprocess.check_output([self.pdfium_test_path, |
| 224 | '--show-config']) |
| 225 | self.test_suppressor = suppressor.Suppressor(finder, self.feature_string) |
| 226 | self.image_differ = pngdiffer.PNGDiffer(finder) |
| 227 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 228 | walk_from_dir = finder.TestingDir(test_dir); |
| 229 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 230 | self.test_cases = [] |
| 231 | self.execution_suppressed_cases = [] |
Henrique Nakashima | 62d5076 | 2017-06-27 13:06:23 -0400 | [diff] [blame] | 232 | input_file_re = re.compile('^.+[.](in|pdf)$') |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 233 | if self.args: |
| 234 | for file_name in self.args: |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 235 | file_name.replace('.pdf', '.in') |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 236 | input_path = os.path.join(walk_from_dir, file_name) |
| 237 | if not os.path.isfile(input_path): |
| 238 | print "Can't find test file '%s'" % file_name |
| 239 | return 1 |
| 240 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 241 | self.test_cases.append((os.path.basename(input_path), |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 242 | os.path.dirname(input_path))) |
| 243 | else: |
| 244 | for file_dir, _, filename_list in os.walk(walk_from_dir): |
| 245 | for input_filename in filename_list: |
| 246 | if input_file_re.match(input_filename): |
| 247 | input_path = os.path.join(file_dir, input_filename) |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 248 | if self.test_suppressor.IsExecutionSuppressed(input_path): |
| 249 | self.execution_suppressed_cases.append(input_path) |
| 250 | else: |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 251 | if os.path.isfile(input_path): |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 252 | self.test_cases.append((input_filename, file_dir)) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 253 | |
| 254 | self.failures = [] |
| 255 | self.surprises = [] |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 256 | self.result_suppressed_cases = [] |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 257 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 258 | # Collect Gold results if an output directory was named. |
| 259 | self.gold_results = None |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 260 | if self.options.gold_output_dir: |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 261 | self.gold_results = gold.GoldResults('pdfium', |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 262 | self.options.gold_output_dir, |
| 263 | self.options.gold_properties, |
| 264 | self.options.gold_key, |
| 265 | self.options.gold_ignore_hashes) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 266 | |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 267 | if self.options.num_workers > 1 and len(self.test_cases) > 1: |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 268 | try: |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 269 | pool = multiprocessing.Pool(self.options.num_workers) |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 270 | worker_func = functools.partial(TestOneFileParallel, self) |
| 271 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 272 | worker_results = pool.imap(worker_func, self.test_cases) |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 273 | for worker_result in worker_results: |
| 274 | result, input_filename, source_dir = worker_result |
| 275 | input_path = os.path.join(source_dir, input_filename) |
| 276 | |
| 277 | self.HandleResult(input_filename, input_path, result) |
| 278 | |
| 279 | except KeyboardInterrupt: |
| 280 | pool.terminate() |
| 281 | finally: |
| 282 | pool.close() |
| 283 | pool.join() |
| 284 | else: |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 285 | for test_case in self.test_cases: |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 286 | input_filename, input_file_dir = test_case |
| 287 | result = self.GenerateAndTest(input_filename, input_file_dir) |
| 288 | self.HandleResult(input_filename, |
| 289 | os.path.join(input_file_dir, input_filename), result) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 290 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 291 | if self.gold_results: |
| 292 | self.gold_results.WriteResults() |
| 293 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 294 | if self.surprises: |
| 295 | self.surprises.sort() |
| 296 | print '\n\nUnexpected Successes:' |
| 297 | for surprise in self.surprises: |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 298 | print surprise |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 299 | |
| 300 | if self.failures: |
| 301 | self.failures.sort() |
| 302 | print '\n\nSummary of Failures:' |
| 303 | for failure in self.failures: |
| 304 | print failure |
dan sinclair | 00d4064 | 2017-01-30 19:48:54 -0800 | [diff] [blame] | 305 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 306 | self._PrintSummary() |
| 307 | |
| 308 | if self.failures: |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 309 | if not self.options.ignore_errors: |
dan sinclair | 00d4064 | 2017-01-30 19:48:54 -0800 | [diff] [blame] | 310 | return 1 |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 311 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 312 | return 0 |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 313 | |
| 314 | def _PrintSummary(self): |
| 315 | number_test_cases = len(self.test_cases) |
| 316 | number_failures = len(self.failures) |
| 317 | number_suppressed = len(self.result_suppressed_cases) |
| 318 | number_successes = number_test_cases - number_failures - number_suppressed |
| 319 | number_surprises = len(self.surprises) |
| 320 | print |
| 321 | print 'Test cases executed: %d' % number_test_cases |
| 322 | print ' Successes: %d' % number_successes |
| 323 | print ' Suppressed: %d' % number_suppressed |
| 324 | print ' Surprises: %d' % number_surprises |
| 325 | print ' Failures: %d' % number_failures |
| 326 | print |
| 327 | print 'Test cases not executed: %d' % len(self.execution_suppressed_cases) |
| 328 | |
| 329 | def SetEnforceExpectedImages(self, new_value): |
| 330 | """Set whether to enforce that each test case provide an expected image.""" |
| 331 | self.enforce_expected_images = new_value |
Dan Sinclair | aeadad1 | 2017-07-18 16:43:41 -0400 | [diff] [blame] | 332 | |
| 333 | def SetOneShotRenderer(self, new_value): |
| 334 | """Set whether to use the oneshot renderer. """ |
| 335 | self.oneshot_renderer = new_value |