Closed teymour-aldridge closed 3 years ago
Hi Teymour! I'm terribly sorry, again, for the bugs. This one should be easy to fix, I'll get back to you later today or tomorrow :)
in the meantime, if you move the tests to a lib.rs
file instead of main.rs
, it might fix it. There's an option in the latest cargo-fuzzcheck to fuzz-test non-library targets, but I haven't released that yet I think
The previous version of cargo fuzzcheck
would always call
cargo test --lib ... # other arguments
which would only compile the crate’s library. But if your fuzz tests are in an executable (main.rs
) or integration tests (inside tests
folder), then that wouldn't work.
In the newest cargo fuzzcheck
(version 0.8.0, which I've just released), the command that is called instead is simply cargo test
, which compiles everything. That's actually not great either, since it might compile other stuff that doesn't depend on fuzzcheck and then will complain that there is a missing runtime for -Zinstrument-coverage
. I should come up with a proper solution for it, but for now, you can use a new option: --cargo-args
which passes extra arbitrary options to the cargo test
invocation.
So you can do:
cargo fuzzcheck tests::fuzz fuzz --cargo-args="--lib"
which will run cargo test --lib ...
to specifically compile/test only the library target.
Or:
cargo fuzzcheck tests::fuzz fuzz --cargo-args="--bins"
which will run cargo test --bins ...
to compile/test only the executables.
As an aside, I see that you are using grammar-based string mutators, which is nice! But you should be aware of a few drawbacks:
repetition!
because of a bug I'm hoping to fix sooncargo fuzzcheck tests::fuzz tmin ...
to minify a failing test case, you might enter an infinite loop where the fuzzer thinks it's making progress but is actually stuck. It will still minify the input, but not as much or as quickly as it should.I've started writing a guide at https://fuzzcheck.neocities.org , which is in a pretty rough shape at the moment. But it already contains a section on how to write a grammar-based fuzz test on pulldown-cmark
. Because the grammar for that test is too ambiguous, I choose instead to generate values of type (AST, String)
. That way, fuzzcheck’s parser is not involved and the grammar can be as complicated as you want.
And finally, I have unfortunately changed the API to launch a fuzz test again. Look at the final code at https://fuzzcheck.neocities.org/example2_fuzzing.html (or other examples) to see how to use it.
No worries about the bugs – thank you for all your help resolving them :)
It works!
running 1 test
test fuzz::test_fuzz_parser ... START
NEW 1 high_cov_hits(1 sum: 654) uniq_cov(0 cov: 0.00% cplx: 0.00) artifacts(0) iter/s: 273
NEW 1 high_cov_hits(0 sum: 0) uniq_cov(1 cov: 63.16% cplx: 676.00) artifacts(0) iter/s: 227
NEW 1 high_cov_hits(0 sum: 0) uniq_cov(0 cov: 0.00% cplx: 0.00) artifacts(0) iter/s: 213
NEW 1 high_cov_hits(0 sum: 0) uniq_cov(0 cov: 0.00% cplx: 0.00) artifacts(0) iter/s: 197
RPLC 1 2 high_cov_hits(1 sum: 2146) uniq_cov(1 cov: 63.16% cplx: 676.00) artifacts(0) iter/s: 102
RPLC 1 2 high_cov_hits(1 sum: 654) uniq_cov(1 cov: 63.16% cplx: 676.00) artifacts(0) iter/s: 87
RPLC 1 3 high_cov_hits(1 sum: 2146) uniq_cov(1 cov: 63.16% cplx: 135.00) artifacts(0) iter/s: 100
RPLC 1 3 high_cov_hits(1 sum: 2146) uniq_cov(1 cov: 63.16% cplx: 676.00) artifacts(0) iter/s: 96
NEW 4 high_cov_hits(2 sum: 2150) uniq_cov(1 cov: 63.16% cplx: 135.00) artifacts(0) iter/s: 89
NEW 4 high_cov_hits(1 sum: 2146) uniq_cov(2 cov: 84.21% cplx: 579.50) artifacts(0) iter/s: 86
RPLC 1 4 high_cov_hits(1 sum: 2146) uniq_cov(1 cov: 63.16% cplx: 135.00) artifacts(0) iter/s: 82
RPLC 1 6 high_cov_hits(2 sum: 2652) uniq_cov(2 cov: 84.21% cplx: 579.50) artifacts(0) iter/s: 84
NEW 6 high_cov_hits(2 sum: 2150) uniq_cov(3 cov: 94.74% cplx: 1372.33) artifacts(0) iter/s: 83
RPLC 1 6 high_cov_hits(2 sum: 2150) uniq_cov(2 cov: 84.21% cplx: 579.50) artifacts(0) iter/s: 83
RPLC 1 6 high_cov_hits(2 sum: 2150) uniq_cov(2 cov: 84.21% cplx: 579.50) artifacts(0) iter/s: 80
RPLC 1 9 high_cov_hits(2 sum: 2656) uniq_cov(3 cov: 94.74% cplx: 1372.33) artifacts(0) iter/s: 103
RPLC 2 9 high_cov_hits(2 sum: 2652) uniq_cov(2 cov: 94.74% cplx: 547.50) artifacts(0) iter/s: 102
RPLC 1 9 high_cov_hits(2 sum: 2652) uniq_cov(3 cov: 94.74% cplx: 1372.33) artifacts(0) iter/s: 101
NEW 13 high_cov_hits(3 sum: 2748) uniq_cov(2 cov: 94.74% cplx: 547.50) artifacts(0) iter/s: 119
RPLC 1 13 high_cov_hits(2 sum: 2656) uniq_cov(2 cov: 94.74% cplx: 547.50) artifacts(0) iter/s: 116
NEW 15 high_cov_hits(4 sum: 2767) uniq_cov(2 cov: 94.74% cplx: 547.50) artifacts(0) iter/s: 119
NEW 15 high_cov_hits(4 sum: 2767) uniq_cov(2 cov: 94.74% cplx: 547.50) artifacts(1) iter/s: 115
The book is really helpful, thanks! And thank you for your guidance about the grammar-based mutator.
amazing! thanks for reporting the bug :) let me know if you need any more help
I hope you're well :)
(relevant code at the bottom of this issue)
I'm trying to test a small parser with fuzzcheck, and I am running into a couple of errors.
The first error I found was (everything running on MacOS Catalina, x86_64):
I updated everything (rust toolchain – so running the latest nightly – and fuzzcheck) and that issue went away (yay!) but instead this issue appears:
My code is as follows: