-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/go: allow fuzzing multiple targets per package #46312
Comments
For reference, the I think |
I feel like running multiple fuzz targets concurrently is just asking for trouble (e.g. races). Though I guess if each is in it's own process, maybe the risk of that isn't actually that high. We also have to decide what to do if someone wants to fuzz 10 targets at once but only use 3 processes. At that point we'll have to run them sequentially/in a round anyway. I think it will be simpler and equally efficient to just run each target for some period of time in a round. For example, we run each target for 3 seconds before moving to the next, and so on, until we're back at the first target, then repeat. I don't see a compelling reason why the "time to run each target before moving to the next" needs to be user-configurable, but LMK if you can think of a reason. |
Change https://golang.org/cl/350156 mentions this issue: |
Until we have a system for managing load across multiple fuzz targets in multiple test executables, we'll only support fuzzing one target in one package at a time. Users can still run multiple 'go test -fuzz' commands concurrently, but this may overwhelm some systems unless -parallel and -p are set carefully. For #46312 Change-Id: If84c58d1b3e60498ce955eae5ad4d52100dbd4b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/350156 Trust: Jay Conrod <jayconrod@google.com> Trust: Katie Hockman <katie@golang.org> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
OK that is getting weird now: Are you now supposed to iterate over the list of fuzzable packages yourself? Useful CI systems usually run go ACTION ./... for any major action the go command offers. If that is not possible, could you at least provide some way to create the full list of fuzz parallel jobs with the sequential lists of each fuzz function? That together with a max fuzz time would allow CI systems to express the resource budgets itself. |
For now. This isn't necessarily the long term solution for fuzzing. It's just a safety measure that's in place now until we can build this out effectively.
That might be possible. We'll take a look and see if we can provide something like this before 1.18. |
Here's the quick-n-dirty bash solution: #!/bin/bash
set -e
fuzzTime=${1:-10}
files=$(grep -r --include='**_test.go' --files-with-matches 'func Fuzz' .)
for file in ${files}
do
funcs=$(grep -oP 'func \K(Fuzz\w*)' $file)
for func in ${funcs}
do
echo "Fuzzing $func in $file"
parentDir=$(dirname $file)
go test $parentDir -run=$func -fuzz=$func -fuzztime=${fuzzTime}s
done
done |
Here's an updated script that works a little more broadly
|
@benjivesterby does grep actually support a -P flag? ran this on macos and run into: grep: invalid option -- P
usage: grep [-abcdDEFGHhIiJLlMmnOopqRSsUVvwXxZz] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...] |
this is what i use on MacOS
|
Currently,
go test
only allows fuzzing one target per package. So if packageexample.com/a
has targetsFuzz1
andFuzz2
, this command fails:(Actually, it still exits zero without fuzzing, which is probably bad, too).
If multiple packages have individual fuzz targets, that's okay though:
This seems a little strange. We should decide to either allow one fuzzing target globally across all matched packages on the
go test
command line, or allow multiple targets per package and fuzz them all in parallel.The text was updated successfully, but these errors were encountered: