xref: /llvm-project/compiler-rt/test/xray/lit.cfg.py (revision f98ee40f4b5d7474fc67e82824bf6abbaedb7b1c)
18007ff1aSReid Kleckner# -*- Python -*-
28007ff1aSReid Kleckner
38007ff1aSReid Klecknerimport os
48007ff1aSReid Kleckner
58007ff1aSReid Kleckner# Setup config name.
6*f98ee40fSTobias Hietaconfig.name = "XRay" + config.name_suffix
78007ff1aSReid Kleckner
88007ff1aSReid Kleckner# Setup source root.
98007ff1aSReid Klecknerconfig.test_source_root = os.path.dirname(__file__)
108007ff1aSReid Kleckner
118007ff1aSReid Kleckner# Setup default compiler flags use with -fxray-instrument option.
12*f98ee40fSTobias Hietaclang_xray_cflags = ["-fxray-instrument", config.target_cflags]
138007ff1aSReid Kleckner
148007ff1aSReid Kleckner# If libc++ was used to build XRAY libraries, libc++ is needed. Fix applied
158007ff1aSReid Kleckner# to Linux only since -rpath may not be portable. This can be extended to
168007ff1aSReid Kleckner# other platforms.
178007ff1aSReid Klecknerif config.libcxx_used == "1" and config.host_os == "Linux":
18*f98ee40fSTobias Hieta    clang_xray_cflags = clang_xray_cflags + (
19*f98ee40fSTobias Hieta        ["-L%s -lc++ -Wl,-rpath=%s" % (config.llvm_shlib_dir, config.llvm_shlib_dir)]
20*f98ee40fSTobias Hieta    )
218007ff1aSReid Kleckner
228007ff1aSReid Klecknerclang_xray_cxxflags = config.cxx_mode_flags + clang_xray_cflags
238007ff1aSReid Kleckner
24*f98ee40fSTobias Hieta
258007ff1aSReid Klecknerdef build_invocation(compile_flags):
26*f98ee40fSTobias Hieta    return " " + " ".join([config.clang] + compile_flags) + " "
27*f98ee40fSTobias Hieta
288007ff1aSReid Kleckner
298007ff1aSReid Kleckner# Assume that llvm-xray is in the config.llvm_tools_dir.
30*f98ee40fSTobias Hietallvm_xray = os.path.join(config.llvm_tools_dir, "llvm-xray")
318007ff1aSReid Kleckner
328007ff1aSReid Kleckner# Setup substitutions.
338007ff1aSReid Klecknerif config.host_os == "Linux":
348007ff1aSReid Kleckner    libdl_flag = "-ldl"
358007ff1aSReid Klecknerelse:
368007ff1aSReid Kleckner    libdl_flag = ""
378007ff1aSReid Kleckner
38*f98ee40fSTobias Hietaconfig.substitutions.append(("%clang ", build_invocation([config.target_cflags])))
398007ff1aSReid Klecknerconfig.substitutions.append(
40*f98ee40fSTobias Hieta    ("%clangxx ", build_invocation(config.cxx_mode_flags + [config.target_cflags]))
41*f98ee40fSTobias Hieta)
42*f98ee40fSTobias Hietaconfig.substitutions.append(("%clang_xray ", build_invocation(clang_xray_cflags)))
43*f98ee40fSTobias Hietaconfig.substitutions.append(("%clangxx_xray", build_invocation(clang_xray_cxxflags)))
44*f98ee40fSTobias Hietaconfig.substitutions.append(("%llvm_xray", llvm_xray))
458007ff1aSReid Klecknerconfig.substitutions.append(
46*f98ee40fSTobias Hieta    (
47*f98ee40fSTobias Hieta        "%xraylib",
48*f98ee40fSTobias Hieta        (
49*f98ee40fSTobias Hieta            "-lm -lpthread %s -lrt -L%s "
50*f98ee40fSTobias Hieta            "-Wl,-whole-archive -lclang_rt.xray%s -Wl,-no-whole-archive"
51*f98ee40fSTobias Hieta        )
52*f98ee40fSTobias Hieta        % (libdl_flag, config.compiler_rt_libdir, config.target_suffix),
53*f98ee40fSTobias Hieta    )
54*f98ee40fSTobias Hieta)
558007ff1aSReid Kleckner
568007ff1aSReid Kleckner# Default test suffixes.
57*f98ee40fSTobias Hietaconfig.suffixes = [".c", ".cpp"]
588007ff1aSReid Kleckner
59*f98ee40fSTobias Hietaif config.host_os not in ["FreeBSD", "Linux", "NetBSD", "OpenBSD"]:
608007ff1aSReid Kleckner    config.unsupported = True
61*f98ee40fSTobias Hietaelif "64" not in config.host_arch:
62*f98ee40fSTobias Hieta    if "arm" in config.host_arch:
63*f98ee40fSTobias Hieta        if "-mthumb" in config.target_cflags:
648007ff1aSReid Kleckner            config.unsupported = True
658007ff1aSReid Kleckner    else:
668007ff1aSReid Kleckner        config.unsupported = True
67e73c662bSMichał Górny
68*f98ee40fSTobias Hietaif config.host_os == "NetBSD":
69*f98ee40fSTobias Hieta    config.substitutions.insert(0, ("%run", config.netbsd_nomprotect_prefix))
70