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