xref: /llvm-project/compiler-rt/test/ubsan_minimal/lit.common.cfg.py (revision 0af6c304e48e0484672b53be49a15f411d173e59)
1# -*- Python -*-
2
3import os
4
5
6def get_required_attr(config, attr_name):
7    attr_value = getattr(config, attr_name, None)
8    if attr_value is None:
9        lit_config.fatal(
10            "No attribute %r in test configuration! You may need to run "
11            "tests from your build directory or add this attribute "
12            "to lit.site.cfg.py " % attr_name
13        )
14    return attr_value
15
16
17# Setup source root.
18config.test_source_root = os.path.dirname(__file__)
19config.name = "UBSan-Minimal-" + config.target_arch
20
21
22def build_invocation(compile_flags):
23    return " " + " ".join([config.clang] + compile_flags) + " "
24
25
26target_cflags = [get_required_attr(config, "target_cflags")]
27clang_ubsan_cflags = ["-fsanitize-minimal-runtime"] + target_cflags
28clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags
29
30# Define %clang and %clangxx substitutions to use in test RUN lines.
31config.substitutions.append(("%clang ", build_invocation(clang_ubsan_cflags)))
32config.substitutions.append(("%clangxx ", build_invocation(clang_ubsan_cxxflags)))
33
34# Default test suffixes.
35config.suffixes = [".c", ".cpp"]
36
37# Check that the host supports UndefinedBehaviorSanitizerMinimal tests
38if config.host_os not in [
39    "Linux",
40    "FreeBSD",
41    "NetBSD",
42    "Darwin",
43    "OpenBSD",
44    "SunOS",
45]:  # TODO: Windows
46    config.unsupported = True
47
48# Don't target x86_64h if the test machine can't execute x86_64h binaries.
49if "-arch x86_64h" in target_cflags and "x86_64h" not in config.available_features:
50    config.unsupported = True
51