-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[WIP] fuzz: parsing support for #[fuzz]
and #[fuzz_param]
attributes
#7354
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
base: master
Are you sure you want to change the base?
Conversation
#[fuzz]
and #[fuzz_param]
attributes**#[fuzz]
and #[fuzz_param]
attributes**
#[fuzz]
and #[fuzz_param]
attributes**#[fuzz]
and #[fuzz_param]
attributes
CodSpeed Performance ReportMerging #7354 will not alter performanceComparing Summary
|
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.
Awesome to see fuzzing coming to life 💪 ❤️
Just a small remark, we have a standardize way of testing attributes.
To adapt tests in this PR, please take a look at should_pass/language/attributes_all_in_one
tests. For failing tests that test multiplicity etc., please take a look at should_fail/attributes_invalid_...
tests.
Essentially, the separate tests from this PR should be added to those standard tests.
If there is a special logic to be tested, e.g., no #[test]
and #[fuzz]
attribute together, only then a dedicated test needs to be added. For this we also have examples, like, e.g., attributes_cfg_mismatching_program_type
and several other tests.
Sounds great, will move the tests. I am more in experimenting phase, opened the PR to just talk over it. Curious to see if you have a preference on how we should enable this? Like should this be an attribute as in this PR or should this interface move to Forc.toml |
Personally, I am for fixture-based approach where fuzzing is just one of the possible ways to parameterize tests. And everything is attribute-defined. A good example of this would be rstest in Rust. This is IMO the most general approach that can be stepwise taken in all directions we want, based on the community input and need. (It is a pity that we don't have macros like Rust and need to implement these attributes in the compiler/tooling, but that's a whole other topic.) If we go with fixture-based approach (with only attributes implemented at first being #[test] // This is mandatory.
#[case(0, 0)] // Fixed case we are particularly interested in.
#[fuzz(a_iterations = 10, b_min = 42, b_max = 84)] // Additional test casess based on fuzzing input.
fn test(a: u64, b: u64) { ... } Note that in this case we don't need |
DISCLAIMER
Currently still experimenting, will come up with the RFC once that I have a more robust mindset around how to expose this to the user.
This PR adds parsing infrastructure for fuzz testing attributes in preparation for future fuzzing capabilities. The implementation follows the same patterns as existing
#[test]
attributes.Changes
FUZZ_ATTRIBUTE_NAME
,FUZZ_PARAM_ATTRIBUTE_NAME
and parameter namesFuzz
andFuzzParam
enum variants with proper validationis_test_function()
to include fuzz functionsUsage Examples
Basic fuzz function:
With parameters:
Implementation Notes
#[test]
and#[fuzz]
attributes#[fuzz]
attribute expects no arguments (similar to#[test]
)#[fuzz_param]
supportsname
,iteration
,min_val
,max_val
arguments#[fuzz_param]
attributes allowed per function#[fuzz]
attribute per functionTesting
Added comprehensive test coverage: