blob: be03e21516c15440eb2890cc5f538c1f852252ac [file] [log] [blame]
Tom Sepez30762ce2015-04-09 13:37:02 -07001#!/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
6import os
7
8import common
9
10class Suppressor:
Tom Sepez5c1efd42016-01-19 15:05:36 -080011 def __init__(self, finder, feature_string):
12 feature_vector = feature_string.strip().split(",")
tsepez86d945b2016-04-18 17:15:42 -070013 self.has_v8 = "V8" in feature_vector
14 self.has_xfa = "XFA" in feature_vector
Henrique Nakashima3bcabf32017-06-27 09:48:24 -040015 self.suppression_set = self._LoadSuppressedSet('SUPPRESSIONS', finder)
16 self.pixel_suppression_set = self._LoadSuppressedSet('SUPPRESSIONS_PIXEL',
17 finder)
18
19 def _LoadSuppressedSet(self, suppressions_filename, finder):
tsepez86d945b2016-04-18 17:15:42 -070020 v8_option = "v8" if self.has_v8 else "nov8"
21 xfa_option = "xfa" if self.has_xfa else "noxfa"
Henrique Nakashima3bcabf32017-06-27 09:48:24 -040022 with open(os.path.join(finder.TestingDir(), suppressions_filename)) as f:
23 return set(self._FilterSuppressions(
Tom Sepez5c1efd42016-01-19 15:05:36 -080024 common.os_name(), v8_option, xfa_option, self._ExtractSuppressions(f)))
Tom Sepez30762ce2015-04-09 13:37:02 -070025
Tom Sepezacfe9a72016-01-19 11:28:59 -080026 def _ExtractSuppressions(self, f):
27 return [y.split(' ') for y in
28 [x.split('#')[0].strip() for x in
29 f.readlines()] if y]
30
31 def _FilterSuppressions(self, os, js, xfa, unfiltered_list):
32 return [x[0] for x in unfiltered_list
33 if self._MatchSuppression(x, os, js, xfa)]
34
35 def _MatchSuppression(self, item, os, js, xfa):
36 os_column = item[1].split(",");
37 js_column = item[2].split(",");
38 xfa_column = item[3].split(",");
39 return (('*' in os_column or os in os_column) and
40 ('*' in js_column or js in js_column) and
41 ('*' in xfa_column or xfa in xfa_column))
Tom Sepez30762ce2015-04-09 13:37:02 -070042
tsepez86d945b2016-04-18 17:15:42 -070043 def IsResultSuppressed(self, input_filename):
Tom Sepezacfe9a72016-01-19 11:28:59 -080044 if input_filename in self.suppression_set:
tsepez86d945b2016-04-18 17:15:42 -070045 print "%s result is suppressed" % input_filename
46 return True
47 return False
48
49 def IsExecutionSuppressed(self, input_filepath):
50 if "xfa_specific" in input_filepath and not self.has_xfa:
51 print "%s execution is suppressed" % input_filepath
Tom Sepez30762ce2015-04-09 13:37:02 -070052 return True
53 return False
Henrique Nakashima3bcabf32017-06-27 09:48:24 -040054
55 def IsPixelDiffSuppressed(self, input_filename):
56 if input_filename in self.pixel_suppression_set:
57 print "%s is pixel suppressed" % input_filename
58 return True
59 return False