xref: /llvm-project/offload/test/lit.cfg (revision fd3907ccb583df99e9c19d2fe84e4e7c52d75de9)
1# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
2# Configuration file for the 'lit' test runner.
3
4import os
5import lit.formats
6
7# Tell pylint that we know config and lit_config exist somewhere.
8if 'PYLINT_IMPORT' in os.environ:
9    config = object()
10    lit_config = object()
11
12# Use the CUDA device as suggested by the env
13if 'CUDA_VISIBLE_DEVICES' in os.environ:
14    config.environment['CUDA_VISIBLE_DEVICES'] = os.environ['CUDA_VISIBLE_DEVICES']
15
16# Use the ROCR device as suggested by the env
17if 'ROCR_VISIBLE_DEVICES' in os.environ:
18    config.environment['ROCR_VISIBLE_DEVICES'] = os.environ['ROCR_VISIBLE_DEVICES']
19
20# Allow running the tests with omptarget debug output
21if 'LIBOMPTARGET_DEBUG' in os.environ:
22    config.environment['LIBOMPTARGET_DEBUG'] = os.environ['LIBOMPTARGET_DEBUG']
23
24# Allow running the tests with nextgen plugins when available
25if 'LIBOMPTARGET_NEXTGEN_PLUGINS' in os.environ:
26    config.environment['LIBOMPTARGET_NEXTGEN_PLUGINS'] = os.environ['LIBOMPTARGET_NEXTGEN_PLUGINS']
27
28if 'LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS' in os.environ:
29    config.environment['LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS'] = os.environ['LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS']
30
31if 'OMP_TARGET_OFFLOAD' in os.environ:
32    config.environment['OMP_TARGET_OFFLOAD'] = os.environ['OMP_TARGET_OFFLOAD']
33
34if 'HSA_ENABLE_SDMA' in os.environ:
35    config.environment['HSA_ENABLE_SDMA'] = os.environ['HSA_ENABLE_SDMA']
36
37# Architectures like gfx942 may or may not be APUs so an additional environment
38# variable is required as some tests can be APU specific.
39if 'IS_APU' in os.environ:
40    config.environment['IS_APU'] = os.environ['IS_APU']
41
42# set default environment variables for test
43if 'CHECK_OPENMP_ENV' in os.environ:
44    test_env = os.environ['CHECK_OPENMP_ENV'].split()
45    for env in test_env:
46        name = env.split('=')[0]
47        value = env.split('=')[1]
48        config.environment[name] = value
49
50def append_dynamic_library_path(name, value, sep):
51    if name in config.environment:
52        config.environment[name] = value + sep + config.environment[name]
53    else:
54        config.environment[name] = value
55
56# Evaluate the environment variable which is a string boolean value.
57def evaluate_bool_env(env):
58    env = env.lower()
59    possible_true_values = ["on", "true", "1"]
60    for v in possible_true_values:
61        if env == v:
62            return True
63    return False
64
65# name: The name of this test suite.
66config.name = 'libomptarget :: ' + config.libomptarget_current_target
67
68# suffixes: A list of file extensions to treat as test files.
69config.suffixes = ['.c', '.cpp', '.cc', '.f90', '.cu', '.td']
70
71# excludes: A list of directories to exclude from the testuites.
72config.excludes = ['Inputs']
73
74# test_source_root: The root path where tests are located.
75config.test_source_root = os.path.dirname(__file__)
76
77# test_exec_root: The root object directory where output is placed
78config.test_exec_root = config.libomptarget_obj_root
79
80# test format
81config.test_format = lit.formats.ShTest()
82
83# compiler flags
84config.test_flags = " -I " + config.test_source_root + \
85    " -I " + config.omp_header_directory + \
86    " -L " + config.library_dir + \
87    " -L " + config.llvm_lib_directory
88
89# compiler specific flags
90config.test_flags_clang = ""
91config.test_flags_flang = "-fopenmp-version=52"
92
93if config.omp_host_rtl_directory:
94    config.test_flags = config.test_flags + " -L " + \
95        config.omp_host_rtl_directory
96
97config.test_flags = config.test_flags + " " + config.test_extra_flags
98
99# Allow REQUIRES / UNSUPPORTED / XFAIL to work
100config.target_triple = [ ]
101for feature in config.test_compiler_features:
102    config.available_features.add(feature)
103
104if config.libomptarget_debug:
105  config.available_features.add('libomptarget-debug')
106
107if config.has_libomptarget_ompt:
108  config.available_features.add('ompt')
109
110config.available_features.add(config.libomptarget_current_target)
111
112if config.libomptarget_has_libc:
113  config.available_features.add('libc')
114
115if config.libomptarget_test_pgo:
116  config.available_features.add('pgo')
117
118# Determine whether the test system supports unified memory.
119# For CUDA, this is the case with compute capability 70 (Volta) or higher.
120# For all other targets, we currently assume it is.
121supports_unified_shared_memory = True
122supports_apu = False
123if config.libomptarget_current_target.startswith('nvptx'):
124  try:
125    cuda_arch = int(config.cuda_test_arch[:3])
126    if cuda_arch < 70:
127      supports_unified_shared_memory = False
128  except ValueError:
129    # If the architecture is invalid, assume it is supported.
130    supports_unified_shared_memory = True
131elif config.libomptarget_current_target.startswith('amdgcn'):
132    # amdgpu_test_arch contains a list of AMD GPUs in the system
133    # only check the first one assuming that we will run the test on it.
134    if not (config.amdgpu_test_arch.startswith("gfx90a") or
135            config.amdgpu_test_arch.startswith("gfx940") or
136            config.amdgpu_test_arch.startswith("gfx942")):
137       supports_unified_shared_memory = False
138    # check if AMD architecture is an APU:
139    if (config.amdgpu_test_arch.startswith("gfx940") or
140        (config.amdgpu_test_arch.startswith("gfx942") and
141         evaluate_bool_env(config.environment['IS_APU']))):
142       supports_apu = True
143if supports_unified_shared_memory:
144   config.available_features.add('unified_shared_memory')
145if supports_apu:
146   config.available_features.add('apu')
147
148# Setup environment to find dynamic library at runtime
149if config.operating_system == 'Windows':
150    append_dynamic_library_path('PATH', config.library_dir, ";")
151    append_dynamic_library_path('PATH', config.omp_host_rtl_directory, ";")
152elif config.operating_system == 'Darwin':
153    append_dynamic_library_path('DYLD_LIBRARY_PATH', config.library_dir, ":")
154    append_dynamic_library_path('DYLD_LIBRARY_PATH', \
155        config.omp_host_rtl_directory, ";")
156    config.test_flags += " -Wl,-rpath," + config.library_dir
157    config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory
158else: # Unices
159    if config.libomptarget_current_target != "nvptx64-nvidia-cuda":
160        config.test_flags += " -nogpulib"
161    config.test_flags += " -Wl,-rpath," + config.library_dir
162    config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory
163    config.test_flags += " -Wl,-rpath," + config.llvm_lib_directory
164    if config.cuda_libdir:
165        config.test_flags += " -Wl,-rpath," + config.cuda_libdir
166    if config.libomptarget_current_target.startswith('nvptx'):
167        config.test_flags_clang += " --libomptarget-nvptx-bc-path=" + config.library_dir + '/DeviceRTL'
168    if config.libomptarget_current_target.endswith('-LTO'):
169        config.test_flags += " -foffload-lto"
170    if config.libomptarget_current_target.endswith('-JIT-LTO') and evaluate_bool_env(
171        config.environment['LIBOMPTARGET_NEXTGEN_PLUGINS']
172    ):
173        config.test_flags += " -foffload-lto"
174        config.test_flags += " -Wl,--embed-bitcode"
175
176def remove_suffix_if_present(name):
177    if name.endswith('-LTO'):
178        return name[:-4]
179    elif name.endswith('-JIT-LTO'):
180        return name[:-8]
181    else:
182        return name
183
184def add_libraries(source):
185    if config.libomptarget_has_libc:
186        return source + " -Xoffload-linker " + "-lc " + \
187               "-Xoffload-linker " + "-lm " + \
188               config.llvm_library_intdir + "/libomptarget.devicertl.a"
189    else:
190        return source + " " + config.llvm_library_intdir + "/libomptarget.devicertl.a"
191
192# Add platform targets
193host_targets = [
194    "aarch64-unknown-linux-gnu",
195    "aarch64-unknown-linux-gnu-LTO",
196    "x86_64-unknown-linux-gnu",
197    "x86_64-unknown-linux-gnu-LTO",
198    "s390x-ibm-linux-gnu",
199    "s390x-ibm-linux-gnu-LTO",
200]
201if config.libomptarget_current_target.startswith('nvptx'):
202    config.available_features.add('gpu')
203    config.available_features.add('nvidiagpu')
204if config.libomptarget_current_target.startswith('amdgcn'):
205    config.available_features.add('gpu')
206    config.available_features.add('amdgpu')
207if config.libomptarget_current_target in host_targets:
208    config.available_features.add('host')
209
210# substitutions
211# - for targets that exist in the system create the actual command.
212# - for valid targets that do not exist in the system, return false, so that the
213#   same test can be used for different targets.
214
215# Scan all the valid targets.
216for libomptarget_target in config.libomptarget_all_targets:
217    # Is this target in the current system? If so create a compile, run and test
218    # command. Otherwise create command that return false.
219    if libomptarget_target == config.libomptarget_current_target:
220        config.substitutions.append(("%libomptarget-compilexx-run-and-check-generic",
221            "%libomptarget-compilexx-run-and-check-" + libomptarget_target))
222        config.substitutions.append(("%libomptarget-compile-run-and-check-generic",
223            "%libomptarget-compile-run-and-check-" + libomptarget_target))
224        config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-generic",
225            "%libomptarget-compile-fortran-run-and-check-" + libomptarget_target))
226        config.substitutions.append(("%libomptarget-compilexx-and-run-generic",
227            "%libomptarget-compilexx-and-run-" + libomptarget_target))
228        config.substitutions.append(("%libomptarget-compile-and-run-generic",
229            "%libomptarget-compile-and-run-" + libomptarget_target))
230        config.substitutions.append(("%libomptarget-compilexx-generic",
231            "%libomptarget-compilexx-" + libomptarget_target))
232        config.substitutions.append(("%libomptarget-compilexxx-generic-force-usm",
233            "%libomptarget-compilexxx-force-usm-" + libomptarget_target))
234        config.substitutions.append(("%libomptarget-compile-generic",
235            "%libomptarget-compile-" + libomptarget_target))
236        config.substitutions.append(("%libomptarget-compile-fortran-generic",
237            "%libomptarget-compile-fortran-" + libomptarget_target))
238        config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-generic",
239            "%libomptarget-compileoptxx-run-and-check-" + libomptarget_target))
240        config.substitutions.append(("%libomptarget-compileopt-run-and-check-generic",
241            "%libomptarget-compileopt-run-and-check-" + libomptarget_target))
242        config.substitutions.append(("%libomptarget-compileoptxx-and-run-generic",
243            "%libomptarget-compileoptxx-and-run-" + libomptarget_target))
244        config.substitutions.append(("%libomptarget-compileopt-and-run-generic",
245            "%libomptarget-compileopt-and-run-" + libomptarget_target))
246        config.substitutions.append(("%libomptarget-compileoptxx-generic",
247            "%libomptarget-compileoptxx-" + libomptarget_target))
248        config.substitutions.append(("%libomptarget-compileopt-generic",
249            "%libomptarget-compileopt-" + libomptarget_target))
250        config.substitutions.append(("%libomptarget-run-generic",
251            "%libomptarget-run-" + libomptarget_target))
252        config.substitutions.append(("%libomptarget-run-fail-generic",
253            "%libomptarget-run-fail-" + libomptarget_target))
254        config.substitutions.append(("%clangxx-generic",
255            "%clangxx-" + libomptarget_target))
256        config.substitutions.append(("%clang-generic",
257            "%clang-" + libomptarget_target))
258        config.substitutions.append(("%fcheck-generic",
259            config.libomptarget_filecheck + " %s"))
260        config.substitutions.append(("%fcheck-plain-generic",
261            config.libomptarget_filecheck))
262
263
264        config.substitutions.append(("%libomptarget-compilexx-run-and-check-" + \
265            libomptarget_target, \
266            "%libomptarget-compilexx-and-run-" + libomptarget_target + \
267            " | " + config.libomptarget_filecheck + " %s"))
268        config.substitutions.append(("%libomptarget-compile-run-and-check-" + \
269            libomptarget_target, \
270            "%libomptarget-compile-and-run-" + libomptarget_target + \
271            " | " + config.libomptarget_filecheck + " %s"))
272        config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-" + \
273            libomptarget_target, \
274            "%libomptarget-compile-fortran-and-run-" + libomptarget_target + \
275            " | " + config.libomptarget_filecheck + " %s"))
276        config.substitutions.append(("%libomptarget-compilexx-and-run-" + \
277            libomptarget_target, \
278            "%libomptarget-compilexx-" + libomptarget_target + " && " + \
279            "%libomptarget-run-" + libomptarget_target))
280        config.substitutions.append(("%libomptarget-compile-and-run-" + \
281            libomptarget_target, \
282            "%libomptarget-compile-" + libomptarget_target + " && " + \
283            "%libomptarget-run-" + libomptarget_target))
284        config.substitutions.append(("%libomptarget-compile-fortran-and-run-" + \
285            libomptarget_target, \
286            "%libomptarget-compile-fortran-" + libomptarget_target + " && " + \
287            "%libomptarget-run-" + libomptarget_target))
288        config.substitutions.append(("%libomptarget-compilexx-" + \
289            libomptarget_target, \
290            "%clangxx-" + libomptarget_target + add_libraries(" %s -o %t")))
291        config.substitutions.append(("%libomptarget-compilexxx-force-usm-" +
292            libomptarget_target, "%clangxxx-force-usm-" + libomptarget_target + \
293                                     add_libraries(" %s -o %t")))
294        config.substitutions.append(("%libomptarget-compile-" + \
295            libomptarget_target, \
296            "%clang-" + libomptarget_target + add_libraries(" %s -o %t")))
297        config.substitutions.append(("%libomptarget-compile-fortran-" + \
298            libomptarget_target, \
299            "%flang-" + libomptarget_target + add_libraries(" %s -o %t")))
300        config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-" + \
301            libomptarget_target, \
302            "%libomptarget-compileoptxx-and-run-" + libomptarget_target + \
303            " | " + config.libomptarget_filecheck + " %s"))
304        config.substitutions.append(("%libomptarget-compileopt-run-and-check-" + \
305            libomptarget_target, \
306            "%libomptarget-compileopt-and-run-" + libomptarget_target + \
307            " | " + config.libomptarget_filecheck + " %s"))
308        config.substitutions.append(("%libomptarget-compileoptxx-and-run-" + \
309            libomptarget_target, \
310            "%libomptarget-compileoptxx-" + libomptarget_target + " && " + \
311            "%libomptarget-run-" + libomptarget_target))
312        config.substitutions.append(("%libomptarget-compileopt-and-run-" + \
313            libomptarget_target, \
314            "%libomptarget-compileopt-" + libomptarget_target + " && " + \
315            "%libomptarget-run-" + libomptarget_target))
316        config.substitutions.append(("%libomptarget-compileoptxx-" + \
317            libomptarget_target, \
318            "%clangxx-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))
319        config.substitutions.append(("%libomptarget-compileopt-" + \
320            libomptarget_target, \
321            "%clang-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))
322        config.substitutions.append(("%libomptarget-run-" + \
323            libomptarget_target, \
324            "%t"))
325        config.substitutions.append(("%libomptarget-run-fail-" + \
326            libomptarget_target, \
327            "%not --crash %t"))
328        config.substitutions.append(("%clangxx-" + libomptarget_target, \
329                                     "%clangxx %openmp_flags %cuda_flags %flags %flags_clang -fopenmp-targets=" +\
330                                     remove_suffix_if_present(libomptarget_target)))
331        config.substitutions.append(("%clangxxx-force-usm-" + libomptarget_target, \
332                                     "%clangxx %openmp_flags -fopenmp-force-usm  %cuda_flags %flags %flags_clang -fopenmp-targets=" +\
333                                     remove_suffix_if_present(libomptarget_target)))
334        config.substitutions.append(("%clang-" + libomptarget_target, \
335                                     "%clang %openmp_flags %cuda_flags %flags %flags_clang -fopenmp-targets=" +\
336                                     remove_suffix_if_present(libomptarget_target)))
337        config.substitutions.append(("%flang-" + libomptarget_target, \
338                                     "%flang %openmp_flags %flags %flags_flang -fopenmp-targets=" +\
339                                     remove_suffix_if_present(libomptarget_target)))
340        config.substitutions.append(("%fcheck-" + libomptarget_target, \
341            config.libomptarget_filecheck + " %s"))
342    else:
343        config.substitutions.append(("%libomptarget-compile-run-and-check-" + \
344            libomptarget_target, \
345            "echo ignored-command"))
346        config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-" + \
347            libomptarget_target, \
348            "echo ignored-command"))
349        config.substitutions.append(("%libomptarget-compilexx-run-and-check-" + \
350            libomptarget_target, \
351            "echo ignored-command"))
352        config.substitutions.append(("%libomptarget-compile-and-run-" + \
353            libomptarget_target, \
354            "echo ignored-command"))
355        config.substitutions.append(("%libomptarget-compile-fortran-and-run-" + \
356            libomptarget_target, \
357            "echo ignored-command"))
358        config.substitutions.append(("%libomptarget-compilexx-and-run-" + \
359            libomptarget_target, \
360            "echo ignored-command"))
361        config.substitutions.append(("%libomptarget-compilexx-" + \
362            libomptarget_target, \
363            "echo ignored-command"))
364        config.substitutions.append(("%libomptarget-compile-" + \
365            libomptarget_target, \
366            "echo ignored-command"))
367        config.substitutions.append(("%libomptarget-compile-fortran-" + \
368            libomptarget_target, \
369            "echo ignored-command"))
370        config.substitutions.append(("%libomptarget-compileopt-run-and-check-" + \
371            libomptarget_target, \
372            "echo ignored-command"))
373        config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-" + \
374            libomptarget_target, \
375            "echo ignored-command"))
376        config.substitutions.append(("%libomptarget-compileopt-and-run-" + \
377            libomptarget_target, \
378            "echo ignored-command"))
379        config.substitutions.append(("%libomptarget-compileoptxx-and-run-" + \
380            libomptarget_target, \
381            "echo ignored-command"))
382        config.substitutions.append(("%libomptarget-compileoptxx-" + \
383            libomptarget_target, \
384            "echo ignored-command"))
385        config.substitutions.append(("%libomptarget-compileopt-" + \
386            libomptarget_target, \
387            "echo ignored-command"))
388        config.substitutions.append(("%libomptarget-run-" + \
389            libomptarget_target, \
390            "echo ignored-command"))
391        config.substitutions.append(("%libomptarget-run-fail-" + \
392            libomptarget_target, \
393            "echo ignored-command"))
394        config.substitutions.append(("%clang-" + libomptarget_target, \
395            "echo ignored-command"))
396        config.substitutions.append(("%clangxx-" + libomptarget_target, \
397            "echo ignored-command"))
398        config.substitutions.append(("%fcheck-" + libomptarget_target, \
399            "echo ignored-command"))
400        config.substitutions.append(("%flang-" + libomptarget_target, \
401            "echo ignored-command"))
402
403config.substitutions.append(("%clangxx", config.test_cxx_compiler))
404config.substitutions.append(("%clang", config.test_c_compiler))
405
406if config.test_fortran_compiler:
407    config.available_features.add('flang')
408    config.substitutions.append(("%flang", config.test_fortran_compiler))
409
410config.substitutions.append(("%openmp_flags", config.test_openmp_flags))
411if config.libomptarget_current_target.startswith('nvptx') and config.cuda_path:
412    config.substitutions.append(("%cuda_flags", "--cuda-path=" + config.cuda_path))
413else:
414    config.substitutions.append(("%cuda_flags", ""))
415config.substitutions.append(("%flags_clang", config.test_flags_clang))
416config.substitutions.append(("%flags_flang", config.test_flags_flang))
417config.substitutions.append(("%flags", config.test_flags))
418config.substitutions.append(("%not", config.libomptarget_not))
419config.substitutions.append(("%offload-device-info",
420                             config.offload_device_info))
421config.substitutions.append(("%offload-tblgen", config.offload_tblgen))
422