Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / lit.cfg.py
blob73ba872b20e4081f35fc336edff5d2ee09d6ce2f
1 # -*- Python -*-
3 import os
4 import platform
5 import re
6 import subprocess
7 import sys
9 import lit.formats
10 import lit.util
12 from lit.llvm import llvm_config
13 from lit.llvm.subst import ToolSubst
14 from lit.llvm.subst import FindTool
16 # Configuration file for the 'lit' test runner.
18 # name: The name of this test suite.
19 config.name = 'Flang'
21 # testFormat: The test format to use to interpret tests.
23 # For now we require '&&' between commands, until they get globally killed and
24 # the test runner updated.
25 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
27 # suffixes: A list of file extensions to treat as test files.
28 config.suffixes = ['.c', '.cpp', '.f', '.F', '.ff', '.FOR', '.for', '.f77', '.f90', '.F90',
29 '.ff90', '.f95', '.F95', '.ff95', '.fpp', '.FPP', '.cuf'
30 '.CUF', '.f18', '.F18', '.f03', '.F03', '.f08', '.F08',
31 '.ll', '.fir', '.mlir']
33 config.substitutions.append(('%PATH%', config.environment['PATH']))
34 config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir))
35 config.substitutions.append(('%pluginext', config.llvm_plugin_ext))
37 llvm_config.use_default_substitutions()
39 # ask llvm-config about asserts
40 llvm_config.feature_config(
41 [('--assertion-mode', {'ON': 'asserts'})])
43 # Targets
44 config.targets = frozenset(config.targets_to_build.split())
45 for arch in config.targets_to_build.split():
46 config.available_features.add(arch.lower() + '-registered-target')
48 # To modify the default target triple for flang tests.
49 if config.flang_test_triple:
50 config.target_triple = config.flang_test_triple
51 config.environment[config.llvm_target_triple_env] = config.flang_test_triple
53 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
54 # subdirectories contain auxiliary inputs for various tests in their parent
55 # directories.
56 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
58 # If the flang examples are built, add examples to the config
59 if config.flang_examples:
60 config.available_features.add('examples')
62 # Plugins (loadable modules)
63 if config.has_plugins:
64 config.available_features.add('plugins')
66 if config.linked_bye_extension:
67 config.substitutions.append(('%loadbye', ''))
68 else:
69 config.substitutions.append(('%loadbye',
70 '-fpass-plugin={}/Bye{}'.format(config.llvm_shlib_dir,
71 config.llvm_plugin_ext)))
73 # test_source_root: The root path where tests are located.
74 config.test_source_root = os.path.dirname(__file__)
76 # test_exec_root: The root path where tests should be run.
77 config.test_exec_root = os.path.join(config.flang_obj_root, 'test')
79 # Tweak the PATH to include the tools dir.
80 llvm_config.with_environment('PATH', config.flang_tools_dir, append_path=True)
81 llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
83 if config.flang_standalone_build:
84 # For builds with FIR, set path for tco and enable related tests
85 if config.flang_llvm_tools_dir != "":
86 config.available_features.add('fir')
87 if config.llvm_tools_dir != config.flang_llvm_tools_dir:
88 llvm_config.with_environment('PATH', config.flang_llvm_tools_dir, append_path=True)
90 # For each occurrence of a flang tool name, replace it with the full path to
91 # the build directory holding that tool.
92 tools = [
93 ToolSubst('%flang', command=FindTool('flang-new'), unresolved='fatal'),
94 ToolSubst('%flang_fc1', command=FindTool('flang-new'), extra_args=['-fc1'],
95 unresolved='fatal')]
97 # Flang has several unimplemented features. TODO messages are used to mark
98 # and fail if these features are exercised. Some TODOs exit with a non-zero
99 # exit code, but others abort the execution in assert builds.
100 # To catch aborts, the `--crash` option for the `not` command has to be used.
101 tools.append(ToolSubst('%not_todo_cmd', command=FindTool('not'), unresolved='fatal'))
102 if 'asserts' in config.available_features:
103 tools.append(ToolSubst('%not_todo_abort_cmd', command=FindTool('not'),
104 extra_args=['--crash'], unresolved='fatal'))
105 else:
106 tools.append(ToolSubst('%not_todo_abort_cmd', command=FindTool('not'),
107 unresolved='fatal'))
109 # Define some variables to help us test that the flang runtime doesn't depend on
110 # the C++ runtime libraries. For this we need a C compiler. If for some reason
111 # we don't have one, we can just disable the test.
112 if config.cc:
113 libruntime = os.path.join(config.flang_lib_dir, 'libFortranRuntime.a')
114 libdecimal = os.path.join(config.flang_lib_dir, 'libFortranDecimal.a')
115 include = os.path.join(config.flang_src_dir, 'include')
117 if os.path.isfile(libruntime) and os.path.isfile(libdecimal) and os.path.isdir(include):
118 config.available_features.add('c-compiler')
119 tools.append(ToolSubst('%cc', command=config.cc, unresolved='fatal'))
120 tools.append(ToolSubst('%libruntime', command=libruntime,
121 unresolved='fatal'))
122 tools.append(ToolSubst('%libdecimal', command=libdecimal,
123 unresolved='fatal'))
124 tools.append(ToolSubst('%include', command=include,
125 unresolved='fatal'))
127 # Add all the tools and their substitutions (if applicable). Use the search paths provided for
128 # finding the tools.
129 if config.flang_standalone_build:
130 llvm_config.add_tool_substitutions(tools, [config.flang_llvm_tools_dir, config.llvm_tools_dir])
131 else:
132 llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
134 # Enable libpgmath testing
135 result = lit_config.params.get("LIBPGMATH")
136 if result:
137 config.environment["LIBPGMATH"] = True