xref: /llvm-project/flang/test/lit.cfg.py (revision 06eb10dadfaeaadc5d0d95d38bea4bfb5253e077)
1da9d002bSLuke Ireland# -*- Python -*-
2da9d002bSLuke Ireland
3da9d002bSLuke Irelandimport os
4da9d002bSLuke Irelandimport platform
5da9d002bSLuke Irelandimport re
6da9d002bSLuke Irelandimport subprocess
7da9d002bSLuke Irelandimport sys
8da9d002bSLuke Ireland
9da9d002bSLuke Irelandimport lit.formats
10da9d002bSLuke Irelandimport lit.util
11da9d002bSLuke Ireland
12da9d002bSLuke Irelandfrom lit.llvm import llvm_config
13da9d002bSLuke Irelandfrom lit.llvm.subst import ToolSubst
14da9d002bSLuke Irelandfrom lit.llvm.subst import FindTool
15da9d002bSLuke Ireland
16da9d002bSLuke Ireland# Configuration file for the 'lit' test runner.
17da9d002bSLuke Ireland
18da9d002bSLuke Ireland# name: The name of this test suite.
19f98ee40fSTobias Hietaconfig.name = "Flang"
20da9d002bSLuke Ireland
21da9d002bSLuke Ireland# testFormat: The test format to use to interpret tests.
22da9d002bSLuke Ireland#
23da9d002bSLuke Ireland# For now we require '&&' between commands, until they get globally killed and
24da9d002bSLuke Ireland# the test runner updated.
25da9d002bSLuke Irelandconfig.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
26da9d002bSLuke Ireland
27da9d002bSLuke Ireland# suffixes: A list of file extensions to treat as test files.
28f98ee40fSTobias Hietaconfig.suffixes = [
29f98ee40fSTobias Hieta    ".c",
30f98ee40fSTobias Hieta    ".cpp",
31f98ee40fSTobias Hieta    ".f",
32f98ee40fSTobias Hieta    ".F",
33f98ee40fSTobias Hieta    ".ff",
34f98ee40fSTobias Hieta    ".FOR",
35f98ee40fSTobias Hieta    ".for",
36f98ee40fSTobias Hieta    ".f77",
37f98ee40fSTobias Hieta    ".f90",
38f98ee40fSTobias Hieta    ".F90",
39f98ee40fSTobias Hieta    ".ff90",
40f98ee40fSTobias Hieta    ".f95",
41f98ee40fSTobias Hieta    ".F95",
42f98ee40fSTobias Hieta    ".ff95",
43f98ee40fSTobias Hieta    ".fpp",
44f98ee40fSTobias Hieta    ".FPP",
454ad72793SPeter Klausler    ".cuf",
464ad72793SPeter Klausler    ".CUF",
47f98ee40fSTobias Hieta    ".f18",
48f98ee40fSTobias Hieta    ".F18",
49f98ee40fSTobias Hieta    ".f03",
50f98ee40fSTobias Hieta    ".F03",
51f98ee40fSTobias Hieta    ".f08",
52f98ee40fSTobias Hieta    ".F08",
53f98ee40fSTobias Hieta    ".ll",
54f98ee40fSTobias Hieta    ".fir",
55f98ee40fSTobias Hieta    ".mlir",
56f98ee40fSTobias Hieta]
57da9d002bSLuke Ireland
58f98ee40fSTobias Hietaconfig.substitutions.append(("%PATH%", config.environment["PATH"]))
59f98ee40fSTobias Hietaconfig.substitutions.append(("%llvmshlibdir", config.llvm_shlib_dir))
60f98ee40fSTobias Hietaconfig.substitutions.append(("%pluginext", config.llvm_plugin_ext))
61da9d002bSLuke Ireland
62da9d002bSLuke Irelandllvm_config.use_default_substitutions()
63da9d002bSLuke Ireland
647ce8c6fcSKiran Chandramohan# ask llvm-config about asserts
65f98ee40fSTobias Hietallvm_config.feature_config([("--assertion-mode", {"ON": "asserts"})])
667ce8c6fcSKiran Chandramohan
6738101b4eSAndrzej Warzynski# Targets
6838101b4eSAndrzej Warzynskiconfig.targets = frozenset(config.targets_to_build.split())
6938101b4eSAndrzej Warzynskifor arch in config.targets_to_build.split():
70f98ee40fSTobias Hieta    config.available_features.add(arch.lower() + "-registered-target")
7138101b4eSAndrzej Warzynski
7254dc764dSUsman Nadeem# To modify the default target triple for flang tests.
7354dc764dSUsman Nadeemif config.flang_test_triple:
7454dc764dSUsman Nadeem    config.target_triple = config.flang_test_triple
7554dc764dSUsman Nadeem    config.environment[config.llvm_target_triple_env] = config.flang_test_triple
7654dc764dSUsman Nadeem
77da9d002bSLuke Ireland# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
78da9d002bSLuke Ireland# subdirectories contain auxiliary inputs for various tests in their parent
79da9d002bSLuke Ireland# directories.
80f98ee40fSTobias Hietaconfig.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"]
81da9d002bSLuke Ireland
82f52fc591SStuart Ellis# If the flang examples are built, add examples to the config
83f52fc591SStuart Ellisif config.flang_examples:
84f98ee40fSTobias Hieta    config.available_features.add("examples")
85f52fc591SStuart Ellis
86f52fc591SStuart Ellis# Plugins (loadable modules)
87f52fc591SStuart Ellisif config.has_plugins:
88f98ee40fSTobias Hieta    config.available_features.add("plugins")
89f52fc591SStuart Ellis
90d34dce25SUsman Nadeemif config.linked_bye_extension:
91f98ee40fSTobias Hieta    config.substitutions.append(("%loadbye", ""))
92d34dce25SUsman Nadeemelse:
93f98ee40fSTobias Hieta    config.substitutions.append(
94f98ee40fSTobias Hieta        (
95f98ee40fSTobias Hieta            "%loadbye",
96f98ee40fSTobias Hieta            "-fpass-plugin={}/Bye{}".format(
97f98ee40fSTobias Hieta                config.llvm_shlib_dir, config.llvm_plugin_ext
98f98ee40fSTobias Hieta            ),
99f98ee40fSTobias Hieta        )
100f98ee40fSTobias Hieta    )
101d34dce25SUsman Nadeem
102da9d002bSLuke Ireland# test_source_root: The root path where tests are located.
103da9d002bSLuke Irelandconfig.test_source_root = os.path.dirname(__file__)
104da9d002bSLuke Ireland
105da9d002bSLuke Ireland# test_exec_root: The root path where tests should be run.
106f98ee40fSTobias Hietaconfig.test_exec_root = os.path.join(config.flang_obj_root, "test")
107da9d002bSLuke Ireland
108da9d002bSLuke Ireland# Tweak the PATH to include the tools dir.
109f98ee40fSTobias Hietallvm_config.with_environment("PATH", config.flang_tools_dir, append_path=True)
110f98ee40fSTobias Hietallvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
111da9d002bSLuke Ireland
112621681e3SAndrzej Warzynskiif config.flang_standalone_build:
113765b81f6STim Keith    # For builds with FIR, set path for tco and enable related tests
114765b81f6STim Keith    if config.flang_llvm_tools_dir != "":
115f98ee40fSTobias Hieta        config.available_features.add("fir")
116765b81f6STim Keith        if config.llvm_tools_dir != config.flang_llvm_tools_dir:
117f98ee40fSTobias Hieta            llvm_config.with_environment(
118f98ee40fSTobias Hieta                "PATH", config.flang_llvm_tools_dir, append_path=True
119f98ee40fSTobias Hieta            )
120765b81f6STim Keith
1219edcf7a2SLeandro Lupori# On MacOS, -isysroot is needed to build binaries.
1229edcf7a2SLeandro Luporiisysroot_flag = []
1239edcf7a2SLeandro Luporiif config.osx_sysroot:
1249edcf7a2SLeandro Lupori    isysroot_flag = ["-isysroot", config.osx_sysroot]
1259edcf7a2SLeandro Lupori
12607abde27SLeandro Lupori# Check for DEFAULT_SYSROOT, because when it is set -isysroot has no effect.
12707abde27SLeandro Luporiif config.default_sysroot:
12807abde27SLeandro Lupori    config.available_features.add("default_sysroot")
12907abde27SLeandro Lupori
130da9d002bSLuke Ireland# For each occurrence of a flang tool name, replace it with the full path to
1310195b3a9STim Keith# the build directory holding that tool.
1327b73ca30SAndrzej Warzynskitools = [
1339edcf7a2SLeandro Lupori    ToolSubst(
1349edcf7a2SLeandro Lupori        "%flang",
135*06eb10daSBrad Richardson        command=FindTool("flang"),
1369edcf7a2SLeandro Lupori        extra_args=isysroot_flag,
1379edcf7a2SLeandro Lupori        unresolved="fatal",
1389edcf7a2SLeandro Lupori    ),
139f98ee40fSTobias Hieta    ToolSubst(
140f98ee40fSTobias Hieta        "%flang_fc1",
141*06eb10daSBrad Richardson        command=FindTool("flang"),
142f98ee40fSTobias Hieta        extra_args=["-fc1"],
143f98ee40fSTobias Hieta        unresolved="fatal",
144f98ee40fSTobias Hieta    ),
145f98ee40fSTobias Hieta]
146257b2971SCaroline Concatto
147e8a79dc3SSlava Zakharin# Flang has several unimplemented features. TODO messages are used to mark
148e8a79dc3SSlava Zakharin# and fail if these features are exercised. Some TODOs exit with a non-zero
149e8a79dc3SSlava Zakharin# exit code, but others abort the execution in assert builds.
150e8a79dc3SSlava Zakharin# To catch aborts, the `--crash` option for the `not` command has to be used.
151f98ee40fSTobias Hietatools.append(ToolSubst("%not_todo_cmd", command=FindTool("not"), unresolved="fatal"))
152f98ee40fSTobias Hietaif "asserts" in config.available_features:
153f98ee40fSTobias Hieta    tools.append(
154f98ee40fSTobias Hieta        ToolSubst(
155f98ee40fSTobias Hieta            "%not_todo_abort_cmd",
156f98ee40fSTobias Hieta            command=FindTool("not"),
157f98ee40fSTobias Hieta            extra_args=["--crash"],
158f98ee40fSTobias Hieta            unresolved="fatal",
159f98ee40fSTobias Hieta        )
160f98ee40fSTobias Hieta    )
161e8a79dc3SSlava Zakharinelse:
162f98ee40fSTobias Hieta    tools.append(
163f98ee40fSTobias Hieta        ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal")
164f98ee40fSTobias Hieta    )
1657ce8c6fcSKiran Chandramohan
1660ad051b5SDiana Picus# Define some variables to help us test that the flang runtime doesn't depend on
1670ad051b5SDiana Picus# the C++ runtime libraries. For this we need a C compiler. If for some reason
1680ad051b5SDiana Picus# we don't have one, we can just disable the test.
1690ad051b5SDiana Picusif config.cc:
170ffc67bb3SDavid Spickett    libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
171ffc67bb3SDavid Spickett    libdecimal = os.path.join(config.flang_lib_dir, "libFortranDecimal.a")
172f98ee40fSTobias Hieta    include = os.path.join(config.flang_src_dir, "include")
1730ad051b5SDiana Picus
174f98ee40fSTobias Hieta    if (
175f98ee40fSTobias Hieta        os.path.isfile(libruntime)
176ffc67bb3SDavid Spickett        and os.path.isfile(libdecimal)
177f98ee40fSTobias Hieta        and os.path.isdir(include)
178f98ee40fSTobias Hieta    ):
179f98ee40fSTobias Hieta        config.available_features.add("c-compiler")
1809edcf7a2SLeandro Lupori        tools.append(
1819edcf7a2SLeandro Lupori            ToolSubst(
1829edcf7a2SLeandro Lupori                "%cc", command=config.cc, extra_args=isysroot_flag, unresolved="fatal"
1839edcf7a2SLeandro Lupori            )
1849edcf7a2SLeandro Lupori        )
185f98ee40fSTobias Hieta        tools.append(ToolSubst("%libruntime", command=libruntime, unresolved="fatal"))
186ffc67bb3SDavid Spickett        tools.append(ToolSubst("%libdecimal", command=libdecimal, unresolved="fatal"))
187f98ee40fSTobias Hieta        tools.append(ToolSubst("%include", command=include, unresolved="fatal"))
1880ad051b5SDiana Picus
1897ce8c6fcSKiran Chandramohan# Add all the tools and their substitutions (if applicable). Use the search paths provided for
1907ce8c6fcSKiran Chandramohan# finding the tools.
191621681e3SAndrzej Warzynskiif config.flang_standalone_build:
192f98ee40fSTobias Hieta    llvm_config.add_tool_substitutions(
193f98ee40fSTobias Hieta        tools, [config.flang_llvm_tools_dir, config.llvm_tools_dir]
194f98ee40fSTobias Hieta    )
195621681e3SAndrzej Warzynskielse:
196621681e3SAndrzej Warzynski    llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
197da9d002bSLuke Ireland
198da9d002bSLuke Ireland# Enable libpgmath testing
199da9d002bSLuke Irelandresult = lit_config.params.get("LIBPGMATH")
200da9d002bSLuke Irelandif result:
201da9d002bSLuke Ireland    config.environment["LIBPGMATH"] = True
2026398baa4SSlava Zakharin
203fb5fd2d8SMichael Klemm# Determine if OpenMP runtime was built (enable OpenMP tests via REQUIRES in test file)
204fb5fd2d8SMichael Klemmif config.have_openmp_rtl:
205fb5fd2d8SMichael Klemm    config.available_features.add("openmp_runtime")
206bfeebda3SMichael Klemm    # For the enabled OpenMP tests, add a substitution that is needed in the tests to find
207bfeebda3SMichael Klemm    # the omp_lib.{h,mod} files, depending on whether the OpenMP runtime was built as a
208bfeebda3SMichael Klemm    # project or runtime.
209bfeebda3SMichael Klemm    if config.openmp_module_dir:
210bfeebda3SMichael Klemm        config.substitutions.append(
211bfeebda3SMichael Klemm            ("%openmp_flags", f"-fopenmp -J {config.openmp_module_dir}")
212bfeebda3SMichael Klemm        )
213bfeebda3SMichael Klemm    else:
214bfeebda3SMichael Klemm        config.substitutions.append(("%openmp_flags", "-fopenmp"))
215fb5fd2d8SMichael Klemm
2166398baa4SSlava Zakharin# Add features and substitutions to test F128 math support.
2176398baa4SSlava Zakharin# %f128-lib substitution may be used to generate check prefixes
2186398baa4SSlava Zakharin# for LIT tests checking for F128 library support.
2193b19e480STom Ecclesif config.flang_runtime_f128_math_lib or config.have_ldbl_mant_dig_113:
2208ae877a0STom Eccles    config.available_features.add("flang-supports-f128-math")
2213b19e480STom Ecclesif config.flang_runtime_f128_math_lib:
2226398baa4SSlava Zakharin    config.available_features.add(
2236398baa4SSlava Zakharin        "flang-f128-math-lib-" + config.flang_runtime_f128_math_lib
2246398baa4SSlava Zakharin    )
2256398baa4SSlava Zakharin    config.substitutions.append(
2266398baa4SSlava Zakharin        ("%f128-lib", config.flang_runtime_f128_math_lib.upper())
2276398baa4SSlava Zakharin    )
2286398baa4SSlava Zakharinelse:
2296398baa4SSlava Zakharin    config.substitutions.append(("%f128-lib", "NONE"))
230