go-fuzz: Compilation fails: Functions are undefined

Hi!

I’m not a golang pro, but I feel like I’m going crazy. I try to compile a fuzz case for a geth component. There are already some cases implemented in the code namely: https://github.com/ethereum/go-ethereum/blob/master/core/vm/runtime/fuzz.go. I wrote a different case with this code:

// +build gofuzz

package p2p

func Fuzz(data []byte) int {
        closer, rw, p, _ := testPeer(nil)
        defer closer()
        if err := Senditems(rw, &data, data); err != nil {
                return 0;
        }
        return 1
}

I placed the fuzz.go file in the p2p subdirectory. testpeer and SendItems are defined in the peer_test.go and message.go in the same directory (p2p) and package. While I can indeed compile the already added fuzz case with ~/go/bin/go-fuzz-build -tags nocgo github.com/ethereum/go-ethereum/core/vm/runtime I can’t compile with

~/go/bin/go-fuzz-build -tags nocgo github.com/ethereum/go-ethereum/p2p
failed to execute go build: exit status 2
# github.com/ethereum/go-ethereum/p2p
p2p/Fuzz.go:6:22: undefined: testPeer
p2p/Fuzz.go:8:12: undefined: Senditems

I really don’t understand how this is not working… The fuzzcase inside the geth package doesn’t seem to make anything different. Please help me understand.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

*_test.go files are compiled only into tests, they are not part of normal build. That’s why testPeer is not in the package. And Senditems is named SendItems, not Senditems: https://github.com/ethereum/go-ethereum/blob/89a32451aeb418db3fd5d9c427a0c29fddb1e85b/p2p/message.go#L109

Since you are giving an additional tag (-tags nocgo) I wonder if these functions are in fact not implemented with the tag. Try to build it with go build and with the tag.