blob: 86e2203b1f78f0a58cdd2cb1038d96daef6debf0 [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 Picus49ee93a2018-02-15 05:52:34 +010079 def test_stage1_and_default_testsuite(self):
Diana Picusb03e5082018-02-05 12:36:49 +010080 """
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
Diana Picus49ee93a2018-02-15 05:52:34 +0100126 def test_stage1_and_custom_testsuite(self):
127 """Test that we can add custom flags to our test-suite run."""
128 reposDir = "path-to-repos"
129 sourceDir = "path-to-sources"
130 buildDir = "path-to-stage1"
131 sandboxDir = "path-to-sandbox"
132
133 testSuiteDir = os.path.join(reposDir, "test-suite")
134 lntDir = os.path.join(reposDir, "lnt")
135
136 output = self.run_with_output(
137 self.llvm_build_and_test(
138 "--dry-run",
139 "--repos-dir", reposDir,
140 "--source-dir", sourceDir,
141 "--stage1-build-dir", buildDir,
142 "--enable-test-suite",
143 "--sandbox", sandboxDir,
144 "--lnt-flag=--threads=4",
145 "--lnt-flag=--cppflags",
146 "--lnt-flag", "'-mcpu=cortex-a15 -marm'"))
147
148 commands = output.splitlines()
149
150 self.assertRegex(commands[0],
151 "{build}\$ cmake -G Ninja .* {sources}".format(
152 build=buildDir, sources=sourceDir))
153
154 self.assertRegex(commands[1],
155 "{build}\$ ninja".format(build=buildDir))
156
157 self.assertRegex(
158 commands[2], ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir))
159
160 self.assertRegex(
161 commands[3],
162 ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format(
163 sandbox=sandboxDir,
164 lnt=lntDir))
165
166 self.assertRegex(
167 commands[4],
168 ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite "
169 "--sandbox={sandbox} --test-suite={testsuite} "
170 "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang "
171 "--threads=4 --cppflags '-mcpu=cortex-a15 -marm'".format(
172 sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir))
173
Diana Picusb03e5082018-02-05 12:36:49 +0100174 def test_default_stage2(self):
175 """
176 Test that we dump the correct commands for a 2-stage build of LLVM.
177 """
Diana Picusfcfc6282018-02-14 18:50:24 +0100178 reposDir = "path-to-repos"
Diana Picusb03e5082018-02-05 12:36:49 +0100179 sourceDir = "path-to-sources"
180 buildDir1 = "path-to-stage1"
181 buildDir2 = "path-to-stage2"
182
183 output = self.run_with_output(
184 self.llvm_build_and_test(
185 "--dry-run",
Diana Picusfcfc6282018-02-14 18:50:24 +0100186 "--repos-dir", reposDir,
Diana Picusb03e5082018-02-05 12:36:49 +0100187 "--source-dir", sourceDir,
188 "--stage1-build-dir", buildDir1,
189 "--stage2-build-dir", buildDir2))
190
191 commands = output.splitlines()
192
193 self.assertRegex(
194 commands[0],
195 "{stage1}\$ cmake -G Ninja .* {sources}".format(
196 stage1=buildDir1, sources=sourceDir))
197
198 self.assertRegex(
199 commands[1],
200 "{stage1}\$ ninja".format(stage1=buildDir1))
201
202 self.assertRegex(
203 commands[2], "{stage2}\$ cmake -G Ninja .* "
204 "-DCMAKE_C_COMPILER={stage1}/bin/clang "
205 "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
206 stage1=buildDir1, stage2=buildDir2, sources=sourceDir))
207
208 self.assertRegex(
209 commands[3],
210 "{stage2}\$ ninja".format(stage2=buildDir2))
211
Diana Picus2c580832018-02-14 14:51:00 +0100212 def test_custom_stage1_default_stage2(self):
213 """
214 Test that we preserve the subprojects, but not the CMake or build flags.
215 """
216 reposDir = "path-to-repos"
217 sourceDir = "path-to-sources"
218 buildDir1 = "path-to-stage1"
219 buildDir2 = "path-to-stage2"
220
221 output = self.run_with_output(
222 self.llvm_build_and_test(
223 "--dry-run",
224 "--repos-dir", reposDir,
225 "--source-dir", sourceDir,
226 "--stage1-build-dir", buildDir1,
227 "--stage1-subproject", "clang",
228 "--stage1-subproject", "compiler-rt",
229 "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm",
230 "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True",
231 "--stage1-build-flag=-j8",
232 "--stage1-build-flag", "check-all",
233 "--stage2-build-dir", buildDir2))
234
235 commands = output.splitlines()
236
237 self.assertRegex(commands[0],
238 "{build}\$ cmake -G Ninja .* {sources}".format(
239 build=buildDir1, sources=sourceDir))
240
241 self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0])
242 self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0])
243 self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0])
244 self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0])
245
246 self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0])
247 self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0])
248
249 self.assertRegex(commands[1],
250 "{build}\$ ninja -j8 check-all".format(build=buildDir1))
251
252 self.assertRegex(
253 commands[2], "{stage2}\$ cmake -G Ninja .* "
254 "-DCMAKE_C_COMPILER={stage1}/bin/clang "
255 "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
256 stage1=buildDir1, stage2=buildDir2, sources=sourceDir))
257
258 self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[2])
259 self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[2])
260 self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[2])
261 self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[2])
262
263 self.assertNotIn("-DCMAKE_CXX_FLAGS=-marm", commands[2])
264 self.assertNotIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[2])
265
266 self.assertRegex(
267 commands[3],
268 "{stage2}\$ ninja".format(stage2=buildDir2))
269
Diana Picus6cdb5162018-02-15 05:29:46 +0100270 def test_custom_both_stages(self):
271 """
272 Test that we get the correct commands when trying to customize both
273 stage 1 and stage 2.
274 """
275 reposDir = "path-to-repos"
276 sourceDir = "path-to-sources"
277 buildDir1 = "path-to-stage1"
278 buildDir2 = "path-to-stage2"
279
280 output = self.run_with_output(
281 self.llvm_build_and_test(
282 "--dry-run",
283 "--repos-dir", reposDir,
284 "--source-dir", sourceDir,
285 "--stage1-build-dir", buildDir1,
286 "--stage1-subproject", "clang",
287 "--stage1-subproject", "compiler-rt",
288 "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm",
289 "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True",
290 "--stage1-build-flag=-j8",
291 "--stage2-build-dir", buildDir2,
292 "--stage2-subproject", "clang",
293 "--stage2-subproject", "libcxx",
294 "--stage2-cmake-def", "CMAKE_BUILD_TYPE=MinSizeRel",
295 "--stage2-build-flag", "check-all"))
296
297 commands = output.splitlines()
298
299 self.assertRegex(commands[0],
300 "{build}\$ cmake -G Ninja .* {sources}".format(
301 build=buildDir1, sources=sourceDir))
302
303 self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0])
304 self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0])
305 self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0])
306 self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0])
307
308 self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0])
309 self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0])
310 self.assertNotIn("-DCMAKE_BUILD_TYPE=MinSizeRel", commands[0])
311
312 self.assertRegex(commands[1],
313 "{build}\$ ninja -j8".format(build=buildDir1))
314
315 self.assertRegex(
316 commands[2], "{stage2}\$ cmake -G Ninja .* "
317 "-DCMAKE_C_COMPILER={stage1}/bin/clang "
318 "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
319 stage1=buildDir1, stage2=buildDir2, sources=sourceDir))
320
321 self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[2])
322 self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=OFF", commands[2])
323 self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=ON", commands[2])
324 self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[2])
325
326 self.assertNotIn("-DCMAKE_CXX_FLAGS=-marm", commands[2])
327 self.assertNotIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[2])
328 self.assertIn("-DCMAKE_BUILD_TYPE=MinSizeRel", commands[2])
329
330 self.assertRegex(
331 commands[3],
332 "{stage2}\$ ninja check-all".format(stage2=buildDir2))
Diana Picus2c580832018-02-14 14:51:00 +0100333
Diana Picusb03e5082018-02-05 12:36:49 +0100334 def test_stage2_and_testsuite(self):
335 """
336 Test that we dump the correct commands for a 2-stage build of LLVM and a
337 run of the test-suite with the resulting compiler.
338 """
Diana Picusfcfc6282018-02-14 18:50:24 +0100339 reposDir = "path-to-repos"
Diana Picusb03e5082018-02-05 12:36:49 +0100340 sourceDir = "path-to-sources"
341 buildDir1 = "path-to-stage1"
342 buildDir2 = "path-to-stage2"
Diana Picusb03e5082018-02-05 12:36:49 +0100343 sandboxDir = "path-to-sandbox"
Diana Picusfcfc6282018-02-14 18:50:24 +0100344
345 testSuiteDir = os.path.join(reposDir, "test-suite")
346 lntDir = os.path.join(reposDir, "lnt")
Diana Picusb03e5082018-02-05 12:36:49 +0100347
348 output = self.run_with_output(
349 self.llvm_build_and_test(
350 "--dry-run",
Diana Picusfcfc6282018-02-14 18:50:24 +0100351 "--repos-dir", reposDir,
Diana Picusb03e5082018-02-05 12:36:49 +0100352 "--source-dir", sourceDir,
353 "--stage1-build-dir", buildDir1,
354 "--stage2-build-dir", buildDir2,
Diana Picusfcfc6282018-02-14 18:50:24 +0100355 "--enable-test-suite",
356 "--sandbox", sandboxDir))
Diana Picusb03e5082018-02-05 12:36:49 +0100357
358 commands = output.splitlines()
359
360 self.assertRegex(
361 commands[0],
362 "{stage1}\$ cmake -G Ninja .* {sources}".format(
363 stage1=buildDir1,
364 sources=sourceDir))
365
366 self.assertRegex(
367 commands[1],
368 "{stage1}\$ ninja".format(stage1=buildDir1))
369
370 self.assertRegex(
371 commands[2], "{stage2}\$ cmake -G Ninja .* "
372 "-DCMAKE_C_COMPILER={stage1}/bin/clang "
373 "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
374 stage1=buildDir1, stage2=buildDir2, sources=sourceDir))
375
376 self.assertRegex(
377 commands[3],
378 "{stage2}\$ ninja".format(stage2=buildDir2))
379
380 self.assertRegex(
381 commands[4],
382 ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir))
383
384 self.assertRegex(
385 commands[5],
386 ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format(
387 sandbox=sandboxDir,
388 lnt=lntDir))
389
390 self.assertRegex(
391 commands[6],
392 ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite "
393 "--sandbox={sandbox} --test-suite={testsuite} "
394 "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang".format(
395 sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir2))