[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / mlir / test / lit.cfg.py
blob7c8bd6aea8aba7790b615cfee0761c4c9e524781
1 # -*- Python -*-
3 import os
4 import platform
5 import re
6 import subprocess
7 import tempfile
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 = 'MLIR'
21 config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
23 # suffixes: A list of file extensions to treat as test files.
24 config.suffixes = ['.td', '.mlir', '.toy', '.ll', '.tc', '.py', '.yaml', '.test', '.pdll', '.c']
26 # test_source_root: The root path where tests are located.
27 config.test_source_root = os.path.dirname(__file__)
29 # test_exec_root: The root path where tests should be run.
30 config.test_exec_root = os.path.join(config.mlir_obj_root, 'test')
32 config.substitutions.append(('%PATH%', config.environment['PATH']))
33 config.substitutions.append(('%shlibext', config.llvm_shlib_ext))
34 config.substitutions.append(("%mlir_src_root", config.mlir_src_root))
35 config.substitutions.append(("%host_cxx", config.host_cxx))
36 config.substitutions.append(("%host_cc", config.host_cc))
39 # Searches for a runtime library with the given name and returns a tool
40 # substitution of the same name and the found path.
41 # Correctly handles the platforms shared library directory and naming conventions.
42 def add_runtime(name):
43 path = ''
44 for prefix in ['', 'lib']:
45 path = os.path.join(config.llvm_shlib_dir, f'{prefix}{name}{config.llvm_shlib_ext}')
46 if os.path.isfile(path):
47 break
48 return ToolSubst(f'%{name}', path)
51 llvm_config.with_system_environment(
52 ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP'])
54 llvm_config.use_default_substitutions()
56 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
57 # subdirectories contain auxiliary inputs for various tests in their parent
58 # directories.
59 config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt',
60 'lit.cfg.py', 'lit.site.cfg.py']
62 # Tweak the PATH to include the tools dir.
63 llvm_config.with_environment('PATH', config.mlir_tools_dir, append_path=True)
64 llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
66 tool_dirs = [config.mlir_tools_dir, config.llvm_tools_dir]
67 tools = [
68 'mlir-opt',
69 'mlir-tblgen',
70 'mlir-translate',
71 'mlir-lsp-server',
72 'mlir-capi-execution-engine-test',
73 'mlir-capi-ir-test',
74 'mlir-capi-llvm-test',
75 'mlir-capi-pass-test',
76 'mlir-capi-pdl-test',
77 'mlir-capi-quant-test',
78 'mlir-capi-sparse-tensor-test',
79 'mlir-capi-transform-test',
80 'mlir-cpu-runner',
81 add_runtime('mlir_runner_utils'),
82 add_runtime('mlir_c_runner_utils'),
83 add_runtime('mlir_async_runtime'),
84 'mlir-linalg-ods-yaml-gen',
85 'mlir-reduce',
86 'mlir-pdll',
87 'not',
90 if config.enable_spirv_cpu_runner:
91 tools.extend(['mlir-spirv-cpu-runner', add_runtime('mlir_test_spirv_cpu_runner_c_wrappers')])
93 if config.enable_vulkan_runner:
94 tools.extend([add_runtime('vulkan-runtime-wrappers')])
96 if config.enable_rocm_runner:
97 tools.extend([add_runtime('mlir_rocm_runtime')])
99 if config.enable_cuda_runner:
100 tools.extend([add_runtime('mlir_cuda_runtime')])
102 # The following tools are optional
103 tools.extend([
104 ToolSubst('toyc-ch1', unresolved='ignore'),
105 ToolSubst('toyc-ch2', unresolved='ignore'),
106 ToolSubst('toyc-ch3', unresolved='ignore'),
107 ToolSubst('toyc-ch4', unresolved='ignore'),
108 ToolSubst('toyc-ch5', unresolved='ignore'),
109 ToolSubst('toyc-ch6', unresolved='ignore'),
110 ToolSubst('toyc-ch7', unresolved='ignore'),
111 ToolSubst('%mlir_lib_dir', config.mlir_lib_dir, unresolved='ignore'),
112 ToolSubst('%mlir_src_dir', config.mlir_src_root, unresolved='ignore'),
115 python_executable = config.python_executable
116 # Python configuration with sanitizer requires some magic preloading. This will only work on clang/linux.
117 # TODO: detect Darwin/Windows situation (or mark these tests as unsupported on these platforms).
118 if "asan" in config.available_features and "Linux" in config.host_os:
119 python_executable = f"LD_PRELOAD=$({config.host_cxx} -print-file-name=libclang_rt.asan-{config.host_arch}.so) {config.python_executable}"
120 # On Windows the path to python could contains spaces in which case it needs to be provided in quotes.
121 # This is the equivalent of how %python is setup in llvm/utils/lit/lit/llvm/config.py.
122 elif "Windows" in config.host_os:
123 python_executable = '"%s"' % (python_executable)
124 tools.extend([
125 ToolSubst('%PYTHON', python_executable, unresolved='ignore'),
128 llvm_config.add_tool_substitutions(tools, tool_dirs)
131 # FileCheck -enable-var-scope is enabled by default in MLIR test
132 # This option avoids to accidentally reuse variable across -LABEL match,
133 # it can be explicitly opted-in by prefixing the variable name with $
134 config.environment['FILECHECK_OPTS'] = "-enable-var-scope --allow-unused-prefixes=false"
136 # Add the python path for both the source and binary tree.
137 # Note that presently, the python sources come from the source tree and the
138 # binaries come from the build tree. This should be unified to the build tree
139 # by copying/linking sources to build.
140 if config.enable_bindings_python:
141 llvm_config.with_environment('PYTHONPATH', [
142 os.path.join(config.mlir_obj_root, 'python_packages', 'mlir_core'),
143 os.path.join(config.mlir_obj_root, 'python_packages', 'mlir_test'),
144 ], append_path=True)
146 if config.enable_assertions:
147 config.available_features.add('asserts')
148 else:
149 config.available_features.add('noasserts')
151 def have_host_jit_feature_support(feature_name):
152 mlir_cpu_runner_exe = lit.util.which('mlir-cpu-runner', config.mlir_tools_dir)
154 if not mlir_cpu_runner_exe:
155 return False
157 try:
158 mlir_cpu_runner_cmd = subprocess.Popen(
159 [mlir_cpu_runner_exe, '--host-supports-' + feature_name], stdout=subprocess.PIPE)
160 except OSError:
161 print('could not exec mlir-cpu-runner')
162 return False
164 mlir_cpu_runner_out = mlir_cpu_runner_cmd.stdout.read().decode('ascii')
165 mlir_cpu_runner_cmd.wait()
167 return 'true' in mlir_cpu_runner_out
169 if have_host_jit_feature_support('jit'):
170 config.available_features.add('host-supports-jit')