-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fuzz): arbitrary implementation for Cell and CellBuilder
- Loading branch information
1 parent
0abd815
commit 21795f6
Showing
9 changed files
with
279 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Check if the correct number of arguments is provided | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 <fuzz_target>" | ||
exit 1 | ||
fi | ||
|
||
# Assign the first argument to the fuzz_target variable | ||
FUZZ_TARGET=$1 | ||
|
||
# Ensure necessary tools are installed | ||
if ! command -v cargo &> /dev/null; then | ||
echo "cargo could not be found, please install Rust and Cargo." | ||
exit 1 | ||
fi | ||
|
||
if ! command -v llvm-cov &> /dev/null; then | ||
echo "llvm-cov could not be found, please install LLVM." | ||
exit 1 | ||
fi | ||
|
||
if ! command -v rustfilt &> /dev/null; then | ||
echo "rustfilt could not be found, please install rustfilt." | ||
exit 1 | ||
fi | ||
|
||
# Run the cargo fuzz coverage command with the provided fuzz target | ||
cargo +nightly fuzz coverage "$FUZZ_TARGET" | ||
|
||
# Define the paths | ||
TARGET_DIR="target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release" | ||
PROF_DATA="fuzz/coverage/$FUZZ_TARGET/coverage.profdata" | ||
OUTPUT_FILE="lcov.info" | ||
|
||
# Check if the coverage data file exists | ||
if [ ! -f "$PROF_DATA" ]; then | ||
echo "Coverage data file $PROF_DATA not found." | ||
exit 1 | ||
fi | ||
|
||
# Generate the coverage report in HTML format | ||
llvm-cov export "$TARGET_DIR/$FUZZ_TARGET" --format=lcov \ | ||
-Xdemangler=rustfilt \ | ||
--ignore-filename-regex="\.cargo" \ | ||
-instr-profile="$PROF_DATA" \ | ||
> "$OUTPUT_FILE" | ||
|
||
echo "Coverage report generated as $OUTPUT_FILE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
target | ||
corpus | ||
artifacts | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
#![no_main] | ||
use libfuzzer_sys::fuzz_target; | ||
use libfuzzer_sys::{fuzz_target, Corpus}; | ||
|
||
use everscale_types::prelude::Boc; | ||
use everscale_types::cell::CellTreeStats; | ||
use everscale_types::prelude::*; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
fuzz_target!(|data: &[u8]| -> Corpus { | ||
if let Ok(cell) = Boc::decode(data) { | ||
_ = Boc::encode(cell.as_ref()); | ||
let res = Boc::encode(cell.as_ref()); | ||
let redecoded = Boc::decode(&res).unwrap(); | ||
assert_eq!(cell.as_ref(), redecoded.as_ref()); | ||
let l = call_all_cell_methods(&cell); | ||
let r = call_all_cell_methods(&redecoded); | ||
assert_eq!(l, r); | ||
return Corpus::Keep; | ||
} | ||
Corpus::Reject | ||
}); | ||
|
||
fn call_all_cell_methods(cell: &Cell) -> CellTreeStats { | ||
let hash = cell.hash(0); | ||
let hash = cell.hash(1); | ||
let hash = cell.hash(2); | ||
let hash = cell.hash(3); | ||
|
||
let _ = cell.virtualize(); | ||
cell.compute_unique_stats(usize::MAX).unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![no_main] | ||
use libfuzzer_sys::{fuzz_target, Corpus}; | ||
|
||
use everscale_types::prelude::{Cell, RawDict}; | ||
|
||
fuzz_target!(|data: Cell| -> Corpus { | ||
if let Ok(map) = data.parse::<RawDict<32>>() { | ||
_ = map.iter().count(); | ||
return Corpus::Keep; | ||
} | ||
Corpus::Reject | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![no_main] | ||
use libfuzzer_sys::{fuzz_target, Corpus}; | ||
|
||
use everscale_types::models::Message; | ||
use everscale_types::prelude::Cell; | ||
|
||
fuzz_target!(|cell: Cell| -> Corpus { | ||
if cell.parse::<Message>().is_ok() { | ||
return Corpus::Keep; | ||
} | ||
|
||
Corpus::Reject | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters