• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, 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 config: config for an expected failing test.
20        @return True if test arch or board is part of the config, else False.
21        """
22        dut_config = ['all', arch, board]
23        return len(set(dut_config).intersection(config)) > 0
24
25    def _load_failures(self, failure_files):
26        """Load failures from files.
27
28        @param failure_files: files with failure configs.
29        @return a dictionary of failures config in yaml format.
30        """
31        waivers_yaml = {}
32        for failure_file in failure_files:
33            try:
34                logging.info('Loading expected failure file: %s.', failure_file)
35                with open(failure_file) as wf:
36                    waivers_yaml.update(yaml.load(wf.read()))
37            except IOError as e:
38                logging.error('Error loading %s (%s).',
39                              failure_file,
40                              e.strerror)
41                continue
42            logging.info('Finished loading expected failure file: %s',
43                         failure_file)
44        return waivers_yaml
45
46    def find_waivers(self, arch, board):
47        """Finds waivers for the test board.
48
49        @param arch: DUT's arch type.
50        @param board: DUT's board name.
51        @return a set of waivers/no-test-modules applied to the test board.
52        """
53        applied_waiver_list = set()
54        for test, config in self.waivers_yaml.iteritems():
55            if self._validate_waiver_config(arch, board, config):
56                applied_waiver_list.add(test)
57        logging.info('Excluding tests/packages from rerun: %s.',
58                     applied_waiver_list)
59        return applied_waiver_list
60