1*4d6fc14bSjoerg#===----------------------------------------------------------------------===## 2*4d6fc14bSjoerg# 3*4d6fc14bSjoerg# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*4d6fc14bSjoerg# See https://llvm.org/LICENSE.txt for license information. 5*4d6fc14bSjoerg# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*4d6fc14bSjoerg# 7*4d6fc14bSjoerg#===----------------------------------------------------------------------===## 8*4d6fc14bSjoerg 9*4d6fc14bSjoergfrom libcxx.test.dsl import * 10*4d6fc14bSjoergfrom libcxx.test.features import _isMSVC 11*4d6fc14bSjoerg 12*4d6fc14bSjoerg_warningFlags = [ 13*4d6fc14bSjoerg '-Werror', 14*4d6fc14bSjoerg '-Wall', 15*4d6fc14bSjoerg '-Wextra', 16*4d6fc14bSjoerg '-Wshadow', 17*4d6fc14bSjoerg '-Wundef', 18*4d6fc14bSjoerg '-Wno-unused-command-line-argument', 19*4d6fc14bSjoerg '-Wno-attributes', 20*4d6fc14bSjoerg '-Wno-pessimizing-move', 21*4d6fc14bSjoerg '-Wno-c++11-extensions', 22*4d6fc14bSjoerg '-Wno-user-defined-literals', 23*4d6fc14bSjoerg '-Wno-noexcept-type', 24*4d6fc14bSjoerg '-Wno-aligned-allocation-unavailable', 25*4d6fc14bSjoerg '-Wno-atomic-alignment', 26*4d6fc14bSjoerg 27*4d6fc14bSjoerg # GCC warns about places where we might want to add sized allocation/deallocation 28*4d6fc14bSjoerg # functions, but we know better what we're doing/testing in the test suite. 29*4d6fc14bSjoerg '-Wno-sized-deallocation', 30*4d6fc14bSjoerg 31*4d6fc14bSjoerg # These warnings should be enabled in order to support the MSVC 32*4d6fc14bSjoerg # team using the test suite; They enable the warnings below and 33*4d6fc14bSjoerg # expect the test suite to be clean. 34*4d6fc14bSjoerg '-Wsign-compare', 35*4d6fc14bSjoerg '-Wunused-variable', 36*4d6fc14bSjoerg '-Wunused-parameter', 37*4d6fc14bSjoerg '-Wunreachable-code', 38*4d6fc14bSjoerg '-Wno-unused-local-typedef', 39*4d6fc14bSjoerg] 40*4d6fc14bSjoerg 41*4d6fc14bSjoerg_allStandards = ['c++03', 'c++11', 'c++14', 'c++17', 'c++20', 'c++2b'] 42*4d6fc14bSjoergdef getStdFlag(cfg, std): 43*4d6fc14bSjoerg fallbacks = { 44*4d6fc14bSjoerg 'c++11': 'c++0x', 45*4d6fc14bSjoerg 'c++14': 'c++1y', 46*4d6fc14bSjoerg 'c++17': 'c++1z', 47*4d6fc14bSjoerg 'c++20': 'c++2a', 48*4d6fc14bSjoerg } 49*4d6fc14bSjoerg if hasCompileFlag(cfg, '-std='+std): 50*4d6fc14bSjoerg return '-std='+std 51*4d6fc14bSjoerg if std in fallbacks and hasCompileFlag(cfg, '-std='+fallbacks[std]): 52*4d6fc14bSjoerg return '-std='+fallbacks[std] 53*4d6fc14bSjoerg return None 54*4d6fc14bSjoerg 55*4d6fc14bSjoergDEFAULT_PARAMETERS = [ 56*4d6fc14bSjoerg # Core parameters of the test suite 57*4d6fc14bSjoerg Parameter(name='target_triple', type=str, default=getHostTriple, 58*4d6fc14bSjoerg help="The target triple to compile the test suite for. This must be " 59*4d6fc14bSjoerg "compatible with the target that the tests will be run on.", 60*4d6fc14bSjoerg actions=lambda triple: filter(None, [ 61*4d6fc14bSjoerg AddFeature(triple), 62*4d6fc14bSjoerg AddFlagIfSupported('--target={}'.format(triple)), 63*4d6fc14bSjoerg AddFeature('linux-gnu') if re.match(r'^.*-linux-gnu', triple) else None, 64*4d6fc14bSjoerg AddFeature('x86_64-linux') if re.match(r'^x86_64.*-linux', triple) else None, 65*4d6fc14bSjoerg AddFeature('x86_64-apple') if re.match(r'^x86_64.*-apple', triple) else None, 66*4d6fc14bSjoerg AddFeature('target-x86') if re.match(r'^i.86.*', triple) else None, 67*4d6fc14bSjoerg AddFeature('target-x86_64') if re.match(r'^x86_64.*', triple) else None, 68*4d6fc14bSjoerg AddFeature('target-aarch64') if re.match(r'^aarch64.*', triple) else None, 69*4d6fc14bSjoerg AddFeature('target-arm') if re.match(r'^arm.*', triple) else None, 70*4d6fc14bSjoerg ])), 71*4d6fc14bSjoerg 72*4d6fc14bSjoerg Parameter(name='std', choices=_allStandards, type=str, 73*4d6fc14bSjoerg help="The version of the standard to compile the test suite with.", 74*4d6fc14bSjoerg default=lambda cfg: next(s for s in reversed(_allStandards) if getStdFlag(cfg, s)), 75*4d6fc14bSjoerg actions=lambda std: [ 76*4d6fc14bSjoerg AddFeature(std), 77*4d6fc14bSjoerg AddCompileFlag(lambda cfg: getStdFlag(cfg, std)), 78*4d6fc14bSjoerg ]), 79*4d6fc14bSjoerg 80*4d6fc14bSjoerg Parameter(name='enable_exceptions', choices=[True, False], type=bool, default=True, 81*4d6fc14bSjoerg help="Whether to enable exceptions when compiling the test suite.", 82*4d6fc14bSjoerg actions=lambda exceptions: [] if exceptions else [ 83*4d6fc14bSjoerg AddFeature('no-exceptions'), 84*4d6fc14bSjoerg AddCompileFlag('-fno-exceptions') 85*4d6fc14bSjoerg ]), 86*4d6fc14bSjoerg 87*4d6fc14bSjoerg Parameter(name='enable_rtti', choices=[True, False], type=bool, default=True, 88*4d6fc14bSjoerg help="Whether to enable RTTI when compiling the test suite.", 89*4d6fc14bSjoerg actions=lambda rtti: [] if rtti else [ 90*4d6fc14bSjoerg AddFeature('no-rtti'), 91*4d6fc14bSjoerg AddCompileFlag('-fno-rtti') 92*4d6fc14bSjoerg ]), 93*4d6fc14bSjoerg 94*4d6fc14bSjoerg Parameter(name='stdlib', choices=['libc++', 'libstdc++', 'msvc'], type=str, default='libc++', 95*4d6fc14bSjoerg help="The C++ Standard Library implementation being tested.", 96*4d6fc14bSjoerg actions=lambda stdlib: [ 97*4d6fc14bSjoerg AddFeature(stdlib) 98*4d6fc14bSjoerg ]), 99*4d6fc14bSjoerg 100*4d6fc14bSjoerg Parameter(name='enable_warnings', choices=[True, False], type=bool, default=True, 101*4d6fc14bSjoerg help="Whether to enable warnings when compiling the test suite.", 102*4d6fc14bSjoerg actions=lambda warnings: [] if not warnings else [ 103*4d6fc14bSjoerg AddOptionalWarningFlag(w) for w in _warningFlags 104*4d6fc14bSjoerg ]), 105*4d6fc14bSjoerg 106*4d6fc14bSjoerg Parameter(name='debug_level', choices=['', '0', '1'], type=str, default='', 107*4d6fc14bSjoerg help="The debugging level to enable in the test suite.", 108*4d6fc14bSjoerg actions=lambda debugLevel: [] if debugLevel == '' else [ 109*4d6fc14bSjoerg AddFeature('debug_level={}'.format(debugLevel)), 110*4d6fc14bSjoerg AddCompileFlag('-D_LIBCPP_DEBUG={}'.format(debugLevel)) 111*4d6fc14bSjoerg ]), 112*4d6fc14bSjoerg 113*4d6fc14bSjoerg Parameter(name='use_sanitizer', choices=['', 'Address', 'Undefined', 'Memory', 'MemoryWithOrigins', 'Thread', 'DataFlow', 'Leaks'], type=str, default='', 114*4d6fc14bSjoerg help="An optional sanitizer to enable when building and running the test suite.", 115*4d6fc14bSjoerg actions=lambda sanitizer: filter(None, [ 116*4d6fc14bSjoerg AddFlag('-g -fno-omit-frame-pointer') if sanitizer else None, 117*4d6fc14bSjoerg 118*4d6fc14bSjoerg AddFlag('-fsanitize=undefined -fno-sanitize=float-divide-by-zero -fno-sanitize-recover=all') if sanitizer == 'Undefined' else None, 119*4d6fc14bSjoerg AddFeature('ubsan') if sanitizer == 'Undefined' else None, 120*4d6fc14bSjoerg 121*4d6fc14bSjoerg AddFlag('-fsanitize=address') if sanitizer == 'Address' else None, 122*4d6fc14bSjoerg AddFeature('asan') if sanitizer == 'Address' else None, 123*4d6fc14bSjoerg 124*4d6fc14bSjoerg AddFlag('-fsanitize=memory') if sanitizer in ['Memory', 'MemoryWithOrigins'] else None, 125*4d6fc14bSjoerg AddFeature('msan') if sanitizer in ['Memory', 'MemoryWithOrigins'] else None, 126*4d6fc14bSjoerg AddFlag('-fsanitize-memory-track-origins') if sanitizer == 'MemoryWithOrigins' else None, 127*4d6fc14bSjoerg 128*4d6fc14bSjoerg AddFlag('-fsanitize=thread') if sanitizer == 'Thread' else None, 129*4d6fc14bSjoerg AddFeature('tsan') if sanitizer == 'Thread' else None, 130*4d6fc14bSjoerg 131*4d6fc14bSjoerg AddFlag('-fsanitize=dataflow') if sanitizer == 'DataFlow' else None, 132*4d6fc14bSjoerg AddFlag('-fsanitize=leaks') if sanitizer == 'Leaks' else None, 133*4d6fc14bSjoerg 134*4d6fc14bSjoerg AddFeature('sanitizer-new-delete') if sanitizer in ['Address', 'Memory', 'MemoryWithOrigins', 'Thread'] else None, 135*4d6fc14bSjoerg ])), 136*4d6fc14bSjoerg 137*4d6fc14bSjoerg # Parameters to enable or disable parts of the test suite 138*4d6fc14bSjoerg Parameter(name='enable_experimental', choices=[True, False], type=bool, default=False, 139*4d6fc14bSjoerg help="Whether to enable tests for experimental C++ libraries (typically Library Fundamentals TSes).", 140*4d6fc14bSjoerg actions=lambda experimental: [] if not experimental else [ 141*4d6fc14bSjoerg AddFeature('c++experimental'), 142*4d6fc14bSjoerg # When linking in MSVC mode via the Clang driver, a -l<foo> 143*4d6fc14bSjoerg # maps to <foo>.lib, so we need to use -llibc++experimental here 144*4d6fc14bSjoerg # to make it link against the static libc++experimental.lib. 145*4d6fc14bSjoerg # We can't check for the feature 'msvc' in available_features 146*4d6fc14bSjoerg # as those features are added after processing parameters. 147*4d6fc14bSjoerg PrependLinkFlag(lambda config: '-llibc++experimental' if _isMSVC(config) else '-lc++experimental') 148*4d6fc14bSjoerg ]), 149*4d6fc14bSjoerg 150*4d6fc14bSjoerg Parameter(name='long_tests', choices=[True, False], type=bool, default=True, 151*4d6fc14bSjoerg help="Whether to enable tests that take longer to run. This can be useful when running on a very slow device.", 152*4d6fc14bSjoerg actions=lambda enabled: [] if not enabled else [ 153*4d6fc14bSjoerg AddFeature('long_tests') 154*4d6fc14bSjoerg ]), 155*4d6fc14bSjoerg 156*4d6fc14bSjoerg Parameter(name='enable_debug_tests', choices=[True, False], type=bool, default=True, 157*4d6fc14bSjoerg help="Whether to enable tests that exercise the libc++ debugging mode.", 158*4d6fc14bSjoerg actions=lambda enabled: [] if enabled else [ 159*4d6fc14bSjoerg AddFeature('libcxx-no-debug-mode') 160*4d6fc14bSjoerg ]), 161*4d6fc14bSjoerg] 162*4d6fc14bSjoerg 163*4d6fc14bSjoergDEFAULT_PARAMETERS += [ 164*4d6fc14bSjoerg Parameter(name='use_system_cxx_lib', choices=[True, False], type=bool, default=False, 165*4d6fc14bSjoerg help=""" 166*4d6fc14bSjoerg Whether the test suite is being *run* against the library shipped on the 167*4d6fc14bSjoerg target triple in use, as opposed to the trunk library. 168*4d6fc14bSjoerg 169*4d6fc14bSjoerg When vendor-specific availability annotations are enabled, we add the 170*4d6fc14bSjoerg 'use_system_cxx_lib' Lit feature to allow writing XFAIL or UNSUPPORTED 171*4d6fc14bSjoerg markup for tests that are known to fail on a particular triple. 172*4d6fc14bSjoerg 173*4d6fc14bSjoerg That feature can be used to XFAIL a test that fails when deployed on (or is 174*4d6fc14bSjoerg compiled for) an older system. For example, if the test exhibits a bug in the 175*4d6fc14bSjoerg libc on a particular system version, or if the test uses a symbol that is not 176*4d6fc14bSjoerg available on an older version of the dylib, it can be marked as XFAIL with 177*4d6fc14bSjoerg the above feature. 178*4d6fc14bSjoerg 179*4d6fc14bSjoerg It is sometimes useful to check that a test fails specifically when compiled 180*4d6fc14bSjoerg for a given deployment target. For example, this is the case when testing 181*4d6fc14bSjoerg availability markup, where we want to make sure that using the annotated 182*4d6fc14bSjoerg facility on a deployment target that doesn't support it will fail at compile 183*4d6fc14bSjoerg time, not at runtime. This can be achieved by creating a `.compile.pass.cpp` 184*4d6fc14bSjoerg and XFAILing it for the right deployment target. If the test doesn't fail at 185*4d6fc14bSjoerg compile-time like it's supposed to, the test will XPASS. Another option is to 186*4d6fc14bSjoerg create a `.verify.cpp` test that checks for the right errors, and mark that 187*4d6fc14bSjoerg test as requiring `use_system_cxx_lib && <target>`. 188*4d6fc14bSjoerg """, 189*4d6fc14bSjoerg actions=lambda useSystem: [ 190*4d6fc14bSjoerg AddFeature('use_system_cxx_lib') 191*4d6fc14bSjoerg ] if useSystem else [ 192*4d6fc14bSjoerg # If we're testing upstream libc++, disable availability markup, 193*4d6fc14bSjoerg # which is not relevant for non-shipped flavors of libc++. 194*4d6fc14bSjoerg AddCompileFlag('-D_LIBCPP_DISABLE_AVAILABILITY') 195*4d6fc14bSjoerg ]) 196*4d6fc14bSjoerg] 197