Skip to content

Commit 0a71a5b

Browse files
albertsrobpike
authored andcommitted
all: Skip AllocsPerRun tests if GOMAXPROCS>1.
Fixes #4974. R=rsc, bradfitz, r CC=golang-dev https://golang.org/cl/7545043
1 parent 45a3b37 commit 0a71a5b

File tree

10 files changed

+50
-0
lines changed

10 files changed

+50
-0
lines changed

src/pkg/encoding/gob/timing_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io"
1111
"os"
12+
"runtime"
1213
"testing"
1314
)
1415

@@ -49,6 +50,10 @@ func BenchmarkEndToEndByteBuffer(b *testing.B) {
4950
}
5051

5152
func TestCountEncodeMallocs(t *testing.T) {
53+
if runtime.GOMAXPROCS(0) > 1 {
54+
t.Skip("skipping; GOMAXPROCS>1")
55+
}
56+
5257
const N = 1000
5358

5459
var buf bytes.Buffer
@@ -65,6 +70,10 @@ func TestCountEncodeMallocs(t *testing.T) {
6570
}
6671

6772
func TestCountDecodeMallocs(t *testing.T) {
73+
if runtime.GOMAXPROCS(0) > 1 {
74+
t.Skip("skipping; GOMAXPROCS>1")
75+
}
76+
6877
const N = 1000
6978

7079
var buf bytes.Buffer

src/pkg/fmt/fmt_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
. "fmt"
1010
"io"
1111
"math"
12+
"runtime"
1213
"strings"
1314
"testing"
1415
"time"
@@ -601,6 +602,9 @@ var mallocTest = []struct {
601602
var _ bytes.Buffer
602603

603604
func TestCountMallocs(t *testing.T) {
605+
if runtime.GOMAXPROCS(0) > 1 {
606+
t.Skip("skipping; GOMAXPROCS>1")
607+
}
604608
for _, mt := range mallocTest {
605609
mallocs := testing.AllocsPerRun(100, mt.fn)
606610
if got, max := mallocs, float64(mt.count); got > max {

src/pkg/net/http/header_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package http
66

77
import (
88
"bytes"
9+
"runtime"
910
"testing"
1011
"time"
1112
)
@@ -192,6 +193,9 @@ func BenchmarkHeaderWriteSubset(b *testing.B) {
192193
}
193194

194195
func TestHeaderWriteSubsetMallocs(t *testing.T) {
196+
if runtime.GOMAXPROCS(0) > 1 {
197+
t.Skip("skipping; GOMAXPROCS>1")
198+
}
195199
n := testing.AllocsPerRun(100, func() {
196200
buf.Reset()
197201
testHeader.WriteSubset(&buf, nil)

src/pkg/net/rpc/server_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,16 @@ func countMallocs(dial func() (*Client, error), t *testing.T) float64 {
465465
}
466466

467467
func TestCountMallocs(t *testing.T) {
468+
if runtime.GOMAXPROCS(0) > 1 {
469+
t.Skip("skipping; GOMAXPROCS>1")
470+
}
468471
fmt.Printf("mallocs per rpc round trip: %v\n", countMallocs(dialDirect, t))
469472
}
470473

471474
func TestCountMallocsOverHTTP(t *testing.T) {
475+
if runtime.GOMAXPROCS(0) > 1 {
476+
t.Skip("skipping; GOMAXPROCS>1")
477+
}
472478
fmt.Printf("mallocs per HTTP rpc round trip: %v\n", countMallocs(dialHTTP, t))
473479
}
474480

src/pkg/path/filepath/path_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ func TestClean(t *testing.T) {
107107
}
108108
}
109109

110+
if runtime.GOMAXPROCS(0) > 1 {
111+
t.Log("skipping AllocsPerRun checks; GOMAXPROCS>1")
112+
return
113+
}
114+
110115
for _, test := range tests {
111116
allocs := testing.AllocsPerRun(100, func() { filepath.Clean(test.result) })
112117
if allocs > 0 {

src/pkg/path/path_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package path
66

77
import (
8+
"runtime"
89
"testing"
910
)
1011

@@ -72,6 +73,11 @@ func TestClean(t *testing.T) {
7273
}
7374
}
7475

76+
if runtime.GOMAXPROCS(0) > 1 {
77+
t.Log("skipping AllocsPerRun checks; GOMAXPROCS>1")
78+
return
79+
}
80+
7581
for _, test := range cleantests {
7682
allocs := testing.AllocsPerRun(100, func() { Clean(test.result) })
7783
if allocs > 0 {

src/pkg/reflect/all_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"math/rand"
1414
"os"
1515
. "reflect"
16+
"runtime"
1617
"sync"
1718
"testing"
1819
"time"
@@ -2011,6 +2012,9 @@ func TestAddr(t *testing.T) {
20112012
}
20122013

20132014
func noAlloc(t *testing.T, n int, f func(int)) {
2015+
if runtime.GOMAXPROCS(0) > 1 {
2016+
t.Skip("skipping; GOMAXPROCS>1")
2017+
}
20142018
i := -1
20152019
allocs := testing.AllocsPerRun(n, func() {
20162020
f(i)

src/pkg/sort/search_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package sort_test
66

77
import (
8+
"runtime"
89
. "sort"
910
"testing"
1011
)
@@ -127,6 +128,9 @@ func runSearchWrappers() {
127128
}
128129

129130
func TestSearchWrappersDontAlloc(t *testing.T) {
131+
if runtime.GOMAXPROCS(0) > 1 {
132+
t.Skip("skipping; GOMAXPROCS>1")
133+
}
130134
allocs := testing.AllocsPerRun(100, runSearchWrappers)
131135
if allocs != 0 {
132136
t.Errorf("expected no allocs for runSearchWrappers, got %v", allocs)

src/pkg/strconv/strconv_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package strconv_test
66

77
import (
8+
"runtime"
89
. "strconv"
910
"strings"
1011
"testing"
@@ -43,6 +44,9 @@ var (
4344
)
4445

4546
func TestCountMallocs(t *testing.T) {
47+
if runtime.GOMAXPROCS(0) > 1 {
48+
t.Skip("skipping; GOMAXPROCS>1")
49+
}
4650
for _, mt := range mallocTest {
4751
allocs := testing.AllocsPerRun(100, mt.fn)
4852
if max := float64(mt.count); allocs > max {

src/pkg/time/time_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"math/big"
1313
"math/rand"
14+
"runtime"
1415
"strconv"
1516
"strings"
1617
"testing"
@@ -1299,6 +1300,9 @@ var mallocTest = []struct {
12991300
}
13001301

13011302
func TestCountMallocs(t *testing.T) {
1303+
if runtime.GOMAXPROCS(0) > 1 {
1304+
t.Skip("skipping; GOMAXPROCS>1")
1305+
}
13021306
for _, mt := range mallocTest {
13031307
allocs := int(testing.AllocsPerRun(100, mt.fn))
13041308
if allocs > mt.count {

0 commit comments

Comments
 (0)