Home | History | Annotate | Download | only in ubsan
      1 # -*- Python -*-
      2 
      3 import os
      4 
      5 def get_required_attr(config, attr_name):
      6   attr_value = getattr(config, attr_name, None)
      7   if attr_value == None:
      8     lit_config.fatal(
      9       "No attribute %r in test configuration! You may need to run "
     10       "tests from your build directory or add this attribute "
     11       "to lit.site.cfg " % attr_name)
     12   return attr_value
     13 
     14 # Setup source root.
     15 config.test_source_root = os.path.dirname(__file__)
     16 
     17 # Choose between standalone and UBSan+ASan modes.
     18 ubsan_lit_test_mode = get_required_attr(config, 'ubsan_lit_test_mode')
     19 if ubsan_lit_test_mode == "Standalone":
     20   config.name = 'UBSan-Standalone-' + config.target_arch
     21   config.available_features.add("ubsan-standalone")
     22   clang_ubsan_cflags = []
     23 elif ubsan_lit_test_mode == "AddressSanitizer":
     24   if config.host_os == 'Darwin':
     25     # ubsan-asan doesn't yet work on Darwin,
     26     # see http://llvm.org/bugs/show_bug.cgi?id=21112.
     27     config.unsupported = True
     28   config.name = 'UBSan-ASan-' + config.target_arch
     29   config.available_features.add("ubsan-asan")
     30   clang_ubsan_cflags = ["-fsanitize=address"]
     31   config.environment['ASAN_OPTIONS'] = 'detect_leaks=0'
     32 else:
     33   lit_config.fatal("Unknown UBSan test mode: %r" % ubsan_lit_test_mode)
     34 
     35 def build_invocation(compile_flags):
     36   return " " + " ".join([config.clang] + compile_flags) + " "
     37 
     38 target_cflags = [get_required_attr(config, "target_cflags")]
     39 clang_ubsan_cflags += target_cflags
     40 clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags
     41 
     42 # Define %clang and %clangxx substitutions to use in test RUN lines.
     43 config.substitutions.append( ("%clang ", build_invocation(clang_ubsan_cflags)) )
     44 config.substitutions.append( ("%clangxx ", build_invocation(clang_ubsan_cxxflags)) )
     45 
     46 # Default test suffixes.
     47 config.suffixes = ['.c', '.cc', '.cpp']
     48 
     49 # Check that the host supports UndefinedBehaviorSanitizer tests
     50 if config.host_os not in ['Linux', 'Darwin', 'FreeBSD']:
     51   config.unsupported = True
     52 
     53 # Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL
     54 # because the test hangs or fails on one configuration and not the other.
     55 if config.target_arch.startswith('arm') == False:
     56   config.available_features.add('stable-runtime')
     57