Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 1 | """Command line interface tests for llvm.py build-and-test. |
| 2 | |
| 3 | Note that although this uses the unittest framework, it does *not* contain unit |
| 4 | tests. |
| 5 | |
| 6 | """ |
| 7 | import os |
Diana Picus | bb6a76e | 2018-02-23 13:18:37 +0100 | [diff] [blame] | 8 | from subprocess import CalledProcessError |
Diana Picus | fec612c | 2018-02-19 19:14:00 +0100 | [diff] [blame] | 9 | from tempfile import NamedTemporaryFile |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 10 | |
| 11 | from llvmtestcase import LLVMTestCase, require_command_arg, debug |
| 12 | |
| 13 | |
| 14 | class Testllvmbuildandtest(LLVMTestCase): |
| 15 | |
| 16 | @classmethod |
| 17 | def llvm_build_and_test(cls, *args, **kwargs): |
| 18 | return cls.command_with_defaults("build-and-test", *args, **kwargs) |
| 19 | |
Diana Picus | fec612c | 2018-02-19 19:14:00 +0100 | [diff] [blame] | 20 | @classmethod |
| 21 | def get_temp_file_with_content(cls, content): |
| 22 | """Return a temporary file with the given content.""" |
| 23 | theFile = NamedTemporaryFile(mode='wt') |
| 24 | print(content, file=theFile, flush=True) |
| 25 | return theFile |
| 26 | |
Diana Picus | c1b4d34 | 2018-02-15 17:09:45 +0100 | [diff] [blame] | 27 | @require_command_arg("--repos") |
| 28 | def test_repos_dir_is_compulsory(self): |
| 29 | """Test that we get an error if we don't pass the path to the repos.""" |
| 30 | self.run_with_output( |
| 31 | self.llvm_build_and_test("--source-dir=somewhere", |
| 32 | "--stage1-build-dir=elsewhere")) |
| 33 | |
| 34 | @require_command_arg("--source-dir") |
| 35 | def test_source_dir_is_compulsory(self): |
| 36 | """Test that we get an error if we don't pass the path to the sources.""" |
| 37 | self.run_with_output( |
| 38 | self.llvm_build_and_test("--repos-dir=somewhere", |
| 39 | "--stage1-build-dir=elsewhere")) |
| 40 | |
| 41 | @require_command_arg("--stage1-build-dir") |
| 42 | def test_stage1_build_dir_is_compulsory(self): |
| 43 | """ |
| 44 | Test that we get an error if we don't pass the path to the stage 1 |
| 45 | build directory. |
| 46 | """ |
| 47 | self.run_with_output( |
| 48 | self.llvm_build_and_test("--repos-dir=somewhere", |
| 49 | "--source-dir=elsewhere")) |
| 50 | |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 51 | def test_default_stage1(self): |
| 52 | """ |
| 53 | Test that we dump the correct commands for a single stage build of LLVM. |
| 54 | """ |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 55 | reposDir = "path-to-repos" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 56 | sourceDir = "path-to-sources" |
| 57 | buildDir = "path-to-stage1" |
| 58 | |
| 59 | output = self.run_with_output( |
| 60 | self.llvm_build_and_test( |
| 61 | "--dry-run", |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 62 | "--repos-dir", reposDir, |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 63 | "--source-dir", sourceDir, |
| 64 | "--stage1-build-dir", buildDir)) |
| 65 | |
| 66 | commands = output.splitlines() |
| 67 | |
| 68 | self.assertRegex(commands[0], |
| 69 | "{build}\$ cmake -G Ninja .* {sources}".format( |
| 70 | build=buildDir, sources=sourceDir)) |
| 71 | |
| 72 | self.assertRegex(commands[1], |
| 73 | "{build}\$ ninja".format(build=buildDir)) |
| 74 | |
Diana Picus | 2c58083 | 2018-02-14 14:51:00 +0100 | [diff] [blame] | 75 | def test_custom_stage1(self): |
| 76 | """Test that we can customize the first stage of the build.""" |
| 77 | reposDir = "path-to-repos" |
| 78 | sourceDir = "path-to-sources" |
| 79 | buildDir = "path-to-stage1" |
| 80 | |
| 81 | output = self.run_with_output( |
| 82 | self.llvm_build_and_test( |
| 83 | "--dry-run", |
| 84 | "--repos-dir", reposDir, |
| 85 | "--source-dir", sourceDir, |
| 86 | "--stage1-build-dir", buildDir, |
| 87 | "--stage1-subproject", "clang", |
| 88 | "--stage1-subproject", "compiler-rt", |
| 89 | "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm", |
| 90 | "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True", |
| 91 | "--stage1-build-flag=-j8", |
| 92 | "--stage1-build-flag", "check-all")) |
| 93 | |
| 94 | commands = output.splitlines() |
| 95 | |
| 96 | self.assertRegex(commands[0], |
| 97 | "{build}\$ cmake -G Ninja .* {sources}".format( |
| 98 | build=buildDir, sources=sourceDir)) |
| 99 | |
| 100 | self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0]) |
| 101 | self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0]) |
| 102 | self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0]) |
| 103 | self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0]) |
| 104 | |
| 105 | self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0]) |
| 106 | self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0]) |
| 107 | |
| 108 | self.assertRegex(commands[1], |
| 109 | "{build}\$ ninja -j8 check-all".format(build=buildDir)) |
| 110 | |
| 111 | |
Diana Picus | 49ee93a | 2018-02-15 05:52:34 +0100 | [diff] [blame] | 112 | def test_stage1_and_default_testsuite(self): |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 113 | """ |
| 114 | Test that we dump the correct commands for a single stage build of LLVM |
| 115 | and a run of the test-suite with the resulting compiler. |
| 116 | """ |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 117 | reposDir = "path-to-repos" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 118 | sourceDir = "path-to-sources" |
| 119 | buildDir = "path-to-stage1" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 120 | sandboxDir = "path-to-sandbox" |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 121 | |
| 122 | testSuiteDir = os.path.join(reposDir, "test-suite") |
| 123 | lntDir = os.path.join(reposDir, "lnt") |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 124 | |
| 125 | output = self.run_with_output( |
| 126 | self.llvm_build_and_test( |
| 127 | "--dry-run", |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 128 | "--repos-dir", reposDir, |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 129 | "--source-dir", sourceDir, |
| 130 | "--stage1-build-dir", buildDir, |
Diana Picus | bb6a76e | 2018-02-23 13:18:37 +0100 | [diff] [blame] | 131 | "--stage1-subproject", "clang", |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 132 | "--enable-test-suite", |
| 133 | "--sandbox", sandboxDir)) |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 134 | |
| 135 | commands = output.splitlines() |
| 136 | |
| 137 | self.assertRegex(commands[0], |
| 138 | "{build}\$ cmake -G Ninja .* {sources}".format( |
| 139 | build=buildDir, sources=sourceDir)) |
| 140 | |
| 141 | self.assertRegex(commands[1], |
| 142 | "{build}\$ ninja".format(build=buildDir)) |
| 143 | |
| 144 | self.assertRegex( |
| 145 | commands[2], ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir)) |
| 146 | |
| 147 | self.assertRegex( |
| 148 | commands[3], |
| 149 | ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format( |
| 150 | sandbox=sandboxDir, |
| 151 | lnt=lntDir)) |
| 152 | |
| 153 | self.assertRegex( |
| 154 | commands[4], |
| 155 | ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite " |
| 156 | "--sandbox={sandbox} --test-suite={testsuite} " |
| 157 | "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang".format( |
| 158 | sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir)) |
| 159 | |
Diana Picus | 49ee93a | 2018-02-15 05:52:34 +0100 | [diff] [blame] | 160 | def test_stage1_and_custom_testsuite(self): |
| 161 | """Test that we can add custom flags to our test-suite run.""" |
| 162 | reposDir = "path-to-repos" |
| 163 | sourceDir = "path-to-sources" |
| 164 | buildDir = "path-to-stage1" |
| 165 | sandboxDir = "path-to-sandbox" |
| 166 | |
| 167 | testSuiteDir = os.path.join(reposDir, "test-suite") |
| 168 | lntDir = os.path.join(reposDir, "lnt") |
| 169 | |
| 170 | output = self.run_with_output( |
| 171 | self.llvm_build_and_test( |
| 172 | "--dry-run", |
| 173 | "--repos-dir", reposDir, |
| 174 | "--source-dir", sourceDir, |
| 175 | "--stage1-build-dir", buildDir, |
Diana Picus | bb6a76e | 2018-02-23 13:18:37 +0100 | [diff] [blame] | 176 | "--stage1-subproject", "clang", |
Diana Picus | 49ee93a | 2018-02-15 05:52:34 +0100 | [diff] [blame] | 177 | "--enable-test-suite", |
| 178 | "--sandbox", sandboxDir, |
| 179 | "--lnt-flag=--threads=4", |
| 180 | "--lnt-flag=--cppflags", |
| 181 | "--lnt-flag", "'-mcpu=cortex-a15 -marm'")) |
| 182 | |
| 183 | commands = output.splitlines() |
| 184 | |
| 185 | self.assertRegex(commands[0], |
| 186 | "{build}\$ cmake -G Ninja .* {sources}".format( |
| 187 | build=buildDir, sources=sourceDir)) |
| 188 | |
| 189 | self.assertRegex(commands[1], |
| 190 | "{build}\$ ninja".format(build=buildDir)) |
| 191 | |
| 192 | self.assertRegex( |
| 193 | commands[2], ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir)) |
| 194 | |
| 195 | self.assertRegex( |
| 196 | commands[3], |
| 197 | ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format( |
| 198 | sandbox=sandboxDir, |
| 199 | lnt=lntDir)) |
| 200 | |
| 201 | self.assertRegex( |
| 202 | commands[4], |
| 203 | ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite " |
| 204 | "--sandbox={sandbox} --test-suite={testsuite} " |
| 205 | "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang " |
| 206 | "--threads=4 --cppflags '-mcpu=cortex-a15 -marm'".format( |
| 207 | sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir)) |
| 208 | |
Diana Picus | bb6a76e | 2018-02-23 13:18:37 +0100 | [diff] [blame] | 209 | def test_stage1_needs_clang_if_testsuite_is_enabled(self): |
| 210 | """ |
| 211 | Test that we error out early on if we enable the test-suite but don't |
| 212 | add clang to stage 1. |
| 213 | """ |
| 214 | reposDir = "path-to-repos" |
| 215 | sourceDir = "path-to-sources" |
| 216 | buildDir = "path-to-stage1" |
| 217 | sandboxDir = "path-to-sandbox" |
| 218 | |
| 219 | testSuiteDir = os.path.join(reposDir, "test-suite") |
| 220 | lntDir = os.path.join(reposDir, "lnt") |
| 221 | |
| 222 | with self.assertRaises(CalledProcessError) as context: |
| 223 | output = self.run_with_output( |
| 224 | self.llvm_build_and_test( |
| 225 | "--dry-run", |
| 226 | "--repos-dir", reposDir, |
| 227 | "--source-dir", sourceDir, |
| 228 | "--stage1-build-dir", buildDir, |
| 229 | "--enable-test-suite", |
| 230 | "--sandbox", sandboxDir)) |
| 231 | |
| 232 | self.assertIn( |
| 233 | "Can't enable the test-suite if stage 1 doesn't build clang", |
| 234 | str(context.exception.output)) |
| 235 | |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 236 | def test_default_stage2(self): |
| 237 | """ |
| 238 | Test that we dump the correct commands for a 2-stage build of LLVM. |
| 239 | """ |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 240 | reposDir = "path-to-repos" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 241 | sourceDir = "path-to-sources" |
| 242 | buildDir1 = "path-to-stage1" |
| 243 | buildDir2 = "path-to-stage2" |
| 244 | |
| 245 | output = self.run_with_output( |
| 246 | self.llvm_build_and_test( |
| 247 | "--dry-run", |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 248 | "--repos-dir", reposDir, |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 249 | "--source-dir", sourceDir, |
| 250 | "--stage1-build-dir", buildDir1, |
Diana Picus | bb6a76e | 2018-02-23 13:18:37 +0100 | [diff] [blame] | 251 | "--stage1-subproject", "clang", |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 252 | "--stage2-build-dir", buildDir2)) |
| 253 | |
| 254 | commands = output.splitlines() |
| 255 | |
| 256 | self.assertRegex( |
| 257 | commands[0], |
| 258 | "{stage1}\$ cmake -G Ninja .* {sources}".format( |
| 259 | stage1=buildDir1, sources=sourceDir)) |
| 260 | |
| 261 | self.assertRegex( |
| 262 | commands[1], |
| 263 | "{stage1}\$ ninja".format(stage1=buildDir1)) |
| 264 | |
| 265 | self.assertRegex( |
| 266 | commands[2], "{stage2}\$ cmake -G Ninja .* " |
| 267 | "-DCMAKE_C_COMPILER={stage1}/bin/clang " |
| 268 | "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format( |
| 269 | stage1=buildDir1, stage2=buildDir2, sources=sourceDir)) |
| 270 | |
| 271 | self.assertRegex( |
| 272 | commands[3], |
| 273 | "{stage2}\$ ninja".format(stage2=buildDir2)) |
| 274 | |
Diana Picus | 2c58083 | 2018-02-14 14:51:00 +0100 | [diff] [blame] | 275 | def test_custom_stage1_default_stage2(self): |
| 276 | """ |
| 277 | Test that we preserve the subprojects, but not the CMake or build flags. |
| 278 | """ |
| 279 | reposDir = "path-to-repos" |
| 280 | sourceDir = "path-to-sources" |
| 281 | buildDir1 = "path-to-stage1" |
| 282 | buildDir2 = "path-to-stage2" |
| 283 | |
| 284 | output = self.run_with_output( |
| 285 | self.llvm_build_and_test( |
| 286 | "--dry-run", |
| 287 | "--repos-dir", reposDir, |
| 288 | "--source-dir", sourceDir, |
| 289 | "--stage1-build-dir", buildDir1, |
| 290 | "--stage1-subproject", "clang", |
| 291 | "--stage1-subproject", "compiler-rt", |
| 292 | "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm", |
| 293 | "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True", |
| 294 | "--stage1-build-flag=-j8", |
| 295 | "--stage1-build-flag", "check-all", |
| 296 | "--stage2-build-dir", buildDir2)) |
| 297 | |
| 298 | commands = output.splitlines() |
| 299 | |
| 300 | self.assertRegex(commands[0], |
| 301 | "{build}\$ cmake -G Ninja .* {sources}".format( |
| 302 | build=buildDir1, sources=sourceDir)) |
| 303 | |
| 304 | self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0]) |
| 305 | self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0]) |
| 306 | self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0]) |
| 307 | self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0]) |
| 308 | |
| 309 | self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0]) |
| 310 | self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0]) |
| 311 | |
| 312 | self.assertRegex(commands[1], |
| 313 | "{build}\$ ninja -j8 check-all".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=ON", commands[2]) |
| 323 | self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", 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 | |
| 329 | self.assertRegex( |
| 330 | commands[3], |
| 331 | "{stage2}\$ ninja".format(stage2=buildDir2)) |
| 332 | |
Diana Picus | 6cdb516 | 2018-02-15 05:29:46 +0100 | [diff] [blame] | 333 | def test_custom_both_stages(self): |
| 334 | """ |
| 335 | Test that we get the correct commands when trying to customize both |
| 336 | stage 1 and stage 2. |
| 337 | """ |
| 338 | reposDir = "path-to-repos" |
| 339 | sourceDir = "path-to-sources" |
| 340 | buildDir1 = "path-to-stage1" |
| 341 | buildDir2 = "path-to-stage2" |
| 342 | |
| 343 | output = self.run_with_output( |
| 344 | self.llvm_build_and_test( |
| 345 | "--dry-run", |
| 346 | "--repos-dir", reposDir, |
| 347 | "--source-dir", sourceDir, |
| 348 | "--stage1-build-dir", buildDir1, |
| 349 | "--stage1-subproject", "clang", |
| 350 | "--stage1-subproject", "compiler-rt", |
| 351 | "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm", |
| 352 | "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True", |
| 353 | "--stage1-build-flag=-j8", |
| 354 | "--stage2-build-dir", buildDir2, |
| 355 | "--stage2-subproject", "clang", |
| 356 | "--stage2-subproject", "libcxx", |
| 357 | "--stage2-cmake-def", "CMAKE_BUILD_TYPE=MinSizeRel", |
| 358 | "--stage2-build-flag", "check-all")) |
| 359 | |
| 360 | commands = output.splitlines() |
| 361 | |
| 362 | self.assertRegex(commands[0], |
| 363 | "{build}\$ cmake -G Ninja .* {sources}".format( |
| 364 | build=buildDir1, sources=sourceDir)) |
| 365 | |
| 366 | self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0]) |
| 367 | self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0]) |
| 368 | self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0]) |
| 369 | self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0]) |
| 370 | |
| 371 | self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0]) |
| 372 | self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0]) |
| 373 | self.assertNotIn("-DCMAKE_BUILD_TYPE=MinSizeRel", commands[0]) |
| 374 | |
| 375 | self.assertRegex(commands[1], |
| 376 | "{build}\$ ninja -j8".format(build=buildDir1)) |
| 377 | |
| 378 | self.assertRegex( |
| 379 | commands[2], "{stage2}\$ cmake -G Ninja .* " |
| 380 | "-DCMAKE_C_COMPILER={stage1}/bin/clang " |
| 381 | "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format( |
| 382 | stage1=buildDir1, stage2=buildDir2, sources=sourceDir)) |
| 383 | |
| 384 | self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[2]) |
| 385 | self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=OFF", commands[2]) |
| 386 | self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=ON", commands[2]) |
| 387 | self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[2]) |
| 388 | |
| 389 | self.assertNotIn("-DCMAKE_CXX_FLAGS=-marm", commands[2]) |
| 390 | self.assertNotIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[2]) |
| 391 | self.assertIn("-DCMAKE_BUILD_TYPE=MinSizeRel", commands[2]) |
| 392 | |
| 393 | self.assertRegex( |
| 394 | commands[3], |
| 395 | "{stage2}\$ ninja check-all".format(stage2=buildDir2)) |
Diana Picus | 2c58083 | 2018-02-14 14:51:00 +0100 | [diff] [blame] | 396 | |
Diana Picus | bb6a76e | 2018-02-23 13:18:37 +0100 | [diff] [blame] | 397 | def test_stage1_needs_clang_if_stage2_is_enabled(self): |
| 398 | """ |
| 399 | Test that we can't enable stage 2 unless stage 1 builds clang. |
| 400 | """ |
| 401 | reposDir = "path-to-repos" |
| 402 | sourceDir = "path-to-sources" |
| 403 | buildDir1 = "path-to-stage1" |
| 404 | buildDir2 = "path-to-stage2" |
| 405 | |
| 406 | with self.assertRaises(CalledProcessError) as context: |
| 407 | output = self.run_with_output( |
| 408 | self.llvm_build_and_test( |
| 409 | "--dry-run", |
| 410 | "--repos-dir", reposDir, |
| 411 | "--source-dir", sourceDir, |
| 412 | "--stage1-build-dir", buildDir1, |
| 413 | "--stage2-build-dir", buildDir2)) |
| 414 | |
| 415 | self.assertIn( |
| 416 | "Can't enable stage 2 if stage 1 doesn't build clang", |
| 417 | str(context.exception.output)) |
| 418 | |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 419 | def test_stage2_and_testsuite(self): |
| 420 | """ |
| 421 | Test that we dump the correct commands for a 2-stage build of LLVM and a |
| 422 | run of the test-suite with the resulting compiler. |
| 423 | """ |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 424 | reposDir = "path-to-repos" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 425 | sourceDir = "path-to-sources" |
| 426 | buildDir1 = "path-to-stage1" |
| 427 | buildDir2 = "path-to-stage2" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 428 | sandboxDir = "path-to-sandbox" |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 429 | |
| 430 | testSuiteDir = os.path.join(reposDir, "test-suite") |
| 431 | lntDir = os.path.join(reposDir, "lnt") |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 432 | |
| 433 | output = self.run_with_output( |
| 434 | self.llvm_build_and_test( |
| 435 | "--dry-run", |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 436 | "--repos-dir", reposDir, |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 437 | "--source-dir", sourceDir, |
| 438 | "--stage1-build-dir", buildDir1, |
Diana Picus | bb6a76e | 2018-02-23 13:18:37 +0100 | [diff] [blame] | 439 | "--stage1-subproject", "clang", |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 440 | "--stage2-build-dir", buildDir2, |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 441 | "--enable-test-suite", |
| 442 | "--sandbox", sandboxDir)) |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 443 | |
| 444 | commands = output.splitlines() |
| 445 | |
| 446 | self.assertRegex( |
| 447 | commands[0], |
| 448 | "{stage1}\$ cmake -G Ninja .* {sources}".format( |
| 449 | stage1=buildDir1, |
| 450 | sources=sourceDir)) |
| 451 | |
| 452 | self.assertRegex( |
| 453 | commands[1], |
| 454 | "{stage1}\$ ninja".format(stage1=buildDir1)) |
| 455 | |
| 456 | self.assertRegex( |
| 457 | commands[2], "{stage2}\$ cmake -G Ninja .* " |
| 458 | "-DCMAKE_C_COMPILER={stage1}/bin/clang " |
| 459 | "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format( |
| 460 | stage1=buildDir1, stage2=buildDir2, sources=sourceDir)) |
| 461 | |
| 462 | self.assertRegex( |
| 463 | commands[3], |
| 464 | "{stage2}\$ ninja".format(stage2=buildDir2)) |
| 465 | |
| 466 | self.assertRegex( |
| 467 | commands[4], |
| 468 | ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir)) |
| 469 | |
| 470 | self.assertRegex( |
| 471 | commands[5], |
| 472 | ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format( |
| 473 | sandbox=sandboxDir, |
| 474 | lnt=lntDir)) |
| 475 | |
| 476 | self.assertRegex( |
| 477 | commands[6], |
| 478 | ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite " |
| 479 | "--sandbox={sandbox} --test-suite={testsuite} " |
| 480 | "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang".format( |
| 481 | sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir2)) |
Diana Picus | fec612c | 2018-02-19 19:14:00 +0100 | [diff] [blame] | 482 | |
| 483 | def test_read_flags_from_file(self): |
| 484 | """Test that we can read our flags from a configuration file.""" |
| 485 | reposDir = "path-to-repos" |
| 486 | sourceDir = "path-to-sources" |
| 487 | buildDir = "path-to-stage1" |
| 488 | |
| 489 | flagsInFile = ("--dry-run\n" |
| 490 | "--repos-dir\n" |
| 491 | "{repos}\n" |
| 492 | "--source-dir\n" |
| 493 | "{sources}\n" |
| 494 | "--stage1-build-dir\n" |
| 495 | "{build}").format( |
| 496 | repos=reposDir, sources=sourceDir, build=buildDir) |
| 497 | |
| 498 | with self.get_temp_file_with_content(flagsInFile) as configFile: |
| 499 | output = self.run_with_output( |
| 500 | self.llvm_build_and_test("@{}".format(configFile.name))) |
| 501 | |
| 502 | commands = output.splitlines() |
| 503 | |
| 504 | self.assertRegex(commands[0], |
| 505 | "{build}\$ cmake -G Ninja .* {sources}".format( |
| 506 | build=buildDir, sources=sourceDir)) |
| 507 | |
| 508 | self.assertRegex(commands[1], |
| 509 | "{build}\$ ninja".format(build=buildDir)) |
| 510 | |
| 511 | def test_override_flags_from_file(self): |
| 512 | """ |
| 513 | Test that we can combine flags from a configuration file and command |
| 514 | line flags. The command line flags that come before the name of the |
| 515 | configuration file should be overriden by those from the file, whereas |
| 516 | command line flags that come after the name of the configuration file |
| 517 | should override the values found in the file. For arguments that can be |
| 518 | passed multiple times, all the values are collected (both from the |
| 519 | command line and from the config file). They should however appear in |
| 520 | the order that they were given. |
| 521 | """ |
| 522 | reposDir = "path-to-repos" |
| 523 | sourceDir = "path-to-sources" |
| 524 | buildDir = "path-to-stage1" |
| 525 | |
| 526 | overridenSourceDir = "overriden-sources" |
| 527 | overridenBuildDir = "overriden-build" |
| 528 | |
| 529 | flagsInFile = ( |
| 530 | "--dry-run\n" |
| 531 | "--repos-dir\n" |
| 532 | "{repos}\n" |
| 533 | "--source-dir\n" |
| 534 | "{sources}\n" |
| 535 | "--stage1-build-dir\n" |
| 536 | "{build}\n" |
| 537 | "--stage1-subproject\n" |
| 538 | "clang\n" |
| 539 | "--stage1-cmake-def\n" |
| 540 | "CMAKE_CXX_FLAGS=-mthumb").format(repos=reposDir, sources=sourceDir, |
| 541 | build=overridenBuildDir) |
| 542 | |
| 543 | with self.get_temp_file_with_content(flagsInFile) as configFile: |
| 544 | output = self.run_with_output( |
| 545 | self.llvm_build_and_test( |
| 546 | # This should be overriden by the value in the config file. |
| 547 | "--source-dir", overridenSourceDir, |
| 548 | # This should be appended to the value in the config file. |
| 549 | "--stage1-subproject", "lld", |
| 550 | # The config file. |
| 551 | "@{}".format(configFile.name), |
| 552 | # This should override the value in the config file. |
| 553 | "--stage1-build-dir", buildDir, |
| 554 | # These should be appended to the values in the config file. |
| 555 | "--stage1-subproject", "compiler-rt", |
| 556 | "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm", |
| 557 | "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True")) |
| 558 | |
| 559 | commands = output.splitlines() |
| 560 | |
| 561 | self.assertRegex(commands[0], |
| 562 | "{build}\$ cmake -G Ninja .* {sources}".format( |
| 563 | build=buildDir, sources=sourceDir)) |
| 564 | |
| 565 | self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0]) |
| 566 | self.assertIn("-DLLVM_TOOL_LLD_BUILD=ON", commands[0]) |
| 567 | self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0]) |
| 568 | self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0]) |
| 569 | self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0]) |
| 570 | |
| 571 | self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0]) |
| 572 | self.assertIn("-DCMAKE_CXX_FLAGS=-mthumb", commands[0]) |
| 573 | self.assertLess(commands[0].find("-DCMAKE_CXX_FLAGS=-mthumb"), |
| 574 | commands[0].find("-DCMAKE_CXX_FLAGS=-marm")) |
| 575 | self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0]) |
| 576 | |
| 577 | self.assertRegex(commands[1], |
| 578 | "{build}\$ ninja".format(build=buildDir)) |