-
Notifications
You must be signed in to change notification settings - Fork 37.7k
fuzz: Introduce CallOneOf helper to replace switch-case #20828
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
Conversation
I'll update the remaining fuzz targets once this has one or two Concept ACKs |
Concept ACK.
It will be tedious to review only this pull :) |
fa22d21
to
fa68ea5
Compare
Concept ACK!
With ignored whitespace ( |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
fa68ea5
to
fa56269
Compare
Concept ACK. Where a case statement previously had a I'm not a fan of "Fuzz input format might already change implicitly on every commit, so this isn't something worthwhile to pursue." -- changing the fuzz input format invalidates the code coverage of the qa assets corpus, so it seems like we should try to minimise fuzz input format changes to me. But I think this makes dealing with that easier anyway: to have it behave stably when cases are added or removed I think you could do something like: const size_t call_index{ConsumeIntegral<size_t>}();
if (call_index < size) return callables[call_index](); and have an I was kind of expecting to see a recursive template function here -- something like: template<typename... Cases>
void CallOneOf(size_t selection, Cases... cases);
template<typename T, typename... Cases>
void CallOneOf(size_t selection, T case0, Cases... cases)
{
if (selection == 0) return case0();
else return CallOneOf(selection - 1, cases...);
}
template<>
void CallOneOf(size_t selection) { return; }
template<typename... Cases>
void CallOneOf(FDP& fdp, Cases... cases) {
size_t call_index = fdp.ConsumeIntegral<size_t>();
return CallOneOf(call_index, cases...);
} Not sure the |
Good point, but a
Ok, I see that my pull doesn't solve the question whether seeds should be invalidated or not. Maybe it is best to answer this in a separate discussion. Before it was possible to invalidate or not invalidate seeds on a case-by-case basis and with this pull, it is possible, too. Edit: Let's discuss this in #20837 .
|
0afca24
to
fa12a5d
Compare
Removed |
Strong concept ACK. Thanks for doing this! Merge conflicts in the fuzz files seem to be very common, so eliminating the majority of them in this way would be a big win. |
For a second I thought you were adding Call of Duty into bitcoin. This is a great idea. Concept ACK. |
This is much more elegant! Concept/quick skim code review ACK. |
Concept ACK: much better! Thanks! Will review. |
Can be reviewed with --ignore-all-space
fa12a5d
to
fa75d40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK.
const size_t call_index{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, call_size - 1)}; | ||
|
||
size_t i{0}; | ||
return ((i++ == call_index ? callables() : void()), ...); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent. Thanks for doing this @MarcoFalke!
utACK fa75d40
Call of Duty is already being fuzzed: https://twitter.com/NedWilliamson/status/1348432573836349441 |
When using the Example (all using the same fixed seed input in the form of a finite scream
One trick that can be used to tackle this is to choose from a larger range such as That way we'll only have to invalidate existing seeds when we've exhausted the entire range In other words: instead of invalidating every time we add a new Perhaps that strategy could be incorporated in this PR? |
The pr is tagged with "refactoring", so behaviour changes are not allowed. The suggestion can be discussed in #20837 and addressed in a follow-up pull request. The changes should be trivial based on this pr. |
ACK fa75d40 - code review only |
The current
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, nn)) { case 0: ... case 1: ... case nn: ...
has several problems:Updating the target raises the question whether the case labels should be preserved to not invalidate the existing fuzz inputs format. Fuzz input format might already change implicitly on every commit, so this isn't something worthwhile to pursue.Edit: This pull doesn't fix this problem.Fix all issues by adding a new
CallOneOf
helper