dvyukov / go-fuzz

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

README guide not working correctly #317

Open huornlmj opened 3 years ago

huornlmj commented 3 years ago

From the front page readme, the following section fails:

  1. $ go get -d github.com/dvyukov/go-fuzz-corpus
  2. $ cd $GOPATH/src/github.com/dvyukov/go-fuzz-corpus

Line 2 yields: "No such file or directory"

cristaloleg commented 3 years ago

What is your $GOPATH ?

huornlmj commented 3 years ago

/home/{me}/go

thepudds commented 3 years ago

Try cd ~/go/src/github.com/dvyukov/go-fuzz-corpus (or something similar to that if you happen to be on windows).

thepudds commented 3 years ago

Also, if you are using Go modules, you might need to use git clone.

huornlmj commented 3 years ago

I can get as far as ~/go/src/github.com and I see plenty of component directories that I have used over time (e.g. BurntSushi, go-logr, eclipse, google, hashicorp etc. etc) but no dvyukov directory. There was no error or output when I ran "go get -d github.com/dvyukov/go-fuzz-corpus". I ran "echo $?" just to see the go get return code and it was 0.

cristaloleg commented 3 years ago

Try GO111MODULE=auto go get -d github.com/dvyukov/go-fuzz-corpus

Sadly there is a 'problem' with fetching deps with go get and modules.

UPD: GO111MODULE=off should work too, outside the $GOPATH. I'm trying to find exact line regarding naive fetch of deps here but haven't yet https://github.com/golang/go/wiki/Modules

huornlmj commented 3 years ago

BTW -this is a on a fresh Go installation, following the steps in https://github.com/dvyukov/go-fuzz/blob/master/README.md#L101

huornlmj commented 3 years ago

I tried manually git cloning the go-fuzz-corpus and running go-fuzz-build within the png directory only to get:

could not resolve package ".": go [-e -json -compiled=false -test=false -export=false -deps=false -find=true -tags gofuzz -- .]: exit status 1: go: cannot find main module, but found .git/config in /home/jason/fuzzing/go-fuzz/go-fuzz-corpus
        to create a module there, run:
        cd .. && go mod init

My env:

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/jason/go/bin"
GOCACHE="/home/jason/.cache/go-build"
GOENV="/home/jason/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jason/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jason/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.16"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.16/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build1559716842=/tmp/go-build -gno-record-gcc-switches"
msooseth commented 1 year ago

Hi,

I'm having trouble too. Managed to get a bit further. Some helpful stuff below:

The directory that eventually gets created is $GOPATH/pkg/mod/github.com/dvyukov/go-fuzz-corpus@v0.0.0-20190920191254-c42c1b2914c7/. So that needs to be updated in the README. Then the png directory is under there. Once I'm in the png directory, running go-fuzz-build produces:

could not resolve package ".": err: exit status 1: stderr: go: go.mod file not found in current directory or any parent directory; see 'go help modules'

Indeed, no go.mod files to be found anywhere: find ../ | grep go.mod produces empty output. However, the checkout seems fine, e.g. the png directory contains:

$ ls -lah
total 36K
dr-xr-xr-x  4 matesoos matesoos 4.0K Jan 19 13:56 .
dr-xr-xr-x 73 matesoos matesoos 4.0K Jan 19 13:56 ..
dr-xr-xr-x  2 matesoos matesoos  20K Jan 19 13:56 corpus
dr-xr-xr-x  2 matesoos matesoos 4.0K Jan 19 13:56 gen
-r--r--r--  1 matesoos matesoos  978 Jan 19 13:56 png.go

Which seems reasonable.

If I try the GO111MODULE=off hack from under png then:

$ export GO111MODULE=off
$ go-fuzz-build         
-: cannot find package "github.com/dvyukov/go-fuzz/go-fuzz-dep" in any of:
        /usr/lib/go/src/github.com/dvyukov/go-fuzz/go-fuzz-dep (from $GOROOT)
        /home/matesoos/go/src/github.com/dvyukov/go-fuzz/go-fuzz-dep (from $GOPATH)
typechecking of . failed

Note that /home/matesoos/go/src/github.com/dvyukov/go-fuzz/go-fuzz-dep is wrong, because the src directory doesn't even exist. As mentioned above, the command go get -d github.com/dvyukov/go-fuzz-corpus will download the source here: $GOPATH/pkg/mod/github.com/dvyukov/go-fuzz-corpus@v0.0.0-20190920191254-c42c1b2914c7/

Maybe the README needs to be revamped to match how go (and go-fuzz?) has changed over the years?