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 |
| 8 | |
| 9 | from llvmtestcase import LLVMTestCase, require_command_arg, debug |
| 10 | |
| 11 | |
| 12 | class 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 Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 22 | reposDir = "path-to-repos" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 23 | 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 Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 29 | "--repos-dir", reposDir, |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 30 | "--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 Picus | 2c58083 | 2018-02-14 14:51:00 +0100 | [diff] [blame] | 42 | 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 Picus | 49ee93a | 2018-02-15 05:52:34 +0100 | [diff] [blame^] | 79 | def test_stage1_and_default_testsuite(self): |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 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 Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 84 | reposDir = "path-to-repos" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 85 | sourceDir = "path-to-sources" |
| 86 | buildDir = "path-to-stage1" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 87 | sandboxDir = "path-to-sandbox" |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 88 | |
| 89 | testSuiteDir = os.path.join(reposDir, "test-suite") |
| 90 | lntDir = os.path.join(reposDir, "lnt") |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 91 | |
| 92 | output = self.run_with_output( |
| 93 | self.llvm_build_and_test( |
| 94 | "--dry-run", |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 95 | "--repos-dir", reposDir, |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 96 | "--source-dir", sourceDir, |
| 97 | "--stage1-build-dir", buildDir, |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 98 | "--enable-test-suite", |
| 99 | "--sandbox", sandboxDir)) |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 100 | |
| 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 Picus | 49ee93a | 2018-02-15 05:52:34 +0100 | [diff] [blame^] | 126 | 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 Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 174 | def test_default_stage2(self): |
| 175 | """ |
| 176 | Test that we dump the correct commands for a 2-stage build of LLVM. |
| 177 | """ |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 178 | reposDir = "path-to-repos" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 179 | 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 Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 186 | "--repos-dir", reposDir, |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 187 | "--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 Picus | 2c58083 | 2018-02-14 14:51:00 +0100 | [diff] [blame] | 212 | 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 Picus | 6cdb516 | 2018-02-15 05:29:46 +0100 | [diff] [blame] | 270 | 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 Picus | 2c58083 | 2018-02-14 14:51:00 +0100 | [diff] [blame] | 333 | |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 334 | 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 Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 339 | reposDir = "path-to-repos" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 340 | sourceDir = "path-to-sources" |
| 341 | buildDir1 = "path-to-stage1" |
| 342 | buildDir2 = "path-to-stage2" |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 343 | sandboxDir = "path-to-sandbox" |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 344 | |
| 345 | testSuiteDir = os.path.join(reposDir, "test-suite") |
| 346 | lntDir = os.path.join(reposDir, "lnt") |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 347 | |
| 348 | output = self.run_with_output( |
| 349 | self.llvm_build_and_test( |
| 350 | "--dry-run", |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 351 | "--repos-dir", reposDir, |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 352 | "--source-dir", sourceDir, |
| 353 | "--stage1-build-dir", buildDir1, |
| 354 | "--stage2-build-dir", buildDir2, |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame] | 355 | "--enable-test-suite", |
| 356 | "--sandbox", sandboxDir)) |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 357 | |
| 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)) |