xref: /llvm-project/compiler-rt/test/memprof/lit.cfg.py (revision 0af6c304e48e0484672b53be49a15f411d173e59)
13d4bba30STeresa Johnson# -*- Python -*-
23d4bba30STeresa Johnson
33d4bba30STeresa Johnsonimport os
43d4bba30STeresa Johnsonimport platform
53d4bba30STeresa Johnsonimport re
63d4bba30STeresa Johnson
73d4bba30STeresa Johnsonimport lit.formats
83d4bba30STeresa Johnson
9f98ee40fSTobias Hieta
103d4bba30STeresa Johnsondef get_required_attr(config, attr_name):
113d4bba30STeresa Johnson    attr_value = getattr(config, attr_name, None)
12*0af6c304SEisuke Kawashima    if attr_value is None:
133d4bba30STeresa Johnson        lit_config.fatal(
143d4bba30STeresa Johnson            "No attribute %r in test configuration! You may need to run "
153d4bba30STeresa Johnson            "tests from your build directory or add this attribute "
16f98ee40fSTobias Hieta            "to lit.site.cfg.py " % attr_name
17f98ee40fSTobias Hieta        )
183d4bba30STeresa Johnson    return attr_value
193d4bba30STeresa Johnson
20f98ee40fSTobias Hieta
213d4bba30STeresa Johnson# Setup config name.
22f98ee40fSTobias Hietaconfig.name = "MemProfiler" + config.name_suffix
233d4bba30STeresa Johnson
243d4bba30STeresa Johnson# Platform-specific default MEMPROF_OPTIONS for lit tests.
253d4bba30STeresa Johnsondefault_memprof_opts = list(config.default_sanitizer_opts)
263d4bba30STeresa Johnson
27f98ee40fSTobias Hietadefault_memprof_opts_str = ":".join(default_memprof_opts)
283d4bba30STeresa Johnsonif default_memprof_opts_str:
29f98ee40fSTobias Hieta    config.environment["MEMPROF_OPTIONS"] = default_memprof_opts_str
30f98ee40fSTobias Hieta    default_memprof_opts_str += ":"
31f98ee40fSTobias Hietaconfig.substitutions.append(
32f98ee40fSTobias Hieta    ("%env_memprof_opts=", "env MEMPROF_OPTIONS=" + default_memprof_opts_str)
33f98ee40fSTobias Hieta)
343d4bba30STeresa Johnson
353d4bba30STeresa Johnson# Setup source root.
363d4bba30STeresa Johnsonconfig.test_source_root = os.path.dirname(__file__)
373d4bba30STeresa Johnson
38f98ee40fSTobias Hietalibdl_flag = "-ldl"
393d4bba30STeresa Johnson
403d4bba30STeresa Johnson# Setup default compiler flags used with -fmemory-profile option.
413d4bba30STeresa Johnson# FIXME: Review the set of required flags and check if it can be reduced.
42f98ee40fSTobias Hietatarget_cflags = [get_required_attr(config, "target_cflags")]
433d4bba30STeresa Johnsontarget_cxxflags = config.cxx_mode_flags + target_cflags
44f98ee40fSTobias Hietaclang_memprof_static_cflags = (
45f98ee40fSTobias Hieta    [
46f98ee40fSTobias Hieta        "-fmemory-profile",
47f98ee40fSTobias Hieta        "-mno-omit-leaf-frame-pointer",
48f98ee40fSTobias Hieta        "-fno-omit-frame-pointer",
49f98ee40fSTobias Hieta        "-fno-optimize-sibling-calls",
50f98ee40fSTobias Hieta    ]
51f98ee40fSTobias Hieta    + config.debug_info_flags
52f98ee40fSTobias Hieta    + target_cflags
53f98ee40fSTobias Hieta)
543d4bba30STeresa Johnsonclang_memprof_static_cxxflags = config.cxx_mode_flags + clang_memprof_static_cflags
553d4bba30STeresa Johnson
563d4bba30STeresa Johnsonmemprof_dynamic_flags = []
573d4bba30STeresa Johnsonif config.memprof_dynamic:
58f98ee40fSTobias Hieta    memprof_dynamic_flags = ["-shared-libsan"]
59f98ee40fSTobias Hieta    config.available_features.add("memprof-dynamic-runtime")
603d4bba30STeresa Johnsonelse:
61f98ee40fSTobias Hieta    config.available_features.add("memprof-static-runtime")
623d4bba30STeresa Johnsonclang_memprof_cflags = clang_memprof_static_cflags + memprof_dynamic_flags
633d4bba30STeresa Johnsonclang_memprof_cxxflags = clang_memprof_static_cxxflags + memprof_dynamic_flags
643d4bba30STeresa Johnson
65f98ee40fSTobias Hieta
663d4bba30STeresa Johnsondef build_invocation(compile_flags):
67f98ee40fSTobias Hieta    return " " + " ".join([config.clang] + compile_flags) + " "
68f98ee40fSTobias Hieta
693d4bba30STeresa Johnson
703d4bba30STeresa Johnsonconfig.substitutions.append(("%clang ", build_invocation(target_cflags)))
713d4bba30STeresa Johnsonconfig.substitutions.append(("%clangxx ", build_invocation(target_cxxflags)))
723d4bba30STeresa Johnsonconfig.substitutions.append(("%clang_memprof ", build_invocation(clang_memprof_cflags)))
73f98ee40fSTobias Hietaconfig.substitutions.append(
74f98ee40fSTobias Hieta    ("%clangxx_memprof ", build_invocation(clang_memprof_cxxflags))
75f98ee40fSTobias Hieta)
763d4bba30STeresa Johnsonif config.memprof_dynamic:
77f98ee40fSTobias Hieta    shared_libmemprof_path = os.path.join(
78f98ee40fSTobias Hieta        config.compiler_rt_libdir,
79f98ee40fSTobias Hieta        "libclang_rt.memprof{}.so".format(config.target_suffix),
80f98ee40fSTobias Hieta    )
813d4bba30STeresa Johnson    config.substitutions.append(("%shared_libmemprof", shared_libmemprof_path))
82f98ee40fSTobias Hieta    config.substitutions.append(
83f98ee40fSTobias Hieta        ("%clang_memprof_static ", build_invocation(clang_memprof_static_cflags))
84f98ee40fSTobias Hieta    )
85f98ee40fSTobias Hieta    config.substitutions.append(
86f98ee40fSTobias Hieta        ("%clangxx_memprof_static ", build_invocation(clang_memprof_static_cxxflags))
87f98ee40fSTobias Hieta    )
883d4bba30STeresa Johnson
893d4bba30STeresa Johnsonconfig.substitutions.append(("%libdl", libdl_flag))
903d4bba30STeresa Johnson
91f98ee40fSTobias Hietaconfig.available_features.add("memprof-" + config.bits + "-bits")
923d4bba30STeresa Johnson
93f98ee40fSTobias Hietaconfig.available_features.add("fast-unwinder-works")
943d4bba30STeresa Johnson
953d4bba30STeresa Johnson# Set LD_LIBRARY_PATH to pick dynamic runtime up properly.
963d4bba30STeresa Johnsonnew_ld_library_path = os.path.pathsep.join(
97f98ee40fSTobias Hieta    (config.compiler_rt_libdir, config.environment.get("LD_LIBRARY_PATH", ""))
98f98ee40fSTobias Hieta)
99f98ee40fSTobias Hietaconfig.environment["LD_LIBRARY_PATH"] = new_ld_library_path
1003d4bba30STeresa Johnson
1013d4bba30STeresa Johnson# Default test suffixes.
102f98ee40fSTobias Hietaconfig.suffixes = [".c", ".cpp"]
1033d4bba30STeresa Johnson
104f98ee40fSTobias Hietaconfig.substitutions.append(("%fPIC", "-fPIC"))
105f98ee40fSTobias Hietaconfig.substitutions.append(("%fPIE", "-fPIE"))
106f98ee40fSTobias Hietaconfig.substitutions.append(("%pie", "-pie"))
1073d4bba30STeresa Johnson
1083d4bba30STeresa Johnson# Only run the tests on supported OSs.
109f98ee40fSTobias Hietaif config.host_os not in ["Linux"]:
1103d4bba30STeresa Johnson    config.unsupported = True
1113d4bba30STeresa Johnson
1123d4bba30STeresa Johnsonif not config.parallelism_group:
113f98ee40fSTobias Hieta    config.parallelism_group = "shadow-memory"
114