Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2015 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 | |
| 6 | import os |
| 7 | |
| 8 | import common |
| 9 | |
| 10 | class Suppressor: |
Tom Sepez | 5c1efd4 | 2016-01-19 15:05:36 -0800 | [diff] [blame] | 11 | def __init__(self, finder, feature_string): |
| 12 | feature_vector = feature_string.strip().split(",") |
tsepez | 86d945b | 2016-04-18 17:15:42 -0700 | [diff] [blame] | 13 | self.has_v8 = "V8" in feature_vector |
| 14 | self.has_xfa = "XFA" in feature_vector |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 15 | self.suppression_set = self._LoadSuppressedSet('SUPPRESSIONS', finder) |
Henrique Nakashima | 6fac27d | 2017-06-27 15:52:45 -0400 | [diff] [blame] | 16 | self.image_suppression_set = self._LoadSuppressedSet( |
| 17 | 'SUPPRESSIONS_IMAGE_DIFF', |
| 18 | finder) |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 19 | |
| 20 | def _LoadSuppressedSet(self, suppressions_filename, finder): |
tsepez | 86d945b | 2016-04-18 17:15:42 -0700 | [diff] [blame] | 21 | v8_option = "v8" if self.has_v8 else "nov8" |
| 22 | xfa_option = "xfa" if self.has_xfa else "noxfa" |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 23 | with open(os.path.join(finder.TestingDir(), suppressions_filename)) as f: |
| 24 | return set(self._FilterSuppressions( |
Tom Sepez | 5c1efd4 | 2016-01-19 15:05:36 -0800 | [diff] [blame] | 25 | common.os_name(), v8_option, xfa_option, self._ExtractSuppressions(f))) |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 26 | |
Tom Sepez | acfe9a7 | 2016-01-19 11:28:59 -0800 | [diff] [blame] | 27 | def _ExtractSuppressions(self, f): |
| 28 | return [y.split(' ') for y in |
| 29 | [x.split('#')[0].strip() for x in |
| 30 | f.readlines()] if y] |
| 31 | |
| 32 | def _FilterSuppressions(self, os, js, xfa, unfiltered_list): |
| 33 | return [x[0] for x in unfiltered_list |
| 34 | if self._MatchSuppression(x, os, js, xfa)] |
| 35 | |
| 36 | def _MatchSuppression(self, item, os, js, xfa): |
| 37 | os_column = item[1].split(","); |
| 38 | js_column = item[2].split(","); |
| 39 | xfa_column = item[3].split(","); |
| 40 | return (('*' in os_column or os in os_column) and |
| 41 | ('*' in js_column or js in js_column) and |
| 42 | ('*' in xfa_column or xfa in xfa_column)) |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 43 | |
tsepez | 86d945b | 2016-04-18 17:15:42 -0700 | [diff] [blame] | 44 | def IsResultSuppressed(self, input_filename): |
Tom Sepez | acfe9a7 | 2016-01-19 11:28:59 -0800 | [diff] [blame] | 45 | if input_filename in self.suppression_set: |
tsepez | 86d945b | 2016-04-18 17:15:42 -0700 | [diff] [blame] | 46 | print "%s result is suppressed" % input_filename |
| 47 | return True |
| 48 | return False |
| 49 | |
| 50 | def IsExecutionSuppressed(self, input_filepath): |
| 51 | if "xfa_specific" in input_filepath and not self.has_xfa: |
| 52 | print "%s execution is suppressed" % input_filepath |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 53 | return True |
| 54 | return False |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 55 | |
Henrique Nakashima | 6fac27d | 2017-06-27 15:52:45 -0400 | [diff] [blame] | 56 | def IsImageDiffSuppressed(self, input_filename): |
| 57 | if input_filename in self.image_suppression_set: |
| 58 | print "%s image diff comparison is suppressed" % input_filename |
Henrique Nakashima | 3bcabf3 | 2017-06-27 09:48:24 -0400 | [diff] [blame] | 59 | return True |
| 60 | return False |