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 <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
"errors"
"fmt"
"hash"
- "internal/race"
"internal/testenv"
"io"
"io/ioutil"
// Tests that we generate a zip64 file if the directory at offset
// 0xFFFFFFFF, but not before.
func TestZip64DirectoryOffset(t *testing.T) {
- if testing.Short() && race.Enabled {
+ if testing.Short() {
t.Skip("skipping in short mode")
}
t.Parallel()
// At 16k records, we need to generate a zip64 file.
func TestZip64ManyRecords(t *testing.T) {
- if testing.Short() && race.Enabled {
+ if testing.Short() {
t.Skip("skipping in short mode")
}
t.Parallel()
name: "nolibgcc:" + pkg,
heading: "Testing without libgcc.",
fn: func(dt *distTest) error {
- t.addCmd(dt, "src", t.goTest(), "-ldflags=-linkmode=internal -libgcc=none", pkg, t.runFlag(run))
+ // What matters is that the tests build and start up.
+ // Skip expensive tests, especially x509 TestSystemRoots.
+ t.addCmd(dt, "src", t.goTest(), "-ldflags=-linkmode=internal -libgcc=none", "-run=^Test[^CS]", pkg, t.runFlag(run))
return nil
},
})
}
if goos != "android" && !t.iOS() {
- t.registerTest("bench_go1", "../test/bench/go1", t.goTest(), t.timeout(600))
+ // There are no tests in this directory, only benchmarks.
+ // Check that the test binary builds but don't bother running it.
+ // (It has init-time work to set up for the benchmarks that is not worth doing unnecessarily.)
+ t.registerTest("bench_go1", "../test/bench/go1", t.goTest(), "-c", "-o="+os.DevNull)
}
if goos != "android" && !t.iOS() {
// Only start multiple test dir shards on builders,
// TODO(iant): Figure out how to catch this.
// t.addCmd(dt, "src", t.goTest(), "-race", "-run=TestParallelTest", "cmd/go")
if t.cgoEnabled {
- cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-race")
- cmd.Env = append(os.Environ(), "GOTRACEBACK=2")
+ // Building misc/cgo/test takes a long time.
+ // There are already cgo-enabled packages being tested with the race detector.
+ // We shouldn't need to redo all of misc/cgo/test too.
+ // The race buildler will take care of this.
+ // cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-race")
+ // cmd.Env = append(os.Environ(), "GOTRACEBACK=2")
}
if t.extLink() {
// Test with external linking; see issue 9133.
n := 10000
if testing.Short() {
- n = 1000
+ n = 10
}
for i := 0; i < n; i++ {
for idx := len(data) - 1; idx >= 0; idx-- {
// check that RET wasn't overwritten.
if bytes.Index(data[idx], []byte("RET")) != -1 {
+ if testing.Short() {
+ break LOOP
+ }
continue LOOP
}
}
func TestDWARF(t *testing.T) {
testDWARF(t, "", true)
- if runtime.GOOS == "darwin" {
- testDWARF(t, "c-archive", true)
+ if runtime.GOOS == "darwin" && !testing.Short() {
+ t.Run("c-archive", func(t *testing.T) {
+ testDWARF(t, "c-archive", true)
+ })
}
}
}
}
-func TestBuildFortvOS(t *testing.T) {
+func TestBuildForTvOS(t *testing.T) {
testenv.MustHaveCGO(t)
testenv.MustHaveGoBuild(t)
if runtime.GOARCH != "amd64" || runtime.GOOS != "darwin" {
t.Skip("skipping on non-darwin/amd64 platform")
}
+ if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" {
+ t.Skip("skipping in -short mode with $GO_BUILDER_NAME empty")
+ }
if err := exec.Command("xcrun", "--help").Run(); err != nil {
t.Skipf("error running xcrun, required for iOS cross build: %v", err)
}
// Test that pack works with very long lines in PKGDEF.
func TestLargeDefs(t *testing.T) {
+ if testing.Short() {
+ t.Skip("skipping in -short mode")
+ }
testenv.MustHaveGoBuild(t)
dir := tmpDir(t)
func TestDeflateInflate(t *testing.T) {
t.Parallel()
for i, h := range deflateInflateTests {
+ if testing.Short() && len(h.in) > 10000 {
+ continue
+ }
testToFromWithLimit(t, h.in, fmt.Sprintf("#%d", i), [11]int{})
}
}
}
for i, tc := range testCases {
+ if i >= 3 && testing.Short() {
+ break
+ }
for _, firstN := range []int{1, 65534, 65535, 65536, 65537, 131072} {
tc[0] = firstN
outer:
func TestLink3(t *testing.T) {
var r Ring
n := 1
- for i := 1; i < 100; i++ {
+ for i := 1; i < 10; i++ {
n += i
verify(t, r.Link(New(i)), n, -1)
}
testenv.SkipFlaky(t, 31812)
}
for j := 1; j <= 1024; j++ {
+ if testing.Short() && j > 16 {
+ break
+ }
for alignP := 0; alignP < 2; alignP++ {
for alignQ := 0; alignQ < 2; alignQ++ {
for alignD := 0; alignD < 2; alignD++ {
var timeout *time.Timer
if testing.Short() {
- timeout = time.NewTimer(500 * time.Millisecond)
+ timeout = time.NewTimer(10 * time.Millisecond)
} else {
timeout = time.NewTimer(2 * time.Second)
}
for max := 1; max <= 256; max++ {
t.Run(fmt.Sprintf("max=%d", max), func(t *testing.T) {
for i := 0; i < max; i++ {
+ if testing.Short() && i == 0 {
+ i = max - 1
+ }
var b bytes.Buffer
b.WriteByte(byte(i))
n, err := rand.Int(&b, big.NewInt(int64(max)))
}
func testResumption(t *testing.T, version uint16) {
+ if testing.Short() {
+ t.Skip("skipping in -short mode")
+ }
serverConfig := &Config{
MaxVersion: version,
CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA},
}
func TestHandshakeRace(t *testing.T) {
+ if testing.Short() {
+ t.Skip("skipping in -short mode")
+ }
t.Parallel()
// This test races a Read and Write to try and complete a handshake in
// order to provide some evidence that there are no races or deadlocks
}
func TestImports(t *testing.T) {
+ if testing.Short() {
+ t.Skip("skipping in -short mode")
+ }
testenv.MustHaveGoRun(t)
if out, err := exec.Command(testenv.GoToolPath(t), "run", "x509_test_import.go").CombinedOutput(); err != nil {
}
func TestPCLine(t *testing.T) {
+ if testing.Short() {
+ t.Skip("skipping in -short mode")
+ }
dotest(t)
defer endtest()
// Test that encodeState.stringBytes and encodeState.string use the same encoding.
var r []rune
for i := '\u0000'; i <= unicode.MaxRune; i++ {
+ if testing.Short() && i > 1000 {
+ i = unicode.MaxRune
+ }
r = append(r, i)
}
s := string(r) + "\xff\xff\xffhello" // some invalid UTF-8 too
var digits = "1.2345678901234567890123"
for i := len(digits); i >= 2; i-- {
+ if testing.Short() && i < len(digits)-4 {
+ break
+ }
for exp := -30; exp <= 30; exp++ {
for _, sign := range "+-" {
for bits := 32; bits <= 64; bits += 32 {
t.Skip("no source code available")
}
- dt := maxTime
if testing.Short() && testenv.Builder() == "" {
- dt = 500 * time.Millisecond
+ t.Skip("skipping in -short mode")
}
+ dt := maxTime
nimports, _ := walkDir(t, "", time.Now().Add(dt)) // installed packages
t.Logf("tested %d imports", nimports)
}
func TestMMUTrace(t *testing.T) {
// Can't be t.Parallel() because it modifies the
// testingOneBand package variable.
+ if testing.Short() {
+ // test input too big for all.bash
+ t.Skip("skipping in -short mode")
+ }
data, err := ioutil.ReadFile("testdata/stress_1_10_good")
if err != nil {
import (
"bytes"
"io/ioutil"
+ "os"
"path/filepath"
"strings"
"testing"
t.Fatalf("failed to read ./testdata: %v", err)
}
for _, f := range files {
- data, err := ioutil.ReadFile(filepath.Join("./testdata", f.Name()))
+ name := filepath.Join("./testdata", f.Name())
+ info, err := os.Stat(name)
if err != nil {
- t.Fatalf("failed to read input file: %v", err)
+ t.Fatal(err)
+ }
+ if testing.Short() && info.Size() > 10000 {
+ continue
+ }
+ data, err := ioutil.ReadFile(name)
+ if err != nil {
+ t.Fatal(err)
}
// Instead of Parse that requires a proper binary name for old traces,
// we use 'parse' that omits symbol lookup if an empty string is given.
for _, test := range floatVals {
for _, sign := range []string{"", "+", "-"} {
for _, prec := range []uint{0, 1, 2, 10, 53, 64, 100, 1000} {
+ if prec > 53 && testing.Short() {
+ continue
+ }
x := sign + test
var tx Float
_, _, err := tx.SetPrec(prec).Parse(x, 0)
var p Word
for b := 2; b <= 16; b++ {
for p = 0; p <= 512; p++ {
+ if testing.Short() && p > 10 {
+ break
+ }
x := nat(nil).expWW(Word(b), p)
xs := x.utoa(b)
xs2 := itoa(x, b)
func TestProbablyPrime(t *testing.T) {
nreps := 20
if testing.Short() {
- nreps = 3
+ nreps = 1
}
for i, s := range primes {
p, _ := new(Int).SetString(s, 10)
- if !p.ProbablyPrime(nreps) || !p.ProbablyPrime(1) || !p.ProbablyPrime(0) {
+ if !p.ProbablyPrime(nreps) || nreps != 1 && !p.ProbablyPrime(1) || !p.ProbablyPrime(0) {
t.Errorf("#%d prime found to be non-prime (%s)", i, s)
}
}
for i, s := range composites {
s = strings.Map(cutSpace, s)
c, _ := new(Int).SetString(s, 10)
- if c.ProbablyPrime(nreps) || c.ProbablyPrime(1) || c.ProbablyPrime(0) {
+ if c.ProbablyPrime(nreps) || nreps != 1 && c.ProbablyPrime(1) || c.ProbablyPrime(0) {
t.Errorf("#%d composite found to be prime (%s)", i, s)
}
}
func testPseudoprimes(t *testing.T, name string, cond func(nat) bool, want []int) {
n := nat{1}
for i := 3; i < 100000; i += 2 {
+ if testing.Short() {
+ if len(want) == 0 {
+ break
+ }
+ if i < want[0]-2 {
+ i = want[0] - 2
+ }
+ }
n[0] = Word(i)
pseudo := cond(n)
if pseudo && (len(want) == 0 || i != want[0]) {
// behaves like float math.Sqrt.
func TestFloatSqrt64(t *testing.T) {
for i := 0; i < 1e5; i++ {
+ if i == 1e2 && testing.Short() {
+ break
+ }
r := rand.Float64()
got := new(Float).SetPrec(53)
r := New(NewSource(testSeeds[0]))
top := 6
if testing.Short() {
- top = 4
+ top = 3
}
for n := 3; n <= top; n++ {
t.Run(fmt.Sprintf("n=%d", n), func(t *testing.T) {
// TestReadForm_NonFileMaxMemory asserts that the ReadForm maxMemory limit is applied
// while processing non-file form data as well as file form data.
func TestReadForm_NonFileMaxMemory(t *testing.T) {
- largeTextValue := strings.Repeat("1", (10<<20)+25)
+ n := 10<<20 + 25
+ if testing.Short() {
+ n = 10<<10 + 25
+ }
+ largeTextValue := strings.Repeat("1", n)
message := `--MyBoundary
Content-Disposition: form-data; name="largetext"
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
+ if tc.maxMemory == 0 && testing.Short() {
+ t.Skip("skipping in -short mode")
+ }
b := strings.NewReader(testBody)
r := NewReader(b, boundary)
f, err := r.ReadForm(tc.maxMemory)
func TestParseAllSizes(t *testing.T) {
t.Parallel()
- const maxSize = 5 << 10
+ maxSize := 5 << 10
+ if testing.Short() {
+ maxSize = 512
+ }
var buf bytes.Buffer
body := strings.Repeat("a", maxSize)
bodyb := []byte(body)
var buf bytes.Buffer
res := make(map[string]int)
- everySequence("", "0A \r\n=", 6, func(s string) {
+ n := 6
+ if testing.Short() {
+ n = 4
+ }
+ everySequence("", "0A \r\n=", n, func(s string) {
if strings.HasSuffix(s, "=") || strings.Contains(s, "==") {
return
}
invalid bytes after =: 3949
quotedprintable: invalid hex byte 0x0d: 2048
unexpected EOF: 194`
+ if testing.Short() {
+ want = `OK: 896
+invalid bytes after =: 100
+quotedprintable: invalid hex byte 0x0d: 26
+unexpected EOF: 3`
+ }
+
if got != want {
t.Errorf("Got:\n%s\nWant:\n%s", got, want)
}
setParallel(t)
defer afterTest(t)
- const goroutines = 5
- const requests = 2000
+ goroutines := 5
+ requests := 2000
+ if testing.Short() {
+ goroutines = 3
+ requests = 100
+ }
hts := httptest.NewServer(HandlerFunc(NotFound))
defer hts.Close()
}
for i := 0; i < 10; i++ {
+ if testing.Short() && i >= 3 {
+ break
+ }
la := listen()
ca := helperCommand(t, "describefiles")
ca.ExtraFiles = []*os.File{listenerFile(la)}
}
func TestXadduintptr(t *testing.T) {
- const N = 20
- const iter = 100000
+ N := 20
+ iter := 100000
+ if testing.Short() {
+ N = 10
+ iter = 10000
+ }
inc := uintptr(100)
total := uintptr(0)
runParallel(N, iter, func() {
atomic.Xadduintptr(&total, inc)
})
- if want := uintptr(N * iter * inc); want != total {
+ if want := uintptr(N*iter) * inc; want != total {
t.Fatalf("xadduintpr error, want %d, got %d", want, total)
}
total = 0
t.Skip("skipping on plan9")
}
- const maxDuration = 5 * time.Second
+ broken := false
+ switch runtime.GOOS {
+ case "darwin", "dragonfly", "netbsd", "illumos", "solaris":
+ broken = true
+ case "openbsd":
+ if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
+ broken = true
+ }
+ }
+
+ maxDuration := 5 * time.Second
+ if testing.Short() && broken {
+ // If it's expected to be broken, no point waiting around.
+ maxDuration /= 10
+ }
+
// If we're running a long test, start with a long duration
// for tests that try to make sure something *doesn't* happen.
duration := 5 * time.Second
if testing.Short() {
- duration = 200 * time.Millisecond
+ duration = 100 * time.Millisecond
}
// Profiling tests are inherently flaky, especially on a
}
}
- switch runtime.GOOS {
- case "darwin", "dragonfly", "netbsd", "illumos", "solaris":
- t.Skipf("ignoring failure on %s; see golang.org/issue/13841", runtime.GOOS)
- case "openbsd":
- if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
- t.Skipf("ignoring failure on %s/%s; see golang.org/issue/13841", runtime.GOOS, runtime.GOARCH)
- }
+ if broken {
+ t.Skipf("ignoring failure on %s/%s; see golang.org/issue/13841", runtime.GOOS, runtime.GOARCH)
}
+
// Ignore the failure if the tests are running in a QEMU-based emulator,
// QEMU is not perfect at emulating everything.
// IN_QEMU environmental variable is set by some of the Go builders.
7ffc34343000 7ffc34345000 00000000 [vdso]
ffffffffff600000 ffffffffff601000 00000090 [vsyscall]
-00400000-07000000 r-xp 00000000 00:00 0
+00400000-07000000 r-xp 00000000 00:00 0
07000000-07093000 r-xp 06c00000 00:2e 536754 /path/to/gobench_server_main
07093000-0722d000 rw-p 06c92000 00:2e 536754 /path/to/gobench_server_main
-0722d000-07b21000 rw-p 00000000 00:00 0
-c000000000-c000036000 rw-p 00000000 00:00 0
+0722d000-07b21000 rw-p 00000000 00:00 0
+c000000000-c000036000 rw-p 00000000 00:00 0
->
07000000 07093000 06c00000 /path/to/gobench_server_main
`
})
}
-// TestMapping checkes the mapping section of CPU profiles
+// TestMapping checks the mapping section of CPU profiles
// has the HasFunctions field set correctly. If all PCs included
// in the samples are successfully symbolized, the corresponding
// mapping entry (in this test case, only one entry) should have
if err := pprof.StartCPUProfile(os.Stdout); err != nil {
log.Fatal("can't start CPU profile: ", err)
}
- time.Sleep(1 * time.Second)
+ time.Sleep(200 * time.Millisecond)
pprof.StopCPUProfile()
if err := os.Stdout.Close(); err != nil {
package runtime_test
import (
- "internal/testenv"
- "io/ioutil"
- "os"
"os/exec"
- "path/filepath"
"syscall"
"testing"
"time"
if *flagQuick {
t.Skip("-quick")
}
- testenv.MustHaveGoBuild(t)
- tempDir, err := ioutil.TempDir("", "issue-27250")
- if err != nil {
- t.Fatalf("Failed to create the temp directory: %v", err)
- }
- defer os.RemoveAll(tempDir)
-
- repro := `
- package main
-
- import "time"
- func main() {
- <-time.After(1 * time.Second)
- }
- `
- mainPath := filepath.Join(tempDir, "main.go")
- if err := ioutil.WriteFile(mainPath, []byte(repro), 0644); err != nil {
- t.Fatalf("Failed to create temp file for repro.go: %v", err)
- }
- binaryPath := filepath.Join(tempDir, "binary")
-
- // Build the binary so that we can send the signal to its PID.
- out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", binaryPath, mainPath).CombinedOutput()
+ exe, err := buildTestProg(t, "testprog")
if err != nil {
- t.Fatalf("Failed to compile the binary: err: %v\nOutput: %s\n", err, out)
- }
- if err := os.Chmod(binaryPath, 0755); err != nil {
- t.Fatalf("Failed to chmod binary: %v", err)
+ t.Fatal(err)
}
- // Now run the binary.
- cmd := exec.Command(binaryPath)
+ start := time.Now()
+ cmd := exec.Command(exe, "After1")
if err := cmd.Start(); err != nil {
t.Fatalf("Failed to start command: %v", err)
}
if err != nil {
t.Fatalf("The program returned but unfortunately with an error: %v", err)
}
+ if time.Since(start) < 100*time.Millisecond {
+ t.Fatalf("The program stopped too quickly.")
+ }
return
}
}
}
func GoexitExit() {
+ println("t1")
go func() {
time.Sleep(time.Millisecond)
}()
i := 0
+ println("t2")
runtime.SetFinalizer(&i, func(p *int) {})
+ println("t3")
runtime.GC()
+ println("t4")
runtime.Goexit()
}
--- /dev/null
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "time"
+
+// for golang.org/issue/27250
+
+func init() {
+ register("After1", After1)
+}
+
+func After1() {
+ <-time.After(1 * time.Second)
+}
if IsEnabled() {
t.Skip("skipping because -test.trace is set")
}
+ if testing.Short() {
+ t.Skip("skipping in -short mode")
+ }
+
var wg sync.WaitGroup
done := make(chan bool)
const N = 100
loop:
for try := 0; try < 3; try++ {
+ if try == 1 && testing.Short() {
+ break
+ }
var fin, fin1 uint32
for i := 0; i < N; i++ {
v := new(string)
}
}
func testGetdirentries(t *testing.T, count int) {
+ if count > 100 && testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" {
+ t.Skip("skipping in -short mode")
+ }
d, err := ioutil.TempDir("", "getdirentries-test")
if err != nil {
t.Fatalf("Tempdir: %v", err)
}
return true
}
- cfg := &Config{MaxCount: 100000}
+ cfg := &Config{MaxCount: 10000}
Check(f, cfg)
if uint64(lo)>>62 == 0 || uint64(hi)>>62 == 0 {
t.Errorf("int64 returned range %#016x,%#016x; does not look like full range", lo, hi)
}
func TestMaxExecDepth(t *testing.T) {
+ if testing.Short() {
+ t.Skip("skipping in -short mode")
+ }
tmpl := Must(New("tmpl").Parse(`{{template "tmpl" .}}`))
err := tmpl.Execute(ioutil.Discard, nil)
got := "<nil>"