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