Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing, internal/fuzz: Support -c flag #52169

Closed
AdamKorcz opened this issue Apr 5, 2022 · 4 comments
Closed

testing, internal/fuzz: Support -c flag #52169

AdamKorcz opened this issue Apr 5, 2022 · 4 comments

Comments

@AdamKorcz
Copy link

When building a native fuzzer with the -c flag, a unit test is built.

For example, I have a simple fuzzer:

package fuzz

import (
        "fmt"
        "testing"
)

func Fuzz(f *testing.F) {
        f.Fuzz(func(t *testing.T, data string) {
                fmt.Println(data)
        })
}

I build it with go test -fuzz=Fuzz -c
...which gives me the fuzz.test executable.
Running that executable with ./fuzz.test prints out: PASS

This may be intended, but it would be highly desirable to offer support for building an executable that can be run with the same flags as go test -fuzz=Fuzz.

@seankhliao
Copy link
Member

You need to pass the fuzz flags (like any other test flags) to the built binary, not to the build command.

For questions please refer to https://github.com/golang/go/wiki/Questions

@AdamKorcz
Copy link
Author

./fuzz.test -test.fuzztime 20s also prints out PASS

@seankhliao
Copy link
Member

./fuzz.test -test.fuzz=Fuzz

@AdamKorcz
Copy link
Author

AdamKorcz commented Apr 5, 2022

./fuzz.test -test.fuzz=Fuzz

Thank you. That is partially correct. The result of that command alone is:

testing: -test.fuzzcachedir must be set if -test.fuzz is set
Usage of ./fuzz.test:                                                                     
  -test.bench regexp                                                                      
        run only benchmarks matching regexp
  -test.benchmem                                                                          
        print memory allocations for benchmarks  
  -test.benchtime d                                                                                                                                                                  
        run each benchmark for duration d (default 1s)
  -test.blockprofile file                                                                 
        write a goroutine blocking profile to file                           
  -test.blockprofilerate rate
        set blocking profile rate (see runtime.SetBlockProfileRate) (default 1)
  -test.count n                                                                           
        run tests and benchmarks n times (default 1)                                                                                                                                 
  -test.coverprofile file
        write a coverage profile to file
  -test.cpu list
        comma-separated list of cpu counts to run each test with
  -test.cpuprofile file
        write a cpu profile to file
  -test.failfast
        do not start new tests after the first test failure
  -test.fuzz regexp
        run the fuzz test matching regexp
  -test.fuzzcachedir string
        directory where interesting fuzzing inputs are stored (for use only by cmd/go)
  -test.fuzzminimizetime value
        time to spend minimizing a value after finding a failing input (default 1m0s)
  -test.fuzztime value
        time to spend fuzzing; default is to run indefinitely
  -test.fuzzworker
        coordinate with the parent process to fuzz random values (for use only by cmd/go)
  -test.list regexp
        list tests, examples, and benchmarks matching regexp then exit
  -test.memprofile file
        write an allocation profile to file
  -test.memprofilerate rate
        set memory allocation profiling rate (see runtime.MemProfileRate)
  -test.mutexprofile string
        write a mutex contention profile to the named file after execution
  -test.mutexprofilefraction int
        if >= 0, calls runtime.SetMutexProfileFraction() (default 1)
  -test.outputdir dir
        write profiles to dir
  -test.paniconexit0
        panic on call to os.Exit(0)
  -test.parallel n
        run at most n tests in parallel (default 5)
  -test.run regexp
        run only tests and examples matching regexp
  -test.short
        run smaller test suite to save time
  -test.shuffle string
        randomize the execution order of tests and benchmarks (default "off")
  -test.testlogfile file
        write test action log to file (for use only by cmd/go)
  -test.timeout d
        panic test binary after duration d (default 0, timeout disabled)
  -test.trace file
        write an execution trace to file
  -test.v
        verbose: print additional output

And as is mentioned on the first line, if we create an empty directory and run ./fuzz.test -test.fuzz=Fuzz -test.fuzzcachedir $PWD/cachedir/, then it works.

Thank you very much for the quick reply, @seankhliao

@golang golang locked and limited conversation to collaborators Apr 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants