xref: /llvm-project/lldb/packages/Python/lldbsuite/test/test_categories.py (revision 01a28ca7f8f0999527ffa2d86f6e77b374ef1ed6)
1"""
2Provides definitions for various lldb test categories
3"""
4
5from __future__ import absolute_import
6from __future__ import print_function
7
8# System modules
9import sys
10
11# Third-party modules
12
13# LLDB modules
14from lldbsuite.support import gmodules
15
16
17debug_info_categories = [
18    'dwarf', 'dwo', 'dsym', 'gmodules'
19]
20
21all_categories = {
22    'dataformatters': 'Tests related to the type command and the data formatters subsystem',
23    'dwarf': 'Tests that can be run with DWARF debug information',
24    'dwo': 'Tests that can be run with DWO debug information',
25    'dsym': 'Tests that can be run with DSYM debug information',
26    'gmodules': 'Tests that can be run with -gmodules debug information',
27    'expression': 'Tests related to the expression parser',
28    'libc++': 'Test for libc++ data formatters',
29    'objc': 'Tests related to the Objective-C programming language support',
30    'pyapi': 'Tests related to the Python API',
31    'basic_process': 'Basic process execution sniff tests.',
32    'cmdline': 'Tests related to the LLDB command-line interface',
33    'dyntype': 'Tests related to dynamic type support',
34    'stresstest': 'Tests related to stressing lldb limits',
35    'flakey': 'Flakey test cases, i.e. tests that do not reliably pass at each execution',
36    'lldb-mi': 'lldb-mi tests'}
37
38
39def unique_string_match(yourentry, list):
40    candidate = None
41    for item in list:
42        if not item.startswith(yourentry):
43            continue
44        if candidate:
45            return None
46        candidate = item
47    return candidate
48
49
50def is_supported_on_platform(category, platform, compiler_path):
51    if category == "dwo":
52        # -gsplit-dwarf is not implemented by clang on Windows.
53        return platform in ["linux", "freebsd"]
54    elif category == "dsym":
55        return platform in ["darwin", "macosx", "ios"]
56    elif category == "gmodules":
57        # First, check to see if the platform can even support gmodules.
58        if platform not in ["linux", "freebsd", "darwin", "macosx", "ios"]:
59            return False
60        return gmodules.is_compiler_clang_with_gmodules(compiler_path)
61    return True
62
63
64def validate(categories, exact_match):
65    """
66    For each category in categories, ensure that it's a valid category (if exact_match is false,
67    unique prefixes are also accepted). If a category is invalid, print a message and quit.
68       If all categories are valid, return the list of categories. Prefixes are expanded in the
69       returned list.
70    """
71    result = []
72    for category in categories:
73        origCategory = category
74        if category not in all_categories and not exact_match:
75            category = unique_string_match(category, all_categories)
76        if (category not in all_categories) or category is None:
77            print(
78                "fatal error: category '" +
79                origCategory +
80                "' is not a valid category")
81            print("if you have added a new category, please edit test_categories.py, adding your new category to all_categories")
82            print("else, please specify one or more of the following: " +
83                  str(list(all_categories.keys())))
84            sys.exit(1)
85        result.append(category)
86    return result
87