1# -*- Python -*- 2 3import os 4import platform 5import re 6import subprocess 7import tempfile 8 9import lit.formats 10import lit.util 11 12from lit.llvm import llvm_config 13from lit.llvm.subst import ToolSubst 14from lit.llvm.subst import FindTool 15 16# Configuration file for the 'lit' test runner. 17 18# name: The name of this test suite. 19config.name = "BOLT" 20 21# testFormat: The test format to use to interpret tests. 22# 23# For now we require '&&' between commands, until they get globally killed and 24# the test runner updated. 25config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) 26 27# suffixes: A list of file extensions to treat as test files. 28config.suffixes = [ 29 ".c", 30 ".cpp", 31 ".cppm", 32 ".m", 33 ".mm", 34 ".cu", 35 ".ll", 36 ".cl", 37 ".s", 38 ".S", 39 ".modulemap", 40 ".test", 41 ".rs", 42] 43 44# excludes: A list of directories to exclude from the testsuite. The 'Inputs' 45# subdirectories contain auxiliary inputs for various tests in their parent 46# directories. 47config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"] 48 49# test_source_root: The root path where tests are located. 50config.test_source_root = os.path.dirname(__file__) 51 52# test_exec_root: The root path where tests should be run. 53config.test_exec_root = os.path.join(config.bolt_obj_root, "test") 54 55# checking if maxIndividualTestTime is available on the platform and sets 56# it to 60sec if so, declares lit-max-individual-test-time feature for 57# further checking by tests. 58supported, errormsg = lit_config.maxIndividualTestTimeIsSupported 59if supported: 60 config.available_features.add("lit-max-individual-test-time") 61 lit_config.maxIndividualTestTime = 60 62else: 63 lit_config.warning( 64 "Setting a timeout per test not supported. " 65 + errormsg 66 + " Some tests will be skipped." 67 ) 68 69if config.bolt_enable_runtime: 70 config.available_features.add("bolt-runtime") 71 72if config.gnu_ld: 73 config.available_features.add("gnu_ld") 74 75if lit.util.which("fuser"): 76 config.available_features.add("fuser") 77 78llvm_config.use_default_substitutions() 79 80llvm_config.config.environment["CLANG"] = config.bolt_clang 81llvm_config.use_clang() 82 83llvm_config.config.environment["LD_LLD"] = config.bolt_lld 84ld_lld = llvm_config.use_llvm_tool("ld.lld", required=True, search_env="LD_LLD") 85llvm_config.config.available_features.add("ld.lld") 86llvm_config.add_tool_substitutions([ToolSubst(r"ld\.lld", command=ld_lld)]) 87 88config.substitutions.append(("%cflags", "")) 89config.substitutions.append(("%cxxflags", "")) 90 91link_fdata_cmd = os.path.join(config.test_source_root, "link_fdata.py") 92 93tool_dirs = [config.llvm_tools_dir, config.test_source_root] 94 95llvm_bolt_args = [] 96 97if config.libbolt_rt_instr: 98 llvm_bolt_args.append(f"--runtime-instrumentation-lib={config.libbolt_rt_instr}") 99 100if config.libbolt_rt_hugify: 101 llvm_bolt_args.append(f"--runtime-hugify-lib={config.libbolt_rt_hugify}") 102 103tools = [ 104 ToolSubst("llc", unresolved="fatal"), 105 ToolSubst("llvm-dwarfdump", unresolved="fatal"), 106 ToolSubst( 107 "llvm-bolt", 108 unresolved="fatal", 109 extra_args=llvm_bolt_args, 110 ), 111 ToolSubst("llvm-boltdiff", unresolved="fatal"), 112 ToolSubst("llvm-bolt-heatmap", unresolved="fatal"), 113 ToolSubst("llvm-bolt-binary-analysis", unresolved="fatal"), 114 ToolSubst("llvm-bat-dump", unresolved="fatal"), 115 ToolSubst("perf2bolt", unresolved="fatal"), 116 ToolSubst("yaml2obj", unresolved="fatal"), 117 ToolSubst("llvm-mc", unresolved="fatal"), 118 ToolSubst("llvm-nm", unresolved="fatal"), 119 ToolSubst("llvm-objdump", unresolved="fatal"), 120 ToolSubst("llvm-objcopy", unresolved="fatal"), 121 ToolSubst("llvm-strings", unresolved="fatal"), 122 ToolSubst("llvm-strip", unresolved="fatal"), 123 ToolSubst("llvm-readelf", unresolved="fatal"), 124 ToolSubst( 125 "link_fdata", 126 command=sys.executable, 127 unresolved="fatal", 128 extra_args=[link_fdata_cmd], 129 ), 130 ToolSubst("merge-fdata", unresolved="fatal"), 131 ToolSubst("llvm-readobj", unresolved="fatal"), 132 ToolSubst("llvm-dwp", unresolved="fatal"), 133 ToolSubst("split-file", unresolved="fatal"), 134] 135llvm_config.add_tool_substitutions(tools, tool_dirs) 136 137 138def calculate_arch_features(arch_string): 139 features = [] 140 for arch in arch_string.split(): 141 features.append(arch.lower() + "-registered-target") 142 return features 143 144 145llvm_config.feature_config( 146 [ 147 ("--assertion-mode", {"ON": "asserts"}), 148 ("--cxxflags", {r"-D_GLIBCXX_DEBUG\b": "libstdcxx-safe-mode"}), 149 ("--targets-built", calculate_arch_features), 150 ] 151) 152 153config.targets = frozenset(config.targets_to_build.split(";")) 154