xref: /llvm-project-15.0.7/flang/test/lit.cfg.py (revision b9f3b7f8)
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 = ['.c', '.cpp', '.f', '.F', '.ff', '.FOR', '.for', '.f77', '.f90', '.F90',
29                   '.ff90', '.f95', '.F95', '.ff95', '.fpp', '.FPP', '.cuf'
30                   '.CUF', '.f18', '.F18', '.fir', '.f03', '.F03', '.f08',
31                   '.F08', '.ll']
32
33config.substitutions.append(('%PATH%', config.environment['PATH']))
34config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir))
35config.substitutions.append(('%pluginext', config.llvm_plugin_ext))
36
37llvm_config.use_default_substitutions()
38
39# ask llvm-config about asserts
40llvm_config.feature_config(
41    [('--assertion-mode', {'ON': 'asserts'})])
42
43# Targets
44config.targets = frozenset(config.targets_to_build.split())
45for arch in config.targets_to_build.split():
46    config.available_features.add(arch.lower() + '-registered-target')
47
48# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
49# subdirectories contain auxiliary inputs for various tests in their parent
50# directories.
51config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
52
53# If the flang examples are built, add examples to the config
54if config.flang_examples:
55    config.available_features.add('examples')
56
57# Plugins (loadable modules)
58if config.has_plugins:
59    config.available_features.add('plugins')
60
61# test_source_root: The root path where tests are located.
62config.test_source_root = os.path.dirname(__file__)
63
64# test_exec_root: The root path where tests should be run.
65config.test_exec_root = os.path.join(config.flang_obj_root, 'test')
66
67# Tweak the PATH to include the tools dir.
68llvm_config.with_environment('PATH', config.flang_tools_dir, append_path=True)
69llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
70
71if config.flang_standalone_build:
72    # For builds with FIR, set path for tco and enable related tests
73    if config.flang_llvm_tools_dir != "":
74        config.available_features.add('fir')
75        if config.llvm_tools_dir != config.flang_llvm_tools_dir:
76            llvm_config.with_environment('PATH', config.flang_llvm_tools_dir, append_path=True)
77
78# For each occurrence of a flang tool name, replace it with the full path to
79# the build directory holding that tool.
80tools = [
81        ToolSubst('%flang', command=FindTool('flang-new'), unresolved='fatal'),
82    ToolSubst('%flang_fc1', command=FindTool('flang-new'), extra_args=['-fc1'],
83        unresolved='fatal')]
84
85# Flang has several unimplemented features. TODO messages are used to mark and fail if these
86# features are exercised. TODOs exit with an error in non-assert builds but in assert builds
87# it aborts. To catch aborts, the `--crash` option for the `not` command has to be used.
88if 'asserts' in config.available_features:
89    tools.append(ToolSubst('%not_todo_cmd', command=FindTool('not'), extra_args=['--crash'],
90        unresolved='fatal'))
91else:
92    tools.append(ToolSubst('%not_todo_cmd', command=FindTool('not'), unresolved='fatal'))
93
94# Define some variables to help us test that the flang runtime doesn't depend on
95# the C++ runtime libraries. For this we need a C compiler. If for some reason
96# we don't have one, we can just disable the test.
97if config.cc:
98    libruntime = os.path.join(config.flang_lib_dir, 'libFortranRuntime.a')
99    libdecimal = os.path.join(config.flang_lib_dir, 'libFortranDecimal.a')
100    include = os.path.join(config.flang_src_dir, 'include')
101
102    if os.path.isfile(libruntime) and os.path.isfile(libdecimal) and os.path.isdir(include):
103        config.available_features.add('c-compiler')
104        tools.append(ToolSubst('%cc', command=config.cc, unresolved='fatal'))
105        tools.append(ToolSubst('%libruntime', command=libruntime,
106            unresolved='fatal'))
107        tools.append(ToolSubst('%libdecimal', command=libdecimal,
108            unresolved='fatal'))
109        tools.append(ToolSubst('%include', command=include,
110            unresolved='fatal'))
111
112# Add all the tools and their substitutions (if applicable). Use the search paths provided for
113# finding the tools.
114if config.flang_standalone_build:
115    llvm_config.add_tool_substitutions(tools, [config.flang_llvm_tools_dir, config.llvm_tools_dir])
116else:
117    llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
118
119# Enable libpgmath testing
120result = lit_config.params.get("LIBPGMATH")
121if result:
122    config.environment["LIBPGMATH"] = True
123