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" % (
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 = ["darwin-log"]
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 'arch' and 'compiler' can be specified via command line.
80arch = None        # Must be initialized after option parsing
81compiler = None    # Must be initialized after option parsing
82
83# The arch might dictate some specific CFLAGS to be passed to the toolchain to build
84# the inferior programs.  The global variable cflags_extras provides a hook to do
85# just that.
86cflags_extras = ''
87
88# The filters (testclass.testmethod) used to admit tests into our test suite.
89filters = []
90
91# By default, we skip long running test case.  Use '-l' option to override.
92skip_long_running_test = True
93
94# Parsable mode silences headers, and any other output this script might generate, and instead
95# prints machine-readable output similar to what clang tests produce.
96parsable = False
97
98# The regular expression pattern to match against eligible filenames as
99# our test cases.
100regexp = None
101
102# Sets of tests which are excluded at runtime
103skip_tests = None
104xfail_tests = None
105
106# By default, recorded session info for errored/failed test are dumped into its
107# own file under a session directory named after the timestamp of the test suite
108# run.  Use '-s session-dir-name' to specify a specific dir name.
109sdir_name = None
110
111# Valid options:
112# f - test file name (without extension)
113# n - test class name
114# m - test method name
115# a - architecture
116# c - compiler path
117# The default is to write all fields.
118session_file_format = 'fnmac'
119
120# Set this flag if there is any session info dumped during the test run.
121sdir_has_content = False
122
123# svn_info stores the output from 'svn info lldb.base.dir'.
124svn_info = ''
125
126# Default verbosity is 0.
127verbose = 0
128
129# By default, search from the script directory.
130# We can't use sys.path[0] to determine the script directory
131# because it doesn't work under a debugger
132testdirs = [os.path.dirname(os.path.realpath(__file__))]
133
134# Separator string.
135separator = '-' * 70
136
137failed = False
138
139# LLDB Remote platform setting
140lldb_platform_name = None
141lldb_platform_url = None
142lldb_platform_working_dir = None
143
144# Parallel execution settings
145is_inferior_test_runner = False
146multiprocess_test_subdir = None
147num_threads = None
148no_multiprocess_test_runner = False
149test_runner_name = None
150
151# Test results handling globals
152results_filename = None
153results_port = None
154results_formatter_name = None
155results_formatter_object = None
156results_formatter_options = None
157test_result = None
158
159# Test rerun configuration vars
160rerun_all_issues = False
161rerun_max_file_threhold = 0
162
163# The names of all tests. Used to assert we don't have two tests with the
164# same base name.
165all_tests = set()
166
167# safe default
168setCrashInfoHook = lambda x: None
169
170
171def shouldSkipBecauseOfCategories(test_categories):
172    if useCategories:
173        if len(test_categories) == 0 or len(
174                categoriesList & set(test_categories)) == 0:
175            return True
176
177    for category in skipCategories:
178        if category in test_categories:
179            return True
180
181    return False
182