1*7c3d14c8STreehugger Robot# -*- Python -*- 2*7c3d14c8STreehugger Robot 3*7c3d14c8STreehugger Robot# Common configuration for running leak detection tests under LSan/ASan. 4*7c3d14c8STreehugger Robot 5*7c3d14c8STreehugger Robotimport os 6*7c3d14c8STreehugger Robot 7*7c3d14c8STreehugger Robotdef get_required_attr(config, attr_name): 8*7c3d14c8STreehugger Robot attr_value = getattr(config, attr_name, None) 9*7c3d14c8STreehugger Robot if attr_value == None: 10*7c3d14c8STreehugger Robot lit_config.fatal( 11*7c3d14c8STreehugger Robot "No attribute %r in test configuration! You may need to run " 12*7c3d14c8STreehugger Robot "tests from your build directory or add this attribute " 13*7c3d14c8STreehugger Robot "to lit.site.cfg " % attr_name) 14*7c3d14c8STreehugger Robot return attr_value 15*7c3d14c8STreehugger Robot 16*7c3d14c8STreehugger Robot# Setup source root. 17*7c3d14c8STreehugger Robotconfig.test_source_root = os.path.dirname(__file__) 18*7c3d14c8STreehugger Robot 19*7c3d14c8STreehugger Robot# Choose between standalone and LSan+ASan modes. 20*7c3d14c8STreehugger Robotlsan_lit_test_mode = get_required_attr(config, 'lsan_lit_test_mode') 21*7c3d14c8STreehugger Robotif lsan_lit_test_mode == "Standalone": 22*7c3d14c8STreehugger Robot config.name = "LeakSanitizer-Standalone" 23*7c3d14c8STreehugger Robot lsan_cflags = ["-fsanitize=leak"] 24*7c3d14c8STreehugger Robotelif lsan_lit_test_mode == "AddressSanitizer": 25*7c3d14c8STreehugger Robot config.name = "LeakSanitizer-AddressSanitizer" 26*7c3d14c8STreehugger Robot lsan_cflags = ["-fsanitize=address"] 27*7c3d14c8STreehugger Robot config.available_features.add('asan') 28*7c3d14c8STreehugger Robotelse: 29*7c3d14c8STreehugger Robot lit_config.fatal("Unknown LSan test mode: %r" % lsan_lit_test_mode) 30*7c3d14c8STreehugger Robotconfig.name += config.name_suffix 31*7c3d14c8STreehugger Robot 32*7c3d14c8STreehugger Robotclang_cflags = ["-O0", config.target_cflags] + config.debug_info_flags 33*7c3d14c8STreehugger Robotclang_cxxflags = config.cxx_mode_flags + clang_cflags 34*7c3d14c8STreehugger Robotclang_lsan_cflags = clang_cflags + lsan_cflags 35*7c3d14c8STreehugger Robotclang_lsan_cxxflags = clang_cxxflags + lsan_cflags 36*7c3d14c8STreehugger Robot 37*7c3d14c8STreehugger Robotconfig.clang_cflags = clang_cflags 38*7c3d14c8STreehugger Robotconfig.clang_cxxflags = clang_cxxflags 39*7c3d14c8STreehugger Robot 40*7c3d14c8STreehugger Robotdef build_invocation(compile_flags): 41*7c3d14c8STreehugger Robot return " " + " ".join([config.clang] + compile_flags) + " " 42*7c3d14c8STreehugger Robot 43*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clang ", build_invocation(clang_cflags)) ) 44*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) ) 45*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clang_lsan ", build_invocation(clang_lsan_cflags)) ) 46*7c3d14c8STreehugger Robotconfig.substitutions.append( ("%clangxx_lsan ", build_invocation(clang_lsan_cxxflags)) ) 47*7c3d14c8STreehugger Robot 48*7c3d14c8STreehugger Robot# LeakSanitizer tests are currently supported on x86-64 Linux and mips64 Linux only. 49*7c3d14c8STreehugger Robotif config.host_os not in ['Linux'] or config.host_arch not in ['x86_64', 'mips64']: 50*7c3d14c8STreehugger Robot config.unsupported = True 51*7c3d14c8STreehugger Robot 52*7c3d14c8STreehugger Robotconfig.suffixes = ['.c', '.cc', '.cpp'] 53