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 6import os 7 8# pylint: disable=relative-import 9import common 10 11 12class Suppressor: 13 14 def __init__(self, finder, feature_string, js_disabled, xfa_disabled): 15 feature_vector = feature_string.strip().split(",") 16 self.has_v8 = not js_disabled and "V8" in feature_vector 17 self.has_xfa = (not js_disabled and not xfa_disabled and 18 "XFA" in feature_vector) 19 self.suppression_set = self._LoadSuppressedSet('SUPPRESSIONS', finder) 20 self.image_suppression_set = self._LoadSuppressedSet( 21 'SUPPRESSIONS_IMAGE_DIFF', finder) 22 23 def _LoadSuppressedSet(self, suppressions_filename, finder): 24 v8_option = "v8" if self.has_v8 else "nov8" 25 xfa_option = "xfa" if self.has_xfa else "noxfa" 26 with open(os.path.join(finder.TestingDir(), suppressions_filename)) as f: 27 return set( 28 self._FilterSuppressions(common.os_name(), v8_option, xfa_option, 29 self._ExtractSuppressions(f))) 30 31 def _ExtractSuppressions(self, f): 32 return [ 33 y.split(' ') for y in [x.split('#')[0].strip() 34 for x in f.readlines()] if y 35 ] 36 37 def _FilterSuppressions(self, os_name, js, xfa, unfiltered_list): 38 return [ 39 x[0] 40 for x in unfiltered_list 41 if self._MatchSuppression(x, os_name, js, xfa) 42 ] 43 44 def _MatchSuppression(self, item, os_name, js, xfa): 45 os_column = item[1].split(",") 46 js_column = item[2].split(",") 47 xfa_column = item[3].split(",") 48 return (('*' in os_column or os_name in os_column) and 49 ('*' in js_column or js in js_column) and 50 ('*' in xfa_column or xfa in xfa_column)) 51 52 def IsResultSuppressed(self, input_filename): 53 if input_filename in self.suppression_set: 54 print "%s result is suppressed" % input_filename 55 return True 56 return False 57 58 def IsExecutionSuppressed(self, input_filepath): 59 if "xfa_specific" in input_filepath and not self.has_xfa: 60 print "%s execution is suppressed" % input_filepath 61 return True 62 return False 63 64 def IsImageDiffSuppressed(self, input_filename): 65 if input_filename in self.image_suppression_set: 66 print "%s image diff comparison is suppressed" % input_filename 67 return True 68 return False 69