blob: 7e1f7d5b160da69364da290f62700b90cd629b32 [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",
Carlos Amedee2ecf4242021-04-23 11:33:51 -040095 "freebsd-amd64-12_2",
Heschi Kreinick4c800c52022-01-05 12:21:24 -050096 "freebsd-amd64-12_3",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +000097 "js-wasm",
98 "linux-386",
99 "linux-amd64",
100 "linux-amd64-race",
Matthew Dempsky4f8007b2021-08-12 15:11:41 -0700101 "linux-amd64-unified",
Carlos Amedeec1822c72021-03-19 13:54:17 -0400102 "linux-arm-aws",
Carlos Amedee34b0d642021-03-19 14:53:06 -0400103 "linux-arm64-aws",
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500104 "openbsd-amd64-68",
Heschi Kreinick90a1d272021-11-15 15:02:19 -0500105 "openbsd-amd64-70",
Alexander Rakoczy87c1ba42021-11-19 14:22:11 -0500106 "openbsd-amd64-70-n1",
Jason A. Donenfeld34415802021-11-23 21:55:31 +0100107 "windows-386-2008",
Carlos Amedeef077b9b2021-11-11 15:05:21 -0500108 "windows-386-2012",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000109 "windows-amd64-2016",
Dmitri Shuralyov646d48d2021-04-23 16:56:37 -0400110
111 "misc-compile-darwinarm64",
112 "misc-compile-freebsd",
113 "misc-compile-mac-win",
114 "misc-compile-mips",
115 "misc-compile-mipsle",
116 "misc-compile-netbsd",
117 "misc-compile-netbsd-arm",
118 "misc-compile-openbsd",
119 "misc-compile-openbsd-arm",
120 "misc-compile-plan9",
121 "misc-compile-ppc",
122 "misc-compile-other-1",
123 "misc-compile-other-2",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000124 },
125 },
126 {
127 repo: "go",
Matthew Dempskydf58bba2021-06-16 23:08:22 -0700128 branch: "dev.typeparams",
Brad Fitzpatrick90670e12019-10-11 18:47:51 +0000129 want: []string{
Cherry Zhang50a78802020-03-13 17:09:21 -0400130 "android-amd64-emu",
Carlos Amedee2ecf4242021-04-23 11:33:51 -0400131 "freebsd-amd64-12_2",
Heschi Kreinick4c800c52022-01-05 12:21:24 -0500132 "freebsd-amd64-12_3",
Brad Fitzpatrick90670e12019-10-11 18:47:51 +0000133 "js-wasm",
134 "linux-386",
135 "linux-amd64",
136 "linux-amd64-race",
Matthew Dempskydf58bba2021-06-16 23:08:22 -0700137 "linux-amd64-unified",
Carlos Amedeec1822c72021-03-19 13:54:17 -0400138 "linux-arm-aws",
Carlos Amedee34b0d642021-03-19 14:53:06 -0400139 "linux-arm64-aws",
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500140 "openbsd-amd64-68",
Heschi Kreinick90a1d272021-11-15 15:02:19 -0500141 "openbsd-amd64-70",
Alexander Rakoczy87c1ba42021-11-19 14:22:11 -0500142 "openbsd-amd64-70-n1",
Jason A. Donenfeld34415802021-11-23 21:55:31 +0100143 "windows-386-2008",
Carlos Amedeef077b9b2021-11-11 15:05:21 -0500144 "windows-386-2012",
Brad Fitzpatrick90670e12019-10-11 18:47:51 +0000145 "windows-amd64-2016",
Dmitri Shuralyov646d48d2021-04-23 16:56:37 -0400146
147 "misc-compile-darwinarm64",
148 "misc-compile-freebsd",
149 "misc-compile-mac-win",
150 "misc-compile-mips",
151 "misc-compile-mipsle",
152 "misc-compile-netbsd",
153 "misc-compile-netbsd-arm",
154 "misc-compile-openbsd",
155 "misc-compile-openbsd-arm",
156 "misc-compile-plan9",
157 "misc-compile-ppc",
158 "misc-compile-other-1",
159 "misc-compile-other-2",
Brad Fitzpatrick90670e12019-10-11 18:47:51 +0000160 },
161 },
162 {
163 repo: "go",
Carlos Amedee060178c2022-01-07 12:21:07 -0500164 branch: "release-branch.go1.17",
165 want: []string{
166 "android-amd64-emu",
167 "freebsd-amd64-12_2",
168 "freebsd-amd64-12_3",
169 "js-wasm",
170 "linux-386",
171 "linux-amd64",
172 "linux-amd64-race",
173 "linux-arm-aws",
174 "linux-arm64-aws",
175 "openbsd-amd64-68",
176 "openbsd-amd64-70",
177 "openbsd-amd64-70-n1",
178 "windows-386-2008",
179 "windows-386-2012",
180 "windows-amd64-2016",
181
182 "misc-compile-darwinarm64",
183 "misc-compile-freebsd",
184 "misc-compile-mac-win",
185 "misc-compile-mips",
186 "misc-compile-mipsle",
187 "misc-compile-netbsd",
188 "misc-compile-netbsd-arm",
189 "misc-compile-openbsd",
190 "misc-compile-openbsd-arm",
191 "misc-compile-plan9",
192 "misc-compile-ppc",
193 "misc-compile-other-1",
194 "misc-compile-other-2",
195
196 // Include longtest builders on Go repo release branches. See issue 37827.
197 "linux-386-longtest",
198 "linux-amd64-longtest",
199 "windows-amd64-longtest",
200 },
201 },
202 {
203 repo: "go",
Dmitri Shuralyov4c544cb2020-11-02 22:25:51 -0500204 branch: "release-branch.go1.16",
205 want: []string{
206 "android-amd64-emu",
Carlos Amedee2ecf4242021-04-23 11:33:51 -0400207 "freebsd-amd64-12_2",
Heschi Kreinick4c800c52022-01-05 12:21:24 -0500208 "freebsd-amd64-12_3",
Dmitri Shuralyov4c544cb2020-11-02 22:25:51 -0500209 "js-wasm",
210 "linux-386",
211 "linux-amd64",
212 "linux-amd64-race",
Carlos Amedeec1822c72021-03-19 13:54:17 -0400213 "linux-arm-aws",
Carlos Amedee34b0d642021-03-19 14:53:06 -0400214 "linux-arm64-aws",
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500215 "openbsd-amd64-68",
Dmitri Shuralyov4c544cb2020-11-02 22:25:51 -0500216 "windows-386-2008",
Jason A. Donenfeld34415802021-11-23 21:55:31 +0100217 "windows-386-2012",
Dmitri Shuralyov4c544cb2020-11-02 22:25:51 -0500218 "windows-amd64-2016",
219
Dmitri Shuralyov646d48d2021-04-23 16:56:37 -0400220 "misc-compile-darwinarm64", // Starts with Go 1.16.
221 "misc-compile-freebsd",
222 "misc-compile-mac-win",
223 "misc-compile-mips",
224 "misc-compile-mipsle",
225 "misc-compile-netbsd",
226 "misc-compile-netbsd-arm",
227 "misc-compile-openbsd",
228 "misc-compile-openbsd-arm",
229 "misc-compile-plan9",
230 "misc-compile-ppc",
231 "misc-compile-other-1",
232 "misc-compile-other-2",
233
Dmitri Shuralyov4c544cb2020-11-02 22:25:51 -0500234 // Include longtest builders on Go repo release branches. See issue 37827.
235 "linux-386-longtest",
236 "linux-amd64-longtest",
237 "windows-amd64-longtest",
238 },
239 },
240 {
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000241 repo: "mobile",
242 branch: "master",
243 want: []string{
244 "android-amd64-emu",
245 "linux-amd64-androidemu",
246 },
247 },
248 {
249 repo: "sys",
250 branch: "master",
251 want: []string{
Brad Fitzpatrick6d867c82019-04-26 14:04:00 +0000252 "android-amd64-emu",
Carlos Amedee858ecaf2021-11-18 16:33:40 -0500253 "freebsd-386-13_0",
Carlos Amedee2ecf4242021-04-23 11:33:51 -0400254 "freebsd-amd64-12_2",
Heschi Kreinick4c800c52022-01-05 12:21:24 -0500255 "freebsd-amd64-12_3",
Carlos Amedee858ecaf2021-11-18 16:33:40 -0500256 "freebsd-amd64-13_0",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000257 "linux-386",
258 "linux-amd64",
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000259 "linux-amd64-race",
Carlos Amedeec1822c72021-03-19 13:54:17 -0400260 "linux-arm-aws",
Carlos Amedee34b0d642021-03-19 14:53:06 -0400261 "linux-arm64-aws",
Dmitri Shuralyov5bbd5582020-04-08 12:43:09 -0400262 "netbsd-amd64-9_0",
Alexander Rakoczy87c1ba42021-11-19 14:22:11 -0500263 "netbsd-amd64-9_0-n1",
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500264 "openbsd-386-68",
Heschi Kreinick90a1d272021-11-15 15:02:19 -0500265 "openbsd-386-70",
Alexander Rakoczy87c1ba42021-11-19 14:22:11 -0500266 "openbsd-386-70-n1",
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500267 "openbsd-amd64-68",
Heschi Kreinick90a1d272021-11-15 15:02:19 -0500268 "openbsd-amd64-70",
Alexander Rakoczy87c1ba42021-11-19 14:22:11 -0500269 "openbsd-amd64-70-n1",
Jason A. Donenfeld34415802021-11-23 21:55:31 +0100270 "windows-386-2008",
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000271 "windows-amd64-2016",
272 },
273 },
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000274 {
275 repo: "exp",
276 branch: "master",
277 want: []string{
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000278 "linux-amd64",
279 "linux-amd64-race",
Jason A. Donenfeld34415802021-11-23 21:55:31 +0100280 "windows-386-2008",
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000281 "windows-amd64-2016",
282 },
283 },
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000284 }
285 for i, tt := range tests {
286 if tt.branch == "" || tt.repo == "" {
287 t.Errorf("incomplete test entry %d", i)
288 return
289 }
290 t.Run(fmt.Sprintf("%s/%s", tt.repo, tt.branch), func(t *testing.T) {
291 var got []string
292 goBranch := tt.branch // hard-code the common case for now
293 for _, bc := range TryBuildersForProject(tt.repo, tt.branch, goBranch) {
294 got = append(got, bc.Name)
295 }
296 m := map[string]bool{}
297 for _, b := range tt.want {
298 m[b] = true
299 }
300 for _, b := range got {
301 if _, ok := m[b]; !ok {
Jason A. Donenfeld34415802021-11-23 21:55:31 +0100302 t.Errorf("got unexpected %q for %s/%s", b, tt.repo, tt.branch)
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000303 }
304 delete(m, b)
305 }
306 for b := range m {
Jason A. Donenfeld34415802021-11-23 21:55:31 +0100307 t.Errorf("missing expected %q for %s/%s", b, tt.repo, tt.branch)
Brad Fitzpatrickc517aed2018-10-26 19:21:58 +0000308 }
309 })
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000310 }
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000311}
312
Dmitri Shuralyove0288b02021-05-07 17:26:04 -0400313// TestBuilderConfig tests whether a given builder and repo at different branches is
314// completely disabled ("none"),
315// a TryBot and a post-submit builder ("both"), or
316// a post-submit only builder ("onlyPost").
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000317func TestBuilderConfig(t *testing.T) {
Dmitri Shuralyove0288b02021-05-07 17:26:04 -0400318 // want is a bitmask of 4 different things to assert are wanted:
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000319 // - being a post-submit builder
320 // - NOT being a post-submit builder
321 // - being a trybot builder
322 // - NOT being a post-submit builder
Dmitri Shuralyove0288b02021-05-07 17:26:04 -0400323 // Note: a builder cannot be configured as a TryBot without also being a post-submit builder.
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000324 type want uint8
325 const (
326 isTrybot want = 1 << iota
327 notTrybot
328 isBuilder // post-submit
329 notBuilder // not post-submit
330
Dmitri Shuralyove0288b02021-05-07 17:26:04 -0400331 // Available combinations:
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000332 none = notTrybot + notBuilder
333 both = isTrybot + isBuilder
334 onlyPost = notTrybot + isBuilder
335 )
336
337 type builderAndRepo struct {
338 testName string
339 builder string
340 repo string
341 branch string
342 goBranch string
343 }
Dmitri Shuralyov76fd6b52019-10-08 13:08:27 -0400344 // builder may end in "@go1.N" or "@1.N" (as alias for "@release-branch.go1.N") or "@branch-name".
345 // 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 +0000346 b := func(builder, repo string) builderAndRepo {
347 br := builderAndRepo{
348 testName: builder + "," + repo,
349 builder: builder,
350 goBranch: "master",
351 repo: repo,
352 branch: "master",
353 }
354 if strings.Contains(builder, "@") {
355 f := strings.SplitN(builder, "@", 2)
356 br.builder = f[0]
357 br.goBranch = f[1]
358 }
359 if strings.Contains(repo, "@") {
360 f := strings.SplitN(repo, "@", 2)
361 br.repo = f[0]
362 br.branch = f[1]
Dmitri Shuralyov76fd6b52019-10-08 13:08:27 -0400363 if br.repo == "go" {
364 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))
365 }
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000366 }
367 expandBranch := func(s *string) {
368 if strings.HasPrefix(*s, "go1.") {
369 *s = "release-branch." + *s
370 } else if strings.HasPrefix(*s, "1.") {
371 *s = "release-branch.go" + *s
372 }
373 }
374 expandBranch(&br.branch)
375 expandBranch(&br.goBranch)
376 if br.repo == "go" {
377 br.branch = br.goBranch
378 }
379 return br
380 }
381 tests := []struct {
382 br builderAndRepo
Dmitri Shuralyove0288b02021-05-07 17:26:04 -0400383 want want // none, both, or onlyPost.
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000384 }{
385 {b("linux-amd64", "go"), both},
386 {b("linux-amd64", "net"), both},
387 {b("linux-amd64", "sys"), both},
Dmitri Shuralyov7aef06b2019-05-16 16:04:34 -0400388 {b("linux-amd64", "website"), both},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000389
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000390 // Don't test all subrepos on all the builders.
391 {b("linux-amd64-ssacheck", "net"), none},
Dmitri Shuralyovdf6c66f2020-10-05 12:20:33 -0400392 {b("linux-amd64-ssacheck@go1.15", "net"), none},
Dmitri Shuralyov0f5b1a72020-10-07 11:24:42 -0400393 {b("linux-386-softfloat", "crypto"), onlyPost},
394 {b("linux-386-softfloat@go1.16", "crypto"), onlyPost},
395 {b("linux-386-softfloat@go1.15", "crypto"), none},
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000396
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000397 // The mobile repo requires Go 1.13+.
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000398 {b("android-amd64-emu", "mobile"), both},
399 {b("android-amd64-emu", "mobile@1.10"), none},
400 {b("android-amd64-emu", "mobile@1.11"), none},
401 {b("android-amd64-emu@go1.10", "mobile"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000402 {b("android-amd64-emu@go1.12", "mobile"), none},
403 {b("android-amd64-emu@go1.13", "mobile"), both},
404 {b("android-amd64-emu", "mobile@1.13"), both},
Dmitri Shuralyov220eca82020-01-10 15:53:25 -0500405
406 {b("android-amd64-emu", "go"), both},
Brad Fitzpatrick6d867c82019-04-26 14:04:00 +0000407 {b("android-amd64-emu", "crypto"), both},
408 {b("android-amd64-emu", "net"), both},
409 {b("android-amd64-emu", "sync"), both},
410 {b("android-amd64-emu", "sys"), both},
411 {b("android-amd64-emu", "text"), both},
412 {b("android-amd64-emu", "time"), both},
413 {b("android-amd64-emu", "tools"), both},
Dmitri Shuralyovbb0f2242019-08-29 09:22:13 -0400414 {b("android-amd64-emu", "website"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000415
416 {b("android-386-emu", "go"), onlyPost},
417 {b("android-386-emu", "mobile"), onlyPost},
418 {b("android-386-emu", "mobile@1.10"), none},
419 {b("android-386-emu", "mobile@1.11"), none},
420 {b("android-386-emu@go1.10", "mobile"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000421 {b("android-386-emu@go1.12", "mobile"), none},
422 {b("android-386-emu@go1.13", "mobile"), onlyPost},
423 {b("android-386-emu", "mobile@1.13"), onlyPost},
424
425 {b("linux-amd64", "net"), both},
426 {b("linux-amd64", "net@1.12"), both},
427 {b("linux-amd64@go1.12", "net@1.12"), both},
428 {b("linux-amd64", "net@1.11"), both},
429 {b("linux-amd64", "net@1.11"), both},
430 {b("linux-amd64", "net@1.10"), none}, // too old
431 {b("linux-amd64@go1.10", "net"), none}, // too old
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000432 {b("linux-amd64@go1.12", "net@1.12"), both},
433
Meng Zhuo88052792019-09-10 07:21:11 +0800434 {b("linux-mips64le-mengzhuo", "go"), onlyPost},
435 {b("linux-mips64le-mengzhuo", "sys"), onlyPost},
436 {b("linux-mips64le-mengzhuo", "net"), onlyPost},
437
Xiaodong Liu5eaa6e02021-09-02 15:51:28 +0800438 {b("linux-loong64-3a5000", "go"), onlyPost},
439 {b("linux-loong64-3a5000", "sys"), onlyPost},
440 {b("linux-loong64-3a5000", "net"), onlyPost},
441
Dmitri Shuralyov5f7fe5e2020-11-10 12:56:57 -0500442 // OpenBSD.
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500443 {b("openbsd-amd64-68@go1.16", "go"), both},
444 {b("openbsd-amd64-68@go1.15", "go"), both},
445 {b("openbsd-amd64-68@go1.14", "go"), both},
Dmitri Shuralyov5f7fe5e2020-11-10 12:56:57 -0500446
Carlos Amedee858ecaf2021-11-18 16:33:40 -0500447 // FreeBSD 13.0
448 {b("freebsd-amd64-13_0", "go"), onlyPost},
449 {b("freebsd-amd64-13_0", "net"), onlyPost},
450 {b("freebsd-amd64-13_0", "mobile"), none},
451 {b("freebsd-386-13_0", "go"), onlyPost},
452 {b("freebsd-386-13_0", "net"), onlyPost},
453 {b("freebsd-386-13_0", "mobile"), none},
454
Carlos Amedee2ecf4242021-04-23 11:33:51 -0400455 // FreeBSD 12.2
456 {b("freebsd-amd64-12_2", "go"), both},
457 {b("freebsd-amd64-12_2", "net"), both},
458 {b("freebsd-amd64-12_2", "mobile"), none},
459 {b("freebsd-386-12_2", "go"), onlyPost},
460 {b("freebsd-386-12_2", "net"), onlyPost},
461 {b("freebsd-386-12_2", "mobile"), none},
462
Carlos Amedee060178c2022-01-07 12:21:07 -0500463 // FreeBSD 11.4
464 {b("freebsd-amd64-11_4@go1.16", "go"), onlyPost},
465 {b("freebsd-amd64-11_4@go1.16", "net"), onlyPost},
466 {b("freebsd-amd64-11_4@go1.16", "sys"), both},
467 {b("freebsd-amd64-11_4", "go"), none},
468 {b("freebsd-386-11_4@go1.17", "go"), onlyPost},
469 {b("freebsd-386-11_4@go1.17", "net"), onlyPost},
470 {b("freebsd-386-11_4@go1.17", "sys"), both},
471 {b("freebsd-386-11_4", "go"), none},
472
Carlos Amedee2ecf4242021-04-23 11:33:51 -0400473 // FreeBSD 11.2
474 // See golang.org/issue/45727
Dmitri Shuralyove0288b02021-05-07 17:26:04 -0400475 {b("freebsd-amd64-11_2@go1.15", "go"), onlyPost},
Carlos Amedee2ecf4242021-04-23 11:33:51 -0400476 {b("freebsd-amd64-11_2@go1.15", "net"), onlyPost},
477 {b("freebsd-amd64-11_2@go1.15", "sys"), both},
478 {b("freebsd-amd64-11_2", "go"), none},
Dmitri Shuralyove0288b02021-05-07 17:26:04 -0400479 {b("freebsd-386-11_2@go1.16", "go"), onlyPost},
Carlos Amedee2ecf4242021-04-23 11:33:51 -0400480 {b("freebsd-386-11_2@go1.16", "net"), onlyPost},
481 {b("freebsd-386-11_2@go1.16", "sys"), both},
482 {b("freebsd-386-11_2", "go"), none},
Brad Fitzpatrick9e52fce2019-03-12 21:13:50 +0000483
Brad Fitzpatrickfcf7a582019-04-30 22:37:31 +0000484 // NetBSD
Dmitri Shuralyov5bbd5582020-04-08 12:43:09 -0400485 {b("netbsd-amd64-9_0", "go"), onlyPost},
486 {b("netbsd-amd64-9_0", "net"), onlyPost},
Dmitri Shuralyovb7c61f72020-04-09 07:59:16 -0400487 {b("netbsd-amd64-9_0", "sys"), both},
Dmitri Shuralyov5bbd5582020-04-08 12:43:09 -0400488 {b("netbsd-386-9_0", "go"), onlyPost},
489 {b("netbsd-386-9_0", "net"), onlyPost},
Brad Fitzpatrickfcf7a582019-04-30 22:37:31 +0000490
Tobias Klauserb7b66932019-03-13 09:29:15 +0100491 // AIX starts at Go 1.12
492 {b("aix-ppc64", "go"), onlyPost},
493 {b("aix-ppc64", "net"), onlyPost},
Tobias Klauserc2ec9e42019-06-04 10:14:55 +0200494 {b("aix-ppc64", "mobile"), none},
495 {b("aix-ppc64", "exp"), none},
Tobias Klausercbdd89b2019-10-14 11:31:13 +0200496 {b("aix-ppc64", "term"), onlyPost},
Dmitri Shuralyov43ea6942021-02-19 12:17:28 -0500497 {b("aix-ppc64@go1.15", "go"), onlyPost},
498 {b("aix-ppc64@go1.15", "net"), onlyPost},
499 {b("aix-ppc64@go1.15", "mobile"), none},
500 {b("aix-ppc64@go1.16", "net"), onlyPost},
501 {b("aix-ppc64@go1.16", "mobile"), none},
Cherry Zhang50a78802020-03-13 17:09:21 -0400502 {b("aix-ppc64@dev.link", "go"), onlyPost},
Tobias Klauserb7b66932019-03-13 09:29:15 +0100503
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000504 {b("linux-amd64-nocgo", "mobile"), none},
505
Elias Naur4d0f77a2019-05-01 22:28:43 +0200506 // Virtual mobiledevices
Dmitri Shuralyove0288b02021-05-07 17:26:04 -0400507 {b("ios-arm64-corellium", "go"), onlyPost},
508 {b("android-arm64-corellium", "go"), onlyPost},
509 {b("android-arm-corellium", "go"), onlyPost},
Elias Naur6bebc8e2019-05-01 20:33:26 +0200510
Elias Naur18919d62020-10-03 11:37:07 +0200511 // Mobile builders that run with GOOS=linux/ios and have
Brad Fitzpatrick13f1da92019-03-12 16:21:55 +0000512 // a device attached.
513 {b("linux-amd64-androidemu", "mobile"), both},
Brad Fitzpatrick13f1da92019-03-12 16:21:55 +0000514
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000515 // But the emulators run all:
Dmitri Shuralyove0288b02021-05-07 17:26:04 -0400516 {b("android-amd64-emu", "mobile"), both},
517 {b("android-386-emu", "mobile"), onlyPost},
518 {b("android-amd64-emu", "net"), both},
519 {b("android-386-emu", "net"), onlyPost},
520 {b("android-amd64-emu", "go"), both},
521 {b("android-386-emu", "go"), onlyPost},
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000522
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000523 // Only test tip for js/wasm, and only for some repos:
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000524 {b("js-wasm", "go"), both},
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000525 {b("js-wasm", "arch"), onlyPost},
526 {b("js-wasm", "crypto"), onlyPost},
527 {b("js-wasm", "sys"), onlyPost},
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000528 {b("js-wasm", "net"), onlyPost},
529 {b("js-wasm@go1.12", "net"), none},
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000530 {b("js-wasm", "benchmarks"), none},
531 {b("js-wasm", "debug"), none},
532 {b("js-wasm", "mobile"), none},
533 {b("js-wasm", "perf"), none},
534 {b("js-wasm", "talks"), none},
535 {b("js-wasm", "tools"), none},
536 {b("js-wasm", "tour"), none},
537 {b("js-wasm", "website"), none},
538
539 // Race builders. Linux for all, GCE buidlers for
540 // post-submit, and only post-submit for "go" for
541 // Darwin (limited resources).
542 {b("linux-amd64-race", "go"), both},
543 {b("linux-amd64-race", "net"), both},
544 {b("windows-amd64-race", "go"), onlyPost},
545 {b("windows-amd64-race", "net"), onlyPost},
546 {b("freebsd-amd64-race", "go"), onlyPost},
547 {b("freebsd-amd64-race", "net"), onlyPost},
548 {b("darwin-amd64-race", "go"), onlyPost},
549 {b("darwin-amd64-race", "net"), none},
550
551 // Long test.
552 {b("linux-amd64-longtest", "go"), onlyPost},
553 {b("linux-amd64-longtest", "net"), onlyPost},
Dmitri Shuralyov5a8fb632020-05-26 18:19:05 -0400554 {b("linux-amd64-longtest@go1.14", "go"), both},
Dmitri Shuralyov9e7a7622020-05-26 18:12:12 -0400555 {b("linux-amd64-longtest@go1.14", "net"), none},
Brad Fitzpatrickf9c537e2019-10-28 20:16:36 +0000556 {b("windows-amd64-longtest", "go"), onlyPost},
Dmitri Shuralyov5a8fb632020-05-26 18:19:05 -0400557 {b("windows-amd64-longtest@go1.14", "go"), both},
Brad Fitzpatrickf9c537e2019-10-28 20:16:36 +0000558 {b("windows-amd64-longtest", "net"), onlyPost},
559 {b("windows-amd64-longtest", "exp"), onlyPost},
560 {b("windows-amd64-longtest", "mobile"), none},
Dmitri Shuralyovdd5ac552020-07-01 14:14:47 -0400561 {b("linux-386-longtest", "go"), onlyPost},
562 {b("linux-386-longtest", "net"), onlyPost},
563 {b("linux-386-longtest", "exp"), none},
564 {b("linux-386-longtest", "mobile"), none},
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000565
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000566 // Experimental exp repo runs in very few places.
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000567 {b("linux-amd64", "exp"), both},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000568 {b("linux-amd64-race", "exp"), both},
569 {b("linux-amd64-longtest", "exp"), onlyPost},
Jason A. Donenfeld34415802021-11-23 21:55:31 +0100570 {b("windows-386-2008", "exp"), both},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000571 {b("windows-amd64-2016", "exp"), both},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000572 {b("darwin-amd64-10_14", "exp"), onlyPost},
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000573 {b("darwin-amd64-10_15", "exp"), onlyPost},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000574 // ... but not on most others:
Dmitri Shuralyov3b77b3a2019-09-28 17:43:42 +0000575 {b("darwin-amd64-10_12", "exp"), none},
Carlos Amedee2ecf4242021-04-23 11:33:51 -0400576 {b("freebsd-386-11_4", "exp"), none},
577 {b("freebsd-386-12_2", "exp"), none},
578 {b("freebsd-amd64-11_4", "exp"), none},
579 {b("freebsd-amd64-12_2", "exp"), none},
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500580 {b("openbsd-amd64-68", "exp"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000581 {b("js-wasm", "exp"), none},
582
583 // exp is experimental; it doesn't test against release branches.
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000584 {b("linux-amd64@go1.12", "exp"), none},
Brad Fitzpatrick8a071d42019-03-18 16:48:22 +0000585
Brad Fitzpatrickc8ca9622019-12-07 05:14:28 +0000586 // the build repo is only really useful for linux-amd64 (where we run it),
587 // and darwin-amd64 and perhaps windows-amd64 (for stuff like gomote).
588 // No need for any other operating systems to use it.
589 {b("linux-amd64", "build"), both},
590 {b("linux-amd64-longtest", "build"), onlyPost},
591 {b("windows-amd64-2016", "build"), both},
592 {b("darwin-amd64-10_12", "build"), none},
593 {b("darwin-amd64-10_14", "build"), none},
594 {b("darwin-amd64-10_15", "build"), onlyPost},
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500595 {b("openbsd-amd64-68", "build"), none},
Brad Fitzpatrickc8ca9622019-12-07 05:14:28 +0000596 {b("linux-amd64-fedora", "build"), none},
597 {b("linux-amd64-clang", "build"), none},
598 {b("linux-amd64-sid", "build"), none},
Carlos Amedee43864932021-08-16 15:35:39 -0400599 {b("linux-amd64-bullseye", "build"), none},
Brad Fitzpatrickf6d512d2019-12-12 17:43:59 +0000600 {b("linux-amd64-nocgo", "build"), none},
601 {b("linux-386-longtest", "build"), none},
Brad Fitzpatrickf6d512d2019-12-12 17:43:59 +0000602 {b("js-wasm", "build"), none},
603 {b("android-386-emu", "build"), none},
604 {b("android-amd64-emu", "build"), none},
Brad Fitzpatrickc8ca9622019-12-07 05:14:28 +0000605
Brad Fitzpatrick8a071d42019-03-18 16:48:22 +0000606 // Only use latest macOS for subrepos, and only amd64:
Carlos Amedee6469a762021-04-22 13:51:16 -0400607 {b("darwin-amd64-10_12@go1.16", "net"), onlyPost},
608 {b("darwin-amd64-10_12", "net"), none},
609 {b("darwin-amd64-10_14", "net"), onlyPost},
Brad Fitzpatrick8bd8e0e2019-03-26 23:04:31 +0000610
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000611 {b("darwin-amd64-10_15", "go"), onlyPost},
Brad Fitzpatrick8bd8e0e2019-03-26 23:04:31 +0000612 {b("darwin-amd64-10_14", "go"), onlyPost},
Carlos Amedee6469a762021-04-22 13:51:16 -0400613 {b("darwin-amd64-10_12", "go"), none},
614 {b("darwin-amd64-10_12@go1.16", "go"), onlyPost},
Brad Fitzpatrick85a73d72019-04-03 04:45:29 +0000615
Brad Fitzpatrick67073b92019-04-18 19:33:19 +0000616 // plan9 only lived at master. We didn't support any past releases.
617 // But it's off for now as it's always failing.
618 {b("plan9-386", "go"), none}, // temporarily disabled
619 {b("plan9-386", "net"), none}, // temporarily disabled
Tobias Klauser22d3b242019-11-28 11:33:00 +0100620 {b("plan9-386", "exp"), none},
621 {b("plan9-386", "mobile"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000622 {b("plan9-386@go1.12", "go"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000623 {b("plan9-386@go1.12", "net"), none},
David du Colombier9d711212021-04-05 20:42:05 +0200624 {b("plan9-amd64-0intro", "go"), onlyPost},
625 {b("plan9-amd64-0intro", "exp"), none},
626 {b("plan9-amd64-0intro", "mobile"), none},
627 {b("plan9-amd64-0intro@go1.12", "go"), none},
628 {b("plan9-amd64-0intro", "net"), onlyPost},
629 {b("plan9-amd64-0intro@go1.12", "net"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000630 {b("plan9-arm", "go"), onlyPost},
Tobias Klauser22d3b242019-11-28 11:33:00 +0100631 {b("plan9-arm", "exp"), none},
632 {b("plan9-arm", "mobile"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000633 {b("plan9-arm@go1.12", "go"), none},
634 {b("plan9-arm", "net"), onlyPost},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000635 {b("plan9-arm@go1.12", "net"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000636
Brad Fitzpatrick58771952019-10-21 15:00:32 +0000637 {b("dragonfly-amd64", "go"), onlyPost},
638 {b("dragonfly-amd64", "net"), onlyPost},
639 {b("dragonfly-amd64@go1.13", "net"), none}, // Dragonfly ABI changes only supported by Go 1.14+
640 {b("dragonfly-amd64@go1.13", "go"), none}, // Dragonfly ABI changes only supported by Go 1.14+
Dmitri Shuralyov77c96bb2020-03-19 10:34:11 -0400641
642 {b("linux-amd64-staticlockranking", "go"), onlyPost},
643 {b("linux-amd64-staticlockranking@go1.15", "go"), onlyPost},
644 {b("linux-amd64-staticlockranking@go1.14", "go"), none},
645 {b("linux-amd64-staticlockranking", "net"), none},
Austin Clements80886082020-12-21 16:08:53 -0500646
Matthew Dempsky4f8007b2021-08-12 15:11:41 -0700647 {b("linux-amd64-unified", "go"), both},
648 {b("linux-amd64-unified", "tools"), both},
Matthew Dempskydf58bba2021-06-16 23:08:22 -0700649 {b("linux-amd64-unified", "net"), none},
650 {b("linux-amd64-unified@dev.typeparams", "go"), both},
651 {b("linux-amd64-unified@dev.typeparams", "tools"), both},
652 {b("linux-amd64-unified@dev.typeparams", "net"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000653 }
654 for _, tt := range tests {
655 t.Run(tt.br.testName, func(t *testing.T) {
Dmitri Shuralyove0288b02021-05-07 17:26:04 -0400656 // Require a want value that asserts both dimensions: try or not, post or not.
657 switch tt.want {
658 case none, both, onlyPost:
659 // OK.
660 default:
661 t.Fatalf("tt.want must be one of: none, both, or onlyPost")
662 }
663
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000664 bc, ok := Builders[tt.br.builder]
665 if !ok {
666 t.Fatalf("unknown builder %q", tt.br.builder)
667 }
668 gotPost := bc.BuildsRepoPostSubmit(tt.br.repo, tt.br.branch, tt.br.goBranch)
669 if tt.want&isBuilder != 0 && !gotPost {
670 t.Errorf("not a post-submit builder, but expected")
671 }
672 if tt.want&notBuilder != 0 && gotPost {
673 t.Errorf("unexpectedly a post-submit builder")
674 }
675
676 gotTry := bc.BuildsRepoTryBot(tt.br.repo, tt.br.branch, tt.br.goBranch)
677 if tt.want&isTrybot != 0 && !gotTry {
678 t.Errorf("not trybot, but expected")
679 }
680 if tt.want&notTrybot != 0 && gotTry {
681 t.Errorf("unexpectedly a trybot")
682 }
683
684 if t.Failed() {
685 t.Logf("For: %+v", tt.br)
686 }
687 })
688 }
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000689}
690
691func TestHostConfigsAllUsed(t *testing.T) {
Dmitri Shuralyov07688122020-08-04 12:01:34 -0400692 knownUnused := map[string]bool{
693 // Currently host-linux-armhf-cross and host-linux-armel-cross aren't
694 // referenced, but the coordinator hard-codes them, so don't make
695 // these two an error for now.
696 "host-linux-armhf-cross": true,
697 "host-linux-armel-cross": true,
698
699 "host-linux-x86-alpine": true, // TODO(golang.org/issue/19938): Fix the Alpine builder, or remove it.
Dmitri Shuralyov07688122020-08-04 12:01:34 -0400700 }
701
702 used := make(map[string]bool)
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000703 for _, conf := range Builders {
704 used[conf.HostType] = true
705 }
706 for hostType := range Hosts {
Dmitri Shuralyov07688122020-08-04 12:01:34 -0400707 if !used[hostType] && !knownUnused[hostType] {
708 t.Errorf("host type %q is not referenced from any build config", hostType)
709 }
710 if used[hostType] && knownUnused[hostType] {
711 t.Errorf("host type %q should not be listed in knownUnused since it's in use", hostType)
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000712 }
713 }
714}
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000715
Dmitri Shuralyov2891c2e2021-11-16 12:42:29 -0500716// Test that all specified builder owners are non-nil.
717func TestBuilderOwners(t *testing.T) {
718 for host, config := range Hosts {
719 for i, p := range config.Owners {
720 if p == nil {
721 t.Errorf("dashboard.Hosts[%q].Owners[%d] is nil, want non-nil", host, i)
722 }
723 }
724 }
725}
726
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000727// tests that goBranch is optional for repo == "go"
728func TestBuildsRepoAtAllImplicitGoBranch(t *testing.T) {
729 builder := Builders["android-amd64-emu"]
730 got := builder.buildsRepoAtAll("go", "master", "")
731 if !got {
732 t.Error("got = false; want true")
733 }
734}
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000735
736func TestShouldRunDistTest(t *testing.T) {
737 type buildMode int
738 const (
739 tryMode buildMode = 0
740 postSubmit buildMode = 1
741 )
742
743 tests := []struct {
744 builder string
745 test string
746 mode buildMode
747 want bool
748 }{
749 {"linux-amd64", "api", postSubmit, true},
750 {"linux-amd64", "api", tryMode, true},
Carlos Amedee2ecf4242021-04-23 11:33:51 -0400751 {"freebsd-amd64-12_2", "api", postSubmit, true}, // freebsd-amd64-12_2 uses fasterTrybots policy, should still build.
752 {"freebsd-amd64-12_2", "api", tryMode, false}, // freebsd-amd64-12_2 uses fasterTrybots policy, should skip in try mode.
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000753
754 {"linux-amd64", "reboot", tryMode, true},
755 {"linux-amd64-race", "reboot", tryMode, false},
756
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000757 {"darwin-amd64-10_12", "test:foo", postSubmit, false},
758 {"darwin-amd64-10_14", "test:foo", postSubmit, false},
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000759 {"darwin-amd64-10_14", "reboot", postSubmit, false},
760 {"darwin-amd64-10_14", "api", postSubmit, false},
761 {"darwin-amd64-10_14", "codewalk", postSubmit, false},
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000762 {"darwin-amd64-10_15", "test:foo", postSubmit, false},
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000763 }
764 for _, tt := range tests {
765 bc, ok := Builders[tt.builder]
766 if !ok {
767 t.Errorf("unknown builder %q", tt.builder)
768 continue
769 }
770 isTry := tt.mode == tryMode
771 if isTry && !bc.BuildsRepoTryBot("go", "master", "master") {
772 t.Errorf("builder %q is not a trybot, so can't run test %q in try mode", tt.builder, tt.test)
773 continue
774 }
775 got := bc.ShouldRunDistTest(tt.test, isTry)
776 if got != tt.want {
777 t.Errorf("%q.ShouldRunDistTest(%q, try %v) = %v; want %v", tt.builder, tt.test, isTry, got, tt.want)
778 }
779 }
780}
Dmitri Shuralyov01fd2992019-09-09 16:48:08 -0400781
Brad Fitzpatrickaab85042019-10-16 06:02:29 +0000782func TestSlowBotAliases(t *testing.T) {
783 for term, name := range slowBotAliases {
784 if name == "" {
785 // Empty string means known missing builder.
786 continue
787 }
788 if _, ok := Builders[name]; !ok {
789 t.Errorf("slowbot term %q references unknown builder %q", term, name)
790 }
791 }
792
793 out, err := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "tool", "dist", "list").Output()
794 if err != nil {
795 t.Errorf("dist list: %v", err)
796 }
797 ports := strings.Fields(string(out))
798
799 done := map[string]bool{}
Carlos Amedee3e01d872020-04-22 18:52:59 -0400800
Brad Fitzpatrickaab85042019-10-16 06:02:29 +0000801 var add bytes.Buffer
802 check := func(term string, isArch bool) {
803 if done[term] {
804 return
805 }
806 done[term] = true
807 _, isBuilderName := Builders[term]
808 _, hasAlias := slowBotAliases[term]
809 if !isBuilderName && !hasAlias {
810 prefix := term
811 if isArch {
812 prefix = "linux-" + term
813 }
814 var matches []string
815 for name := range Builders {
816 if strings.HasPrefix(name, prefix) {
817 matches = append(matches, name)
818 }
819 }
820 sort.Strings(matches)
821 t.Errorf("term %q has no match in slowBotAliases", term)
822 if len(matches) == 1 {
823 fmt.Fprintf(&add, "%q: %q,\n", term, matches[0])
824 } else if len(matches) > 1 {
825 t.Errorf("maybe add: %q: %q, (matches=%q)", term, matches[len(matches)-1], matches)
826 }
827 }
828 }
829
830 for _, port := range ports {
831 slash := strings.IndexByte(port, '/')
832 if slash == -1 {
833 t.Fatalf("unexpected port %q", port)
834 }
835 goos, goarch := port[:slash], port[slash+1:]
836 check(goos+"-"+goarch, false)
837 check(goos, false)
838 check(goarch, true)
839 }
840
841 if add.Len() > 0 {
842 t.Errorf("Missing items from slowBotAliases:\n%s", add.String())
843 }
844}
Brad Fitzpatrickad7af462019-10-19 02:49:53 +0000845
846func TestCrossCompileConfigs(t *testing.T) {
847 // Verify that Builders.CrossCompileConfig have valid host types.
848 for name, bc := range Builders {
849 cc := bc.CrossCompileConfig
850 if cc == nil {
851 continue
852 }
853 if _, ok := Hosts[cc.CompileHostType]; !ok {
854 t.Errorf("unknown host type %q for builder %q", cc.CompileHostType, name)
855 }
856 }
857}
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100858
Dmitri Shuralyov646d48d2021-04-23 16:56:37 -0400859// TestTryBotsCompileAllPorts verifies that each port (go tool dist list)
860// is covered by either a real TryBot or a misc-compile TryBot.
861//
862// The special pseudo-port 'linux-arm-arm5' is tested in TestMiscCompileLinuxGOARM5.
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100863func TestTryBotsCompileAllPorts(t *testing.T) {
864 out, err := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "tool", "dist", "list").Output()
865 if err != nil {
866 t.Errorf("dist list: %v", err)
867 }
868 ports := strings.Fields(string(out))
869
Dmitri Shuralyovca017122021-04-23 14:08:15 -0400870 // knownMissing tracks Go ports that that are known to be
871 // completely missing TryBot (pre-submit) test coverage.
872 //
Dmitri Shuralyovf9ec3ca2021-04-27 15:33:27 -0400873 // All completed ports should have either a real TryBot or at least a misc-compile TryBot,
Dmitri Shuralyovca017122021-04-23 14:08:15 -0400874 // so this map is meant to be used to temporarily fix tests
875 // when the work of adding a new port is actively underway.
Dmitri Shuralyovf9ec3ca2021-04-27 15:33:27 -0400876 knownMissing := map[string]bool{}
Dmitri Shuralyovca017122021-04-23 14:08:15 -0400877
878 var done = make(map[string]bool)
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100879 check := func(goos, goarch string) {
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400880 if goos == "android" || goos == "ios" {
Brad Fitzpatrick8a3c1d92019-11-15 04:29:29 +0000881 // TODO(golang.org/issue/25963): support
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400882 // compilation-only Android and iOS trybots.
Brad Fitzpatrick8a3c1d92019-11-15 04:29:29 +0000883 // buildall.bash doesn't set the environment
884 // up enough for e.g. compiling android-386
885 // from linux-amd64. (Issue #35596 too)
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400886 // iOS likely needs to be built on macOS
887 // with Xcode available.
Brad Fitzpatrick8a3c1d92019-11-15 04:29:29 +0000888 return
889 }
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100890 goosArch := goos + "-" + goarch
891 if done[goosArch] {
892 return
893 }
894 for _, conf := range Builders {
Dmitri Shuralyov2e5c6aa2021-04-26 15:33:46 -0400895 if conf.GOOS() == goos && conf.GOARCH() == goarch &&
896 conf.BuildsRepoTryBot("go", "master", "master") {
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100897
Dmitri Shuralyov2e5c6aa2021-04-26 15:33:46 -0400898 // There's a real TryBot for this GOOS/GOARCH pair.
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100899 done[goosArch] = true
900 break
901 }
902
903 if strings.HasPrefix(conf.Name, "misc-compile-") {
904 re, err := regexp.Compile(conf.allScriptArgs[0])
905 if err != nil {
Dmitri Shuralyov2e5c6aa2021-04-26 15:33:46 -0400906 t.Fatalf("invalid misc-compile filtering pattern for builder %q: %q",
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100907 conf.Name, conf.allScriptArgs[0])
908 }
Dmitri Shuralyov2e5c6aa2021-04-26 15:33:46 -0400909 if re.MatchString(goosArch) {
910 // There's a misc-compile TryBot for this GOOS/GOARCH pair.
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100911 done[goosArch] = true
912 break
913 }
914 }
915 }
Dmitri Shuralyovca017122021-04-23 14:08:15 -0400916 if knownMissing[goosArch] && done[goosArch] {
917 // Make it visible when a builder is added but the old
918 // knownMissing entry isn't removed by failing the test.
919 t.Errorf("knownMissing[%q] is true, but a corresponding TryBot (real or misc-compile) exists", goosArch)
920 } else if _, ok := done[goosArch]; !ok && !knownMissing[goosArch] {
921 t.Errorf("missing real TryBot or misc-compile TryBot for %q", goosArch)
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100922 }
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100923 }
924
925 for _, port := range ports {
926 slash := strings.IndexByte(port, '/')
927 if slash == -1 {
928 t.Fatalf("unexpected port %q", port)
929 }
930 check(port[:slash], port[slash+1:])
931 }
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100932}
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000933
Dmitri Shuralyov646d48d2021-04-23 16:56:37 -0400934// The 'linux-arm-arm5' pseduo-port is supported by src/buildall.bash
935// and tests linux/arm with GOARM=5 set. Since it's not a normal port,
936// the TestTryBotsCompileAllPorts wouldn't report if the misc-compile
937// TryBot that covers is is accidentally removed. Check it explicitly.
938func TestMiscCompileLinuxGOARM5(t *testing.T) {
939 var ok bool
940 for _, b := range Builders {
941 if !strings.HasPrefix(b.Name, "misc-compile-") {
942 continue
943 }
944 re, err := regexp.Compile(b.allScriptArgs[0])
945 if err != nil {
946 t.Fatalf("invalid misc-compile filtering pattern for builder %q: %q",
947 b.Name, b.allScriptArgs[0])
948 }
949 if re.MatchString("linux-arm-arm5") {
950 ok = true
951 break
952 }
953 }
954 if !ok {
955 // We get here if the linux-arm-arm5 port is no longer checked by
956 // a misc-compile TryBot. Report it as a failure in case the coverage
957 // was removed accidentally (e.g., as part of a refactor).
958 t.Errorf("no misc-compile TryBot coverage for the special 'linux-arm-arm5' pseudo-port")
959 }
960}
961
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000962// TestExpectedMacstadiumVMCount ensures that only 20 instances of macOS virtual machines
963// are expected at MacStadium.
964// TODO: remove once the scheduler allocates VMs based on demand https://golang.org/issue/35698
965func TestExpectedMacstadiumVMCount(t *testing.T) {
966 got := 0
967 for host, config := range Hosts {
Carlos Amedeed576fd32021-01-29 15:47:13 -0500968 if strings.HasPrefix(host, "host-darwin-10_") || strings.HasPrefix(host, "host-darwin-amd64-") {
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000969 got += config.ExpectNum
970 }
971 }
Carlos Amedeeb7678aa2021-04-06 11:28:57 -0400972 if got != 16 {
973 t.Fatalf("macstadium host count: got %d; want 16", got)
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000974 }
975}
Dmitri Shuralyovdf328b12020-05-13 14:30:25 -0400976
977// Test that we have a longtest builder and
978// that its environment configuration is okay.
979func TestLongTestBuilder(t *testing.T) {
980 long, ok := Builders["linux-amd64-longtest"]
981 if !ok {
982 t.Fatal("we don't have a linux-amd64-longtest builder anymore, is that intentional?")
983 }
984 if !long.IsLongTest() {
985 t.Error("the linux-amd64-longtest builder isn't a longtest builder, is that intentional?")
986 }
987 var shortDisabled bool
988 for _, e := range long.Env() {
989 if e == "GO_TEST_SHORT=0" {
990 shortDisabled = true
991 }
992 }
993 if !shortDisabled {
994 t.Error("the linux-amd64-longtest builder doesn't set GO_TEST_SHORT=0, is that intentional?")
995 }
996}
Carlos Amedeed77c6d02020-08-18 13:32:05 -0400997
998func TestHostConfigIsVM(t *testing.T) {
999 testCases := []struct {
1000 desc string
1001 config *HostConfig
1002 want bool
1003 }{
1004 {
1005 desc: "non-ec2-vm",
1006 config: &HostConfig{
1007 VMImage: "image-x",
1008 ContainerImage: "",
1009 isEC2: false,
1010 },
1011 want: true,
1012 },
1013 {
1014 desc: "non-ec2-container",
1015 config: &HostConfig{
1016 VMImage: "",
1017 ContainerImage: "container-image-x",
1018 isEC2: false,
1019 },
1020 want: false,
1021 },
1022 {
1023 desc: "ec2-container",
1024 config: &HostConfig{
1025 VMImage: "image-x",
1026 ContainerImage: "container-image-x",
1027 isEC2: true,
1028 },
1029 want: false,
1030 },
1031 {
1032 desc: "ec2-vm",
1033 config: &HostConfig{
1034 VMImage: "image-x",
1035 ContainerImage: "",
1036 isEC2: true,
1037 },
1038 want: true,
1039 },
1040 }
1041 for _, tc := range testCases {
1042 t.Run(fmt.Sprintf(tc.desc), func(t *testing.T) {
1043 if got := tc.config.IsVM(); got != tc.want {
1044 t.Errorf("HostConfig.IsVM() = %t; want %t", got, tc.want)
1045 }
1046 })
1047 }
1048}
Carlos Amedee1e761992020-08-20 11:53:58 -04001049
1050func TestModulesEnv(t *testing.T) {
1051 testCases := []struct {
1052 desc string
1053 buildConfig *BuildConfig
1054 repo string
1055 want []string
1056 }{
1057 {
1058 desc: "ec2-builder-repo-non-go",
1059 buildConfig: &BuildConfig{
1060 testHostConf: &HostConfig{
1061 IsReverse: false,
1062 isEC2: true,
1063 },
1064 },
1065 repo: "bar",
1066 want: []string{"GOPROXY=https://proxy.golang.org"},
1067 },
1068 {
1069 desc: "reverse-builder-repo-non-go",
1070 buildConfig: &BuildConfig{
1071 testHostConf: &HostConfig{
1072 IsReverse: true,
1073 isEC2: false,
1074 },
1075 },
1076 repo: "bar",
1077 want: []string{"GOPROXY=https://proxy.golang.org"},
1078 },
1079 {
1080 desc: "reverse-builder-repo-go",
1081 buildConfig: &BuildConfig{
1082 testHostConf: &HostConfig{
1083 IsReverse: true,
1084 isEC2: false,
1085 },
1086 },
1087 repo: "go",
1088 want: []string{"GOPROXY=off"},
1089 },
1090 {
1091 desc: "builder-repo-go",
1092 buildConfig: &BuildConfig{
1093 testHostConf: &HostConfig{
1094 IsReverse: false,
1095 isEC2: false,
1096 },
1097 },
1098 repo: "go",
1099 want: []string{"GOPROXY=off"},
1100 },
1101 {
1102 desc: "builder-repo-go-outbound-network-allowed",
1103 buildConfig: &BuildConfig{
1104 Name: "test-longtest",
1105 testHostConf: &HostConfig{
1106 IsReverse: false,
1107 isEC2: false,
1108 },
1109 },
1110 repo: "go",
1111 want: nil,
1112 },
1113 {
1114 desc: "builder-repo-special-case",
1115 buildConfig: &BuildConfig{
1116 testHostConf: &HostConfig{
1117 IsReverse: false,
1118 isEC2: false,
1119 },
1120 },
1121 repo: "build",
1122 want: []string{"GO111MODULE=on"},
1123 },
1124 {
1125 desc: "reverse-builder-repo-special-case",
1126 buildConfig: &BuildConfig{
1127 testHostConf: &HostConfig{
1128 IsReverse: true,
1129 isEC2: false,
1130 },
1131 },
1132 repo: "build",
1133 want: []string{"GOPROXY=https://proxy.golang.org", "GO111MODULE=on"},
1134 },
1135 {
1136 desc: "builder-repo-non-special-case",
1137 buildConfig: &BuildConfig{
1138 testHostConf: &HostConfig{
1139 IsReverse: false,
1140 isEC2: false,
1141 },
1142 },
1143 repo: "bar",
1144 want: nil,
1145 },
1146 }
1147 for _, tc := range testCases {
1148 t.Run(tc.desc, func(t *testing.T) {
1149 got := tc.buildConfig.ModulesEnv(tc.repo)
1150 if diff := cmp.Diff(tc.want, got); diff != "" {
1151 t.Errorf("BuildConfig.ModulesEnv(%q) mismatch (-want, +got)\n%s", tc.repo, diff)
1152 }
1153 })
1154 }
1155}