Skip to content

Commit

Permalink
🩹 Simplified stats logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikrk committed May 31, 2024
1 parent f394a3a commit add07bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
10 changes: 4 additions & 6 deletions crates/client/derive/fuzz_test_executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ pub fn fuzz_test_executor(input: TokenStream) -> TokenStream {
#enum_name::#variant_name (ix) => {
#[cfg(fuzzing_with_stats)]
let mut stats_logger = FuzzingStatistics::new();
#[cfg(fuzzing_with_stats)]
stats_logger.increase_invoked(self.to_context_string());


let (mut signers, metas) = ix.get_accounts(client, &mut accounts.borrow_mut())
.map_err(|e| e.with_origin(Origin::Instruction(self.to_context_string())))
Expand Down Expand Up @@ -58,15 +55,16 @@ pub fn fuzz_test_executor(input: TokenStream) -> TokenStream {
match tx_result {
Ok(_) => {
#[cfg(fuzzing_with_stats)]
stats_logger.increase_successful(self.to_context_string());
{
stats_logger.increase_successful(self.to_context_string());
stats_logger.output_serialized();
}

snaphot.capture_after(client).unwrap();
let (acc_before, acc_after) = snaphot.get_snapshot()
.map_err(|e| e.with_origin(Origin::Instruction(self.to_context_string())))
.expect("Snapshot deserialization expect"); // we want to panic if we cannot unwrap to cause a crash

#[cfg(fuzzing_with_stats)]
stats_logger.output_serialized();
if let Err(e) = ix.check(acc_before, acc_after, data).map_err(|e| e.with_origin(Origin::Instruction(self.to_context_string()))) {
eprintln!(
"\x1b[31mCRASH DETECTED!\x1b[0m Custom check after the {} instruction did not pass!",
Expand Down
23 changes: 8 additions & 15 deletions crates/client/src/fuzzer/fuzzing_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,16 @@ impl FuzzingStatistics {
println!("{}", serialized);
}

/// Increments the invocation count for a given instruction.
/// # Arguments
/// * `instruction` - The instruction to increment the count for.
pub fn increase_invoked(&mut self, instruction: String) {
self.instructions
.entry(instruction)
.and_modify(|iterations_stats| iterations_stats.invoked += 1)
.or_insert(IterationStats {
invoked: 1,
successful: 0,
failed: 0,
});
}
/// Increments the successful invocation count for a given instruction.
/// # Arguments
/// * `instruction` - The instruction to increment the successful count for.
pub fn increase_successful(&mut self, instruction: String) {
self.instructions
.entry(instruction)
.and_modify(|iterations_stats| iterations_stats.successful += 1)
.and_modify(|iterations_stats| {
iterations_stats.successful += 1;
iterations_stats.invoked += 1;
})
.or_insert(
// this should not occure as instruction has to be invoked
// and then successfully_invoked
Expand All @@ -63,7 +53,10 @@ impl FuzzingStatistics {
pub fn increase_failed(&mut self, instruction: String) {
self.instructions
.entry(instruction)
.and_modify(|iterations_stats| iterations_stats.failed += 1)
.and_modify(|iterations_stats| {
iterations_stats.failed += 1;
iterations_stats.invoked += 1;
})
.or_insert(
// this should not occure as instruction has to be invoked
// and then unsuccessfully_invoked
Expand Down

0 comments on commit add07bc

Please sign in to comment.