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-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    [('--build-mode', {'DEBUG': 'debug'}),
67     ('--assertion-mode', {'ON': 'asserts'}),
68     ('--targets-built', {'AArch64': 'aarch64',
69                          'AMDGPU': 'amdgpu',
70                          'ARM': 'arm',
71                          'AVR': 'avr',
72                          'Hexagon': 'hexagon',
73                          'Mips': 'mips',
74                          'MSP430': 'msp430',
75                          'PowerPC': 'ppc',
76                          'RISCV': 'riscv',
77                          'Sparc': 'sparc',
78                          'WebAssembly': 'wasm',
79                          'X86': 'x86'})
80     ])
81
82# Set a fake constant version so that we get consistent output.
83config.environment['LLD_VERSION'] = 'LLD 1.0'
84config.environment['LLD_IN_TEST'] = '1'
85
86# Indirectly check if the mt.exe Microsoft utility exists by searching for
87# cvtres, which always accompanies it.  Alternatively, check if we can use
88# libxml2 to merge manifests.
89if (lit.util.which('cvtres', config.environment['PATH']) or
90        config.have_libxml2):
91    config.available_features.add('manifest_tool')
92
93if config.have_libxar:
94    config.available_features.add('xar')
95
96if config.have_libxml2:
97    config.available_features.add('libxml2')
98
99if config.have_dia_sdk:
100    config.available_features.add("diasdk")
101
102if config.sizeof_void_p == 8:
103    config.available_features.add("llvm-64-bits")
104
105tar_executable = lit.util.which('tar', config.environment['PATH'])
106if tar_executable:
107    env = os.environ
108    env['LANG'] = 'C'
109    tar_version = subprocess.Popen(
110        [tar_executable, '--version'],
111        stdout=subprocess.PIPE,
112        stderr=subprocess.PIPE,
113        env=env)
114    sout, _ = tar_version.communicate()
115    if 'GNU tar' in sout.decode():
116        config.available_features.add('gnutar')
117
118# ELF tests expect the default target for ld.lld to be ELF.
119if config.ld_lld_default_mingw:
120    config.excludes.append('ELF')
121