Source file
src/cmd/dist/test.go
1
2
3
4
5 package main
6
7 import (
8 "bytes"
9 "encoding/json"
10 "flag"
11 "fmt"
12 "io"
13 "io/fs"
14 "log"
15 "os"
16 "os/exec"
17 "path/filepath"
18 "reflect"
19 "regexp"
20 "runtime"
21 "slices"
22 "strconv"
23 "strings"
24 "time"
25 )
26
27 func cmdtest() {
28 gogcflags = os.Getenv("GO_GCFLAGS")
29 setNoOpt()
30
31 var t tester
32
33 t.asmflags = os.Getenv("GO_TEST_ASMFLAGS")
34
35 var noRebuild bool
36 flag.BoolVar(&t.listMode, "list", false, "list available tests")
37 flag.BoolVar(&t.rebuild, "rebuild", false, "rebuild everything first")
38 flag.BoolVar(&noRebuild, "no-rebuild", false, "overrides -rebuild (historical dreg)")
39 flag.BoolVar(&t.keepGoing, "k", false, "keep going even when error occurred")
40 flag.BoolVar(&t.race, "race", false, "run in race builder mode (different set of tests)")
41 flag.BoolVar(&t.compileOnly, "compile-only", false, "compile tests, but don't run them")
42 flag.StringVar(&t.banner, "banner", "##### ", "banner prefix; blank means no section banners")
43 flag.StringVar(&t.runRxStr, "run", "",
44 "run only those tests matching the regular expression; empty means to run all. "+
45 "Special exception: if the string begins with '!', the match is inverted.")
46 flag.BoolVar(&t.msan, "msan", false, "run in memory sanitizer builder mode")
47 flag.BoolVar(&t.asan, "asan", false, "run in address sanitizer builder mode")
48 flag.BoolVar(&t.json, "json", false, "report test results in JSON")
49 flag.StringVar(&t.artifactsDir, "artifacts-dir", "", "save test artifacts in the specified directory")
50 flag.StringVar(&debugTrace, "debug-trace", debugTrace, "write a merged trace of the test run to `file`")
51
52 xflagparse(-1)
53 if noRebuild {
54 debugTraceAppend = true
55 t.rebuild = false
56 }
57
58 t.run()
59 }
60
61
62 type tester struct {
63 race bool
64 msan bool
65 asan bool
66 listMode bool
67 rebuild bool
68 failed bool
69 keepGoing bool
70 compileOnly bool
71 short bool
72 cgoEnabled bool
73 asmflags string
74 json bool
75 artifactsDir string
76 runRxStr string
77 runRx *regexp.Regexp
78 runRxWant bool
79 runNames []string
80 banner string
81 lastHeading string
82
83 tests []distTest
84 testNames map[string]bool
85 timeoutScale int
86
87 worklist []*work
88 }
89
90
91 type work struct {
92 dt *distTest
93 cmd *exec.Cmd
94 flush func()
95 start chan bool
96 out bytes.Buffer
97 err error
98 end chan struct{}
99 }
100
101
102 func (w *work) printSkip(t *tester, msg string) {
103 if t.json {
104 synthesizeSkipEvent(json.NewEncoder(&w.out), w.dt.name, msg)
105 return
106 }
107 fmt.Fprintln(&w.out, msg)
108 }
109
110
111
112 type distTest struct {
113 name string
114 heading string
115 fn func(*distTest) error
116 }
117
118 func (t *tester) run() {
119 timelog("start", "dist test")
120 distSpan := startSpan("dist test")
121
122 os.Setenv("PATH", fmt.Sprintf("%s%c%s", gorootBin, os.PathListSeparator, os.Getenv("PATH")))
123
124 t.short = true
125 if v := os.Getenv("GO_TEST_SHORT"); v != "" {
126 short, err := strconv.ParseBool(v)
127 if err != nil {
128 fatalf("invalid GO_TEST_SHORT %q: %v", v, err)
129 }
130 t.short = short
131 }
132
133 cmd := exec.Command(gorootBinGo, "env", "CGO_ENABLED")
134 cmd.Stderr = new(bytes.Buffer)
135 slurp, err := cmd.Output()
136 if err != nil {
137 fatalf("Error running %s: %v\n%s", cmd, err, cmd.Stderr)
138 }
139 parts := strings.Split(string(slurp), "\n")
140 if nlines := len(parts) - 1; nlines < 1 {
141 fatalf("Error running %s: output contains <1 lines\n%s", cmd, cmd.Stderr)
142 }
143 t.cgoEnabled, _ = strconv.ParseBool(parts[0])
144
145 if flag.NArg() > 0 && t.runRxStr != "" {
146 fatalf("the -run regular expression flag is mutually exclusive with test name arguments")
147 }
148
149 t.runNames = flag.Args()
150
151
152
153
154
155
156 if ok := isEnvSet("GOTRACEBACK"); !ok {
157 if err := os.Setenv("GOTRACEBACK", "system"); err != nil {
158 if t.keepGoing {
159 log.Printf("Failed to set GOTRACEBACK: %v", err)
160 } else {
161 fatalf("Failed to set GOTRACEBACK: %v", err)
162 }
163 }
164 }
165
166 if t.rebuild {
167 t.out("Building packages and commands.")
168
169 rebuildSpan := startSpan("rebuild toolchain")
170 goInstall(toolenv(), gorootBinGo, append(append(maybeTraceFlag("rebuildToolchain"), "-a"), toolchain...)...)
171 rebuildSpan.done()
172 }
173
174 if !t.listMode {
175 if builder := os.Getenv("GO_BUILDER_NAME"); builder == "" {
176
177
178
179
180
181
182
183
184
185
186
187
188 toolchain1Span := startSpan("toolchain1")
189 goInstall(toolenv(), gorootBinGo, append(maybeTraceFlag("toolchain1"), toolchain...)...)
190 toolchain1Span.done()
191 toolchain2Span := startSpan("toolchain2")
192 goInstall(toolenv(), gorootBinGo, append(maybeTraceFlag("toolchain2"), toolchain...)...)
193 toolchain2Span.done()
194 toolsSpan := startSpan("tools")
195 goInstall(toolenv(), gorootBinGo, append(maybeTraceFlag("tools"), toolsToInstall...)...)
196 toolsSpan.done()
197 }
198 }
199
200 t.timeoutScale = 1
201 if s := os.Getenv("GO_TEST_TIMEOUT_SCALE"); s != "" {
202 t.timeoutScale, err = strconv.Atoi(s)
203 if err != nil {
204 fatalf("failed to parse $GO_TEST_TIMEOUT_SCALE = %q as integer: %v", s, err)
205 }
206 }
207
208 if t.runRxStr != "" {
209 if t.runRxStr[0] == '!' {
210 t.runRxWant = false
211 t.runRxStr = t.runRxStr[1:]
212 } else {
213 t.runRxWant = true
214 }
215 t.runRx = regexp.MustCompile(t.runRxStr)
216 }
217
218 t.registerTests()
219 if t.listMode {
220 for _, tt := range t.tests {
221 fmt.Println(tt.name)
222 }
223 return
224 }
225
226 for _, name := range t.runNames {
227 if !t.testNames[name] {
228 fatalf("unknown test %q", name)
229 }
230 }
231
232
233 if strings.HasPrefix(os.Getenv("GO_BUILDER_NAME"), "linux-") {
234 if os.Getuid() == 0 {
235
236
237 } else {
238 xatexit(t.makeGOROOTUnwritable())
239 }
240 }
241
242 if !t.json {
243 if err := t.maybeLogMetadata(); err != nil {
244 t.failed = true
245 if t.keepGoing {
246 log.Printf("Failed logging metadata: %v", err)
247 } else {
248 fatalf("Failed logging metadata: %v", err)
249 }
250 }
251 }
252
253 var anyIncluded, someExcluded bool
254 for _, dt := range t.tests {
255 if !t.shouldRunTest(dt.name) {
256 someExcluded = true
257 continue
258 }
259 anyIncluded = true
260 dt := dt
261 if err := dt.fn(&dt); err != nil {
262 t.runPending(&dt)
263 t.failed = true
264 if t.keepGoing {
265 log.Printf("Failed: %v", err)
266 } else {
267 fatalf("Failed: %v", err)
268 }
269 }
270 }
271 t.runPending(nil)
272 timelog("end", "dist test")
273 distSpan.done()
274 if debugTrace != "" {
275 writeTrace()
276 }
277
278 if !t.json {
279 if t.failed {
280 fmt.Println("\nFAILED")
281 } else if !anyIncluded {
282 fmt.Println()
283 errprintf("go tool dist: warning: %q matched no tests; use the -list flag to list available tests\n", t.runRxStr)
284 fmt.Println("NO TESTS TO RUN")
285 } else if someExcluded {
286 fmt.Println("\nALL TESTS PASSED (some were excluded)")
287 } else {
288 fmt.Println("\nALL TESTS PASSED")
289 }
290 }
291 if t.failed {
292 xexit(1)
293 }
294 }
295
296 func (t *tester) shouldRunTest(name string) bool {
297 if t.runRx != nil {
298 return t.runRx.MatchString(name) == t.runRxWant
299 }
300 if len(t.runNames) == 0 {
301 return true
302 }
303 return slices.Contains(t.runNames, name)
304 }
305
306 func (t *tester) maybeLogMetadata() error {
307 if t.compileOnly {
308
309
310 return nil
311 }
312 t.out("Test execution environment.")
313
314
315
316
317
318
319 return t.dirCmd(filepath.Join(goroot, "src/cmd/internal/metadata"), gorootBinGo, []string{"run", "main.go"}).Run()
320 }
321
322
323 func testName(pkg, variant string) string {
324 name := pkg
325 if variant != "" {
326 name += ":" + variant
327 }
328 return name
329 }
330
331
332
333 type goTest struct {
334 short bool
335 tags []string
336 race bool
337 bench bool
338 runTests string
339 cpu string
340 skip string
341
342 gcflags string
343 ldflags string
344 buildmode string
345
346 env []string
347
348
349
350
351
352
353
354
355
356 timeout time.Duration
357
358 runOnHost bool
359
360
361
362
363 variant string
364
365
366
367 pkgs []string
368 pkg string
369
370 testFlags []string
371 trace string
372 }
373
374
375
376 func (opts *goTest) compileOnly() bool {
377 return opts.runTests == "^$" && !opts.bench
378 }
379
380
381 func (opts *goTest) scaledTimeout(t *tester) time.Duration {
382 d := goTestDefaultTimeout
383 if opts.timeout != 0 {
384 d = opts.timeout
385 }
386 d *= time.Duration(t.timeoutScale)
387 return d
388 }
389
390 const goTestDefaultTimeout = 10 * time.Minute
391
392
393
394
395 func (opts *goTest) bgCommand(t *tester, stdout, stderr io.Writer) (cmd *exec.Cmd, flush func()) {
396 build, run, pkgs, testFlags, setupCmd := opts.buildArgs(t)
397
398
399 args := append([]string{"test"}, build...)
400 if t.compileOnly || opts.compileOnly() {
401 args = append(args, "-c", "-o", os.DevNull)
402 } else {
403 args = append(args, run...)
404 }
405 args = append(args, pkgs...)
406 if !t.compileOnly && !opts.compileOnly() {
407 args = append(args, testFlags...)
408 }
409
410 cmd = exec.Command(gorootBinGo, args...)
411 setupCmd(cmd)
412 if t.json && opts.variant != "" {
413
414
415
416
417
418
419
420
421
422
423
424
425 if stdout == stderr {
426 stdout = &lockedWriter{w: stdout}
427 stderr = stdout
428 }
429 f := &testJSONFilter{w: stdout, variant: opts.variant}
430 cmd.Stdout = f
431 flush = f.Flush
432 } else {
433 cmd.Stdout = stdout
434 flush = func() {}
435 }
436 cmd.Stderr = stderr
437
438 return cmd, flush
439 }
440
441
442 func (opts *goTest) run(t *tester) error {
443 cmd, flush := opts.bgCommand(t, os.Stdout, os.Stderr)
444 err := cmd.Run()
445 flush()
446 return err
447 }
448
449
450
451
452
453
454
455
456 func (opts *goTest) buildArgs(t *tester) (build, run, pkgs, testFlags []string, setupCmd func(*exec.Cmd)) {
457 run = append(run, "-count=1")
458 if d := opts.scaledTimeout(t); d > goTestDefaultTimeout {
459 run = append(run, "-timeout="+d.String())
460 }
461 if opts.short || t.short {
462 run = append(run, "-short")
463 }
464 var tags []string
465 if noOpt {
466 tags = append(tags, "noopt")
467 }
468 tags = append(tags, opts.tags...)
469 if len(tags) > 0 {
470 build = append(build, "-tags="+strings.Join(tags, ","))
471 }
472 if t.race || opts.race {
473 build = append(build, "-race")
474 }
475 if t.msan {
476 build = append(build, "-msan")
477 }
478 if t.asan {
479 build = append(build, "-asan")
480 }
481 if opts.bench {
482
483 run = append(run, "-run=^$")
484
485 run = append(run, "-bench=.*", "-benchtime=.1s")
486 } else if opts.runTests != "" {
487 run = append(run, "-run="+opts.runTests)
488 }
489 if opts.cpu != "" {
490 run = append(run, "-cpu="+opts.cpu)
491 }
492 if opts.skip != "" {
493 run = append(run, "-skip="+opts.skip)
494 }
495 if t.json {
496 build = append(build, "-json")
497 }
498 if t.artifactsDir != "" {
499 run = append(run, "-artifacts", "-outputdir="+t.artifactsDir)
500 }
501
502 if opts.gcflags != "" {
503 build = append(build, "-gcflags=all="+opts.gcflags)
504 }
505 if opts.ldflags != "" {
506 build = append(build, "-ldflags="+opts.ldflags)
507 }
508 if t.asmflags != "" {
509 build = append(build, "-asmflags="+t.asmflags)
510 }
511 if opts.buildmode != "" {
512 build = append(build, "-buildmode="+opts.buildmode)
513 }
514 if opts.trace != "" {
515 build = append(build, maybeTraceFlag(opts.trace)...)
516 }
517
518 pkgs = opts.packages()
519
520 runOnHost := opts.runOnHost && (goarch != gohostarch || goos != gohostos)
521 needTestFlags := len(opts.testFlags) > 0 || runOnHost
522 if needTestFlags {
523 testFlags = append([]string{"-args"}, opts.testFlags...)
524 }
525 if runOnHost {
526
527 testFlags = append(testFlags, "-target="+goos+"/"+goarch)
528 }
529
530 setupCmd = func(cmd *exec.Cmd) {
531 setDir(cmd, filepath.Join(goroot, "src"))
532 if len(opts.env) != 0 {
533 for _, kv := range opts.env {
534 if i := strings.Index(kv, "="); i < 0 {
535 unsetEnv(cmd, kv[:len(kv)-1])
536 } else {
537 setEnv(cmd, kv[:i], kv[i+1:])
538 }
539 }
540 }
541 if runOnHost {
542 setEnv(cmd, "GOARCH", gohostarch)
543 setEnv(cmd, "GOOS", gohostos)
544 }
545 }
546
547 return
548 }
549
550
551
552 func (opts *goTest) packages() []string {
553 pkgs := opts.pkgs
554 if opts.pkg != "" {
555 pkgs = append(pkgs[:len(pkgs):len(pkgs)], opts.pkg)
556 }
557 if len(pkgs) == 0 {
558 panic("no packages")
559 }
560 return pkgs
561 }
562
563
564 func (opts *goTest) printSkip(t *tester, msg string) {
565 if t.json {
566 enc := json.NewEncoder(os.Stdout)
567 for _, pkg := range opts.packages() {
568 synthesizeSkipEvent(enc, pkg, msg)
569 }
570 return
571 }
572 fmt.Println(msg)
573 }
574
575
576
577
578
579
580
581 var (
582 ranGoTest bool
583 stdMatches []string
584
585 ranGoBench bool
586 benchMatches []string
587 )
588
589 func (t *tester) registerStdTest(pkg string) {
590 const stdTestHeading = "Testing packages."
591 gcflags := gogcflags
592 name := testName(pkg, "")
593 if t.runRx == nil || t.runRx.MatchString(name) == t.runRxWant {
594 stdMatches = append(stdMatches, pkg)
595 }
596 t.addTest(name, stdTestHeading, func(dt *distTest) error {
597 if ranGoTest {
598 return nil
599 }
600 t.runPending(dt)
601 timelog("start", dt.name)
602 defer timelog("end", dt.name)
603 ranGoTest = true
604
605 stdSpan := startSpan("go test std cmd")
606 defer stdSpan.done()
607
608 return (&goTest{
609 gcflags: gcflags,
610 pkgs: stdMatches,
611 trace: "std",
612 }).run(t)
613 })
614 }
615
616 func (t *tester) registerRaceBenchTest(pkg string) {
617 const raceBenchHeading = "Running benchmarks briefly."
618 name := testName(pkg, "racebench")
619 if t.runRx == nil || t.runRx.MatchString(name) == t.runRxWant {
620 benchMatches = append(benchMatches, pkg)
621 }
622 t.addTest(name, raceBenchHeading, func(dt *distTest) error {
623 if ranGoBench {
624 return nil
625 }
626 t.runPending(dt)
627 timelog("start", dt.name)
628 defer timelog("end", dt.name)
629 ranGoBench = true
630 return (&goTest{
631
632
633
634 variant: "racebench",
635 timeout: 20 * time.Minute,
636 race: true,
637 bench: true,
638 cpu: "4",
639 pkgs: benchMatches,
640 }).run(t)
641 })
642 }
643
644 func (t *tester) registerTests() {
645
646
647
648 if len(t.runNames) > 0 {
649 for _, name := range t.runNames {
650 if !strings.Contains(name, ":") {
651 t.registerStdTest(name)
652 } else if strings.HasSuffix(name, ":racebench") {
653 t.registerRaceBenchTest(strings.TrimSuffix(name, ":racebench"))
654 }
655 }
656 } else {
657
658
659
660
661
662
663
664
665
666
667
668
669
670 cmd := exec.Command(gorootBinGo, "list")
671 if t.race {
672 cmd.Args = append(cmd.Args, "-tags=race")
673 }
674 cmd.Args = append(cmd.Args, "std", "cmd")
675 cmd.Stderr = new(bytes.Buffer)
676 all, err := cmd.Output()
677 if err != nil {
678 fatalf("Error running go list std cmd: %v:\n%s", err, cmd.Stderr)
679 }
680 pkgs := strings.Fields(string(all))
681 for _, pkg := range pkgs {
682 if t.short && (strings.HasPrefix(pkg, "vendor/") || strings.HasPrefix(pkg, "cmd/vendor/")) {
683
684
685
686 continue
687 }
688 t.registerStdTest(pkg)
689 }
690 if t.race && !t.short {
691 for _, pkg := range pkgs {
692 if t.packageHasBenchmarks(pkg) {
693 t.registerRaceBenchTest(pkg)
694 }
695 }
696 }
697 }
698
699 if t.race {
700 return
701 }
702
703
704 if !t.compileOnly {
705 t.registerTest("os/user with tag osusergo",
706 &goTest{
707 variant: "osusergo",
708 tags: []string{"osusergo"},
709 pkg: "os/user",
710 })
711 }
712
713
714
715 for _, tag := range []string{"nethttpomithttp2", "nethttpomithttp2server", "nethttpomithttp2client"} {
716 t.registerTest("net/http with tag "+tag, &goTest{
717 variant: tag,
718 tags: []string{tag},
719 pkg: "net/http",
720 })
721 }
722
723
724 t.registerTest("crypto with tag purego (build and vet only)", &goTest{
725 variant: "purego",
726 tags: []string{"purego"},
727 pkg: "crypto/...",
728 runTests: "^$",
729 })
730
731
732 if t.fips140Supported() {
733
734 t.registerTest("GOFIPS140=latest go test crypto/...", &goTest{
735 variant: "gofips140",
736 env: []string{"GOFIPS140=latest"},
737 pkg: "crypto/...",
738 })
739
740
741
742 for _, version := range fips140Versions() {
743 suffix := " # (build and vet only)"
744 run := "^$"
745 if !t.short {
746 suffix = ""
747 run = ""
748 }
749 t.registerTest("GOFIPS140="+version+" go test crypto/..."+suffix, &goTest{
750 variant: "gofips140-" + version,
751 pkg: "crypto/...",
752 runTests: run,
753 env: []string{"GOFIPS140=" + version, "GOMODCACHE=" + filepath.Join(workdir, "fips-"+version)},
754 })
755 }
756 }
757
758
759 if !strings.Contains(goexperiment, "nojsonv2") {
760 t.registerTest("GOEXPERIMENT=nojsonv2 go test encoding/json/...", &goTest{
761 variant: "nojsonv2",
762 env: []string{"GOEXPERIMENT=" + goexperiments("nojsonv2")},
763 pkg: "encoding/json/...",
764 })
765 }
766
767
768 if !strings.Contains(goexperiment, "runtimesecret") {
769 t.registerTest("GOEXPERIMENT=runtimesecret go test runtime/secret/...", &goTest{
770 variant: "runtimesecret",
771 env: []string{"GOEXPERIMENT=" + goexperiments("runtimesecret")},
772 pkg: "runtime/secret/...",
773 })
774 }
775
776
777 if !strings.Contains(goexperiment, "simd") {
778
779 t.registerTest("GOEXPERIMENT=simd go test simd", &goTest{
780 variant: "simd",
781 env: []string{"GOEXPERIMENT=" + goexperiments("simd")},
782 pkg: "simd",
783 })
784
785 archsimdSupported := goarch == "amd64" || goarch == "arm64" || goarch == "wasm"
786 if archsimdSupported {
787 t.registerTest("GOEXPERIMENT=simd go test simd/archsimd/...", &goTest{
788 variant: "simd",
789 env: []string{"GOEXPERIMENT=" + goexperiments("simd")},
790 pkg: "simd/archsimd/...",
791 })
792 }
793 }
794
795
796 if goos == "darwin" && goarch == "amd64" && t.cgoEnabled {
797 t.registerTest("GOOS=ios on darwin/amd64",
798 &goTest{
799 variant: "amd64ios",
800 runTests: "SystemRoots",
801 env: []string{"GOOS=ios", "CGO_ENABLED=1"},
802 pkg: "crypto/x509",
803 })
804 }
805
806
807
808
809 if !t.compileOnly && !t.short {
810 t.registerTest("GODEBUG=gcstoptheworld=2 archive/zip",
811 &goTest{
812 variant: "gcstoptheworld2",
813 short: true,
814 env: []string{"GODEBUG=gcstoptheworld=2"},
815 pkg: "archive/zip",
816 })
817 t.registerTest("GODEBUG=gccheckmark=1 runtime",
818 &goTest{
819 variant: "gccheckmark",
820 short: true,
821 env: []string{"GODEBUG=gccheckmark=1"},
822 pkg: "runtime",
823 })
824 }
825
826
827 if goos == "linux" && goarch == "amd64" && !(gogcflags == "-spectre=all" && t.asmflags == "all=-spectre=all") {
828
829 pkgs := []string{"internal/runtime/...", "reflect", "crypto/..."}
830 if !t.short {
831 pkgs = append(pkgs, "runtime")
832 }
833 t.registerTest("spectre",
834 &goTest{
835 variant: "spectre",
836 short: true,
837 env: []string{"GOFLAGS=-gcflags=all=-spectre=all -asmflags=all=-spectre=all"},
838 pkgs: pkgs,
839 })
840 }
841
842
843
844
845
846 if !t.compileOnly && !t.short {
847
848 hooks := []string{"mayMoreStackPreempt", "mayMoreStackMove"}
849
850
851 hookPkgs := []string{"runtime/...", "reflect", "sync"}
852
853
854 unhookPkgs := []string{"runtime/testdata/..."}
855 for _, hook := range hooks {
856
857
858
859
860
861
862 goFlagsList := []string{}
863 for _, flag := range []string{"-gcflags", "-asmflags"} {
864 for _, hookPkg := range hookPkgs {
865 goFlagsList = append(goFlagsList, flag+"="+hookPkg+"=-d=maymorestack=runtime."+hook)
866 }
867 for _, unhookPkg := range unhookPkgs {
868 goFlagsList = append(goFlagsList, flag+"="+unhookPkg+"=")
869 }
870 }
871 goFlags := strings.Join(goFlagsList, " ")
872
873 t.registerTest("maymorestack="+hook,
874 &goTest{
875 variant: hook,
876 short: true,
877 env: []string{"GOFLAGS=" + goFlags},
878 pkgs: []string{"runtime", "reflect", "sync"},
879 })
880 }
881 }
882
883
884
885
886
887 for _, pkg := range cgoPackages {
888 if !t.internalLink() {
889 break
890 }
891
892
893 if goarch == "arm" {
894 break
895 }
896
897
898
899 run := "^Test[^CS]"
900 if pkg == "net" {
901 run = "TestTCPStress"
902 }
903 t.registerTest("Testing without libgcc.",
904 &goTest{
905 variant: "nolibgcc",
906 ldflags: "-linkmode=internal -libgcc=none",
907 runTests: run,
908 pkg: pkg,
909 })
910 }
911
912
913 builderName := os.Getenv("GO_BUILDER_NAME")
914 disablePIE := strings.HasSuffix(builderName, "-alpine")
915
916
917 if t.internalLinkPIE() && !disablePIE {
918 t.registerTest("internal linking, -buildmode=pie",
919 &goTest{
920 variant: "pie_internal",
921 buildmode: "pie",
922 ldflags: "-linkmode=internal",
923 env: []string{"CGO_ENABLED=0"},
924 pkg: "reflect",
925 })
926 t.registerTest("internal linking, -buildmode=pie",
927 &goTest{
928 variant: "pie_internal",
929 buildmode: "pie",
930 ldflags: "-linkmode=internal",
931 env: []string{"CGO_ENABLED=0"},
932 pkg: "crypto/internal/fips140test",
933 runTests: "TestFIPSCheck",
934 })
935
936 if t.cgoEnabled && t.internalLink() && !disablePIE {
937 t.registerTest("internal linking, -buildmode=pie",
938 &goTest{
939 variant: "pie_internal",
940 buildmode: "pie",
941 ldflags: "-linkmode=internal",
942 pkg: "os/user",
943 })
944 }
945 }
946
947 if t.extLink() && !t.compileOnly {
948 if goos != "android" {
949 t.registerTest("external linking, -buildmode=exe",
950 &goTest{
951 variant: "exe_external",
952 buildmode: "exe",
953 ldflags: "-linkmode=external",
954 env: []string{"CGO_ENABLED=1"},
955 pkg: "crypto/internal/fips140test",
956 runTests: "TestFIPSCheck",
957 })
958 }
959 if t.externalLinkPIE() && !disablePIE {
960 t.registerTest("external linking, -buildmode=pie",
961 &goTest{
962 variant: "pie_external",
963 buildmode: "pie",
964 ldflags: "-linkmode=external",
965 env: []string{"CGO_ENABLED=1"},
966 pkg: "crypto/internal/fips140test",
967 runTests: "TestFIPSCheck",
968 })
969 }
970 }
971
972
973 if !t.compileOnly && t.hasParallelism() {
974 t.registerTest("sync -cpu=10",
975 &goTest{
976 variant: "cpu10",
977 cpu: "10",
978 pkg: "sync",
979 })
980 }
981
982 const cgoHeading = "Testing cgo"
983 if t.cgoEnabled {
984 t.registerCgoTests(cgoHeading)
985 }
986
987 if goos == "wasip1" {
988 t.registerTest("wasip1 host tests",
989 &goTest{
990 variant: "host",
991 pkg: "internal/runtime/wasitest",
992 runOnHost: true,
993 })
994 }
995
996
997 if !t.compileOnly && t.hasParallelism() {
998 for i := 1; i <= 4; i *= 2 {
999 t.registerTest(fmt.Sprintf("GOMAXPROCS=2 runtime -cpu=%d -quick", i),
1000 &goTest{
1001 variant: "cpu" + strconv.Itoa(i),
1002 cpu: strconv.Itoa(i),
1003 gcflags: gogcflags,
1004 short: true,
1005 testFlags: []string{"-quick"},
1006
1007
1008 env: []string{"GOMAXPROCS=2"},
1009 pkg: "runtime",
1010 })
1011 }
1012 }
1013
1014 if t.raceDetectorSupported() && !t.msan && !t.asan {
1015
1016 t.registerRaceTests()
1017 }
1018
1019
1020
1021 if goos == "js" || goos == "wasip1" {
1022 t.registerTest("../test",
1023 &goTest{
1024 variant: "host",
1025 pkg: "cmd/internal/testdir",
1026 runOnHost: true,
1027 },
1028 )
1029 }
1030 }
1031
1032
1033
1034
1035 func (t *tester) addTest(name, heading string, fn func(*distTest) error) {
1036 if t.testNames[name] {
1037 panic("duplicate registered test name " + name)
1038 }
1039 if heading == "" {
1040 panic("empty heading")
1041 }
1042
1043 if !strings.Contains(name, ":") && heading != "Testing packages." {
1044 panic("empty variant is reserved exclusively for registerStdTest")
1045 } else if strings.HasSuffix(name, ":racebench") && heading != "Running benchmarks briefly." {
1046 panic("racebench variant is reserved exclusively for registerRaceBenchTest")
1047 }
1048 if t.testNames == nil {
1049 t.testNames = make(map[string]bool)
1050 }
1051 t.testNames[name] = true
1052 t.tests = append(t.tests, distTest{
1053 name: name,
1054 heading: heading,
1055 fn: fn,
1056 })
1057 }
1058
1059 type registerTestOpt interface {
1060 isRegisterTestOpt()
1061 }
1062
1063
1064
1065 type rtSkipFunc struct {
1066 skip func(*distTest) (string, bool)
1067 }
1068
1069 func (rtSkipFunc) isRegisterTestOpt() {}
1070
1071
1072
1073
1074
1075
1076
1077 func (t *tester) registerTest(heading string, test *goTest, opts ...registerTestOpt) {
1078 var skipFunc func(*distTest) (string, bool)
1079 for _, opt := range opts {
1080 switch opt := opt.(type) {
1081 case rtSkipFunc:
1082 skipFunc = opt.skip
1083 }
1084 }
1085
1086 register1 := func(test *goTest) {
1087 if test.variant == "" {
1088 panic("empty variant")
1089 }
1090 name := testName(test.pkg, test.variant)
1091 t.addTest(name, heading, func(dt *distTest) error {
1092 if skipFunc != nil {
1093 msg, skip := skipFunc(dt)
1094 if skip {
1095 test.printSkip(t, msg)
1096 return nil
1097 }
1098 }
1099 w := &work{dt: dt}
1100 w.cmd, w.flush = test.bgCommand(t, &w.out, &w.out)
1101 t.worklist = append(t.worklist, w)
1102 return nil
1103 })
1104 }
1105 if test.pkg != "" && len(test.pkgs) == 0 {
1106
1107 register1(test)
1108 return
1109 }
1110
1111
1112
1113
1114
1115
1116 for _, pkg := range test.packages() {
1117 test1 := *test
1118 test1.pkg, test1.pkgs = pkg, nil
1119 register1(&test1)
1120 }
1121 }
1122
1123
1124
1125
1126 func (t *tester) dirCmd(dir string, cmdline ...any) *exec.Cmd {
1127 bin, args := flattenCmdline(cmdline)
1128 cmd := exec.Command(bin, args...)
1129 if filepath.IsAbs(dir) {
1130 setDir(cmd, dir)
1131 } else {
1132 setDir(cmd, filepath.Join(goroot, dir))
1133 }
1134 cmd.Stdout = os.Stdout
1135 cmd.Stderr = os.Stderr
1136 if vflag > 1 {
1137 errprintf("%#q\n", cmd)
1138 }
1139 return cmd
1140 }
1141
1142
1143
1144 func flattenCmdline(cmdline []any) (bin string, args []string) {
1145 var list []string
1146 for _, x := range cmdline {
1147 switch x := x.(type) {
1148 case string:
1149 list = append(list, x)
1150 case []string:
1151 list = append(list, x...)
1152 default:
1153 panic("invalid dirCmd argument type: " + reflect.TypeOf(x).String())
1154 }
1155 }
1156
1157 bin = list[0]
1158 if !filepath.IsAbs(bin) {
1159 panic("command is not absolute: " + bin)
1160 }
1161 return bin, list[1:]
1162 }
1163
1164 func (t *tester) iOS() bool {
1165 return goos == "ios"
1166 }
1167
1168 func (t *tester) out(v string) {
1169 if t.json {
1170 return
1171 }
1172 if t.banner == "" {
1173 return
1174 }
1175 fmt.Println("\n" + t.banner + v)
1176 }
1177
1178
1179
1180 func (t *tester) extLink() bool {
1181 if !cgoEnabled[goos+"/"+goarch] {
1182 return false
1183 }
1184 if goarch == "ppc64" && goos != "aix" && goos != "linux" {
1185 return false
1186 }
1187 return true
1188 }
1189
1190 func (t *tester) internalLink() bool {
1191 if gohostos == "dragonfly" {
1192
1193 return false
1194 }
1195 if goos == "android" {
1196 return false
1197 }
1198 if goos == "ios" {
1199 return false
1200 }
1201
1202
1203
1204 if goarch == "mips64" || goarch == "mips64le" || goarch == "mips" || goarch == "mipsle" || goarch == "riscv64" {
1205 return false
1206 }
1207 if goos == "aix" {
1208
1209 return false
1210 }
1211 if t.msan || t.asan {
1212
1213 return false
1214 }
1215 return true
1216 }
1217
1218 func (t *tester) internalLinkPIE() bool {
1219 if t.msan || t.asan {
1220
1221 return false
1222 }
1223 switch goos + "-" + goarch {
1224 case "darwin-amd64", "darwin-arm64",
1225 "freebsd-amd64",
1226 "linux-amd64", "linux-arm64", "linux-loong64", "linux-ppc64", "linux-ppc64le", "linux-s390x",
1227 "android-arm64",
1228 "windows-amd64", "windows-386", "windows-arm64":
1229 return true
1230 }
1231 return false
1232 }
1233
1234 func (t *tester) externalLinkPIE() bool {
1235
1236 return t.internalLinkPIE() && t.extLink()
1237 }
1238
1239
1240 func (t *tester) supportedBuildmode(mode string) bool {
1241 switch mode {
1242 case "c-archive", "c-shared", "shared", "plugin", "pie":
1243 default:
1244 fatalf("internal error: unknown buildmode %s", mode)
1245 return false
1246 }
1247
1248 return buildModeSupported("gc", mode, goos, goarch)
1249 }
1250
1251 func (t *tester) registerCgoTests(heading string) {
1252 cgoTest := func(variant string, subdir, linkmode, buildmode string, opts ...registerTestOpt) *goTest {
1253 gt := &goTest{
1254 variant: variant,
1255 pkg: "cmd/cgo/internal/" + subdir,
1256 buildmode: buildmode,
1257 }
1258 var ldflags []string
1259 if linkmode != "auto" {
1260
1261 ldflags = append(ldflags, "-linkmode="+linkmode)
1262 }
1263
1264 if linkmode == "internal" {
1265 gt.tags = append(gt.tags, "internal")
1266 if buildmode == "pie" {
1267 gt.tags = append(gt.tags, "internal_pie")
1268 }
1269 }
1270 if buildmode == "static" {
1271
1272
1273 gt.buildmode = ""
1274 switch linkmode {
1275 case "external":
1276 ldflags = append(ldflags, `-extldflags "-static -pthread"`)
1277 case "auto":
1278 gt.env = append(gt.env, "CGO_LDFLAGS=-static -pthread")
1279 default:
1280 panic("unknown linkmode with static build: " + linkmode)
1281 }
1282 gt.tags = append(gt.tags, "static")
1283 }
1284 gt.ldflags = strings.Join(ldflags, " ")
1285
1286 t.registerTest(heading, gt, opts...)
1287 return gt
1288 }
1289
1290
1291
1292
1293
1294
1295 builderName := os.Getenv("GO_BUILDER_NAME")
1296 disablePIE := strings.HasSuffix(builderName, "-alpine")
1297
1298 if t.internalLink() {
1299 cgoTest("internal", "test", "internal", "")
1300 }
1301
1302 os := gohostos
1303 p := gohostos + "/" + goarch
1304 switch os {
1305 case "darwin", "windows":
1306 if !t.extLink() {
1307 break
1308 }
1309
1310 cgoTest("external", "test", "external", "")
1311
1312 gt := cgoTest("external-s", "test", "external", "")
1313 gt.ldflags += " -s"
1314
1315 if t.supportedBuildmode("pie") && !disablePIE {
1316 cgoTest("auto-pie", "test", "auto", "pie")
1317 if t.internalLink() && t.internalLinkPIE() {
1318 cgoTest("internal-pie", "test", "internal", "pie")
1319 }
1320 }
1321
1322 case "aix", "android", "dragonfly", "freebsd", "linux", "netbsd", "openbsd":
1323 gt := cgoTest("external-g0", "test", "external", "")
1324 gt.env = append(gt.env, "CGO_CFLAGS=-g0 -fdiagnostics-color")
1325
1326 cgoTest("external", "testtls", "external", "")
1327 switch {
1328 case os == "aix":
1329
1330 case p == "freebsd/arm":
1331
1332
1333
1334
1335
1336 default:
1337
1338 var staticCheck rtSkipFunc
1339 ccName := compilerEnvLookup("CC", defaultcc, goos, goarch)
1340 cc, err := exec.LookPath(ccName)
1341 if err != nil {
1342 staticCheck.skip = func(*distTest) (string, bool) {
1343 return fmt.Sprintf("$CC (%q) not found, skip cgo static linking test.", ccName), true
1344 }
1345 } else {
1346 cmd := t.dirCmd("src/cmd/cgo/internal/test", cc, "-xc", "-o", "/dev/null", "-static", "-")
1347 cmd.Stdin = strings.NewReader("int main() {}")
1348 cmd.Stdout, cmd.Stderr = nil, nil
1349 if err := cmd.Run(); err != nil {
1350
1351 staticCheck.skip = func(*distTest) (string, bool) {
1352 return "No support for static linking found (lacks libc.a?), skip cgo static linking test.", true
1353 }
1354 }
1355 }
1356
1357
1358
1359
1360
1361 if staticCheck.skip == nil && goos == "linux" && strings.Contains(goexperiment, "boringcrypto") {
1362 staticCheck.skip = func(*distTest) (string, bool) {
1363 return "skipping static linking check on Linux when using boringcrypto to avoid C linker warning about getaddrinfo", true
1364 }
1365 }
1366
1367
1368 if goos != "android" && p != "netbsd/arm" && !t.msan && !t.asan {
1369
1370
1371
1372 cgoTest("static", "testtls", "external", "static", staticCheck)
1373 }
1374 cgoTest("external", "testnocgo", "external", "", staticCheck)
1375 if goos != "android" && !t.msan && !t.asan {
1376
1377
1378 cgoTest("static", "testnocgo", "external", "static", staticCheck)
1379 cgoTest("static", "test", "external", "static", staticCheck)
1380
1381
1382
1383 if goarch != "loong64" && !t.msan && !t.asan {
1384
1385 cgoTest("auto-static", "test", "auto", "static", staticCheck)
1386 }
1387 }
1388
1389
1390 if t.supportedBuildmode("pie") && !disablePIE {
1391 cgoTest("auto-pie", "test", "auto", "pie")
1392 if t.internalLink() && t.internalLinkPIE() {
1393 cgoTest("internal-pie", "test", "internal", "pie")
1394 }
1395 cgoTest("auto-pie", "testtls", "auto", "pie")
1396 cgoTest("auto-pie", "testnocgo", "auto", "pie")
1397 }
1398 }
1399 }
1400 }
1401
1402
1403
1404
1405
1406
1407
1408 func (t *tester) runPending(nextTest *distTest) {
1409 worklist := t.worklist
1410 t.worklist = nil
1411 var pendingSpan span
1412 if len(worklist) > 0 {
1413 pendingSpan = startSpan("runPending")
1414 }
1415 maxbg := runtime.GOMAXPROCS(0)
1416 for i, w := range worklist {
1417 w.start = make(chan bool)
1418 w.end = make(chan struct{})
1419
1420
1421 if w.cmd.Stdout == nil || w.cmd.Stdout == os.Stdout || w.cmd.Stderr == nil || w.cmd.Stderr == os.Stderr {
1422 panic("work.cmd.Stdout/Stderr must be redirected")
1423 }
1424 go func(w *work) {
1425 if !<-w.start {
1426 timelog("skip", w.dt.name)
1427 w.printSkip(t, "skipped due to earlier error")
1428 } else {
1429 timelog("start", w.dt.name)
1430 s := startSpanTID(w.dt.name, uint64(i%maxbg+1))
1431 w.err = w.cmd.Run()
1432 if w.flush != nil {
1433 w.flush()
1434 }
1435 s.done()
1436 if w.err != nil {
1437 if isUnsupportedVMASize(w) {
1438 timelog("skip", w.dt.name)
1439 w.out.Reset()
1440 w.printSkip(t, "skipped due to unsupported VMA")
1441 w.err = nil
1442 }
1443 }
1444 }
1445 timelog("end", w.dt.name)
1446 w.end <- struct{}{}
1447 }(w)
1448 }
1449
1450 started := 0
1451 ended := 0
1452 var last *distTest
1453 for ended < len(worklist) {
1454 for started < len(worklist) && started-ended < maxbg {
1455 w := worklist[started]
1456 started++
1457 w.start <- !t.failed || t.keepGoing
1458 }
1459 w := worklist[ended]
1460 dt := w.dt
1461 if t.lastHeading != dt.heading {
1462 t.lastHeading = dt.heading
1463 t.out(dt.heading)
1464 }
1465 if dt != last {
1466
1467 last = w.dt
1468 if vflag > 0 {
1469 fmt.Printf("# go tool dist test -run=^%s$\n", dt.name)
1470 }
1471 }
1472 if vflag > 1 {
1473 errprintf("%#q\n", w.cmd)
1474 }
1475 ended++
1476 <-w.end
1477 os.Stdout.Write(w.out.Bytes())
1478
1479 w.out = bytes.Buffer{}
1480 if w.err != nil {
1481 log.Printf("Failed: %v", w.err)
1482 t.failed = true
1483 }
1484 }
1485 pendingSpan.done()
1486 if t.failed && !t.keepGoing {
1487 fatalf("FAILED")
1488 }
1489
1490 if dt := nextTest; dt != nil {
1491 if t.lastHeading != dt.heading {
1492 t.lastHeading = dt.heading
1493 t.out(dt.heading)
1494 }
1495 if vflag > 0 {
1496 fmt.Printf("# go tool dist test -run=^%s$\n", dt.name)
1497 }
1498 }
1499 }
1500
1501
1502
1503
1504 func (t *tester) hasParallelism() bool {
1505 switch goos {
1506 case "js", "wasip1":
1507 return false
1508 }
1509 return true
1510 }
1511
1512 func (t *tester) raceDetectorSupported() bool {
1513 if gohostos != goos {
1514 return false
1515 }
1516 if !t.cgoEnabled {
1517 return false
1518 }
1519 if !raceDetectorSupported(goos, goarch) {
1520 return false
1521 }
1522
1523
1524 if isAlpineLinux() {
1525 return false
1526 }
1527
1528
1529 if goos == "netbsd" {
1530 return false
1531 }
1532 return true
1533 }
1534
1535 func isAlpineLinux() bool {
1536 if runtime.GOOS != "linux" {
1537 return false
1538 }
1539 fi, err := os.Lstat("/etc/alpine-release")
1540 return err == nil && fi.Mode().IsRegular()
1541 }
1542
1543 func (t *tester) registerRaceTests() {
1544 hdr := "Testing race detector"
1545 t.registerTest(hdr,
1546 &goTest{
1547 variant: "race",
1548 race: true,
1549 runTests: "Output",
1550 pkg: "runtime/race",
1551 })
1552 t.registerTest(hdr,
1553 &goTest{
1554 variant: "race",
1555 race: true,
1556 runTests: "TestParse|TestEcho|TestStdinCloseRace|TestClosedPipeRace|TestTypeRace|TestFdRace|TestFdReadRace|TestFileCloseRace",
1557 pkgs: []string{"flag", "net", "os", "os/exec", "encoding/gob"},
1558 })
1559
1560
1561
1562
1563
1564 if t.cgoEnabled {
1565
1566
1567
1568
1569
1570 }
1571 if t.extLink() {
1572
1573 t.registerTest(hdr,
1574 &goTest{
1575 variant: "race-external",
1576 race: true,
1577 ldflags: "-linkmode=external",
1578 runTests: "TestParse|TestEcho|TestStdinCloseRace",
1579 pkgs: []string{"flag", "os/exec"},
1580 })
1581 }
1582 }
1583
1584
1585 var cgoPackages = []string{
1586 "net",
1587 "os/user",
1588 }
1589
1590 var funcBenchmark = []byte("\nfunc Benchmark")
1591
1592
1593
1594
1595
1596
1597
1598
1599 func (t *tester) packageHasBenchmarks(pkg string) bool {
1600 pkgDir := filepath.Join(goroot, "src", pkg)
1601 d, err := os.Open(pkgDir)
1602 if err != nil {
1603 return true
1604 }
1605 defer d.Close()
1606 names, err := d.Readdirnames(-1)
1607 if err != nil {
1608 return true
1609 }
1610 for _, name := range names {
1611 if !strings.HasSuffix(name, "_test.go") {
1612 continue
1613 }
1614 slurp, err := os.ReadFile(filepath.Join(pkgDir, name))
1615 if err != nil {
1616 return true
1617 }
1618 if bytes.Contains(slurp, funcBenchmark) {
1619 return true
1620 }
1621 }
1622 return false
1623 }
1624
1625
1626
1627 func (t *tester) makeGOROOTUnwritable() (undo func()) {
1628 dir := os.Getenv("GOROOT")
1629 if dir == "" {
1630 panic("GOROOT not set")
1631 }
1632
1633 type pathMode struct {
1634 path string
1635 mode os.FileMode
1636 }
1637 var dirs []pathMode
1638
1639 undo = func() {
1640 for i := range dirs {
1641 os.Chmod(dirs[i].path, dirs[i].mode)
1642 }
1643 }
1644
1645 filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
1646 if suffix := strings.TrimPrefix(path, dir+string(filepath.Separator)); suffix != "" {
1647 if suffix == ".git" {
1648
1649
1650
1651 return filepath.SkipDir
1652 }
1653 }
1654 if err != nil {
1655 return nil
1656 }
1657
1658 info, err := d.Info()
1659 if err != nil {
1660 return nil
1661 }
1662
1663 mode := info.Mode()
1664 if mode&0222 != 0 && (mode.IsDir() || mode.IsRegular()) {
1665 dirs = append(dirs, pathMode{path, mode})
1666 }
1667 return nil
1668 })
1669
1670
1671 for i := len(dirs) - 1; i >= 0; i-- {
1672 err := os.Chmod(dirs[i].path, dirs[i].mode&^0222)
1673 if err != nil {
1674 dirs = dirs[i:]
1675 undo()
1676 fatalf("failed to make GOROOT read-only: %v", err)
1677 }
1678 }
1679
1680 return undo
1681 }
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691 func raceDetectorSupported(goos, goarch string) bool {
1692 switch goos {
1693 case "linux":
1694 return goarch == "amd64" || goarch == "arm64" || goarch == "loong64" || goarch == "ppc64le" || goarch == "riscv64" || goarch == "s390x"
1695 case "darwin":
1696 return goarch == "amd64" || goarch == "arm64"
1697 case "freebsd", "netbsd", "windows":
1698 return goarch == "amd64"
1699 default:
1700 return false
1701 }
1702 }
1703
1704
1705
1706
1707 func fips140Supported(goos, goarch string) bool {
1708 switch {
1709 case goarch == "wasm",
1710 goos == "windows" && goarch == "386",
1711 goos == "openbsd",
1712 goos == "aix":
1713 return false
1714 }
1715 return true
1716 }
1717
1718
1719
1720
1721 func buildModeSupported(compiler, buildmode, goos, goarch string) bool {
1722 if compiler == "gccgo" {
1723 return true
1724 }
1725
1726 platform := goos + "/" + goarch
1727
1728 switch buildmode {
1729 case "archive":
1730 return true
1731
1732 case "c-archive":
1733 switch goos {
1734 case "aix", "darwin", "ios", "windows":
1735 return true
1736 case "linux":
1737 switch goarch {
1738 case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "loong64", "ppc64", "ppc64le", "riscv64", "s390x":
1739 return true
1740 default:
1741
1742
1743
1744
1745
1746
1747 return false
1748 }
1749 case "freebsd":
1750 return goarch == "amd64"
1751 }
1752 return false
1753
1754 case "c-shared":
1755 switch platform {
1756 case "linux/amd64", "linux/arm", "linux/arm64", "linux/loong64", "linux/386", "linux/ppc64", "linux/ppc64le", "linux/riscv64", "linux/s390x",
1757 "android/amd64", "android/arm", "android/arm64", "android/386",
1758 "freebsd/amd64",
1759 "darwin/amd64", "darwin/arm64",
1760 "windows/amd64", "windows/386", "windows/arm64",
1761 "wasip1/wasm":
1762 return true
1763 }
1764 return false
1765
1766 case "default":
1767 return true
1768
1769 case "exe":
1770 return true
1771
1772 case "pie":
1773 switch platform {
1774 case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/loong64", "linux/ppc64", "linux/ppc64le", "linux/riscv64", "linux/s390x",
1775 "android/amd64", "android/arm", "android/arm64", "android/386",
1776 "freebsd/amd64",
1777 "darwin/amd64", "darwin/arm64",
1778 "ios/amd64", "ios/arm64",
1779 "aix/ppc64",
1780 "openbsd/amd64", "openbsd/arm64",
1781 "windows/386", "windows/amd64", "windows/arm64":
1782 return true
1783 }
1784 return false
1785
1786 case "shared":
1787 switch platform {
1788 case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64", "linux/ppc64le", "linux/s390x":
1789 return true
1790 }
1791 return false
1792
1793 case "plugin":
1794 switch platform {
1795 case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/loong64", "linux/riscv64", "linux/s390x", "linux/ppc64", "linux/ppc64le",
1796 "android/amd64", "android/386",
1797 "darwin/amd64", "darwin/arm64",
1798 "freebsd/amd64":
1799 return true
1800 }
1801 return false
1802
1803 default:
1804 return false
1805 }
1806 }
1807
1808
1809
1810
1811 func isUnsupportedVMASize(w *work) bool {
1812 unsupportedVMA := []byte("unsupported VMA range")
1813 return strings.Contains(w.dt.name, ":race") && bytes.Contains(w.out.Bytes(), unsupportedVMA)
1814 }
1815
1816
1817
1818 func isEnvSet(evar string) bool {
1819 evarEq := evar + "="
1820 for _, e := range os.Environ() {
1821 if strings.HasPrefix(e, evarEq) {
1822 return true
1823 }
1824 }
1825 return false
1826 }
1827
1828 func (t *tester) fips140Supported() bool {
1829 if !fips140Supported(goos, goarch) {
1830 return false
1831 }
1832
1833
1834
1835
1836
1837 if strings.Contains(goexperiment, "boringcrypto") {
1838 return false
1839 }
1840
1841
1842
1843 if t.asan {
1844 return false
1845 }
1846
1847 return true
1848 }
1849
1850
1851 func fips140Versions() []string {
1852 var versions []string
1853 zips, err := filepath.Glob(filepath.Join(goroot, "lib/fips140/*.zip"))
1854 if err != nil {
1855 fatalf("%v", err)
1856 }
1857 for _, zip := range zips {
1858 versions = append(versions, strings.TrimSuffix(filepath.Base(zip), ".zip"))
1859 }
1860 return versions
1861 }
1862
1863
1864
1865
1866
1867 func goexperiments(exps ...string) string {
1868 if len(exps) == 0 {
1869 return goexperiment
1870 }
1871 existing := goexperiment
1872 if existing != "" {
1873 existing += ","
1874 }
1875 return existing + strings.Join(exps, ",")
1876
1877 }
1878
View as plain text