Commit bbe60178 authored by Rob Pike's avatar Rob Pike

encoding/gob: disable fuzz tests unless command-line flag is set

They can generate huge amounts of memory, causing failure on
small machines. Also they can be very slow. So slow that one test
was commented out! We uncomment it and use a flag.

Fixes #3742.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6373044
parent 882b6ef4
...@@ -7,6 +7,7 @@ package gob ...@@ -7,6 +7,7 @@ package gob
import ( import (
"bytes" "bytes"
"errors" "errors"
"flag"
"math" "math"
"math/rand" "math/rand"
"reflect" "reflect"
...@@ -16,6 +17,8 @@ import ( ...@@ -16,6 +17,8 @@ import (
"unsafe" "unsafe"
) )
var doFuzzTests = flag.Bool("gob.fuzz", false, "run the fuzz tests, which are large and very slow")
// Guarantee encoding format by comparing some encodings to hand-written values // Guarantee encoding format by comparing some encodings to hand-written values
type EncodeT struct { type EncodeT struct {
x uint64 x uint64
...@@ -1434,7 +1437,8 @@ func encFuzzDec(rng *rand.Rand, in interface{}) error { ...@@ -1434,7 +1437,8 @@ func encFuzzDec(rng *rand.Rand, in interface{}) error {
// This does some "fuzz testing" by attempting to decode a sequence of random bytes. // This does some "fuzz testing" by attempting to decode a sequence of random bytes.
func TestFuzz(t *testing.T) { func TestFuzz(t *testing.T) {
if testing.Short() { if !*doFuzzTests {
t.Logf("disabled; run with -gob.fuzz to enable")
return return
} }
...@@ -1453,11 +1457,16 @@ func TestFuzz(t *testing.T) { ...@@ -1453,11 +1457,16 @@ func TestFuzz(t *testing.T) {
} }
func TestFuzzRegressions(t *testing.T) { func TestFuzzRegressions(t *testing.T) {
if !*doFuzzTests {
t.Logf("disabled; run with -gob.fuzz to enable")
return
}
// An instance triggering a type name of length ~102 GB. // An instance triggering a type name of length ~102 GB.
testFuzz(t, 1328492090837718000, 100, new(float32)) testFuzz(t, 1328492090837718000, 100, new(float32))
// An instance triggering a type name of 1.6 GB. // An instance triggering a type name of 1.6 GB.
// Commented out because it takes 5m to run. // Note: can take several minutes to run.
//testFuzz(t, 1330522872628565000, 100, new(int)) testFuzz(t, 1330522872628565000, 100, new(int))
} }
func testFuzz(t *testing.T, seed int64, n int, input ...interface{}) { func testFuzz(t *testing.T, seed int64, n int, input ...interface{}) {
......
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