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