10 def get_required_attr(config
, attr_name
):
11 attr_value
= getattr(config
, attr_name
, None)
12 if attr_value
== None:
14 "No attribute %r in test configuration! You may need to run "
15 "tests from your build directory or add this attribute "
16 "to lit.site.cfg.py " % attr_name
22 config
.name
= "MemProfiler" + config
.name_suffix
24 # Platform-specific default MEMPROF_OPTIONS for lit tests.
25 default_memprof_opts
= list(config
.default_sanitizer_opts
)
27 default_memprof_opts_str
= ":".join(default_memprof_opts
)
28 if default_memprof_opts_str
:
29 config
.environment
["MEMPROF_OPTIONS"] = default_memprof_opts_str
30 default_memprof_opts_str
+= ":"
31 config
.substitutions
.append(
32 ("%env_memprof_opts=", "env MEMPROF_OPTIONS=" + default_memprof_opts_str
)
36 config
.test_source_root
= os
.path
.dirname(__file__
)
40 # Setup default compiler flags used with -fmemory-profile option.
41 # FIXME: Review the set of required flags and check if it can be reduced.
42 target_cflags
= [get_required_attr(config
, "target_cflags")]
43 target_cxxflags
= config
.cxx_mode_flags
+ target_cflags
44 clang_memprof_static_cflags
= (
47 "-mno-omit-leaf-frame-pointer",
48 "-fno-omit-frame-pointer",
49 "-fno-optimize-sibling-calls",
51 + config
.debug_info_flags
54 clang_memprof_static_cxxflags
= config
.cxx_mode_flags
+ clang_memprof_static_cflags
56 memprof_dynamic_flags
= []
57 if config
.memprof_dynamic
:
58 memprof_dynamic_flags
= ["-shared-libsan"]
59 config
.available_features
.add("memprof-dynamic-runtime")
61 config
.available_features
.add("memprof-static-runtime")
62 clang_memprof_cflags
= clang_memprof_static_cflags
+ memprof_dynamic_flags
63 clang_memprof_cxxflags
= clang_memprof_static_cxxflags
+ memprof_dynamic_flags
66 def build_invocation(compile_flags
):
67 return " " + " ".join([config
.clang
] + compile_flags
) + " "
70 config
.substitutions
.append(("%clang ", build_invocation(target_cflags
)))
71 config
.substitutions
.append(("%clangxx ", build_invocation(target_cxxflags
)))
72 config
.substitutions
.append(("%clang_memprof ", build_invocation(clang_memprof_cflags
)))
73 config
.substitutions
.append(
74 ("%clangxx_memprof ", build_invocation(clang_memprof_cxxflags
))
76 if config
.memprof_dynamic
:
77 shared_libmemprof_path
= os
.path
.join(
78 config
.compiler_rt_libdir
,
79 "libclang_rt.memprof{}.so".format(config
.target_suffix
),
81 config
.substitutions
.append(("%shared_libmemprof", shared_libmemprof_path
))
82 config
.substitutions
.append(
83 ("%clang_memprof_static ", build_invocation(clang_memprof_static_cflags
))
85 config
.substitutions
.append(
86 ("%clangxx_memprof_static ", build_invocation(clang_memprof_static_cxxflags
))
89 config
.substitutions
.append(("%libdl", libdl_flag
))
91 config
.available_features
.add("memprof-" + config
.bits
+ "-bits")
93 config
.available_features
.add("fast-unwinder-works")
95 # Set LD_LIBRARY_PATH to pick dynamic runtime up properly.
96 new_ld_library_path
= os
.path
.pathsep
.join(
97 (config
.compiler_rt_libdir
, config
.environment
.get("LD_LIBRARY_PATH", ""))
99 config
.environment
["LD_LIBRARY_PATH"] = new_ld_library_path
101 # Default test suffixes.
102 config
.suffixes
= [".c", ".cpp"]
104 config
.substitutions
.append(("%fPIC", "-fPIC"))
105 config
.substitutions
.append(("%fPIE", "-fPIE"))
106 config
.substitutions
.append(("%pie", "-pie"))
108 # Only run the tests on supported OSs.
109 if config
.host_os
not in ["Linux"]:
110 config
.unsupported
= True
112 if not config
.parallelism_group
:
113 config
.parallelism_group
= "shadow-memory"