@@ -74,6 +74,8 @@ type tester struct {
74
74
testNames map [string ]bool
75
75
timeoutScale int
76
76
77
+ variantNames map [string ]bool // check that pkg[:variant] names are unique
78
+
77
79
worklist []* work
78
80
}
79
81
@@ -298,6 +300,13 @@ type goTest struct {
298
300
299
301
runOnHost bool // When cross-compiling, run this test on the host instead of guest
300
302
303
+ // variant, if non-empty, is a name used to distinguish different
304
+ // configurations of the same test package(s).
305
+ variant string
306
+ // sharded indicates that variant is used solely for sharding and that
307
+ // the set of test names run by each variant of a package is non-overlapping.
308
+ sharded bool
309
+
301
310
// We have both pkg and pkgs as a convenience. Both may be set, in which
302
311
// case they will be combined. At least one must be set.
303
312
pkgs []string // Multiple packages to test
@@ -405,13 +414,7 @@ func (opts *goTest) buildArgs(t *tester) (goCmd string, build, run, pkgs, testFl
405
414
build = append (build , "-buildmode=" + opts .buildmode )
406
415
}
407
416
408
- pkgs = opts .pkgs
409
- if opts .pkg != "" {
410
- pkgs = append (pkgs [:len (pkgs ):len (pkgs )], opts .pkg )
411
- }
412
- if len (pkgs ) == 0 {
413
- panic ("no packages" )
414
- }
417
+ pkgs = opts .packages ()
415
418
416
419
runOnHost := opts .runOnHost && (goarch != gohostarch || goos != gohostos )
417
420
needTestFlags := len (opts .testFlags ) > 0 || runOnHost
@@ -448,6 +451,19 @@ func (opts *goTest) buildArgs(t *tester) (goCmd string, build, run, pkgs, testFl
448
451
return
449
452
}
450
453
454
+ // packages returns the full list of packages to be run by this goTest. This
455
+ // will always include at least one package.
456
+ func (opts * goTest ) packages () []string {
457
+ pkgs := opts .pkgs
458
+ if opts .pkg != "" {
459
+ pkgs = append (pkgs [:len (pkgs ):len (pkgs )], opts .pkg )
460
+ }
461
+ if len (pkgs ) == 0 {
462
+ panic ("no packages" )
463
+ }
464
+ return pkgs
465
+ }
466
+
451
467
// ranGoTest and stdMatches are state closed over by the stdlib
452
468
// testing func in registerStdTest below. The tests are run
453
469
// sequentially, so there's no need for locks.
@@ -592,12 +608,14 @@ func (t *tester) registerTests() {
592
608
if ! t .compileOnly {
593
609
t .registerTest ("osusergo" , "os/user with tag osusergo" ,
594
610
& goTest {
611
+ variant : "osusergo" ,
595
612
timeout : 300 * time .Second ,
596
613
tags : []string {"osusergo" },
597
614
pkg : "os/user" ,
598
615
})
599
616
t .registerTest ("purego:hash/maphash" , "hash/maphash purego implementation" ,
600
617
& goTest {
618
+ variant : "purego" ,
601
619
timeout : 300 * time .Second ,
602
620
tags : []string {"purego" },
603
621
pkg : "hash/maphash" ,
@@ -608,6 +626,7 @@ func (t *tester) registerTests() {
608
626
if goos == "darwin" && goarch == "amd64" && t .cgoEnabled {
609
627
t .registerTest ("amd64ios" , "GOOS=ios on darwin/amd64" ,
610
628
& goTest {
629
+ variant : "amd64ios" ,
611
630
timeout : 300 * time .Second ,
612
631
runTests : "SystemRoots" ,
613
632
env : []string {"GOOS=ios" , "CGO_ENABLED=1" },
@@ -619,6 +638,7 @@ func (t *tester) registerTests() {
619
638
if ! t .compileOnly && t .hasParallelism () {
620
639
t .registerTest ("runtime:cpu124" , "GOMAXPROCS=2 runtime -cpu=1,2,4 -quick" ,
621
640
& goTest {
641
+ variant : "cpu124" ,
622
642
timeout : 300 * time .Second ,
623
643
cpu : "1,2,4" ,
624
644
short : true ,
@@ -666,6 +686,7 @@ func (t *tester) registerTests() {
666
686
for _ , pkg := range pkgs {
667
687
t .registerTest (hook + ":" + pkg , "maymorestack=" + hook ,
668
688
& goTest {
689
+ variant : hook ,
669
690
timeout : 600 * time .Second ,
670
691
short : true ,
671
692
env : []string {"GOFLAGS=" + goFlags },
@@ -704,8 +725,9 @@ func (t *tester) registerTests() {
704
725
// Run `go test fmt` in the moved GOROOT, without explicitly setting
705
726
// GOROOT in the environment. The 'go' command should find itself.
706
727
cmd := (& goTest {
707
- goroot : moved ,
708
- pkg : "fmt" ,
728
+ variant : "moved_goroot" ,
729
+ goroot : moved ,
730
+ pkg : "fmt" ,
709
731
}).command (t )
710
732
unsetEnv (cmd , "GOROOT" )
711
733
err := cmd .Run ()
@@ -739,6 +761,7 @@ func (t *tester) registerTests() {
739
761
}
740
762
t .registerTest ("nolibgcc:" + pkg , "Testing without libgcc." ,
741
763
& goTest {
764
+ variant : "nolibgcc" ,
742
765
ldflags : "-linkmode=internal -libgcc=none" ,
743
766
runTests : run ,
744
767
pkg : pkg ,
@@ -753,6 +776,7 @@ func (t *tester) registerTests() {
753
776
if t .internalLinkPIE () && ! disablePIE {
754
777
t .registerTest ("pie_internal" , "internal linking of -buildmode=pie" ,
755
778
& goTest {
779
+ variant : "pie_internal" ,
756
780
timeout : 60 * time .Second ,
757
781
buildmode : "pie" ,
758
782
ldflags : "-linkmode=internal" ,
@@ -763,6 +787,7 @@ func (t *tester) registerTests() {
763
787
if t .cgoEnabled && t .internalLink () && ! disablePIE {
764
788
t .registerTest ("pie_internal_cgo" , "internal linking of -buildmode=pie" ,
765
789
& goTest {
790
+ variant : "pie_internal" ,
766
791
timeout : 60 * time .Second ,
767
792
buildmode : "pie" ,
768
793
ldflags : "-linkmode=internal" ,
@@ -775,6 +800,7 @@ func (t *tester) registerTests() {
775
800
if t .hasParallelism () {
776
801
t .registerTest ("sync_cpu" , "sync -cpu=10" ,
777
802
& goTest {
803
+ variant : "cpu10" ,
778
804
timeout : 120 * time .Second ,
779
805
cpu : "10" ,
780
806
pkg : "sync" ,
@@ -837,10 +863,13 @@ func (t *tester) registerTests() {
837
863
nShards = n
838
864
}
839
865
for shard := 0 ; shard < nShards ; shard ++ {
866
+ id := fmt .Sprintf ("%d_%d" , shard , nShards )
840
867
t .registerTest (
841
- fmt . Sprintf ( "test:%d_%d" , shard , nShards ) ,
868
+ "test:" + id ,
842
869
"../test" ,
843
870
& goTest {
871
+ variant : id ,
872
+ sharded : true ,
844
873
pkg : "cmd/internal/testdir" ,
845
874
testFlags : []string {fmt .Sprintf ("-shard=%d" , shard ), fmt .Sprintf ("-shards=%d" , nShards )},
846
875
runOnHost : true ,
@@ -854,7 +883,7 @@ func (t *tester) registerTests() {
854
883
// To help developers avoid trybot-only failures, we try to run on typical developer machines
855
884
// which is darwin,linux,windows/amd64 and darwin/arm64.
856
885
if goos == "darwin" || ((goos == "linux" || goos == "windows" ) && goarch == "amd64" ) {
857
- t .registerTest ("api" , "API check" , & goTest {pkg : "cmd/api" , timeout : 5 * time .Minute , testFlags : []string {"-check" }})
886
+ t .registerTest ("api" , "API check" , & goTest {variant : "check" , pkg : "cmd/api" , timeout : 5 * time .Minute , testFlags : []string {"-check" }})
858
887
}
859
888
}
860
889
@@ -895,6 +924,19 @@ func (rtPreFunc) isRegisterTestOpt() {}
895
924
//
896
925
// name must uniquely identify the test and heading must be non-empty.
897
926
func (t * tester ) registerTest (name , heading string , test * goTest , opts ... registerTestOpt ) {
927
+ if t .variantNames == nil {
928
+ t .variantNames = make (map [string ]bool )
929
+ }
930
+ for _ , pkg := range test .packages () {
931
+ variantName := pkg
932
+ if test .variant != "" {
933
+ variantName += ":" + test .variant
934
+ }
935
+ if t .variantNames [variantName ] {
936
+ panic ("duplicate variant name " + variantName )
937
+ }
938
+ t .variantNames [variantName ] = true
939
+ }
898
940
var preFunc func (* distTest ) bool
899
941
for _ , opt := range opts {
900
942
switch opt := opt .(type ) {
@@ -1049,8 +1091,9 @@ func (t *tester) supportedBuildmode(mode string) bool {
1049
1091
}
1050
1092
1051
1093
func (t * tester ) registerCgoTests (heading string ) {
1052
- cgoTest := func (name string , subdir , linkmode , buildmode string , opts ... registerTestOpt ) * goTest {
1094
+ cgoTest := func (variant string , subdir , linkmode , buildmode string , opts ... registerTestOpt ) * goTest {
1053
1095
gt := & goTest {
1096
+ variant : variant ,
1054
1097
pkg : "cmd/cgo/internal/" + subdir ,
1055
1098
buildmode : buildmode ,
1056
1099
ldflags : "-linkmode=" + linkmode ,
@@ -1076,18 +1119,18 @@ func (t *tester) registerCgoTests(heading string) {
1076
1119
gt .tags = append (gt .tags , "static" )
1077
1120
}
1078
1121
1079
- t .registerTest ("cgo:" + name , heading , gt , opts ... )
1122
+ t .registerTest ("cgo:" + subdir + ":" + variant , heading , gt , opts ... )
1080
1123
return gt
1081
1124
}
1082
1125
1083
- cgoTest ("test- auto" , "test" , "auto" , "" )
1126
+ cgoTest ("auto" , "test" , "auto" , "" )
1084
1127
1085
1128
// Stub out various buildmode=pie tests on alpine until 54354 resolved.
1086
1129
builderName := os .Getenv ("GO_BUILDER_NAME" )
1087
1130
disablePIE := strings .HasSuffix (builderName , "-alpine" )
1088
1131
1089
1132
if t .internalLink () {
1090
- cgoTest ("test- internal" , "test" , "internal" , "" )
1133
+ cgoTest ("internal" , "test" , "internal" , "" )
1091
1134
}
1092
1135
1093
1136
os := gohostos
@@ -1098,24 +1141,24 @@ func (t *tester) registerCgoTests(heading string) {
1098
1141
break
1099
1142
}
1100
1143
// test linkmode=external, but __thread not supported, so skip testtls.
1101
- cgoTest ("test- external" , "test" , "external" , "" )
1144
+ cgoTest ("external" , "test" , "external" , "" )
1102
1145
1103
- gt := cgoTest ("test- external-s" , "test" , "external" , "" )
1146
+ gt := cgoTest ("external-s" , "test" , "external" , "" )
1104
1147
gt .ldflags += " -s"
1105
1148
1106
1149
if t .supportedBuildmode ("pie" ) && ! disablePIE {
1107
- cgoTest ("test- auto-pie" , "test" , "auto" , "pie" )
1150
+ cgoTest ("auto-pie" , "test" , "auto" , "pie" )
1108
1151
if t .internalLink () && t .internalLinkPIE () {
1109
- cgoTest ("test- internal-pie" , "test" , "internal" , "pie" )
1152
+ cgoTest ("internal-pie" , "test" , "internal" , "pie" )
1110
1153
}
1111
1154
}
1112
1155
1113
1156
case os == "aix" , os == "android" , os == "dragonfly" , os == "freebsd" , os == "linux" , os == "netbsd" , os == "openbsd" :
1114
- gt := cgoTest ("test- external-g0" , "test" , "external" , "" )
1157
+ gt := cgoTest ("external-g0" , "test" , "external" , "" )
1115
1158
gt .env = append (gt .env , "CGO_CFLAGS=-g0 -fdiagnostics-color" )
1116
1159
1117
- cgoTest ("testtls- auto" , "testtls" , "auto" , "" )
1118
- cgoTest ("testtls- external" , "testtls" , "external" , "" )
1160
+ cgoTest ("auto" , "testtls" , "auto" , "" )
1161
+ cgoTest ("external" , "testtls" , "external" , "" )
1119
1162
switch {
1120
1163
case os == "aix" :
1121
1164
// no static linking
@@ -1162,30 +1205,30 @@ func (t *tester) registerCgoTests(heading string) {
1162
1205
// Static linking tests
1163
1206
if goos != "android" && p != "netbsd/arm" {
1164
1207
// TODO(#56629): Why does this fail on netbsd-arm?
1165
- cgoTest ("testtls- static" , "testtls" , "external" , "static" , staticCheck )
1208
+ cgoTest ("static" , "testtls" , "external" , "static" , staticCheck )
1166
1209
}
1167
- cgoTest ("nocgo- auto" , "testnocgo" , "auto" , "" , staticCheck )
1168
- cgoTest ("nocgo- external" , "testnocgo" , "external" , "" , staticCheck )
1210
+ cgoTest ("auto" , "testnocgo" , "auto" , "" , staticCheck )
1211
+ cgoTest ("external" , "testnocgo" , "external" , "" , staticCheck )
1169
1212
if goos != "android" {
1170
- cgoTest ("nocgo- static" , "testnocgo" , "external" , "static" , staticCheck )
1171
- cgoTest ("test- static" , "test" , "external" , "static" , staticCheck )
1213
+ cgoTest ("static" , "testnocgo" , "external" , "static" , staticCheck )
1214
+ cgoTest ("static" , "test" , "external" , "static" , staticCheck )
1172
1215
// -static in CGO_LDFLAGS triggers a different code path
1173
1216
// than -static in -extldflags, so test both.
1174
1217
// See issue #16651.
1175
1218
if goarch != "loong64" {
1176
1219
// TODO(#56623): Why does this fail on loong64?
1177
- cgoTest ("test -static-env " , "test" , "auto" , "static" , staticCheck )
1220
+ cgoTest ("auto -static" , "test" , "auto" , "static" , staticCheck )
1178
1221
}
1179
1222
}
1180
1223
1181
1224
// PIE linking tests
1182
1225
if t .supportedBuildmode ("pie" ) && ! disablePIE {
1183
- cgoTest ("test -pie" , "test" , "auto" , "pie" )
1226
+ cgoTest ("auto -pie" , "test" , "auto" , "pie" )
1184
1227
if t .internalLink () && t .internalLinkPIE () {
1185
- cgoTest ("test -pie-internal " , "test" , "internal" , "pie" )
1228
+ cgoTest ("internal -pie" , "test" , "internal" , "pie" )
1186
1229
}
1187
- cgoTest ("testtls -pie" , "testtls" , "auto" , "pie" )
1188
- cgoTest ("nocgo -pie" , "testnocgo" , "auto" , "pie" )
1230
+ cgoTest ("auto -pie" , "testtls" , "auto" , "pie" )
1231
+ cgoTest ("auto -pie" , "testnocgo" , "auto" , "pie" )
1189
1232
}
1190
1233
}
1191
1234
}
@@ -1325,12 +1368,14 @@ func (t *tester) registerRaceTests() {
1325
1368
hdr := "Testing race detector"
1326
1369
t .registerTest ("race:runtime/race" , hdr ,
1327
1370
& goTest {
1371
+ variant : "race" ,
1328
1372
race : true ,
1329
1373
runTests : "Output" ,
1330
1374
pkg : "runtime/race" ,
1331
1375
})
1332
1376
t .registerTest ("race" , hdr ,
1333
1377
& goTest {
1378
+ variant : "race" ,
1334
1379
race : true ,
1335
1380
runTests : "TestParse|TestEcho|TestStdinCloseRace|TestClosedPipeRace|TestTypeRace|TestFdRace|TestFdReadRace|TestFileCloseRace" ,
1336
1381
pkgs : []string {"flag" , "net" , "os" , "os/exec" , "encoding/gob" },
@@ -1345,12 +1390,13 @@ func (t *tester) registerRaceTests() {
1345
1390
// There are already cgo-enabled packages being tested with the race detector.
1346
1391
// We shouldn't need to redo all of cmd/cgo/internal/test too.
1347
1392
// The race buildler will take care of this.
1348
- // t.registerTest("race:cmd/cgo/internal/test", hdr, &goTest{dir: "cmd/cgo/internal/test", race: true, env: []string{"GOTRACEBACK=2"}})
1393
+ // t.registerTest("race:cmd/cgo/internal/test", hdr, &goTest{variant:"race", dir: "cmd/cgo/internal/test", race: true, env: []string{"GOTRACEBACK=2"}})
1349
1394
}
1350
1395
if t .extLink () {
1351
1396
// Test with external linking; see issue 9133.
1352
1397
t .registerTest ("race:external" , hdr ,
1353
1398
& goTest {
1399
+ variant : "race-external" ,
1354
1400
race : true ,
1355
1401
ldflags : "-linkmode=external" ,
1356
1402
runTests : "TestParse|TestEcho|TestStdinCloseRace" ,
0 commit comments