From: Rob Pike Date: Wed, 21 Aug 2013 04:00:45 +0000 (+1000) Subject: all: protect alloc count tests by -testing.short X-Git-Tag: go1.2rc2~468 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f578726de1d75b5816904972b0a29c1a5fdbda24;p=gostls13.git 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 --- diff --git a/src/pkg/encoding/gob/timing_test.go b/src/pkg/encoding/gob/timing_test.go index f589675dd9..9fbb0ac6d5 100644 --- a/src/pkg/encoding/gob/timing_test.go +++ b/src/pkg/encoding/gob/timing_test.go @@ -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) + } } diff --git a/src/pkg/fmt/fmt_test.go b/src/pkg/fmt/fmt_test.go index 42c5915120..199f337ec2 100644 --- a/src/pkg/fmt/fmt_test.go +++ b/src/pkg/fmt/fmt_test.go @@ -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") } diff --git a/src/pkg/net/http/header_test.go b/src/pkg/net/http/header_test.go index a2b82a701c..69b41a7953 100644 --- a/src/pkg/net/http/header_test.go +++ b/src/pkg/net/http/header_test.go @@ -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") } diff --git a/src/pkg/net/rpc/server_test.go b/src/pkg/net/rpc/server_test.go index 0631acdf94..3b9a88380c 100644 --- a/src/pkg/net/rpc/server_test.go +++ b/src/pkg/net/rpc/server_test.go @@ -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") } diff --git a/src/pkg/net/tcp_test.go b/src/pkg/net/tcp_test.go index e3c79b2c84..15f46a1361 100644 --- a/src/pkg/net/tcp_test.go +++ b/src/pkg/net/tcp_test.go @@ -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. diff --git a/src/pkg/path/filepath/path_test.go b/src/pkg/path/filepath/path_test.go index b1cdcee4ce..bbb4e16f2a 100644 --- a/src/pkg/path/filepath/path_test.go +++ b/src/pkg/path/filepath/path_test.go @@ -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 diff --git a/src/pkg/path/path_test.go b/src/pkg/path/path_test.go index 69caa80e4f..13b585223f 100644 --- a/src/pkg/path/path_test.go +++ b/src/pkg/path/path_test.go @@ -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 diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go index fcdf87af81..c169c3594d 100644 --- a/src/pkg/reflect/all_test.go +++ b/src/pkg/reflect/all_test.go @@ -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) diff --git a/src/pkg/sort/search_test.go b/src/pkg/sort/search_test.go index ee95c663cc..29b8d62dfe 100644 --- a/src/pkg/sort/search_test.go +++ b/src/pkg/sort/search_test.go @@ -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") } diff --git a/src/pkg/strconv/strconv_test.go b/src/pkg/strconv/strconv_test.go index 40ab4ce6a4..9a007dde4a 100644 --- a/src/pkg/strconv/strconv_test.go +++ b/src/pkg/strconv/strconv_test.go @@ -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") } diff --git a/src/pkg/time/time_test.go b/src/pkg/time/time_test.go index 6d6e8ccd8a..0619f88f09 100644 --- a/src/pkg/time/time_test.go +++ b/src/pkg/time/time_test.go @@ -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") }