xref: /aosp_15_r20/external/autotest/server/cros/tradefed/cts_expected_failure_parser_unittest.py (revision 9c5db1993ded3edbeafc8092d69fe5de2ee02df7)
1# Lint as: python2, python3
2# Copyright 2021 The Chromium OS 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.
5import glob
6import os
7import unittest
8
9import common
10
11from autotest_lib.server.cros.tradefed import cts_expected_failure_parser
12from autotest_lib.server.hosts import cros_host
13
14
15class MockHost(cros_host.CrosHost):
16    """Simple host for running mock'd host commands"""
17
18    def __init__(self, hostname, vulkan=False):
19        self.hostname = hostname
20        self.vulkan = vulkan
21
22    def has_arc_hardware_vulkan(self):
23        return self.vulkan
24
25
26def glob_add_files(expected_fail_dir):
27    """Return a list of files based on a directory path."""
28
29    expected_fail_files = []
30    expected_fail_dir_path = os.path.join(
31            os.path.dirname(os.path.realpath(__file__)), expected_fail_dir)
32    if os.path.exists(expected_fail_dir_path):
33        expected_fail_files += glob.glob(expected_fail_dir_path + '/*.yaml')
34    return expected_fail_files
35
36
37class CtsExpectedFailureParserTest(unittest.TestCase):
38    """Unittest for cts_expected_failure_parser."""
39
40    def test_should_skip_if_no_vulkan(self):
41        mockhost = MockHost('MockHost', False)
42        expected_fail_files = glob_add_files(
43                'cts_expected_failure_parser_unittest_data')
44
45        waivers = cts_expected_failure_parser.ParseKnownCTSFailures(
46                expected_fail_files)
47        # params: arch, board, model, bundle_abi, sdk_ver, first_api_level, host
48        found_waivers = waivers.find_waivers('x86', 'hatch', 'kohaku', 'x86',
49                                             '30', '30', mockhost)
50        self.assertFalse('GtsOpenglTestCases' in found_waivers)
51        self.assertTrue('GtsVulkanTestCases' in found_waivers)
52
53    def test_should_not_skip_if_has_vulkan(self):
54        mockhost = MockHost('MockHost', True)
55        expected_fail_files = glob_add_files(
56                'cts_expected_failure_parser_unittest_data')
57
58        waivers = cts_expected_failure_parser.ParseKnownCTSFailures(
59                expected_fail_files)
60        # params: arch, board, model, bundle_abi, sdk_ver, first_api_level, host
61        found_waivers = waivers.find_waivers('x86', 'hatch', 'kohaku', 'x86',
62                                             '30', '30', mockhost)
63
64        self.assertTrue('GtsOpenglTestCases' in found_waivers)
65        self.assertFalse('GtsVulkanTestCases' in found_waivers)
66
67    def test_binarytranslated_tag(self):
68        mockhost = MockHost('MockHost', False)
69        expected_fail_files = glob_add_files(
70                'cts_expected_failure_parser_unittest_data')
71
72        waivers = cts_expected_failure_parser.ParseKnownCTSFailures(
73                expected_fail_files)
74        # params: arch, board, model, bundle_abi, sdk_ver, first_api_level, host
75        found_waivers = waivers.find_waivers('x86', 'hatch', 'kohaku', 'arm',
76                                             '30', '30', mockhost)
77
78        self.assertTrue('GtsOnlyPrimaryAbiTestCases' in found_waivers)
79
80        # params: arch, board, model, bundle_abi, sdk_ver, first_api_level, host
81        found_waivers = waivers.find_waivers('x86', 'hatch', 'kohaku', 'x86',
82                                             '30', '30', mockhost)
83
84        self.assertFalse('GtsOnlyPrimaryAbiTestCases' in found_waivers)
85
86
87if __name__ == '__main__':
88    unittest.main()
89