243 lines · plain
1# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:2# Configuration file for the 'lit' test runner.3 4import os5import re6import subprocess7import lit.formats8from lit.llvm.subst import ToolSubst9from lit.llvm import llvm_config10 11# Tell pylint that we know config and lit_config exist somewhere.12if 'PYLINT_IMPORT' in os.environ:13 config = object()14 lit_config = object()15 16def 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] = path37 38# name: The name of this test suite.39config.name = 'libomp'40 41# suffixes: A list of file extensions to treat as test files.42config.suffixes = ['.c', '.cpp']43 44if config.test_fortran_compiler:45 lit_config.note("OpenMP Fortran tests enabled")46 config.suffixes += ['.f90', '.F90']47 llvm_config.add_tool_substitutions([48 ToolSubst(49 "%flang",50 command=config.test_fortran_compiler,51 unresolved="fatal",52 ),53 ], [config.llvm_tools_dir])54else:55 lit_config.note("OpenMP Fortran tests disabled")56 57# test_source_root: The root path where tests are located.58config.test_source_root = os.path.dirname(__file__)59 60# test_exec_root: The root object directory where output is placed61config.test_exec_root = config.libomp_obj_root62 63# test format64config.test_format = lit.formats.ShTest()65 66# compiler flags67flags = " -I " + config.test_source_root + \68 " -L " + config.library_dir + \69 " " + config.test_extra_flags70if config.has_omit_frame_pointer_flag:71 flags += " -fno-omit-frame-pointer"72if config.target_arch == "s390x":73 flags += " -mbackchain"74 75config.test_flags = " -I " + config.omp_header_directory + flags76config.test_flags_use_compiler_omp_h = flags77 78 79# extra libraries80libs = ""81if config.operating_system != 'Haiku':82 if config.has_libm:83 libs += " -lm"84 if config.has_libatomic:85 libs += " -latomic"86 87# Allow REQUIRES / UNSUPPORTED / XFAIL to work88for feature in config.test_compiler_features:89 config.available_features.add(feature)90 91# Setup environment to find dynamic library at runtime92if config.using_hwloc:93 prepend_dynamic_library_path(config.hwloc_library_dir)94 config.available_features.add('hwloc')95# Note: please keep config.library_dir *after* any potentially system96# directories, as otherwise preinstalled openmp libraries will be used97# over just-built98prepend_dynamic_library_path(config.library_dir)99 100# Rpath modifications for Darwin101if config.operating_system == 'Darwin':102 config.test_flags += " -Wl,-rpath," + config.library_dir103 if config.using_hwloc:104 config.test_flags += " -Wl,-rpath," + config.hwloc_library_dir105 106# Find the SDK on Darwin107if config.operating_system == 'Darwin':108 cmd = subprocess.Popen(['xcrun', '--show-sdk-path'],109 stdout=subprocess.PIPE, stderr=subprocess.PIPE)110 out, err = cmd.communicate()111 out = out.strip().decode()112 res = cmd.wait()113 if res == 0 and out:114 config.test_flags += " -isysroot " + out115 116# Disable OMPT tests if FileCheck was not found117if config.has_ompt and config.test_filecheck == "":118 lit_config.note("Not testing OMPT because FileCheck was not found")119 config.has_ompt = False120 121if config.has_ompt:122 config.available_features.add("ompt")123 # for callback.h124 config.test_flags += " -I " + config.test_source_root + "/ompt"125 126if config.has_ompx_taskgraph:127 config.available_features.add("ompx_taskgraph")128 129if config.operating_system == 'AIX':130 config.available_features.add("aix")131 object_mode = os.environ.get('OBJECT_MODE', '32')132 if object_mode == '64':133 # Set OBJECT_MODE to 64 for LIT test if it is explicitly set.134 config.environment['OBJECT_MODE'] = os.environ['OBJECT_MODE']135 elif object_mode == '32':136 # Set user data area to 2GB since the default size 256MB in 32-bit mode137 # is not sufficient to run LIT tests on systems that have a lot of138 # CPUs when creating one worker thread for each CPU and each worker139 # thread uses 4MB stack size.140 config.test_flags += " -Wl,-bmaxdata:0x80000000"141 config.test_openmp_flags += " -Wl,-bmaxdata:0x80000000"142 143if 'Linux' in config.operating_system:144 config.available_features.add("linux")145 146if config.operating_system == 'NetBSD':147 config.available_features.add("netbsd")148 149if config.operating_system == 'Darwin':150 config.available_features.add("darwin")151 152if config.operating_system in ['Windows', 'Linux', 'FreeBSD', 'NetBSD', 'DragonFly', 'AIX']:153 config.available_features.add('affinity')154 155if config.operating_system in ['Linux']:156 config.available_features.add('hidden-helper')157 158if config.compiler_frontend_variant == 'MSVC' or config.compiler_simulate_id == 'MSVC':159 config.available_features.add("msvc")160 161target_arch = getattr(config, 'target_arch', None)162if target_arch:163 config.available_features.add(target_arch + '-target-arch')164 if target_arch in ['x86_64', 'i386']:165 config.available_features.add('x86-target-arch')166 167import multiprocessing168try:169 if multiprocessing.cpu_count() > 1:170 config.available_features.add('multicpu')171except NotImplementedError:172 pass173 174# to run with icc INTEL_LICENSE_FILE must be set175if 'INTEL_LICENSE_FILE' in os.environ:176 config.environment['INTEL_LICENSE_FILE'] = os.environ['INTEL_LICENSE_FILE']177 178# set default environment variables for test179if 'CHECK_OPENMP_ENV' in os.environ:180 test_env = os.environ['CHECK_OPENMP_ENV'].split()181 for env in test_env:182 name = env.split('=')[0]183 value = env.split('=')[1]184 config.environment[name] = value185 186# substitutions187config.substitutions.append(("%libomp-compile-and-run", \188 "%libomp-compile && %libomp-run"))189config.substitutions.append(("%libomp-irbuilder-compile-and-run", \190 "%libomp-irbuilder-compile && %libomp-run"))191config.substitutions.append(("%libomp-c99-compile-and-run", \192 "%libomp-c99-compile && %libomp-run"))193config.substitutions.append(("%libomp-cxx-compile-and-run", \194 "%libomp-cxx-compile && %libomp-run"))195config.substitutions.append(("%libomp-cxx20-compile-and-run", \196 "%libomp-cxx20-compile && %libomp-run"))197config.substitutions.append(("%libomp-cxx-compile-c", \198 "%clangXX %openmp_flags %flags -std=c++17 -x c++ %s -o %t" + libs))199config.substitutions.append(("%libomp-cxx-compile", \200 "%clangXX %openmp_flags %flags -std=c++17 %s -o %t" + libs))201config.substitutions.append(("%libomp-cxx20-compile", \202 "%clangXX %openmp_flags %flags -std=c++20 %s -o %t" + libs))203config.substitutions.append(("%libomp-compile", \204 "%clang %openmp_flags %flags %s -o %t" + libs))205config.substitutions.append(("%libomp-irbuilder-compile", \206 "%clang %openmp_flags %flags -fopenmp-enable-irbuilder %s -o %t" + libs))207config.substitutions.append(("%libomp-c99-compile", \208 "%clang %openmp_flags %flags -std=c99 %s -o %t" + libs))209config.substitutions.append(("%libomp-run", "%t"))210config.substitutions.append(("%clangXX", config.test_cxx_compiler))211config.substitutions.append(("%clang", config.test_c_compiler))212config.substitutions.append(("%openmp_flags", config.test_openmp_flags))213# %flags-use-compiler-omp-h allows us to use the test compiler's omp.h file which214# may have different definitions of structures than our omp.h file.215if config.is_standalone_build and config.test_compiler_has_omp_h:216 config.substitutions.append(("%flags-use-compiler-omp-h",217 config.test_flags_use_compiler_omp_h))218else:219 # If testing the runtime within an LLVM tree, then always include omp.h220 # directory associated with the new clang compiler.221 config.substitutions.append(("%flags-use-compiler-omp-h",222 config.test_flags))223config.substitutions.append(("%flags", config.test_flags))224config.substitutions.append(("%python", '"%s"' % (sys.executable)))225config.substitutions.append(("%not", config.test_not))226 227if config.has_ompt:228 config.substitutions.append(("FileCheck", "tee %%t.out | %s" % config.test_filecheck))229 config.substitutions.append(("%sort-threads", "sort -n -s"))230 if config.operating_system == 'Windows':231 # No such environment variable on Windows.232 config.substitutions.append(("%preload-tool", "true ||"))233 config.substitutions.append(("%no-as-needed-flag", "-Wl,--no-as-needed"))234 elif config.operating_system == 'Darwin':235 config.substitutions.append(("%preload-tool", "env DYLD_INSERT_LIBRARIES=%t.tool_dir/tool.so"))236 # No such linker flag on Darwin.237 config.substitutions.append(("%no-as-needed-flag", ""))238 else:239 config.substitutions.append(("%preload-tool", "env LD_PRELOAD=%t.tool_dir/tool.so"))240 config.substitutions.append(("%no-as-needed-flag", "-Wl,--no-as-needed"))241else:242 config.substitutions.append(("FileCheck", config.test_filecheck))243