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 = 'UndefinedBehaviorSanitizer-Standalone' 21 clang_ubsan_cflags = [] 22 elif ubsan_lit_test_mode == "AddressSanitizer": 23 config.name = 'UndefinedBehaviorSanitizer-AddressSanitizer' 24 clang_ubsan_cflags = ["-fsanitize=address"] 25 else: 26 lit_config.fatal("Unknown UBSan test mode: %r" % ubsan_lit_test_mode) 27 28 def build_invocation(compile_flags): 29 return " " + " ".join([config.clang] + compile_flags) + " " 30 31 target_cflags = [get_required_attr(config, "target_cflags")] 32 clang_ubsan_cflags += target_cflags 33 clang_ubsan_cxxflags = config.cxx_mode_flags + clang_ubsan_cflags 34 35 # Define %clang and %clangxx substitutions to use in test RUN lines. 36 config.substitutions.append( ("%clang ", build_invocation(clang_ubsan_cflags)) ) 37 config.substitutions.append( ("%clangxx ", build_invocation(clang_ubsan_cxxflags)) ) 38 39 # Default test suffixes. 40 config.suffixes = ['.c', '.cc', '.cpp'] 41 42 # UndefinedBehaviorSanitizer tests are currently supported on 43 # Linux and Darwin only. 44 if config.host_os not in ['Linux', 'Darwin']: 45 config.unsupported = True 46 47 config.pipefail = False 48