aboutsummaryrefslogtreecommitdiff
path: root/tests/cli/testbuildandtest.py
blob: 1475958b2c9e2f9594a279c594add789aa8ddc1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
"""Command line interface tests for llvm.py build-and-test.

Note that although this uses the unittest framework, it does *not* contain unit
tests.

"""
import os

from llvmtestcase import LLVMTestCase, require_command_arg, debug


class Testllvmbuildandtest(LLVMTestCase):

    @classmethod
    def llvm_build_and_test(cls, *args, **kwargs):
        return cls.command_with_defaults("build-and-test", *args, **kwargs)

    def test_default_stage1(self):
        """
        Test that we dump the correct commands for a single stage build of LLVM.
        """
        reposDir = "path-to-repos"
        sourceDir = "path-to-sources"
        buildDir = "path-to-stage1"

        output = self.run_with_output(
            self.llvm_build_and_test(
                "--dry-run",
                "--repos-dir", reposDir,
                "--source-dir", sourceDir,
                "--stage1-build-dir", buildDir))

        commands = output.splitlines()

        self.assertRegex(commands[0],
                         "{build}\$ cmake -G Ninja .* {sources}".format(
                             build=buildDir, sources=sourceDir))

        self.assertRegex(commands[1],
                         "{build}\$ ninja".format(build=buildDir))

    def test_custom_stage1(self):
        """Test that we can customize the first stage of the build."""
        reposDir = "path-to-repos"
        sourceDir = "path-to-sources"
        buildDir = "path-to-stage1"

        output = self.run_with_output(
            self.llvm_build_and_test(
                "--dry-run",
                "--repos-dir", reposDir,
                "--source-dir", sourceDir,
                "--stage1-build-dir", buildDir,
                "--stage1-subproject", "clang",
                "--stage1-subproject", "compiler-rt",
                "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm",
                "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True",
                "--stage1-build-flag=-j8",
                "--stage1-build-flag", "check-all"))

        commands = output.splitlines()

        self.assertRegex(commands[0],
                         "{build}\$ cmake -G Ninja .* {sources}".format(
                             build=buildDir, sources=sourceDir))

        self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0])
        self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0])
        self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0])
        self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0])

        self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0])
        self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0])

        self.assertRegex(commands[1],
                         "{build}\$ ninja -j8 check-all".format(build=buildDir))


    def test_stage1_and_testsuite(self):
        """
        Test that we dump the correct commands for a single stage build of LLVM
        and a run of the test-suite with the resulting compiler.
        """
        reposDir = "path-to-repos"
        sourceDir = "path-to-sources"
        buildDir = "path-to-stage1"
        sandboxDir = "path-to-sandbox"

        testSuiteDir = os.path.join(reposDir, "test-suite")
        lntDir = os.path.join(reposDir, "lnt")

        output = self.run_with_output(
            self.llvm_build_and_test(
                "--dry-run",
                "--repos-dir", reposDir,
                "--source-dir", sourceDir,
                "--stage1-build-dir", buildDir,
                "--enable-test-suite",
                "--sandbox", sandboxDir))

        commands = output.splitlines()

        self.assertRegex(commands[0],
                         "{build}\$ cmake -G Ninja .* {sources}".format(
                             build=buildDir, sources=sourceDir))

        self.assertRegex(commands[1],
                         "{build}\$ ninja".format(build=buildDir))

        self.assertRegex(
            commands[2], ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir))

        self.assertRegex(
            commands[3],
            ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format(
                sandbox=sandboxDir,
                lnt=lntDir))

        self.assertRegex(
            commands[4],
            ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite "
            "--sandbox={sandbox} --test-suite={testsuite} "
            "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang".format(
                sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir))

    def test_default_stage2(self):
        """
        Test that we dump the correct commands for a 2-stage build of LLVM.
        """
        reposDir = "path-to-repos"
        sourceDir = "path-to-sources"
        buildDir1 = "path-to-stage1"
        buildDir2 = "path-to-stage2"

        output = self.run_with_output(
            self.llvm_build_and_test(
                "--dry-run",
                "--repos-dir", reposDir,
                "--source-dir", sourceDir,
                "--stage1-build-dir", buildDir1,
                "--stage2-build-dir", buildDir2))

        commands = output.splitlines()

        self.assertRegex(
            commands[0],
            "{stage1}\$ cmake -G Ninja .* {sources}".format(
                stage1=buildDir1, sources=sourceDir))

        self.assertRegex(
            commands[1],
            "{stage1}\$ ninja".format(stage1=buildDir1))

        self.assertRegex(
            commands[2], "{stage2}\$ cmake -G Ninja .* "
            "-DCMAKE_C_COMPILER={stage1}/bin/clang "
            "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
                stage1=buildDir1, stage2=buildDir2, sources=sourceDir))

        self.assertRegex(
            commands[3],
            "{stage2}\$ ninja".format(stage2=buildDir2))

    def test_custom_stage1_default_stage2(self):
        """
        Test that we preserve the subprojects, but not the CMake or build flags.
        """
        reposDir = "path-to-repos"
        sourceDir = "path-to-sources"
        buildDir1 = "path-to-stage1"
        buildDir2 = "path-to-stage2"

        output = self.run_with_output(
            self.llvm_build_and_test(
                "--dry-run",
                "--repos-dir", reposDir,
                "--source-dir", sourceDir,
                "--stage1-build-dir", buildDir1,
                "--stage1-subproject", "clang",
                "--stage1-subproject", "compiler-rt",
                "--stage1-cmake-def", "CMAKE_CXX_FLAGS=-marm",
                "--stage1-cmake-def", "LLVM_ENABLE_ASSERTIONS=True",
                "--stage1-build-flag=-j8",
                "--stage1-build-flag", "check-all",
                "--stage2-build-dir", buildDir2))

        commands = output.splitlines()

        self.assertRegex(commands[0],
                         "{build}\$ cmake -G Ninja .* {sources}".format(
                             build=buildDir1, sources=sourceDir))

        self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[0])
        self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[0])
        self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[0])
        self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[0])

        self.assertIn("-DCMAKE_CXX_FLAGS=-marm", commands[0])
        self.assertIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[0])

        self.assertRegex(commands[1],
                         "{build}\$ ninja -j8 check-all".format(build=buildDir1))

        self.assertRegex(
            commands[2], "{stage2}\$ cmake -G Ninja .* "
            "-DCMAKE_C_COMPILER={stage1}/bin/clang "
            "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
                stage1=buildDir1, stage2=buildDir2, sources=sourceDir))

        self.assertIn("-DLLVM_TOOL_CLANG_BUILD=ON", commands[2])
        self.assertIn("-DLLVM_TOOL_COMPILER_RT_BUILD=ON", commands[2])
        self.assertIn("-DLLVM_TOOL_LIBCXX_BUILD=OFF", commands[2])
        self.assertIn("-DLLVM_TOOL_LLDB_BUILD=OFF", commands[2])

        self.assertNotIn("-DCMAKE_CXX_FLAGS=-marm", commands[2])
        self.assertNotIn("-DLLVM_ENABLE_ASSERTIONS=True", commands[2])

        self.assertRegex(
            commands[3],
            "{stage2}\$ ninja".format(stage2=buildDir2))


    def test_stage2_and_testsuite(self):
        """
        Test that we dump the correct commands for a 2-stage build of LLVM and a
        run of the test-suite with the resulting compiler.
        """
        reposDir = "path-to-repos"
        sourceDir = "path-to-sources"
        buildDir1 = "path-to-stage1"
        buildDir2 = "path-to-stage2"
        sandboxDir = "path-to-sandbox"

        testSuiteDir = os.path.join(reposDir, "test-suite")
        lntDir = os.path.join(reposDir, "lnt")

        output = self.run_with_output(
            self.llvm_build_and_test(
                "--dry-run",
                "--repos-dir", reposDir,
                "--source-dir", sourceDir,
                "--stage1-build-dir", buildDir1,
                "--stage2-build-dir", buildDir2,
                "--enable-test-suite",
                "--sandbox", sandboxDir))

        commands = output.splitlines()

        self.assertRegex(
            commands[0],
            "{stage1}\$ cmake -G Ninja .* {sources}".format(
                stage1=buildDir1,
                sources=sourceDir))

        self.assertRegex(
            commands[1],
            "{stage1}\$ ninja".format(stage1=buildDir1))

        self.assertRegex(
            commands[2], "{stage2}\$ cmake -G Ninja .* "
            "-DCMAKE_C_COMPILER={stage1}/bin/clang "
            "-DCMAKE_CXX_COMPILER={stage1}/bin/clang\+\+ {sources}".format(
                stage1=buildDir1, stage2=buildDir2, sources=sourceDir))

        self.assertRegex(
            commands[3],
            "{stage2}\$ ninja".format(stage2=buildDir2))

        self.assertRegex(
            commands[4],
            ".*\$ virtualenv {sandbox}".format(sandbox=sandboxDir))

        self.assertRegex(
            commands[5],
            ".*\$ {sandbox}/bin/python {lnt}/setup.py develop".format(
                sandbox=sandboxDir,
                lnt=lntDir))

        self.assertRegex(
            commands[6],
            ".*\$ {sandbox}/bin/python {sandbox}/bin/lnt runtest test-suite "
            "--sandbox={sandbox} --test-suite={testsuite} "
            "--use-lit={build}/bin/llvm-lit --cc={build}/bin/clang".format(
                sandbox=sandboxDir, testsuite=testSuiteDir, build=buildDir2))