6 # Configuration file for the 'lit' test runner.
8 # name: The name of this test suite.
11 # Tweak PATH for Win32
12 if platform.system() == 'Windows':
13 # Seek sane tools in directories and set to $PATH.
14 path = getattr(config, 'lit_tools_dir', None)
15 path = lit.getToolsPath(path,
16 config.environment['PATH'],
17 ['cmp.exe', 'grep.exe', 'sed.exe'])
19 path = os.path.pathsep.join((path,
20 config.environment['PATH']))
21 config.environment['PATH'] = path
23 # testFormat: The test format to use to interpret tests.
25 # For now we require '&&' between commands, until they get globally killed and
26 # the test runner updated.
27 execute_external = platform.system() != 'Windows'
28 config.test_format = lit.formats.ShTest(execute_external)
30 # suffixes: A list of file extensions to treat as test files.
31 config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl']
33 # test_source_root: The root path where tests are located.
34 config.test_source_root = os.path.dirname(__file__)
36 # test_exec_root: The root path where tests should be run.
37 clang_obj_root = getattr(config, 'clang_obj_root', None)
38 if clang_obj_root is not None:
39 config.test_exec_root = os.path.join(clang_obj_root, 'test')
41 # Set llvm_{src,obj}_root for use by others.
42 config.llvm_src_root = getattr(config, 'llvm_src_root', None)
43 config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
45 # Tweak the PATH to include the tools dir and the scripts dir.
46 if clang_obj_root is not None:
47 llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
48 if not llvm_tools_dir:
49 lit.fatal('No LLVM tools dir set!')
50 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
51 config.environment['PATH'] = path
53 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
55 lit.fatal('No LLVM libs dir set!')
56 path = os.path.pathsep.join((llvm_libs_dir,
57 config.environment.get('LD_LIBRARY_PATH','')))
58 config.environment['LD_LIBRARY_PATH'] = path
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).
69 # Check for 'clang_site_config' user parameter, and use that if available.
70 site_cfg = lit.params.get('clang_site_config', None)
71 if site_cfg and os.path.exists(site_cfg):
72 lit.load_config(config, site_cfg)
75 # Try to detect the situation where we are using an out-of-tree build by
76 # looking for 'llvm-config'.
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.
84 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
86 lit.fatal('No site specific configuration available!')
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 clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
92 clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
94 # Validate that we got a tree which points to here, using the standard
96 this_src_root = os.path.dirname(config.test_source_root)
97 if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
98 lit.fatal('No site specific configuration available!')
100 # Check that the site specific configuration exists.
101 site_cfg = os.path.join(clang_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 Clang build directory.')
106 # Okay, that worked. Notify the user of the automagic, and reconfigure.
107 lit.note('using out-of-tree build at %r' % clang_obj_root)
108 lit.load_config(config, site_cfg)
113 # Discover the 'clang' and 'clangcc' to use.
117 def inferClang(PATH):
118 # Determine which clang to use.
119 clang = os.getenv('CLANG')
121 # If the user set clang in the environment, definitely use that and don't
126 # Otherwise look in the path.
127 clang = lit.util.which('clang', PATH)
130 lit.fatal("couldn't find 'clang' program, try setting "
131 "CLANG in your environment")
135 # When running under valgrind, we mangle '-vg' onto the end of the triple so we
136 # can check it with XFAIL and XTARGET.
138 config.target_triple += '-vg'
140 config.clang = inferClang(config.environment['PATH'])
142 lit.note('using clang: %r' % config.clang)
143 config.substitutions.append( ('%clang_cc1', config.clang + ' -cc1') )
144 config.substitutions.append( ('%clangxx', ' ' + config.clang +
145 ' -ccc-clang-cxx -ccc-cxx '))
146 config.substitutions.append( ('%clang', ' ' + config.clang + ' ') )
147 config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') )
149 # FIXME: Find nicer way to prohibit this.
150 config.substitutions.append(
151 (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") )
152 config.substitutions.append(
153 (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***"""))
154 config.substitutions.append(
156 """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") )
157 config.substitutions.append(
159 """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") )
160 config.substitutions.append(
162 """*** invalid substitution, use '%clang_cc1'. ***""") )
166 # Set available features we allow tests to conditionalize on.
167 if platform.system() != 'Windows':
168 config.available_features.add('crash-recovery')