Skip to content

Commit

Permalink
fuzz: fuzz testing (tikv#2942)
Browse files Browse the repository at this point in the history
  • Loading branch information
overvenus authored Apr 26, 2018
1 parent f5f655c commit 9846b78
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ out/

target
tmp
/bin
/bin

# Cargo-fuzz
corpus
artifacts
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ features = ["secure"]
[replace]
"protobuf:1.4.1" = { git = "https://github.com/stepancheg/rust-protobuf.git" }

[workspace]
members = ["fuzz"]

[profile.dev]
opt-level = 0 # Controls the --opt-level the compiler builds with
debug = true # Controls whether the compiler passes `-g`
Expand Down
16 changes: 16 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "tikv-fuzz"
version = "0.0.1"
publish = false

[package.metadata]
cargo-fuzz = true

[dependencies.tikv]
path = ".."
[dependencies.libfuzzer-sys]
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"

[[bin]]
name = "codec_bytes"
path = "fuzz_targets/codec_bytes.rs"
19 changes: 19 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Fuzz testing

Fuzz testing for TiKV.

Currently, it targets in following components:

- tikv::util::codec::bytes

To run fuzz testing, you need to install `cargo-fuzz`:

```sh
$ cargo install cargo-fuzz
```

Then pick a target:

```sh
$ cargo fuzz run codec_bytes
```
14 changes: 14 additions & 0 deletions fuzz/fuzz_targets/codec_bytes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
extern crate tikv;

fuzz_target!(|data: &[u8]| {
use tikv::util::codec;

let _ = codec::bytes::encode_bytes(data);
let _ = codec::bytes::encode_bytes_desc(data);
let _ = codec::bytes::encoded_compact_len(data);
let _ = codec::bytes::encoded_bytes_len(data, true);
let _ = codec::bytes::encoded_bytes_len(data, false);
});

0 comments on commit 9846b78

Please sign in to comment.