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# Key: Category name
17# Value: should be used in lldbtest's debug-info replication
18debug_info_categories = {
19    'dwarf'    : True,
20    'dwo'      : True,
21    'dsym'     : True,
22    'gmodules' : False
23}
24
25all_categories = {
26    'basic_process': 'Basic process execution sniff tests.',
27    'cmdline': 'Tests related to the LLDB command-line interface',
28    'dataformatters': 'Tests related to the type command and the data formatters subsystem',
29    'debugserver': 'Debugserver tests',
30    'dsym': 'Tests that can be run with DSYM debug information',
31    'dwarf': 'Tests that can be run with DWARF debug information',
32    'dwo': 'Tests that can be run with DWO debug information',
33    'dyntype': 'Tests related to dynamic type support',
34    'expression': 'Tests related to the expression parser',
35    'flakey': 'Flakey test cases, i.e. tests that do not reliably pass at each execution',
36    'fork': 'Tests requiring the process plugin fork/vfork event support',
37    'gmodules': 'Tests that can be run with -gmodules debug information',
38    'instrumentation-runtime': 'Tests for the instrumentation runtime plugins',
39    'libc++': 'Test for libc++ data formatters',
40    'libstdcxx': 'Test for libstdcxx data formatters',
41    'lldb-server': 'Tests related to lldb-server',
42    'lldb-vscode': 'Visual Studio Code debug adaptor tests',
43    'llgs': 'Tests for the gdb-server functionality of lldb-server',
44    'objc': 'Tests related to the Objective-C programming language support',
45    'pyapi': 'Tests related to the Python API',
46    'std-module': 'Tests related to importing the std module',
47    'stresstest': 'Tests related to stressing lldb limits',
48    'watchpoint': 'Watchpoint-related tests',
49}
50
51
52def unique_string_match(yourentry, list):
53    candidate = None
54    for item in list:
55        if not item.startswith(yourentry):
56            continue
57        if candidate:
58            return None
59        candidate = item
60    return candidate
61
62
63def is_supported_on_platform(category, platform, compiler_path):
64    if category == "dwo":
65        # -gsplit-dwarf is not implemented by clang on Windows.
66        return platform in ["linux", "freebsd"]
67    elif category == "dsym":
68        return platform in ["darwin", "macosx", "ios", "watchos", "tvos", "bridgeos"]
69    elif category == "gmodules":
70        # First, check to see if the platform can even support gmodules.
71        if platform not in ["darwin", "macosx", "ios", "watchos", "tvos", "bridgeos"]:
72            return False
73        return gmodules.is_compiler_clang_with_gmodules(compiler_path)
74    return True
75
76
77def validate(categories, exact_match):
78    """
79    For each category in categories, ensure that it's a valid category (if exact_match is false,
80    unique prefixes are also accepted). If a category is invalid, print a message and quit.
81       If all categories are valid, return the list of categories. Prefixes are expanded in the
82       returned list.
83    """
84    result = []
85    for category in categories:
86        origCategory = category
87        if category not in all_categories and not exact_match:
88            category = unique_string_match(category, all_categories)
89        if (category not in all_categories) or category is None:
90            print(
91                "fatal error: category '" +
92                origCategory +
93                "' is not a valid category")
94            print("if you have added a new category, please edit test_categories.py, adding your new category to all_categories")
95            print("else, please specify one or more of the following: " +
96                  str(list(all_categories.keys())))
97            sys.exit(1)
98        result.append(category)
99    return result
100