xref: /llvm-project/lldb/packages/Python/lldbsuite/test/configuration.py (revision b9c1b51e45b845debb76d8658edabca70ca56079)
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
27def __setCrashInfoHook_Mac(text):
28    from . import crashinfo
29    crashinfo.setCrashReporterDescription(text)
30
31
32def setupCrashInfoHook():
33    if platform.system() == "Darwin":
34        from . import lock
35        test_dir = os.environ['LLDB_TEST']
36        if not test_dir or not os.path.exists(test_dir):
37            return
38        dylib_lock = os.path.join(test_dir, "crashinfo.lock")
39        dylib_src = os.path.join(test_dir, "crashinfo.c")
40        dylib_dst = os.path.join(test_dir, "crashinfo.so")
41        try:
42            compile_lock = lock.Lock(dylib_lock)
43            compile_lock.acquire()
44            if not os.path.isfile(dylib_dst) or os.path.getmtime(
45                    dylib_dst) < os.path.getmtime(dylib_src):
46                # we need to compile
47                cmd = "SDKROOT= xcrun clang %s -o %s -framework Python -Xlinker -dylib -iframework /System/Library/Frameworks/ -Xlinker -F /System/Library/Frameworks/" % (
48                    dylib_src, dylib_dst)
49                if subprocess.call(
50                        cmd, shell=True) != 0 or not os.path.isfile(dylib_dst):
51                    raise Exception('command failed: "{}"'.format(cmd))
52        finally:
53            compile_lock.release()
54            del compile_lock
55
56        setCrashInfoHook = __setCrashInfoHook_Mac
57
58    else:
59        pass
60
61# The test suite.
62suite = unittest2.TestSuite()
63
64# The list of categories we said we care about
65categoriesList = None
66# set to true if we are going to use categories for cherry-picking test cases
67useCategories = False
68# Categories we want to skip
69skipCategories = []
70# use this to track per-category failures
71failuresPerCategory = {}
72
73# The path to LLDB.framework is optional.
74lldbFrameworkPath = None
75
76# Test suite repeat count.  Can be overwritten with '-# count'.
77count = 1
78
79# The 'archs' and 'compilers' can be specified via command line.  The corresponding
80# options can be specified more than once. For example, "-A x86_64 -A i386"
81# => archs=['x86_64', 'i386'] and "-C gcc -C clang" => compilers=['gcc', 'clang'].
82archs = None        # Must be initialized after option parsing
83compilers = None    # Must be initialized after option parsing
84
85# The arch might dictate some specific CFLAGS to be passed to the toolchain to build
86# the inferior programs.  The global variable cflags_extras provides a hook to do
87# just that.
88cflags_extras = ''
89
90# The filters (testclass.testmethod) used to admit tests into our test suite.
91filters = []
92
93# By default, we skip long running test case.  Use '-l' option to override.
94skip_long_running_test = True
95
96# Parsable mode silences headers, and any other output this script might generate, and instead
97# prints machine-readable output similar to what clang tests produce.
98parsable = False
99
100# The regular expression pattern to match against eligible filenames as
101# our test cases.
102regexp = None
103
104# By default, recorded session info for errored/failed test are dumped into its
105# own file under a session directory named after the timestamp of the test suite
106# run.  Use '-s session-dir-name' to specify a specific dir name.
107sdir_name = None
108
109# Valid options:
110# f - test file name (without extension)
111# n - test class name
112# m - test method name
113# a - architecture
114# c - compiler path
115# The default is to write all fields.
116session_file_format = 'fnmac'
117
118# Set this flag if there is any session info dumped during the test run.
119sdir_has_content = False
120
121# svn_info stores the output from 'svn info lldb.base.dir'.
122svn_info = ''
123
124# Default verbosity is 0.
125verbose = 0
126
127# By default, search from the script directory.
128# We can't use sys.path[0] to determine the script directory
129# because it doesn't work under a debugger
130testdirs = [os.path.dirname(os.path.realpath(__file__))]
131
132# Separator string.
133separator = '-' * 70
134
135failed = False
136
137# LLDB Remote platform setting
138lldb_platform_name = None
139lldb_platform_url = None
140lldb_platform_working_dir = None
141
142# Parallel execution settings
143is_inferior_test_runner = False
144multiprocess_test_subdir = None
145num_threads = None
146no_multiprocess_test_runner = False
147test_runner_name = None
148
149# Test results handling globals
150results_filename = None
151results_port = None
152results_formatter_name = None
153results_formatter_object = None
154results_formatter_options = None
155test_result = None
156
157# Test rerun configuration vars
158rerun_all_issues = False
159rerun_max_file_threhold = 0
160
161# The names of all tests. Used to assert we don't have two tests with the
162# same base name.
163all_tests = set()
164
165# safe default
166setCrashInfoHook = lambda x: None
167
168
169def shouldSkipBecauseOfCategories(test_categories):
170    if useCategories:
171        if len(test_categories) == 0 or len(
172                categoriesList & set(test_categories)) == 0:
173            return True
174
175    for category in skipCategories:
176        if category in test_categories:
177            return True
178
179    return False
180