Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | # Configuration file for the 'lit' test runner. |
| 4 | |
| 5 | import os |
Dmitri Gribenko | 1bf8d91 | 2014-02-18 15:20:02 +0000 | [diff] [blame] | 6 | import platform |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 7 | |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 8 | import lit.formats |
| 9 | import lit.util |
| 10 | |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 11 | # name: The name of this test suite. |
| 12 | config.name = 'Clang-Unit' |
| 13 | |
| 14 | # suffixes: A list of file extensions to treat as test files. |
| 15 | config.suffixes = [] |
| 16 | |
| 17 | # test_source_root: The root path where tests are located. |
| 18 | # test_exec_root: The root path where tests should be run. |
| 19 | clang_obj_root = getattr(config, 'clang_obj_root', None) |
| 20 | if clang_obj_root is not None: |
| 21 | config.test_exec_root = os.path.join(clang_obj_root, 'unittests') |
| 22 | config.test_source_root = config.test_exec_root |
| 23 | |
| 24 | # testFormat: The test format to use to interpret tests. |
| 25 | llvm_build_mode = getattr(config, 'llvm_build_mode', "Debug") |
| 26 | config.test_format = lit.formats.GoogleTest(llvm_build_mode, 'Tests') |
| 27 | |
| 28 | # Propagate the temp directory. Windows requires this because it uses \Windows\ |
| 29 | # if none of these are present. |
| 30 | if 'TMP' in os.environ: |
| 31 | config.environment['TMP'] = os.environ['TMP'] |
| 32 | if 'TEMP' in os.environ: |
| 33 | config.environment['TEMP'] = os.environ['TEMP'] |
| 34 | |
Alexey Samsonov | c01f4f0 | 2013-04-04 07:41:20 +0000 | [diff] [blame] | 35 | # Propagate path to symbolizer for ASan/MSan. |
| 36 | for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']: |
| 37 | if symbolizer in os.environ: |
| 38 | config.environment[symbolizer] = os.environ[symbolizer] |
| 39 | |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 40 | ### |
| 41 | |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 42 | # Check that the object root is known. |
| 43 | if config.test_exec_root is None: |
| 44 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 45 | # probably trying to run on a test file directly, and either the site |
| 46 | # configuration hasn't been created by the build system, or we are in an |
| 47 | # out-of-tree build situation). |
| 48 | |
Jeffrey Yasskin | cd3858b | 2011-02-15 07:54:28 +0000 | [diff] [blame] | 49 | # Check for 'clang_unit_site_config' user parameter, and use that if available. |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 50 | site_cfg = lit_config.params.get('clang_unit_site_config', None) |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 51 | if site_cfg and os.path.exists(site_cfg): |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 52 | lit_config.load_config(config, site_cfg) |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 53 | raise SystemExit |
| 54 | |
| 55 | # Try to detect the situation where we are using an out-of-tree build by |
| 56 | # looking for 'llvm-config'. |
| 57 | # |
| 58 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 59 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
| 60 | # build situation. This means knowing how to invoke the build system |
| 61 | # though, and I decided it was too much magic. |
| 62 | |
| 63 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 64 | if not llvm_config: |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 65 | lit_config.fatal('No site specific configuration available!') |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 66 | |
| 67 | # Get the source and object roots. |
| 68 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 69 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 70 | clang_src_root = os.path.join(llvm_src_root, "tools", "clang") |
| 71 | clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang") |
| 72 | |
| 73 | # Validate that we got a tree which points to here, using the standard |
| 74 | # tools/clang layout. |
Daniel Dunbar | a60a269 | 2011-06-22 21:46:43 +0000 | [diff] [blame] | 75 | this_src_root = os.path.join(os.path.dirname(__file__),'..','..') |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 76 | if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root): |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 77 | lit_config.fatal('No site specific configuration available!') |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 78 | |
| 79 | # Check that the site specific configuration exists. |
| 80 | site_cfg = os.path.join(clang_obj_root, 'test', 'Unit', 'lit.site.cfg') |
| 81 | if not os.path.exists(site_cfg): |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 82 | lit_config.fatal('No site specific configuration available!') |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 83 | |
| 84 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
Daniel Dunbar | 94ec6cc | 2013-08-09 14:43:04 +0000 | [diff] [blame] | 85 | lit_config.note('using out-of-tree build at %r' % clang_obj_root) |
| 86 | lit_config.load_config(config, site_cfg) |
Jeffrey Yasskin | c7da993 | 2011-02-03 04:51:52 +0000 | [diff] [blame] | 87 | raise SystemExit |
Daniel Dunbar | a60a269 | 2011-06-22 21:46:43 +0000 | [diff] [blame] | 88 | |
Dmitri Gribenko | 1bf8d91 | 2014-02-18 15:20:02 +0000 | [diff] [blame] | 89 | shlibpath_var = '' |
| 90 | if platform.system() == 'Linux': |
| 91 | shlibpath_var = 'LD_LIBRARY_PATH' |
| 92 | elif platform.system() == 'Darwin': |
| 93 | shlibpath_var = 'DYLD_LIBRARY_PATH' |
| 94 | elif platform.system() == 'Windows': |
| 95 | shlibpath_var = 'PATH' |
| 96 | |
Michal Gorny | 391f221 | 2016-12-15 20:31:08 +0000 | [diff] [blame] | 97 | # in stand-alone builds, shlibdir is clang's build tree |
| 98 | # while llvm_libs_dir is installed LLVM (and possibly older clang) |
| 99 | llvm_shlib_dir = getattr(config, 'shlibdir', None) |
| 100 | if not llvm_shlib_dir: |
| 101 | lit_config.fatal('No shlibdir set!') |
Dmitri Gribenko | 1bf8d91 | 2014-02-18 15:20:02 +0000 | [diff] [blame] | 102 | # Point the dynamic loader at dynamic libraries in 'lib'. |
| 103 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 104 | if not llvm_libs_dir: |
| 105 | lit_config.fatal('No LLVM libs dir set!') |
Michal Gorny | 391f221 | 2016-12-15 20:31:08 +0000 | [diff] [blame] | 106 | shlibpath = os.path.pathsep.join((llvm_shlib_dir, llvm_libs_dir, |
Dmitri Gribenko | 1bf8d91 | 2014-02-18 15:20:02 +0000 | [diff] [blame] | 107 | config.environment.get(shlibpath_var,''))) |
NAKAMURA Takumi | b52c761 | 2014-07-04 05:11:55 +0000 | [diff] [blame] | 108 | |
Dmitri Gribenko | 1bf8d91 | 2014-02-18 15:20:02 +0000 | [diff] [blame] | 109 | config.environment[shlibpath_var] = shlibpath |