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
28categories_list = None
29# set to true if we are going to use categories for cherry-picking test cases
30use_categories = False
31# Categories we want to skip
32skip_categories = ["darwin-log"]
33# Categories we expect to fail
34xfail_categories = []
35# use this to track per-category failures
36failures_per_category = {}
37
38# The path to LLDB.framework is optional.
39lldb_framework_path = None
40
41# Test suite repeat count.  Can be overwritten with '-# count'.
42count = 1
43
44# The 'arch' and 'compiler' can be specified via command line.
45arch = None        # Must be initialized after option parsing
46compiler = None    # Must be initialized after option parsing
47
48# The overriden dwarf verison.
49dwarf_version = 0
50
51# Any overridden settings.
52# Always disable default dynamic types for testing purposes.
53settings = [('target.prefer-dynamic-value', 'no-dynamic-values')]
54
55# Path to the FileCheck testing tool. Not optional.
56filecheck = None
57
58# The arch might dictate some specific CFLAGS to be passed to the toolchain to build
59# the inferior programs.  The global variable cflags_extras provides a hook to do
60# just that.
61cflags_extras = ''
62
63# The filters (testclass.testmethod) used to admit tests into our test suite.
64filters = []
65
66# The regular expression pattern to match against eligible filenames as
67# our test cases.
68regexp = None
69
70# Sets of tests which are excluded at runtime
71skip_tests = None
72xfail_tests = None
73
74# By default, recorded session info for errored/failed test are dumped into its
75# own file under a session directory named after the timestamp of the test suite
76# run.  Use '-s session-dir-name' to specify a specific dir name.
77sdir_name = None
78
79# Valid options:
80# f - test file name (without extension)
81# n - test class name
82# m - test method name
83# a - architecture
84# c - compiler path
85# The default is to write all fields.
86session_file_format = 'fnmac'
87
88# Set this flag if there is any session info dumped during the test run.
89sdir_has_content = False
90# svn_info stores the output from 'svn info lldb.base.dir'.
91svn_info = ''
92
93# Default verbosity is 0.
94verbose = 0
95
96# By default, search from the script directory.
97# We can't use sys.path[0] to determine the script directory
98# because it doesn't work under a debugger
99testdirs = [lldbsuite.lldb_test_root]
100
101# Separator string.
102separator = '-' * 70
103
104failed = False
105
106# LLDB Remote platform setting
107lldb_platform_name = None
108lldb_platform_url = None
109lldb_platform_working_dir = None
110
111# The base directory in which the tests are being built.
112test_build_dir = None
113
114# The clang module cache directory used by lldb.
115lldb_module_cache_dir = None
116# The clang module cache directory used by clang.
117clang_module_cache_dir = 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# Reproducers
127capture_path = None
128replay_path = None
129
130# Test rerun configuration vars
131rerun_all_issues = False
132
133# The names of all tests. Used to assert we don't have two tests with the
134# same base name.
135all_tests = set()
136
137# LLDB library directory.
138lldb_libs_dir = None
139
140# A plugin whose tests will be enabled, like intel-pt.
141enabled_plugins = []
142
143
144def shouldSkipBecauseOfCategories(test_categories):
145    if use_categories:
146        if len(test_categories) == 0 or len(
147                categories_list & set(test_categories)) == 0:
148            return True
149
150    for category in skip_categories:
151        if category in test_categories:
152            return True
153
154    return False
155
156
157def get_filecheck_path():
158    """
159    Get the path to the FileCheck testing tool.
160    """
161    if filecheck and os.path.lexists(filecheck):
162        return filecheck
163