Skip to content

Commit 06b0bab

Browse files
committed
all: shorten some tests
Shorten some of the longest tests that run during all.bash. Removes 7r 50u 21s from all.bash. After this change, all.bash is under 5 minutes again on my laptop. For #26473. Change-Id: Ie0460aa935808d65460408feaed210fbaa1d5d79 Reviewed-on: https://go-review.googlesource.com/c/go/+/177559 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b0e238a commit 06b0bab

File tree

41 files changed

+207
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+207
-77
lines changed

src/archive/zip/zip_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"errors"
1212
"fmt"
1313
"hash"
14-
"internal/race"
1514
"internal/testenv"
1615
"io"
1716
"io/ioutil"
@@ -309,7 +308,7 @@ func TestZip64EdgeCase(t *testing.T) {
309308
// Tests that we generate a zip64 file if the directory at offset
310309
// 0xFFFFFFFF, but not before.
311310
func TestZip64DirectoryOffset(t *testing.T) {
312-
if testing.Short() && race.Enabled {
311+
if testing.Short() {
313312
t.Skip("skipping in short mode")
314313
}
315314
t.Parallel()
@@ -354,7 +353,7 @@ func TestZip64DirectoryOffset(t *testing.T) {
354353

355354
// At 16k records, we need to generate a zip64 file.
356355
func TestZip64ManyRecords(t *testing.T) {
357-
if testing.Short() && race.Enabled {
356+
if testing.Short() {
358357
t.Skip("skipping in short mode")
359358
}
360359
t.Parallel()

src/cmd/dist/test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,9 @@ func (t *tester) registerTests() {
551551
name: "nolibgcc:" + pkg,
552552
heading: "Testing without libgcc.",
553553
fn: func(dt *distTest) error {
554-
t.addCmd(dt, "src", t.goTest(), "-ldflags=-linkmode=internal -libgcc=none", pkg, t.runFlag(run))
554+
// What matters is that the tests build and start up.
555+
// Skip expensive tests, especially x509 TestSystemRoots.
556+
t.addCmd(dt, "src", t.goTest(), "-ldflags=-linkmode=internal -libgcc=none", "-run=^Test[^CS]", pkg, t.runFlag(run))
555557
return nil
556558
},
557559
})
@@ -693,7 +695,10 @@ func (t *tester) registerTests() {
693695
}
694696

695697
if goos != "android" && !t.iOS() {
696-
t.registerTest("bench_go1", "../test/bench/go1", t.goTest(), t.timeout(600))
698+
// There are no tests in this directory, only benchmarks.
699+
// Check that the test binary builds but don't bother running it.
700+
// (It has init-time work to set up for the benchmarks that is not worth doing unnecessarily.)
701+
t.registerTest("bench_go1", "../test/bench/go1", t.goTest(), "-c", "-o="+os.DevNull)
697702
}
698703
if goos != "android" && !t.iOS() {
699704
// Only start multiple test dir shards on builders,
@@ -1292,8 +1297,12 @@ func (t *tester) raceTest(dt *distTest) error {
12921297
// TODO(iant): Figure out how to catch this.
12931298
// t.addCmd(dt, "src", t.goTest(), "-race", "-run=TestParallelTest", "cmd/go")
12941299
if t.cgoEnabled {
1295-
cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-race")
1296-
cmd.Env = append(os.Environ(), "GOTRACEBACK=2")
1300+
// Building misc/cgo/test takes a long time.
1301+
// There are already cgo-enabled packages being tested with the race detector.
1302+
// We shouldn't need to redo all of misc/cgo/test too.
1303+
// The race buildler will take care of this.
1304+
// cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-race")
1305+
// cmd.Env = append(os.Environ(), "GOTRACEBACK=2")
12971306
}
12981307
if t.extLink() {
12991308
// Test with external linking; see issue 9133.

src/cmd/go/internal/cache/cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestGrowth(t *testing.T) {
7878

7979
n := 10000
8080
if testing.Short() {
81-
n = 1000
81+
n = 10
8282
}
8383

8484
for i := 0; i < n; i++ {

src/cmd/internal/obj/x86/pcrelative_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ LOOP:
9696
for idx := len(data) - 1; idx >= 0; idx-- {
9797
// check that RET wasn't overwritten.
9898
if bytes.Index(data[idx], []byte("RET")) != -1 {
99+
if testing.Short() {
100+
break LOOP
101+
}
99102
continue LOOP
100103
}
101104
}

src/cmd/link/dwarf_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string)
165165

166166
func TestDWARF(t *testing.T) {
167167
testDWARF(t, "", true)
168-
if runtime.GOOS == "darwin" {
169-
testDWARF(t, "c-archive", true)
168+
if runtime.GOOS == "darwin" && !testing.Short() {
169+
t.Run("c-archive", func(t *testing.T) {
170+
testDWARF(t, "c-archive", true)
171+
})
170172
}
171173
}
172174

src/cmd/link/link_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,17 @@ main.x: relocation target main.zero not defined
170170
}
171171
}
172172

173-
func TestBuildFortvOS(t *testing.T) {
173+
func TestBuildForTvOS(t *testing.T) {
174174
testenv.MustHaveCGO(t)
175175
testenv.MustHaveGoBuild(t)
176176

177177
// Only run this on darwin/amd64, where we can cross build for tvOS.
178178
if runtime.GOARCH != "amd64" || runtime.GOOS != "darwin" {
179179
t.Skip("skipping on non-darwin/amd64 platform")
180180
}
181+
if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" {
182+
t.Skip("skipping in -short mode with $GO_BUILDER_NAME empty")
183+
}
181184
if err := exec.Command("xcrun", "--help").Run(); err != nil {
182185
t.Skipf("error running xcrun, required for iOS cross build: %v", err)
183186
}

src/cmd/pack/pack_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ func TestHello(t *testing.T) {
231231

232232
// Test that pack works with very long lines in PKGDEF.
233233
func TestLargeDefs(t *testing.T) {
234+
if testing.Short() {
235+
t.Skip("skipping in -short mode")
236+
}
234237
testenv.MustHaveGoBuild(t)
235238

236239
dir := tmpDir(t)

src/compress/flate/deflate_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ func testToFromWithLimit(t *testing.T, input []byte, name string, limit [11]int)
345345
func TestDeflateInflate(t *testing.T) {
346346
t.Parallel()
347347
for i, h := range deflateInflateTests {
348+
if testing.Short() && len(h.in) > 10000 {
349+
continue
350+
}
348351
testToFromWithLimit(t, h.in, fmt.Sprintf("#%d", i), [11]int{})
349352
}
350353
}
@@ -591,6 +594,9 @@ func TestBestSpeed(t *testing.T) {
591594
}
592595

593596
for i, tc := range testCases {
597+
if i >= 3 && testing.Short() {
598+
break
599+
}
594600
for _, firstN := range []int{1, 65534, 65535, 65536, 65537, 131072} {
595601
tc[0] = firstN
596602
outer:

src/container/ring/ring_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func TestLink2(t *testing.T) {
179179
func TestLink3(t *testing.T) {
180180
var r Ring
181181
n := 1
182-
for i := 1; i < 100; i++ {
182+
for i := 1; i < 10; i++ {
183183
n += i
184184
verify(t, r.Link(New(i)), n, -1)
185185
}

src/crypto/cipher/xor_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ func TestXOR(t *testing.T) {
2020
testenv.SkipFlaky(t, 31812)
2121
}
2222
for j := 1; j <= 1024; j++ {
23+
if testing.Short() && j > 16 {
24+
break
25+
}
2326
for alignP := 0; alignP < 2; alignP++ {
2427
for alignQ := 0; alignQ < 2; alignQ++ {
2528
for alignD := 0; alignD < 2; alignD++ {

src/crypto/elliptic/fuzz_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestFuzz(t *testing.T) {
2222
var timeout *time.Timer
2323

2424
if testing.Short() {
25-
timeout = time.NewTimer(500 * time.Millisecond)
25+
timeout = time.NewTimer(10 * time.Millisecond)
2626
} else {
2727
timeout = time.NewTimer(2 * time.Second)
2828
}

src/crypto/rand/util_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func TestIntMask(t *testing.T) {
8484
for max := 1; max <= 256; max++ {
8585
t.Run(fmt.Sprintf("max=%d", max), func(t *testing.T) {
8686
for i := 0; i < max; i++ {
87+
if testing.Short() && i == 0 {
88+
i = max - 1
89+
}
8790
var b bytes.Buffer
8891
b.WriteByte(byte(i))
8992
n, err := rand.Int(&b, big.NewInt(int64(max)))

src/crypto/tls/handshake_client_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,9 @@ func TestResumption(t *testing.T) {
880880
}
881881

882882
func testResumption(t *testing.T, version uint16) {
883+
if testing.Short() {
884+
t.Skip("skipping in -short mode")
885+
}
883886
serverConfig := &Config{
884887
MaxVersion: version,
885888
CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA},
@@ -1727,6 +1730,9 @@ func TestAlertFlushing(t *testing.T) {
17271730
}
17281731

17291732
func TestHandshakeRace(t *testing.T) {
1733+
if testing.Short() {
1734+
t.Skip("skipping in -short mode")
1735+
}
17301736
t.Parallel()
17311737
// This test races a Read and Write to try and complete a handshake in
17321738
// order to provide some evidence that there are no races or deadlocks

src/crypto/x509/x509_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,9 @@ func TestParsePEMCRL(t *testing.T) {
12431243
}
12441244

12451245
func TestImports(t *testing.T) {
1246+
if testing.Short() {
1247+
t.Skip("skipping in -short mode")
1248+
}
12461249
testenv.MustHaveGoRun(t)
12471250

12481251
if out, err := exec.Command(testenv.GoToolPath(t), "run", "x509_test_import.go").CombinedOutput(); err != nil {

src/debug/gosym/pclntab_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ func TestLineAline(t *testing.T) {
196196
}
197197

198198
func TestPCLine(t *testing.T) {
199+
if testing.Short() {
200+
t.Skip("skipping in -short mode")
201+
}
199202
dotest(t)
200203
defer endtest()
201204

src/encoding/json/encode_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,9 @@ func TestStringBytes(t *testing.T) {
580580
// Test that encodeState.stringBytes and encodeState.string use the same encoding.
581581
var r []rune
582582
for i := '\u0000'; i <= unicode.MaxRune; i++ {
583+
if testing.Short() && i > 1000 {
584+
i = unicode.MaxRune
585+
}
583586
r = append(r, i)
584587
}
585588
s := string(r) + "\xff\xff\xffhello" // some invalid UTF-8 too
@@ -864,6 +867,9 @@ func TestMarshalFloat(t *testing.T) {
864867

865868
var digits = "1.2345678901234567890123"
866869
for i := len(digits); i >= 2; i-- {
870+
if testing.Short() && i < len(digits)-4 {
871+
break
872+
}
867873
for exp := -30; exp <= 30; exp++ {
868874
for _, sign := range "+-" {
869875
for bits := 32; bits <= 64; bits += 32 {

src/go/internal/srcimporter/srcimporter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ func TestImportStdLib(t *testing.T) {
8181
t.Skip("no source code available")
8282
}
8383

84-
dt := maxTime
8584
if testing.Short() && testenv.Builder() == "" {
86-
dt = 500 * time.Millisecond
85+
t.Skip("skipping in -short mode")
8786
}
87+
dt := maxTime
8888
nimports, _ := walkDir(t, "", time.Now().Add(dt)) // installed packages
8989
t.Logf("tested %d imports", nimports)
9090
}

src/internal/trace/gc_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func TestMMU(t *testing.T) {
7979
func TestMMUTrace(t *testing.T) {
8080
// Can't be t.Parallel() because it modifies the
8181
// testingOneBand package variable.
82+
if testing.Short() {
83+
// test input too big for all.bash
84+
t.Skip("skipping in -short mode")
85+
}
8286

8387
data, err := ioutil.ReadFile("testdata/stress_1_10_good")
8488
if err != nil {

src/internal/trace/parser_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package trace
77
import (
88
"bytes"
99
"io/ioutil"
10+
"os"
1011
"path/filepath"
1112
"strings"
1213
"testing"
@@ -38,9 +39,17 @@ func TestParseCanned(t *testing.T) {
3839
t.Fatalf("failed to read ./testdata: %v", err)
3940
}
4041
for _, f := range files {
41-
data, err := ioutil.ReadFile(filepath.Join("./testdata", f.Name()))
42+
name := filepath.Join("./testdata", f.Name())
43+
info, err := os.Stat(name)
4244
if err != nil {
43-
t.Fatalf("failed to read input file: %v", err)
45+
t.Fatal(err)
46+
}
47+
if testing.Short() && info.Size() > 10000 {
48+
continue
49+
}
50+
data, err := ioutil.ReadFile(name)
51+
if err != nil {
52+
t.Fatal(err)
4453
}
4554
// Instead of Parse that requires a proper binary name for old traces,
4655
// we use 'parse' that omits symbol lookup if an empty string is given.

src/math/big/floatmarsh_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ func TestFloatJSONEncoding(t *testing.T) {
109109
for _, test := range floatVals {
110110
for _, sign := range []string{"", "+", "-"} {
111111
for _, prec := range []uint{0, 1, 2, 10, 53, 64, 100, 1000} {
112+
if prec > 53 && testing.Short() {
113+
continue
114+
}
112115
x := sign + test
113116
var tx Float
114117
_, _, err := tx.SetPrec(prec).Parse(x, 0)

src/math/big/natconv_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ func TestStringPowers(t *testing.T) {
446446
var p Word
447447
for b := 2; b <= 16; b++ {
448448
for p = 0; p <= 512; p++ {
449+
if testing.Short() && p > 10 {
450+
break
451+
}
449452
x := nat(nil).expWW(Word(b), p)
450453
xs := x.utoa(b)
451454
xs2 := itoa(x, b)

src/math/big/prime_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,19 @@ func cutSpace(r rune) rune {
125125
func TestProbablyPrime(t *testing.T) {
126126
nreps := 20
127127
if testing.Short() {
128-
nreps = 3
128+
nreps = 1
129129
}
130130
for i, s := range primes {
131131
p, _ := new(Int).SetString(s, 10)
132-
if !p.ProbablyPrime(nreps) || !p.ProbablyPrime(1) || !p.ProbablyPrime(0) {
132+
if !p.ProbablyPrime(nreps) || nreps != 1 && !p.ProbablyPrime(1) || !p.ProbablyPrime(0) {
133133
t.Errorf("#%d prime found to be non-prime (%s)", i, s)
134134
}
135135
}
136136

137137
for i, s := range composites {
138138
s = strings.Map(cutSpace, s)
139139
c, _ := new(Int).SetString(s, 10)
140-
if c.ProbablyPrime(nreps) || c.ProbablyPrime(1) || c.ProbablyPrime(0) {
140+
if c.ProbablyPrime(nreps) || nreps != 1 && c.ProbablyPrime(1) || c.ProbablyPrime(0) {
141141
t.Errorf("#%d composite found to be prime (%s)", i, s)
142142
}
143143
}
@@ -197,6 +197,14 @@ func TestLucasPseudoprimes(t *testing.T) {
197197
func testPseudoprimes(t *testing.T, name string, cond func(nat) bool, want []int) {
198198
n := nat{1}
199199
for i := 3; i < 100000; i += 2 {
200+
if testing.Short() {
201+
if len(want) == 0 {
202+
break
203+
}
204+
if i < want[0]-2 {
205+
i = want[0] - 2
206+
}
207+
}
200208
n[0] = Word(i)
201209
pseudo := cond(n)
202210
if pseudo && (len(want) == 0 || i != want[0]) {

src/math/big/sqrt_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import (
1515
// behaves like float math.Sqrt.
1616
func TestFloatSqrt64(t *testing.T) {
1717
for i := 0; i < 1e5; i++ {
18+
if i == 1e2 && testing.Short() {
19+
break
20+
}
1821
r := rand.Float64()
1922

2023
got := new(Float).SetPrec(53)

src/math/rand/rand_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ func TestUniformFactorial(t *testing.T) {
486486
r := New(NewSource(testSeeds[0]))
487487
top := 6
488488
if testing.Short() {
489-
top = 4
489+
top = 3
490490
}
491491
for n := 3; n <= top; n++ {
492492
t.Run(fmt.Sprintf("n=%d", n), func(t *testing.T) {

src/mime/multipart/formdata_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ func (r *failOnReadAfterErrorReader) Read(p []byte) (n int, err error) {
176176
// TestReadForm_NonFileMaxMemory asserts that the ReadForm maxMemory limit is applied
177177
// while processing non-file form data as well as file form data.
178178
func TestReadForm_NonFileMaxMemory(t *testing.T) {
179-
largeTextValue := strings.Repeat("1", (10<<20)+25)
179+
n := 10<<20 + 25
180+
if testing.Short() {
181+
n = 10<<10 + 25
182+
}
183+
largeTextValue := strings.Repeat("1", n)
180184
message := `--MyBoundary
181185
Content-Disposition: form-data; name="largetext"
182186
@@ -196,6 +200,9 @@ Content-Disposition: form-data; name="largetext"
196200
}
197201
for _, tc := range testCases {
198202
t.Run(tc.name, func(t *testing.T) {
203+
if tc.maxMemory == 0 && testing.Short() {
204+
t.Skip("skipping in -short mode")
205+
}
199206
b := strings.NewReader(testBody)
200207
r := NewReader(b, boundary)
201208
f, err := r.ReadForm(tc.maxMemory)

0 commit comments

Comments
 (0)