Skip to content

Commit e3b3c01

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
go/pointer: break TestInput into subtests and update skips
TestInput is fiendishly slow and memory-hungry. Breaking it into subtests reveals that the vast majority of that cost can be attributed to a single test case: "testdata/a_test.go". Update the address-space-based skip to skip only that one input, skip it under the race detector (it is timing out on the new "linux-amd64-longtest-race" builder), and run the remaining inputs in parallel (to reduce test latency now that we've better identified the culprit). Updates golang/go#14113. Updates golang/go#54630. Change-Id: I105cfa173edc74692eaa41efd50ae08eeacf0d7d Reviewed-on: https://go-review.googlesource.com/c/tools/+/449518 TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 13648cd commit e3b3c01

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

go/pointer/pointer_race_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build race
6+
// +build race
7+
8+
package pointer_test
9+
10+
func init() {
11+
raceEnabled = true
12+
}

go/pointer/pointer_test.go

+28-19
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ var inputs = []string{
6666
// "testdata/timer.go", // TODO(adonovan): fix broken assumptions about runtime timers
6767
}
6868

69+
var raceEnabled = false
70+
6971
// Expectation grammar:
7072
//
7173
// @calls f -> g
@@ -609,10 +611,6 @@ func TestInput(t *testing.T) {
609611
if testing.Short() {
610612
t.Skip("skipping in short mode; this test requires tons of memory; https://golang.org/issue/14113")
611613
}
612-
if unsafe.Sizeof(unsafe.Pointer(nil)) <= 4 {
613-
t.Skip("skipping memory-intensive test on platform with small address space; https://golang.org/issue/14113")
614-
}
615-
ok := true
616614

617615
wd, err := os.Getwd()
618616
if err != nil {
@@ -627,23 +625,34 @@ func TestInput(t *testing.T) {
627625
fmt.Fprintf(os.Stderr, "Entering directory `%s'\n", wd)
628626

629627
for _, filename := range inputs {
630-
content, err := ioutil.ReadFile(filename)
631-
if err != nil {
632-
t.Errorf("couldn't read file '%s': %s", filename, err)
633-
continue
634-
}
628+
filename := filename
629+
t.Run(filename, func(t *testing.T) {
630+
if filename == "testdata/a_test.go" {
631+
// For some reason this particular file is way more expensive than the others.
632+
if unsafe.Sizeof(unsafe.Pointer(nil)) <= 4 {
633+
t.Skip("skipping memory-intensive test on platform with small address space; https://golang.org/issue/14113")
634+
}
635+
if raceEnabled {
636+
t.Skip("skipping memory-intensive test under race detector; https://golang.org/issue/14113")
637+
}
638+
} else {
639+
t.Parallel()
640+
}
635641

636-
fpath, err := filepath.Abs(filename)
637-
if err != nil {
638-
t.Errorf("couldn't get absolute path for '%s': %s", filename, err)
639-
}
642+
content, err := ioutil.ReadFile(filename)
643+
if err != nil {
644+
t.Fatalf("couldn't read file '%s': %s", filename, err)
645+
}
640646

641-
if !doOneInput(t, string(content), fpath) {
642-
ok = false
643-
}
644-
}
645-
if !ok {
646-
t.Fail()
647+
fpath, err := filepath.Abs(filename)
648+
if err != nil {
649+
t.Fatalf("couldn't get absolute path for '%s': %s", filename, err)
650+
}
651+
652+
if !doOneInput(t, string(content), fpath) {
653+
t.Fail()
654+
}
655+
})
647656
}
648657
}
649658

0 commit comments

Comments
 (0)