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
46compiler = None
47dsymutil = None
48sdkroot = None
49
50# The overriden dwarf verison.
51dwarf_version = 0
52
53# Any overridden settings.
54# Always disable default dynamic types for testing purposes.
55settings = [('target.prefer-dynamic-value', 'no-dynamic-values')]
56
57# Path to the FileCheck testing tool. Not optional.
58filecheck = None
59
60# The arch might dictate some specific CFLAGS to be passed to the toolchain to build
61# the inferior programs.  The global variable cflags_extras provides a hook to do
62# just that.
63cflags_extras = ''
64
65# The filters (testclass.testmethod) used to admit tests into our test suite.
66filters = []
67
68# The regular expression pattern to match against eligible filenames as
69# our test cases.
70regexp = None
71
72# Sets of tests which are excluded at runtime
73skip_tests = None
74xfail_tests = None
75
76# By default, recorded session info for errored/failed test are dumped into its
77# own file under a session directory named after the timestamp of the test suite
78# run.  Use '-s session-dir-name' to specify a specific dir name.
79sdir_name = None
80
81# Valid options:
82# f - test file name (without extension)
83# n - test class name
84# m - test method name
85# a - architecture
86# c - compiler path
87# The default is to write all fields.
88session_file_format = 'fnmac'
89
90# Set this flag if there is any session info dumped during the test run.
91sdir_has_content = False
92# svn_info stores the output from 'svn info lldb.base.dir'.
93svn_info = ''
94
95# Default verbosity is 0.
96verbose = 0
97
98# By default, search from the script directory.
99# We can't use sys.path[0] to determine the script directory
100# because it doesn't work under a debugger
101testdirs = [lldbsuite.lldb_test_root]
102
103# Separator string.
104separator = '-' * 70
105
106failed = False
107
108# LLDB Remote platform setting
109lldb_platform_name = None
110lldb_platform_url = None
111lldb_platform_working_dir = None
112
113# The base directory in which the tests are being built.
114test_build_dir = None
115
116# The clang module cache directory used by lldb.
117lldb_module_cache_dir = None
118# The clang module cache directory used by clang.
119clang_module_cache_dir = None
120
121# Test results handling globals
122results_filename = None
123results_formatter_name = None
124results_formatter_object = None
125results_formatter_options = None
126test_result = None
127
128# Reproducers
129capture_path = None
130replay_path = None
131
132# Test rerun configuration vars
133rerun_all_issues = False
134
135# The names of all tests. Used to assert we don't have two tests with the
136# same base name.
137all_tests = set()
138
139# LLDB library directory.
140lldb_libs_dir = None
141
142# A plugin whose tests will be enabled, like intel-pt.
143enabled_plugins = []
144
145
146def shouldSkipBecauseOfCategories(test_categories):
147    if use_categories:
148        if len(test_categories) == 0 or len(
149                categories_list & set(test_categories)) == 0:
150            return True
151
152    for category in skip_categories:
153        if category in test_categories:
154            return True
155
156    return False
157
158
159def get_filecheck_path():
160    """
161    Get the path to the FileCheck testing tool.
162    """
163    if filecheck and os.path.lexists(filecheck):
164        return filecheck
165
166def is_reproducer_replay():
167    """
168    Returns true when dotest is being replayed from a reproducer. Never use
169    this method to guard SB API calls as it will cause a divergence between
170    capture and replay.
171    """
172    return replay_path is not None
173
174def is_reproducer():
175    """
176    Returns true when dotest is capturing a reproducer or is being replayed
177    from a reproducer. Use this method to guard SB API calls.
178    """
179    return capture_path or replay_path
180