Daniel Dunbar | 40722cc | 2013-01-31 00:21:39 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
Daniel Dunbar | 6d0ed4c | 2013-08-14 05:07:09 +0000 | [diff] [blame] | 4 | import sys |
Daniel Dunbar | 40722cc | 2013-01-31 00:21:39 +0000 | [diff] [blame] | 5 | |
Daniel Dunbar | 72868c7 | 2013-08-09 21:39:17 +0000 | [diff] [blame] | 6 | import lit.formats |
| 7 | |
Daniel Dunbar | 40722cc | 2013-01-31 00:21:39 +0000 | [diff] [blame] | 8 | # Configuration file for the 'lit' test runner. |
| 9 | |
| 10 | # name: The name of this test suite. |
| 11 | config.name = 'lit' |
| 12 | |
| 13 | # testFormat: The test format to use to interpret tests. |
| 14 | config.test_format = lit.formats.ShTest(execute_external=False) |
| 15 | |
| 16 | # suffixes: A list of file extensions to treat as test files. |
| 17 | config.suffixes = ['.py'] |
| 18 | |
| 19 | # excludes: A list of individual files to exclude. |
| 20 | config.excludes = ['Inputs'] |
| 21 | |
| 22 | # test_source_root: The root path where tests are located. |
| 23 | config.test_source_root = os.path.dirname(__file__) |
| 24 | config.test_exec_root = config.test_source_root |
| 25 | |
Daniel Dunbar | cd625f4e | 2013-09-14 01:19:17 +0000 | [diff] [blame] | 26 | config.target_triple = '(unused)' |
Daniel Dunbar | 40722cc | 2013-01-31 00:21:39 +0000 | [diff] [blame] | 27 | |
| 28 | src_root = os.path.join(config.test_source_root, '..') |
Brian Gesiak | f0850e3 | 2017-07-27 19:18:35 +0000 | [diff] [blame] | 29 | llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 30 | if llvm_src_root != None: |
| 31 | # ``src_root`` may be in LLVM's binary build directory which does not contain |
| 32 | # ``lit.py``, so use `llvm_src_root` instead. |
| 33 | lit_path = os.path.join(llvm_src_root, 'utils', 'lit') |
| 34 | else: |
| 35 | lit_path = src_root |
| 36 | |
| 37 | config.environment['PYTHONPATH'] = lit_path # Required because some tests import the lit module |
Daniel Dunbar | 40722cc | 2013-01-31 00:21:39 +0000 | [diff] [blame] | 38 | config.substitutions.append(('%{src_root}', src_root)) |
| 39 | config.substitutions.append(('%{inputs}', os.path.join( |
| 40 | src_root, 'tests', 'Inputs'))) |
Daniel Dunbar | 6d0ed4c | 2013-08-14 05:07:09 +0000 | [diff] [blame] | 41 | config.substitutions.append(('%{lit}', "%%{python} %s" % ( |
Brian Gesiak | f0850e3 | 2017-07-27 19:18:35 +0000 | [diff] [blame] | 42 | os.path.join(lit_path, 'lit.py'),))) |
Stella Stamenova | cc2404c | 2018-08-06 22:37:44 +0000 | [diff] [blame] | 43 | config.substitutions.append(('%{python}', "'%s'" % (sys.executable))) |
| 44 | |
Daniel Dunbar | 40722cc | 2013-01-31 00:21:39 +0000 | [diff] [blame] | 45 | |
| 46 | # Enable coverage.py reporting, assuming the coverage module has been installed |
| 47 | # and sitecustomize.py in the virtualenv has been modified appropriately. |
Daniel Dunbar | 72868c7 | 2013-08-09 21:39:17 +0000 | [diff] [blame] | 48 | if lit_config.params.get('check-coverage', None): |
Daniel Dunbar | 40722cc | 2013-01-31 00:21:39 +0000 | [diff] [blame] | 49 | config.environment['COVERAGE_PROCESS_START'] = os.path.join( |
| 50 | os.path.dirname(__file__), ".coveragerc") |
Daniel Dunbar | cd625f4e | 2013-09-14 01:19:17 +0000 | [diff] [blame] | 51 | |
| 52 | # Add a feature to detect the Python version. |
| 53 | config.available_features.add("python%d.%d" % (sys.version_info[0], |
| 54 | sys.version_info[1])) |
Dan Liew | 7574241 | 2015-12-27 14:03:49 +0000 | [diff] [blame] | 55 | |
| 56 | # Add a feature to detect if psutil is available |
| 57 | try: |
| 58 | import psutil |
| 59 | lit_config.note('Found python psutil module') |
| 60 | config.available_features.add("python-psutil") |
| 61 | except ImportError: |
| 62 | lit_config.warning('Could not import psutil. Some tests will be skipped and' |
| 63 | ' the --timeout command line argument will not work.') |
Brian Gesiak | 0787253 | 2017-07-26 15:10:50 +0000 | [diff] [blame] | 64 | |
| 65 | if sys.platform.startswith('win') or sys.platform.startswith('cygwin'): |
| 66 | config.available_features.add('windows') |
Brian Gesiak | f0850e3 | 2017-07-27 19:18:35 +0000 | [diff] [blame] | 67 | |
Greg Bedwell | 34a83f0 | 2017-11-29 18:05:26 +0000 | [diff] [blame] | 68 | # Add llvm and lit tools directories if this config is being loaded indirectly. |
| 69 | path = config.environment['PATH'] |
| 70 | for attribute in ('llvm_tools_dir', 'lit_tools_dir'): |
| 71 | directory = getattr(config, attribute, None) |
| 72 | if directory: |
| 73 | path = os.path.pathsep.join((directory, path)) |
| 74 | config.environment['PATH'] = path |