• 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, bundle_abi, sdk_ver,
15                                first_api_level, config):
16        """Validate if the test environment matches the test config.
17
18        @param arch: DUT's arch type.
19        @param board: DUT's board name.
20        @param bundle_abi: The test's abi type.
21        @param sdk_ver: DUT's Android SDK version
22        @param first_api_level: DUT's Android first API level.
23        @param config: config for an expected failing test.
24        @return True if test arch or board is part of the config, else False.
25        """
26        # Map only the versions that ARC releases care.
27        sdk_ver_map = {25: 'N', 28: 'P', 30: 'R'}
28
29        # 'all' applies to all devices.
30        # 'x86' or 'arm' applies to the DUT's architecture.
31        # board name like 'eve' or 'kevin' applies to the DUT running the board.
32        dut_config = ['all', arch, board]
33        # 'nativebridge' applies to the case running ARM CTS on x86 devices.
34        if bundle_abi and bundle_abi != arch:
35            dut_config.append('nativebridge')
36        # 'N' or 'P' or 'R' applies to the device running that Android version.
37        if sdk_ver in sdk_ver_map:
38            dut_config.append(sdk_ver_map[sdk_ver])
39        # 'shipatN' or 'shipatP' or 'shipatR' applies to those originally
40        # launched at that Android version.
41        if first_api_level in sdk_ver_map:
42            dut_config.append('shipat' + sdk_ver_map[first_api_level])
43        return len(set(dut_config).intersection(config)) > 0
44
45    def _load_failures(self, failure_files):
46        """Load failures from files.
47
48        @param failure_files: files with failure configs.
49        @return a dictionary of failures config in yaml format.
50        """
51        waivers_yaml = {}
52        for failure_file in failure_files:
53            try:
54                logging.info('Loading expected failure file: %s.', failure_file)
55                with open(failure_file) as wf:
56                    waivers_yaml.update(yaml.load(wf.read()))
57            except IOError as e:
58                logging.error('Error loading %s (%s).',
59                              failure_file,
60                              e.strerror)
61                continue
62            logging.info('Finished loading expected failure file: %s',
63                         failure_file)
64        return waivers_yaml
65
66    def find_waivers(self, arch, board, bundle_abi, sdk_ver, first_api_level):
67        """Finds waivers for the test board.
68
69        @param arch: DUT's arch type.
70        @param board: DUT's board name.
71        @param bundle_abi: The test's abi type.
72        @param sdk_ver: DUT's Android SDK version.
73        @param first_api_level: DUT's Android first API level.
74        @return a set of waivers/no-test-modules applied to the test board.
75        """
76        applied_waiver_list = set()
77        for test, config in self.waivers_yaml.iteritems():
78            if self._validate_waiver_config(arch, board, bundle_abi, sdk_ver,
79                                            first_api_level, config):
80                applied_waiver_list.add(test)
81        logging.info('Excluding tests/packages from rerun: %s.',
82                     applied_waiver_list)
83        return applied_waiver_list
84