Debian Codegraph @

openmp/runtime/test/lit.cfg

raw
1 # -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
2 # Configuration file for the 'lit' test runner.
3
4 import os
5 import re
6 import subprocess
7 import lit.formats
8 from lit.llvm.subst import ToolSubst
9 from lit.llvm import llvm_config
10
11 # Tell pylint that we know config and lit_config exist somewhere.
12 if 'PYLINT_IMPORT' in os.environ:
13 config = object()
14 lit_config = object()
15
16 def prepend_dynamic_library_path(path):
17 target_arch = getattr(config, 'target_arch', None)
18 if config.operating_system == 'Windows':
19 name = 'PATH'
20 sep = ';'
21 elif config.operating_system == 'Darwin':
22 name = 'DYLD_LIBRARY_PATH'
23 sep = ':'
24 elif config.operating_system == 'Haiku':
25 name = 'LIBRARY_PATH'
26 sep = ':'
27 elif target_arch == 've':
28 name = 'VE_LD_LIBRARY_PATH'
29 sep = ':'
30 else:
31 name = 'LD_LIBRARY_PATH'
32 sep = ':'
33 if name in config.environment:
34 config.environment[name] = path + sep + config.environment[name]
35 else:
36 config.environment[name] = path
37
38 # name: The name of this test suite.
39 config.name = 'libomp'
40
41 # suffixes: A list of file extensions to treat as test files.
42 config.suffixes = ['.c', '.cpp']
43
44 # Exclude Unit tests - they are run separately via check-libomp-unit
45 config.excludes = ['Unit']
46
47 if config.test_fortran_compiler:
48 lit_config.note("OpenMP Fortran tests enabled")
49 config.suffixes += ['.f90', '.F90']
50 llvm_config.add_tool_substitutions([
51 ToolSubst(
52 "%flang",
53 command=config.test_fortran_compiler,
54 unresolved="fatal",
55 ),
56 ], [config.llvm_tools_dir])
57 else:
58 lit_config.note("OpenMP Fortran tests disabled")
59
60 # test_source_root: The root path where tests are located.
61 config.test_source_root = os.path.dirname(__file__)
62
63 # test_exec_root: The root object directory where output is placed
64 config.test_exec_root = config.libomp_obj_root
65
66 # test format
67 config.test_format = lit.formats.ShTest()
68
69 # compiler flags
70 flags = " -I " + config.test_source_root + \
71 " -L " + config.library_dir + \
72 " " + config.test_extra_flags
73 if config.has_omit_frame_pointer_flag:
74 flags += " -fno-omit-frame-pointer"
75 if config.target_arch == "s390x":
76 flags += " -mbackchain"
77
78 config.test_flags = " -I " + config.omp_header_directory + flags
79 config.test_flags_use_compiler_omp_h = flags
80
81
82 # extra libraries
83 libs = ""
84 if config.operating_system != 'Haiku':
85 if config.has_libm:
86 libs += " -lm"
87 if config.has_libatomic:
88 libs += " -latomic"
89
90 # Allow REQUIRES / UNSUPPORTED / XFAIL to work
91 for feature in config.test_compiler_features:
92 config.available_features.add(feature)
93
94 # Setup environment to find dynamic library at runtime
95 if config.using_hwloc:
96 prepend_dynamic_library_path(config.hwloc_library_dir)
97 config.available_features.add('hwloc')
98 # Note: please keep config.library_dir *after* any potentially system
99 # directories, as otherwise preinstalled openmp libraries will be used
100 # over just-built
101 prepend_dynamic_library_path(config.library_dir)
102
103 # Rpath modifications for Darwin
104 if config.operating_system == 'Darwin':
105 config.test_flags += " -Wl,-rpath," + config.library_dir
106 if config.using_hwloc:
107 config.test_flags += " -Wl,-rpath," + config.hwloc_library_dir
108
109 # Find the SDK on Darwin
110 if config.operating_system == 'Darwin':
111 cmd = subprocess.Popen(['xcrun', '--show-sdk-path'],
112 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
113 out, err = cmd.communicate()
114 out = out.strip().decode()
115 res = cmd.wait()
116 if res == 0 and out:
117 config.test_flags += " -isysroot " + out
118
119 # Disable OMPT tests if FileCheck was not found
120 if config.has_ompt and config.test_filecheck == "":
121 lit_config.note("Not testing OMPT because FileCheck was not found")
122 config.has_ompt = False
123
124 if config.has_ompt:
125 config.available_features.add("ompt")
126 # for callback.h
127 config.test_flags += " -I " + config.test_source_root + "/ompt"
128
129 if config.has_ompx_taskgraph:
130 config.available_features.add("ompx_taskgraph")
131
132 if config.operating_system == 'AIX':
133 config.available_features.add("aix")
134 object_mode = os.environ.get('OBJECT_MODE', '32')
135 if object_mode == '64':
136 # Set OBJECT_MODE to 64 for LIT test if it is explicitly set.
137 config.environment['OBJECT_MODE'] = os.environ['OBJECT_MODE']
138 elif object_mode == '32':
139 # Set user data area to 2GB since the default size 256MB in 32-bit mode
140 # is not sufficient to run LIT tests on systems that have a lot of
141 # CPUs when creating one worker thread for each CPU and each worker
142 # thread uses 4MB stack size.
143 config.test_flags += " -Wl,-bmaxdata:0x80000000"
144 config.test_openmp_flags += " -Wl,-bmaxdata:0x80000000"
145
146 if 'Linux' in config.operating_system:
147 config.available_features.add("linux")
148
149 if config.operating_system == 'NetBSD':
150 config.available_features.add("netbsd")
151
152 if config.operating_system == 'Darwin':
153 config.available_features.add("darwin")
154
155 if config.operating_system in ['Windows', 'Linux', 'FreeBSD', 'NetBSD', 'DragonFly', 'AIX']:
156 config.available_features.add('affinity')
157
158 if config.operating_system in ['Linux']:
159 config.available_features.add('hidden-helper')
160
161 if config.compiler_frontend_variant == 'MSVC' or config.compiler_simulate_id == 'MSVC':
162 config.available_features.add("msvc")
163
164 target_arch = getattr(config, 'target_arch', None)
165 if target_arch:
166 config.available_features.add(target_arch + '-target-arch')
167 if target_arch in ['x86_64', 'i386']:
168 config.available_features.add('x86-target-arch')
169
170 import multiprocessing
171 try:
172 if multiprocessing.cpu_count() > 1:
173 config.available_features.add('multicpu')
174 except NotImplementedError:
175 pass
176
177 # to run with icc INTEL_LICENSE_FILE must be set
178 if 'INTEL_LICENSE_FILE' in os.environ:
179 config.environment['INTEL_LICENSE_FILE'] = os.environ['INTEL_LICENSE_FILE']
180
181 # set default environment variables for test
182 if 'CHECK_OPENMP_ENV' in os.environ:
183 test_env = os.environ['CHECK_OPENMP_ENV'].split()
184 for env in test_env:
185 name = env.split('=')[0]
186 value = env.split('=')[1]
187 config.environment[name] = value
188
189 # substitutions
190 config.substitutions.append(("%libomp-compile-and-run", \
191 "%libomp-compile && %libomp-run"))
192 config.substitutions.append(("%libomp-irbuilder-compile-and-run", \
193 "%libomp-irbuilder-compile && %libomp-run"))
194 config.substitutions.append(("%libomp-c99-compile-and-run", \
195 "%libomp-c99-compile && %libomp-run"))
196 config.substitutions.append(("%libomp-cxx-compile-and-run", \
197 "%libomp-cxx-compile && %libomp-run"))
198 config.substitutions.append(("%libomp-cxx20-compile-and-run", \
199 "%libomp-cxx20-compile && %libomp-run"))
200 config.substitutions.append(("%libomp-cxx-compile-c", \
201 "%clangXX %openmp_flags %flags -std=c++17 -x c++ %s -o %t" + libs))
202 config.substitutions.append(("%libomp-cxx-compile", \
203 "%clangXX %openmp_flags %flags -std=c++17 %s -o %t" + libs))
204 config.substitutions.append(("%libomp-cxx20-compile", \
205 "%clangXX %openmp_flags %flags -std=c++20 %s -o %t" + libs))
206 config.substitutions.append(("%libomp-compile", \
207 "%clang %openmp_flags %flags %s -o %t" + libs))
208 config.substitutions.append(("%libomp-irbuilder-compile", \
209 "%clang %openmp_flags %flags -fopenmp-enable-irbuilder %s -o %t" + libs))
210 config.substitutions.append(("%libomp-c99-compile", \
211 "%clang %openmp_flags %flags -std=c99 %s -o %t" + libs))
212 config.substitutions.append(("%libomp-run", "%t"))
213 config.substitutions.append(("%clangXX", config.test_cxx_compiler))
214 config.substitutions.append(("%clang", config.test_c_compiler))
215 config.substitutions.append(("%openmp_flags", config.test_openmp_flags))
216 # %flags-use-compiler-omp-h allows us to use the test compiler's omp.h file which
217 # may have different definitions of structures than our omp.h file.
218 if config.is_standalone_build and config.test_compiler_has_omp_h:
219 config.substitutions.append(("%flags-use-compiler-omp-h",
220 config.test_flags_use_compiler_omp_h))
221 else:
222 # If testing the runtime within an LLVM tree, then always include omp.h
223 # directory associated with the new clang compiler.
224 config.substitutions.append(("%flags-use-compiler-omp-h",
225 config.test_flags))
226 config.substitutions.append(("%flags", config.test_flags))
227 config.substitutions.append(("%python", '"%s"' % (sys.executable)))
228 config.substitutions.append(("%not", config.test_not))
229
230 if config.has_ompt:
231 config.substitutions.append(("FileCheck", "tee %%t.out | %s" % config.test_filecheck))
232 config.substitutions.append(("%sort-threads", "sort -n -s"))
233 if config.operating_system == 'Windows':
234 # No such environment variable on Windows.
235 config.substitutions.append(("%preload-tool", "true ||"))
236 config.substitutions.append(("%no-as-needed-flag", "-Wl,--no-as-needed"))
237 elif config.operating_system == 'Darwin':
238 config.substitutions.append(("%preload-tool", "env DYLD_INSERT_LIBRARIES=%t.tool_dir/tool.so"))
239 # No such linker flag on Darwin.
240 config.substitutions.append(("%no-as-needed-flag", ""))
241 else:
242 config.substitutions.append(("%preload-tool", "env LD_PRELOAD=%t.tool_dir/tool.so"))
243 config.substitutions.append(("%no-as-needed-flag", "-Wl,--no-as-needed"))
244 else:
245 config.substitutions.append(("FileCheck", config.test_filecheck))