221 lines · python
1# -*- Python -*-2 3import os4import platform5import re6import subprocess7import sys8 9import lit.formats10import lit.util11 12from lit.llvm import llvm_config13from lit.llvm.subst import ToolSubst14from lit.llvm.subst import FindTool15 16# Configuration file for the 'lit' test runner.17 18# name: The name of this test suite.19config.name = "Flang"20 21# TODO: Consolidate the logic for turning on the internal shell by default for all LLVM test suites.22# See https://github.com/llvm/llvm-project/issues/106636 for more details.23#24# We prefer the lit internal shell which provides a better user experience on failures25# and is faster unless the user explicitly disables it with LIT_USE_INTERNAL_SHELL=026# env var.27use_lit_shell = True28lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")29if lit_shell_env:30 use_lit_shell = lit.util.pythonize_bool(lit_shell_env)31 32# testFormat: The test format to use to interpret tests.33#34# For now we require '&&' between commands, until they get globally killed and35# the test runner updated.36config.test_format = lit.formats.ShTest(execute_external=not use_lit_shell)37 38# suffixes: A list of file extensions to treat as test files.39config.suffixes = [40 ".c",41 ".cpp",42 ".f",43 ".F",44 ".ff",45 ".FOR",46 ".for",47 ".f77",48 ".f90",49 ".F90",50 ".ff90",51 ".f95",52 ".F95",53 ".ff95",54 ".fpp",55 ".FPP",56 ".cuf",57 ".CUF",58 ".f18",59 ".F18",60 ".f03",61 ".F03",62 ".f08",63 ".F08",64 ".ll",65 ".fir",66 ".mlir",67]68 69config.substitutions.append(("%PATH%", config.environment["PATH"]))70config.substitutions.append(("%llvmshlibdir", config.llvm_shlib_dir))71config.substitutions.append(("%pluginext", config.llvm_plugin_ext))72 73llvm_config.use_default_substitutions()74 75# ask llvm-config about asserts76llvm_config.feature_config([("--assertion-mode", {"ON": "asserts"})])77 78# Targets79config.targets = frozenset(config.targets_to_build.split())80for arch in config.targets_to_build.split():81 config.available_features.add(arch.lower() + "-registered-target")82 83# To modify the default target triple for flang tests.84if config.flang_test_triple:85 config.target_triple = config.flang_test_triple86 config.environment[config.llvm_target_triple_env] = config.flang_test_triple87 88# excludes: A list of directories to exclude from the testsuite. The 'Inputs'89# subdirectories contain auxiliary inputs for various tests in their parent90# directories.91config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"]92 93# If the flang examples are built, add examples to the config94if config.flang_examples:95 config.available_features.add("examples")96 97# Plugins (loadable modules)98if config.has_plugins:99 config.available_features.add("plugins")100 101if config.linked_bye_extension:102 config.substitutions.append(("%loadbye", ""))103else:104 config.substitutions.append(105 (106 "%loadbye",107 "-fpass-plugin={}/Bye{}".format(108 config.llvm_shlib_dir, config.llvm_plugin_ext109 ),110 )111 )112 113# test_source_root: The root path where tests are located.114config.test_source_root = os.path.dirname(__file__)115 116# test_exec_root: The root path where tests should be run.117config.test_exec_root = os.path.join(config.flang_obj_root, "test")118 119# Tweak the PATH to include the tools dir.120llvm_config.with_environment("PATH", config.flang_tools_dir, append_path=True)121llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)122 123if config.flang_standalone_build:124 # For builds with FIR, set path for tco and enable related tests125 if config.flang_llvm_tools_dir != "":126 config.available_features.add("fir")127 if config.llvm_tools_dir != config.flang_llvm_tools_dir:128 llvm_config.with_environment(129 "PATH", config.flang_llvm_tools_dir, append_path=True130 )131 132# On MacOS, some tests need -isysroot to build binaries.133isysroot_flag = []134if config.osx_sysroot:135 isysroot_flag = ["-isysroot", config.osx_sysroot]136config.substitutions.append(("%isysroot", " ".join(isysroot_flag)))137 138# Check for DEFAULT_SYSROOT, because when it is set -isysroot has no effect.139if config.default_sysroot:140 config.available_features.add("default_sysroot")141 142# For each occurrence of a flang tool name, replace it with the full path to143# the build directory holding that tool.144tools = [145 ToolSubst(146 "%flang",147 command=FindTool("flang"),148 unresolved="fatal",149 ),150 ToolSubst(151 "%flang_fc1",152 command=FindTool("flang"),153 extra_args=["-fc1"],154 unresolved="fatal",155 ),156]157 158# Flang has several unimplemented features. TODO messages are used to mark159# and fail if these features are exercised. Some TODOs exit with a non-zero160# exit code, but others abort the execution in assert builds.161# To catch aborts, the `--crash` option for the `not` command has to be used.162tools.append(ToolSubst("%not_todo_cmd", command=FindTool("not"), unresolved="fatal"))163if "asserts" in config.available_features:164 tools.append(165 ToolSubst(166 "%not_todo_abort_cmd",167 command=FindTool("not"),168 extra_args=["--crash"],169 unresolved="fatal",170 )171 )172else:173 tools.append(174 ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal")175 )176 177# Add all the tools and their substitutions (if applicable). Use the search paths provided for178# finding the tools.179if config.flang_standalone_build:180 llvm_config.add_tool_substitutions(181 tools, [config.flang_llvm_tools_dir, config.llvm_tools_dir]182 )183else:184 llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)185 186llvm_config.use_clang(required=False)187 188# Clang may need the include path for ISO_fortran_binding.h.189config.substitutions.append(("%flang_include", config.flang_headers_dir))190 191# Enable libpgmath testing192result = lit_config.params.get("LIBPGMATH")193if result:194 config.environment["LIBPGMATH"] = True195 196# Determine if OpenMP runtime was built (enable OpenMP tests via REQUIRES in test file)197openmp_flags_substitution = "-fopenmp"198if config.have_openmp_rtl:199 config.available_features.add("openmp_runtime")200 # For the enabled OpenMP tests, add a substitution that is needed in the tests to find201 # the omp_lib.{h,mod} files, depending on whether the OpenMP runtime was built as a202 # project or runtime.203 if config.openmp_module_dir:204 openmp_flags_substitution += f" -J {config.openmp_module_dir}"205config.substitutions.append(("%openmp_flags", openmp_flags_substitution))206 207# Add features and substitutions to test F128 math support.208# %f128-lib substitution may be used to generate check prefixes209# for LIT tests checking for F128 library support.210if config.flang_runtime_f128_math_lib or config.have_ldbl_mant_dig_113:211 config.available_features.add("flang-supports-f128-math")212if config.flang_runtime_f128_math_lib:213 config.available_features.add(214 "flang-f128-math-lib-" + config.flang_runtime_f128_math_lib215 )216 config.substitutions.append(217 ("%f128-lib", config.flang_runtime_f128_math_lib.upper())218 )219else:220 config.substitutions.append(("%f128-lib", "NONE"))221