Skip to content

Commit

Permalink
Add remaining fuzz tests to ClusterFuzzLite
Browse files Browse the repository at this point in the history
  • Loading branch information
hickford authored and AlCutter committed Aug 9, 2022
1 parent 8eafa9d commit 0b6d7ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
# undocumented dependency
go install github.com/AdamKorcz/go-118-fuzz-build@latest
go get github.com/AdamKorcz/go-118-fuzz-build/utils

# workaround https://github.com/AdamKorcz/go-118-fuzz-build/issues/2
mv testonly/constants.go testonly/constants_fuzz.go
mv testonly/reference_test.go testonly/reference_test_fuzz.go
mv testonly/tree_test.go testonly/tree_test_fuzz.go
mv testonly/tree.go testonly/tree_fuzz.go

# necessary to list each fuzz test explicitly
compile_native_go_fuzzer github.com/transparency-dev/merkle/compact FuzzRangeNodes FuzzRangeNodes
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzConsistencyProofAndVerify FuzzConsistencyProofAndVerify
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzInclusionProofAndVerify FuzzInclusionProofAndVerify
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzHashAtAgainstReferenceImplementation FuzzHashAtAgainstReferenceImplementation
compile_native_go_fuzzer github.com/transparency-dev/merkle/testonly FuzzInclusionProofAgainstReferenceImplementation FuzzInclusionProofAgainstReferenceImplementation
18 changes: 16 additions & 2 deletions testonly/tree_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package testonly

import (
"bytes"
"math"
"testing"

"github.com/google/go-cmp/cmp"
Expand All @@ -12,7 +13,7 @@ import (
)

// Compute and verify consistency proofs
func FuzzConsistencyProof(f *testing.F) {
func FuzzConsistencyProofAndVerify(f *testing.F) {
for size := 0; size <= 8; size++ {
for end := 0; end <= size; end++ {
for begin := 0; begin <= end; begin++ {
Expand All @@ -21,6 +22,10 @@ func FuzzConsistencyProof(f *testing.F) {
}
}
f.Fuzz(func(t *testing.T, size, begin, end uint64) {
// necessary to restrict size for compile_native_go_fuzzer
if size >= math.MaxUint16 {
return
}
t.Logf("size=%d, begin=%d, end=%d", size, begin, end)
if begin > end || end > size {
return
Expand All @@ -39,13 +44,16 @@ func FuzzConsistencyProof(f *testing.F) {
}

// Compute and verify inclusion proofs
func FuzzInclusionProof(f *testing.F) {
func FuzzInclusionProofAndVerify(f *testing.F) {
for size := 0; size <= 8; size++ {
for index := 0; index <= size; index++ {
f.Add(uint64(index), uint64(size))
}
}
f.Fuzz(func(t *testing.T, index, size uint64) {
if size >= math.MaxUint16 {
return
}
t.Logf("index=%d, size=%d", index, size)
if index >= size {
return
Expand All @@ -70,6 +78,9 @@ func FuzzHashAtAgainstReferenceImplementation(f *testing.F) {
}
}
f.Fuzz(func(t *testing.T, index, size uint64) {
if size >= math.MaxUint16 {
return
}
t.Logf("index=%d, size=%d", index, size)
if index >= size {
return
Expand All @@ -91,6 +102,9 @@ func FuzzInclusionProofAgainstReferenceImplementation(f *testing.F) {
}
}
f.Fuzz(func(t *testing.T, index, size uint64) {
if size >= math.MaxUint16 {
return
}
t.Logf("index=%d, size=%d", index, size)
if index >= size {
return
Expand Down

0 comments on commit 0b6d7ff

Please sign in to comment.