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