StmtPrinter: factor out arg printing code to PrintCallArgs
[clang.git] / test / lit.cfg
blob5dec8ff477b55a0547e6d743bc3cac5666c1be7c
1 # -*- Python -*-
3 import os
4 import platform
6 # Configuration file for the 'lit' test runner.
8 # name: The name of this test suite.
9 config.name = 'Clang'
11 # testFormat: The test format to use to interpret tests.
13 # For now we require '&&' between commands, until they get globally killed and
14 # the test runner updated.
15 execute_external = platform.system() != 'Windows'
16 config.test_format = lit.formats.ShTest(execute_external)
18 # suffixes: A list of file extensions to treat as test files.
19 config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll']
21 # test_source_root: The root path where tests are located.
22 config.test_source_root = os.path.dirname(__file__)
24 # test_exec_root: The root path where tests should be run.
25 clang_obj_root = getattr(config, 'clang_obj_root', None)
26 if clang_obj_root is not None:
27     config.test_exec_root = os.path.join(clang_obj_root, 'test')
29 # Set llvm_{src,obj}_root for use by others.
30 config.llvm_src_root = getattr(config, 'llvm_src_root', None)
31 config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
33 # Tweak the PATH to include the tools dir and the scripts dir.
34 if clang_obj_root is not None:
35     llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
36     if not llvm_tools_dir:
37         lit.fatal('No LLVM tools dir set!')
38     path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
39     config.environment['PATH'] = path
41     llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
42     if not llvm_libs_dir:
43         lit.fatal('No LLVM libs dir set!')
44     path = os.path.pathsep.join((llvm_libs_dir,
45                                  config.environment.get('LD_LIBRARY_PATH','')))
46     config.environment['LD_LIBRARY_PATH'] = path
48 ###
50 # Check that the object root is known.
51 if config.test_exec_root is None:
52     # Otherwise, we haven't loaded the site specific configuration (the user is
53     # probably trying to run on a test file directly, and either the site
54     # configuration hasn't been created by the build system, or we are in an
55     # out-of-tree build situation).
57     # Check for 'clang_site_config' user parameter, and use that if available.
58     site_cfg = lit.params.get('clang_site_config', None)
59     if site_cfg and os.path.exists(site_cfg):
60         lit.load_config(config, site_cfg)
61         raise SystemExit
63     # Try to detect the situation where we are using an out-of-tree build by
64     # looking for 'llvm-config'.
65     #
66     # FIXME: I debated (i.e., wrote and threw away) adding logic to
67     # automagically generate the lit.site.cfg if we are in some kind of fresh
68     # build situation. This means knowing how to invoke the build system though,
69     # and I decided it was too much magic. We should solve this by just having
70     # the .cfg files generated during the configuration step.
72     llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
73     if not llvm_config:
74         lit.fatal('No site specific configuration available!')
76     # Get the source and object roots.
77     llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
78     llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
79     clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
80     clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
82     # Validate that we got a tree which points to here, using the standard
83     # tools/clang layout.
84     this_src_root = os.path.dirname(config.test_source_root)
85     if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
86         lit.fatal('No site specific configuration available!')
88     # Check that the site specific configuration exists.
89     site_cfg = os.path.join(clang_obj_root, 'test', 'lit.site.cfg')
90     if not os.path.exists(site_cfg):
91         lit.fatal('No site specific configuration available! You may need to '
92                   'run "make test" in your Clang build directory.')
94     # Okay, that worked. Notify the user of the automagic, and reconfigure.
95     lit.note('using out-of-tree build at %r' % clang_obj_root)
96     lit.load_config(config, site_cfg)
97     raise SystemExit
99 ###
101 # Discover the 'clang' and 'clangcc' to use.
103 import os
105 def inferClang(PATH):
106     # Determine which clang to use.
107     clang = os.getenv('CLANG')
109     # If the user set clang in the environment, definitely use that and don't
110     # try to validate.
111     if clang:
112         return clang
114     # Otherwise look in the path.
115     clang = lit.util.which('clang', PATH)
117     if not clang:
118         lit.fatal("couldn't find 'clang' program, try setting "
119                   "CLANG in your environment")
121     return clang
123 # When running under valgrind, we mangle '-vg' onto the end of the triple so we
124 # can check it with XFAIL and XTARGET.
125 if lit.useValgrind:
126     config.target_triple += '-vg'
128 config.clang = inferClang(config.environment['PATH'])
129 if not lit.quiet:
130     lit.note('using clang: %r' % config.clang)
131 config.substitutions.append( ('%clang_cc1', config.clang + ' -cc1') )
132 config.substitutions.append( ('%clangxx', ' ' + config.clang +
133                               ' -ccc-clang-cxx -ccc-cxx '))
134 config.substitutions.append( ('%clang', ' ' + config.clang + ' ') )
135 config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') )
137 # FIXME: Find nicer way to prohibit this.
138 config.substitutions.append(
139     (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") )
140 config.substitutions.append(
141     (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***"""))
142 config.substitutions.append(
143     (' clang-cc ',
144      """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") )
145 config.substitutions.append(
146     (' clang -cc1 ',
147      """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") )
148 config.substitutions.append(
149     (' %clang-cc1 ',
150      """*** invalid substitution, use '%clang_cc1'. ***""") )
154 # Set available features we allow tests to conditionalize on.
155 if platform.system() != 'Windows':
156     config.available_features.add('crash-recovery')