106 lines · python
1# -*- Python -*-2 3# Setup source root.4config.test_source_root = os.path.join(os.path.dirname(__file__), "TestCases")5 6config.name = "SanitizerCommon-" + config.name_suffix7 8default_tool_options = []9collect_stack_traces = ""10if config.tool_name == "asan":11 tool_cflags = ["-fsanitize=address"]12 tool_options = "ASAN_OPTIONS"13elif config.tool_name == "hwasan":14 tool_cflags = ["-fsanitize=hwaddress", "-fuse-ld=lld"]15 if config.target_arch == "x86_64":16 tool_cflags += ["-fsanitize-hwaddress-experimental-aliasing"]17 config.available_features.add("hwasan-aliasing")18 tool_options = "HWASAN_OPTIONS"19 if not config.has_lld:20 config.unsupported = True21elif config.tool_name == "rtsan":22 tool_cflags = ["-fsanitize=realtime"]23 tool_options = "RTSAN_OPTIONS"24elif config.tool_name == "tsan":25 tool_cflags = ["-fsanitize=thread"]26 tool_options = "TSAN_OPTIONS"27elif config.tool_name == "msan":28 tool_cflags = ["-fsanitize=memory"]29 tool_options = "MSAN_OPTIONS"30 collect_stack_traces = "-fsanitize-memory-track-origins"31elif config.tool_name == "lsan":32 tool_cflags = ["-fsanitize=leak"]33 tool_options = "LSAN_OPTIONS"34elif config.tool_name == "ubsan":35 tool_cflags = ["-fsanitize=undefined"]36 tool_options = "UBSAN_OPTIONS"37else:38 lit_config.fatal("Unknown tool for sanitizer_common tests: %r" % config.tool_name)39 40config.available_features.add(config.tool_name)41 42if (43 config.target_os == "Linux"44 and config.tool_name == "lsan"45 and config.target_arch == "i386"46):47 config.available_features.add("lsan-x86")48 49if config.arm_thumb:50 config.available_features.add("thumb")51 52if config.target_os == "Darwin":53 # On Darwin, we default to `abort_on_error=1`, which would make tests run54 # much slower. Let's override this and run lit tests with 'abort_on_error=0'.55 default_tool_options += ["abort_on_error=0"]56 if config.tool_name == "tsan":57 default_tool_options += ["ignore_interceptors_accesses=0"]58elif config.android:59 # The same as on Darwin, we default to "abort_on_error=1" which slows down60 # testing. Also, all existing tests are using "not" instead of "not --crash"61 # which does not work for abort()-terminated programs.62 default_tool_options += ["abort_on_error=0"]63 64default_tool_options_str = ":".join(default_tool_options)65if default_tool_options_str:66 config.environment[tool_options] = default_tool_options_str67 default_tool_options_str += ":"68 69extra_link_flags = []70 71if config.target_os in ["Linux"]:72 extra_link_flags += ["-ldl"]73 74clang_cflags = config.debug_info_flags + tool_cflags + [config.target_cflags]75clang_cflags += ["-I%s" % os.path.dirname(os.path.dirname(__file__))]76clang_cflags += extra_link_flags77clang_cxxflags = config.cxx_mode_flags + clang_cflags78 79 80def build_invocation(compile_flags):81 return " " + " ".join([config.clang] + compile_flags) + " "82 83 84config.substitutions.append(("%clang ", build_invocation(clang_cflags)))85config.substitutions.append(("%clangxx ", build_invocation(clang_cxxflags)))86config.substitutions.append(("%collect_stack_traces", collect_stack_traces))87config.substitutions.append(("%tool_name", config.tool_name))88config.substitutions.append(("%tool_options", tool_options))89config.substitutions.append(90 ("%env_tool_opts=", "%env " + tool_options + "=" + default_tool_options_str)91)92 93config.suffixes = [".c", ".cpp"]94 95if config.target_os not in ["Linux", "Darwin", "NetBSD", "FreeBSD", "SunOS"]:96 config.unsupported = True97 98if not config.parallelism_group:99 config.parallelism_group = "shadow-memory"100 101if config.target_os == "NetBSD":102 config.substitutions.insert(0, ("%run", config.netbsd_noaslr_prefix))103 104if os.path.exists("/etc/services"):105 config.available_features.add("netbase")106