]> Cypherpunks repositories - gostls13.git/commitdiff
all: set GOMAXPROCS to 1 when counting mallocs
authorShenghou Ma <minux.ma@gmail.com>
Fri, 30 Nov 2012 16:38:01 +0000 (00:38 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Fri, 30 Nov 2012 16:38:01 +0000 (00:38 +0800)
also fix an annoying test that relies on $GOROOT be set.
Fixes #3690.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6844086

src/pkg/encoding/gob/timing_test.go
src/pkg/fmt/fmt_test.go
src/pkg/math/big/nat_test.go
src/pkg/net/http/header_test.go
src/pkg/net/rpc/server_test.go
src/pkg/path/filepath/path_test.go
src/pkg/path/path_test.go
src/pkg/reflect/all_test.go
src/pkg/runtime/gc_test.go
src/pkg/runtime/mallocrep1.go
src/pkg/strconv/strconv_test.go

index b9371c42309eec79e858001e423ac106afcc1468..9a0e51d1fe19bea0193f56bcddb8bc0508f61ce0 100644 (file)
@@ -50,6 +50,7 @@ func BenchmarkEndToEndByteBuffer(b *testing.B) {
 }
 
 func TestCountEncodeMallocs(t *testing.T) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        var buf bytes.Buffer
        enc := NewEncoder(&buf)
        bench := &Bench{7, 3.2, "now is the time", []byte("for all good men")}
@@ -69,6 +70,7 @@ func TestCountEncodeMallocs(t *testing.T) {
 }
 
 func TestCountDecodeMallocs(t *testing.T) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        var buf bytes.Buffer
        enc := NewEncoder(&buf)
        bench := &Bench{7, 3.2, "now is the time", []byte("for all good men")}
index 210d8f8b3df9265fe91d598307741e4013fc9b78..84fc380307f7ba457560f9db7a1dcb63e0dff02e 100644 (file)
@@ -581,6 +581,7 @@ var mallocTest = []struct {
 var _ bytes.Buffer
 
 func TestCountMallocs(t *testing.T) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        for _, mt := range mallocTest {
                const N = 100
                memstats := new(runtime.MemStats)
index 6244eeefc91af70ae9292d34e4af305f19e50227..2dd7bf63968976f0c87f16fb2c6092bcf8e8ff67 100644 (file)
@@ -180,6 +180,7 @@ func allocBytes(f func()) uint64 {
 // does not cause deep recursion and in turn allocate too much memory.
 // Test case for issue 3807.
 func TestMulUnbalanced(t *testing.T) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        x := rndNat(50000)
        y := rndNat(40)
        allocSize := allocBytes(func() {
index fd971a61d054d0416d9e3a520e5ab367f6a0b2eb..01bb4dce00002fad0a3426722ff8a4a12dd1d75f 100644 (file)
@@ -188,6 +188,7 @@ type errorfer interface {
 }
 
 func doHeaderWriteSubset(n int, t errorfer) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        h := Header(map[string][]string{
                "Content-Length": {"123"},
                "Content-Type":   {"text/plain"},
@@ -204,7 +205,7 @@ func doHeaderWriteSubset(n int, t errorfer) {
        var m1 runtime.MemStats
        runtime.ReadMemStats(&m1)
        if mallocs := m1.Mallocs - m0.Mallocs; n >= 100 && mallocs >= uint64(n) {
-               // TODO(bradfitz,rsc): once we can sort with allocating,
+               // TODO(bradfitz,rsc): once we can sort without allocating,
                // make this an error.  See http://golang.org/issue/3761
                // t.Errorf("did %d mallocs (>= %d iterations); should have avoided mallocs", mallocs, n)
        }
index d9ebe71e5c310a6cecff9a6435681ae9de18d4a1..2c734a479fd63365976cfb4687011635095c33b3 100644 (file)
@@ -446,6 +446,7 @@ func dialHTTP() (*Client, error) {
 }
 
 func countMallocs(dial func() (*Client, error), t *testing.T) uint64 {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        once.Do(startServer)
        client, err := dial()
        if err != nil {
index ef554dd7fa122c1cc8d44402159b26afb1de8b9c..bd251a4ebb431d6ec27c048bbb20d3786af9d8a6 100644 (file)
@@ -91,6 +91,7 @@ var wincleantests = []PathTest{
 }
 
 func TestClean(t *testing.T) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        tests := cleantests
        if runtime.GOOS == "windows" {
                for i := range tests {
@@ -897,7 +898,7 @@ func TestDriveLetterInEvalSymlinks(t *testing.T) {
 }
 
 func TestBug3486(t *testing.T) { // http://code.google.com/p/go/issues/detail?id=3486
-       root, err := filepath.EvalSymlinks(os.Getenv("GOROOT"))
+       root, err := filepath.EvalSymlinks(runtime.GOROOT())
        if err != nil {
                t.Fatal(err)
        }
index 0f353be34dd7c2d342420ac9f701155e96d0927b..52cbb494e830306d4d90cc4daae96c77cdf992d2 100644 (file)
@@ -64,6 +64,7 @@ var cleantests = []PathTest{
 }
 
 func TestClean(t *testing.T) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        for _, test := range cleantests {
                if s := Clean(test.path); s != test.result {
                        t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.result)
index 12cdbe1ca9b9d4ffde45aa586fe3790ab8ad657f..8dd24de28e33b0c26f006dc0293f16ae28d58e6c 100644 (file)
@@ -2012,6 +2012,7 @@ func TestAddr(t *testing.T) {
 }
 
 func noAlloc(t *testing.T, n int, f func(int)) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        // once to prime everything
        f(-1)
        memstats := new(runtime.MemStats)
@@ -2021,12 +2022,9 @@ func noAlloc(t *testing.T, n int, f func(int)) {
        for j := 0; j < n; j++ {
                f(j)
        }
-       // A few allocs may happen in the testing package when GOMAXPROCS > 1, so don't
-       // require zero mallocs.
-       // A new thread, one of which will be created if GOMAXPROCS>1, does 6 allocations.
        runtime.ReadMemStats(memstats)
        mallocs := memstats.Mallocs - oldmallocs
-       if mallocs > 10 {
+       if mallocs > 0 {
                t.Fatalf("%d mallocs after %d iterations", mallocs, n)
        }
 }
index 56dd93819e179f1e4a8c65140cfd6fd0203c2d82..283a6812e95f3d270920ff526cfffe45d50ecdd1 100644 (file)
@@ -10,6 +10,7 @@ import (
 )
 
 func TestGcSys(t *testing.T) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        memstats := new(runtime.MemStats)
        runtime.GC()
        runtime.ReadMemStats(memstats)
index 41c104c0ba798331655702883ea8748b417395ff..bc33e3a6b4b643ebd8dc9fbbeddd17774d4dd869 100644 (file)
@@ -39,6 +39,7 @@ func OkAmount(size, n uintptr) bool {
 }
 
 func AllocAndFree(size, count int) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        if *chatty {
                fmt.Printf("size=%d count=%d ...\n", size, count)
        }
index 5cab4bf42b8fcec26391ca34904cb2785d7bb184..6a99522a6114babd6414f7851bc9e993724e88e2 100644 (file)
@@ -44,6 +44,7 @@ var (
 )
 
 func TestCountMallocs(t *testing.T) {
+       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
        for _, mt := range mallocTest {
                const N = 100
                memstats := new(runtime.MemStats)