Fix two warnings in polly, -Wmismatched-tags and -Wreorder
[polly-mirror.git] / test / lit.cfg
blobac4eeee52a75bfa28d1cda007d8ff998ab30531f
1 # -*clang- Python -*-
3 import os
4 import platform
5 import re
6 import subprocess
8 import lit.formats
9 import lit.util
11 # Configuration file for the 'lit' test runner.
13 # name: The name of this test suite.
14 config.name = 'Polly'
16 # testFormat: The test format to use to interpret tests.
18 # For now we require '&&' between commands, until they get globally killed and
19 # the test runner updated.
20 execute_external = platform.system() != 'Windows'
21 config.test_format = lit.formats.ShTest(execute_external)
23 # suffixes: A list of file extensions to treat as test files.
24 config.suffixes = ['.ll']
26 # test_source_root: The root path where tests are located.
27 config.test_source_root = os.path.dirname(__file__)
29 # test_exec_root: The root path where tests should be run.
30 polly_obj_root = getattr(config, 'polly_obj_root', None)
31 if polly_obj_root is not None:
32     config.test_exec_root = os.path.join(polly_obj_root, 'test')
34 # Set llvm_{src,obj}_root for use by others.
35 config.llvm_src_root = getattr(config, 'llvm_src_root', None)
36 config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
38 # Tweak the PATH to include the tools dir and the scripts dir.
39 if polly_obj_root is not None:
40     llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
41     if not llvm_tools_dir:
42         lit_config.fatal('No LLVM tools dir set!')
43     extra_paths = getattr(config, 'extra_paths', [])
44     base_paths = [llvm_tools_dir, config.environment['PATH']]
45     path = os.path.pathsep.join(base_paths + extra_paths)
46     config.environment['PATH'] = path
48     llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
49     if not llvm_libs_dir:
50         lit_config.fatal('No LLVM libs dir set!')
51     path = os.path.pathsep.join((llvm_libs_dir,
52                                  config.environment.get('LD_LIBRARY_PATH','')))
53     config.environment['LD_LIBRARY_PATH'] = path
55 ###
57 # Check that the object root is known.
58 if config.test_exec_root is None:
59     # Otherwise, we haven't loaded the site specific configuration (the user is
60     # probably trying to run on a test file directly, and either the site
61     # configuration hasn't been created by the build system, or we are in an
62     # out-of-tree build situation).
64     # Check for 'polly_site_config' user parameter, and use that if available.
65     site_cfg = lit_config.params.get('polly_site_config', None)
66     if site_cfg and os.path.exists(site_cfg):
67         lit_config.load_config(config, site_cfg)
68         raise SystemExit
70     # Try to detect the situation where we are using an out-of-tree build by
71     # looking for 'llvm-config'.
72     #
73     # FIXME: I debated (i.e., wrote and threw away) adding logic to
74     # automagically generate the lit.site.cfg if we are in some kind of fresh
75     # build situation. This means knowing how to invoke the build system though,
76     # and I decided it was too much magic. We should solve this by just having
77     # the .cfg files generated during the configuration step.
79     llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
80     if not llvm_config:
81         lit_config.fatal('No site specific configuration available!')
83     # Get the source and object roots.
84     llvm_src_root = subprocess.check_output(['llvm-config', '--src-root']).decode("utf-8").strip()
85     llvm_obj_root = subprocess.check_output(['llvm-config', '--obj-root']).decode("utf-8").strip()
87     polly_src_root = os.path.join(llvm_src_root, "tools", "polly")
88     polly_obj_root = os.path.join(llvm_obj_root, "tools", "polly")
90     # Validate that we got a tree which points to here, using the standard
91     # tools/polly layout.
92     this_src_root = os.path.dirname(config.test_source_root)
93     if os.path.realpath(polly_src_root) != os.path.realpath(this_src_root):
94         lit_config.fatal('No site specific configuration available!')
96     # Check that the site specific configuration exists.
97     site_cfg = os.path.join(polly_obj_root, 'test', 'lit.site.cfg')
98     if not os.path.exists(site_cfg):
99         lit_config.fatal('No site specific configuration available!')
101     # Okay, that worked. Notify the user of the automagic, and reconfigure.
102     lit_config.note('using out-of-tree build at %r' % polly_obj_root)
103     lit_config.load_config(config, site_cfg)
104     raise SystemExit
106 # opt knows whether it is compiled with -DNDEBUG.
107 import subprocess
108 try:
109     opt_cmd = subprocess.Popen([os.path.join(llvm_tools_dir, 'opt'), '-version'],
110                            stdout = subprocess.PIPE,
111                            env=config.environment)
112 except OSError:
113     print("Could not find opt in " + llvm_tools_dir)
114     exit(42)
116 if re.search(r'with assertions', opt_cmd.stdout.read().decode('ascii')):
117     config.available_features.add('asserts')
118 opt_cmd.wait()
120 try:
121     llvm_config_cmd = subprocess.Popen([os.path.join(llvm_tools_dir,
122                                                      'llvm-config'),
123                                         '--targets-built'],
124                                        stdout = subprocess.PIPE,
125                                        env=config.environment)
126 except OSError:
127     print("Could not find llvm-config in " + llvm_tools_dir)
128     exit(42)
130 if re.search(r'NVPTX', llvm_config_cmd.stdout.read().decode('ascii')):
131     config.available_features.add('nvptx-registered-target')
132 llvm_config_cmd.wait()