-
Notifications
You must be signed in to change notification settings - Fork 18.1k
proposal: add package containing fuzz function helpers #46268
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
Comments
This seems like a good idea, but it seems to me not inherently tied to fuzzing. CheckTextMarshaler could be used to test any implementation, randomly generated or not, the same way that we have testing/fstest and testing/iotest: those are for testing arbitrary implementations. If we supplied a function that returns an error instead of panicking, then it could be used in other contexts besides fuzzing where it might be just as useful. So the question is: how much are these things really specific to fuzzing? Should they be written in a more general way (in particular, returning an error instead of panicking) so that they can be used beyond that use case? And what other kinds of helpers did you have in mind besides interface implementation checks? I should add that putting everything into a 'package fuzztest' doesn't seem like it makes sense. We should want packages that define the interfaces to define the tests, or at least to have the tests defined near them, not in a central place. |
This proposal has been added to the active column of the proposals project |
For a Given an http.Handler, feed it a wide variety of requests. Dmitry might have other ideas. From the above, it looks like mostly interface implementation checks. :) |
It's entirely possible that people writing text marshalling/unmarshalling methods are doing to on type with unexported fields. Is there a way to capture that as well? or is that just something that should be documented as out of scope? |
Does this work on the std lib types? Especially re Dan's concern re unexported fields. |
This was the thinking behind my parenthetical in the OP: "(This would probably benefit from generics and/or a testing comparison function such as proposed in #45200.)" With generics, we could use ==, which is a narrower definition than reflect.DeepEqual. #45200 would give us the tools to express a great many more notions of equality.
I believe so, as you wrote and ran fuzzers for most of them that used checks like this. :) But it'd be worth double-checking.
I presume you mean unmarshaling. Hmm, yes, good point. The advantage to writing it this way is that it is useful for other ways of constructing an object (e.g. table-driven tests). I'm not too worried about unexported fields, as I expect this would mainly be used from within the same package. I've been using prototypes of these helpers in netaddr, and I do a parse before calling these checks. But for fuzzing, doing the checks directly from bytes would be better. |
Ah yes, the other advantage to writing it this way is if there are values that cannot be constructed via UnmarshalText, but can be constructed programatically. You want to be able to test those. |
Then it indeed looks like what Russ said re being not-fuzzing-specific. |
Nothing comes to mind so far. This is indeed very common and useful pattern, but it frequently looked a bit differently due to small differences in interfaces (encoding/, compress/, image/*). And these round-trippers are not TextMarshaller nor BinaryMarshaller. Overall I would wait until we have a set of cases where we know it's applicable as is, and if we introduce a new package I think we need some plan for having more than 1 function there (otherwise it may just go into testing maybe?). |
It sounds like people agree that these are not really limited to fuzzing and that we should not tie them to it. Today we have testing/iotest and testing/fstest. We could keep adding subdirectories of testing, but we might end up repeating the entire std hierarchy, and it doesn't set much of a pattern for external repos. So what should we do? We could establish a convention of adding Check functions in the actual packages that define the interfaces, or in packages nearby (io/fs/fstest or image/imagetest or something like that). For interface-only packages which typically try to have very few dependencies (like encoding), we will want separate packages. For larger packages it might be fine to put the checkers into the main package, but it might also be nice to isolate them in subdirectories, just to keep the APIs separate. We already have net/http/httptest, and the subdirectory there was not motivated by trying to keep net/http's dependencies light. Maybe we should follow that example and just have foo/footest for checkers and other helpers? |
Something I hope will come from the native fuzzing support is getting over the idea that fuzzers should panic. A panic also leads to a test failure, but we use Testing toolkits and interface tests are great, and should return errors, so they can be used both with tests and with fuzz targets.
I have a collection of these is the golang.org/x/crypto/cryptotest package I never finished :) |
It sounds like we are converging on using foo/footest as the place to put testing helpers, like net/http/httptest. Is that the general consensus? If so, then probably this specific proposal should be declined and we can discuss specific test packages and APIs in other proposal issues. |
SGTM. I would like to add that this is the proposal process at its best: My rather crude idea has, with input from others, been shaped into something far better. |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
Uh oh!
There was an error while loading. Please reload this page.
There are some common fuzzing patterns that:
I propose we add a std package containing some such helpers, perhaps with import path testing/fuzz or testing/fuzzcheck.
Here's a sample function:
(This would probably benefit from generics and/or a testing comparison function such as proposed in #45200.)
Other good helper functions include any kind of custom encoding method (binary encoding, JSON encoding, gob) and checks that
String()
methods don't panic. We could use this issue as a place to note other ideas.We could even have a meta "CheckAll" function that uses type assertions and runs all relevant checks. This would make many common fuzz functions a few lines at most.
cc @katiehockman @dvyukov
The text was updated successfully, but these errors were encountered: