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

Fuzzer improvements #721

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions fuzz/fuzz_targets/fuzz_redb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use redb::backends::FileBackend;
use crate::FuzzerSavepoint::{Ephemeral, NotYetDurablePersistent, Persistent};

// These slow down the fuzzer, so don't create too many
const MAX_PERSISTENT_SAVEPOINTS: usize = 20;
const MAX_PERSISTENT_SAVEPOINTS: usize = 10;
// Table to count which transactions have been successfully committed so that the reference BtreeMap can be kept in sync
const COUNTER_TABLE: TableDefinition<(), u64> = TableDefinition::new("transaction_counter");
const TABLE_DEF: TableDefinition<u64, &[u8]> = TableDefinition::new("fuzz_table");
Expand Down Expand Up @@ -494,7 +494,7 @@ fn exec_table_crash_support<T: Clone>(config: &FuzzConfig, apply: fn(WriteTransa
let mut non_durable_reference = reference.clone();

for (txn_id, transaction) in config.transactions.iter().enumerate() {
let result = handle_savepoints(db.begin_write().unwrap(), &mut non_durable_reference, transaction, &mut savepoint_manager);
let result = handle_savepoints(db.begin_write().unwrap(), &mut non_durable_reference, transaction, &mut savepoint_manager, countdown.clone());
match result {
Ok(durable) => {
if durable {
Expand Down Expand Up @@ -613,7 +613,7 @@ fn run_compaction<T: Clone>(db: &mut Database, savepoint_manager: &mut Savepoint
}

// Returns true if a durable commit was made
fn handle_savepoints<T: Clone>(mut txn: WriteTransaction, reference: &mut BTreeMap<u64, T>, transaction: &FuzzTransaction, savepoints: &mut SavepointManager<T>) -> Result<bool, redb::Error> {
fn handle_savepoints<T: Clone>(mut txn: WriteTransaction, reference: &mut BTreeMap<u64, T>, transaction: &FuzzTransaction, savepoints: &mut SavepointManager<T>, countdown: Arc<AtomicU64>) -> Result<bool, redb::Error> {
if transaction.create_ephemeral_savepoint {
savepoints.ephemeral_savepoint(&txn, &reference)?;
}
Expand All @@ -625,10 +625,18 @@ fn handle_savepoints<T: Clone>(mut txn: WriteTransaction, reference: &mut BTreeM
if let Some(ref restore_to) = transaction.restore_savepoint {
savepoints.restore_savepoint(restore_to.value, &mut txn, reference)?;
}
// Disable simulated IO failures. It's tricky to handle commit failures here in the fuzzer,
// and it doesn't add value since we already fuzz failures on the main transaction path
let old_countdown = countdown.swap(u64::MAX, Ordering::SeqCst);
txn.commit()?;
countdown.store(old_countdown, Ordering::SeqCst);
Ok(true)
} else {
// Disable simulated IO failures. It's tricky to handle commit failures here in the fuzzer,
// and it doesn't add value since we already fuzz failures on the main transaction path
let old_countdown = countdown.swap(u64::MAX, Ordering::SeqCst);
txn.abort()?;
countdown.store(old_countdown, Ordering::SeqCst);
Ok(false)
}

Expand Down
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ watch +args='test':
cargo watch --clear --exec "{{args}}"

fuzz: pre
cargo fuzz run --sanitizer=none fuzz_redb -- -max_len=100000
cargo fuzz run --sanitizer=none fuzz_redb -- -max_len=10000

fuzz_cmin:
cargo fuzz cmin --sanitizer=none fuzz_redb -- -max_len=100000
cargo fuzz cmin --sanitizer=none fuzz_redb -- -max_len=10000

fuzz_ci: pre
cargo fuzz run --sanitizer=none fuzz_redb -- -max_len=100000 -max_total_time=60
cargo fuzz run --sanitizer=none fuzz_redb -- -max_len=10000 -max_total_time=60

fuzz_coverage: pre
#!/usr/bin/env bash
Expand Down
Loading