all: set GOMAXPROCS to 1 when counting mallocs

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
This commit is contained in:
Shenghou Ma 2012-12-01 00:38:01 +08:00
parent 5b425cc3ab
commit 9e30b708a1
11 changed files with 15 additions and 6 deletions

View 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)
}
}