blob: f7996ad179297b12a5c3d384d972ccbefa06141a [file] [log] [blame]
Diana Picusb03e5082018-02-05 12:36:49 +01001"""Command line interface tests for llvm.py build-and-test.
2
3Note that although this uses the unittest framework, it does *not* contain unit
4tests.
5
6"""
7import os
8
9from llvmtestcase import LLVMTestCase, require_command_arg, debug
10
11
12class Testllvmbuildandtest(LLVMTestCase):
13
14 @classmethod
15 def llvm_build_and_test(cls, *args, **kwargs):
16 return cls.command_with_defaults("build-and-test", *args, **kwargs)
17
18 def test_default_stage1(self):
19 """
20 Test that we dump the correct commands for a single stage build of LLVM.
21 """
Diana Picusfcfc6282018-02-14 18:50:24 +010022 reposDir = "path-to-repos"
Diana Picusb03e5082018-02-05 12:36:49 +010023 sourceDir = "path-to-sources"
24 buildDir = "path-to-stage1"
25
26 output = self.run_with_output(
27 self.llvm_build_and_test(
28 "--dry-run",
Diana Picusfcfc6282018-02-14 18:50:24 +010029 "--repos-dir", reposDir,
Diana Picusb03e5082018-02-05 12:36:49 +010030 "--source-dir", sourceDir,
31 "--stage1-build-dir", buildDir))
32
33 commands = output.splitlines()
34
35 self.assertRegex(commands[0],
36 "{build}\$ cmake -G Ninja .* {sources}".format(
37 build=buildDir, sources=sourceDir))
38
39 self.assertRegex(commands[1],
40 "{build}\$ ninja".format(build=buildDir))
41
Diana Picus2c580832018-02-14 14:51:00 +010042 def test_custom_stage1(self):
43 """Test that we can customize the first stage of the build."""
44 reposDir = "path-to-repos"
45 sourceDir = "path-to-sources"
46 buildDir = "path-to-stage1"
47
48 output = self.run_with_output(
49 self.llvm_build_and_test(
50 "--dry-run",
51 "--repos-dir", reposDir,
52 "--source-dir", sourceDir,
53 "--stage1-build-dir", buildDir,
54 "--stage1-subproject", "clang",
55 "--stage1-subproject", "compiler-rt",
56 "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm",
57 "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True",
58 "--stage1-build-flag=-j8",
59 "--stage1-build-flag", "check-all"))
60
61 commands = output.splitlines()
62
63 self.assertRegex(commands[0],
64 "{build}\$ cmake -G Ninja .* {sources}".format(
65 build=buildDir, sources=sourceDir))
66
67 self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0])
68 self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0])
69 self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0])
70 self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0])
71
72 self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0])
73 self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0])
74
75 self.assertRegex(commands[1],
76 "{build}\$ ninja -j8 check-all".format(build=buildDir))
77
78
Diana Picusb03e5082018-02-05 12:36:49 +010079 def test_stage1_and_testsuite(self):
80 """
81 Test that we dump the correct commands for a single stage build of LLVM
82 and a run of the test-suite with the resulting compiler.
83 """
Diana Picusfcfc6282018-02-14 18:50:24 +010084 reposDir = "path-to-repos"
Diana Picusb03e5082018-02-05 12:36:49 +010085 sourceDir = "path-to-sources"
86 buildDir = "path-to-stage1"
Diana Picusb03e5082018-02-05 12:36:49 +010087 sandboxDir = "path-to-sandbox"
Diana Picusfcfc6282018-02-14 18:50:24 +010088
89 testSuiteDir = os.path.join(reposDir, "test-suite")
90 lntDir = os.path.join(reposDir, "lnt")
Diana Picusb03e5082018-02-05 12:36:49 +010091
92 output = self.run_with_output(
93 self.llvm_build_and_test(
94 "--dry-run",
Diana Picusfcfc6282018-02-14 18:50:24 +010095 "--repos-dir", reposDir,
Diana Picusb03e5082018-02-05 12:36:49 +010096 "--source-dir", sourceDir,
97 "--stage1-build-dir", buildDir,
Diana Picusfcfc6282018-02-14 18:50:24 +010098 "--enable-test-suite",
99 "--sandbox", sandboxDir))
Diana Picusb03e5082018-02-05 12:36:49 +0100100
101 commands = output.splitlines()
102
103 self.assertRegex(commands[0],
104 "{build}\$ cmake -G Ninja .* {sources}".format(
105 build=buildDir, sources=sourceDir))
106
107 self.assertRegex(commands[1],
108 "{build}\$ ninja".format(build=buildDir))
109
110 self.assertRegex(
111 commands[2], ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir))
112
113 self.assertRegex(
114 commands[3],
115 ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format(
116 sandbox=sandboxDir,
117 lnt=lntDir))
118
119 self.assertRegex(
120 commands[4],
121 ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite "
122 "--sandbox={sandbox} --test-suite={testsuite} "
123 "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang".format(
124 sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir))
125
126 def test_default_stage2(self):
127 """
128 Test that we dump the correct commands for a 2-stage build of LLVM.
129 """
Diana Picusfcfc6282018-02-14 18:50:24 +0100130 reposDir = "path-to-repos"
Diana Picusb03e5082018-02-05 12:36:49 +0100131 sourceDir = "path-to-sources"
132 buildDir1 = "path-to-stage1"
133 buildDir2 = "path-to-stage2"
134
135 output = self.run_with_output(
136 self.llvm_build_and_test(
137 "--dry-run",
Diana Picusfcfc6282018-02-14 18:50:24 +0100138 "--repos-dir", reposDir,
Diana Picusb03e5082018-02-05 12:36:49 +0100139 "--source-dir", sourceDir,
140 "--stage1-build-dir", buildDir1,
141 "--stage2-build-dir", buildDir2))
142
143 commands = output.splitlines()
144
145 self.assertRegex(
146 commands[0],
147 "{stage1}\$ cmake -G Ninja .* {sources}".format(
148 stage1=buildDir1, sources=sourceDir))
149
150 self.assertRegex(
151 commands[1],
152 "{stage1}\$ ninja".format(stage1=buildDir1))
153
154 self.assertRegex(
155 commands[2], "{stage2}\$ cmake -G Ninja .* "
156 "-DCMAKE_C_COMPILER={stage1}/bin/clang "
157 "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
158 stage1=buildDir1, stage2=buildDir2, sources=sourceDir))
159
160 self.assertRegex(
161 commands[3],
162 "{stage2}\$ ninja".format(stage2=buildDir2))
163
Diana Picus2c580832018-02-14 14:51:00 +0100164 def test_custom_stage1_default_stage2(self):
165 """
166 Test that we preserve the subprojects, but not the CMake or build flags.
167 """
168 reposDir = "path-to-repos"
169 sourceDir = "path-to-sources"
170 buildDir1 = "path-to-stage1"
171 buildDir2 = "path-to-stage2"
172
173 output = self.run_with_output(
174 self.llvm_build_and_test(
175 "--dry-run",
176 "--repos-dir", reposDir,
177 "--source-dir", sourceDir,
178 "--stage1-build-dir", buildDir1,
179 "--stage1-subproject", "clang",
180 "--stage1-subproject", "compiler-rt",
181 "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm",
182 "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True",
183 "--stage1-build-flag=-j8",
184 "--stage1-build-flag", "check-all",
185 "--stage2-build-dir", buildDir2))
186
187 commands = output.splitlines()
188
189 self.assertRegex(commands[0],
190 "{build}\$ cmake -G Ninja .* {sources}".format(
191 build=buildDir1, sources=sourceDir))
192
193 self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0])
194 self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0])
195 self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0])
196 self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0])
197
198 self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0])
199 self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0])
200
201 self.assertRegex(commands[1],
202 "{build}\$ ninja -j8 check-all".format(build=buildDir1))
203
204 self.assertRegex(
205 commands[2], "{stage2}\$ cmake -G Ninja .* "
206 "-DCMAKE_C_COMPILER={stage1}/bin/clang "
207 "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
208 stage1=buildDir1, stage2=buildDir2, sources=sourceDir))
209
210 self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[2])
211 self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[2])
212 self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[2])
213 self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[2])
214
215 self.assertNotIn("-DCMAKE_CXX_FLAGS=-marm", commands[2])
216 self.assertNotIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[2])
217
218 self.assertRegex(
219 commands[3],
220 "{stage2}\$ ninja".format(stage2=buildDir2))
221
Diana Picus6cdb5162018-02-15 05:29:46 +0100222 def test_custom_both_stages(self):
223 """
224 Test that we get the correct commands when trying to customize both
225 stage 1 and stage 2.
226 """
227 reposDir = "path-to-repos"
228 sourceDir = "path-to-sources"
229 buildDir1 = "path-to-stage1"
230 buildDir2 = "path-to-stage2"
231
232 output = self.run_with_output(
233 self.llvm_build_and_test(
234 "--dry-run",
235 "--repos-dir", reposDir,
236 "--source-dir", sourceDir,
237 "--stage1-build-dir", buildDir1,
238 "--stage1-subproject", "clang",
239 "--stage1-subproject", "compiler-rt",
240 "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm",
241 "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True",
242 "--stage1-build-flag=-j8",
243 "--stage2-build-dir", buildDir2,
244 "--stage2-subproject", "clang",
245 "--stage2-subproject", "libcxx",
246 "--stage2-cmake-def", "CMAKE_BUILD_TYPE=MinSizeRel",
247 "--stage2-build-flag", "check-all"))
248
249 commands = output.splitlines()
250
251 self.assertRegex(commands[0],
252 "{build}\$ cmake -G Ninja .* {sources}".format(
253 build=buildDir1, sources=sourceDir))
254
255 self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0])
256 self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0])
257 self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0])
258 self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0])
259
260 self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0])
261 self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0])
262 self.assertNotIn("-DCMAKE_BUILD_TYPE=MinSizeRel", commands[0])
263
264 self.assertRegex(commands[1],
265 "{build}\$ ninja -j8".format(build=buildDir1))
266
267 self.assertRegex(
268 commands[2], "{stage2}\$ cmake -G Ninja .* "
269 "-DCMAKE_C_COMPILER={stage1}/bin/clang "
270 "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
271 stage1=buildDir1, stage2=buildDir2, sources=sourceDir))
272
273 self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[2])
274 self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=OFF", commands[2])
275 self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=ON", commands[2])
276 self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[2])
277
278 self.assertNotIn("-DCMAKE_CXX_FLAGS=-marm", commands[2])
279 self.assertNotIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[2])
280 self.assertIn("-DCMAKE_BUILD_TYPE=MinSizeRel", commands[2])
281
282 self.assertRegex(
283 commands[3],
284 "{stage2}\$ ninja check-all".format(stage2=buildDir2))
Diana Picus2c580832018-02-14 14:51:00 +0100285
Diana Picusb03e5082018-02-05 12:36:49 +0100286 def test_stage2_and_testsuite(self):
287 """
288 Test that we dump the correct commands for a 2-stage build of LLVM and a
289 run of the test-suite with the resulting compiler.
290 """
Diana Picusfcfc6282018-02-14 18:50:24 +0100291 reposDir = "path-to-repos"
Diana Picusb03e5082018-02-05 12:36:49 +0100292 sourceDir = "path-to-sources"
293 buildDir1 = "path-to-stage1"
294 buildDir2 = "path-to-stage2"
Diana Picusb03e5082018-02-05 12:36:49 +0100295 sandboxDir = "path-to-sandbox"
Diana Picusfcfc6282018-02-14 18:50:24 +0100296
297 testSuiteDir = os.path.join(reposDir, "test-suite")
298 lntDir = os.path.join(reposDir, "lnt")
Diana Picusb03e5082018-02-05 12:36:49 +0100299
300 output = self.run_with_output(
301 self.llvm_build_and_test(
302 "--dry-run",
Diana Picusfcfc6282018-02-14 18:50:24 +0100303 "--repos-dir", reposDir,
Diana Picusb03e5082018-02-05 12:36:49 +0100304 "--source-dir", sourceDir,
305 "--stage1-build-dir", buildDir1,
306 "--stage2-build-dir", buildDir2,
Diana Picusfcfc6282018-02-14 18:50:24 +0100307 "--enable-test-suite",
308 "--sandbox", sandboxDir))
Diana Picusb03e5082018-02-05 12:36:49 +0100309
310 commands = output.splitlines()
311
312 self.assertRegex(
313 commands[0],
314 "{stage1}\$ cmake -G Ninja .* {sources}".format(
315 stage1=buildDir1,
316 sources=sourceDir))
317
318 self.assertRegex(
319 commands[1],
320 "{stage1}\$ ninja".format(stage1=buildDir1))
321
322 self.assertRegex(
323 commands[2], "{stage2}\$ cmake -G Ninja .* "
324 "-DCMAKE_C_COMPILER={stage1}/bin/clang "
325 "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
326 stage1=buildDir1, stage2=buildDir2, sources=sourceDir))
327
328 self.assertRegex(
329 commands[3],
330 "{stage2}\$ ninja".format(stage2=buildDir2))
331
332 self.assertRegex(
333 commands[4],
334 ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir))
335
336 self.assertRegex(
337 commands[5],
338 ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format(
339 sandbox=sandboxDir,
340 lnt=lntDir))
341
342 self.assertRegex(
343 commands[6],
344 ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite "
345 "--sandbox={sandbox} --test-suite={testsuite} "
346 "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang".format(
347 sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir2))