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

Switch to cargo-fuzz #261

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

uncomputable
Copy link
Collaborator

Adapt the fuzzing infrastructure to use cargo-fuzz. I keep the existing shell scripts because they turned out to be useful.

Everything should work as before, except that the fuzzing flag is producing warnings when the tests are run. Let's discuss solutions here.

@apoelstra
Copy link
Collaborator

Can you update the lockfiles as suggested by CI?

Everything should work as before, except that the fuzzing flag is producing warnings when the tests are run. Let's discuss solutions here.

What kind of warnings?

@uncomputable
Copy link
Collaborator Author

warning: unexpected `cfg` condition name: `fuzzing`
 --> fuzz/fuzz_targets/parse_human.rs:3:13
  |
3 | #![cfg_attr(fuzzing, no_main)]
  |             ^^^^^^^
  |
  = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows`
  = help: consider using a Cargo feature instead
  = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
           [lints.rust]
           unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }
  = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(fuzzing)");` to the top of the `build.rs`
  = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
  = note: `#[warn(unexpected_cfgs)]` on by defaul

@uncomputable
Copy link
Collaborator Author

I fixed the normal CI, but the fuzz test CI seems to be disabled. Investigating.

@uncomputable uncomputable force-pushed the 2025-01-cargo-fuzz branch 3 times, most recently from 32591e2 to 3625437 Compare January 23, 2025 14:16
The file is not executed yet.

I upgraded upload-artifact and download-artifact from v3 to v4 because
v3 has been deprecated and automatically fails.

I upgraded cache from v3 to v4 because v3 is scheduled for deprecation
on 2025-02-01.
`bash fuzz/generate.sh`

`cargo update && cp Cargo.lock Cargo-recent.lock`
using the MSRV-aware resolver from Rust 1.84.0:
https://blog.rust-lang.org/2025/01/09/Rust-1.84.0.html

Rewrite each fuzz target to work with cargo-fuzz. Crash seeds are
displayed in base 64, so use that inside duplicate_crash() tests.

cargo-fuzz has special entry points for its fuzz tests, which is why
every fuzz target is prefixed with #![no_main]. However, this breaks
our unit tests that live inside the same file, presumably because unit
tests need a normal entry point. My solution is conditionally include
the fuzzing code when the `fuzzing` flag is set. This works with
`cargo-fuzz run` and with cargo test for the unit tests. Unfortunately,
`fuzzing` seems to be a nonstandard flag which produces a warning. The
absence of a main method also breaks `cargo clippy` inside the `fuzz`
directory. I will post the commit as is so we can discuss solutions on
GitHub.
Use cargo-fuzz instead of hongfuzz.
Make the scripts more readable.
We switched to cargo-fuzz and no longer need this.
@uncomputable
Copy link
Collaborator Author

Fuzzing CI works now :) I had to update the upload-artifact and download-artifact actions because of deprecation. I also updated the cache action because it will be deprecated soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants