1# -*- Python -*- 2 3import os 4import platform 5import re 6import subprocess 7import sys 8 9import lit.formats 10import lit.util 11 12from lit.llvm import llvm_config 13from lit.llvm.subst import ToolSubst 14from lit.llvm.subst import FindTool 15 16# Configuration file for the 'lit' test runner. 17 18# name: The name of this test suite. 19config.name = "Flang" 20 21# testFormat: The test format to use to interpret tests. 22# 23# For now we require '&&' between commands, until they get globally killed and 24# the test runner updated. 25config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) 26 27# suffixes: A list of file extensions to treat as test files. 28config.suffixes = [ 29 ".c", 30 ".cpp", 31 ".f", 32 ".F", 33 ".ff", 34 ".FOR", 35 ".for", 36 ".f77", 37 ".f90", 38 ".F90", 39 ".ff90", 40 ".f95", 41 ".F95", 42 ".ff95", 43 ".fpp", 44 ".FPP", 45 ".cuf", 46 ".CUF", 47 ".f18", 48 ".F18", 49 ".f03", 50 ".F03", 51 ".f08", 52 ".F08", 53 ".ll", 54 ".fir", 55 ".mlir", 56] 57 58config.substitutions.append(("%PATH%", config.environment["PATH"])) 59config.substitutions.append(("%llvmshlibdir", config.llvm_shlib_dir)) 60config.substitutions.append(("%pluginext", config.llvm_plugin_ext)) 61 62llvm_config.use_default_substitutions() 63 64# ask llvm-config about asserts 65llvm_config.feature_config([("--assertion-mode", {"ON": "asserts"})]) 66 67# Targets 68config.targets = frozenset(config.targets_to_build.split()) 69for arch in config.targets_to_build.split(): 70 config.available_features.add(arch.lower() + "-registered-target") 71 72# To modify the default target triple for flang tests. 73if config.flang_test_triple: 74 config.target_triple = config.flang_test_triple 75 config.environment[config.llvm_target_triple_env] = config.flang_test_triple 76 77# excludes: A list of directories to exclude from the testsuite. The 'Inputs' 78# subdirectories contain auxiliary inputs for various tests in their parent 79# directories. 80config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"] 81 82# If the flang examples are built, add examples to the config 83if config.flang_examples: 84 config.available_features.add("examples") 85 86# Plugins (loadable modules) 87if config.has_plugins: 88 config.available_features.add("plugins") 89 90if config.linked_bye_extension: 91 config.substitutions.append(("%loadbye", "")) 92else: 93 config.substitutions.append( 94 ( 95 "%loadbye", 96 "-fpass-plugin={}/Bye{}".format( 97 config.llvm_shlib_dir, config.llvm_plugin_ext 98 ), 99 ) 100 ) 101 102# test_source_root: The root path where tests are located. 103config.test_source_root = os.path.dirname(__file__) 104 105# test_exec_root: The root path where tests should be run. 106config.test_exec_root = os.path.join(config.flang_obj_root, "test") 107 108# Tweak the PATH to include the tools dir. 109llvm_config.with_environment("PATH", config.flang_tools_dir, append_path=True) 110llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True) 111 112if config.flang_standalone_build: 113 # For builds with FIR, set path for tco and enable related tests 114 if config.flang_llvm_tools_dir != "": 115 config.available_features.add("fir") 116 if config.llvm_tools_dir != config.flang_llvm_tools_dir: 117 llvm_config.with_environment( 118 "PATH", config.flang_llvm_tools_dir, append_path=True 119 ) 120 121# On MacOS, -isysroot is needed to build binaries. 122isysroot_flag = [] 123if config.osx_sysroot: 124 isysroot_flag = ["-isysroot", config.osx_sysroot] 125 126# Check for DEFAULT_SYSROOT, because when it is set -isysroot has no effect. 127if config.default_sysroot: 128 config.available_features.add("default_sysroot") 129 130# For each occurrence of a flang tool name, replace it with the full path to 131# the build directory holding that tool. 132tools = [ 133 ToolSubst( 134 "%flang", 135 command=FindTool("flang"), 136 extra_args=isysroot_flag, 137 unresolved="fatal", 138 ), 139 ToolSubst( 140 "%flang_fc1", 141 command=FindTool("flang"), 142 extra_args=["-fc1"], 143 unresolved="fatal", 144 ), 145] 146 147# Flang has several unimplemented features. TODO messages are used to mark 148# and fail if these features are exercised. Some TODOs exit with a non-zero 149# exit code, but others abort the execution in assert builds. 150# To catch aborts, the `--crash` option for the `not` command has to be used. 151tools.append(ToolSubst("%not_todo_cmd", command=FindTool("not"), unresolved="fatal")) 152if "asserts" in config.available_features: 153 tools.append( 154 ToolSubst( 155 "%not_todo_abort_cmd", 156 command=FindTool("not"), 157 extra_args=["--crash"], 158 unresolved="fatal", 159 ) 160 ) 161else: 162 tools.append( 163 ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal") 164 ) 165 166# Define some variables to help us test that the flang runtime doesn't depend on 167# the C++ runtime libraries. For this we need a C compiler. If for some reason 168# we don't have one, we can just disable the test. 169if config.cc: 170 libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a") 171 libdecimal = os.path.join(config.flang_lib_dir, "libFortranDecimal.a") 172 include = os.path.join(config.flang_src_dir, "include") 173 174 if ( 175 os.path.isfile(libruntime) 176 and os.path.isfile(libdecimal) 177 and os.path.isdir(include) 178 ): 179 config.available_features.add("c-compiler") 180 tools.append( 181 ToolSubst( 182 "%cc", command=config.cc, extra_args=isysroot_flag, unresolved="fatal" 183 ) 184 ) 185 tools.append(ToolSubst("%libruntime", command=libruntime, unresolved="fatal")) 186 tools.append(ToolSubst("%libdecimal", command=libdecimal, unresolved="fatal")) 187 tools.append(ToolSubst("%include", command=include, unresolved="fatal")) 188 189# Add all the tools and their substitutions (if applicable). Use the search paths provided for 190# finding the tools. 191if config.flang_standalone_build: 192 llvm_config.add_tool_substitutions( 193 tools, [config.flang_llvm_tools_dir, config.llvm_tools_dir] 194 ) 195else: 196 llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir) 197 198# Enable libpgmath testing 199result = lit_config.params.get("LIBPGMATH") 200if result: 201 config.environment["LIBPGMATH"] = True 202 203# Determine if OpenMP runtime was built (enable OpenMP tests via REQUIRES in test file) 204if config.have_openmp_rtl: 205 config.available_features.add("openmp_runtime") 206 # For the enabled OpenMP tests, add a substitution that is needed in the tests to find 207 # the omp_lib.{h,mod} files, depending on whether the OpenMP runtime was built as a 208 # project or runtime. 209 if config.openmp_module_dir: 210 config.substitutions.append( 211 ("%openmp_flags", f"-fopenmp -J {config.openmp_module_dir}") 212 ) 213 else: 214 config.substitutions.append(("%openmp_flags", "-fopenmp")) 215 216# Add features and substitutions to test F128 math support. 217# %f128-lib substitution may be used to generate check prefixes 218# for LIT tests checking for F128 library support. 219if config.flang_runtime_f128_math_lib or config.have_ldbl_mant_dig_113: 220 config.available_features.add("flang-supports-f128-math") 221if config.flang_runtime_f128_math_lib: 222 config.available_features.add( 223 "flang-f128-math-lib-" + config.flang_runtime_f128_math_lib 224 ) 225 config.substitutions.append( 226 ("%f128-lib", config.flang_runtime_f128_math_lib.upper()) 227 ) 228else: 229 config.substitutions.append(("%f128-lib", "NONE")) 230