Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
| 4 | import platform |
| 5 | import re |
| 6 | import subprocess |
| 7 | |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 8 | import lit.formats |
| 9 | import lit.util |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 10 | |
| 11 | # Configuration file for the 'lit' test runner. |
| 12 | |
| 13 | # name: The name of this test suite. |
| 14 | config.name = 'lld' |
| 15 | |
| 16 | # testFormat: The test format to use to interpret tests. |
| 17 | # |
| 18 | # For now we require '&&' between commands, until they get globally killed and |
| 19 | # the test runner updated. |
| 20 | execute_external = (platform.system() != 'Windows' |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 21 | or lit_config.getBashPath() not in [None, ""]) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 22 | config.test_format = lit.formats.ShTest(execute_external) |
| 23 | |
| 24 | # suffixes: A list of file extensions to treat as test files. |
Michael J. Spencer | 74f29af | 2012-12-10 02:53:10 +0000 | [diff] [blame] | 25 | config.suffixes = ['.objtxt', '.test'] |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 26 | |
| 27 | # test_source_root: The root path where tests are located. |
| 28 | config.test_source_root = os.path.dirname(__file__) |
| 29 | |
| 30 | # test_exec_root: The root path where tests should be run. |
| 31 | lld_obj_root = getattr(config, 'lld_obj_root', None) |
| 32 | if lld_obj_root is not None: |
| 33 | config.test_exec_root = os.path.join(lld_obj_root, 'test') |
| 34 | |
| 35 | # Set llvm_{src,obj}_root for use by others. |
| 36 | config.llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 37 | config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 38 | |
| 39 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 40 | if lld_obj_root is not None: |
| 41 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 42 | if not llvm_tools_dir: |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 43 | lit_config.fatal('No LLVM tools dir set!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 44 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
Sid Manning | 37e3120 | 2012-09-14 20:04:36 +0000 | [diff] [blame] | 45 | path = os.path.pathsep.join((os.path.join(getattr(config, 'llvm_src_root', None),'test','Scripts'),path)) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 46 | |
Sid Manning | 37e3120 | 2012-09-14 20:04:36 +0000 | [diff] [blame] | 47 | config.environment['PATH'] = path |
Hemant Kulkarni | 927bbc2 | 2012-09-14 16:11:34 +0000 | [diff] [blame] | 48 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 49 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 50 | if not llvm_libs_dir: |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 51 | lit_config.fatal('No LLVM libs dir set!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 52 | path = os.path.pathsep.join((llvm_libs_dir, |
| 53 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 54 | config.environment['LD_LIBRARY_PATH'] = path |
| 55 | |
Michael J. Spencer | ca20ffb | 2013-01-13 01:09:51 +0000 | [diff] [blame] | 56 | # Propagate LLVM_SRC_ROOT into the environment. |
| 57 | config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '') |
| 58 | |
| 59 | # Propagate PYTHON_EXECUTABLE into the environment |
| 60 | config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable', |
| 61 | '') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 62 | ### |
| 63 | |
| 64 | # Check that the object root is known. |
| 65 | if config.test_exec_root is None: |
| 66 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 67 | # probably trying to run on a test file directly, and either the site |
| 68 | # configuration hasn't been created by the build system, or we are in an |
| 69 | # out-of-tree build situation). |
| 70 | |
| 71 | # Check for 'lld_site_config' user parameter, and use that if available. |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 72 | site_cfg = lit_config.params.get('lld_site_config', None) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 73 | if site_cfg and os.path.exists(site_cfg): |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 74 | lit_config.load_config(config, site_cfg) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 75 | raise SystemExit |
| 76 | |
| 77 | # Try to detect the situation where we are using an out-of-tree build by |
| 78 | # looking for 'llvm-config'. |
| 79 | # |
| 80 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 81 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
| 82 | # build situation. This means knowing how to invoke the build system though, |
| 83 | # and I decided it was too much magic. We should solve this by just having |
| 84 | # the .cfg files generated during the configuration step. |
| 85 | |
| 86 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 87 | if not llvm_config: |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 88 | lit_config.fatal('No site specific configuration available!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 89 | |
| 90 | # Get the source and object roots. |
| 91 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 92 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 93 | lld_src_root = os.path.join(llvm_src_root, "tools", "lld") |
| 94 | lld_obj_root = os.path.join(llvm_obj_root, "tools", "lld") |
| 95 | |
| 96 | # Validate that we got a tree which points to here, using the standard |
| 97 | # tools/lld layout. |
| 98 | this_src_root = os.path.dirname(config.test_source_root) |
| 99 | if os.path.realpath(lld_src_root) != os.path.realpath(this_src_root): |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 100 | lit_config.fatal('No site specific configuration available!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 101 | |
| 102 | # Check that the site specific configuration exists. |
| 103 | site_cfg = os.path.join(lld_obj_root, 'test', 'lit.site.cfg') |
| 104 | if not os.path.exists(site_cfg): |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 105 | lit_config.fatal( |
| 106 | 'No site specific configuration available! You may need to ' |
| 107 | 'run "make test" in your lld build directory.') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 108 | |
| 109 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 110 | lit_config.note('using out-of-tree build at %r' % lld_obj_root) |
| 111 | lit_config.load_config(config, site_cfg) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 112 | raise SystemExit |
| 113 | |
| 114 | # When running under valgrind, we mangle '-vg' onto the end of the triple so we |
| 115 | # can check it with XFAIL and XTARGET. |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 116 | if lit_config.useValgrind: |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 117 | config.target_triple += '-vg' |
| 118 | |
| 119 | # Shell execution |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 120 | if platform.system() not in ['Windows'] or lit_config.getBashPath() != '': |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 121 | config.available_features.add('shell') |
Rui Ueyama | 9249222 | 2013-07-03 09:09:13 +0000 | [diff] [blame] | 122 | |
| 123 | # llc knows whether it is compiled with -DNDEBUG. |
| 124 | import subprocess |
| 125 | try: |
| 126 | llc_cmd = subprocess.Popen([os.path.join(llvm_tools_dir, 'llc'), '-version'], |
| 127 | stdout = subprocess.PIPE) |
| 128 | except OSError, why: |
| 129 | print "Could not find llc in " + llvm_tools_dir |
| 130 | exit(42) |
| 131 | |
Rui Ueyama | 130a6eb | 2013-07-04 09:29:47 +0000 | [diff] [blame] | 132 | if re.search(r'DEBUG', llc_cmd.stdout.read()): |
| 133 | config.available_features.add('debug') |
Rui Ueyama | 9249222 | 2013-07-03 09:09:13 +0000 | [diff] [blame] | 134 | if re.search(r'with assertions', llc_cmd.stdout.read()): |
| 135 | config.available_features.add('asserts') |
| 136 | llc_cmd.wait() |
Rui Ueyama | f23b27a | 2013-11-04 05:17:54 +0000 | [diff] [blame^] | 137 | |
| 138 | # Check if Windows resource file compiler exists. |
| 139 | cvtres = lit.util.which('cvtres', config.environment['PATH']) |
| 140 | rc = lit.util.which('rc', config.environment['PATH']) |
| 141 | if cvtres and rc: |
| 142 | config.available_features.add('winres') |