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

[dev.fuzz] cmd/go: don't run the other tests if -fuzz is specified #46222

Closed
katiehockman opened this issue May 18, 2021 · 4 comments
Closed
Labels
FrozenDueToAge fuzz Issues related to native fuzzing support NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@katiehockman
Copy link
Contributor

The current behavior of go test when -fuzz is specified is to run all of the unit tests, examples, and benchmarks first, then start fuzzing only if all the other tests succeed. The reason behind this is that if a new bug has been introduced and an existing test would already catch this issue, then attempting to discover and report a "new" crasher could end up being redundant to the existing tests. Thus, fuzzing only begins once the go command has exhausted all other ways of finding a bug.

However, if there are a lot of other tests, this can delay the start of fuzzing in a way that may surprise developers. When I ran fuzz targets locally, I often found myself wanting to execute something like
go test -run=FuzzFoo -fuzz=FuzzFoo

We may want to consider changing the default behavior based on user experience feedback.

@katiehockman katiehockman added the fuzz Issues related to native fuzzing support label May 18, 2021
@katiehockman katiehockman added this to the Backlog milestone May 18, 2021
@katiehockman katiehockman added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 18, 2021
@iand
Copy link
Contributor

iand commented Aug 3, 2021

I would expect fuzzing to work like benchmarks, i.e. run the tests first unless I disable them (-run=^$ or similar)

@rsc
Copy link
Contributor

rsc commented Sep 1, 2021

Strong agree with @iand.

Fuzzing and benchmarks have in common that you end up making changes that may actually cause unintended breakages. You want to find that out sooner rather than later (your results stop being valid at the point where you break the code), so the tests should be run by default.

This is the right behavior even if user feedback complains about it. You are not hearing from the users who are helped by this, who have not lost hours and hours to fuzzing (or benchmarking) broken code.

@rsc
Copy link
Contributor

rsc commented Sep 2, 2021

Not sure if @jayconrod filed another issue, but it would make sense to check whether a fuzz test matches the -fuzz pattern and if so not run just that one test function as an ordinary test case, because that duplicates work and also because the fuzzing harness can do a better job with infinite loops.

@katiehockman
Copy link
Contributor Author

Skipping the fuzz target as an ordinary test case seems like a reasonable option. I didn't see a bug filed for this, so I went ahead and filed one: #48296

I am considering this new issue lower priority since it's more of an optimization than a bug, so not a release-blocker. The seed corpus will get run either way, it's just that we can likely make it so that they are only run once (by the fuzz workers) instead of as a typical unit test. But we'll try to get it done before the release. Comment on that bug if you disagree, though.

I'll close this original bug since it sounds like we're all in agreement that we shouldn't skip all other tests when fuzzing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge fuzz Issues related to native fuzzing support NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
Status: No status
Development

No branches or pull requests

4 participants