1"""
2Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3See https://llvm.org/LICENSE.txt for license information.
4SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
6Provides the configuration class, which holds all information related to
7how this invocation of the test suite should be run.
8"""
9
10from __future__ import absolute_import
11from __future__ import print_function
12
13# System modules
14import os
15
16
17# Third-party modules
18import unittest2
19
20# LLDB Modules
21import lldbsuite
22
23
24# The test suite.
25suite = unittest2.TestSuite()
26
27# The list of categories we said we care about
28categoriesList = None
29# set to true if we are going to use categories for cherry-picking test cases
30useCategories = False
31# Categories we want to skip
32skipCategories = ["darwin-log"]
33# use this to track per-category failures
34failuresPerCategory = {}
35
36# The path to LLDB.framework is optional.
37lldbFrameworkPath = None
38
39# Test suite repeat count.  Can be overwritten with '-# count'.
40count = 1
41
42# The 'arch' and 'compiler' can be specified via command line.
43arch = None        # Must be initialized after option parsing
44compiler = None    # Must be initialized after option parsing
45
46# The overriden dwarf verison.
47dwarf_version = 0
48
49# Path to the FileCheck testing tool. Not optional.
50filecheck = None
51
52# The arch might dictate some specific CFLAGS to be passed to the toolchain to build
53# the inferior programs.  The global variable cflags_extras provides a hook to do
54# just that.
55cflags_extras = ''
56
57# The filters (testclass.testmethod) used to admit tests into our test suite.
58filters = []
59
60# The regular expression pattern to match against eligible filenames as
61# our test cases.
62regexp = None
63
64# Sets of tests which are excluded at runtime
65skip_tests = None
66xfail_tests = None
67
68# By default, recorded session info for errored/failed test are dumped into its
69# own file under a session directory named after the timestamp of the test suite
70# run.  Use '-s session-dir-name' to specify a specific dir name.
71sdir_name = None
72
73# Valid options:
74# f - test file name (without extension)
75# n - test class name
76# m - test method name
77# a - architecture
78# c - compiler path
79# The default is to write all fields.
80session_file_format = 'fnmac'
81
82# Set this flag if there is any session info dumped during the test run.
83sdir_has_content = False
84
85# svn_info stores the output from 'svn info lldb.base.dir'.
86svn_info = ''
87
88# Default verbosity is 0.
89verbose = 0
90
91# By default, search from the script directory.
92# We can't use sys.path[0] to determine the script directory
93# because it doesn't work under a debugger
94testdirs = [os.path.dirname(os.path.realpath(__file__))]
95
96# Separator string.
97separator = '-' * 70
98
99failed = False
100
101# LLDB Remote platform setting
102lldb_platform_name = None
103lldb_platform_url = None
104lldb_platform_working_dir = None
105
106# The base directory in which the tests are being built.
107test_build_dir = None
108
109# The clang module cache directory used by lldb.
110lldb_module_cache_dir = None
111# The clang module cache directory used by clang.
112clang_module_cache_dir = None
113
114# The only directory to scan for tests. If multiple test directories are
115# specified, and an exclusive test subdirectory is specified, the latter option
116# takes precedence.
117exclusive_test_subdir = None
118
119# Test results handling globals
120results_filename = None
121results_formatter_name = None
122results_formatter_object = None
123results_formatter_options = None
124test_result = None
125
126# Test rerun configuration vars
127rerun_all_issues = False
128
129# The names of all tests. Used to assert we don't have two tests with the
130# same base name.
131all_tests = set()
132
133def shouldSkipBecauseOfCategories(test_categories):
134    if useCategories:
135        if len(test_categories) == 0 or len(
136                categoriesList & set(test_categories)) == 0:
137            return True
138
139    for category in skipCategories:
140        if category in test_categories:
141            return True
142
143    return False
144
145
146def get_absolute_path_to_exclusive_test_subdir():
147    """
148    If an exclusive test subdirectory is specified, return its absolute path.
149    Otherwise return None.
150    """
151    test_directory = os.path.dirname(os.path.realpath(__file__))
152
153    if not exclusive_test_subdir:
154        return
155
156    if len(exclusive_test_subdir) > 0:
157        test_subdir = os.path.join(test_directory, exclusive_test_subdir)
158        if os.path.isdir(test_subdir):
159            return test_subdir
160
161        print('specified test subdirectory {} is not a valid directory\n'
162                .format(test_subdir))
163
164
165def get_absolute_path_to_root_test_dir():
166    """
167    If an exclusive test subdirectory is specified, return its absolute path.
168    Otherwise, return the absolute path of the root test directory.
169    """
170    test_subdir = get_absolute_path_to_exclusive_test_subdir()
171    if test_subdir:
172        return test_subdir
173
174    return os.path.dirname(os.path.realpath(__file__))
175
176
177def get_filecheck_path():
178    """
179    Get the path to the FileCheck testing tool.
180    """
181    if filecheck and os.path.lexists(filecheck):
182        return filecheck
183