Skip to content

Commit 311ec03

Browse files
author
Bryan C. Mills
committed
all: skip more memory-intensive tests on linux-arm
Updates golang/go#32834 Change-Id: I9844dc09d9a6eb2e79a0b28a1e69ed018bfa1bff Reviewed-on: https://go-review.googlesource.com/c/tools/+/192578 Run-TryBot: Bryan C. Mills <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent df13fa7 commit 311ec03

File tree

8 files changed

+44
-16
lines changed

8 files changed

+44
-16
lines changed

go/internal/gcimporter/gcimporter_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import (
2323
"golang.org/x/tools/internal/testenv"
2424
)
2525

26+
func TestMain(m *testing.M) {
27+
testenv.ExitIfSmallMachine()
28+
os.Exit(m.Run())
29+
}
30+
2631
// ----------------------------------------------------------------------------
2732
// The following three functions (Builder, HasGoBuild, MustHaveGoBuild) were
2833
// copied from $GOROOT/src/internal/testenv since that package is not available

go/loader/loader_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"go/build"
1414
"go/constant"
1515
"go/types"
16+
"os"
1617
"path/filepath"
1718
"reflect"
1819
"runtime"
@@ -23,8 +24,14 @@ import (
2324

2425
"golang.org/x/tools/go/buildutil"
2526
"golang.org/x/tools/go/loader"
27+
"golang.org/x/tools/internal/testenv"
2628
)
2729

30+
func TestMain(m *testing.M) {
31+
testenv.ExitIfSmallMachine()
32+
os.Exit(m.Run())
33+
}
34+
2835
// TestFromArgs checks that conf.FromArgs populates conf correctly.
2936
// It does no I/O.
3037
func TestFromArgs(t *testing.T) {

go/packages/packages_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ import (
2828
)
2929

3030
func TestMain(m *testing.M) {
31-
if os.Getenv("GO_BUILDER_NAME") == "linux-arm" {
32-
fmt.Fprintf(os.Stderr, "skipping test: linux-arm builder lacks sufficient memory (https://golang.org/issue/32834)\n")
33-
os.Exit(0)
34-
}
35-
31+
testenv.ExitIfSmallMachine()
3632
os.Exit(m.Run())
3733
}
3834

internal/imports/imports_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ package imports
22

33
import (
44
"go/build"
5+
"os"
56
"testing"
7+
8+
"golang.org/x/tools/internal/testenv"
69
)
710

11+
func TestMain(m *testing.M) {
12+
testenv.ExitIfSmallMachine()
13+
os.Exit(m.Run())
14+
}
15+
816
// TestNilOpts tests that process does not crash with nil opts.
917
func TestNilOpts(t *testing.T) {
1018
var testOpts = []struct {

internal/lsp/cmd/cmd_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package cmd_test
77
import (
88
"bytes"
99
"context"
10-
"fmt"
1110
"io/ioutil"
1211
"os"
1312
"path/filepath"
@@ -17,14 +16,11 @@ import (
1716

1817
"golang.org/x/tools/go/packages/packagestest"
1918
"golang.org/x/tools/internal/lsp/tests"
19+
"golang.org/x/tools/internal/testenv"
2020
)
2121

2222
func TestMain(m *testing.M) {
23-
if os.Getenv("GO_BUILDER_NAME") == "linux-arm" {
24-
fmt.Fprintf(os.Stderr, "skipping test: linux-arm builder lacks sufficient memory (https://golang.org/issue/32834)\n")
25-
os.Exit(0)
26-
}
27-
23+
testenv.ExitIfSmallMachine()
2824
os.Exit(m.Run())
2925
}
3026

internal/lsp/lsp_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ import (
2323
"golang.org/x/tools/internal/lsp/source"
2424
"golang.org/x/tools/internal/lsp/tests"
2525
"golang.org/x/tools/internal/span"
26+
"golang.org/x/tools/internal/testenv"
2627
)
2728

2829
func TestMain(m *testing.M) {
29-
if os.Getenv("GO_BUILDER_NAME") == "linux-arm" {
30-
fmt.Fprintf(os.Stderr, "skipping test: linux-arm builder lacks sufficient memory (https://golang.org/issue/32834)\n")
31-
os.Exit(0)
32-
}
33-
30+
testenv.ExitIfSmallMachine()
3431
os.Exit(m.Run())
3532
}
3633

internal/lsp/source/source_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bytes"
99
"context"
1010
"fmt"
11+
"os"
1112
"os/exec"
1213
"path/filepath"
1314
"sort"
@@ -22,8 +23,14 @@ import (
2223
"golang.org/x/tools/internal/lsp/source"
2324
"golang.org/x/tools/internal/lsp/tests"
2425
"golang.org/x/tools/internal/span"
26+
"golang.org/x/tools/internal/testenv"
2527
)
2628

29+
func TestMain(m *testing.M) {
30+
testenv.ExitIfSmallMachine()
31+
os.Exit(m.Run())
32+
}
33+
2734
func TestSource(t *testing.T) {
2835
packagestest.TestAll(t, testSource)
2936
}

internal/testenv/testenv.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package testenv
88

99
import (
10+
"fmt"
1011
"os"
1112
"os/exec"
1213
"runtime"
@@ -106,3 +107,14 @@ func NeedsGoPackagesEnv(t Testing, env []string) {
106107

107108
NeedsGoPackages(t)
108109
}
110+
111+
// ExitIfSmallMachine emits a helpful diagnostic and calls os.Exit(0) if the
112+
// current machine is a builder known to have scarce resources.
113+
//
114+
// It should be called from within a TestMain function.
115+
func ExitIfSmallMachine() {
116+
if os.Getenv("GO_BUILDER_NAME") == "linux-arm" {
117+
fmt.Fprintln(os.Stderr, "skipping test: linux-arm builder lacks sufficient memory (https://golang.org/issue/32834)")
118+
os.Exit(0)
119+
}
120+
}

0 commit comments

Comments
 (0)