xref: /llvm-project/compiler-rt/test/scudo/lit.cfg.py (revision f98ee40f4b5d7474fc67e82824bf6abbaedb7b1c)
1f7c5c0d8SMitch Phillips# -*- Python -*-
2f7c5c0d8SMitch Phillips
3f7c5c0d8SMitch Phillipsimport os
4f7c5c0d8SMitch Phillips
5f7c5c0d8SMitch Phillips# Setup config name.
6*f98ee40fSTobias Hietaconfig.name = "Scudo" + config.name_suffix
7f7c5c0d8SMitch Phillips
8f7c5c0d8SMitch Phillips# Setup source root.
9f7c5c0d8SMitch Phillipsconfig.test_source_root = os.path.dirname(__file__)
10f7c5c0d8SMitch Phillips
11f7c5c0d8SMitch Phillips# Path to the shared library
12*f98ee40fSTobias Hietashared_libscudo = os.path.join(
13*f98ee40fSTobias Hieta    config.compiler_rt_libdir, "libclang_rt.scudo%s.so" % config.target_suffix
14*f98ee40fSTobias Hieta)
15*f98ee40fSTobias Hietashared_minlibscudo = os.path.join(
16*f98ee40fSTobias Hieta    config.compiler_rt_libdir, "libclang_rt.scudo_minimal%s.so" % config.target_suffix
17*f98ee40fSTobias Hieta)
18f7c5c0d8SMitch Phillips
19f7c5c0d8SMitch Phillips# Test suffixes.
20*f98ee40fSTobias Hietaconfig.suffixes = [".c", ".cpp", ".test"]
21f7c5c0d8SMitch Phillips
22f7c5c0d8SMitch Phillips# C & CXX flags.
23*f98ee40fSTobias Hietac_flags = [config.target_cflags] + [
24*f98ee40fSTobias Hieta    "-pthread",
25f7c5c0d8SMitch Phillips    "-fPIE",
26f7c5c0d8SMitch Phillips    "-pie",
27f7c5c0d8SMitch Phillips    "-O0",
28f7c5c0d8SMitch Phillips    "-UNDEBUG",
29f7c5c0d8SMitch Phillips    "-ldl",
30*f98ee40fSTobias Hieta    "-Wl,--gc-sections",
31*f98ee40fSTobias Hieta]
32f7c5c0d8SMitch Phillips
33f7c5c0d8SMitch Phillips# Android doesn't want -lrt.
34f7c5c0d8SMitch Phillipsif not config.android:
35f7c5c0d8SMitch Phillips    c_flags += ["-lrt"]
36f7c5c0d8SMitch Phillips
37*f98ee40fSTobias Hietacxx_flags = c_flags + config.cxx_mode_flags + ["-std=c++11"]
38f7c5c0d8SMitch Phillips
39f7c5c0d8SMitch Phillipsscudo_flags = ["-fsanitize=scudo"]
40f7c5c0d8SMitch Phillips
41*f98ee40fSTobias Hieta
42f7c5c0d8SMitch Phillipsdef build_invocation(compile_flags):
43f7c5c0d8SMitch Phillips    return " " + " ".join([config.clang] + compile_flags) + " "
44f7c5c0d8SMitch Phillips
45*f98ee40fSTobias Hieta
46f7c5c0d8SMitch Phillips# Add substitutions.
47f7c5c0d8SMitch Phillipsconfig.substitutions.append(("%clang ", build_invocation(c_flags)))
48f7c5c0d8SMitch Phillipsconfig.substitutions.append(("%clang_scudo ", build_invocation(c_flags + scudo_flags)))
49*f98ee40fSTobias Hietaconfig.substitutions.append(
50*f98ee40fSTobias Hieta    ("%clangxx_scudo ", build_invocation(cxx_flags + scudo_flags))
51*f98ee40fSTobias Hieta)
52f7c5c0d8SMitch Phillipsconfig.substitutions.append(("%shared_libscudo", shared_libscudo))
53f7c5c0d8SMitch Phillipsconfig.substitutions.append(("%shared_minlibscudo", shared_minlibscudo))
54f7c5c0d8SMitch Phillips
55f7c5c0d8SMitch Phillips# Platform-specific default SCUDO_OPTIONS for lit tests.
56*f98ee40fSTobias Hietadefault_scudo_opts = ""
57f7c5c0d8SMitch Phillipsif config.android:
58f7c5c0d8SMitch Phillips    # Android defaults to abort_on_error=1, which doesn't work for us.
59*f98ee40fSTobias Hieta    default_scudo_opts = "abort_on_error=0"
60f7c5c0d8SMitch Phillips
61f7c5c0d8SMitch Phillips# Disable GWP-ASan for scudo internal tests.
62f7c5c0d8SMitch Phillipsif config.gwp_asan:
63*f98ee40fSTobias Hieta    config.environment["GWP_ASAN_OPTIONS"] = "Enabled=0"
64f7c5c0d8SMitch Phillips
65f7c5c0d8SMitch Phillipsif default_scudo_opts:
66*f98ee40fSTobias Hieta    config.environment["SCUDO_OPTIONS"] = default_scudo_opts
67*f98ee40fSTobias Hieta    default_scudo_opts += ":"
68*f98ee40fSTobias Hietaconfig.substitutions.append(
69*f98ee40fSTobias Hieta    ("%env_scudo_opts=", "env SCUDO_OPTIONS=" + default_scudo_opts)
70*f98ee40fSTobias Hieta)
71f7c5c0d8SMitch Phillips
72f7c5c0d8SMitch Phillips# Hardened Allocator tests are currently supported on Linux only.
73*f98ee40fSTobias Hietaif config.host_os not in ["Linux"]:
74f7c5c0d8SMitch Phillips    config.unsupported = True
75