Lei Zhang | c5568a2 | 2022-01-08 06:42:01 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 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 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 6 | from __future__ import print_function |
Stephanie Kim | 34cbd92 | 2021-03-17 20:25:12 +0000 | [diff] [blame] | 7 | from __future__ import division |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 8 | |
| 9 | import argparse |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 10 | import functools |
| 11 | import multiprocessing |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 12 | import os |
| 13 | import re |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 14 | import shutil |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 15 | import subprocess |
| 16 | import sys |
| 17 | |
| 18 | import common |
| 19 | import pngdiffer |
| 20 | import suppressor |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 21 | from skia_gold import skia_gold |
| 22 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 23 | |
Ryan Harrison | 70cca36 | 2018-08-10 18:55:46 +0000 | [diff] [blame] | 24 | # Arbitrary timestamp, expressed in seconds since the epoch, used to make sure |
| 25 | # that tests that depend on the current time are stable. Happens to be the |
| 26 | # timestamp of the first commit to repo, 2014/5/9 17:48:50. |
| 27 | TEST_SEED_TIME = "1399672130" |
| 28 | |
Lei Zhang | fe3ab67 | 2019-11-19 19:09:40 +0000 | [diff] [blame] | 29 | # List of test types that should run text tests instead of pixel tests. |
| 30 | TEXT_TESTS = ['javascript'] |
| 31 | |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 32 | |
| 33 | class KeyboardInterruptError(Exception): |
| 34 | pass |
| 35 | |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 36 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 37 | # Nomenclature: |
| 38 | # x_root - "x" |
| 39 | # x_filename - "x.ext" |
| 40 | # x_path - "path/to/a/b/c/x.ext" |
| 41 | # c_dir - "path/to/a/b/c" |
| 42 | |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 43 | |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 44 | def TestOneFileParallel(this, test_case): |
| 45 | """Wrapper to call GenerateAndTest() and redirect output to stdout.""" |
| 46 | try: |
| 47 | input_filename, source_dir = test_case |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 48 | result = this.GenerateAndTest(input_filename, source_dir) |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 49 | return (result, input_filename, source_dir) |
| 50 | except KeyboardInterrupt: |
Lingqi Chi | ed29367 | 2021-11-24 20:53:01 +0000 | [diff] [blame] | 51 | # TODO(https://crbug.com/pdfium/1674): Re-enable this check after try bots |
| 52 | # can run with Python3. |
| 53 | # pylint: disable=raise-missing-from |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 54 | raise KeyboardInterruptError() |
| 55 | |
| 56 | |
Stephanie Kim | 34cbd92 | 2021-03-17 20:25:12 +0000 | [diff] [blame] | 57 | def RunSkiaWrapper(this, input_chunk): |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 58 | """Wrapper to call RunSkia() and redirect output to stdout""" |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 59 | try: |
Stephanie Kim | 34cbd92 | 2021-03-17 20:25:12 +0000 | [diff] [blame] | 60 | results = [] |
| 61 | for img_path_input_filename in input_chunk: |
| 62 | img_path, input_filename = img_path_input_filename |
| 63 | multiprocessing_name = multiprocessing.current_process().name |
| 64 | |
| 65 | test_name, skia_success = this.RunSkia(img_path, multiprocessing_name) |
| 66 | results.append((test_name, skia_success, input_filename)) |
| 67 | return results |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 68 | except KeyboardInterrupt: |
Lingqi Chi | ed29367 | 2021-11-24 20:53:01 +0000 | [diff] [blame] | 69 | # TODO(https://crbug.com/pdfium/1674): Re-enable this check after try bots |
| 70 | # can run with Python3. |
| 71 | # pylint: disable=raise-missing-from |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 72 | raise KeyboardInterruptError() |
| 73 | |
| 74 | |
Lei Zhang | 5767aca | 2018-12-05 19:57:46 +0000 | [diff] [blame] | 75 | def DeleteFiles(files): |
| 76 | """Utility function to delete a list of files""" |
| 77 | for f in files: |
| 78 | if os.path.exists(f): |
| 79 | os.remove(f) |
| 80 | |
| 81 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 82 | class TestRunner: |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 83 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 84 | def __init__(self, dirname): |
Ryan Harrison | 80302c7 | 2018-05-10 18:27:25 +0000 | [diff] [blame] | 85 | # Currently the only used directories are corpus, javascript, and pixel, |
| 86 | # which all correspond directly to the type for the test being run. In the |
| 87 | # future if there are tests that don't have this clean correspondence, then |
| 88 | # an argument for the type will need to be added. |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 89 | self.test_dir = dirname |
Ryan Harrison | 80302c7 | 2018-05-10 18:27:25 +0000 | [diff] [blame] | 90 | self.test_type = dirname |
Lei Zhang | 5767aca | 2018-12-05 19:57:46 +0000 | [diff] [blame] | 91 | self.delete_output_on_success = False |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 92 | self.enforce_expected_images = False |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 93 | self.skia_tester = None |
| 94 | |
| 95 | def GetSkiaGoldTester(self, process_name=None): |
| 96 | if not self.skia_tester: |
| 97 | self.skia_tester = skia_gold.SkiaGoldTester( |
| 98 | source_type=self.test_type, |
| 99 | skia_gold_args=self.options, |
| 100 | process_name=process_name) |
| 101 | return self.skia_tester |
| 102 | |
| 103 | def RunSkia(self, img_path, process_name=None): |
| 104 | skia_tester = self.GetSkiaGoldTester(process_name=process_name) |
| 105 | # The output filename without image extension becomes the test name. |
| 106 | # For example, "/path/to/.../testing/corpus/example_005.pdf.0.png" |
| 107 | # becomes "example_005.pdf.0". |
| 108 | test_name = os.path.splitext(os.path.split(img_path)[1])[0] |
| 109 | skia_success = skia_tester.UploadTestResultToSkiaGold(test_name, img_path) |
| 110 | sys.stdout.flush() |
| 111 | return test_name, skia_success |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 112 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 113 | # GenerateAndTest returns a tuple <success, outputfiles> where |
| 114 | # success is a boolean indicating whether the tests passed comparison |
| 115 | # tests and outputfiles is a list tuples: |
| 116 | # (path_to_image, md5_hash_of_pixelbuffer) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 117 | def GenerateAndTest(self, input_filename, source_dir): |
| 118 | input_root, _ = os.path.splitext(input_filename) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 119 | pdf_path = os.path.join(self.working_dir, input_root + '.pdf') |
| 120 | |
| 121 | # Remove any existing generated images from previous runs. |
| 122 | actual_images = self.image_differ.GetActualFiles(input_filename, source_dir, |
| 123 | self.working_dir) |
Lei Zhang | 5767aca | 2018-12-05 19:57:46 +0000 | [diff] [blame] | 124 | DeleteFiles(actual_images) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 125 | |
| 126 | sys.stdout.flush() |
| 127 | |
| 128 | raised_exception = self.Generate(source_dir, input_filename, input_root, |
| 129 | pdf_path) |
| 130 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 131 | if raised_exception is not None: |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 132 | print('FAILURE: {}; {}'.format(input_filename, raised_exception)) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 133 | return False, [] |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 134 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 135 | results = [] |
Lei Zhang | fe3ab67 | 2019-11-19 19:09:40 +0000 | [diff] [blame] | 136 | if self.test_type in TEXT_TESTS: |
| 137 | expected_txt_path = os.path.join(source_dir, input_root + '_expected.txt') |
Daniel Hosseinian | 77b3a43 | 2019-12-18 17:54:37 +0000 | [diff] [blame] | 138 | raised_exception = self.TestText(input_filename, input_root, |
| 139 | expected_txt_path, pdf_path) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 140 | else: |
Lei Zhang | 17b6722 | 2022-04-01 18:02:29 +0000 | [diff] [blame^] | 141 | raised_exception, results = self.TestPixel(pdf_path, source_dir) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 142 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 143 | if raised_exception is not None: |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 144 | print('FAILURE: {}; {}'.format(input_filename, raised_exception)) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 145 | return False, results |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 146 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 147 | if actual_images: |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 148 | if self.image_differ.HasDifferences(input_filename, source_dir, |
| 149 | self.working_dir): |
Henrique Nakashima | 15bc974 | 2018-04-26 15:55:07 +0000 | [diff] [blame] | 150 | self.RegenerateIfNeeded_(input_filename, source_dir) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 151 | return False, results |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 152 | else: |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 153 | if (self.enforce_expected_images and |
| 154 | not self.test_suppressor.IsImageDiffSuppressed(input_filename)): |
Henrique Nakashima | 15bc974 | 2018-04-26 15:55:07 +0000 | [diff] [blame] | 155 | self.RegenerateIfNeeded_(input_filename, source_dir) |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 156 | print('FAILURE: {}; Missing expected images'.format(input_filename)) |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 157 | return False, results |
| 158 | |
Lei Zhang | 5767aca | 2018-12-05 19:57:46 +0000 | [diff] [blame] | 159 | if self.delete_output_on_success: |
| 160 | DeleteFiles(actual_images) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 161 | return True, results |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 162 | |
Hui Yingst | b8b3f5f | 2020-04-11 00:20:36 +0000 | [diff] [blame] | 163 | # TODO(crbug.com/pdfium/1508): Add support for an option to automatically |
| 164 | # generate Skia/SkiaPaths specific expected results. |
Henrique Nakashima | 15bc974 | 2018-04-26 15:55:07 +0000 | [diff] [blame] | 165 | def RegenerateIfNeeded_(self, input_filename, source_dir): |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 166 | if (not self.options.regenerate_expected or |
| 167 | self.test_suppressor.IsResultSuppressed(input_filename) or |
| 168 | self.test_suppressor.IsImageDiffSuppressed(input_filename)): |
Henrique Nakashima | 15bc974 | 2018-04-26 15:55:07 +0000 | [diff] [blame] | 169 | return |
| 170 | |
| 171 | platform_only = (self.options.regenerate_expected == 'platform') |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 172 | self.image_differ.Regenerate(input_filename, source_dir, self.working_dir, |
| 173 | platform_only) |
Henrique Nakashima | 15bc974 | 2018-04-26 15:55:07 +0000 | [diff] [blame] | 174 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 175 | def Generate(self, source_dir, input_filename, input_root, pdf_path): |
| 176 | original_path = os.path.join(source_dir, input_filename) |
| 177 | input_path = os.path.join(source_dir, input_root + '.in') |
| 178 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 179 | input_event_path = os.path.join(source_dir, input_root + '.evt') |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 180 | if os.path.exists(input_event_path): |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 181 | output_event_path = os.path.splitext(pdf_path)[0] + '.evt' |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 182 | shutil.copyfile(input_event_path, output_event_path) |
| 183 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 184 | if not os.path.exists(input_path): |
| 185 | if os.path.exists(original_path): |
| 186 | shutil.copyfile(original_path, pdf_path) |
| 187 | return None |
| 188 | |
| 189 | sys.stdout.flush() |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 190 | |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 191 | return common.RunCommand([ |
| 192 | sys.executable, self.fixup_path, '--output-dir=' + self.working_dir, |
| 193 | input_path |
| 194 | ]) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 195 | |
Daniel Hosseinian | 77b3a43 | 2019-12-18 17:54:37 +0000 | [diff] [blame] | 196 | def TestText(self, input_filename, input_root, expected_txt_path, pdf_path): |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 197 | txt_path = os.path.join(self.working_dir, input_root + '.txt') |
| 198 | |
| 199 | with open(txt_path, 'w') as outfile: |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 200 | cmd_to_run = [ |
Daniel Hosseinian | 77b3a43 | 2019-12-18 17:54:37 +0000 | [diff] [blame] | 201 | self.pdfium_test_path, '--send-events', '--time=' + TEST_SEED_TIME |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 202 | ] |
Daniel Hosseinian | 77b3a43 | 2019-12-18 17:54:37 +0000 | [diff] [blame] | 203 | |
| 204 | if self.options.disable_javascript: |
| 205 | cmd_to_run.append('--disable-javascript') |
| 206 | |
Daniel Hosseinian | 09dbeac | 2020-01-24 19:41:31 +0000 | [diff] [blame] | 207 | if self.options.disable_xfa: |
| 208 | cmd_to_run.append('--disable-xfa') |
| 209 | |
Daniel Hosseinian | 77b3a43 | 2019-12-18 17:54:37 +0000 | [diff] [blame] | 210 | cmd_to_run.append(pdf_path) |
K. Moon | 5d075e4 | 2021-04-06 22:57:11 +0000 | [diff] [blame] | 211 | try: |
| 212 | subprocess.check_call(cmd_to_run, stdout=outfile) |
| 213 | except subprocess.CalledProcessError as e: |
| 214 | return e |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 215 | |
Daniel Hosseinian | 77b3a43 | 2019-12-18 17:54:37 +0000 | [diff] [blame] | 216 | # If the expected file does not exist, the output is expected to be empty. |
Lei Zhang | fe3ab67 | 2019-11-19 19:09:40 +0000 | [diff] [blame] | 217 | if not os.path.exists(expected_txt_path): |
| 218 | return self._VerifyEmptyText(txt_path) |
| 219 | |
Daniel Hosseinian | 77b3a43 | 2019-12-18 17:54:37 +0000 | [diff] [blame] | 220 | # If JavaScript is disabled, the output should be empty. |
| 221 | # However, if the test is suppressed and JavaScript is disabled, do not |
| 222 | # verify that the text is empty so the suppressed test does not surprise. |
| 223 | if (self.options.disable_javascript and |
| 224 | not self.test_suppressor.IsResultSuppressed(input_filename)): |
| 225 | return self._VerifyEmptyText(txt_path) |
| 226 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 227 | cmd = [sys.executable, self.text_diff_path, expected_txt_path, txt_path] |
| 228 | return common.RunCommand(cmd) |
| 229 | |
Lei Zhang | fe3ab67 | 2019-11-19 19:09:40 +0000 | [diff] [blame] | 230 | def _VerifyEmptyText(self, txt_path): |
| 231 | try: |
| 232 | with open(txt_path, "r") as txt_file: |
| 233 | txt_data = txt_file.readlines() |
Lingqi Chi | ed29367 | 2021-11-24 20:53:01 +0000 | [diff] [blame] | 234 | if not txt_data: |
Lei Zhang | fe3ab67 | 2019-11-19 19:09:40 +0000 | [diff] [blame] | 235 | return None |
| 236 | sys.stdout.write('Unexpected output:\n') |
| 237 | for line in txt_data: |
| 238 | sys.stdout.write(line) |
| 239 | raise Exception('%s should be empty.' % txt_path) |
| 240 | except Exception as e: |
| 241 | return e |
| 242 | |
Stephanie Kim | 0314ade | 2021-03-11 00:27:35 +0000 | [diff] [blame] | 243 | # TODO(crbug.com/pdfium/1656): Remove when ready to fully switch over to |
| 244 | # Skia Gold |
Lei Zhang | 17b6722 | 2022-04-01 18:02:29 +0000 | [diff] [blame^] | 245 | def TestPixel(self, pdf_path, source_dir): |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 246 | cmd_to_run = [ |
| 247 | self.pdfium_test_path, '--send-events', '--png', '--md5', |
| 248 | '--time=' + TEST_SEED_TIME |
| 249 | ] |
Ryan Harrison | 1118a66 | 2018-05-31 19:26:52 +0000 | [diff] [blame] | 250 | |
Lei Zhang | 17b6722 | 2022-04-01 18:02:29 +0000 | [diff] [blame^] | 251 | if 'use_ahem' in source_dir or 'use_symbolneu' in source_dir: |
Ryan Harrison | 1118a66 | 2018-05-31 19:26:52 +0000 | [diff] [blame] | 252 | cmd_to_run.append('--font-dir=%s' % self.font_dir) |
Lei Zhang | 17b6722 | 2022-04-01 18:02:29 +0000 | [diff] [blame^] | 253 | else: |
| 254 | cmd_to_run.append('--font-dir=%s' % self.third_party_font_dir) |
| 255 | cmd_to_run.append('--croscore-font-names') |
Ryan Harrison | 1118a66 | 2018-05-31 19:26:52 +0000 | [diff] [blame] | 256 | |
Daniel Hosseinian | 77b3a43 | 2019-12-18 17:54:37 +0000 | [diff] [blame] | 257 | if self.options.disable_javascript: |
| 258 | cmd_to_run.append('--disable-javascript') |
| 259 | |
Daniel Hosseinian | 09dbeac | 2020-01-24 19:41:31 +0000 | [diff] [blame] | 260 | if self.options.disable_xfa: |
| 261 | cmd_to_run.append('--disable-xfa') |
| 262 | |
Hui Yingst | c511fd2 | 2021-10-25 18:03:10 +0000 | [diff] [blame] | 263 | if self.options.render_oneshot: |
| 264 | cmd_to_run.append('--render-oneshot') |
| 265 | |
Lei Zhang | afce853 | 2019-11-20 18:09:41 +0000 | [diff] [blame] | 266 | if self.options.reverse_byte_order: |
| 267 | cmd_to_run.append('--reverse-byte-order') |
| 268 | |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 269 | cmd_to_run.append(pdf_path) |
| 270 | return common.RunCommandExtractHashedFiles(cmd_to_run) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 271 | |
| 272 | def HandleResult(self, input_filename, input_path, result): |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 273 | success, _ = result |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 274 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 275 | if self.test_suppressor.IsResultSuppressed(input_filename): |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 276 | self.result_suppressed_cases.append(input_filename) |
dan sinclair | 00d4064 | 2017-01-30 19:48:54 -0800 | [diff] [blame] | 277 | if success: |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 278 | self.surprises.append(input_path) |
| 279 | else: |
dan sinclair | 00d4064 | 2017-01-30 19:48:54 -0800 | [diff] [blame] | 280 | if not success: |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 281 | self.failures.append(input_path) |
| 282 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 283 | def Run(self): |
K Moon | 8de7d57d | 2019-12-05 19:32:33 +0000 | [diff] [blame] | 284 | # Running a test defines a number of attributes on the fly. |
| 285 | # pylint: disable=attribute-defined-outside-init |
| 286 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 287 | parser = argparse.ArgumentParser() |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 288 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 289 | parser.add_argument( |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 290 | '--build-dir', |
| 291 | default=os.path.join('out', 'Debug'), |
| 292 | help='relative path from the base source directory') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 293 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 294 | parser.add_argument( |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 295 | '-j', |
| 296 | default=multiprocessing.cpu_count(), |
| 297 | dest='num_workers', |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 298 | type=int, |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 299 | help='run NUM_WORKERS jobs in parallel') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 300 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 301 | parser.add_argument( |
Daniel Hosseinian | 77b3a43 | 2019-12-18 17:54:37 +0000 | [diff] [blame] | 302 | '--disable-javascript', |
| 303 | action="store_true", |
| 304 | dest="disable_javascript", |
| 305 | help='Prevents JavaScript from executing in PDF files.') |
| 306 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 307 | parser.add_argument( |
Daniel Hosseinian | 09dbeac | 2020-01-24 19:41:31 +0000 | [diff] [blame] | 308 | '--disable-xfa', |
| 309 | action="store_true", |
| 310 | dest="disable_xfa", |
| 311 | help='Prevents processing XFA forms.') |
| 312 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 313 | parser.add_argument( |
Hui Yingst | c511fd2 | 2021-10-25 18:03:10 +0000 | [diff] [blame] | 314 | '--render-oneshot', |
| 315 | action="store_true", |
| 316 | dest="render_oneshot", |
| 317 | help='Sets whether to use the oneshot renderer.') |
| 318 | |
| 319 | parser.add_argument( |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 320 | '--run-skia-gold', |
| 321 | action='store_true', |
| 322 | default=False, |
| 323 | help='When flag is on, skia gold tests will be run.') |
| 324 | |
| 325 | # TODO: Remove when pdfium recipe stops passing this argument |
| 326 | parser.add_argument( |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 327 | '--gold_properties', |
| 328 | default='', |
| 329 | dest="gold_properties", |
| 330 | help='Key value pairs that are written to the top level ' |
| 331 | 'of the JSON file that is ingested by Gold.') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 332 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 333 | # TODO: Remove when pdfium recipe stops passing this argument |
| 334 | parser.add_argument( |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 335 | '--gold_ignore_hashes', |
| 336 | default='', |
| 337 | dest="gold_ignore_hashes", |
| 338 | help='Path to a file with MD5 hashes we wish to ignore.') |
stephana | d532036 | 2017-01-26 15:18:54 -0800 | [diff] [blame] | 339 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 340 | parser.add_argument( |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 341 | '--regenerate_expected', |
| 342 | default='', |
| 343 | dest="regenerate_expected", |
| 344 | help='Regenerates expected images. Valid values are ' |
| 345 | '"all" to regenerate all expected pngs, and ' |
| 346 | '"platform" to regenerate only platform-specific ' |
| 347 | 'expected pngs.') |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 348 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 349 | parser.add_argument( |
Lei Zhang | afce853 | 2019-11-20 18:09:41 +0000 | [diff] [blame] | 350 | '--reverse-byte-order', |
| 351 | action='store_true', |
| 352 | dest="reverse_byte_order", |
| 353 | help='Run image-based tests using --reverse-byte-order.') |
| 354 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 355 | parser.add_argument( |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 356 | '--ignore_errors', |
| 357 | action="store_true", |
| 358 | dest="ignore_errors", |
| 359 | help='Prevents the return value from being non-zero ' |
| 360 | 'when image comparison fails.') |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 361 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 362 | skia_gold.add_skia_gold_args(parser) |
| 363 | |
| 364 | self.options, self.inputted_file_paths = parser.parse_known_args() |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 365 | |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 366 | if (self.options.regenerate_expected and |
| 367 | self.options.regenerate_expected not in ['all', 'platform']): |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 368 | print('FAILURE: --regenerate_expected must be "all" or "platform"') |
Henrique Nakashima | 352e251 | 2017-10-26 11:22:52 -0400 | [diff] [blame] | 369 | return 1 |
| 370 | |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 371 | finder = common.DirectoryFinder(self.options.build_dir) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 372 | self.fixup_path = finder.ScriptPath('fixup_pdf_template.py') |
| 373 | self.text_diff_path = finder.ScriptPath('text_diff.py') |
Ryan Harrison | 1118a66 | 2018-05-31 19:26:52 +0000 | [diff] [blame] | 374 | self.font_dir = os.path.join(finder.TestingDir(), 'resources', 'fonts') |
Lei Zhang | 17b6722 | 2022-04-01 18:02:29 +0000 | [diff] [blame^] | 375 | self.third_party_font_dir = finder.ThirdPartyFontsDir() |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 376 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 377 | self.source_dir = finder.TestingDir() |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 378 | if self.test_dir != 'corpus': |
| 379 | test_dir = finder.TestingDir(os.path.join('resources', self.test_dir)) |
| 380 | else: |
| 381 | test_dir = finder.TestingDir(self.test_dir) |
| 382 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 383 | self.pdfium_test_path = finder.ExecutablePath('pdfium_test') |
| 384 | if not os.path.exists(self.pdfium_test_path): |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 385 | print("FAILURE: Can't find test executable '{}'".format( |
| 386 | self.pdfium_test_path)) |
| 387 | print('Use --build-dir to specify its location.') |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 388 | return 1 |
| 389 | |
| 390 | self.working_dir = finder.WorkingDir(os.path.join('testing', self.test_dir)) |
Lei Zhang | 96eff7c | 2019-09-19 21:08:58 +0000 | [diff] [blame] | 391 | shutil.rmtree(self.working_dir, ignore_errors=True) |
| 392 | os.makedirs(self.working_dir) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 393 | |
Lei Zhang | 76f9569 | 2020-04-01 22:16:25 +0000 | [diff] [blame] | 394 | self.features = subprocess.check_output( |
Lei Zhang | ae57853 | 2021-04-15 20:32:56 +0000 | [diff] [blame] | 395 | [self.pdfium_test_path, |
| 396 | '--show-config']).decode('utf-8').strip().split(',') |
Daniel Hosseinian | 77b3a43 | 2019-12-18 17:54:37 +0000 | [diff] [blame] | 397 | self.test_suppressor = suppressor.Suppressor( |
Lei Zhang | 76f9569 | 2020-04-01 22:16:25 +0000 | [diff] [blame] | 398 | finder, self.features, self.options.disable_javascript, |
Daniel Hosseinian | 09dbeac | 2020-01-24 19:41:31 +0000 | [diff] [blame] | 399 | self.options.disable_xfa) |
Hui Yingst | b8b3f5f | 2020-04-11 00:20:36 +0000 | [diff] [blame] | 400 | self.image_differ = pngdiffer.PNGDiffer(finder, self.features, |
Lei Zhang | afce853 | 2019-11-20 18:09:41 +0000 | [diff] [blame] | 401 | self.options.reverse_byte_order) |
Henrique Nakashima | 40be505 | 2018-10-10 23:18:14 +0000 | [diff] [blame] | 402 | error_message = self.image_differ.CheckMissingTools( |
| 403 | self.options.regenerate_expected) |
| 404 | if error_message: |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 405 | print('FAILURE:', error_message) |
Henrique Nakashima | 40be505 | 2018-10-10 23:18:14 +0000 | [diff] [blame] | 406 | return 1 |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 407 | |
Henrique Nakashima | ea4a56d | 2017-11-29 19:34:19 +0000 | [diff] [blame] | 408 | |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 409 | walk_from_dir = finder.TestingDir(test_dir) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 410 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 411 | self.test_cases = [] |
| 412 | self.execution_suppressed_cases = [] |
Henrique Nakashima | 62d5076 | 2017-06-27 13:06:23 -0400 | [diff] [blame] | 413 | input_file_re = re.compile('^.+[.](in|pdf)$') |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 414 | if self.inputted_file_paths: |
| 415 | for file_name in self.inputted_file_paths: |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 416 | file_name.replace('.pdf', '.in') |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 417 | input_path = os.path.join(walk_from_dir, file_name) |
| 418 | if not os.path.isfile(input_path): |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 419 | print("Can't find test file '{}'".format(file_name)) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 420 | return 1 |
| 421 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 422 | self.test_cases.append((os.path.basename(input_path), |
Lei Zhang | 3054337 | 2019-11-19 19:02:30 +0000 | [diff] [blame] | 423 | os.path.dirname(input_path))) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 424 | else: |
| 425 | for file_dir, _, filename_list in os.walk(walk_from_dir): |
| 426 | for input_filename in filename_list: |
| 427 | if input_file_re.match(input_filename): |
| 428 | input_path = os.path.join(file_dir, input_filename) |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 429 | if self.test_suppressor.IsExecutionSuppressed(input_path): |
| 430 | self.execution_suppressed_cases.append(input_path) |
| 431 | else: |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 432 | if os.path.isfile(input_path): |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 433 | self.test_cases.append((input_filename, file_dir)) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 434 | |
Lei Zhang | 1ee9601 | 2018-04-09 17:31:14 +0000 | [diff] [blame] | 435 | self.test_cases.sort() |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 436 | self.failures = [] |
| 437 | self.surprises = [] |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 438 | self.skia_gold_successes = [] |
| 439 | self.skia_gold_unexpected_successes = [] |
| 440 | self.skia_gold_failures = [] |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 441 | self.result_suppressed_cases = [] |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 442 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 443 | gold_results = [] |
Stephanie Kim | 0314ade | 2021-03-11 00:27:35 +0000 | [diff] [blame] | 444 | if self.test_type not in TEXT_TESTS and self.options.run_skia_gold: |
| 445 | assert self.options.gold_output_dir |
Stephanie Kim | ebe79c1 | 2021-03-05 21:14:49 +0000 | [diff] [blame] | 446 | # Clear out and create top level gold output directory before starting |
| 447 | skia_gold.clear_gold_output_dir(self.options.gold_output_dir) |
| 448 | |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 449 | if self.options.num_workers > 1 and len(self.test_cases) > 1: |
Stephanie Kim | 0314ade | 2021-03-11 00:27:35 +0000 | [diff] [blame] | 450 | skia_gold_parallel_inputs = [] |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 451 | try: |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 452 | pool = multiprocessing.Pool(self.options.num_workers) |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 453 | worker_func = functools.partial(TestOneFileParallel, self) |
| 454 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 455 | worker_results = pool.imap(worker_func, self.test_cases) |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 456 | for worker_result in worker_results: |
| 457 | result, input_filename, source_dir = worker_result |
| 458 | input_path = os.path.join(source_dir, input_filename) |
| 459 | |
| 460 | self.HandleResult(input_filename, input_path, result) |
| 461 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 462 | if self.test_type not in TEXT_TESTS and self.options.run_skia_gold: |
| 463 | _, image_paths = result |
| 464 | if image_paths: |
Stephanie Kim | 0314ade | 2021-03-11 00:27:35 +0000 | [diff] [blame] | 465 | path_filename_tuples = [ |
| 466 | (path, input_filename) for path, _ in image_paths |
| 467 | ] |
| 468 | skia_gold_parallel_inputs.extend(path_filename_tuples) |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 469 | |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 470 | except KeyboardInterrupt: |
| 471 | pool.terminate() |
| 472 | finally: |
| 473 | pool.close() |
| 474 | pool.join() |
Stephanie Kim | 0314ade | 2021-03-11 00:27:35 +0000 | [diff] [blame] | 475 | |
| 476 | if skia_gold_parallel_inputs and self.test_type not in TEXT_TESTS: |
| 477 | try: |
| 478 | pool = multiprocessing.Pool(self.options.num_workers) |
| 479 | gold_worker_func = functools.partial(RunSkiaWrapper, self) |
Stephanie Kim | 34cbd92 | 2021-03-17 20:25:12 +0000 | [diff] [blame] | 480 | |
| 481 | def chunk_input(whole_list): |
| 482 | chunked = [] |
| 483 | size = len(whole_list) // self.options.num_workers |
| 484 | for i in range(0, len(whole_list), size): |
| 485 | chunked.append(whole_list[i:i + size]) |
| 486 | return chunked |
| 487 | |
| 488 | chunked_input = chunk_input(skia_gold_parallel_inputs) |
| 489 | pool_results = pool.imap(gold_worker_func, chunked_input) |
| 490 | for r in pool_results: |
| 491 | gold_results.extend(r) |
Stephanie Kim | 0314ade | 2021-03-11 00:27:35 +0000 | [diff] [blame] | 492 | except KeyboardInterrupt: |
| 493 | pool.terminate() |
| 494 | finally: |
| 495 | pool.close() |
| 496 | pool.join() |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 497 | else: |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 498 | for test_case in self.test_cases: |
dsinclair | 849284d | 2016-05-17 06:13:36 -0700 | [diff] [blame] | 499 | input_filename, input_file_dir = test_case |
| 500 | result = self.GenerateAndTest(input_filename, input_file_dir) |
| 501 | self.HandleResult(input_filename, |
| 502 | os.path.join(input_file_dir, input_filename), result) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 503 | |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 504 | _, image_paths = result |
Stephanie Kim | ebe79c1 | 2021-03-05 21:14:49 +0000 | [diff] [blame] | 505 | if image_paths and self.test_type not in TEXT_TESTS and \ |
| 506 | self.options.run_skia_gold: |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 507 | for img_path, _ in image_paths: |
| 508 | test_name, skia_success = self.RunSkia(img_path) |
| 509 | gold_results.append((test_name, skia_success, input_filename)) |
| 510 | |
| 511 | for r in gold_results: |
| 512 | test_name, skia_success, input_filename = r |
| 513 | if skia_success: |
| 514 | if self.test_suppressor.IsResultSuppressed(input_filename): |
| 515 | self.skia_gold_unexpected_successes.append(test_name) |
| 516 | else: |
| 517 | self.skia_gold_successes.append(test_name) |
| 518 | else: |
| 519 | self.skia_gold_failures.append(test_name) |
stephana | fa05e97 | 2017-01-02 06:19:41 -0800 | [diff] [blame] | 520 | |
Stephanie Kim | 0314ade | 2021-03-11 00:27:35 +0000 | [diff] [blame] | 521 | # For some reason, summary will be cut off from stdout on windows if |
| 522 | # _PrintSummary() is called at the end |
| 523 | # TODO(crbug.com/pdfium/1657): Once resolved, move _PrintSummary() back |
| 524 | # down to the end |
| 525 | self._PrintSummary() |
| 526 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 527 | if self.surprises: |
| 528 | self.surprises.sort() |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 529 | print('\nUnexpected Successes:') |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 530 | for surprise in self.surprises: |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 531 | print(surprise) |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 532 | |
| 533 | if self.failures: |
| 534 | self.failures.sort() |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 535 | print('\nSummary of Failures:') |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 536 | for failure in self.failures: |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 537 | print(failure) |
| 538 | |
| 539 | if self.skia_gold_unexpected_successes: |
Stephanie Kim | 0314ade | 2021-03-11 00:27:35 +0000 | [diff] [blame] | 540 | self.skia_gold_unexpected_successes.sort() |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 541 | print('\nUnexpected Skia Gold Successes:') |
| 542 | for surprise in self.skia_gold_unexpected_successes: |
| 543 | print(surprise) |
| 544 | |
| 545 | if self.skia_gold_failures: |
| 546 | self.skia_gold_failures.sort() |
| 547 | print('\nSummary of Skia Gold Failures:') |
| 548 | for failure in self.skia_gold_failures: |
| 549 | print(failure) |
dan sinclair | 00d4064 | 2017-01-30 19:48:54 -0800 | [diff] [blame] | 550 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 551 | if self.failures: |
Henrique Nakashima | 06673ed | 2017-10-25 17:31:13 -0400 | [diff] [blame] | 552 | if not self.options.ignore_errors: |
dan sinclair | 00d4064 | 2017-01-30 19:48:54 -0800 | [diff] [blame] | 553 | return 1 |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 554 | |
dsinclair | 2a8a20c | 2016-04-25 09:46:17 -0700 | [diff] [blame] | 555 | return 0 |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 556 | |
| 557 | def _PrintSummary(self): |
| 558 | number_test_cases = len(self.test_cases) |
| 559 | number_failures = len(self.failures) |
| 560 | number_suppressed = len(self.result_suppressed_cases) |
| 561 | number_successes = number_test_cases - number_failures - number_suppressed |
| 562 | number_surprises = len(self.surprises) |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 563 | print('\nTest cases executed:', number_test_cases) |
| 564 | print(' Successes:', number_successes) |
| 565 | print(' Suppressed:', number_suppressed) |
| 566 | print(' Surprises:', number_surprises) |
| 567 | print(' Failures:', number_failures) |
Stephanie Kim | ebe79c1 | 2021-03-05 21:14:49 +0000 | [diff] [blame] | 568 | if self.test_type not in TEXT_TESTS and self.options.run_skia_gold: |
Stephanie Kim | 606d085 | 2021-03-04 16:02:41 +0000 | [diff] [blame] | 569 | number_gold_failures = len(self.skia_gold_failures) |
| 570 | number_gold_successes = len(self.skia_gold_successes) |
| 571 | number_gold_surprises = len(self.skia_gold_unexpected_successes) |
| 572 | number_total_gold_tests = sum( |
| 573 | [number_gold_failures, number_gold_successes, number_gold_surprises]) |
| 574 | print('\nSkia Gold Test cases executed:', number_total_gold_tests) |
| 575 | print(' Skia Gold Successes:', number_gold_successes) |
| 576 | print(' Skia Gold Surprises:', number_gold_surprises) |
| 577 | print(' Skia Gold Failures:', number_gold_failures) |
| 578 | skia_tester = self.GetSkiaGoldTester() |
| 579 | if self.skia_gold_failures and skia_tester.IsTryjobRun(): |
| 580 | cl_triage_link = skia_tester.GetCLTriageLink() |
| 581 | print(' Triage link for CL:', cl_triage_link) |
| 582 | skia_tester.WriteCLTriageLink(cl_triage_link) |
| 583 | print() |
| 584 | print('Test cases not executed:', len(self.execution_suppressed_cases)) |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 585 | |
Lei Zhang | 5767aca | 2018-12-05 19:57:46 +0000 | [diff] [blame] | 586 | def SetDeleteOutputOnSuccess(self, new_value): |
| 587 | """Set whether to delete generated output if the test passes.""" |
| 588 | self.delete_output_on_success = new_value |
| 589 | |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 590 | def SetEnforceExpectedImages(self, new_value): |
| 591 | """Set whether to enforce that each test case provide an expected image.""" |
| 592 | self.enforce_expected_images = new_value |