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 |
Michael J. Spencer | a4f983e | 2014-03-26 00:53:48 +0000 | [diff] [blame] | 7 | import locale |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 8 | |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 9 | import lit.formats |
| 10 | import lit.util |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 11 | |
| 12 | # Configuration file for the 'lit' test runner. |
| 13 | |
| 14 | # name: The name of this test suite. |
| 15 | config.name = 'lld' |
| 16 | |
| 17 | # testFormat: The test format to use to interpret tests. |
| 18 | # |
| 19 | # For now we require '&&' between commands, until they get globally killed and |
| 20 | # the test runner updated. |
| 21 | execute_external = (platform.system() != 'Windows' |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 22 | or lit_config.getBashPath() not in [None, ""]) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 23 | config.test_format = lit.formats.ShTest(execute_external) |
| 24 | |
| 25 | # suffixes: A list of file extensions to treat as test files. |
Michael J. Spencer | 74f29af | 2012-12-10 02:53:10 +0000 | [diff] [blame] | 26 | config.suffixes = ['.objtxt', '.test'] |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 27 | |
Rafael Espindola | c08ab8e | 2015-04-24 15:51:45 +0000 | [diff] [blame^] | 28 | # excludes: A list of directories to exclude from the testsuite. The 'Inputs' |
| 29 | # subdirectories contain auxiliary inputs for various tests in their parent |
| 30 | # directories. |
| 31 | config.excludes = ['Inputs'] |
| 32 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 33 | # test_source_root: The root path where tests are located. |
| 34 | config.test_source_root = os.path.dirname(__file__) |
| 35 | |
| 36 | # test_exec_root: The root path where tests should be run. |
| 37 | lld_obj_root = getattr(config, 'lld_obj_root', None) |
| 38 | if lld_obj_root is not None: |
| 39 | config.test_exec_root = os.path.join(lld_obj_root, 'test') |
| 40 | |
| 41 | # Set llvm_{src,obj}_root for use by others. |
| 42 | config.llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 43 | config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 44 | |
| 45 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 46 | if lld_obj_root is not None: |
| 47 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 48 | if not llvm_tools_dir: |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 49 | lit_config.fatal('No LLVM tools dir set!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 50 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
Sid Manning | 37e3120 | 2012-09-14 20:04:36 +0000 | [diff] [blame] | 51 | 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] | 52 | |
Sid Manning | 37e3120 | 2012-09-14 20:04:36 +0000 | [diff] [blame] | 53 | config.environment['PATH'] = path |
Hemant Kulkarni | 927bbc2 | 2012-09-14 16:11:34 +0000 | [diff] [blame] | 54 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 55 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 56 | if not llvm_libs_dir: |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 57 | lit_config.fatal('No LLVM libs dir set!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 58 | path = os.path.pathsep.join((llvm_libs_dir, |
| 59 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 60 | config.environment['LD_LIBRARY_PATH'] = path |
| 61 | |
Michael J. Spencer | ca20ffb | 2013-01-13 01:09:51 +0000 | [diff] [blame] | 62 | # Propagate LLVM_SRC_ROOT into the environment. |
| 63 | config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '') |
| 64 | |
| 65 | # Propagate PYTHON_EXECUTABLE into the environment |
| 66 | config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable', |
| 67 | '') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 68 | ### |
| 69 | |
| 70 | # Check that the object root is known. |
| 71 | if config.test_exec_root is None: |
| 72 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 73 | # probably trying to run on a test file directly, and either the site |
| 74 | # configuration hasn't been created by the build system, or we are in an |
| 75 | # out-of-tree build situation). |
| 76 | |
| 77 | # Check for 'lld_site_config' user parameter, and use that if available. |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 78 | site_cfg = lit_config.params.get('lld_site_config', None) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 79 | if site_cfg and os.path.exists(site_cfg): |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 80 | lit_config.load_config(config, site_cfg) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 81 | raise SystemExit |
| 82 | |
| 83 | # Try to detect the situation where we are using an out-of-tree build by |
| 84 | # looking for 'llvm-config'. |
| 85 | # |
| 86 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 87 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
| 88 | # build situation. This means knowing how to invoke the build system though, |
| 89 | # and I decided it was too much magic. We should solve this by just having |
| 90 | # the .cfg files generated during the configuration step. |
| 91 | |
| 92 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 93 | if not llvm_config: |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 94 | lit_config.fatal('No site specific configuration available!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 95 | |
| 96 | # Get the source and object roots. |
| 97 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 98 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 99 | lld_src_root = os.path.join(llvm_src_root, "tools", "lld") |
| 100 | lld_obj_root = os.path.join(llvm_obj_root, "tools", "lld") |
| 101 | |
| 102 | # Validate that we got a tree which points to here, using the standard |
| 103 | # tools/lld layout. |
| 104 | this_src_root = os.path.dirname(config.test_source_root) |
| 105 | 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] | 106 | lit_config.fatal('No site specific configuration available!') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 107 | |
| 108 | # Check that the site specific configuration exists. |
| 109 | site_cfg = os.path.join(lld_obj_root, 'test', 'lit.site.cfg') |
| 110 | if not os.path.exists(site_cfg): |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 111 | lit_config.fatal( |
| 112 | 'No site specific configuration available! You may need to ' |
| 113 | 'run "make test" in your lld build directory.') |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 114 | |
| 115 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 116 | lit_config.note('using out-of-tree build at %r' % lld_obj_root) |
| 117 | lit_config.load_config(config, site_cfg) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 118 | raise SystemExit |
| 119 | |
| 120 | # When running under valgrind, we mangle '-vg' onto the end of the triple so we |
| 121 | # can check it with XFAIL and XTARGET. |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 122 | if lit_config.useValgrind: |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 123 | config.target_triple += '-vg' |
| 124 | |
| 125 | # Shell execution |
Daniel Dunbar | bc7bfb1 | 2013-08-09 18:51:17 +0000 | [diff] [blame] | 126 | if platform.system() not in ['Windows'] or lit_config.getBashPath() != '': |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 127 | config.available_features.add('shell') |
Rui Ueyama | 9249222 | 2013-07-03 09:09:13 +0000 | [diff] [blame] | 128 | |
Nick Kledzik | 50bda29 | 2014-09-11 00:52:05 +0000 | [diff] [blame] | 129 | # Running on Darwin OS |
| 130 | if platform.system() in ['Darwin']: |
| 131 | config.available_features.add('system-linker-mach-o') |
| 132 | |
| 133 | # Running on ELF based *nix |
Ed Maste | 933daef | 2014-09-12 13:16:30 +0000 | [diff] [blame] | 134 | if platform.system() in ['FreeBSD', 'Linux']: |
Nick Kledzik | 50bda29 | 2014-09-11 00:52:05 +0000 | [diff] [blame] | 135 | config.available_features.add('system-linker-elf') |
| 136 | |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 137 | # llvm-config knows whether it is compiled with asserts (and) |
| 138 | # whether we are operating in release/debug mode. |
Rui Ueyama | 9249222 | 2013-07-03 09:09:13 +0000 | [diff] [blame] | 139 | import subprocess |
| 140 | try: |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 141 | llvm_config_cmd = \ |
| 142 | subprocess.Popen([os.path.join(llvm_tools_dir, 'llvm-config'), |
Filipe Cabecinhas | cd8c610 | 2014-04-23 05:35:26 +0000 | [diff] [blame] | 143 | '--build-mode', '--assertion-mode', '--targets-built'], |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 144 | stdout = subprocess.PIPE) |
Michael J. Spencer | a4f983e | 2014-03-26 00:53:48 +0000 | [diff] [blame] | 145 | except OSError as why: |
| 146 | print("Could not find llvm-config in " + llvm_tools_dir) |
Rui Ueyama | 9249222 | 2013-07-03 09:09:13 +0000 | [diff] [blame] | 147 | exit(42) |
| 148 | |
Michael J. Spencer | 876bee8 | 2014-03-26 01:19:07 +0000 | [diff] [blame] | 149 | llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8') |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 150 | llvm_config_output_list = llvm_config_output.split("\n") |
| 151 | |
| 152 | if re.search(r'DEBUG', llvm_config_output_list[0]): |
Rui Ueyama | 130a6eb | 2013-07-04 09:29:47 +0000 | [diff] [blame] | 153 | config.available_features.add('debug') |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 154 | if re.search(r'ON', llvm_config_output_list[1]): |
Rui Ueyama | 9249222 | 2013-07-03 09:09:13 +0000 | [diff] [blame] | 155 | config.available_features.add('asserts') |
Simon Atanasyan | d7bc5d0 | 2014-07-31 19:02:10 +0000 | [diff] [blame] | 156 | if re.search(r'ARM', llvm_config_output_list[2]): |
| 157 | config.available_features.add('arm') |
Filipe Cabecinhas | cd8c610 | 2014-04-23 05:35:26 +0000 | [diff] [blame] | 158 | if re.search(r'Mips', llvm_config_output_list[2]): |
| 159 | config.available_features.add('mips') |
Filipe Cabecinhas | d1787ad | 2015-01-24 03:55:22 +0000 | [diff] [blame] | 160 | if re.search(r'X86', llvm_config_output_list[2]): |
| 161 | config.available_features.add('x86') |
Shankar Easwaran | 7a0818d | 2014-02-25 02:29:17 +0000 | [diff] [blame] | 162 | llvm_config_cmd.wait() |
Rui Ueyama | f23b27a | 2013-11-04 05:17:54 +0000 | [diff] [blame] | 163 | |
| 164 | # Check if Windows resource file compiler exists. |
| 165 | cvtres = lit.util.which('cvtres', config.environment['PATH']) |
| 166 | rc = lit.util.which('rc', config.environment['PATH']) |
| 167 | if cvtres and rc: |
| 168 | config.available_features.add('winres') |
Rui Ueyama | 76d2fa7 | 2014-01-09 01:11:48 +0000 | [diff] [blame] | 169 | |
Filipe Cabecinhas | 47f07f8 | 2014-04-23 04:38:13 +0000 | [diff] [blame] | 170 | # Check if "lib.exe" command exists. |
| 171 | if lit.util.which('lib.exe', config.environment['PATH']): |
Rui Ueyama | 76d2fa7 | 2014-01-09 01:11:48 +0000 | [diff] [blame] | 172 | config.available_features.add('winlib') |