blob: 1f1ce92890d08ad9f9f4d8260bdde22035b5c8ce [file] [log] [blame]
Brad Fitzpatrickf3c01932015-01-15 16:29:16 -08001// Copyright 2015 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package dashboard
6
7import (
Brad Fitzpatrickaab85042019-10-16 06:02:29 +00008 "bytes"
Brad Fitzpatrick756764c2019-03-07 17:44:41 +00009 "fmt"
Brad Fitzpatrickaab85042019-10-16 06:02:29 +000010 "os/exec"
11 "path/filepath"
Tobias Klausercd82ecd2019-11-07 14:15:55 +010012 "regexp"
Brad Fitzpatrickaab85042019-10-16 06:02:29 +000013 "runtime"
14 "sort"
Brad Fitzpatrickf3c01932015-01-15 16:29:16 -080015 "strings"
16 "testing"
Brad Fitzpatrick34b995b2019-02-14 02:18:06 +000017 "time"
Carlos Amedee1e761992020-08-20 11:53:58 -040018
19 "github.com/google/go-cmp/cmp"
Brad Fitzpatrickf3c01932015-01-15 16:29:16 -080020)
21
22func TestOSARCHAccessors(t *testing.T) {
23 valid := func(s string) bool { return s != "" && !strings.Contains(s, "-") }
24 for _, conf := range Builders {
25 os := conf.GOOS()
26 arch := conf.GOARCH()
27 osArch := os + "-" + arch
28 if !valid(os) || !valid(arch) || !(conf.Name == osArch || strings.HasPrefix(conf.Name, osArch+"-")) {
29 t.Errorf("OS+ARCH(%q) = %q, %q; invalid", conf.Name, os, arch)
30 }
31 }
32}
Brad Fitzpatrickc328d042017-04-12 00:35:37 +000033
Brad Fitzpatrick34b995b2019-02-14 02:18:06 +000034func TestDistTestsExecTimeout(t *testing.T) {
35 tests := []struct {
36 c *BuildConfig
37 want time.Duration
38 }{
39 {
40 &BuildConfig{
41 env: []string{},
42 testHostConf: &HostConfig{},
43 },
44 20 * time.Minute,
45 },
46 {
47 &BuildConfig{
48 env: []string{"GO_TEST_TIMEOUT_SCALE=2"},
49 testHostConf: &HostConfig{},
50 },
51 40 * time.Minute,
52 },
53 {
54 &BuildConfig{
55 env: []string{},
56 testHostConf: &HostConfig{
57 env: []string{"GO_TEST_TIMEOUT_SCALE=3"},
58 },
59 },
60 60 * time.Minute,
61 },
62 // BuildConfig's env takes precedence:
63 {
64 &BuildConfig{
65 env: []string{"GO_TEST_TIMEOUT_SCALE=2"},
66 testHostConf: &HostConfig{
67 env: []string{"GO_TEST_TIMEOUT_SCALE=3"},
68 },
69 },
70 40 * time.Minute,
71 },
72 }
73 for i, tt := range tests {
74 got := tt.c.DistTestsExecTimeout(nil)
75 if got != tt.want {
76 t.Errorf("%d. got %v; want %v", i, got, tt.want)
77 }
78 }
79}
80
Brad Fitzpatrick756764c2019-03-07 17:44:41 +000081// TestTrybots tests that a given repo & its branch yields the provided
82// complete set of builders. See also: TestBuilders, which tests both trybots
83// and post-submit builders, both at arbitrary branches.
84func TestTrybots(t *testing.T) {
85 tests := []struct {
86 repo string // "go", "net", etc
87 branch string // of repo
88 want []string
89 }{
90 {
91 repo: "go",
92 branch: "master",
93 want: []string{
Brad Fitzpatrick4e29d672019-04-18 19:45:32 +000094 "android-amd64-emu",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +000095 "freebsd-amd64-12_0",
96 "js-wasm",
97 "linux-386",
98 "linux-amd64",
99 "linux-amd64-race",
Brad Fitzpatrick95bc93b2019-05-10 19:28:40 +0000100 "misc-compile-other",
101 "misc-compile-darwin",
Dmitri Shuralyov4c544cb2020-11-02 22:25:51 -0500102 "misc-compile-darwinarm64",
Brad Fitzpatrick95bc93b2019-05-10 19:28:40 +0000103 "misc-compile-linuxarm",
104 "misc-compile-solaris",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000105 "misc-compile-freebsd",
106 "misc-compile-mips",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000107 "misc-compile-netbsd",
108 "misc-compile-openbsd",
109 "misc-compile-plan9",
110 "misc-compile-ppc",
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500111 "openbsd-amd64-68",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000112 "windows-386-2008",
113 "windows-amd64-2016",
114 },
115 },
116 {
117 repo: "go",
Brad Fitzpatrick90670e12019-10-11 18:47:51 +0000118 branch: "dev.link",
119 want: []string{
Cherry Zhang50a78802020-03-13 17:09:21 -0400120 "android-amd64-emu",
Brad Fitzpatrick90670e12019-10-11 18:47:51 +0000121 "freebsd-amd64-12_0",
122 "js-wasm",
123 "linux-386",
124 "linux-amd64",
125 "linux-amd64-race",
126 "misc-compile-other",
127 "misc-compile-darwin",
Dmitri Shuralyov4c544cb2020-11-02 22:25:51 -0500128 "misc-compile-darwinarm64",
Brad Fitzpatrick90670e12019-10-11 18:47:51 +0000129 "misc-compile-linuxarm",
130 "misc-compile-solaris",
131 "misc-compile-freebsd",
132 "misc-compile-mips",
133 "misc-compile-netbsd",
134 "misc-compile-openbsd",
135 "misc-compile-plan9",
136 "misc-compile-ppc",
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500137 "openbsd-amd64-68",
Brad Fitzpatrick90670e12019-10-11 18:47:51 +0000138 "windows-386-2008",
139 "windows-amd64-2016",
140 },
141 },
142 {
143 repo: "go",
Dmitri Shuralyov4c544cb2020-11-02 22:25:51 -0500144 branch: "release-branch.go1.16",
145 want: []string{
146 "android-amd64-emu",
147 "freebsd-amd64-12_0",
148 "js-wasm",
149 "linux-386",
150 "linux-amd64",
151 "linux-amd64-race",
152 "misc-compile-darwin",
153 "misc-compile-darwinarm64", // Starts with Go 1.16.
154 "misc-compile-freebsd",
155 "misc-compile-linuxarm",
156 "misc-compile-mips",
157 "misc-compile-netbsd",
158 "misc-compile-openbsd",
159 "misc-compile-other",
160 "misc-compile-plan9",
161 "misc-compile-ppc",
162 "misc-compile-solaris",
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500163 "openbsd-amd64-68",
Dmitri Shuralyov4c544cb2020-11-02 22:25:51 -0500164 "windows-386-2008",
165 "windows-amd64-2016",
166
167 // Include longtest builders on Go repo release branches. See issue 37827.
168 "linux-386-longtest",
169 "linux-amd64-longtest",
170 "windows-amd64-longtest",
171 },
172 },
173 {
174 repo: "go",
Dmitri Shuralyov9e7a7622020-05-26 18:12:12 -0400175 branch: "release-branch.go1.14",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000176 want: []string{
Dmitri Shuralyov9e7a7622020-05-26 18:12:12 -0400177 "android-amd64-emu",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000178 "freebsd-amd64-12_0",
179 "js-wasm",
180 "linux-386",
181 "linux-amd64",
182 "linux-amd64-race",
Brad Fitzpatrick95bc93b2019-05-10 19:28:40 +0000183 "misc-compile-darwin",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000184 "misc-compile-freebsd",
Brad Fitzpatrick95bc93b2019-05-10 19:28:40 +0000185 "misc-compile-linuxarm",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000186 "misc-compile-mips",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000187 "misc-compile-netbsd",
188 "misc-compile-openbsd",
Brad Fitzpatrick95bc93b2019-05-10 19:28:40 +0000189 "misc-compile-other",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000190 "misc-compile-plan9",
191 "misc-compile-ppc",
Brad Fitzpatrick95bc93b2019-05-10 19:28:40 +0000192 "misc-compile-solaris",
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500193 "openbsd-amd64-68",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000194 "windows-386-2008",
195 "windows-amd64-2016",
Dmitri Shuralyov5a8fb632020-05-26 18:19:05 -0400196
197 // Include longtest builders on Go repo release branches. See issue 37827.
198 "linux-386-longtest",
199 "linux-amd64-longtest",
200 "windows-amd64-longtest",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000201 },
202 },
203 {
204 repo: "mobile",
205 branch: "master",
206 want: []string{
207 "android-amd64-emu",
208 "linux-amd64-androidemu",
209 },
210 },
211 {
212 repo: "sys",
213 branch: "master",
214 want: []string{
Brad Fitzpatrick6d867c82019-04-26 14:04:00 +0000215 "android-amd64-emu",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000216 "freebsd-386-11_2",
217 "freebsd-amd64-11_2",
218 "freebsd-amd64-12_0",
219 "linux-386",
220 "linux-amd64",
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000221 "linux-amd64-race",
Dmitri Shuralyov5bbd5582020-04-08 12:43:09 -0400222 "netbsd-amd64-9_0",
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500223 "openbsd-386-68",
224 "openbsd-amd64-68",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000225 "windows-386-2008",
226 "windows-amd64-2016",
227 },
228 },
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000229 {
230 repo: "exp",
231 branch: "master",
232 want: []string{
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000233 "linux-amd64",
234 "linux-amd64-race",
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000235 "windows-386-2008",
236 "windows-amd64-2016",
237 },
238 },
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000239 }
240 for i, tt := range tests {
241 if tt.branch == "" || tt.repo == "" {
242 t.Errorf("incomplete test entry %d", i)
243 return
244 }
245 t.Run(fmt.Sprintf("%s/%s", tt.repo, tt.branch), func(t *testing.T) {
246 var got []string
247 goBranch := tt.branch // hard-code the common case for now
248 for _, bc := range TryBuildersForProject(tt.repo, tt.branch, goBranch) {
249 got = append(got, bc.Name)
250 }
251 m := map[string]bool{}
252 for _, b := range tt.want {
253 m[b] = true
254 }
255 for _, b := range got {
256 if _, ok := m[b]; !ok {
257 t.Errorf("got unexpected %q", b)
258 }
259 delete(m, b)
260 }
261 for b := range m {
262 t.Errorf("missing expected %q", b)
Brad Fitzpatrickc517aed2018-10-26 19:21:58 +0000263 }
264 })
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000265 }
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000266}
267
268// TestBuilderConfig whether a given builder and repo at different
269// branches is either a post-submit builder, trybot, neither, or both.
270func TestBuilderConfig(t *testing.T) {
271 // builderConfigWant is bitmask of 4 different things to assert are wanted:
272 // - being a post-submit builder
273 // - NOT being a post-submit builder
274 // - being a trybot builder
275 // - NOT being a post-submit builder
276 type want uint8
277 const (
278 isTrybot want = 1 << iota
279 notTrybot
280 isBuilder // post-submit
281 notBuilder // not post-submit
282
283 none = notTrybot + notBuilder
284 both = isTrybot + isBuilder
285 onlyPost = notTrybot + isBuilder
286 )
287
288 type builderAndRepo struct {
289 testName string
290 builder string
291 repo string
292 branch string
293 goBranch string
294 }
Dmitri Shuralyov76fd6b52019-10-08 13:08:27 -0400295 // builder may end in "@go1.N" or "@1.N" (as alias for "@release-branch.go1.N") or "@branch-name".
296 // repo (other than "go") may end in "@go1.N" or "@1.N" (as alias for "@release-branch.go1.N").
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000297 b := func(builder, repo string) builderAndRepo {
298 br := builderAndRepo{
299 testName: builder + "," + repo,
300 builder: builder,
301 goBranch: "master",
302 repo: repo,
303 branch: "master",
304 }
305 if strings.Contains(builder, "@") {
306 f := strings.SplitN(builder, "@", 2)
307 br.builder = f[0]
308 br.goBranch = f[1]
309 }
310 if strings.Contains(repo, "@") {
311 f := strings.SplitN(repo, "@", 2)
312 br.repo = f[0]
313 br.branch = f[1]
Dmitri Shuralyov76fd6b52019-10-08 13:08:27 -0400314 if br.repo == "go" {
315 panic(fmt.Errorf(`b(%q, %q): for "go" repo, must use the @%s suffix on the builder, not on the repo`, builder, repo, br.branch))
316 }
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000317 }
318 expandBranch := func(s *string) {
319 if strings.HasPrefix(*s, "go1.") {
320 *s = "release-branch." + *s
321 } else if strings.HasPrefix(*s, "1.") {
322 *s = "release-branch.go" + *s
323 }
324 }
325 expandBranch(&br.branch)
326 expandBranch(&br.goBranch)
327 if br.repo == "go" {
328 br.branch = br.goBranch
329 }
330 return br
331 }
332 tests := []struct {
333 br builderAndRepo
334 want want
335 }{
336 {b("linux-amd64", "go"), both},
337 {b("linux-amd64", "net"), both},
338 {b("linux-amd64", "sys"), both},
Dmitri Shuralyov7aef06b2019-05-16 16:04:34 -0400339 {b("linux-amd64", "website"), both},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000340
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000341 // Don't test all subrepos on all the builders.
342 {b("linux-amd64-ssacheck", "net"), none},
Dmitri Shuralyovdf6c66f2020-10-05 12:20:33 -0400343 {b("linux-amd64-ssacheck@go1.15", "net"), none},
Dmitri Shuralyov0f5b1a72020-10-07 11:24:42 -0400344 {b("linux-386-softfloat", "crypto"), onlyPost},
345 {b("linux-386-softfloat@go1.16", "crypto"), onlyPost},
346 {b("linux-386-softfloat@go1.15", "crypto"), none},
Dmitri Shuralyovdf6c66f2020-10-05 12:20:33 -0400347 {b("linux-386-387", "crypto"), none},
348 {b("linux-386-387@go1.16", "crypto"), none},
349 {b("linux-386-387@go1.15", "crypto"), onlyPost},
350 {b("linux-386-387@go1.15", "crypto@1.15"), onlyPost},
351 {b("linux-386-387@go1.15", "build"), none},
352 {b("linux-386-387@go1.14", "crypto"), onlyPost},
353 {b("linux-arm-arm5spacemonkey@go1.15", "net"), none},
Tobias Klauser48cb6ed2019-11-25 10:00:55 +0100354 {b("linux-arm-arm5spacemonkey", "exp"), none},
355 {b("linux-arm-arm5spacemonkey", "mobile"), none},
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000356
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000357 // The mobile repo requires Go 1.13+.
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000358 {b("android-amd64-emu", "mobile"), both},
359 {b("android-amd64-emu", "mobile@1.10"), none},
360 {b("android-amd64-emu", "mobile@1.11"), none},
361 {b("android-amd64-emu@go1.10", "mobile"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000362 {b("android-amd64-emu@go1.12", "mobile"), none},
363 {b("android-amd64-emu@go1.13", "mobile"), both},
364 {b("android-amd64-emu", "mobile@1.13"), both},
Dmitri Shuralyov246beb72020-08-04 11:53:43 -0400365 {b("freebsd-386-11_1@go1.14", "mobile"), none}, // See golang.org/issue/36506.
Dmitri Shuralyov220eca82020-01-10 15:53:25 -0500366
367 {b("android-amd64-emu", "go"), both},
Brad Fitzpatrick6d867c82019-04-26 14:04:00 +0000368 {b("android-amd64-emu", "crypto"), both},
369 {b("android-amd64-emu", "net"), both},
370 {b("android-amd64-emu", "sync"), both},
371 {b("android-amd64-emu", "sys"), both},
372 {b("android-amd64-emu", "text"), both},
373 {b("android-amd64-emu", "time"), both},
374 {b("android-amd64-emu", "tools"), both},
Dmitri Shuralyovbb0f2242019-08-29 09:22:13 -0400375 {b("android-amd64-emu", "website"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000376
377 {b("android-386-emu", "go"), onlyPost},
378 {b("android-386-emu", "mobile"), onlyPost},
379 {b("android-386-emu", "mobile@1.10"), none},
380 {b("android-386-emu", "mobile@1.11"), none},
381 {b("android-386-emu@go1.10", "mobile"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000382 {b("android-386-emu@go1.12", "mobile"), none},
383 {b("android-386-emu@go1.13", "mobile"), onlyPost},
384 {b("android-386-emu", "mobile@1.13"), onlyPost},
385
386 {b("linux-amd64", "net"), both},
387 {b("linux-amd64", "net@1.12"), both},
388 {b("linux-amd64@go1.12", "net@1.12"), both},
389 {b("linux-amd64", "net@1.11"), both},
390 {b("linux-amd64", "net@1.11"), both},
391 {b("linux-amd64", "net@1.10"), none}, // too old
392 {b("linux-amd64@go1.10", "net"), none}, // too old
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000393 {b("linux-amd64@go1.12", "net@1.12"), both},
394
Meng Zhuo88052792019-09-10 07:21:11 +0800395 {b("linux-mips64le-mengzhuo", "go"), onlyPost},
396 {b("linux-mips64le-mengzhuo", "sys"), onlyPost},
397 {b("linux-mips64le-mengzhuo", "net"), onlyPost},
398
Dmitri Shuralyov5f7fe5e2020-11-10 12:56:57 -0500399 // OpenBSD.
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500400 {b("openbsd-amd64-68@go1.16", "go"), both},
401 {b("openbsd-amd64-68@go1.15", "go"), both},
402 {b("openbsd-amd64-68@go1.14", "go"), both},
403 {b("openbsd-amd64-64@go1.16", "go"), onlyPost},
404 {b("openbsd-amd64-64@go1.15", "go"), onlyPost},
405 {b("openbsd-amd64-64@go1.14", "go"), onlyPost},
Dmitri Shuralyov5f7fe5e2020-11-10 12:56:57 -0500406 {b("openbsd-amd64-62@go1.16", "go"), none}, // golang.org/issue/42426.
407 {b("openbsd-amd64-62@go1.15", "go"), onlyPost},
408 {b("openbsd-amd64-62@go1.14", "go"), onlyPost},
409
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000410 // go1.12.html: "Go 1.12 is the last release that is
411 // supported on FreeBSD 10.x [... and 11.1]"
Dmitri Shuralyov246beb72020-08-04 11:53:43 -0400412 // But golang.org/issue/40563 happened.
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000413 {b("freebsd-amd64-11_1", "go"), none},
414 {b("freebsd-amd64-11_1", "net"), none},
Tobias Klauserbe84e8e2019-12-01 14:33:59 +0100415 {b("freebsd-amd64-11_1", "mobile"), none},
Dmitri Shuralyov246beb72020-08-04 11:53:43 -0400416 {b("freebsd-amd64-11_1@go1.14", "go"), isBuilder},
417 {b("freebsd-amd64-11_1@go1.14", "net"), isBuilder},
418 {b("freebsd-amd64-11_1@go1.14", "mobile"), none},
419 {b("freebsd-amd64-11_1@go1.13", "go"), isBuilder},
420 {b("freebsd-amd64-11_1@go1.13", "net"), isBuilder},
Tobias Klauserbe84e8e2019-12-01 14:33:59 +0100421 {b("freebsd-amd64-11_1@go1.13", "mobile"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000422
Brad Fitzpatrick9e52fce2019-03-12 21:13:50 +0000423 // FreeBSD 12.0
424 {b("freebsd-amd64-12_0", "go"), both},
425 {b("freebsd-amd64-12_0", "net"), both},
Tobias Klauserbe84e8e2019-12-01 14:33:59 +0100426 {b("freebsd-amd64-12_0", "mobile"), none},
Brad Fitzpatrick9e52fce2019-03-12 21:13:50 +0000427 {b("freebsd-386-12_0", "go"), onlyPost},
428 {b("freebsd-386-12_0", "net"), onlyPost},
Tobias Klauserbe84e8e2019-12-01 14:33:59 +0100429 {b("freebsd-386-12_0", "mobile"), none},
Brad Fitzpatrick9e52fce2019-03-12 21:13:50 +0000430
Brad Fitzpatrickfcf7a582019-04-30 22:37:31 +0000431 // NetBSD
Dmitri Shuralyov5bbd5582020-04-08 12:43:09 -0400432 {b("netbsd-amd64-9_0", "go"), onlyPost},
433 {b("netbsd-amd64-9_0", "net"), onlyPost},
Dmitri Shuralyovb7c61f72020-04-09 07:59:16 -0400434 {b("netbsd-amd64-9_0", "sys"), both},
Dmitri Shuralyov5bbd5582020-04-08 12:43:09 -0400435 {b("netbsd-386-9_0", "go"), onlyPost},
436 {b("netbsd-386-9_0", "net"), onlyPost},
Brad Fitzpatrickfcf7a582019-04-30 22:37:31 +0000437
Tobias Klauserb7b66932019-03-13 09:29:15 +0100438 // AIX starts at Go 1.12
439 {b("aix-ppc64", "go"), onlyPost},
440 {b("aix-ppc64", "net"), onlyPost},
Tobias Klauserc2ec9e42019-06-04 10:14:55 +0200441 {b("aix-ppc64", "mobile"), none},
442 {b("aix-ppc64", "exp"), none},
Tobias Klausercbdd89b2019-10-14 11:31:13 +0200443 {b("aix-ppc64", "term"), onlyPost},
Tobias Klauserb7b66932019-03-13 09:29:15 +0100444 {b("aix-ppc64@go1.12", "go"), onlyPost},
Brad Fitzpatrick0bbb12f2019-04-19 14:37:11 +0000445 {b("aix-ppc64@go1.12", "net"), none},
Tobias Klauserc2ec9e42019-06-04 10:14:55 +0200446 {b("aix-ppc64@go1.12", "mobile"), none},
Brad Fitzpatrick0bbb12f2019-04-19 14:37:11 +0000447 {b("aix-ppc64@go1.13", "net"), onlyPost},
Tobias Klauserc2ec9e42019-06-04 10:14:55 +0200448 {b("aix-ppc64@go1.13", "mobile"), none},
Cherry Zhang50a78802020-03-13 17:09:21 -0400449 {b("aix-ppc64@dev.link", "go"), onlyPost},
Tobias Klauserb7b66932019-03-13 09:29:15 +0100450
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000451 {b("linux-amd64-nocgo", "mobile"), none},
452
Elias Naur4d0f77a2019-05-01 22:28:43 +0200453 // Virtual mobiledevices
Elias Naur18919d62020-10-03 11:37:07 +0200454 {b("ios-arm64-corellium", "go"), isBuilder},
Elias Naur4d0f77a2019-05-01 22:28:43 +0200455 {b("android-arm64-corellium", "go"), isBuilder},
Elias Naur7ae75392019-05-02 00:54:54 +0200456 {b("android-arm-corellium", "go"), isBuilder},
Elias Naur6bebc8e2019-05-01 20:33:26 +0200457
Elias Naur18919d62020-10-03 11:37:07 +0200458 // Mobile builders that run with GOOS=linux/ios and have
Brad Fitzpatrick13f1da92019-03-12 16:21:55 +0000459 // a device attached.
460 {b("linux-amd64-androidemu", "mobile"), both},
Brad Fitzpatrick13f1da92019-03-12 16:21:55 +0000461
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000462 // But the emulators run all:
463 {b("android-amd64-emu", "mobile"), isBuilder},
464 {b("android-386-emu", "mobile"), isBuilder},
465 {b("android-amd64-emu", "net"), isBuilder},
466 {b("android-386-emu", "net"), isBuilder},
467 {b("android-amd64-emu", "go"), isBuilder},
468 {b("android-386-emu", "go"), isBuilder},
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000469
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000470 // Only test tip for js/wasm, and only for some repos:
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000471 {b("js-wasm", "go"), both},
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000472 {b("js-wasm", "arch"), onlyPost},
473 {b("js-wasm", "crypto"), onlyPost},
474 {b("js-wasm", "sys"), onlyPost},
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000475 {b("js-wasm", "net"), onlyPost},
476 {b("js-wasm@go1.12", "net"), none},
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000477 {b("js-wasm", "benchmarks"), none},
478 {b("js-wasm", "debug"), none},
479 {b("js-wasm", "mobile"), none},
480 {b("js-wasm", "perf"), none},
481 {b("js-wasm", "talks"), none},
482 {b("js-wasm", "tools"), none},
483 {b("js-wasm", "tour"), none},
484 {b("js-wasm", "website"), none},
485
486 // Race builders. Linux for all, GCE buidlers for
487 // post-submit, and only post-submit for "go" for
488 // Darwin (limited resources).
489 {b("linux-amd64-race", "go"), both},
490 {b("linux-amd64-race", "net"), both},
491 {b("windows-amd64-race", "go"), onlyPost},
492 {b("windows-amd64-race", "net"), onlyPost},
493 {b("freebsd-amd64-race", "go"), onlyPost},
494 {b("freebsd-amd64-race", "net"), onlyPost},
495 {b("darwin-amd64-race", "go"), onlyPost},
496 {b("darwin-amd64-race", "net"), none},
497
498 // Long test.
499 {b("linux-amd64-longtest", "go"), onlyPost},
500 {b("linux-amd64-longtest", "net"), onlyPost},
Dmitri Shuralyov5a8fb632020-05-26 18:19:05 -0400501 {b("linux-amd64-longtest@go1.14", "go"), both},
Dmitri Shuralyov9e7a7622020-05-26 18:12:12 -0400502 {b("linux-amd64-longtest@go1.14", "net"), none},
Brad Fitzpatrickf9c537e2019-10-28 20:16:36 +0000503 {b("windows-amd64-longtest", "go"), onlyPost},
Dmitri Shuralyov5a8fb632020-05-26 18:19:05 -0400504 {b("windows-amd64-longtest@go1.14", "go"), both},
Brad Fitzpatrickf9c537e2019-10-28 20:16:36 +0000505 {b("windows-amd64-longtest", "net"), onlyPost},
506 {b("windows-amd64-longtest", "exp"), onlyPost},
507 {b("windows-amd64-longtest", "mobile"), none},
Dmitri Shuralyovdd5ac552020-07-01 14:14:47 -0400508 {b("linux-386-longtest", "go"), onlyPost},
509 {b("linux-386-longtest", "net"), onlyPost},
510 {b("linux-386-longtest", "exp"), none},
511 {b("linux-386-longtest", "mobile"), none},
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000512
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000513 // Experimental exp repo runs in very few places.
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000514 {b("linux-amd64", "exp"), both},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000515 {b("linux-amd64-race", "exp"), both},
516 {b("linux-amd64-longtest", "exp"), onlyPost},
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000517 {b("windows-386-2008", "exp"), both},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000518 {b("windows-amd64-2016", "exp"), both},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000519 {b("darwin-amd64-10_14", "exp"), onlyPost},
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000520 {b("darwin-amd64-10_15", "exp"), onlyPost},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000521 // ... but not on most others:
Dmitri Shuralyov3b77b3a2019-09-28 17:43:42 +0000522 {b("darwin-amd64-10_12", "exp"), none},
Dmitri Shuralyov246beb72020-08-04 11:53:43 -0400523 {b("freebsd-386-11_1@go1.14", "exp"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000524 {b("freebsd-386-11_2", "exp"), none},
525 {b("freebsd-386-12_0", "exp"), none},
Dmitri Shuralyov246beb72020-08-04 11:53:43 -0400526 {b("freebsd-amd64-11_1@go1.14", "exp"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000527 {b("freebsd-amd64-11_2", "exp"), none},
528 {b("freebsd-amd64-12_0", "exp"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000529 {b("openbsd-amd64-64", "exp"), none},
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500530 {b("openbsd-amd64-68", "exp"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000531 {b("js-wasm", "exp"), none},
532
533 // exp is experimental; it doesn't test against release branches.
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000534 {b("linux-amd64@go1.12", "exp"), none},
Brad Fitzpatrick8a071d42019-03-18 16:48:22 +0000535
Brad Fitzpatrickc8ca9622019-12-07 05:14:28 +0000536 // the build repo is only really useful for linux-amd64 (where we run it),
537 // and darwin-amd64 and perhaps windows-amd64 (for stuff like gomote).
538 // No need for any other operating systems to use it.
539 {b("linux-amd64", "build"), both},
540 {b("linux-amd64-longtest", "build"), onlyPost},
541 {b("windows-amd64-2016", "build"), both},
542 {b("darwin-amd64-10_12", "build"), none},
543 {b("darwin-amd64-10_14", "build"), none},
544 {b("darwin-amd64-10_15", "build"), onlyPost},
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500545 {b("openbsd-amd64-68", "build"), none},
Brad Fitzpatrickc8ca9622019-12-07 05:14:28 +0000546 {b("linux-amd64-fedora", "build"), none},
547 {b("linux-amd64-clang", "build"), none},
548 {b("linux-amd64-sid", "build"), none},
Brad Fitzpatrickf6d512d2019-12-12 17:43:59 +0000549 {b("linux-amd64-nocgo", "build"), none},
550 {b("linux-386-longtest", "build"), none},
Brad Fitzpatrickf6d512d2019-12-12 17:43:59 +0000551 {b("freebsd-386-11_1", "build"), none},
552 {b("js-wasm", "build"), none},
553 {b("android-386-emu", "build"), none},
554 {b("android-amd64-emu", "build"), none},
Brad Fitzpatrickc8ca9622019-12-07 05:14:28 +0000555
Brad Fitzpatrick8a071d42019-03-18 16:48:22 +0000556 // Only use latest macOS for subrepos, and only amd64:
557 {b("darwin-amd64-10_12", "net"), onlyPost},
Brad Fitzpatrick8a071d42019-03-18 16:48:22 +0000558 {b("darwin-amd64-10_11", "net"), none},
Brad Fitzpatrick8a071d42019-03-18 16:48:22 +0000559 {b("darwin-amd64-10_11@go1.12", "net"), none},
Brad Fitzpatrick8bd8e0e2019-03-26 23:04:31 +0000560
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000561 {b("darwin-amd64-10_15", "go"), onlyPost},
Brad Fitzpatrick8bd8e0e2019-03-26 23:04:31 +0000562 {b("darwin-amd64-10_14", "go"), onlyPost},
563 {b("darwin-amd64-10_12", "go"), onlyPost},
Dmitri Shuralyova1a9ec12020-03-10 13:26:20 -0400564 {b("darwin-amd64-10_11", "go"), none},
565 {b("darwin-amd64-10_11@go1.14", "go"), onlyPost}, // Go 1.14 is the last release that will run on macOS 10.11 El Capitan.
566 {b("darwin-amd64-10_11@go1.15", "go"), none}, // Go 1.15 will require macOS 10.12 Sierra or later.
Dmitri Shuralyov0e423fd2020-04-04 03:21:35 +0000567 {b("darwin-386-10_14", "go"), none},
Alexander Rakoczy2fe64f72019-08-26 16:40:35 -0400568 {b("darwin-386-10_14@go1.13", "go"), onlyPost},
Dmitri Shuralyov0e423fd2020-04-04 03:21:35 +0000569 {b("darwin-386-10_14@go1.14", "go"), onlyPost}, // Go 1.14 is the last release that supports 32-bit on macOS.
570 {b("darwin-386-10_14@go1.15", "go"), none},
Brad Fitzpatrick85a73d72019-04-03 04:45:29 +0000571
Brad Fitzpatrick67073b92019-04-18 19:33:19 +0000572 // plan9 only lived at master. We didn't support any past releases.
573 // But it's off for now as it's always failing.
574 {b("plan9-386", "go"), none}, // temporarily disabled
575 {b("plan9-386", "net"), none}, // temporarily disabled
Tobias Klauser22d3b242019-11-28 11:33:00 +0100576 {b("plan9-386", "exp"), none},
577 {b("plan9-386", "mobile"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000578 {b("plan9-386@go1.12", "go"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000579 {b("plan9-386@go1.12", "net"), none},
580 {b("plan9-amd64-9front", "go"), onlyPost},
Tobias Klauser22d3b242019-11-28 11:33:00 +0100581 {b("plan9-amd64-9front", "exp"), none},
582 {b("plan9-amd64-9front", "mobile"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000583 {b("plan9-amd64-9front@go1.12", "go"), none},
584 {b("plan9-amd64-9front", "net"), onlyPost},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000585 {b("plan9-amd64-9front@go1.12", "net"), none},
586 {b("plan9-arm", "go"), onlyPost},
Tobias Klauser22d3b242019-11-28 11:33:00 +0100587 {b("plan9-arm", "exp"), none},
588 {b("plan9-arm", "mobile"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000589 {b("plan9-arm@go1.12", "go"), none},
590 {b("plan9-arm", "net"), onlyPost},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000591 {b("plan9-arm@go1.12", "net"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000592
Brad Fitzpatrick58771952019-10-21 15:00:32 +0000593 {b("dragonfly-amd64", "go"), onlyPost},
594 {b("dragonfly-amd64", "net"), onlyPost},
595 {b("dragonfly-amd64@go1.13", "net"), none}, // Dragonfly ABI changes only supported by Go 1.14+
596 {b("dragonfly-amd64@go1.13", "go"), none}, // Dragonfly ABI changes only supported by Go 1.14+
Antonio Huete Jimeneza39e4672020-04-04 10:40:16 +0000597 {b("dragonfly-amd64-5_8", "go"), onlyPost},
598 {b("dragonfly-amd64-5_8", "net"), onlyPost},
599 {b("dragonfly-amd64-5_8@go1.13", "net"), onlyPost},
Dmitri Shuralyov77c96bb2020-03-19 10:34:11 -0400600
601 {b("linux-amd64-staticlockranking", "go"), onlyPost},
602 {b("linux-amd64-staticlockranking@go1.15", "go"), onlyPost},
603 {b("linux-amd64-staticlockranking@go1.14", "go"), none},
604 {b("linux-amd64-staticlockranking", "net"), none},
Austin Clements80886082020-12-21 16:08:53 -0500605
606 {b("linux-amd64-regabi", "go"), onlyPost},
607 {b("linux-amd64-regabi", "net"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000608 }
609 for _, tt := range tests {
610 t.Run(tt.br.testName, func(t *testing.T) {
611 bc, ok := Builders[tt.br.builder]
612 if !ok {
613 t.Fatalf("unknown builder %q", tt.br.builder)
614 }
615 gotPost := bc.BuildsRepoPostSubmit(tt.br.repo, tt.br.branch, tt.br.goBranch)
616 if tt.want&isBuilder != 0 && !gotPost {
617 t.Errorf("not a post-submit builder, but expected")
618 }
619 if tt.want&notBuilder != 0 && gotPost {
620 t.Errorf("unexpectedly a post-submit builder")
621 }
622
623 gotTry := bc.BuildsRepoTryBot(tt.br.repo, tt.br.branch, tt.br.goBranch)
624 if tt.want&isTrybot != 0 && !gotTry {
625 t.Errorf("not trybot, but expected")
626 }
627 if tt.want&notTrybot != 0 && gotTry {
628 t.Errorf("unexpectedly a trybot")
629 }
630
631 if t.Failed() {
632 t.Logf("For: %+v", tt.br)
633 }
634 })
635 }
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000636}
637
638func TestHostConfigsAllUsed(t *testing.T) {
Dmitri Shuralyov07688122020-08-04 12:01:34 -0400639 knownUnused := map[string]bool{
640 // Currently host-linux-armhf-cross and host-linux-armel-cross aren't
641 // referenced, but the coordinator hard-codes them, so don't make
642 // these two an error for now.
643 "host-linux-armhf-cross": true,
644 "host-linux-armel-cross": true,
645
646 "host-linux-x86-alpine": true, // TODO(golang.org/issue/19938): Fix the Alpine builder, or remove it.
Dmitri Shuralyov07688122020-08-04 12:01:34 -0400647 }
648
649 used := make(map[string]bool)
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000650 for _, conf := range Builders {
651 used[conf.HostType] = true
652 }
653 for hostType := range Hosts {
Dmitri Shuralyov07688122020-08-04 12:01:34 -0400654 if !used[hostType] && !knownUnused[hostType] {
655 t.Errorf("host type %q is not referenced from any build config", hostType)
656 }
657 if used[hostType] && knownUnused[hostType] {
658 t.Errorf("host type %q should not be listed in knownUnused since it's in use", hostType)
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000659 }
660 }
661}
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000662
663// tests that goBranch is optional for repo == "go"
664func TestBuildsRepoAtAllImplicitGoBranch(t *testing.T) {
665 builder := Builders["android-amd64-emu"]
666 got := builder.buildsRepoAtAll("go", "master", "")
667 if !got {
668 t.Error("got = false; want true")
669 }
670}
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000671
672func TestShouldRunDistTest(t *testing.T) {
673 type buildMode int
674 const (
675 tryMode buildMode = 0
676 postSubmit buildMode = 1
677 )
678
679 tests := []struct {
680 builder string
681 test string
682 mode buildMode
683 want bool
684 }{
685 {"linux-amd64", "api", postSubmit, true},
686 {"linux-amd64", "api", tryMode, true},
Dmitri Shuralyov75a37cb2020-04-09 12:47:03 -0400687 {"freebsd-amd64-12_0", "api", postSubmit, true}, // freebsd-amd64-12_0 uses fasterTrybots policy, should still build.
688 {"freebsd-amd64-12_0", "api", tryMode, false}, // freebsd-amd64-12_0 uses fasterTrybots policy, should skip in try mode.
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000689
690 {"linux-amd64", "reboot", tryMode, true},
691 {"linux-amd64-race", "reboot", tryMode, false},
692
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000693 {"darwin-amd64-10_11", "test:foo", postSubmit, false},
694 {"darwin-amd64-10_12", "test:foo", postSubmit, false},
695 {"darwin-amd64-10_14", "test:foo", postSubmit, false},
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000696 {"darwin-amd64-10_14", "reboot", postSubmit, false},
697 {"darwin-amd64-10_14", "api", postSubmit, false},
698 {"darwin-amd64-10_14", "codewalk", postSubmit, false},
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000699 {"darwin-amd64-10_15", "test:foo", postSubmit, false},
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000700 }
701 for _, tt := range tests {
702 bc, ok := Builders[tt.builder]
703 if !ok {
704 t.Errorf("unknown builder %q", tt.builder)
705 continue
706 }
707 isTry := tt.mode == tryMode
708 if isTry && !bc.BuildsRepoTryBot("go", "master", "master") {
709 t.Errorf("builder %q is not a trybot, so can't run test %q in try mode", tt.builder, tt.test)
710 continue
711 }
712 got := bc.ShouldRunDistTest(tt.test, isTry)
713 if got != tt.want {
714 t.Errorf("%q.ShouldRunDistTest(%q, try %v) = %v; want %v", tt.builder, tt.test, isTry, got, tt.want)
715 }
716 }
717}
Dmitri Shuralyov01fd2992019-09-09 16:48:08 -0400718
719func TestShouldTestPackageInGOPATHMode(t *testing.T) {
720 // This function doesn't change behavior depending on the builder
721 // at this time, so just use a common one.
722 bc, ok := Builders["linux-amd64"]
723 if !ok {
724 t.Fatal("unknown builder")
725 }
726
727 tests := []struct {
728 importPath string
729 want bool
730 }{
731 {"golang.org/x/image/bmp", true},
732 {"golang.org/x/tools/go/ast/astutil", true},
733 {"golang.org/x/tools/go/packages", true},
734 {"golang.org/x/tools", true}, // Three isn't a package there, but if there was, it should be tested.
735 {"golang.org/x/tools/gopls", false},
736 {"golang.org/x/tools/gopls/internal/foobar", false},
737 }
738 for _, tt := range tests {
739 got := bc.ShouldTestPackageInGOPATHMode(tt.importPath)
740 if got != tt.want {
741 t.Errorf("ShouldTestPackageInGOPATHMode(%q) = %v; want %v", tt.importPath, got, tt.want)
742 }
743 }
744}
Brad Fitzpatrickaab85042019-10-16 06:02:29 +0000745
746func TestSlowBotAliases(t *testing.T) {
747 for term, name := range slowBotAliases {
748 if name == "" {
749 // Empty string means known missing builder.
750 continue
751 }
752 if _, ok := Builders[name]; !ok {
753 t.Errorf("slowbot term %q references unknown builder %q", term, name)
754 }
755 }
756
757 out, err := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "tool", "dist", "list").Output()
758 if err != nil {
759 t.Errorf("dist list: %v", err)
760 }
761 ports := strings.Fields(string(out))
762
763 done := map[string]bool{}
Carlos Amedee3e01d872020-04-22 18:52:59 -0400764
Brad Fitzpatrickaab85042019-10-16 06:02:29 +0000765 var add bytes.Buffer
766 check := func(term string, isArch bool) {
767 if done[term] {
768 return
769 }
770 done[term] = true
771 _, isBuilderName := Builders[term]
772 _, hasAlias := slowBotAliases[term]
773 if !isBuilderName && !hasAlias {
774 prefix := term
775 if isArch {
776 prefix = "linux-" + term
777 }
778 var matches []string
779 for name := range Builders {
780 if strings.HasPrefix(name, prefix) {
781 matches = append(matches, name)
782 }
783 }
784 sort.Strings(matches)
785 t.Errorf("term %q has no match in slowBotAliases", term)
786 if len(matches) == 1 {
787 fmt.Fprintf(&add, "%q: %q,\n", term, matches[0])
788 } else if len(matches) > 1 {
789 t.Errorf("maybe add: %q: %q, (matches=%q)", term, matches[len(matches)-1], matches)
790 }
791 }
792 }
793
794 for _, port := range ports {
795 slash := strings.IndexByte(port, '/')
796 if slash == -1 {
797 t.Fatalf("unexpected port %q", port)
798 }
799 goos, goarch := port[:slash], port[slash+1:]
800 check(goos+"-"+goarch, false)
801 check(goos, false)
802 check(goarch, true)
803 }
804
805 if add.Len() > 0 {
806 t.Errorf("Missing items from slowBotAliases:\n%s", add.String())
807 }
808}
Brad Fitzpatrickad7af462019-10-19 02:49:53 +0000809
810func TestCrossCompileConfigs(t *testing.T) {
811 // Verify that Builders.CrossCompileConfig have valid host types.
812 for name, bc := range Builders {
813 cc := bc.CrossCompileConfig
814 if cc == nil {
815 continue
816 }
817 if _, ok := Hosts[cc.CompileHostType]; !ok {
818 t.Errorf("unknown host type %q for builder %q", cc.CompileHostType, name)
819 }
820 }
821}
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100822
823// TestTryBotsCompileAllPorts verifies that each port (go tool dist list) is covered by
824// either a real trybot or a misc-compile trybot.
825func TestTryBotsCompileAllPorts(t *testing.T) {
826 out, err := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "tool", "dist", "list").Output()
827 if err != nil {
828 t.Errorf("dist list: %v", err)
829 }
830 ports := strings.Fields(string(out))
831
832 done := map[string]bool{}
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400833 done["darwin-arm"] = true // TODO: Remove when Go 1.16 is out and Go 1.14 becomes unsupported.
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400834 done["darwin-arm64"] = true // TODO(golang.org/issue/39782): Add builder for darwin/arm64.
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100835 check := func(goos, goarch string) {
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400836 if goos == "android" || goos == "ios" {
Brad Fitzpatrick8a3c1d92019-11-15 04:29:29 +0000837 // TODO(golang.org/issue/25963): support
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400838 // compilation-only Android and iOS trybots.
Brad Fitzpatrick8a3c1d92019-11-15 04:29:29 +0000839 // buildall.bash doesn't set the environment
840 // up enough for e.g. compiling android-386
841 // from linux-amd64. (Issue #35596 too)
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400842 // iOS likely needs to be built on macOS
843 // with Xcode available.
Brad Fitzpatrick8a3c1d92019-11-15 04:29:29 +0000844 return
845 }
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100846 goosArch := goos + "-" + goarch
847 if done[goosArch] {
848 return
849 }
850 for _, conf := range Builders {
851 os := conf.GOOS()
852 arch := conf.GOARCH()
853
854 if os == goos && arch == goarch && (conf.tryOnly || conf.tryBot != nil) {
855 done[goosArch] = true
856 break
857 }
858
859 if strings.HasPrefix(conf.Name, "misc-compile-") {
860 re, err := regexp.Compile(conf.allScriptArgs[0])
861 if err != nil {
862 t.Errorf("Invalid misc-compile filtering pattern for builder %q: %q",
863 conf.Name, conf.allScriptArgs[0])
864 }
865
866 if re.MatchString(goosArch) || re.MatchString(goos) {
867 done[goosArch] = true
868 break
869 }
870 }
871 }
872 if _, ok := done[goosArch]; !ok {
873 t.Errorf("Missing trybot or misc-compile trybot: %q", goosArch)
874 }
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100875 }
876
877 for _, port := range ports {
878 slash := strings.IndexByte(port, '/')
879 if slash == -1 {
880 t.Fatalf("unexpected port %q", port)
881 }
882 check(port[:slash], port[slash+1:])
883 }
884
885}
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000886
887// TestExpectedMacstadiumVMCount ensures that only 20 instances of macOS virtual machines
888// are expected at MacStadium.
889// TODO: remove once the scheduler allocates VMs based on demand https://golang.org/issue/35698
890func TestExpectedMacstadiumVMCount(t *testing.T) {
891 got := 0
892 for host, config := range Hosts {
893 if strings.HasPrefix(host, "host-darwin-10_") {
894 got += config.ExpectNum
895 }
896 }
897 if got != 20 {
898 t.Fatalf("macstadium host count: got %d; want 20", got)
899 }
900}
Dmitri Shuralyovdf328b12020-05-13 14:30:25 -0400901
902// Test that we have a longtest builder and
903// that its environment configuration is okay.
904func TestLongTestBuilder(t *testing.T) {
905 long, ok := Builders["linux-amd64-longtest"]
906 if !ok {
907 t.Fatal("we don't have a linux-amd64-longtest builder anymore, is that intentional?")
908 }
909 if !long.IsLongTest() {
910 t.Error("the linux-amd64-longtest builder isn't a longtest builder, is that intentional?")
911 }
912 var shortDisabled bool
913 for _, e := range long.Env() {
914 if e == "GO_TEST_SHORT=0" {
915 shortDisabled = true
916 }
917 }
918 if !shortDisabled {
919 t.Error("the linux-amd64-longtest builder doesn't set GO_TEST_SHORT=0, is that intentional?")
920 }
921}
Carlos Amedeed77c6d02020-08-18 13:32:05 -0400922
923func TestHostConfigIsVM(t *testing.T) {
924 testCases := []struct {
925 desc string
926 config *HostConfig
927 want bool
928 }{
929 {
930 desc: "non-ec2-vm",
931 config: &HostConfig{
932 VMImage: "image-x",
933 ContainerImage: "",
934 isEC2: false,
935 },
936 want: true,
937 },
938 {
939 desc: "non-ec2-container",
940 config: &HostConfig{
941 VMImage: "",
942 ContainerImage: "container-image-x",
943 isEC2: false,
944 },
945 want: false,
946 },
947 {
948 desc: "ec2-container",
949 config: &HostConfig{
950 VMImage: "image-x",
951 ContainerImage: "container-image-x",
952 isEC2: true,
953 },
954 want: false,
955 },
956 {
957 desc: "ec2-vm",
958 config: &HostConfig{
959 VMImage: "image-x",
960 ContainerImage: "",
961 isEC2: true,
962 },
963 want: true,
964 },
965 }
966 for _, tc := range testCases {
967 t.Run(fmt.Sprintf(tc.desc), func(t *testing.T) {
968 if got := tc.config.IsVM(); got != tc.want {
969 t.Errorf("HostConfig.IsVM() = %t; want %t", got, tc.want)
970 }
971 })
972 }
973}
Carlos Amedee1e761992020-08-20 11:53:58 -0400974
975func TestModulesEnv(t *testing.T) {
976 testCases := []struct {
977 desc string
978 buildConfig *BuildConfig
979 repo string
980 want []string
981 }{
982 {
983 desc: "ec2-builder-repo-non-go",
984 buildConfig: &BuildConfig{
985 testHostConf: &HostConfig{
986 IsReverse: false,
987 isEC2: true,
988 },
989 },
990 repo: "bar",
991 want: []string{"GOPROXY=https://proxy.golang.org"},
992 },
993 {
994 desc: "reverse-builder-repo-non-go",
995 buildConfig: &BuildConfig{
996 testHostConf: &HostConfig{
997 IsReverse: true,
998 isEC2: false,
999 },
1000 },
1001 repo: "bar",
1002 want: []string{"GOPROXY=https://proxy.golang.org"},
1003 },
1004 {
1005 desc: "reverse-builder-repo-go",
1006 buildConfig: &BuildConfig{
1007 testHostConf: &HostConfig{
1008 IsReverse: true,
1009 isEC2: false,
1010 },
1011 },
1012 repo: "go",
1013 want: []string{"GOPROXY=off"},
1014 },
1015 {
1016 desc: "builder-repo-go",
1017 buildConfig: &BuildConfig{
1018 testHostConf: &HostConfig{
1019 IsReverse: false,
1020 isEC2: false,
1021 },
1022 },
1023 repo: "go",
1024 want: []string{"GOPROXY=off"},
1025 },
1026 {
1027 desc: "builder-repo-go-outbound-network-allowed",
1028 buildConfig: &BuildConfig{
1029 Name: "test-longtest",
1030 testHostConf: &HostConfig{
1031 IsReverse: false,
1032 isEC2: false,
1033 },
1034 },
1035 repo: "go",
1036 want: nil,
1037 },
1038 {
1039 desc: "builder-repo-special-case",
1040 buildConfig: &BuildConfig{
1041 testHostConf: &HostConfig{
1042 IsReverse: false,
1043 isEC2: false,
1044 },
1045 },
1046 repo: "build",
1047 want: []string{"GO111MODULE=on"},
1048 },
1049 {
1050 desc: "reverse-builder-repo-special-case",
1051 buildConfig: &BuildConfig{
1052 testHostConf: &HostConfig{
1053 IsReverse: true,
1054 isEC2: false,
1055 },
1056 },
1057 repo: "build",
1058 want: []string{"GOPROXY=https://proxy.golang.org", "GO111MODULE=on"},
1059 },
1060 {
1061 desc: "builder-repo-non-special-case",
1062 buildConfig: &BuildConfig{
1063 testHostConf: &HostConfig{
1064 IsReverse: false,
1065 isEC2: false,
1066 },
1067 },
1068 repo: "bar",
1069 want: nil,
1070 },
1071 }
1072 for _, tc := range testCases {
1073 t.Run(tc.desc, func(t *testing.T) {
1074 got := tc.buildConfig.ModulesEnv(tc.repo)
1075 if diff := cmp.Diff(tc.want, got); diff != "" {
1076 t.Errorf("BuildConfig.ModulesEnv(%q) mismatch (-want, +got)\n%s", tc.repo, diff)
1077 }
1078 })
1079 }
1080}