dvyukov / go-fuzz

Randomized testing for Go
Apache License 2.0
4.78k stars 279 forks source link

go-fuzz-build: `could not find any fuzz functions` #285

Closed xaionaro closed 4 years ago

xaionaro commented 4 years ago

I'm trying to do step-by-step it by instruction, but I get error could not find any fuzz functions, instead.

[xaionaro@void fit]$ go-fuzz-build
could not find any fuzz functions in experimental/xaionaro/pcr0/pkg/uefi/fit
[xaionaro@void fit]$ cat get_entries_fuzz_test.go 
// +build gofuzz

package fit_test

import (
        fianoUEFI "github.com/linuxboot/fiano/pkg/uefi"

        . "experimental/xaionaro/pcr0/pkg/uefi/fit"
)

func Fuzz(firmwareBytes []byte) int {
        firmware, err := fianoUEFI.Parse(firmwareBytes)
        if err != nil {
                return 0
        }

        _, err = GetEntries(firmware)
        if err != nil {
                return 0
        }

        return 1
}
[xaionaro@void fit]$ pwd
/home/xaionaro/go-hidden/src/experimental/xaionaro/pcr0/pkg/uefi/fit
[xaionaro@void fit]$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xaionaro/.cache/go-build"
GOENV="/home/xaionaro/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xaionaro/go-hidden:/home/xaionaro/go-hidden-3rdparty:/home/xaionaro/go:/home/xaionaro/hidden-gen"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/xaionaro/.gimme/versions/go1.13.linux.amd64"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/xaionaro/.gimme/versions/go1.13.linux.amd64/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build958101203=/tmp/go-build -gno-record-gcc-switches"
josharian commented 4 years ago

Put your Fuzz function in a non-_test.go file. You can use build tags to prevent it from being compiled in regular builds.

xaionaro commented 4 years ago

It helped. Thank you.