blob: 9ac9560fc2a6ee86b141b0281ef8dad0b22f6ff6 [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 Shuralyov43ea6942021-02-19 12:17:28 -0500175 branch: "release-branch.go1.15",
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 Shuralyov220eca82020-01-10 15:53:25 -0500365
366 {b("android-amd64-emu", "go"), both},
Brad Fitzpatrick6d867c82019-04-26 14:04:00 +0000367 {b("android-amd64-emu", "crypto"), both},
368 {b("android-amd64-emu", "net"), both},
369 {b("android-amd64-emu", "sync"), both},
370 {b("android-amd64-emu", "sys"), both},
371 {b("android-amd64-emu", "text"), both},
372 {b("android-amd64-emu", "time"), both},
373 {b("android-amd64-emu", "tools"), both},
Dmitri Shuralyovbb0f2242019-08-29 09:22:13 -0400374 {b("android-amd64-emu", "website"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000375
376 {b("android-386-emu", "go"), onlyPost},
377 {b("android-386-emu", "mobile"), onlyPost},
378 {b("android-386-emu", "mobile@1.10"), none},
379 {b("android-386-emu", "mobile@1.11"), none},
380 {b("android-386-emu@go1.10", "mobile"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000381 {b("android-386-emu@go1.12", "mobile"), none},
382 {b("android-386-emu@go1.13", "mobile"), onlyPost},
383 {b("android-386-emu", "mobile@1.13"), onlyPost},
384
385 {b("linux-amd64", "net"), both},
386 {b("linux-amd64", "net@1.12"), both},
387 {b("linux-amd64@go1.12", "net@1.12"), both},
388 {b("linux-amd64", "net@1.11"), both},
389 {b("linux-amd64", "net@1.11"), both},
390 {b("linux-amd64", "net@1.10"), none}, // too old
391 {b("linux-amd64@go1.10", "net"), none}, // too old
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000392 {b("linux-amd64@go1.12", "net@1.12"), both},
393
Meng Zhuo88052792019-09-10 07:21:11 +0800394 {b("linux-mips64le-mengzhuo", "go"), onlyPost},
395 {b("linux-mips64le-mengzhuo", "sys"), onlyPost},
396 {b("linux-mips64le-mengzhuo", "net"), onlyPost},
397
Dmitri Shuralyov5f7fe5e2020-11-10 12:56:57 -0500398 // OpenBSD.
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500399 {b("openbsd-amd64-68@go1.16", "go"), both},
400 {b("openbsd-amd64-68@go1.15", "go"), both},
401 {b("openbsd-amd64-68@go1.14", "go"), both},
402 {b("openbsd-amd64-64@go1.16", "go"), onlyPost},
403 {b("openbsd-amd64-64@go1.15", "go"), onlyPost},
404 {b("openbsd-amd64-64@go1.14", "go"), onlyPost},
Dmitri Shuralyov5f7fe5e2020-11-10 12:56:57 -0500405 {b("openbsd-amd64-62@go1.16", "go"), none}, // golang.org/issue/42426.
406 {b("openbsd-amd64-62@go1.15", "go"), onlyPost},
407 {b("openbsd-amd64-62@go1.14", "go"), onlyPost},
408
Brad Fitzpatrick9e52fce2019-03-12 21:13:50 +0000409 // FreeBSD 12.0
410 {b("freebsd-amd64-12_0", "go"), both},
411 {b("freebsd-amd64-12_0", "net"), both},
Tobias Klauserbe84e8e2019-12-01 14:33:59 +0100412 {b("freebsd-amd64-12_0", "mobile"), none},
Brad Fitzpatrick9e52fce2019-03-12 21:13:50 +0000413 {b("freebsd-386-12_0", "go"), onlyPost},
414 {b("freebsd-386-12_0", "net"), onlyPost},
Tobias Klauserbe84e8e2019-12-01 14:33:59 +0100415 {b("freebsd-386-12_0", "mobile"), none},
Brad Fitzpatrick9e52fce2019-03-12 21:13:50 +0000416
Brad Fitzpatrickfcf7a582019-04-30 22:37:31 +0000417 // NetBSD
Dmitri Shuralyov5bbd5582020-04-08 12:43:09 -0400418 {b("netbsd-amd64-9_0", "go"), onlyPost},
419 {b("netbsd-amd64-9_0", "net"), onlyPost},
Dmitri Shuralyovb7c61f72020-04-09 07:59:16 -0400420 {b("netbsd-amd64-9_0", "sys"), both},
Dmitri Shuralyov5bbd5582020-04-08 12:43:09 -0400421 {b("netbsd-386-9_0", "go"), onlyPost},
422 {b("netbsd-386-9_0", "net"), onlyPost},
Brad Fitzpatrickfcf7a582019-04-30 22:37:31 +0000423
Tobias Klauserb7b66932019-03-13 09:29:15 +0100424 // AIX starts at Go 1.12
425 {b("aix-ppc64", "go"), onlyPost},
426 {b("aix-ppc64", "net"), onlyPost},
Tobias Klauserc2ec9e42019-06-04 10:14:55 +0200427 {b("aix-ppc64", "mobile"), none},
428 {b("aix-ppc64", "exp"), none},
Tobias Klausercbdd89b2019-10-14 11:31:13 +0200429 {b("aix-ppc64", "term"), onlyPost},
Dmitri Shuralyov43ea6942021-02-19 12:17:28 -0500430 {b("aix-ppc64@go1.15", "go"), onlyPost},
431 {b("aix-ppc64@go1.15", "net"), onlyPost},
432 {b("aix-ppc64@go1.15", "mobile"), none},
433 {b("aix-ppc64@go1.16", "net"), onlyPost},
434 {b("aix-ppc64@go1.16", "mobile"), none},
Cherry Zhang50a78802020-03-13 17:09:21 -0400435 {b("aix-ppc64@dev.link", "go"), onlyPost},
Tobias Klauserb7b66932019-03-13 09:29:15 +0100436
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000437 {b("linux-amd64-nocgo", "mobile"), none},
438
Elias Naur4d0f77a2019-05-01 22:28:43 +0200439 // Virtual mobiledevices
Elias Naur18919d62020-10-03 11:37:07 +0200440 {b("ios-arm64-corellium", "go"), isBuilder},
Elias Naur4d0f77a2019-05-01 22:28:43 +0200441 {b("android-arm64-corellium", "go"), isBuilder},
Elias Naur7ae75392019-05-02 00:54:54 +0200442 {b("android-arm-corellium", "go"), isBuilder},
Elias Naur6bebc8e2019-05-01 20:33:26 +0200443
Elias Naur18919d62020-10-03 11:37:07 +0200444 // Mobile builders that run with GOOS=linux/ios and have
Brad Fitzpatrick13f1da92019-03-12 16:21:55 +0000445 // a device attached.
446 {b("linux-amd64-androidemu", "mobile"), both},
Brad Fitzpatrick13f1da92019-03-12 16:21:55 +0000447
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000448 // But the emulators run all:
449 {b("android-amd64-emu", "mobile"), isBuilder},
450 {b("android-386-emu", "mobile"), isBuilder},
451 {b("android-amd64-emu", "net"), isBuilder},
452 {b("android-386-emu", "net"), isBuilder},
453 {b("android-amd64-emu", "go"), isBuilder},
454 {b("android-386-emu", "go"), isBuilder},
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000455
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000456 // Only test tip for js/wasm, and only for some repos:
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000457 {b("js-wasm", "go"), both},
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000458 {b("js-wasm", "arch"), onlyPost},
459 {b("js-wasm", "crypto"), onlyPost},
460 {b("js-wasm", "sys"), onlyPost},
Brad Fitzpatrickb8db43d2019-03-11 04:20:46 +0000461 {b("js-wasm", "net"), onlyPost},
462 {b("js-wasm@go1.12", "net"), none},
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000463 {b("js-wasm", "benchmarks"), none},
464 {b("js-wasm", "debug"), none},
465 {b("js-wasm", "mobile"), none},
466 {b("js-wasm", "perf"), none},
467 {b("js-wasm", "talks"), none},
468 {b("js-wasm", "tools"), none},
469 {b("js-wasm", "tour"), none},
470 {b("js-wasm", "website"), none},
471
472 // Race builders. Linux for all, GCE buidlers for
473 // post-submit, and only post-submit for "go" for
474 // Darwin (limited resources).
475 {b("linux-amd64-race", "go"), both},
476 {b("linux-amd64-race", "net"), both},
477 {b("windows-amd64-race", "go"), onlyPost},
478 {b("windows-amd64-race", "net"), onlyPost},
479 {b("freebsd-amd64-race", "go"), onlyPost},
480 {b("freebsd-amd64-race", "net"), onlyPost},
481 {b("darwin-amd64-race", "go"), onlyPost},
482 {b("darwin-amd64-race", "net"), none},
483
484 // Long test.
485 {b("linux-amd64-longtest", "go"), onlyPost},
486 {b("linux-amd64-longtest", "net"), onlyPost},
Dmitri Shuralyov5a8fb632020-05-26 18:19:05 -0400487 {b("linux-amd64-longtest@go1.14", "go"), both},
Dmitri Shuralyov9e7a7622020-05-26 18:12:12 -0400488 {b("linux-amd64-longtest@go1.14", "net"), none},
Brad Fitzpatrickf9c537e2019-10-28 20:16:36 +0000489 {b("windows-amd64-longtest", "go"), onlyPost},
Dmitri Shuralyov5a8fb632020-05-26 18:19:05 -0400490 {b("windows-amd64-longtest@go1.14", "go"), both},
Brad Fitzpatrickf9c537e2019-10-28 20:16:36 +0000491 {b("windows-amd64-longtest", "net"), onlyPost},
492 {b("windows-amd64-longtest", "exp"), onlyPost},
493 {b("windows-amd64-longtest", "mobile"), none},
Dmitri Shuralyovdd5ac552020-07-01 14:14:47 -0400494 {b("linux-386-longtest", "go"), onlyPost},
495 {b("linux-386-longtest", "net"), onlyPost},
496 {b("linux-386-longtest", "exp"), none},
497 {b("linux-386-longtest", "mobile"), none},
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000498
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000499 // Experimental exp repo runs in very few places.
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000500 {b("linux-amd64", "exp"), both},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000501 {b("linux-amd64-race", "exp"), both},
502 {b("linux-amd64-longtest", "exp"), onlyPost},
Brad Fitzpatrick83c6b6a2019-03-14 20:35:32 +0000503 {b("windows-386-2008", "exp"), both},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000504 {b("windows-amd64-2016", "exp"), both},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000505 {b("darwin-amd64-10_14", "exp"), onlyPost},
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000506 {b("darwin-amd64-10_15", "exp"), onlyPost},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000507 // ... but not on most others:
Dmitri Shuralyov3b77b3a2019-09-28 17:43:42 +0000508 {b("darwin-amd64-10_12", "exp"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000509 {b("freebsd-386-11_2", "exp"), none},
510 {b("freebsd-386-12_0", "exp"), none},
511 {b("freebsd-amd64-11_2", "exp"), none},
512 {b("freebsd-amd64-12_0", "exp"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000513 {b("openbsd-amd64-64", "exp"), none},
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500514 {b("openbsd-amd64-68", "exp"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000515 {b("js-wasm", "exp"), none},
516
517 // exp is experimental; it doesn't test against release branches.
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000518 {b("linux-amd64@go1.12", "exp"), none},
Brad Fitzpatrick8a071d42019-03-18 16:48:22 +0000519
Brad Fitzpatrickc8ca9622019-12-07 05:14:28 +0000520 // the build repo is only really useful for linux-amd64 (where we run it),
521 // and darwin-amd64 and perhaps windows-amd64 (for stuff like gomote).
522 // No need for any other operating systems to use it.
523 {b("linux-amd64", "build"), both},
524 {b("linux-amd64-longtest", "build"), onlyPost},
525 {b("windows-amd64-2016", "build"), both},
526 {b("darwin-amd64-10_12", "build"), none},
527 {b("darwin-amd64-10_14", "build"), none},
528 {b("darwin-amd64-10_15", "build"), onlyPost},
Dmitri Shuralyov01e47d92020-12-21 14:12:25 -0500529 {b("openbsd-amd64-68", "build"), none},
Brad Fitzpatrickc8ca9622019-12-07 05:14:28 +0000530 {b("linux-amd64-fedora", "build"), none},
531 {b("linux-amd64-clang", "build"), none},
532 {b("linux-amd64-sid", "build"), none},
Brad Fitzpatrickf6d512d2019-12-12 17:43:59 +0000533 {b("linux-amd64-nocgo", "build"), none},
534 {b("linux-386-longtest", "build"), none},
Brad Fitzpatrickf6d512d2019-12-12 17:43:59 +0000535 {b("js-wasm", "build"), none},
536 {b("android-386-emu", "build"), none},
537 {b("android-amd64-emu", "build"), none},
Brad Fitzpatrickc8ca9622019-12-07 05:14:28 +0000538
Brad Fitzpatrick8a071d42019-03-18 16:48:22 +0000539 // Only use latest macOS for subrepos, and only amd64:
540 {b("darwin-amd64-10_12", "net"), onlyPost},
Brad Fitzpatrick8bd8e0e2019-03-26 23:04:31 +0000541
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000542 {b("darwin-amd64-10_15", "go"), onlyPost},
Brad Fitzpatrick8bd8e0e2019-03-26 23:04:31 +0000543 {b("darwin-amd64-10_14", "go"), onlyPost},
544 {b("darwin-amd64-10_12", "go"), onlyPost},
Brad Fitzpatrick85a73d72019-04-03 04:45:29 +0000545
Brad Fitzpatrick67073b92019-04-18 19:33:19 +0000546 // plan9 only lived at master. We didn't support any past releases.
547 // But it's off for now as it's always failing.
548 {b("plan9-386", "go"), none}, // temporarily disabled
549 {b("plan9-386", "net"), none}, // temporarily disabled
Tobias Klauser22d3b242019-11-28 11:33:00 +0100550 {b("plan9-386", "exp"), none},
551 {b("plan9-386", "mobile"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000552 {b("plan9-386@go1.12", "go"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000553 {b("plan9-386@go1.12", "net"), none},
554 {b("plan9-amd64-9front", "go"), onlyPost},
Tobias Klauser22d3b242019-11-28 11:33:00 +0100555 {b("plan9-amd64-9front", "exp"), none},
556 {b("plan9-amd64-9front", "mobile"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000557 {b("plan9-amd64-9front@go1.12", "go"), none},
558 {b("plan9-amd64-9front", "net"), onlyPost},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000559 {b("plan9-amd64-9front@go1.12", "net"), none},
560 {b("plan9-arm", "go"), onlyPost},
Tobias Klauser22d3b242019-11-28 11:33:00 +0100561 {b("plan9-arm", "exp"), none},
562 {b("plan9-arm", "mobile"), none},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000563 {b("plan9-arm@go1.12", "go"), none},
564 {b("plan9-arm", "net"), onlyPost},
Brad Fitzpatrickf7a5fcf2019-04-03 05:03:37 +0000565 {b("plan9-arm@go1.12", "net"), none},
Brad Fitzpatrickd6a8c272019-04-05 05:26:05 +0000566
Brad Fitzpatrick58771952019-10-21 15:00:32 +0000567 {b("dragonfly-amd64", "go"), onlyPost},
568 {b("dragonfly-amd64", "net"), onlyPost},
569 {b("dragonfly-amd64@go1.13", "net"), none}, // Dragonfly ABI changes only supported by Go 1.14+
570 {b("dragonfly-amd64@go1.13", "go"), none}, // Dragonfly ABI changes only supported by Go 1.14+
Antonio Huete Jimeneza39e4672020-04-04 10:40:16 +0000571 {b("dragonfly-amd64-5_8", "go"), onlyPost},
572 {b("dragonfly-amd64-5_8", "net"), onlyPost},
573 {b("dragonfly-amd64-5_8@go1.13", "net"), onlyPost},
Dmitri Shuralyov77c96bb2020-03-19 10:34:11 -0400574
575 {b("linux-amd64-staticlockranking", "go"), onlyPost},
576 {b("linux-amd64-staticlockranking@go1.15", "go"), onlyPost},
577 {b("linux-amd64-staticlockranking@go1.14", "go"), none},
578 {b("linux-amd64-staticlockranking", "net"), none},
Austin Clements80886082020-12-21 16:08:53 -0500579
580 {b("linux-amd64-regabi", "go"), onlyPost},
581 {b("linux-amd64-regabi", "net"), none},
Brad Fitzpatrick756764c2019-03-07 17:44:41 +0000582 }
583 for _, tt := range tests {
584 t.Run(tt.br.testName, func(t *testing.T) {
585 bc, ok := Builders[tt.br.builder]
586 if !ok {
587 t.Fatalf("unknown builder %q", tt.br.builder)
588 }
589 gotPost := bc.BuildsRepoPostSubmit(tt.br.repo, tt.br.branch, tt.br.goBranch)
590 if tt.want&isBuilder != 0 && !gotPost {
591 t.Errorf("not a post-submit builder, but expected")
592 }
593 if tt.want&notBuilder != 0 && gotPost {
594 t.Errorf("unexpectedly a post-submit builder")
595 }
596
597 gotTry := bc.BuildsRepoTryBot(tt.br.repo, tt.br.branch, tt.br.goBranch)
598 if tt.want&isTrybot != 0 && !gotTry {
599 t.Errorf("not trybot, but expected")
600 }
601 if tt.want&notTrybot != 0 && gotTry {
602 t.Errorf("unexpectedly a trybot")
603 }
604
605 if t.Failed() {
606 t.Logf("For: %+v", tt.br)
607 }
608 })
609 }
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000610}
611
612func TestHostConfigsAllUsed(t *testing.T) {
Dmitri Shuralyov07688122020-08-04 12:01:34 -0400613 knownUnused := map[string]bool{
614 // Currently host-linux-armhf-cross and host-linux-armel-cross aren't
615 // referenced, but the coordinator hard-codes them, so don't make
616 // these two an error for now.
617 "host-linux-armhf-cross": true,
618 "host-linux-armel-cross": true,
619
620 "host-linux-x86-alpine": true, // TODO(golang.org/issue/19938): Fix the Alpine builder, or remove it.
Dmitri Shuralyov07688122020-08-04 12:01:34 -0400621 }
622
623 used := make(map[string]bool)
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000624 for _, conf := range Builders {
625 used[conf.HostType] = true
626 }
627 for hostType := range Hosts {
Dmitri Shuralyov07688122020-08-04 12:01:34 -0400628 if !used[hostType] && !knownUnused[hostType] {
629 t.Errorf("host type %q is not referenced from any build config", hostType)
630 }
631 if used[hostType] && knownUnused[hostType] {
632 t.Errorf("host type %q should not be listed in knownUnused since it's in use", hostType)
Brad Fitzpatrickc328d042017-04-12 00:35:37 +0000633 }
634 }
635}
Brad Fitzpatrick86650282019-03-11 18:49:56 +0000636
637// tests that goBranch is optional for repo == "go"
638func TestBuildsRepoAtAllImplicitGoBranch(t *testing.T) {
639 builder := Builders["android-amd64-emu"]
640 got := builder.buildsRepoAtAll("go", "master", "")
641 if !got {
642 t.Error("got = false; want true")
643 }
644}
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000645
646func TestShouldRunDistTest(t *testing.T) {
647 type buildMode int
648 const (
649 tryMode buildMode = 0
650 postSubmit buildMode = 1
651 )
652
653 tests := []struct {
654 builder string
655 test string
656 mode buildMode
657 want bool
658 }{
659 {"linux-amd64", "api", postSubmit, true},
660 {"linux-amd64", "api", tryMode, true},
Dmitri Shuralyov75a37cb2020-04-09 12:47:03 -0400661 {"freebsd-amd64-12_0", "api", postSubmit, true}, // freebsd-amd64-12_0 uses fasterTrybots policy, should still build.
662 {"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 +0000663
664 {"linux-amd64", "reboot", tryMode, true},
665 {"linux-amd64-race", "reboot", tryMode, false},
666
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000667 {"darwin-amd64-10_12", "test:foo", postSubmit, false},
668 {"darwin-amd64-10_14", "test:foo", postSubmit, false},
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000669 {"darwin-amd64-10_14", "reboot", postSubmit, false},
670 {"darwin-amd64-10_14", "api", postSubmit, false},
671 {"darwin-amd64-10_14", "codewalk", postSubmit, false},
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000672 {"darwin-amd64-10_15", "test:foo", postSubmit, false},
Brad Fitzpatrick43eb39e2019-04-02 15:27:10 +0000673 }
674 for _, tt := range tests {
675 bc, ok := Builders[tt.builder]
676 if !ok {
677 t.Errorf("unknown builder %q", tt.builder)
678 continue
679 }
680 isTry := tt.mode == tryMode
681 if isTry && !bc.BuildsRepoTryBot("go", "master", "master") {
682 t.Errorf("builder %q is not a trybot, so can't run test %q in try mode", tt.builder, tt.test)
683 continue
684 }
685 got := bc.ShouldRunDistTest(tt.test, isTry)
686 if got != tt.want {
687 t.Errorf("%q.ShouldRunDistTest(%q, try %v) = %v; want %v", tt.builder, tt.test, isTry, got, tt.want)
688 }
689 }
690}
Dmitri Shuralyov01fd2992019-09-09 16:48:08 -0400691
692func TestShouldTestPackageInGOPATHMode(t *testing.T) {
693 // This function doesn't change behavior depending on the builder
694 // at this time, so just use a common one.
695 bc, ok := Builders["linux-amd64"]
696 if !ok {
697 t.Fatal("unknown builder")
698 }
699
700 tests := []struct {
701 importPath string
702 want bool
703 }{
704 {"golang.org/x/image/bmp", true},
705 {"golang.org/x/tools/go/ast/astutil", true},
706 {"golang.org/x/tools/go/packages", true},
707 {"golang.org/x/tools", true}, // Three isn't a package there, but if there was, it should be tested.
708 {"golang.org/x/tools/gopls", false},
709 {"golang.org/x/tools/gopls/internal/foobar", false},
710 }
711 for _, tt := range tests {
712 got := bc.ShouldTestPackageInGOPATHMode(tt.importPath)
713 if got != tt.want {
714 t.Errorf("ShouldTestPackageInGOPATHMode(%q) = %v; want %v", tt.importPath, got, tt.want)
715 }
716 }
717}
Brad Fitzpatrickaab85042019-10-16 06:02:29 +0000718
719func TestSlowBotAliases(t *testing.T) {
720 for term, name := range slowBotAliases {
721 if name == "" {
722 // Empty string means known missing builder.
723 continue
724 }
725 if _, ok := Builders[name]; !ok {
726 t.Errorf("slowbot term %q references unknown builder %q", term, name)
727 }
728 }
729
730 out, err := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "tool", "dist", "list").Output()
731 if err != nil {
732 t.Errorf("dist list: %v", err)
733 }
734 ports := strings.Fields(string(out))
735
736 done := map[string]bool{}
Carlos Amedee3e01d872020-04-22 18:52:59 -0400737
Brad Fitzpatrickaab85042019-10-16 06:02:29 +0000738 var add bytes.Buffer
739 check := func(term string, isArch bool) {
740 if done[term] {
741 return
742 }
743 done[term] = true
744 _, isBuilderName := Builders[term]
745 _, hasAlias := slowBotAliases[term]
746 if !isBuilderName && !hasAlias {
747 prefix := term
748 if isArch {
749 prefix = "linux-" + term
750 }
751 var matches []string
752 for name := range Builders {
753 if strings.HasPrefix(name, prefix) {
754 matches = append(matches, name)
755 }
756 }
757 sort.Strings(matches)
758 t.Errorf("term %q has no match in slowBotAliases", term)
759 if len(matches) == 1 {
760 fmt.Fprintf(&add, "%q: %q,\n", term, matches[0])
761 } else if len(matches) > 1 {
762 t.Errorf("maybe add: %q: %q, (matches=%q)", term, matches[len(matches)-1], matches)
763 }
764 }
765 }
766
767 for _, port := range ports {
768 slash := strings.IndexByte(port, '/')
769 if slash == -1 {
770 t.Fatalf("unexpected port %q", port)
771 }
772 goos, goarch := port[:slash], port[slash+1:]
773 check(goos+"-"+goarch, false)
774 check(goos, false)
775 check(goarch, true)
776 }
777
778 if add.Len() > 0 {
779 t.Errorf("Missing items from slowBotAliases:\n%s", add.String())
780 }
781}
Brad Fitzpatrickad7af462019-10-19 02:49:53 +0000782
783func TestCrossCompileConfigs(t *testing.T) {
784 // Verify that Builders.CrossCompileConfig have valid host types.
785 for name, bc := range Builders {
786 cc := bc.CrossCompileConfig
787 if cc == nil {
788 continue
789 }
790 if _, ok := Hosts[cc.CompileHostType]; !ok {
791 t.Errorf("unknown host type %q for builder %q", cc.CompileHostType, name)
792 }
793 }
794}
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100795
796// TestTryBotsCompileAllPorts verifies that each port (go tool dist list) is covered by
797// either a real trybot or a misc-compile trybot.
798func TestTryBotsCompileAllPorts(t *testing.T) {
799 out, err := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "tool", "dist", "list").Output()
800 if err != nil {
801 t.Errorf("dist list: %v", err)
802 }
803 ports := strings.Fields(string(out))
804
805 done := map[string]bool{}
Dmitri Shuralyovfc63a042021-02-19 12:18:43 -0500806 done["darwin-arm64"] = true // TODO(golang.org/issue/39782): Add builder for darwin/arm64.
807 done["windows-arm64"] = true // TODO(golang.org/issue/42604): Add builder for windows/arm64.
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100808 check := func(goos, goarch string) {
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400809 if goos == "android" || goos == "ios" {
Brad Fitzpatrick8a3c1d92019-11-15 04:29:29 +0000810 // TODO(golang.org/issue/25963): support
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400811 // compilation-only Android and iOS trybots.
Brad Fitzpatrick8a3c1d92019-11-15 04:29:29 +0000812 // buildall.bash doesn't set the environment
813 // up enough for e.g. compiling android-386
814 // from linux-amd64. (Issue #35596 too)
Dmitri Shuralyov55e1ef62020-09-28 11:04:35 -0400815 // iOS likely needs to be built on macOS
816 // with Xcode available.
Brad Fitzpatrick8a3c1d92019-11-15 04:29:29 +0000817 return
818 }
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100819 goosArch := goos + "-" + goarch
820 if done[goosArch] {
821 return
822 }
823 for _, conf := range Builders {
824 os := conf.GOOS()
825 arch := conf.GOARCH()
826
827 if os == goos && arch == goarch && (conf.tryOnly || conf.tryBot != nil) {
828 done[goosArch] = true
829 break
830 }
831
832 if strings.HasPrefix(conf.Name, "misc-compile-") {
833 re, err := regexp.Compile(conf.allScriptArgs[0])
834 if err != nil {
835 t.Errorf("Invalid misc-compile filtering pattern for builder %q: %q",
836 conf.Name, conf.allScriptArgs[0])
837 }
838
839 if re.MatchString(goosArch) || re.MatchString(goos) {
840 done[goosArch] = true
841 break
842 }
843 }
844 }
845 if _, ok := done[goosArch]; !ok {
846 t.Errorf("Missing trybot or misc-compile trybot: %q", goosArch)
847 }
Tobias Klausercd82ecd2019-11-07 14:15:55 +0100848 }
849
850 for _, port := range ports {
851 slash := strings.IndexByte(port, '/')
852 if slash == -1 {
853 t.Fatalf("unexpected port %q", port)
854 }
855 check(port[:slash], port[slash+1:])
856 }
857
858}
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000859
860// TestExpectedMacstadiumVMCount ensures that only 20 instances of macOS virtual machines
861// are expected at MacStadium.
862// TODO: remove once the scheduler allocates VMs based on demand https://golang.org/issue/35698
863func TestExpectedMacstadiumVMCount(t *testing.T) {
864 got := 0
865 for host, config := range Hosts {
Carlos Amedeed576fd32021-01-29 15:47:13 -0500866 if strings.HasPrefix(host, "host-darwin-10_") || strings.HasPrefix(host, "host-darwin-amd64-") {
Carlos Amedeed6dec9c2019-11-19 14:55:01 +0000867 got += config.ExpectNum
868 }
869 }
870 if got != 20 {
871 t.Fatalf("macstadium host count: got %d; want 20", got)
872 }
873}
Dmitri Shuralyovdf328b12020-05-13 14:30:25 -0400874
875// Test that we have a longtest builder and
876// that its environment configuration is okay.
877func TestLongTestBuilder(t *testing.T) {
878 long, ok := Builders["linux-amd64-longtest"]
879 if !ok {
880 t.Fatal("we don't have a linux-amd64-longtest builder anymore, is that intentional?")
881 }
882 if !long.IsLongTest() {
883 t.Error("the linux-amd64-longtest builder isn't a longtest builder, is that intentional?")
884 }
885 var shortDisabled bool
886 for _, e := range long.Env() {
887 if e == "GO_TEST_SHORT=0" {
888 shortDisabled = true
889 }
890 }
891 if !shortDisabled {
892 t.Error("the linux-amd64-longtest builder doesn't set GO_TEST_SHORT=0, is that intentional?")
893 }
894}
Carlos Amedeed77c6d02020-08-18 13:32:05 -0400895
896func TestHostConfigIsVM(t *testing.T) {
897 testCases := []struct {
898 desc string
899 config *HostConfig
900 want bool
901 }{
902 {
903 desc: "non-ec2-vm",
904 config: &HostConfig{
905 VMImage: "image-x",
906 ContainerImage: "",
907 isEC2: false,
908 },
909 want: true,
910 },
911 {
912 desc: "non-ec2-container",
913 config: &HostConfig{
914 VMImage: "",
915 ContainerImage: "container-image-x",
916 isEC2: false,
917 },
918 want: false,
919 },
920 {
921 desc: "ec2-container",
922 config: &HostConfig{
923 VMImage: "image-x",
924 ContainerImage: "container-image-x",
925 isEC2: true,
926 },
927 want: false,
928 },
929 {
930 desc: "ec2-vm",
931 config: &HostConfig{
932 VMImage: "image-x",
933 ContainerImage: "",
934 isEC2: true,
935 },
936 want: true,
937 },
938 }
939 for _, tc := range testCases {
940 t.Run(fmt.Sprintf(tc.desc), func(t *testing.T) {
941 if got := tc.config.IsVM(); got != tc.want {
942 t.Errorf("HostConfig.IsVM() = %t; want %t", got, tc.want)
943 }
944 })
945 }
946}
Carlos Amedee1e761992020-08-20 11:53:58 -0400947
948func TestModulesEnv(t *testing.T) {
949 testCases := []struct {
950 desc string
951 buildConfig *BuildConfig
952 repo string
953 want []string
954 }{
955 {
956 desc: "ec2-builder-repo-non-go",
957 buildConfig: &BuildConfig{
958 testHostConf: &HostConfig{
959 IsReverse: false,
960 isEC2: true,
961 },
962 },
963 repo: "bar",
964 want: []string{"GOPROXY=https://proxy.golang.org"},
965 },
966 {
967 desc: "reverse-builder-repo-non-go",
968 buildConfig: &BuildConfig{
969 testHostConf: &HostConfig{
970 IsReverse: true,
971 isEC2: false,
972 },
973 },
974 repo: "bar",
975 want: []string{"GOPROXY=https://proxy.golang.org"},
976 },
977 {
978 desc: "reverse-builder-repo-go",
979 buildConfig: &BuildConfig{
980 testHostConf: &HostConfig{
981 IsReverse: true,
982 isEC2: false,
983 },
984 },
985 repo: "go",
986 want: []string{"GOPROXY=off"},
987 },
988 {
989 desc: "builder-repo-go",
990 buildConfig: &BuildConfig{
991 testHostConf: &HostConfig{
992 IsReverse: false,
993 isEC2: false,
994 },
995 },
996 repo: "go",
997 want: []string{"GOPROXY=off"},
998 },
999 {
1000 desc: "builder-repo-go-outbound-network-allowed",
1001 buildConfig: &BuildConfig{
1002 Name: "test-longtest",
1003 testHostConf: &HostConfig{
1004 IsReverse: false,
1005 isEC2: false,
1006 },
1007 },
1008 repo: "go",
1009 want: nil,
1010 },
1011 {
1012 desc: "builder-repo-special-case",
1013 buildConfig: &BuildConfig{
1014 testHostConf: &HostConfig{
1015 IsReverse: false,
1016 isEC2: false,
1017 },
1018 },
1019 repo: "build",
1020 want: []string{"GO111MODULE=on"},
1021 },
1022 {
1023 desc: "reverse-builder-repo-special-case",
1024 buildConfig: &BuildConfig{
1025 testHostConf: &HostConfig{
1026 IsReverse: true,
1027 isEC2: false,
1028 },
1029 },
1030 repo: "build",
1031 want: []string{"GOPROXY=https://proxy.golang.org", "GO111MODULE=on"},
1032 },
1033 {
1034 desc: "builder-repo-non-special-case",
1035 buildConfig: &BuildConfig{
1036 testHostConf: &HostConfig{
1037 IsReverse: false,
1038 isEC2: false,
1039 },
1040 },
1041 repo: "bar",
1042 want: nil,
1043 },
1044 }
1045 for _, tc := range testCases {
1046 t.Run(tc.desc, func(t *testing.T) {
1047 got := tc.buildConfig.ModulesEnv(tc.repo)
1048 if diff := cmp.Diff(tc.want, got); diff != "" {
1049 t.Errorf("BuildConfig.ModulesEnv(%q) mismatch (-want, +got)\n%s", tc.repo, diff)
1050 }
1051 })
1052 }
1053}