xref: /llvm-project/compiler-rt/test/gwp_asan/lit.cfg.py (revision f98ee40f4b5d7474fc67e82824bf6abbaedb7b1c)
18007ff1aSReid Kleckner# -*- Python -*-
28007ff1aSReid Kleckner
38007ff1aSReid Klecknerimport os
48007ff1aSReid Kleckner
58007ff1aSReid Kleckner# Setup config name.
6*f98ee40fSTobias Hietaconfig.name = "GWP-ASan" + config.name_suffix
78007ff1aSReid Kleckner
88007ff1aSReid Kleckner# Setup source root.
98007ff1aSReid Klecknerconfig.test_source_root = os.path.dirname(__file__)
108007ff1aSReid Kleckner
118007ff1aSReid Kleckner# Test suffixes.
12*f98ee40fSTobias Hietaconfig.suffixes = [".c", ".cpp", ".test"]
138007ff1aSReid Kleckner
148007ff1aSReid Kleckner# C & CXX flags.
15*f98ee40fSTobias Hietac_flags = [config.target_cflags]
168007ff1aSReid Kleckner
17*f98ee40fSTobias Hietacxx_flags = c_flags + config.cxx_mode_flags + ["-std=c++14"]
188007ff1aSReid Kleckner
19c17ac843SMitch Phillipslibscudo_standalone = os.path.join(
20*f98ee40fSTobias Hieta    config.compiler_rt_libdir, "libclang_rt.scudo_standalone%s.a" % config.target_suffix
21*f98ee40fSTobias Hieta)
22c17ac843SMitch Phillipslibscudo_standalone_cxx = os.path.join(
23c17ac843SMitch Phillips    config.compiler_rt_libdir,
24*f98ee40fSTobias Hieta    "libclang_rt.scudo_standalone_cxx%s.a" % config.target_suffix,
25*f98ee40fSTobias Hieta)
268007ff1aSReid Kleckner
27*f98ee40fSTobias Hietascudo_link_flags = [
28*f98ee40fSTobias Hieta    "-pthread",
29*f98ee40fSTobias Hieta    "-Wl,--whole-archive",
30*f98ee40fSTobias Hieta    libscudo_standalone,
31*f98ee40fSTobias Hieta    "-Wl,--no-whole-archive",
32*f98ee40fSTobias Hieta]
33*f98ee40fSTobias Hietascudo_link_cxx_flags = [
34*f98ee40fSTobias Hieta    "-Wl,--whole-archive",
35*f98ee40fSTobias Hieta    libscudo_standalone_cxx,
36*f98ee40fSTobias Hieta    "-Wl,--no-whole-archive",
37*f98ee40fSTobias Hieta]
38c17ac843SMitch Phillips
39c17ac843SMitch Phillips# -rdynamic is necessary for online function symbolization.
40c17ac843SMitch Phillipsgwp_asan_flags = ["-rdynamic"] + scudo_link_flags
418007ff1aSReid Kleckner
42*f98ee40fSTobias Hieta
438007ff1aSReid Klecknerdef build_invocation(compile_flags):
448007ff1aSReid Kleckner    return " " + " ".join([config.clang] + compile_flags) + " "
458007ff1aSReid Kleckner
46*f98ee40fSTobias Hieta
478007ff1aSReid Kleckner# Add substitutions.
488007ff1aSReid Klecknerconfig.substitutions.append(("%clang ", build_invocation(c_flags)))
49c17ac843SMitch Phillipsconfig.substitutions.append(
50*f98ee40fSTobias Hieta    ("%clang_gwp_asan ", build_invocation(c_flags + gwp_asan_flags))
51*f98ee40fSTobias Hieta)
52*f98ee40fSTobias Hietaconfig.substitutions.append(
53*f98ee40fSTobias Hieta    (
54c17ac843SMitch Phillips        "%clangxx_gwp_asan ",
55*f98ee40fSTobias Hieta        build_invocation(cxx_flags + gwp_asan_flags + scudo_link_cxx_flags),
56*f98ee40fSTobias Hieta    )
57*f98ee40fSTobias Hieta)
588007ff1aSReid Kleckner
598007ff1aSReid Kleckner# Platform-specific default GWP_ASAN for lit tests. Ensure that GWP-ASan is
608007ff1aSReid Kleckner# enabled and that it samples every allocation.
61*f98ee40fSTobias Hietadefault_gwp_asan_options = "GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1"
628007ff1aSReid Kleckner
63*f98ee40fSTobias Hietaconfig.environment["SCUDO_OPTIONS"] = default_gwp_asan_options
64*f98ee40fSTobias Hietadefault_gwp_asan_options += ":"
65*f98ee40fSTobias Hietaconfig.substitutions.append(
66*f98ee40fSTobias Hieta    ("%env_scudo_options=", "env SCUDO_OPTIONS=" + default_gwp_asan_options)
67*f98ee40fSTobias Hieta)
688007ff1aSReid Kleckner
698007ff1aSReid Kleckner# GWP-ASan tests are currently supported on Linux only.
70*f98ee40fSTobias Hietaif config.host_os not in ["Linux"]:
718007ff1aSReid Kleckner    config.unsupported = True
72