xref: /llvm-project-15.0.7/lld/test/lit.cfg.py (revision dfb77f2e)
1# -*- Python -*-
2
3import os
4import platform
5import re
6import subprocess
7import locale
8
9import lit.formats
10import lit.util
11
12from lit.llvm import llvm_config
13
14# Configuration file for the 'lit' test runner.
15
16# name: The name of this test suite.
17config.name = 'lld'
18
19# testFormat: The test format to use to interpret tests.
20#
21# For now we require '&&' between commands, until they get globally killed and the test runner updated.
22config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
23
24# suffixes: A list of file extensions to treat as test files.
25config.suffixes = ['.ll', '.s', '.test', '.yaml', '.objtxt']
26
27# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
28# subdirectories contain auxiliary inputs for various tests in their parent
29# directories.
30config.excludes = ['Inputs']
31
32# test_source_root: The root path where tests are located.
33config.test_source_root = os.path.dirname(__file__)
34
35config.test_exec_root = os.path.join(config.lld_obj_root, 'test')
36
37llvm_config.use_default_substitutions()
38llvm_config.use_lld()
39
40tool_patterns = [
41    'llc', 'llvm-as', 'llvm-mc', 'llvm-nm', 'llvm-objdump', 'llvm-otool', 'llvm-pdbutil',
42    'llvm-dwarfdump', 'llvm-readelf', 'llvm-readobj', 'obj2yaml', 'yaml2obj',
43    'opt', 'llvm-dis']
44
45llvm_config.add_tool_substitutions(tool_patterns)
46
47# LLD tests tend to be flaky on NetBSD, so add some retries.
48# We don't do this on other platforms because it's slower.
49if platform.system() in ['NetBSD']:
50    config.test_retry_attempts = 2
51
52# When running under valgrind, we mangle '-vg' onto the end of the triple so we
53# can check it with XFAIL and XTARGET.
54if lit_config.useValgrind:
55    config.target_triple += '-vg'
56
57# Running on ELF based *nix
58if platform.system() in ['FreeBSD', 'NetBSD', 'Linux']:
59    config.available_features.add('system-linker-elf')
60
61# Set if host-cxxabi's demangler can handle target's symbols.
62if platform.system() not in ['Windows']:
63    config.available_features.add('demangler')
64
65llvm_config.feature_config(
66    [('--targets-built', {'AArch64': 'aarch64',
67                          'AMDGPU': 'amdgpu',
68                          'ARM': 'arm',
69                          'AVR': 'avr',
70                          'Hexagon': 'hexagon',
71                          'Mips': 'mips',
72                          'MSP430': 'msp430',
73                          'PowerPC': 'ppc',
74                          'RISCV': 'riscv',
75                          'Sparc': 'sparc',
76                          'WebAssembly': 'wasm',
77                          'X86': 'x86'}),
78     ('--assertion-mode', {'ON': 'asserts'}),
79     ])
80
81# Set a fake constant version so that we get consistent output.
82config.environment['LLD_VERSION'] = 'LLD 1.0'
83
84# LLD_IN_TEST determines how many times `main` is run inside each process, which
85# lets us test that it's cleaning up after itself and resetting global state
86# correctly (which is important for usage as a library).
87run_lld_main_twice = lit_config.params.get('RUN_LLD_MAIN_TWICE', False)
88if not run_lld_main_twice:
89    config.environment['LLD_IN_TEST'] = '1'
90else:
91    config.environment['LLD_IN_TEST'] = '2'
92    # Many ELF tests fail in this mode.
93    config.excludes.append('ELF')
94    # Some old Mach-O backend tests fail, and it's due for removal anyway.
95    config.excludes.append('mach-o')
96    # Some new Mach-O backend tests fail; give them a way to mark themselves
97    # unsupported in this mode.
98    config.available_features.add('main-run-twice')
99
100# Indirectly check if the mt.exe Microsoft utility exists by searching for
101# cvtres, which always accompanies it.  Alternatively, check if we can use
102# libxml2 to merge manifests.
103if (lit.util.which('cvtres', config.environment['PATH']) or
104        config.have_libxml2):
105    config.available_features.add('manifest_tool')
106
107if config.enable_backtrace:
108    config.available_features.add('backtrace')
109
110if config.have_libxar:
111    config.available_features.add('xar')
112
113if config.have_libxml2:
114    config.available_features.add('libxml2')
115
116if config.have_dia_sdk:
117    config.available_features.add("diasdk")
118
119if config.sizeof_void_p == 8:
120    config.available_features.add("llvm-64-bits")
121
122if config.has_plugins:
123    config.available_features.add('plugins')
124
125if config.build_examples:
126    config.available_features.add('examples')
127
128if config.linked_bye_extension:
129    config.substitutions.append(('%loadbye', ''))
130    config.substitutions.append(('%loadnewpmbye', ''))
131else:
132    config.substitutions.append(('%loadbye',
133                                 '-load={}/Bye{}'.format(config.llvm_shlib_dir,
134                                                         config.llvm_shlib_ext)))
135    config.substitutions.append(('%loadnewpmbye',
136                                 '-load-pass-plugin={}/Bye{}'
137                                 .format(config.llvm_shlib_dir,
138                                         config.llvm_shlib_ext)))
139
140tar_executable = lit.util.which('tar', config.environment['PATH'])
141if tar_executable:
142    env = os.environ
143    env['LANG'] = 'C'
144    tar_version = subprocess.Popen(
145        [tar_executable, '--version'],
146        stdout=subprocess.PIPE,
147        stderr=subprocess.PIPE,
148        env=env)
149    sout, _ = tar_version.communicate()
150    if 'GNU tar' in sout.decode():
151        config.available_features.add('gnutar')
152
153# ELF tests expect the default target for ld.lld to be ELF.
154if config.ld_lld_default_mingw:
155    config.excludes.append('ELF')
156