I want to build a fuzztest as a standalone binary, for usage in a docker container.
However, the binary complains that the test binary was not built with coverage instrumentation, so fuzzing will run without coverage guidance and may be inefficient
.
I want to enable the coverage instrumentation.
Example test:
package main
import (
"bytes"
"crypto/sha256"
"testing"
)
func FuzzFoobar(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
// Invoke some arbitrary methods
data = sha256.New().Sum(bytes.ToLower(data))
if len(data) == 0 {
panic(1)
}
})
}
Running it regularly works fine:
$ go test . -fuzz Foo
fuzz: elapsed: 0s, gathering baseline coverage: 0/66 completed
fuzz: elapsed: 0s, gathering baseline coverage: 66/66 completed, now fuzzing with 8 workers
^Cfuzz: elapsed: 3s, execs: 107197 (39642/sec), new interesting: 8 (total: 74)
Compiling it yields complaint:
$ go test -c .
$ ./testfuzz.test -test.fuzz=Foo -test.fuzzcachedir=/tmp
warning: the test binary was not built with coverage instrumentation, so fuzzing will run without coverage guidance and may be inefficient
warning: starting with empty corpus
fuzz: elapsed: 0s, execs: 0 (0/sec)
If I try to use the -cover
when compiling, it does not help either:
$ go test -cover -c .
$ ./testfuzz.test -test.fuzz=Foo -test.fuzzcachedir=/tmp
warning: the test binary was not built with coverage instrumentation, so fuzzing will run without coverage guidance and may be inefficient
warning: starting with empty corpus
fuzz: elapsed: 0s, execs: 0 (0/sec)