Damien Neil 7f9c7d9fe4 internal/fuzz: refactor fuzzer
Add a new Fuzz message containing all the message types we want to make
available to fuzzers. Previously, testing (for example) required fields
would require modifying the fuzzer; now, it's just a matter of adding a
message with required fields as a field of the top-level Fuzz message.

Add internal/cmd/generate-corpus to codify where the fuzz seed corpus
comes from. This will simplify adding text and json fuzzers.

Rename internal/fuzz/wire to internal/fuzz/wirefuzz to minimize package
name ambiguity. Also, the addition of the Fuzz container message
invalidates the existing corpus, so using a new name seems like a good
idea.

Change-Id: I94f8f64ba93596c8e8cecb4d42bcc5b98c17d838
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/212218
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-12-20 09:01:58 +00:00

35 lines
604 B
Go

// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package wirefuzz
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func Test(t *testing.T) {
dir, err := os.Open("corpus")
if err != nil {
t.Fatal(err)
}
infos, err := dir.Readdir(0)
if err != nil {
t.Fatal(err)
}
for _, info := range infos {
name := info.Name()
t.Run(name, func(t *testing.T) {
b, err := ioutil.ReadFile(filepath.Join("corpus", name))
if err != nil {
t.Fatal(err)
}
Fuzz(b)
})
}
}