Commit 0a71a5b0 authored by Albert Strasheim's avatar Albert Strasheim Committed by Rob Pike

all: Skip AllocsPerRun tests if GOMAXPROCS>1.

Fixes #4974.

R=rsc, bradfitz, r
CC=golang-dev
https://golang.org/cl/7545043
parent 45a3b371
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"runtime"
"testing" "testing"
) )
...@@ -49,6 +50,10 @@ func BenchmarkEndToEndByteBuffer(b *testing.B) { ...@@ -49,6 +50,10 @@ func BenchmarkEndToEndByteBuffer(b *testing.B) {
} }
func TestCountEncodeMallocs(t *testing.T) { func TestCountEncodeMallocs(t *testing.T) {
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
const N = 1000 const N = 1000
var buf bytes.Buffer var buf bytes.Buffer
...@@ -65,6 +70,10 @@ func TestCountEncodeMallocs(t *testing.T) { ...@@ -65,6 +70,10 @@ func TestCountEncodeMallocs(t *testing.T) {
} }
func TestCountDecodeMallocs(t *testing.T) { func TestCountDecodeMallocs(t *testing.T) {
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
const N = 1000 const N = 1000
var buf bytes.Buffer var buf bytes.Buffer
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
. "fmt" . "fmt"
"io" "io"
"math" "math"
"runtime"
"strings" "strings"
"testing" "testing"
"time" "time"
...@@ -601,6 +602,9 @@ var mallocTest = []struct { ...@@ -601,6 +602,9 @@ var mallocTest = []struct {
var _ bytes.Buffer var _ bytes.Buffer
func TestCountMallocs(t *testing.T) { func TestCountMallocs(t *testing.T) {
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
for _, mt := range mallocTest { for _, mt := range mallocTest {
mallocs := testing.AllocsPerRun(100, mt.fn) mallocs := testing.AllocsPerRun(100, mt.fn)
if got, max := mallocs, float64(mt.count); got > max { if got, max := mallocs, float64(mt.count); got > max {
......
...@@ -6,6 +6,7 @@ package http ...@@ -6,6 +6,7 @@ package http
import ( import (
"bytes" "bytes"
"runtime"
"testing" "testing"
"time" "time"
) )
...@@ -192,6 +193,9 @@ func BenchmarkHeaderWriteSubset(b *testing.B) { ...@@ -192,6 +193,9 @@ func BenchmarkHeaderWriteSubset(b *testing.B) {
} }
func TestHeaderWriteSubsetMallocs(t *testing.T) { func TestHeaderWriteSubsetMallocs(t *testing.T) {
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
n := testing.AllocsPerRun(100, func() { n := testing.AllocsPerRun(100, func() {
buf.Reset() buf.Reset()
testHeader.WriteSubset(&buf, nil) testHeader.WriteSubset(&buf, nil)
......
...@@ -465,10 +465,16 @@ func countMallocs(dial func() (*Client, error), t *testing.T) float64 { ...@@ -465,10 +465,16 @@ func countMallocs(dial func() (*Client, error), t *testing.T) float64 {
} }
func TestCountMallocs(t *testing.T) { func TestCountMallocs(t *testing.T) {
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
fmt.Printf("mallocs per rpc round trip: %v\n", countMallocs(dialDirect, t)) fmt.Printf("mallocs per rpc round trip: %v\n", countMallocs(dialDirect, t))
} }
func TestCountMallocsOverHTTP(t *testing.T) { func TestCountMallocsOverHTTP(t *testing.T) {
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
fmt.Printf("mallocs per HTTP rpc round trip: %v\n", countMallocs(dialHTTP, t)) fmt.Printf("mallocs per HTTP rpc round trip: %v\n", countMallocs(dialHTTP, t))
} }
......
...@@ -107,6 +107,11 @@ func TestClean(t *testing.T) { ...@@ -107,6 +107,11 @@ func TestClean(t *testing.T) {
} }
} }
if runtime.GOMAXPROCS(0) > 1 {
t.Log("skipping AllocsPerRun checks; GOMAXPROCS>1")
return
}
for _, test := range tests { for _, test := range tests {
allocs := testing.AllocsPerRun(100, func() { filepath.Clean(test.result) }) allocs := testing.AllocsPerRun(100, func() { filepath.Clean(test.result) })
if allocs > 0 { if allocs > 0 {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package path package path
import ( import (
"runtime"
"testing" "testing"
) )
...@@ -72,6 +73,11 @@ func TestClean(t *testing.T) { ...@@ -72,6 +73,11 @@ func TestClean(t *testing.T) {
} }
} }
if runtime.GOMAXPROCS(0) > 1 {
t.Log("skipping AllocsPerRun checks; GOMAXPROCS>1")
return
}
for _, test := range cleantests { for _, test := range cleantests {
allocs := testing.AllocsPerRun(100, func() { Clean(test.result) }) allocs := testing.AllocsPerRun(100, func() { Clean(test.result) })
if allocs > 0 { if allocs > 0 {
......
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"math/rand" "math/rand"
"os" "os"
. "reflect" . "reflect"
"runtime"
"sync" "sync"
"testing" "testing"
"time" "time"
...@@ -2011,6 +2012,9 @@ func TestAddr(t *testing.T) { ...@@ -2011,6 +2012,9 @@ func TestAddr(t *testing.T) {
} }
func noAlloc(t *testing.T, n int, f func(int)) { func noAlloc(t *testing.T, n int, f func(int)) {
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
i := -1 i := -1
allocs := testing.AllocsPerRun(n, func() { allocs := testing.AllocsPerRun(n, func() {
f(i) f(i)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package sort_test package sort_test
import ( import (
"runtime"
. "sort" . "sort"
"testing" "testing"
) )
...@@ -127,6 +128,9 @@ func runSearchWrappers() { ...@@ -127,6 +128,9 @@ func runSearchWrappers() {
} }
func TestSearchWrappersDontAlloc(t *testing.T) { func TestSearchWrappersDontAlloc(t *testing.T) {
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
allocs := testing.AllocsPerRun(100, runSearchWrappers) allocs := testing.AllocsPerRun(100, runSearchWrappers)
if allocs != 0 { if allocs != 0 {
t.Errorf("expected no allocs for runSearchWrappers, got %v", allocs) t.Errorf("expected no allocs for runSearchWrappers, got %v", allocs)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package strconv_test package strconv_test
import ( import (
"runtime"
. "strconv" . "strconv"
"strings" "strings"
"testing" "testing"
...@@ -43,6 +44,9 @@ var ( ...@@ -43,6 +44,9 @@ var (
) )
func TestCountMallocs(t *testing.T) { func TestCountMallocs(t *testing.T) {
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
for _, mt := range mallocTest { for _, mt := range mallocTest {
allocs := testing.AllocsPerRun(100, mt.fn) allocs := testing.AllocsPerRun(100, mt.fn)
if max := float64(mt.count); allocs > max { if max := float64(mt.count); allocs > max {
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"math/rand" "math/rand"
"runtime"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
...@@ -1299,6 +1300,9 @@ var mallocTest = []struct { ...@@ -1299,6 +1300,9 @@ var mallocTest = []struct {
} }
func TestCountMallocs(t *testing.T) { func TestCountMallocs(t *testing.T) {
if runtime.GOMAXPROCS(0) > 1 {
t.Skip("skipping; GOMAXPROCS>1")
}
for _, mt := range mallocTest { for _, mt := range mallocTest {
allocs := int(testing.AllocsPerRun(100, mt.fn)) allocs := int(testing.AllocsPerRun(100, mt.fn))
if allocs > mt.count { if allocs > mt.count {
......
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