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