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 f589675..9fbb0ac 100644
--- a/src/pkg/encoding/gob/timing_test.go
+++ b/src/pkg/encoding/gob/timing_test.go
@@ -6,7 +6,6 @@
 
 import (
 	"bytes"
-	"fmt"
 	"io"
 	"os"
 	"runtime"
@@ -50,6 +49,9 @@
 }
 
 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 @@
 			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 @@
 			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 42c5915..199f337 100644
--- a/src/pkg/fmt/fmt_test.go
+++ b/src/pkg/fmt/fmt_test.go
@@ -663,6 +663,9 @@
 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 a2b82a7..69b41a7 100644
--- a/src/pkg/net/http/header_test.go
+++ b/src/pkg/net/http/header_test.go
@@ -193,6 +193,9 @@
 }
 
 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 0631acd..3b9a883 100644
--- a/src/pkg/net/rpc/server_test.go
+++ b/src/pkg/net/rpc/server_test.go
@@ -503,6 +503,9 @@
 }
 
 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 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 e3c79b2..15f46a1 100644
--- a/src/pkg/net/tcp_test.go
+++ b/src/pkg/net/tcp_test.go
@@ -453,6 +453,9 @@
 }
 
 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 b1cdcee..bbb4e16 100644
--- a/src/pkg/path/filepath/path_test.go
+++ b/src/pkg/path/filepath/path_test.go
@@ -107,6 +107,9 @@
 		}
 	}
 
+	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 69caa80..13b5852 100644
--- a/src/pkg/path/path_test.go
+++ b/src/pkg/path/path_test.go
@@ -72,7 +72,12 @@
 			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 fcdf87a..c169c35 100644
--- a/src/pkg/reflect/all_test.go
+++ b/src/pkg/reflect/all_test.go
@@ -2287,6 +2287,9 @@
 }
 
 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 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 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 ee95c66..29b8d62 100644
--- a/src/pkg/sort/search_test.go
+++ b/src/pkg/sort/search_test.go
@@ -128,6 +128,9 @@
 }
 
 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 40ab4ce..9a007dd 100644
--- a/src/pkg/strconv/strconv_test.go
+++ b/src/pkg/strconv/strconv_test.go
@@ -42,6 +42,9 @@
 )
 
 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 6d6e8cc..0619f88 100644
--- a/src/pkg/time/time_test.go
+++ b/src/pkg/time/time_test.go
@@ -1385,6 +1385,9 @@
 }
 
 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")
 	}