-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fuzz: let's do fuzz testing #2942
Conversation
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.
Yes!! 😍 I tested it with cargo fuzz run codec_bytes
and it indeed did get a panic.
Can you add documentation on using it?
Do you think we should add it to the CI?
src/lib.rs
Outdated
@@ -23,7 +23,7 @@ | |||
#![cfg_attr(feature = "dev", feature(plugin))] | |||
#![cfg_attr(feature = "dev", plugin(clippy))] | |||
#![cfg_attr(not(feature = "dev"), allow(unknown_lints))] | |||
#![recursion_limit = "100"] | |||
#![recursion_limit = "200"] |
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.
why is this config changed?
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.
Rustc reports:
error: recursion limit reached while expanding the macro `opts`
--> /home/pingcap/stn/tikv/src/util/rocksdb/engine_metrics.rs:1305:9
|
1305 | / register_int_gauge_vec!(
1306 | | "tikv_engine_oldest_snapshot_duration",
1307 | | "Oldest unreleased snapshot duration in seconds",
1308 | | &["db"]
1309 | | ).unwrap();
| |_________^
|
= help: consider adding a `#![recursion_limit="200"]` attribute to your crate
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: Could not compile `tikv`.
Sure, I am going to add a README.
Good idea! Let's add it to jenkins CI, since it may take a long time to build. And fuzz it in our internal test platform. |
@overvenus Can we maybe make Jenkins do a fuzz once per day or something? It would be sad to have unrelated fuzz failures on otherwise good PRs. |
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 looks good, can you open up a follow-up issue in SRE to add a Jenkins job for this?
fuzz/Cargo.toml
Outdated
git = "https://github.com/pingcap/rust-protobuf.git" | ||
branch = "fuzz-build" | ||
|
||
# Prevent this from interfering with workspaces |
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.
Why not use workspace?
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.
It's automatically generated.
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.
Then I think it's better to put it into workspace, so you don't need an additional lock file.
fuzz/Cargo.toml
Outdated
|
||
[dependencies] | ||
# HACK: A dummy dependency, | ||
# it's only for building TiKV which depends on an unpublished protobuf. |
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.
If this is what you want, you can specify rev
directly.
fuzz/.gitignore
Outdated
@@ -0,0 +1,4 @@ | |||
|
|||
target | |||
corpus |
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.
Use the gitignore file in root directory instead.
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.
It's automatically generated.
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.
So will it be regenerated again?
@@ -0,0 +1,18 @@ | |||
|
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.
Why blank line?
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.
It's automatically generated.
https://github.com/rust-fuzz/cargo-fuzz/blob/4cc2d492def373fa8690a69fe087dc5fe3fe3f62/src/templates.rs#L3
fuzz/Cargo.toml
Outdated
[package] | ||
name = "tikv-fuzz" | ||
version = "0.0.1" | ||
authors = ["Automatically generated"] |
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.
Needs to be updated.
[dependencies.tikv] | ||
path = ".." | ||
[dependencies.libfuzzer-sys] | ||
git = "https://github.com/rust-fuzz/libfuzzer-sys.git" |
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.
Does it have a release version?
fuzz/fuzz_targets/codec_bytes.rs
Outdated
@@ -0,0 +1,14 @@ | |||
#![no_main] | |||
#[macro_use] extern crate libfuzzer_sys; | |||
extern crate tikv; |
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.
Does it mean everything we want to test with fuzz needs to be public?
PTAL |
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.
LGTM
LGTM |
This PR introduces fuzz testing, fuzzing codec::bytes, and it already found a bug #2941.