Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / test / lit.cfg
blob6dab31bd35a9f319bd291cc2319f16734fa65e5a
1 # -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
2 # Configuration file for the 'lit' test runner.
4 import os
5 import lit.formats
7 # Tell pylint that we know config and lit_config exist somewhere.
8 if 'PYLINT_IMPORT' in os.environ:
9     config = object()
10     lit_config = object()
12 # Use the CUDA device as suggested by the env
13 if 'CUDA_VISIBLE_DEVICES' in os.environ:
14     config.environment['CUDA_VISIBLE_DEVICES'] = os.environ['CUDA_VISIBLE_DEVICES']
16 # Use the ROCR device as suggested by the env
17 if 'ROCR_VISIBLE_DEVICES' in os.environ:
18     config.environment['ROCR_VISIBLE_DEVICES'] = os.environ['ROCR_VISIBLE_DEVICES']
20 # Allow running the tests with omptarget debug output
21 if 'LIBOMPTARGET_DEBUG' in os.environ:
22     config.environment['LIBOMPTARGET_DEBUG'] = os.environ['LIBOMPTARGET_DEBUG']
24 # Allow running the tests with nextgen plugins when available
25 if 'LIBOMPTARGET_NEXTGEN_PLUGINS' in os.environ:
26     config.environment['LIBOMPTARGET_NEXTGEN_PLUGINS'] = os.environ['LIBOMPTARGET_NEXTGEN_PLUGINS']
28 if 'LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS' in os.environ:
29     config.environment['LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS'] = os.environ['LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS']
31 if 'OMP_TARGET_OFFLOAD' in os.environ:
32     config.environment['OMP_TARGET_OFFLOAD'] = os.environ['OMP_TARGET_OFFLOAD']
34 # set default environment variables for test
35 if 'CHECK_OPENMP_ENV' in os.environ:
36     test_env = os.environ['CHECK_OPENMP_ENV'].split()
37     for env in test_env:
38         name = env.split('=')[0]
39         value = env.split('=')[1]
40         config.environment[name] = value
42 def append_dynamic_library_path(name, value, sep):
43     if name in config.environment:
44         config.environment[name] = value + sep + config.environment[name]
45     else:
46         config.environment[name] = value
48 # Evaluate the environment variable which is a string boolean value.
49 def evaluate_bool_env(env):
50     env = env.lower()
51     possible_true_values = ["on", "true", "1"]
52     for v in possible_true_values:
53         if env == v:
54             return True
55     return False
57 # name: The name of this test suite.
58 config.name = 'libomptarget :: ' + config.libomptarget_current_target
60 # suffixes: A list of file extensions to treat as test files.
61 config.suffixes = ['.c', '.cpp', '.cc', '.f90']
63 # excludes: A list of directories to exclude from the testuites.
64 config.excludes = ['Inputs']
66 # test_source_root: The root path where tests are located.
67 config.test_source_root = os.path.dirname(__file__)
69 # test_exec_root: The root object directory where output is placed
70 config.test_exec_root = config.libomptarget_obj_root
72 # test format
73 config.test_format = lit.formats.ShTest()
75 # compiler flags
76 config.test_flags = " -I " + config.test_source_root + \
77     " -I " + config.omp_header_directory + \
78     " -L " + config.library_dir + \
79     " -L " + config.llvm_lib_directory
81 if config.omp_host_rtl_directory:
82     config.test_flags = config.test_flags + " -L " + \
83         config.omp_host_rtl_directory
85 config.test_flags = config.test_flags + " " + config.test_extra_flags
87 # Allow REQUIRES / UNSUPPORTED / XFAIL to work
88 config.target_triple = [ ]
89 for feature in config.test_compiler_features:
90     config.available_features.add(feature)
92 if config.libomptarget_debug:
93   config.available_features.add('libomptarget-debug')
95 if config.has_libomptarget_ompt:
96   config.available_features.add('ompt')
98 config.available_features.add(config.libomptarget_current_target)
100 if config.libomptarget_has_libc:
101   config.available_features.add('libc')
103 # Determine whether the test system supports unified memory.
104 # For CUDA, this is the case with compute capability 70 (Volta) or higher.
105 # For all other targets, we currently assume it is.
106 supports_unified_shared_memory = True
107 if config.libomptarget_current_target.startswith('nvptx'):
108   try:
109     cuda_arch = int(config.cuda_test_arch[:3])
110     if cuda_arch < 70:
111       supports_unified_shared_memory = False
112   except ValueError:
113     # If the architecture is invalid, assume it is supported.
114     supports_unified_shared_memory = True
115 if config.libomptarget_current_target.startswith('amdgcn'):
116     supports_unified_shared_memory = False
117 if supports_unified_shared_memory:
118    config.available_features.add('unified_shared_memory')
120 # Setup environment to find dynamic library at runtime
121 if config.operating_system == 'Windows':
122     append_dynamic_library_path('PATH', config.library_dir, ";")
123     append_dynamic_library_path('PATH', config.omp_host_rtl_directory, ";")
124 elif config.operating_system == 'Darwin':
125     append_dynamic_library_path('DYLD_LIBRARY_PATH', config.library_dir, ":")
126     append_dynamic_library_path('DYLD_LIBRARY_PATH', \
127         config.omp_host_rtl_directory, ";")
128     config.test_flags += " -Wl,-rpath," + config.library_dir
129     config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory
130 else: # Unices
131     if config.libomptarget_current_target != "nvptx64-nvidia-cuda":
132         config.test_flags += " -nogpulib"
133     config.test_flags += " -Wl,-rpath," + config.library_dir
134     config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory
135     config.test_flags += " -Wl,-rpath," + config.llvm_lib_directory
136     if config.cuda_libdir:
137         config.test_flags += " -Wl,-rpath," + config.cuda_libdir
138     if config.libomptarget_current_target.startswith('nvptx'):
139         config.test_flags += " --libomptarget-nvptx-bc-path=" + config.library_dir + '/DeviceRTL'
140     if config.libomptarget_current_target.endswith('-LTO'):
141         config.test_flags += " -foffload-lto"
142     if config.libomptarget_current_target.endswith('-JIT-LTO') and evaluate_bool_env(
143         config.environment['LIBOMPTARGET_NEXTGEN_PLUGINS']
144     ):
145         config.test_flags += " -foffload-lto"
146         config.test_flags += " -Wl,--embed-bitcode"
148 def remove_suffix_if_present(name):
149     if name.endswith('-LTO'):
150         return name[:-4]
151     elif name.endswith('-JIT-LTO'):
152         return name[:-8]
153     else:
154         return name
156 def add_libraries(source):
157     if config.libomptarget_has_libc:
158         return source + " " + config.llvm_library_dir + "/libcgpu.a " + \
159                config.library_dir + "/libomptarget.devicertl.a"
160     return source + " " + config.library_dir + "/libomptarget.devicertl.a"
162 # substitutions
163 # - for targets that exist in the system create the actual command.
164 # - for valid targets that do not exist in the system, return false, so that the
165 #   same test can be used for different targets.
167 # Scan all the valid targets.
168 for libomptarget_target in config.libomptarget_all_targets:
169     # Is this target in the current system? If so create a compile, run and test
170     # command. Otherwise create command that return false.
171     if libomptarget_target == config.libomptarget_current_target:
172         config.substitutions.append(("%libomptarget-compilexx-run-and-check-generic",
173             "%libomptarget-compilexx-run-and-check-" + libomptarget_target))
174         config.substitutions.append(("%libomptarget-compile-run-and-check-generic",
175             "%libomptarget-compile-run-and-check-" + libomptarget_target))
176         config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-generic",
177             "%libomptarget-compile-fortran-run-and-check-" + libomptarget_target))
178         config.substitutions.append(("%libomptarget-compilexx-and-run-generic",
179             "%libomptarget-compilexx-and-run-" + libomptarget_target))
180         config.substitutions.append(("%libomptarget-compile-and-run-generic",
181             "%libomptarget-compile-and-run-" + libomptarget_target))
182         config.substitutions.append(("%libomptarget-compilexx-generic",
183             "%libomptarget-compilexx-" + libomptarget_target))
184         config.substitutions.append(("%libomptarget-compile-generic",
185             "%libomptarget-compile-" + libomptarget_target))
186         config.substitutions.append(("%libomptarget-compile-fortran-generic",
187             "%libomptarget-compile-fortran-" + libomptarget_target))
188         config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-generic",
189             "%libomptarget-compileoptxx-run-and-check-" + libomptarget_target))
190         config.substitutions.append(("%libomptarget-compileopt-run-and-check-generic",
191             "%libomptarget-compileopt-run-and-check-" + libomptarget_target))
192         config.substitutions.append(("%libomptarget-compileoptxx-and-run-generic",
193             "%libomptarget-compileoptxx-and-run-" + libomptarget_target))
194         config.substitutions.append(("%libomptarget-compileopt-and-run-generic",
195             "%libomptarget-compileopt-and-run-" + libomptarget_target))
196         config.substitutions.append(("%libomptarget-compileoptxx-generic",
197             "%libomptarget-compileoptxx-" + libomptarget_target))
198         config.substitutions.append(("%libomptarget-compileopt-generic",
199             "%libomptarget-compileopt-" + libomptarget_target))
200         config.substitutions.append(("%libomptarget-run-generic",
201             "%libomptarget-run-" + libomptarget_target))
202         config.substitutions.append(("%libomptarget-run-fail-generic",
203             "%libomptarget-run-fail-" + libomptarget_target))
204         config.substitutions.append(("%clangxx-generic",
205             "%clangxx-" + libomptarget_target))
206         config.substitutions.append(("%clang-generic",
207             "%clang-" + libomptarget_target))
208         config.substitutions.append(("%fcheck-generic",
209             config.libomptarget_filecheck + " %s"))
210         config.substitutions.append(("%fcheck-plain-generic",
211             config.libomptarget_filecheck))
214         config.substitutions.append(("%libomptarget-compilexx-run-and-check-" + \
215             libomptarget_target, \
216             "%libomptarget-compilexx-and-run-" + libomptarget_target + \
217             " | " + config.libomptarget_filecheck + " %s"))
218         config.substitutions.append(("%libomptarget-compile-run-and-check-" + \
219             libomptarget_target, \
220             "%libomptarget-compile-and-run-" + libomptarget_target + \
221             " | " + config.libomptarget_filecheck + " %s"))
222         config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-" + \
223             libomptarget_target, \
224             "%libomptarget-compile-fortran-and-run-" + libomptarget_target + \
225             " | " + config.libomptarget_filecheck + " %s"))
226         config.substitutions.append(("%libomptarget-compilexx-and-run-" + \
227             libomptarget_target, \
228             "%libomptarget-compilexx-" + libomptarget_target + " && " + \
229             "%libomptarget-run-" + libomptarget_target))
230         config.substitutions.append(("%libomptarget-compile-and-run-" + \
231             libomptarget_target, \
232             "%libomptarget-compile-" + libomptarget_target + " && " + \
233             "%libomptarget-run-" + libomptarget_target))
234         config.substitutions.append(("%libomptarget-compile-fortran-and-run-" + \
235             libomptarget_target, \
236             "%libomptarget-compile-fortran-" + libomptarget_target + " && " + \
237             "%libomptarget-run-" + libomptarget_target))
238         config.substitutions.append(("%libomptarget-compilexx-" + \
239             libomptarget_target, \
240             "%clangxx-" + libomptarget_target + add_libraries(" %s -o %t")))
241         config.substitutions.append(("%libomptarget-compile-" + \
242             libomptarget_target, \
243             "%clang-" + libomptarget_target + add_libraries(" %s -o %t")))
244         config.substitutions.append(("%libomptarget-compile-fortran-" + \
245             libomptarget_target, \
246             "%flang-" + libomptarget_target + " %s -o %t"))
247         config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-" + \
248             libomptarget_target, \
249             "%libomptarget-compileoptxx-and-run-" + libomptarget_target + \
250             " | " + config.libomptarget_filecheck + " %s"))
251         config.substitutions.append(("%libomptarget-compileopt-run-and-check-" + \
252             libomptarget_target, \
253             "%libomptarget-compileopt-and-run-" + libomptarget_target + \
254             " | " + config.libomptarget_filecheck + " %s"))
255         config.substitutions.append(("%libomptarget-compileoptxx-and-run-" + \
256             libomptarget_target, \
257             "%libomptarget-compileoptxx-" + libomptarget_target + " && " + \
258             "%libomptarget-run-" + libomptarget_target))
259         config.substitutions.append(("%libomptarget-compileopt-and-run-" + \
260             libomptarget_target, \
261             "%libomptarget-compileopt-" + libomptarget_target + " && " + \
262             "%libomptarget-run-" + libomptarget_target))
263         config.substitutions.append(("%libomptarget-compileoptxx-" + \
264             libomptarget_target, \
265             "%clangxx-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))
266         config.substitutions.append(("%libomptarget-compileopt-" + \
267             libomptarget_target, \
268             "%clang-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))
269         config.substitutions.append(("%libomptarget-run-" + \
270             libomptarget_target, \
271             "%t"))
272         config.substitutions.append(("%libomptarget-run-fail-" + \
273             libomptarget_target, \
274             "%not --crash %t"))
275         config.substitutions.append(("%clangxx-" + libomptarget_target, \
276                                      "%clangxx %openmp_flags %cuda_flags %flags -fopenmp-targets=" +\
277                                      remove_suffix_if_present(libomptarget_target)))
278         config.substitutions.append(("%clang-" + libomptarget_target, \
279                                      "%clang %openmp_flags %cuda_flags %flags -fopenmp-targets=" +\
280                                      remove_suffix_if_present(libomptarget_target)))
281         config.substitutions.append(("%flang-" + libomptarget_target, \
282                                      "%flang %openmp_flags %flags -fopenmp-targets=" +\
283                                      remove_suffix_if_present(libomptarget_target)))
284         config.substitutions.append(("%fcheck-" + libomptarget_target, \
285             config.libomptarget_filecheck + " %s"))
286     else:
287         config.substitutions.append(("%libomptarget-compile-run-and-check-" + \
288             libomptarget_target, \
289             "echo ignored-command"))
290         config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-" + \
291             libomptarget_target, \
292             "echo ignored-command"))
293         config.substitutions.append(("%libomptarget-compilexx-run-and-check-" + \
294             libomptarget_target, \
295             "echo ignored-command"))
296         config.substitutions.append(("%libomptarget-compile-and-run-" + \
297             libomptarget_target, \
298             "echo ignored-command"))
299         config.substitutions.append(("%libomptarget-compile-fortran-and-run-" + \
300             libomptarget_target, \
301             "echo ignored-command"))
302         config.substitutions.append(("%libomptarget-compilexx-and-run-" + \
303             libomptarget_target, \
304             "echo ignored-command"))
305         config.substitutions.append(("%libomptarget-compilexx-" + \
306             libomptarget_target, \
307             "echo ignored-command"))
308         config.substitutions.append(("%libomptarget-compile-" + \
309             libomptarget_target, \
310             "echo ignored-command"))
311         config.substitutions.append(("%libomptarget-compile-fortran-" + \
312             libomptarget_target, \
313             "echo ignored-command"))
314         config.substitutions.append(("%libomptarget-compileopt-run-and-check-" + \
315             libomptarget_target, \
316             "echo ignored-command"))
317         config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-" + \
318             libomptarget_target, \
319             "echo ignored-command"))
320         config.substitutions.append(("%libomptarget-compileopt-and-run-" + \
321             libomptarget_target, \
322             "echo ignored-command"))
323         config.substitutions.append(("%libomptarget-compileoptxx-and-run-" + \
324             libomptarget_target, \
325             "echo ignored-command"))
326         config.substitutions.append(("%libomptarget-compileoptxx-" + \
327             libomptarget_target, \
328             "echo ignored-command"))
329         config.substitutions.append(("%libomptarget-compileopt-" + \
330             libomptarget_target, \
331             "echo ignored-command"))
332         config.substitutions.append(("%libomptarget-run-" + \
333             libomptarget_target, \
334             "echo ignored-command"))
335         config.substitutions.append(("%libomptarget-run-fail-" + \
336             libomptarget_target, \
337             "echo ignored-command"))
338         config.substitutions.append(("%clang-" + libomptarget_target, \
339             "echo ignored-command"))
340         config.substitutions.append(("%clangxx-" + libomptarget_target, \
341             "echo ignored-command"))
342         config.substitutions.append(("%fcheck-" + libomptarget_target, \
343             "echo ignored-command"))
344         config.substitutions.append(("%flang-" + libomptarget_target, \
345             "echo ignored-command"))
347 config.substitutions.append(("%clangxx", config.test_cxx_compiler))
348 config.substitutions.append(("%clang", config.test_c_compiler))
350 if config.test_fortran_compiler:
351     config.available_features.add('flang')
352     config.substitutions.append(("%flang", config.test_fortran_compiler))
354 config.substitutions.append(("%openmp_flags", config.test_openmp_flags))
355 if config.libomptarget_current_target.startswith('nvptx') and config.cuda_path:
356     config.substitutions.append(("%cuda_flags", "--cuda-path=" + config.cuda_path))
357 else:
358     config.substitutions.append(("%cuda_flags", ""))
359 config.substitutions.append(("%flags", config.test_flags))
360 config.substitutions.append(("%not", config.libomptarget_not))