Skip to content

Commit

Permalink
cmd/go: add fuzzing coverage test
Browse files Browse the repository at this point in the history
Adds a test script for fuzzing coverage instrumentation.

Fixes #48654

Change-Id: Ieea7b4146bd5581baae869441cc1c652dd7485f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/375736
Trust: Katie Hockman <[email protected]>
Reviewed-by: Katie Hockman <[email protected]>
Trust: Roland Shoemaker <[email protected]>
Run-TryBot: Roland Shoemaker <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
rolandshoemaker committed Jan 5, 2022
1 parent 88cafe0 commit 2b39d86
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/cmd/go/testdata/script/test_fuzz_cov.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Test that coverage instrumentation is working. Without the instrumentation
# it is _extremely_ unlikely that the fuzzer would produce this particular
# input in any reasonable amount of time.

[short] skip
[!fuzz-instrumented] skip

! go test -fuzz=FuzzCov
! stderr 'cov instrumentation working'

-- go.mod --
module test

-- cov_test.go --
package cov

import "testing"

func FuzzCov(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
if len(b) == 8 &&
b[0] == 'h' &&
b[1] == 'e' &&
b[2] == 'l' &&
b[3] == 'l' &&
b[4] == 'o' &&
b[5] == ' ' &&
b[6] == ':' &&
b[7] == ')' {
panic("cov instrumentation working")
}
})
}

0 comments on commit 2b39d86

Please sign in to comment.