Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
| 4 | import platform |
| 5 | import re |
| 6 | import subprocess |
| 7 | |
Daniel Dunbar | 4d0a3ef | 2013-08-09 18:49:22 | [diff] [blame] | 8 | import lit.formats |
| 9 | import lit.util |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 10 | |
Sam McCall | 69924cc | 2022-03-10 22:09:46 | [diff] [blame^] | 11 | from lit.llvm import llvm_config |
| 12 | |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 13 | # Configuration file for the 'lit' test runner. |
| 14 | |
Chandler Carruth | 074a356 | 2013-03-07 10:09:47 | [diff] [blame] | 15 | # name: The name of this test suite. |
| 16 | config.name = 'Clang Tools' |
| 17 | |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 18 | # testFormat: The test format to use to interpret tests. |
| 19 | # |
| 20 | # For now we require '&&' between commands, until they get globally killed and |
| 21 | # the test runner updated. |
Sam McCall | 69924cc | 2022-03-10 22:09:46 | [diff] [blame^] | 22 | config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 23 | |
| 24 | # suffixes: A list of file extensions to treat as test files. |
Alexander Kornienko | b816ba0 | 2016-01-08 16:37:11 | [diff] [blame] | 25 | config.suffixes = ['.c', '.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', |
Benjamin Kramer | 03016b8 | 2016-05-31 12:12:19 | [diff] [blame] | 26 | '.modularize', '.module-map-checker', '.test'] |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 27 | |
Edwin Vane | 9f7a1c1 | 2013-08-22 19:44:07 | [diff] [blame] | 28 | # Test-time dependencies located in directories called 'Inputs' are excluded |
| 29 | # from test suites; there won't be any lit tests within them. |
| 30 | config.excludes = ['Inputs'] |
| 31 | |
Chandler Carruth | 074a356 | 2013-03-07 10:09:47 | [diff] [blame] | 32 | # test_source_root: The root path where tests are located. |
| 33 | config.test_source_root = os.path.dirname(__file__) |
| 34 | |
| 35 | # test_exec_root: The root path where tests should be run. |
Zachary Turner | ce92db1 | 2017-09-15 22:10:46 | [diff] [blame] | 36 | config.test_exec_root = os.path.join(config.clang_tools_binary_dir, 'test') |
Chandler Carruth | 074a356 | 2013-03-07 10:09:47 | [diff] [blame] | 37 | |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 38 | # Clear some environment variables that might affect Clang. |
| 39 | # |
| 40 | # This first set of vars are read by Clang, but shouldn't affect tests |
| 41 | # that aren't specifically looking for these features, or are required |
| 42 | # simply to run the tests at all. |
| 43 | # |
| 44 | # FIXME: Should we have a tool that enforces this? |
| 45 | |
| 46 | # safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD', |
| 47 | # 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET', |
| 48 | # 'IOS_SIMULATOR_DEPLOYMENT_TARGET', |
| 49 | # 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS', |
| 50 | # 'VC80COMNTOOLS') |
| 51 | possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS', |
| 52 | 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH', |
| 53 | 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', |
| 54 | 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH', |
| 55 | 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING', |
| 56 | 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX', |
| 57 | 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS', |
| 58 | 'LIBCLANG_RESOURCE_USAGE', |
| 59 | 'LIBCLANG_CODE_COMPLETION_LOGGING'] |
| 60 | # Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it. |
| 61 | if platform.system() != 'Windows': |
| 62 | possibly_dangerous_env_vars.append('INCLUDE') |
| 63 | for name in possibly_dangerous_env_vars: |
| 64 | if name in config.environment: |
| 65 | del config.environment[name] |
| 66 | |
| 67 | # Tweak the PATH to include the tools dir and the scripts dir. |
Zachary Turner | ce92db1 | 2017-09-15 22:10:46 | [diff] [blame] | 68 | path = os.path.pathsep.join(( |
| 69 | config.clang_tools_dir, config.llvm_tools_dir, config.environment['PATH'])) |
| 70 | config.environment['PATH'] = path |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 71 | |
Zachary Turner | ce92db1 | 2017-09-15 22:10:46 | [diff] [blame] | 72 | path = os.path.pathsep.join((config.clang_libs_dir, config.llvm_libs_dir, |
| 73 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 74 | config.environment['LD_LIBRARY_PATH'] = path |
David Blaikie | d7086fb | 2012-09-04 22:23:37 | [diff] [blame] | 75 | |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 76 | # When running under valgrind, we mangle '-vg' onto the end of the triple so we |
| 77 | # can check it with XFAIL and XTARGET. |
Daniel Dunbar | 4d0a3ef | 2013-08-09 18:49:22 | [diff] [blame] | 78 | if lit_config.useValgrind: |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 79 | config.target_triple += '-vg' |
| 80 | |
David Carlier | 7e37bf2 | 2019-01-24 07:58:42 | [diff] [blame] | 81 | config.available_features.add('crash-recovery') |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 82 | # Set available features we allow tests to conditionalize on. |
| 83 | # |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 84 | |
Reid Kleckner | 558850a | 2015-05-20 20:33:18 | [diff] [blame] | 85 | # Exclude MSYS due to transforming '/' to 'X:/mingwroot/'. |
| 86 | if not platform.system() in ['Windows'] or not execute_external: |
| 87 | config.available_features.add('shell-preserves-root') |
| 88 | |
David Blaikie | 149bf5d | 2012-09-12 16:29:37 | [diff] [blame] | 89 | # ANSI escape sequences in non-dumb terminal |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 90 | if platform.system() not in ['Windows']: |
| 91 | config.available_features.add('ansi-escape-sequences') |
Alexander Kornienko | 47e8e72 | 2014-06-26 16:32:26 | [diff] [blame] | 92 | |
Nico Weber | 33c9dbb | 2020-09-03 23:37:29 | [diff] [blame] | 93 | if config.clang_tidy_staticanalyzer: |
Michal Gorny | a81de44 | 2017-08-29 05:58:08 | [diff] [blame] | 94 | config.available_features.add('static-analyzer') |
Stephen Kelly | a3c4206 | 2018-10-01 20:24:22 | [diff] [blame] | 95 | |
Reid Kleckner | b250a62 | 2019-06-21 18:17:04 | [diff] [blame] | 96 | # Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if |
| 97 | # it's not available. |
| 98 | try: |
| 99 | import shlex |
| 100 | sh_quote = shlex.quote |
| 101 | except: |
| 102 | import pipes |
| 103 | sh_quote = pipes.quote |
| 104 | python_exec = sh_quote(config.python_executable) |
| 105 | |
Stephen Kelly | a3c4206 | 2018-10-01 20:24:22 | [diff] [blame] | 106 | check_clang_tidy = os.path.join( |
| 107 | config.test_source_root, "clang-tidy", "check_clang_tidy.py") |
| 108 | config.substitutions.append( |
| 109 | ('%check_clang_tidy', |
Reid Kleckner | b250a62 | 2019-06-21 18:17:04 | [diff] [blame] | 110 | '%s %s' % (python_exec, check_clang_tidy)) ) |
Stephen Kelly | a3c4206 | 2018-10-01 20:24:22 | [diff] [blame] | 111 | clang_tidy_diff = os.path.join( |
| 112 | config.test_source_root, "..", "clang-tidy", "tool", "clang-tidy-diff.py") |
| 113 | config.substitutions.append( |
| 114 | ('%clang_tidy_diff', |
Reid Kleckner | b250a62 | 2019-06-21 18:17:04 | [diff] [blame] | 115 | '%s %s' % (python_exec, clang_tidy_diff)) ) |
Stephen Kelly | a3c4206 | 2018-10-01 20:24:22 | [diff] [blame] | 116 | run_clang_tidy = os.path.join( |
| 117 | config.test_source_root, "..", "clang-tidy", "tool", "run-clang-tidy.py") |
| 118 | config.substitutions.append( |
| 119 | ('%run_clang_tidy', |
Reid Kleckner | b250a62 | 2019-06-21 18:17:04 | [diff] [blame] | 120 | '%s %s' % (python_exec, run_clang_tidy)) ) |
Kirill Bobyrev | 73c201d | 2018-09-12 07:49:44 | [diff] [blame] | 121 | |
| 122 | clangd_benchmarks_dir = os.path.join(os.path.dirname(config.clang_tools_dir), |
| 123 | "tools", "clang", "tools", "extra", |
| 124 | "clangd", "benchmarks") |
| 125 | config.substitutions.append(('%clangd-benchmark-dir', |
| 126 | '%s' % (clangd_benchmarks_dir))) |
Jameson Nash | 84f137a | 2022-02-01 17:05:20 | [diff] [blame] | 127 | config.substitutions.append(('%llvmshlibdir', config.clang_libs_dir)) |
| 128 | config.substitutions.append(('%pluginext', config.llvm_plugin_ext)) |
| 129 | |
| 130 | # Plugins (loadable modules) |
| 131 | if config.has_plugins and config.llvm_plugin_ext: |
| 132 | config.available_features.add('plugins') |