Commit f578726d authored by Rob Pike's avatar Rob Pike

all: protect alloc count tests by -testing.short

Update #5000
Should reduce the flakiness a little. Malloc counting is important
to general testing but not to the build dashboard, which uses -short.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12866047
parent a83b17c0
......@@ -6,7 +6,6 @@ package gob
import (
"bytes"
"fmt"
"io"
"os"
"runtime"
......@@ -50,6 +49,9 @@ func BenchmarkEndToEndByteBuffer(b *testing.B) {
}
func TestCountEncodeMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
......@@ -66,10 +68,15 @@ func TestCountEncodeMallocs(t *testing.T) {
t.Fatal("encode:", err)
}
})
fmt.Printf("mallocs per encode of type Bench: %v\n", allocs)
if allocs != 0 {
t.Fatalf("mallocs per encode of type Bench: %v; wanted 0\n", allocs)
}
}
func TestCountDecodeMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
......@@ -96,5 +103,7 @@ func TestCountDecodeMallocs(t *testing.T) {
t.Fatal("decode:", err)
}
})
fmt.Printf("mallocs per decode of type Bench: %v\n", allocs)
if allocs != 3 {
t.Fatalf("mallocs per decode of type Bench: %v; wanted 3\n", allocs)
}
}
......@@ -663,6 +663,9 @@ var mallocTest = []struct {
var _ bytes.Buffer
func TestCountMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
......
......@@ -193,6 +193,9 @@ func BenchmarkHeaderWriteSubset(b *testing.B) {
}
func TestHeaderWriteSubsetMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
......
......@@ -503,6 +503,9 @@ func countMallocs(dial func() (*Client, error), t *testing.T) float64 {
}
func TestCountMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
......@@ -510,6 +513,9 @@ func TestCountMallocs(t *testing.T) {
}
func TestCountMallocsOverHTTP(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
......
......@@ -453,6 +453,9 @@ func TestTCPConcurrentAccept(t *testing.T) {
}
func TestTCPReadWriteMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
maxMallocs := 10000
switch runtime.GOOS {
// Add other OSes if you know how many mallocs they do.
......
......@@ -107,6 +107,9 @@ func TestClean(t *testing.T) {
}
}
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Log("skipping AllocsPerRun checks; GOMAXPROCS>1")
return
......
......@@ -72,7 +72,12 @@ func TestClean(t *testing.T) {
t.Errorf("Clean(%q) = %q, want %q", test.result, s, test.result)
}
}
}
func TestCleanMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Log("skipping AllocsPerRun checks; GOMAXPROCS>1")
return
......
......@@ -2287,6 +2287,9 @@ func TestAddr(t *testing.T) {
}
func noAlloc(t *testing.T, n int, f func(int)) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
......@@ -3433,6 +3436,9 @@ func BenchmarkInterfaceBig(b *testing.B) {
}
func TestAllocsInterfaceBig(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
v := ValueOf(S{})
if allocs := testing.AllocsPerRun(100, func() { v.Interface() }); allocs > 0 {
t.Errorf("allocs:", allocs)
......@@ -3447,6 +3453,9 @@ func BenchmarkInterfaceSmall(b *testing.B) {
}
func TestAllocsInterfaceSmall(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
v := ValueOf(int64(0))
if allocs := testing.AllocsPerRun(100, func() { v.Interface() }); allocs > 0 {
t.Errorf("allocs:", allocs)
......
......@@ -128,6 +128,9 @@ func runSearchWrappers() {
}
func TestSearchWrappersDontAlloc(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
......
......@@ -42,6 +42,9 @@ var (
)
func TestCountMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
......
......@@ -1385,6 +1385,9 @@ var mallocTest = []struct {
}
func TestCountMallocs(t *testing.T) {
if testing.Short() {
t.Skip("skipping malloc count in short mode")
}
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment