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