1# -*- Python -*- 2 3# Configuration file for the 'lit' test runner. 4 5import os 6 7import lit.formats 8import lit.util 9 10# name: The name of this test suite. 11config.name = 'Clang-Unit' 12 13# suffixes: A list of file extensions to treat as test files. 14config.suffixes = [] 15 16# test_source_root: The root path where tests are located. 17# test_exec_root: The root path where tests should be run. 18clang_obj_root = getattr(config, 'clang_obj_root', None) 19if clang_obj_root is not None: 20 config.test_exec_root = os.path.join(clang_obj_root, 'unittests') 21 config.test_source_root = config.test_exec_root 22 23# testFormat: The test format to use to interpret tests. 24llvm_build_mode = getattr(config, 'llvm_build_mode', "Debug") 25config.test_format = lit.formats.GoogleTest(llvm_build_mode, 'Tests') 26 27# Propagate the temp directory. Windows requires this because it uses \Windows\ 28# if none of these are present. 29if 'TMP' in os.environ: 30 config.environment['TMP'] = os.environ['TMP'] 31if 'TEMP' in os.environ: 32 config.environment['TEMP'] = os.environ['TEMP'] 33 34# Propagate path to symbolizer for ASan/MSan. 35for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']: 36 if symbolizer in os.environ: 37 config.environment[symbolizer] = os.environ[symbolizer] 38 39### 40 41# Check that the object root is known. 42if config.test_exec_root is None: 43 # Otherwise, we haven't loaded the site specific configuration (the user is 44 # probably trying to run on a test file directly, and either the site 45 # configuration hasn't been created by the build system, or we are in an 46 # out-of-tree build situation). 47 48 # Check for 'clang_unit_site_config' user parameter, and use that if available. 49 site_cfg = lit_config.params.get('clang_unit_site_config', None) 50 if site_cfg and os.path.exists(site_cfg): 51 lit_config.load_config(config, site_cfg) 52 raise SystemExit 53 54 # Try to detect the situation where we are using an out-of-tree build by 55 # looking for 'llvm-config'. 56 # 57 # FIXME: I debated (i.e., wrote and threw away) adding logic to 58 # automagically generate the lit.site.cfg if we are in some kind of fresh 59 # build situation. This means knowing how to invoke the build system 60 # though, and I decided it was too much magic. 61 62 llvm_config = lit.util.which('llvm-config', config.environment['PATH']) 63 if not llvm_config: 64 lit_config.fatal('No site specific configuration available!') 65 66 # Get the source and object roots. 67 llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() 68 llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() 69 clang_src_root = os.path.join(llvm_src_root, "tools", "clang") 70 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang") 71 72 # Validate that we got a tree which points to here, using the standard 73 # tools/clang layout. 74 this_src_root = os.path.join(os.path.dirname(__file__),'..','..') 75 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root): 76 lit_config.fatal('No site specific configuration available!') 77 78 # Check that the site specific configuration exists. 79 site_cfg = os.path.join(clang_obj_root, 'test', 'Unit', 'lit.site.cfg') 80 if not os.path.exists(site_cfg): 81 lit_config.fatal('No site specific configuration available!') 82 83 # Okay, that worked. Notify the user of the automagic, and reconfigure. 84 lit_config.note('using out-of-tree build at %r' % clang_obj_root) 85 lit_config.load_config(config, site_cfg) 86 raise SystemExit 87 88# If necessary, point the dynamic loader at libLLVM.so. 89if config.enable_shared: 90 shlibpath = config.environment.get(config.shlibpath_var,'') 91 if shlibpath: 92 shlibpath = os.pathsep + shlibpath 93 shlibpath = config.shlibdir + shlibpath 94 config.environment[config.shlibpath_var] = shlibpath 95