blob: 8467eaa82ca9f6179148aca56fbe33b389743ec2 [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.
34config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
35
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 = [
60 'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'opt',
Zachary Turner8eb70052017-10-17 23:43:36 +000061 ToolSubst('%clang_func_map', command=FindTool(
62 'clang-func-mapping'), unresolved='ignore'),
63]
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000064
Don Hintonf55db9ca2017-12-12 16:48:35 +000065# FIXME: This logic can be removed once all buildbots have moved
66# debuginfo-test from clang/test to llvm/projects or monorepo.
67if os.path.exists(os.path.join(config.test_source_root, 'debuginfo-tests')):
68 if os.path.isfile(
69 os.path.join(config.test_source_root, 'debuginfo-tests', 'lit.cfg.py')):
70 config.excludes.append('debuginfo-tests')
71 else:
72 tools.append(ToolSubst('%test_debuginfo', command=os.path.join(
73 config.llvm_src_root, 'utils', 'test_debuginfo.pl')))
74
Zachary Turner8eb70052017-10-17 23:43:36 +000075if config.clang_examples:
76 tools.append('clang-interpreter')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000077
Zachary Turner8eb70052017-10-17 23:43:36 +000078llvm_config.add_tool_substitutions(tools, tool_dirs)
Chandler Carruthc0b1b862011-11-05 10:15:27 +000079
Alp Toker120dd1af2014-01-08 11:38:47 +000080# Plugins (loadable modules)
81# TODO: This should be supplied by Makefile or autoconf.
NAKAMURA Takumiba7d0fe2016-02-11 16:43:08 +000082if sys.platform in ['win32', 'cygwin']:
Michal Gorny638ac702017-01-25 13:11:45 +000083 has_plugins = config.enable_shared
Alp Toker120dd1af2014-01-08 11:38:47 +000084else:
85 has_plugins = True
86
87if has_plugins and config.llvm_plugin_ext:
88 config.available_features.add('plugins')
89
Daniel Dunbarb44eb0b2010-08-24 21:39:55 +000090# Set available features we allow tests to conditionalize on.
Andrew Trick3df28242011-08-26 22:46:31 +000091#
Jonas Hahnfeldfdaaca82016-09-29 07:43:08 +000092if config.clang_default_cxx_stdlib != '':
93 config.available_features.add('default-cxx-stdlib-set')
94
NAKAMURA Takumi1fb02cb2014-07-16 12:05:45 +000095# Enabled/disabled features
Michal Gorny638ac702017-01-25 13:11:45 +000096if config.clang_staticanalyzer:
Zachary Turnerc9814482017-10-06 17:54:27 +000097 config.available_features.add('staticanalyzer')
NAKAMURA Takumi1fb02cb2014-07-16 12:05:45 +000098
Dominic Chen08f943c2017-04-04 19:52:25 +000099 if config.clang_staticanalyzer_z3 == '1':
Zachary Turnerc9814482017-10-06 17:54:27 +0000100 config.available_features.add('z3')
Dominic Chen08f943c2017-04-04 19:52:25 +0000101
Andrew Trick3df28242011-08-26 22:46:31 +0000102# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
103if platform.system() not in ['FreeBSD']:
104 config.available_features.add('crash-recovery')
NAKAMURA Takumif5ea88b2011-02-28 09:41:07 +0000105
NAKAMURA Takumi6bbc9812012-09-12 10:38:03 +0000106# ANSI escape sequences in non-dumb terminal
NAKAMURA Takumib59973e2012-07-11 11:44:00 +0000107if platform.system() not in ['Windows']:
108 config.available_features.add('ansi-escape-sequences')
109
NAKAMURA Takumi0c81c712014-02-06 07:15:59 +0000110# Capability to print utf8 to the terminal.
111# Windows expects codepage, unless Wide API.
112if platform.system() not in ['Windows']:
113 config.available_features.add('utf8-capable-terminal')
114
Michal Gorny7cfe4802016-10-10 12:23:40 +0000115# Support for libgcc runtime. Used to rule out tests that require
116# clang to run with -rtlib=libgcc.
117if platform.system() not in ['Darwin', 'Fuchsia']:
118 config.available_features.add('libgcc')
119
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000120# Case-insensitive file system
Zachary Turner8eb70052017-10-17 23:43:36 +0000121
122
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000123def is_filesystem_case_insensitive():
Zachary Turnerc9814482017-10-06 17:54:27 +0000124 handle, path = tempfile.mkstemp(
125 prefix='case-test', dir=config.test_exec_root)
NAKAMURA Takumi77fcfe72013-07-01 09:51:55 +0000126 isInsensitive = os.path.exists(
127 os.path.join(
128 os.path.dirname(path),
129 os.path.basename(path).upper()
Zachary Turnerc9814482017-10-06 17:54:27 +0000130 ))
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000131 os.close(handle)
132 os.remove(path)
133 return isInsensitive
134
Zachary Turnerc9814482017-10-06 17:54:27 +0000135
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000136if is_filesystem_case_insensitive():
137 config.available_features.add('case-insensitive-filesystem')
138
Daniel Dunbar52385592012-11-15 20:06:10 +0000139# Tests that require the /dev/fd filesystem.
Zachary Turnerc9814482017-10-06 17:54:27 +0000140if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']:
Daniel Dunbar52385592012-11-15 20:06:10 +0000141 config.available_features.add('dev-fd-fs')
142
NAKAMURA Takumi08848872014-02-16 10:15:57 +0000143# Not set on native MS environment.
144if not re.match(r'.*-win32$', config.target_triple):
145 config.available_features.add('non-ms-sdk')
146
Filipe Cabecinhas18a72612015-01-30 18:25:59 +0000147# Not set on native PS4 environment.
Filipe Cabecinhas10ff1332015-02-02 23:17:54 +0000148if not re.match(r'.*-scei-ps4', config.target_triple):
Filipe Cabecinhas18a72612015-01-30 18:25:59 +0000149 config.available_features.add('non-ps4-sdk')
150
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000151# [PR8833] LLP64-incompatible tests
Yaron Kerenf6309712014-12-17 09:55:15 +0000152if not re.match(r'^x86_64.*-(win32|mingw32|windows-gnu)$', config.target_triple):
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000153 config.available_features.add('LP64')
154
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000155# [PR12920] "clang-driver" -- set if gcc driver is not used.
NAKAMURA Takumi79e40ec2015-10-20 22:36:16 +0000156if not re.match(r'.*-(cygwin)$', config.target_triple):
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000157 config.available_features.add('clang-driver')
158
NAKAMURA Takumi23c76712014-02-16 10:15:34 +0000159# [PR18856] Depends to remove opened file. On win32, a file could be removed
160# only if all handles were closed.
161if platform.system() not in ['Windows']:
162 config.available_features.add('can-remove-opened-file')
163
Zachary Turnerc9814482017-10-06 17:54:27 +0000164
Zachary Turnerd4401d32017-09-18 22:26:48 +0000165def calculate_arch_features(arch_string):
166 features = []
167 for arch in arch_string.split():
168 features.append(arch.lower() + '-registered-target')
169 return features
NAKAMURA Takumi67eade62013-12-04 03:40:56 +0000170
Zachary Turnerc9814482017-10-06 17:54:27 +0000171
Zachary Turnerd4401d32017-09-18 22:26:48 +0000172llvm_config.feature_config(
Zachary Turnerc9814482017-10-06 17:54:27 +0000173 [('--assertion-mode', {'ON': 'asserts'}),
174 ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}),
175 ('--targets-built', calculate_arch_features)
176 ])
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +0000177
178if lit.util.which('xmllint'):
179 config.available_features.add('xmllint')
180
Michal Gorny638ac702017-01-25 13:11:45 +0000181if config.enable_backtrace:
Zachary Turnerc9814482017-10-06 17:54:27 +0000182 config.available_features.add('backtrace')
Pete Cooper7dc8af52015-02-10 19:53:38 +0000183
Yunzhong Gao7cbc78e2016-01-27 02:18:28 +0000184# Check if we should allow outputs to console.
185run_console_tests = int(lit_config.params.get('enable_console', '0'))
186if run_console_tests != 0:
Zachary Turnerc9814482017-10-06 17:54:27 +0000187 config.available_features.add('console')
Yunzhong Gao7cbc78e2016-01-27 02:18:28 +0000188
Alexander Potapenko14f8ac02014-06-10 14:22:00 +0000189lit.util.usePlatformSdkOnDarwin(config, lit_config)
Alex Lorenz01bf58d2017-06-02 11:26:35 +0000190macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
191if macOSSDKVersion is not None:
192 config.available_features.add('macos-sdk-' + macOSSDKVersion)