blob: 1ffb6d094d72c24908e4e01a8f7effa56aa6b337 [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',
Puyan Lotfic382d032019-10-08 15:23:14 +000029 '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs']
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
Zachary Turner58db03a2018-11-19 15:12:34 +000046config.substitutions.append(
47 ('%src_include_dir', config.clang_src_dir + '/include'))
48
49
Alexey Samsonovc01f4f02013-04-04 07:41:20 +000050# Propagate path to symbolizer for ASan/MSan.
Zachary Turnerc9814482017-10-06 17:54:27 +000051llvm_config.with_system_environment(
52 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
Alexey Samsonovc01f4f02013-04-04 07:41:20 +000053
Zachary Turner8eb70052017-10-17 23:43:36 +000054config.substitutions.append(('%PATH%', config.environment['PATH']))
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000055
Zachary Turnerc9814482017-10-06 17:54:27 +000056
Zachary Turner8eb70052017-10-17 23:43:36 +000057# For each occurrence of a clang tool name, replace it with the full path to
58# the build directory holding that tool. We explicitly specify the directories
59# to search to ensure that we get the tools just built and not some random
60# tools that might happen to be in the user's PATH.
61tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000062
Zachary Turner8eb70052017-10-17 23:43:36 +000063tools = [
Puyan Lotfic382d032019-10-08 15:23:14 +000064 'c-index-test', 'clang-diff', 'clang-format', 'clang-tblgen', 'opt', 'llvm-ifs',
Rafael Stahl8c487052019-01-10 17:44:04 +000065 ToolSubst('%clang_extdef_map', command=FindTool(
66 'clang-extdef-mapping'), unresolved='ignore'),
Zachary Turner8eb70052017-10-17 23:43:36 +000067]
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000068
Zachary Turner8eb70052017-10-17 23:43:36 +000069if config.clang_examples:
Zachary Turnerb719d1b2018-05-08 18:20:10 +000070 config.available_features.add('examples')
Zachary Turner8eb70052017-10-17 23:43:36 +000071 tools.append('clang-interpreter')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000072
Nico Weber55ef9a12019-05-02 19:47:05 +000073if config.clang_staticanalyzer:
74 config.available_features.add('staticanalyzer')
75 tools.append('clang-check')
76
77 if config.clang_staticanalyzer_z3 == '1':
78 config.available_features.add('z3')
79
80
Zachary Turner8eb70052017-10-17 23:43:36 +000081llvm_config.add_tool_substitutions(tools, tool_dirs)
Chandler Carruthc0b1b862011-11-05 10:15:27 +000082
Benjamin Kramer9b10b692018-06-22 09:46:40 +000083config.substitutions.append(
Benjamin Kramer9508af32018-06-22 20:03:32 +000084 ('%hmaptool', "'%s' %s" % (config.python_executable,
Michal Gorny624169f2018-08-01 20:38:22 +000085 os.path.join(config.clang_tools_dir, 'hmaptool'))))
Benjamin Kramer9b10b692018-06-22 09:46:40 +000086
Alp Toker120dd1af2014-01-08 11:38:47 +000087# Plugins (loadable modules)
Petr Hosekb7804ef2019-05-17 06:07:37 +000088if config.has_plugins and config.llvm_plugin_ext:
Alp Toker120dd1af2014-01-08 11:38:47 +000089 config.available_features.add('plugins')
90
Daniel Dunbarb44eb0b2010-08-24 21:39:55 +000091# Set available features we allow tests to conditionalize on.
Andrew Trick3df28242011-08-26 22:46:31 +000092#
Jonas Hahnfeldfdaaca82016-09-29 07:43:08 +000093if config.clang_default_cxx_stdlib != '':
94 config.available_features.add('default-cxx-stdlib-set')
95
Andrew Trick3df28242011-08-26 22:46:31 +000096# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
97if platform.system() not in ['FreeBSD']:
98 config.available_features.add('crash-recovery')
NAKAMURA Takumif5ea88b2011-02-28 09:41:07 +000099
Leonard Chane6d2c8d2019-06-19 17:41:30 +0000100# Support for new pass manager.
101if config.enable_experimental_new_pass_manager:
102 config.available_features.add('experimental-new-pass-manager')
103
NAKAMURA Takumi6bbc9812012-09-12 10:38:03 +0000104# ANSI escape sequences in non-dumb terminal
NAKAMURA Takumib59973e2012-07-11 11:44:00 +0000105if platform.system() not in ['Windows']:
106 config.available_features.add('ansi-escape-sequences')
107
NAKAMURA Takumi0c81c712014-02-06 07:15:59 +0000108# Capability to print utf8 to the terminal.
109# Windows expects codepage, unless Wide API.
110if platform.system() not in ['Windows']:
111 config.available_features.add('utf8-capable-terminal')
112
Michal Gorny7cfe4802016-10-10 12:23:40 +0000113# Support for libgcc runtime. Used to rule out tests that require
114# clang to run with -rtlib=libgcc.
115if platform.system() not in ['Darwin', 'Fuchsia']:
116 config.available_features.add('libgcc')
117
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000118# Case-insensitive file system
Zachary Turner8eb70052017-10-17 23:43:36 +0000119
120
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000121def is_filesystem_case_insensitive():
Zachary Turnerc9814482017-10-06 17:54:27 +0000122 handle, path = tempfile.mkstemp(
123 prefix='case-test', dir=config.test_exec_root)
NAKAMURA Takumi77fcfe72013-07-01 09:51:55 +0000124 isInsensitive = os.path.exists(
125 os.path.join(
126 os.path.dirname(path),
127 os.path.basename(path).upper()
Zachary Turnerc9814482017-10-06 17:54:27 +0000128 ))
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000129 os.close(handle)
130 os.remove(path)
131 return isInsensitive
132
Zachary Turnerc9814482017-10-06 17:54:27 +0000133
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000134if is_filesystem_case_insensitive():
135 config.available_features.add('case-insensitive-filesystem')
136
Daniel Dunbar52385592012-11-15 20:06:10 +0000137# Tests that require the /dev/fd filesystem.
Zachary Turnerc9814482017-10-06 17:54:27 +0000138if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']:
Daniel Dunbar52385592012-11-15 20:06:10 +0000139 config.available_features.add('dev-fd-fs')
140
Paul Robinson4b66e0f2019-05-10 13:40:17 +0000141# Set on native MS environment.
142if re.match(r'.*-(windows-msvc)$', config.target_triple):
143 config.available_features.add('ms-sdk')
Filipe Cabecinhas18a72612015-01-30 18:25:59 +0000144
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000145# [PR8833] LLP64-incompatible tests
Petr Hosekeb46c952018-08-09 02:16:18 +0000146if not re.match(r'^x86_64.*-(windows-msvc|windows-gnu)$', config.target_triple):
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000147 config.available_features.add('LP64')
148
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000149# [PR12920] "clang-driver" -- set if gcc driver is not used.
NAKAMURA Takumi79e40ec2015-10-20 22:36:16 +0000150if not re.match(r'.*-(cygwin)$', config.target_triple):
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000151 config.available_features.add('clang-driver')
152
NAKAMURA Takumi23c76712014-02-16 10:15:34 +0000153# [PR18856] Depends to remove opened file. On win32, a file could be removed
154# only if all handles were closed.
155if platform.system() not in ['Windows']:
156 config.available_features.add('can-remove-opened-file')
157
Zachary Turnerc9814482017-10-06 17:54:27 +0000158
Zachary Turnerd4401d32017-09-18 22:26:48 +0000159def calculate_arch_features(arch_string):
160 features = []
161 for arch in arch_string.split():
162 features.append(arch.lower() + '-registered-target')
163 return features
NAKAMURA Takumi67eade62013-12-04 03:40:56 +0000164
Zachary Turnerc9814482017-10-06 17:54:27 +0000165
Zachary Turnerd4401d32017-09-18 22:26:48 +0000166llvm_config.feature_config(
Zachary Turnerc9814482017-10-06 17:54:27 +0000167 [('--assertion-mode', {'ON': 'asserts'}),
168 ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}),
169 ('--targets-built', calculate_arch_features)
170 ])
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +0000171
172if lit.util.which('xmllint'):
173 config.available_features.add('xmllint')
174
Michal Gorny638ac702017-01-25 13:11:45 +0000175if config.enable_backtrace:
Zachary Turnerc9814482017-10-06 17:54:27 +0000176 config.available_features.add('backtrace')
Pete Cooper7dc8af52015-02-10 19:53:38 +0000177
Richard Smith26a92d52019-08-26 18:18:07 +0000178if config.enable_threads:
179 config.available_features.add('thread_support')
180
Yunzhong Gao7cbc78e2016-01-27 02:18:28 +0000181# Check if we should allow outputs to console.
182run_console_tests = int(lit_config.params.get('enable_console', '0'))
183if run_console_tests != 0:
Zachary Turnerc9814482017-10-06 17:54:27 +0000184 config.available_features.add('console')
Yunzhong Gao7cbc78e2016-01-27 02:18:28 +0000185
Alexander Potapenko14f8ac02014-06-10 14:22:00 +0000186lit.util.usePlatformSdkOnDarwin(config, lit_config)
Alex Lorenz01bf58d2017-06-02 11:26:35 +0000187macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
188if macOSSDKVersion is not None:
Azharuddin Mohammed18b78bf2019-07-11 21:45:48 +0000189 config.available_features.add('macos-sdk-' + str(macOSSDKVersion))
Michal Gornydae01c32018-12-23 15:07:26 +0000190
191if os.path.exists('/etc/gentoo-release'):
192 config.available_features.add('gentoo')
Don Hinton0a290282019-06-15 20:09:54 +0000193
194if config.enable_shared:
195 config.available_features.add("enable_shared")