1# Copyright 2017 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import logging 6import yaml 7 8class ParseKnownCTSFailures(object): 9 """A class to parse known failures in CTS test.""" 10 11 def __init__(self, failure_files): 12 self.waivers_yaml = self._load_failures(failure_files) 13 14 def _validate_waiver_config(self, arch, board, bundle_abi, sdk_ver, config): 15 """Validate if the test environment matches the test config. 16 17 @param arch: DUT's arch type. 18 @param board: DUT's board name. 19 @param bundle_abi: The test's abi type. 20 @param sdk_ver: DUT's Android SDK version 21 @param config: config for an expected failing test. 22 @return True if test arch or board is part of the config, else False. 23 """ 24 dut_config = ['all', arch, board] 25 if bundle_abi and bundle_abi != arch: 26 dut_config.append('nativebridge') 27 # Map only the versions that ARC releases care. 28 sdk_ver_map = {'25': 'N', '28': 'P'} 29 if sdk_ver in sdk_ver_map: 30 dut_config.append(sdk_ver_map[sdk_ver]) 31 return len(set(dut_config).intersection(config)) > 0 32 33 def _load_failures(self, failure_files): 34 """Load failures from files. 35 36 @param failure_files: files with failure configs. 37 @return a dictionary of failures config in yaml format. 38 """ 39 waivers_yaml = {} 40 for failure_file in failure_files: 41 try: 42 logging.info('Loading expected failure file: %s.', failure_file) 43 with open(failure_file) as wf: 44 waivers_yaml.update(yaml.load(wf.read())) 45 except IOError as e: 46 logging.error('Error loading %s (%s).', 47 failure_file, 48 e.strerror) 49 continue 50 logging.info('Finished loading expected failure file: %s', 51 failure_file) 52 return waivers_yaml 53 54 def find_waivers(self, arch, board, bundle_abi, sdk_ver): 55 """Finds waivers for the test board. 56 57 @param arch: DUT's arch type. 58 @param board: DUT's board name. 59 @param bundle_abi: The test's abi type. 60 @param sdk_ver: DUT's Android SDK version 61 @return a set of waivers/no-test-modules applied to the test board. 62 """ 63 applied_waiver_list = set() 64 for test, config in self.waivers_yaml.iteritems(): 65 if self._validate_waiver_config(arch, board, bundle_abi, sdk_ver, 66 config): 67 applied_waiver_list.add(test) 68 logging.info('Excluding tests/packages from rerun: %s.', 69 applied_waiver_list) 70 return applied_waiver_list 71