blob: 8542b7d8d79db7ecf00c0697baf603821c8ec180 [file] [log] [blame]
Daniel Dunbar1db467f2009-07-31 05:54:17 +00001# -*- Python -*-
2
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +00003import os
Daniel Dunbarb850ddd2009-09-22 10:08:03 +00004import platform
Daniel Dunbar724827f2009-09-08 16:39:23 +00005
Daniel Dunbar1db467f2009-07-31 05:54:17 +00006# Configuration file for the 'lit' test runner.
7
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +00008# name: The name of this test suite.
9config.name = 'Clang'
Daniel Dunbar724827f2009-09-08 16:39:23 +000010
NAKAMURA Takumi98af1ac2011-02-09 04:19:57 +000011# Tweak PATH for Win32
12if 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'])
18 if path is not None:
19 path = os.path.pathsep.join((path,
20 config.environment['PATH']))
21 config.environment['PATH'] = path
22
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000023# testFormat: The test format to use to interpret tests.
Daniel Dunbar1db467f2009-07-31 05:54:17 +000024#
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000025# For now we require '&&' between commands, until they get globally killed and
26# the test runner updated.
Daniel Dunbarb850ddd2009-09-22 10:08:03 +000027execute_external = platform.system() != 'Windows'
Daniel Dunbarbc20ef32009-11-08 01:47:35 +000028config.test_format = lit.formats.ShTest(execute_external)
Daniel Dunbar6827f3f2009-09-06 01:31:12 +000029
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000030# suffixes: A list of file extensions to treat as test files.
Peter Collingbournee2f82f72011-02-11 19:59:54 +000031config.suffixes = ['.c', '.cpp', '.m', '.mm', '.cu', '.ll', '.cl']
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000032
33# test_source_root: The root path where tests are located.
34config.test_source_root = os.path.dirname(__file__)
35
36# test_exec_root: The root path where tests should be run.
37clang_obj_root = getattr(config, 'clang_obj_root', None)
38if clang_obj_root is not None:
39 config.test_exec_root = os.path.join(clang_obj_root, 'test')
40
41# Set llvm_{src,obj}_root for use by others.
42config.llvm_src_root = getattr(config, 'llvm_src_root', None)
43config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)
44
45# Tweak the PATH to include the tools dir and the scripts dir.
46if 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!')
Daniel Dunbaree45d6d2009-09-24 06:31:08 +000050 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000051 config.environment['PATH'] = path
52
Daniel Dunbar9e10cc72009-09-26 07:36:09 +000053 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
54 if not llvm_libs_dir:
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
59
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000060###
61
62# Check that the object root is known.
63if 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).
68
Daniel Dunbarb258d8f2009-11-05 16:36:19 +000069 # 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)
73 raise SystemExit
74
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000075 # Try to detect the situation where we are using an out-of-tree build by
76 # looking for 'llvm-config'.
77 #
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
Daniel Dunbar23354212009-11-07 23:53:17 +000080 # 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.
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +000083
84 llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
85 if not llvm_config:
86 lit.fatal('No site specific configuration available!')
87
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")
93
94 # Validate that we got a tree which points to here, using the standard
95 # tools/clang layout.
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!')
99
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):
Nico Weberb4a88ef2010-09-27 20:40:32 +0000103 lit.fatal('No site specific configuration available! You may need to '
104 'run "make test" in your Clang build directory.')
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000105
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)
109 raise SystemExit
110
111###
112
113# Discover the 'clang' and 'clangcc' to use.
114
115import os
116
117def inferClang(PATH):
118 # Determine which clang to use.
119 clang = os.getenv('CLANG')
120
121 # If the user set clang in the environment, definitely use that and don't
122 # try to validate.
123 if clang:
124 return clang
125
126 # Otherwise look in the path.
127 clang = lit.util.which('clang', PATH)
128
129 if not clang:
130 lit.fatal("couldn't find 'clang' program, try setting "
131 "CLANG in your environment")
132
133 return clang
134
Daniel Dunbare1fa0962010-03-20 21:13:08 +0000135# When running under valgrind, we mangle '-vg' onto the end of the triple so we
136# can check it with XFAIL and XTARGET.
137if lit.useValgrind:
138 config.target_triple += '-vg'
139
Daniel Dunbar5e01e3c2009-09-22 05:16:02 +0000140config.clang = inferClang(config.environment['PATH'])
141if not lit.quiet:
142 lit.note('using clang: %r' % config.clang)
Daniel Dunbara5728872009-12-15 20:14:24 +0000143config.substitutions.append( ('%clang_cc1', config.clang + ' -cc1') )
Daniel Dunbar9fde9c42010-06-29 16:52:24 +0000144config.substitutions.append( ('%clangxx', ' ' + config.clang +
145 ' -ccc-clang-cxx -ccc-cxx '))
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000146config.substitutions.append( ('%clang', ' ' + config.clang + ' ') )
Devang Patel8c6b9132010-09-13 20:46:23 +0000147config.substitutions.append( ('%test_debuginfo', ' ' + config.llvm_src_root + '/utils/test_debuginfo.pl ') )
Daniel Dunbara5728872009-12-15 20:14:24 +0000148
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000149# FIXME: Find nicer way to prohibit this.
150config.substitutions.append(
151 (' clang ', """*** Do not use 'clang' in tests, use '%clang'. ***""") )
152config.substitutions.append(
David Greene431feb52011-01-03 17:28:52 +0000153 (' clang\+\+ ', """*** Do not use 'clang++' in tests, use '%clangxx'. ***"""))
Daniel Dunbar679d6052010-02-17 20:31:01 +0000154config.substitutions.append(
Daniel Dunbar80737ad2009-12-15 22:01:24 +0000155 (' clang-cc ',
156 """*** Do not use 'clang-cc' in tests, use '%clang_cc1'. ***""") )
157config.substitutions.append(
158 (' clang -cc1 ',
159 """*** Do not use 'clang -cc1' in tests, use '%clang_cc1'. ***""") )
Daniel Dunbar9fde9c42010-06-29 16:52:24 +0000160config.substitutions.append(
161 (' %clang-cc1 ',
162 """*** invalid substitution, use '%clang_cc1'. ***""") )
Daniel Dunbardb918642010-08-24 21:39:55 +0000163
164###
165
166# Set available features we allow tests to conditionalize on.
167if platform.system() != 'Windows':
168 config.available_features.add('crash-recovery')
NAKAMURA Takumief34d772011-02-28 09:41:07 +0000169
170# Shell execution
171if platform.system() not in ['Windows'] or lit.getBashPath() != '':
172 config.available_features.add('shell')