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 | """ |
| 22 | sourceDir = "path-to-sources" |
| 23 | buildDir = "path-to-stage1" |
| 24 | |
| 25 | output = self.run_with_output( |
| 26 | self.llvm_build_and_test( |
| 27 | "--dry-run", |
| 28 | "--source-dir", sourceDir, |
| 29 | "--stage1-build-dir", buildDir)) |
| 30 | |
| 31 | commands = output.splitlines() |
| 32 | |
| 33 | self.assertRegex(commands[0], |
| 34 | "{build}\$ cmake -G Ninja .* {sources}".format( |
| 35 | build=buildDir, sources=sourceDir)) |
| 36 | |
| 37 | self.assertRegex(commands[1], |
| 38 | "{build}\$ ninja".format(build=buildDir)) |
| 39 | |
| 40 | def test_stage1_and_testsuite(self): |
| 41 | """ |
| 42 | Test that we dump the correct commands for a single stage build of LLVM |
| 43 | and a run of the test-suite with the resulting compiler. |
| 44 | """ |
| 45 | sourceDir = "path-to-sources" |
| 46 | buildDir = "path-to-stage1" |
| 47 | testSuiteDir = "path-to-test-suite" |
| 48 | sandboxDir = "path-to-sandbox" |
| 49 | lntDir = "path-to-lnt" |
| 50 | |
| 51 | output = self.run_with_output( |
| 52 | self.llvm_build_and_test( |
| 53 | "--dry-run", |
| 54 | "--source-dir", sourceDir, |
| 55 | "--stage1-build-dir", buildDir, |
| 56 | "--test-suite", testSuiteDir, |
| 57 | "--sandbox", sandboxDir, |
| 58 | "--lnt", lntDir)) |
| 59 | |
| 60 | commands = output.splitlines() |
| 61 | |
| 62 | self.assertRegex(commands[0], |
| 63 | "{build}\$ cmake -G Ninja .* {sources}".format( |
| 64 | build=buildDir, sources=sourceDir)) |
| 65 | |
| 66 | self.assertRegex(commands[1], |
| 67 | "{build}\$ ninja".format(build=buildDir)) |
| 68 | |
| 69 | self.assertRegex( |
| 70 | commands[2], ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir)) |
| 71 | |
| 72 | self.assertRegex( |
| 73 | commands[3], |
| 74 | ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format( |
| 75 | sandbox=sandboxDir, |
| 76 | lnt=lntDir)) |
| 77 | |
| 78 | self.assertRegex( |
| 79 | commands[4], |
| 80 | ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite " |
| 81 | "--sandbox={sandbox} --test-suite={testsuite} " |
| 82 | "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang".format( |
| 83 | sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir)) |
| 84 | |
| 85 | def test_default_stage2(self): |
| 86 | """ |
| 87 | Test that we dump the correct commands for a 2-stage build of LLVM. |
| 88 | """ |
| 89 | sourceDir = "path-to-sources" |
| 90 | buildDir1 = "path-to-stage1" |
| 91 | buildDir2 = "path-to-stage2" |
| 92 | |
| 93 | output = self.run_with_output( |
| 94 | self.llvm_build_and_test( |
| 95 | "--dry-run", |
| 96 | "--source-dir", sourceDir, |
| 97 | "--stage1-build-dir", buildDir1, |
| 98 | "--stage2-build-dir", buildDir2)) |
| 99 | |
| 100 | commands = output.splitlines() |
| 101 | |
| 102 | self.assertRegex( |
| 103 | commands[0], |
| 104 | "{stage1}\$ cmake -G Ninja .* {sources}".format( |
| 105 | stage1=buildDir1, sources=sourceDir)) |
| 106 | |
| 107 | self.assertRegex( |
| 108 | commands[1], |
| 109 | "{stage1}\$ ninja".format(stage1=buildDir1)) |
| 110 | |
| 111 | self.assertRegex( |
| 112 | commands[2], "{stage2}\$ cmake -G Ninja .* " |
| 113 | "-DCMAKE_C_COMPILER={stage1}/bin/clang " |
| 114 | "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format( |
| 115 | stage1=buildDir1, stage2=buildDir2, sources=sourceDir)) |
| 116 | |
| 117 | self.assertRegex( |
| 118 | commands[3], |
| 119 | "{stage2}\$ ninja".format(stage2=buildDir2)) |
| 120 | |
| 121 | def test_stage2_and_testsuite(self): |
| 122 | """ |
| 123 | Test that we dump the correct commands for a 2-stage build of LLVM and a |
| 124 | run of the test-suite with the resulting compiler. |
| 125 | """ |
| 126 | sourceDir = "path-to-sources" |
| 127 | buildDir1 = "path-to-stage1" |
| 128 | buildDir2 = "path-to-stage2" |
| 129 | testSuiteDir = "path-to-test-suite" |
| 130 | sandboxDir = "path-to-sandbox" |
| 131 | lntDir = "path-to-lnt" |
| 132 | |
| 133 | output = self.run_with_output( |
| 134 | self.llvm_build_and_test( |
| 135 | "--dry-run", |
| 136 | "--source-dir", sourceDir, |
| 137 | "--stage1-build-dir", buildDir1, |
| 138 | "--stage2-build-dir", buildDir2, |
| 139 | "--test-suite", testSuiteDir, |
| 140 | "--sandbox", sandboxDir, |
| 141 | "--lnt", lntDir)) |
| 142 | |
| 143 | commands = output.splitlines() |
| 144 | |
| 145 | self.assertRegex( |
| 146 | commands[0], |
| 147 | "{stage1}\$ cmake -G Ninja .* {sources}".format( |
| 148 | stage1=buildDir1, |
| 149 | sources=sourceDir)) |
| 150 | |
| 151 | self.assertRegex( |
| 152 | commands[1], |
| 153 | "{stage1}\$ ninja".format(stage1=buildDir1)) |
| 154 | |
| 155 | self.assertRegex( |
| 156 | commands[2], "{stage2}\$ cmake -G Ninja .* " |
| 157 | "-DCMAKE_C_COMPILER={stage1}/bin/clang " |
| 158 | "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format( |
| 159 | stage1=buildDir1, stage2=buildDir2, sources=sourceDir)) |
| 160 | |
| 161 | self.assertRegex( |
| 162 | commands[3], |
| 163 | "{stage2}\$ ninja".format(stage2=buildDir2)) |
| 164 | |
| 165 | self.assertRegex( |
| 166 | commands[4], |
| 167 | ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir)) |
| 168 | |
| 169 | self.assertRegex( |
| 170 | commands[5], |
| 171 | ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format( |
| 172 | sandbox=sandboxDir, |
| 173 | lnt=lntDir)) |
| 174 | |
| 175 | self.assertRegex( |
| 176 | commands[6], |
| 177 | ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite " |
| 178 | "--sandbox={sandbox} --test-suite={testsuite} " |
| 179 | "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang".format( |
| 180 | sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir2)) |