• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- Python -*-
2
3import os
4import platform
5import re
6
7import lit.formats
8
9# Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if
10# it's not available.
11try:
12  import shlex
13  sh_quote = shlex.quote
14except:
15  import pipes
16  sh_quote = pipes.quote
17
18def get_required_attr(config, attr_name):
19  attr_value = getattr(config, attr_name, None)
20  if attr_value == None:
21    lit_config.fatal(
22      "No attribute %r in test configuration! You may need to run "
23      "tests from your build directory or add this attribute "
24      "to lit.site.cfg.py " % attr_name)
25  return attr_value
26
27# Setup config name.
28config.name = 'MemProfiler' + config.name_suffix
29
30# Platform-specific default MEMPROF_OPTIONS for lit tests.
31default_memprof_opts = list(config.default_sanitizer_opts)
32
33default_memprof_opts_str = ':'.join(default_memprof_opts)
34if default_memprof_opts_str:
35  config.environment['MEMPROF_OPTIONS'] = default_memprof_opts_str
36config.substitutions.append(('%env_memprof_opts=',
37                             'env MEMPROF_OPTIONS=' + default_memprof_opts_str))
38
39# Setup source root.
40config.test_source_root = os.path.dirname(__file__)
41
42libdl_flag = '-ldl'
43
44# Setup default compiler flags used with -fmemory-profile option.
45# FIXME: Review the set of required flags and check if it can be reduced.
46target_cflags = [get_required_attr(config, 'target_cflags')]
47target_cxxflags = config.cxx_mode_flags + target_cflags
48clang_memprof_static_cflags = (['-fmemory-profile',
49                            '-mno-omit-leaf-frame-pointer',
50                            '-fno-omit-frame-pointer',
51                            '-fno-optimize-sibling-calls'] +
52                            config.debug_info_flags + target_cflags)
53clang_memprof_static_cxxflags = config.cxx_mode_flags + clang_memprof_static_cflags
54
55memprof_dynamic_flags = []
56if config.memprof_dynamic:
57  memprof_dynamic_flags = ['-shared-libsan']
58  config.available_features.add('memprof-dynamic-runtime')
59else:
60  config.available_features.add('memprof-static-runtime')
61clang_memprof_cflags = clang_memprof_static_cflags + memprof_dynamic_flags
62clang_memprof_cxxflags = clang_memprof_static_cxxflags + memprof_dynamic_flags
63
64def build_invocation(compile_flags):
65  return ' ' + ' '.join([config.clang] + compile_flags) + ' '
66
67config.substitutions.append( ("%clang ", build_invocation(target_cflags)) )
68config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) )
69config.substitutions.append( ("%clang_memprof ", build_invocation(clang_memprof_cflags)) )
70config.substitutions.append( ("%clangxx_memprof ", build_invocation(clang_memprof_cxxflags)) )
71if config.memprof_dynamic:
72  shared_libmemprof_path = os.path.join(config.compiler_rt_libdir, 'libclang_rt.memprof{}.so'.format(config.target_suffix))
73  config.substitutions.append( ("%shared_libmemprof", shared_libmemprof_path) )
74  config.substitutions.append( ("%clang_memprof_static ", build_invocation(clang_memprof_static_cflags)) )
75  config.substitutions.append( ("%clangxx_memprof_static ", build_invocation(clang_memprof_static_cxxflags)) )
76
77# Some tests uses C++11 features such as lambdas and need to pass -std=c++11.
78config.substitutions.append(("%stdcxx11 ", '-std=c++11 '))
79
80config.substitutions.append( ("%libdl", libdl_flag) )
81
82config.available_features.add('memprof-' + config.bits + '-bits')
83
84config.available_features.add('fast-unwinder-works')
85
86# Set LD_LIBRARY_PATH to pick dynamic runtime up properly.
87new_ld_library_path = os.path.pathsep.join(
88  (config.compiler_rt_libdir, config.environment.get('LD_LIBRARY_PATH', '')))
89config.environment['LD_LIBRARY_PATH'] = new_ld_library_path
90
91# Default test suffixes.
92config.suffixes = ['.c', '.cpp']
93
94config.substitutions.append(('%fPIC', '-fPIC'))
95config.substitutions.append(('%fPIE', '-fPIE'))
96config.substitutions.append(('%pie', '-pie'))
97
98# Only run the tests on supported OSs.
99if config.host_os not in ['Linux']:
100  config.unsupported = True
101
102if not config.parallelism_group:
103  config.parallelism_group = 'shadow-memory'
104