blob: 39b5586612cca51743eed2746ae45e2f3ee8f944 [file] [log] [blame]
Daniel Dunbar3667b992009-07-31 05:54:17 +00001# -*- Python -*-
2
Daniel Dunbarb5cbf772009-09-22 05:16:02 +00003import os
Daniel Dunbar79327b62009-09-22 10:08:03 +00004import platform
Chandler Carruth2837f662011-11-05 20:55:50 +00005import re
6import subprocess
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +00007import tempfile
Chandler Carruth2837f662011-11-05 20:55:50 +00008
Daniel Dunbar94ec6cc2013-08-09 14:43:04 +00009import lit.formats
10import lit.util
Daniel Dunbarbe4253a2009-09-08 16:39:23 +000011
Zachary Turnerd4401d32017-09-18 22:26:48 +000012from lit.llvm import llvm_config
Zachary Turner96b04b62017-10-06 17:54:46 +000013from lit.llvm.subst import ToolSubst
14from lit.llvm.subst import FindTool
Zachary Turnerd4401d32017-09-18 22:26:48 +000015
Daniel Dunbar3667b992009-07-31 05:54:17 +000016# Configuration file for the 'lit' test runner.
17
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000018# name: The name of this test suite.
19config.name = 'Clang'
Daniel Dunbarbe4253a2009-09-08 16:39:23 +000020
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000021# testFormat: The test format to use to interpret tests.
Daniel Dunbar3667b992009-07-31 05:54:17 +000022#
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000023# For now we require '&&' between commands, until they get globally killed and
24# the test runner updated.
Zachary Turnerd4401d32017-09-18 22:26:48 +000025config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
Daniel Dunbarf87be552009-09-06 01:31:12 +000026
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000027# suffixes: A list of file extensions to treat as test files.
Zachary Turnerc9814482017-10-06 17:54:27 +000028config.suffixes = ['.c', '.cpp', '.cppm', '.m', '.mm', '.cu',
29 '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs']
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000030
Alp Toker9c5ae472013-11-15 13:37:49 +000031# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
32# subdirectories contain auxiliary inputs for various tests in their parent
33# directories.
Don Hintond15d76e2017-12-14 22:12:46 +000034config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt', 'debuginfo-tests']
Alp Toker9c5ae472013-11-15 13:37:49 +000035
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000036# test_source_root: The root path where tests are located.
37config.test_source_root = os.path.dirname(__file__)
38
39# test_exec_root: The root path where tests should be run.
Zachary Turnerce92db12017-09-15 22:10:46 +000040config.test_exec_root = os.path.join(config.clang_obj_root, 'test')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000041
Zachary Turner8eb70052017-10-17 23:43:36 +000042llvm_config.use_default_substitutions()
Jordy Rose0e09fac2012-04-06 18:14:01 +000043
Zachary Turner8eb70052017-10-17 23:43:36 +000044llvm_config.use_clang()
Daniel Dunbara87097a2009-09-26 07:36:09 +000045
Alexey Samsonovc01f4f02013-04-04 07:41:20 +000046# Propagate path to symbolizer for ASan/MSan.
Zachary Turnerc9814482017-10-06 17:54:27 +000047llvm_config.with_system_environment(
48 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
Alexey Samsonovc01f4f02013-04-04 07:41:20 +000049
Zachary Turner8eb70052017-10-17 23:43:36 +000050config.substitutions.append(('%PATH%', config.environment['PATH']))
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000051
Zachary Turnerc9814482017-10-06 17:54:27 +000052
Zachary Turner8eb70052017-10-17 23:43:36 +000053# For each occurrence of a clang tool name, replace it with the full path to
54# the build directory holding that tool. We explicitly specify the directories
55# to search to ensure that we get the tools just built and not some random
56# tools that might happen to be in the user's PATH.
57tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000058
Zachary Turner8eb70052017-10-17 23:43:36 +000059tools = [
Eric Fiselierb87be182018-05-19 03:12:04 +000060 'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'clang-tblgen',
Benjamin Kramer9b10b692018-06-22 09:46:40 +000061 'opt',
Zachary Turner8eb70052017-10-17 23:43:36 +000062 ToolSubst('%clang_func_map', command=FindTool(
63 'clang-func-mapping'), unresolved='ignore'),
64]
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000065
Zachary Turner8eb70052017-10-17 23:43:36 +000066if config.clang_examples:
Zachary Turnerb719d1b2018-05-08 18:20:10 +000067 config.available_features.add('examples')
Zachary Turner8eb70052017-10-17 23:43:36 +000068 tools.append('clang-interpreter')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000069
Zachary Turner8eb70052017-10-17 23:43:36 +000070llvm_config.add_tool_substitutions(tools, tool_dirs)
Chandler Carruthc0b1b862011-11-05 10:15:27 +000071
Benjamin Kramer9b10b692018-06-22 09:46:40 +000072config.substitutions.append(
Benjamin Kramer9508af32018-06-22 20:03:32 +000073 ('%hmaptool', "'%s' %s" % (config.python_executable,
Michal Gorny624169f2018-08-01 20:38:22 +000074 os.path.join(config.clang_tools_dir, 'hmaptool'))))
Benjamin Kramer9b10b692018-06-22 09:46:40 +000075
Alp Toker120dd1af2014-01-08 11:38:47 +000076# Plugins (loadable modules)
77# TODO: This should be supplied by Makefile or autoconf.
NAKAMURA Takumiba7d0fe2016-02-11 16:43:08 +000078if sys.platform in ['win32', 'cygwin']:
Michal Gorny638ac702017-01-25 13:11:45 +000079 has_plugins = config.enable_shared
Alp Toker120dd1af2014-01-08 11:38:47 +000080else:
81 has_plugins = True
82
83if has_plugins and config.llvm_plugin_ext:
84 config.available_features.add('plugins')
85
Daniel Dunbarb44eb0b2010-08-24 21:39:55 +000086# Set available features we allow tests to conditionalize on.
Andrew Trick3df28242011-08-26 22:46:31 +000087#
Jonas Hahnfeldfdaaca82016-09-29 07:43:08 +000088if config.clang_default_cxx_stdlib != '':
89 config.available_features.add('default-cxx-stdlib-set')
90
NAKAMURA Takumi1fb02cb2014-07-16 12:05:45 +000091# Enabled/disabled features
Michal Gorny638ac702017-01-25 13:11:45 +000092if config.clang_staticanalyzer:
Zachary Turnerc9814482017-10-06 17:54:27 +000093 config.available_features.add('staticanalyzer')
NAKAMURA Takumi1fb02cb2014-07-16 12:05:45 +000094
Dominic Chen08f943c2017-04-04 19:52:25 +000095 if config.clang_staticanalyzer_z3 == '1':
Zachary Turnerc9814482017-10-06 17:54:27 +000096 config.available_features.add('z3')
Dominic Chen08f943c2017-04-04 19:52:25 +000097
Andrew Trick3df28242011-08-26 22:46:31 +000098# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
99if platform.system() not in ['FreeBSD']:
100 config.available_features.add('crash-recovery')
NAKAMURA Takumif5ea88b2011-02-28 09:41:07 +0000101
NAKAMURA Takumi6bbc9812012-09-12 10:38:03 +0000102# ANSI escape sequences in non-dumb terminal
NAKAMURA Takumib59973e2012-07-11 11:44:00 +0000103if platform.system() not in ['Windows']:
104 config.available_features.add('ansi-escape-sequences')
105
NAKAMURA Takumi0c81c712014-02-06 07:15:59 +0000106# Capability to print utf8 to the terminal.
107# Windows expects codepage, unless Wide API.
108if platform.system() not in ['Windows']:
109 config.available_features.add('utf8-capable-terminal')
110
Michal Gorny7cfe4802016-10-10 12:23:40 +0000111# Support for libgcc runtime. Used to rule out tests that require
112# clang to run with -rtlib=libgcc.
113if platform.system() not in ['Darwin', 'Fuchsia']:
114 config.available_features.add('libgcc')
115
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000116# Case-insensitive file system
Zachary Turner8eb70052017-10-17 23:43:36 +0000117
118
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000119def is_filesystem_case_insensitive():
Zachary Turnerc9814482017-10-06 17:54:27 +0000120 handle, path = tempfile.mkstemp(
121 prefix='case-test', dir=config.test_exec_root)
NAKAMURA Takumi77fcfe72013-07-01 09:51:55 +0000122 isInsensitive = os.path.exists(
123 os.path.join(
124 os.path.dirname(path),
125 os.path.basename(path).upper()
Zachary Turnerc9814482017-10-06 17:54:27 +0000126 ))
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000127 os.close(handle)
128 os.remove(path)
129 return isInsensitive
130
Zachary Turnerc9814482017-10-06 17:54:27 +0000131
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000132if is_filesystem_case_insensitive():
133 config.available_features.add('case-insensitive-filesystem')
134
Daniel Dunbar52385592012-11-15 20:06:10 +0000135# Tests that require the /dev/fd filesystem.
Zachary Turnerc9814482017-10-06 17:54:27 +0000136if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']:
Daniel Dunbar52385592012-11-15 20:06:10 +0000137 config.available_features.add('dev-fd-fs')
138
NAKAMURA Takumi08848872014-02-16 10:15:57 +0000139# Not set on native MS environment.
Petr Hosekeb46c952018-08-09 02:16:18 +0000140if not re.match(r'.*-(windows-msvc)$', config.target_triple):
NAKAMURA Takumi08848872014-02-16 10:15:57 +0000141 config.available_features.add('non-ms-sdk')
142
Filipe Cabecinhas18a72612015-01-30 18:25:59 +0000143# Not set on native PS4 environment.
Filipe Cabecinhas10ff1332015-02-02 23:17:54 +0000144if not re.match(r'.*-scei-ps4', config.target_triple):
Filipe Cabecinhas18a72612015-01-30 18:25:59 +0000145 config.available_features.add('non-ps4-sdk')
146
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000147# [PR8833] LLP64-incompatible tests
Petr Hosekeb46c952018-08-09 02:16:18 +0000148if not re.match(r'^x86_64.*-(windows-msvc|windows-gnu)$', config.target_triple):
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000149 config.available_features.add('LP64')
150
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000151# [PR12920] "clang-driver" -- set if gcc driver is not used.
NAKAMURA Takumi79e40ec2015-10-20 22:36:16 +0000152if not re.match(r'.*-(cygwin)$', config.target_triple):
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000153 config.available_features.add('clang-driver')
154
NAKAMURA Takumi23c76712014-02-16 10:15:34 +0000155# [PR18856] Depends to remove opened file. On win32, a file could be removed
156# only if all handles were closed.
157if platform.system() not in ['Windows']:
158 config.available_features.add('can-remove-opened-file')
159
Zachary Turnerc9814482017-10-06 17:54:27 +0000160
Zachary Turnerd4401d32017-09-18 22:26:48 +0000161def calculate_arch_features(arch_string):
162 features = []
163 for arch in arch_string.split():
164 features.append(arch.lower() + '-registered-target')
165 return features
NAKAMURA Takumi67eade62013-12-04 03:40:56 +0000166
Zachary Turnerc9814482017-10-06 17:54:27 +0000167
Zachary Turnerd4401d32017-09-18 22:26:48 +0000168llvm_config.feature_config(
Zachary Turnerc9814482017-10-06 17:54:27 +0000169 [('--assertion-mode', {'ON': 'asserts'}),
170 ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}),
171 ('--targets-built', calculate_arch_features)
172 ])
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +0000173
174if lit.util.which('xmllint'):
175 config.available_features.add('xmllint')
176
Michal Gorny638ac702017-01-25 13:11:45 +0000177if config.enable_backtrace:
Zachary Turnerc9814482017-10-06 17:54:27 +0000178 config.available_features.add('backtrace')
Pete Cooper7dc8af52015-02-10 19:53:38 +0000179
Yunzhong Gao7cbc78e2016-01-27 02:18:28 +0000180# Check if we should allow outputs to console.
181run_console_tests = int(lit_config.params.get('enable_console', '0'))
182if run_console_tests != 0:
Zachary Turnerc9814482017-10-06 17:54:27 +0000183 config.available_features.add('console')
Yunzhong Gao7cbc78e2016-01-27 02:18:28 +0000184
Alexander Potapenko14f8ac02014-06-10 14:22:00 +0000185lit.util.usePlatformSdkOnDarwin(config, lit_config)
Alex Lorenz01bf58d2017-06-02 11:26:35 +0000186macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
187if macOSSDKVersion is not None:
188 config.available_features.add('macos-sdk-' + macOSSDKVersion)