| Zachary Turner | 891af04 | 2015-03-13 20:55:07 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
| 4 | import platform |
| 5 | import re |
| 6 | import subprocess |
| 7 | import locale |
| 8 | |
| 9 | import lit.formats |
| 10 | import lit.util |
| 11 | |
| 12 | # Configuration file for the 'lit' test runner. |
| 13 | |
| 14 | # name: The name of this test suite. |
| 15 | config.name = 'lldb' |
| 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' |
| 22 | or lit_config.getBashPath() not in [None, ""]) |
| 23 | config.test_format = lit.formats.ShTest(execute_external) |
| 24 | |
| 25 | # suffixes: We only support unit tests |
| 26 | config.suffixes = [] |
| 27 | |
| 28 | # test_source_root: The root path where tests are located. |
| 29 | config.test_source_root = os.path.dirname(__file__) |
| 30 | |
| 31 | # test_exec_root: The root path where tests should be run. |
| 32 | lldb_obj_root = getattr(config, 'lldb_obj_root', None) |
| 33 | if lldb_obj_root is not None: |
| 34 | config.test_exec_root = os.path.join(lldb_obj_root, 'lit') |
| 35 | |
| 36 | # Set llvm_{src,obj}_root for use by others. |
| 37 | config.llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 38 | config.llvm_obj_root = getattr(config, 'llvm_obj_root', None) |
| 39 | |
| 40 | # Tweak the PATH to include the tools dir and the scripts dir. |
| 41 | if lldb_obj_root is not None: |
| 42 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 43 | if not llvm_tools_dir: |
| 44 | lit_config.fatal('No LLVM tools dir set!') |
| 45 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
| 46 | path = os.path.pathsep.join((os.path.join(getattr(config, 'llvm_src_root', None),'test','Scripts'),path)) |
| 47 | |
| 48 | config.environment['PATH'] = path |
| 49 | |
| 50 | llvm_libs_dir = getattr(config, 'llvm_libs_dir', None) |
| 51 | if not llvm_libs_dir: |
| 52 | lit_config.fatal('No LLVM libs dir set!') |
| 53 | path = os.path.pathsep.join((llvm_libs_dir, |
| 54 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 55 | config.environment['LD_LIBRARY_PATH'] = path |
| 56 | |
| 57 | # Propagate LLVM_SRC_ROOT into the environment. |
| 58 | config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '') |
| 59 | |
| 60 | # Propagate PYTHON_EXECUTABLE into the environment |
| 61 | config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable', |
| 62 | '') |
| 63 | ### |
| 64 | |
| 65 | # Check that the object root is known. |
| 66 | if config.test_exec_root is None: |
| 67 | # Otherwise, we haven't loaded the site specific configuration (the user is |
| 68 | # probably trying to run on a test file directly, and either the site |
| 69 | # configuration hasn't been created by the build system, or we are in an |
| 70 | # out-of-tree build situation). |
| 71 | |
| 72 | # Check for 'lldb_site_config' user parameter, and use that if available. |
| 73 | site_cfg = lit_config.params.get('lldb_site_config', None) |
| 74 | if site_cfg and os.path.exists(site_cfg): |
| 75 | lit_config.load_config(config, site_cfg) |
| 76 | raise SystemExit |
| 77 | |
| 78 | # Try to detect the situation where we are using an out-of-tree build by |
| 79 | # looking for 'llvm-config'. |
| 80 | # |
| 81 | # FIXME: I debated (i.e., wrote and threw away) adding logic to |
| 82 | # automagically generate the lit.site.cfg if we are in some kind of fresh |
| 83 | # build situation. This means knowing how to invoke the build system though, |
| 84 | # and I decided it was too much magic. We should solve this by just having |
| 85 | # the .cfg files generated during the configuration step. |
| 86 | |
| 87 | llvm_config = lit.util.which('llvm-config', config.environment['PATH']) |
| 88 | if not llvm_config: |
| 89 | lit_config.fatal('No site specific configuration available!') |
| 90 | |
| 91 | # Get the source and object roots. |
| 92 | llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip() |
| 93 | llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip() |
| 94 | lldb_src_root = os.path.join(llvm_src_root, "tools", "lldb") |
| 95 | lldb_obj_root = os.path.join(llvm_obj_root, "tools", "lldb") |
| 96 | |
| 97 | # Validate that we got a tree which points to here, using the standard |
| 98 | # tools/lldb layout. |
| 99 | this_src_root = os.path.dirname(config.test_source_root) |
| 100 | if os.path.realpath(lldb_src_root) != os.path.realpath(this_src_root): |
| 101 | lit_config.fatal('No site specific configuration available!') |
| 102 | |
| 103 | # Check that the site specific configuration exists. |
| 104 | site_cfg = os.path.join(lldb_obj_root, 'test', 'lit.site.cfg') |
| 105 | if not os.path.exists(site_cfg): |
| 106 | lit_config.fatal( |
| 107 | 'No site specific configuration available! You may need to ' |
| 108 | 'run "make test" in your lldb build directory.') |
| 109 | |
| 110 | # Okay, that worked. Notify the user of the automagic, and reconfigure. |
| 111 | lit_config.note('using out-of-tree build at %r' % lldb_obj_root) |
| 112 | lit_config.load_config(config, site_cfg) |
| 113 | raise SystemExit |
| 114 | |
| 115 | # Shell execution |
| 116 | if platform.system() not in ['Windows'] or lit_config.getBashPath() != '': |
| 117 | config.available_features.add('shell') |
| 118 | |
| 119 | # Running on Darwin OS |
| 120 | if platform.system() in ['Darwin']: |
| 121 | config.available_features.add('system-linker-mach-o') |
| 122 | |
| 123 | # Running on ELF based *nix |
| 124 | if platform.system() in ['FreeBSD', 'Linux']: |
| 125 | config.available_features.add('system-linker-elf') |
| 126 | |
| 127 | # llvm-config knows whether it is compiled with asserts (and) |
| 128 | # whether we are operating in release/debug mode. |
| 129 | import subprocess |
| 130 | try: |
| 131 | llvm_config_cmd = \ |
| 132 | subprocess.Popen([os.path.join(llvm_tools_dir, 'llvm-config'), |
| 133 | '--build-mode', '--assertion-mode', '--targets-built'], |
| 134 | stdout = subprocess.PIPE) |
| 135 | except OSError as why: |
| 136 | print("Could not find llvm-config in " + llvm_tools_dir) |
| 137 | exit(42) |
| 138 | |
| 139 | llvm_config_output = llvm_config_cmd.stdout.read().decode('utf_8') |
| 140 | llvm_config_output_list = llvm_config_output.split("\n") |
| 141 | |
| 142 | if re.search(r'DEBUG', llvm_config_output_list[0]): |
| 143 | config.available_features.add('debug') |
| 144 | if re.search(r'ON', llvm_config_output_list[1]): |
| 145 | config.available_features.add('asserts') |
| 146 | if re.search(r'ARM', llvm_config_output_list[2]): |
| 147 | config.available_features.add('arm') |
| 148 | if re.search(r'Mips', llvm_config_output_list[2]): |
| 149 | config.available_features.add('mips') |
| 150 | if re.search(r'X86', llvm_config_output_list[2]): |
| 151 | config.available_features.add('x86') |
| 152 | llvm_config_cmd.wait() |