blob: 5323cfe73550ff0bd6e992e6ac48b47ee3414425 [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 = [
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
Zachary Turner8eb70052017-10-17 23:43:36 +000065if config.clang_examples:
66 tools.append('clang-interpreter')
Daniel Dunbarb5cbf772009-09-22 05:16:02 +000067
Zachary Turner8eb70052017-10-17 23:43:36 +000068llvm_config.add_tool_substitutions(tools, tool_dirs)
Chandler Carruthc0b1b862011-11-05 10:15:27 +000069
Alp Toker120dd1af2014-01-08 11:38:47 +000070# Plugins (loadable modules)
71# TODO: This should be supplied by Makefile or autoconf.
NAKAMURA Takumiba7d0fe2016-02-11 16:43:08 +000072if sys.platform in ['win32', 'cygwin']:
Michal Gorny638ac702017-01-25 13:11:45 +000073 has_plugins = config.enable_shared
Alp Toker120dd1af2014-01-08 11:38:47 +000074else:
75 has_plugins = True
76
77if has_plugins and config.llvm_plugin_ext:
78 config.available_features.add('plugins')
79
Daniel Dunbarb44eb0b2010-08-24 21:39:55 +000080# Set available features we allow tests to conditionalize on.
Andrew Trick3df28242011-08-26 22:46:31 +000081#
Jonas Hahnfeldfdaaca82016-09-29 07:43:08 +000082if config.clang_default_cxx_stdlib != '':
83 config.available_features.add('default-cxx-stdlib-set')
84
NAKAMURA Takumi1fb02cb2014-07-16 12:05:45 +000085# Enabled/disabled features
Michal Gorny638ac702017-01-25 13:11:45 +000086if config.clang_staticanalyzer:
Zachary Turnerc9814482017-10-06 17:54:27 +000087 config.available_features.add('staticanalyzer')
NAKAMURA Takumi1fb02cb2014-07-16 12:05:45 +000088
Dominic Chen08f943c2017-04-04 19:52:25 +000089 if config.clang_staticanalyzer_z3 == '1':
Zachary Turnerc9814482017-10-06 17:54:27 +000090 config.available_features.add('z3')
Dominic Chen08f943c2017-04-04 19:52:25 +000091
Andrew Trick3df28242011-08-26 22:46:31 +000092# As of 2011.08, crash-recovery tests still do not pass on FreeBSD.
93if platform.system() not in ['FreeBSD']:
94 config.available_features.add('crash-recovery')
NAKAMURA Takumif5ea88b2011-02-28 09:41:07 +000095
NAKAMURA Takumi6bbc9812012-09-12 10:38:03 +000096# ANSI escape sequences in non-dumb terminal
NAKAMURA Takumib59973e2012-07-11 11:44:00 +000097if platform.system() not in ['Windows']:
98 config.available_features.add('ansi-escape-sequences')
99
NAKAMURA Takumi0c81c712014-02-06 07:15:59 +0000100# Capability to print utf8 to the terminal.
101# Windows expects codepage, unless Wide API.
102if platform.system() not in ['Windows']:
103 config.available_features.add('utf8-capable-terminal')
104
Michal Gorny7cfe4802016-10-10 12:23:40 +0000105# Support for libgcc runtime. Used to rule out tests that require
106# clang to run with -rtlib=libgcc.
107if platform.system() not in ['Darwin', 'Fuchsia']:
108 config.available_features.add('libgcc')
109
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000110# Case-insensitive file system
Zachary Turner8eb70052017-10-17 23:43:36 +0000111
112
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000113def is_filesystem_case_insensitive():
Zachary Turnerc9814482017-10-06 17:54:27 +0000114 handle, path = tempfile.mkstemp(
115 prefix='case-test', dir=config.test_exec_root)
NAKAMURA Takumi77fcfe72013-07-01 09:51:55 +0000116 isInsensitive = os.path.exists(
117 os.path.join(
118 os.path.dirname(path),
119 os.path.basename(path).upper()
Zachary Turnerc9814482017-10-06 17:54:27 +0000120 ))
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000121 os.close(handle)
122 os.remove(path)
123 return isInsensitive
124
Zachary Turnerc9814482017-10-06 17:54:27 +0000125
Argyrios Kyrtzidisd7c16b22012-10-31 20:59:50 +0000126if is_filesystem_case_insensitive():
127 config.available_features.add('case-insensitive-filesystem')
128
Daniel Dunbar52385592012-11-15 20:06:10 +0000129# Tests that require the /dev/fd filesystem.
Zachary Turnerc9814482017-10-06 17:54:27 +0000130if os.path.exists('/dev/fd/0') and sys.platform not in ['cygwin']:
Daniel Dunbar52385592012-11-15 20:06:10 +0000131 config.available_features.add('dev-fd-fs')
132
NAKAMURA Takumi08848872014-02-16 10:15:57 +0000133# Not set on native MS environment.
134if not re.match(r'.*-win32$', config.target_triple):
135 config.available_features.add('non-ms-sdk')
136
Filipe Cabecinhas18a72612015-01-30 18:25:59 +0000137# Not set on native PS4 environment.
Filipe Cabecinhas10ff1332015-02-02 23:17:54 +0000138if not re.match(r'.*-scei-ps4', config.target_triple):
Filipe Cabecinhas18a72612015-01-30 18:25:59 +0000139 config.available_features.add('non-ps4-sdk')
140
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000141# [PR8833] LLP64-incompatible tests
Yaron Kerenf6309712014-12-17 09:55:15 +0000142if not re.match(r'^x86_64.*-(win32|mingw32|windows-gnu)$', config.target_triple):
NAKAMURA Takumifcd16e32012-09-12 10:45:40 +0000143 config.available_features.add('LP64')
144
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000145# [PR12920] "clang-driver" -- set if gcc driver is not used.
NAKAMURA Takumi79e40ec2015-10-20 22:36:16 +0000146if not re.match(r'.*-(cygwin)$', config.target_triple):
NAKAMURA Takumi556d7132012-12-11 07:06:09 +0000147 config.available_features.add('clang-driver')
148
NAKAMURA Takumi23c76712014-02-16 10:15:34 +0000149# [PR18856] Depends to remove opened file. On win32, a file could be removed
150# only if all handles were closed.
151if platform.system() not in ['Windows']:
152 config.available_features.add('can-remove-opened-file')
153
Zachary Turnerc9814482017-10-06 17:54:27 +0000154
Zachary Turnerd4401d32017-09-18 22:26:48 +0000155def calculate_arch_features(arch_string):
156 features = []
157 for arch in arch_string.split():
158 features.append(arch.lower() + '-registered-target')
159 return features
NAKAMURA Takumi67eade62013-12-04 03:40:56 +0000160
Zachary Turnerc9814482017-10-06 17:54:27 +0000161
Zachary Turnerd4401d32017-09-18 22:26:48 +0000162llvm_config.feature_config(
Zachary Turnerc9814482017-10-06 17:54:27 +0000163 [('--assertion-mode', {'ON': 'asserts'}),
164 ('--cxxflags', {r'-D_GLIBCXX_DEBUG\b': 'libstdcxx-safe-mode'}),
165 ('--targets-built', calculate_arch_features)
166 ])
Dmitri Gribenko740c0fb2012-08-07 17:54:38 +0000167
168if lit.util.which('xmllint'):
169 config.available_features.add('xmllint')
170
Michal Gorny638ac702017-01-25 13:11:45 +0000171if config.enable_backtrace:
Zachary Turnerc9814482017-10-06 17:54:27 +0000172 config.available_features.add('backtrace')
Pete Cooper7dc8af52015-02-10 19:53:38 +0000173
Yunzhong Gao7cbc78e2016-01-27 02:18:28 +0000174# Check if we should allow outputs to console.
175run_console_tests = int(lit_config.params.get('enable_console', '0'))
176if run_console_tests != 0:
Zachary Turnerc9814482017-10-06 17:54:27 +0000177 config.available_features.add('console')
Yunzhong Gao7cbc78e2016-01-27 02:18:28 +0000178
Alexander Potapenko14f8ac02014-06-10 14:22:00 +0000179lit.util.usePlatformSdkOnDarwin(config, lit_config)
Alex Lorenz01bf58d2017-06-02 11:26:35 +0000180macOSSDKVersion = lit.util.findPlatformSdkVersionOnMacOS(config, lit_config)
181if macOSSDKVersion is not None:
182 config.available_features.add('macos-sdk-' + macOSSDKVersion)