1"""
2                     The LLVM Compiler Infrastructure
3
4This file is distributed under the University of Illinois Open Source
5License. See LICENSE.TXT for details.
6
7Provides the configuration class, which holds all information related to
8how this invocation of the test suite should be run.
9"""
10
11from __future__ import absolute_import
12from __future__ import print_function
13
14# System modules
15import os
16import platform
17import subprocess
18
19
20# Third-party modules
21import unittest2
22
23# LLDB Modules
24import lldbsuite
25
26
27# The test suite.
28suite = unittest2.TestSuite()
29
30# The list of categories we said we care about
31categoriesList = None
32# set to true if we are going to use categories for cherry-picking test cases
33useCategories = False
34# Categories we want to skip
35skipCategories = ["darwin-log"]
36# use this to track per-category failures
37failuresPerCategory = {}
38
39# The path to LLDB.framework is optional.
40lldbFrameworkPath = None
41
42# Test suite repeat count.  Can be overwritten with '-# count'.
43count = 1
44
45# The 'arch' and 'compiler' can be specified via command line.
46arch = None        # Must be initialized after option parsing
47compiler = None    # Must be initialized after option parsing
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# By default, we skip long running test case.  Use '-l' option to override.
61skip_long_running_test = True
62
63# Parsable mode silences headers, and any other output this script might generate, and instead
64# prints machine-readable output similar to what clang tests produce.
65parsable = False
66
67# The regular expression pattern to match against eligible filenames as
68# our test cases.
69regexp = None
70
71# Sets of tests which are excluded at runtime
72skip_tests = None
73xfail_tests = None
74
75# By default, recorded session info for errored/failed test are dumped into its
76# own file under a session directory named after the timestamp of the test suite
77# run.  Use '-s session-dir-name' to specify a specific dir name.
78sdir_name = None
79
80# Valid options:
81# f - test file name (without extension)
82# n - test class name
83# m - test method name
84# a - architecture
85# c - compiler path
86# The default is to write all fields.
87session_file_format = 'fnmac'
88
89# Set this flag if there is any session info dumped during the test run.
90sdir_has_content = False
91
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 = [os.path.dirname(os.path.realpath(__file__))]
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 only directory to scan for tests. If multiple test directories are
117# specified, and an exclusive test subdirectory is specified, the latter option
118# takes precedence.
119exclusive_test_subdir = None
120
121# Parallel execution settings
122is_inferior_test_runner = False
123num_threads = None
124no_multiprocess_test_runner = False
125test_runner_name = None
126
127# Test results handling globals
128results_filename = None
129results_port = None
130results_formatter_name = None
131results_formatter_object = None
132results_formatter_options = None
133test_result = None
134
135# Test rerun configuration vars
136rerun_all_issues = False
137rerun_max_file_threhold = 0
138
139# The names of all tests. Used to assert we don't have two tests with the
140# same base name.
141all_tests = set()
142
143def shouldSkipBecauseOfCategories(test_categories):
144    if useCategories:
145        if len(test_categories) == 0 or len(
146                categoriesList & set(test_categories)) == 0:
147            return True
148
149    for category in skipCategories:
150        if category in test_categories:
151            return True
152
153    return False
154
155
156def get_absolute_path_to_exclusive_test_subdir():
157    """
158    If an exclusive test subdirectory is specified, return its absolute path.
159    Otherwise return None.
160    """
161    test_directory = os.path.dirname(os.path.realpath(__file__))
162
163    if not exclusive_test_subdir:
164        return
165
166    if len(exclusive_test_subdir) > 0:
167        test_subdir = os.path.join(test_directory, exclusive_test_subdir)
168        if os.path.isdir(test_subdir):
169            return test_subdir
170
171        print('specified test subdirectory {} is not a valid directory\n'
172                .format(test_subdir))
173
174
175def get_absolute_path_to_root_test_dir():
176    """
177    If an exclusive test subdirectory is specified, return its absolute path.
178    Otherwise, return the absolute path of the root test directory.
179    """
180    test_subdir = get_absolute_path_to_exclusive_test_subdir()
181    if test_subdir:
182        return test_subdir
183
184    return os.path.dirname(os.path.realpath(__file__))
185
186
187def get_filecheck_path():
188    """
189    Get the path to the FileCheck testing tool.
190    """
191    if filecheck and os.path.lexists(filecheck):
192        return filecheck
193