-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed most problems -- now we fail the test if there's any panic in o…
…verflow.
- Loading branch information
Chae
authored and
Chae
committed
Nov 1, 2024
1 parent
e84bc16
commit a06de64
Showing
20 changed files
with
500 additions
and
311 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
target | ||
corpus | ||
artifacts | ||
coverage | ||
fuzz_results | ||
artifacts/ | ||
corpus/ | ||
fuzz_results/ |
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
, | ||
Some(|a: $type, b: $type| a.wrapping_mul(b)), | ||
Some(|a: $type| a) | ||
) | ||
}); | ||
}; | ||
} |
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,7 @@ | ||
#[macro_export] | ||
macro_rules! create_fuzz_functions { | ||
($type:ty, $functions:ident) => { | ||
static $functions: once_cell::sync::Lazy< | ||
lattices_fuzz::algebra_functions::FuzzFunctions<$type>, | ||
> = once_cell::sync::Lazy::new(|| { | ||
lattices_fuzz::algebra_functions::FuzzFunctions::new( |
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,33 +1,48 @@ | ||
#![no_main] | ||
use lattices::algebra::associativity_single; | ||
use libfuzzer_sys::{arbitrary::Unstructured, fuzz_target}; | ||
use lattices_fuzz::utils; | ||
use lattices_fuzz::utils_integrated; | ||
use std::fs::OpenOptions; | ||
use std::io::Write; | ||
use std::panic; | ||
|
||
#[macro_use] | ||
extern crate lattices_fuzz; | ||
|
||
create_fuzz_functions!(utils::InputType, FUNCTIONS); | ||
|
||
create_fuzz_functions!(utils_integrated::InputType, FUNCTIONS); | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let mut us = Unstructured::new(data); | ||
if let Ok(input) = us.arbitrary::<utils::TestingInput>() { | ||
let result = associativity_single(input.i1.clone(), input.i2.clone(), input.i3.clone(), FUNCTIONS.f); | ||
// println!("Associativity test result: {}", result); | ||
let log_file = if result { | ||
format!("fuzz_results/associativity_PASS_{}.log", std::any::type_name::<utils::InputType>()) | ||
|
||
} else { | ||
format!("fuzz_results/associativity_FAIL_{}.log", std::any::type_name::<utils::InputType>()) | ||
if let Ok(input) = us.arbitrary::<utils_integrated::TestingInput>() { | ||
let result = panic::catch_unwind(|| { | ||
associativity_single(input.i1.clone(), input.i2.clone(), input.i3.clone(), FUNCTIONS.f) | ||
}); | ||
|
||
}; | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.append(true) | ||
.open(log_file) | ||
.expect("Unable to open file"); | ||
writeln!(file, "Input: {:?}", input).expect("Unable to write to file"); | ||
match result { | ||
Ok(result) => { | ||
println!("Associativity test result: {}", result); | ||
let log_file = if result { | ||
format!("fuzz_results/associativity_PASS_{}.log", std::any::type_name::<utils_integrated::InputType>()) | ||
} else { | ||
format!("fuzz_results/associativity_FAIL_{}.log", std::any::type_name::<utils_integrated::InputType>()) | ||
}; | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.append(true) | ||
.open(log_file) | ||
.expect("Unable to open file"); | ||
writeln!(file, "Input: {:?}", input).expect("Unable to write to file"); | ||
} | ||
Err(_) => { | ||
let log_file = format!("fuzz_results/associativity_PANIC_{}.log", std::any::type_name::<utils_integrated::InputType>()); | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.append(true) | ||
.open(log_file) | ||
.expect("Unable to open file"); | ||
writeln!(file, "Input: {:?}", input).expect("Unable to write to file"); | ||
println!("A panic occurred during the associativity test."); | ||
} | ||
} | ||
} | ||
}); |
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,29 +1,48 @@ | ||
#![no_main] | ||
use lattices::algebra::commutativity_single; | ||
use libfuzzer_sys::{arbitrary::Unstructured, fuzz_target}; | ||
use lattices_fuzz::utils; | ||
use lattices_fuzz::utils_integrated; | ||
use std::fs::OpenOptions; | ||
use std::io::Write; | ||
use std::panic; | ||
|
||
#[macro_use] | ||
extern crate lattices_fuzz; | ||
|
||
create_fuzz_functions!(utils::InputType, FUNCTIONS); | ||
create_fuzz_functions!(utils_integrated::InputType, FUNCTIONS); | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let mut us = Unstructured::new(data); | ||
if let Ok(input) = us.arbitrary::<utils::TestingInput>() { | ||
let result = commutativity_single(input.i1.clone(), input.i2.clone(), FUNCTIONS.f); | ||
let log_file = if result { | ||
format!("fuzz_results/commutativity_PASS_{}.log", std::any::type_name::<utils::InputType>()) | ||
} else { | ||
format!("fuzz_results/commutativity_FAIL_{}.log", std::any::type_name::<utils::InputType>()) | ||
}; | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.append(true) | ||
.open(log_file) | ||
.expect("Unable to open file"); | ||
writeln!(file, "Input: {:?}", input).expect("Unable to write to file"); | ||
if let Ok(input) = us.arbitrary::<utils_integrated::TestingInput>() { | ||
let result = panic::catch_unwind(|| { | ||
commutativity_single(input.i1.clone(), input.i2.clone(), FUNCTIONS.f) | ||
}); | ||
|
||
match result { | ||
Ok(result) => { | ||
println!("Commutativity test result: {}", result); | ||
let log_file = if result { | ||
format!("fuzz_results/commutativity_PASS_{}.log", std::any::type_name::<utils_integrated::InputType>()) | ||
} else { | ||
format!("fuzz_results/commutativity_FAIL_{}.log", std::any::type_name::<utils_integrated::InputType>()) | ||
}; | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.append(true) | ||
.open(log_file) | ||
.expect("Unable to open file"); | ||
writeln!(file, "Input: {:?}", input).expect("Unable to write to file"); | ||
} | ||
Err(_) => { | ||
let log_file = format!("fuzz_results/commutativity_PANIC_{}.log", std::any::type_name::<utils_integrated::InputType>()); | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.append(true) | ||
.open(log_file) | ||
.expect("Unable to open file"); | ||
writeln!(file, "Input: {:?}", input).expect("Unable to write to file"); | ||
println!("A panic occurred during the commutativity test."); | ||
} | ||
} | ||
} | ||
}); |
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,32 +1,49 @@ | ||
#![no_main] | ||
|
||
use lattices::algebra::commutativity_single; | ||
use lattices::algebra::distributive_single; | ||
use libfuzzer_sys::{arbitrary::Unstructured, fuzz_target}; | ||
use lattices_fuzz::utils; | ||
use lattices_fuzz::utils_integrated; | ||
use std::fs::OpenOptions; | ||
use std::io::Write; | ||
use std::panic; | ||
|
||
#[macro_use] | ||
extern crate lattices_fuzz; | ||
|
||
create_fuzz_functions!(utils::InputType, FUNCTIONS); | ||
create_fuzz_functions!(utils_integrated::InputType, FUNCTIONS); | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let mut us = Unstructured::new(data); | ||
if let Ok(input) = us.arbitrary::<utils::TestingInput>() { | ||
let result = distributive_single(input.i1.clone(), input.i2.clone(), input.i3.clone(), FUNCTIONS.f, FUNCTIONS.g.unwrap_or(utils::default_g)); | ||
// println!("Distributive test result: {}", result); | ||
if let Ok(input) = us.arbitrary::<utils_integrated::TestingInput>() { | ||
let result = panic::catch_unwind(|| { | ||
distributive_single(input.i1.clone(), input.i2.clone(), input.i3.clone(), FUNCTIONS.f, FUNCTIONS.g.unwrap_or(utils_integrated::default_g)) | ||
}); | ||
|
||
let log_file = if result { | ||
format!("fuzz_results/distributivity_PASS_{}.log", std::any::type_name::<utils::InputType>()) | ||
} else { | ||
format!("fuzz_results/distributivity_FAIL_{}.log", std::any::type_name::<utils::InputType>()) | ||
}; | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.append(true) | ||
.open(log_file) | ||
.expect("Unable to open file"); | ||
writeln!(file, "Input: {:?}", input).expect("Unable to write to file"); | ||
match result { | ||
Ok(result) => { | ||
println!("Distributive test result: {}", result); | ||
let log_file = if result { | ||
format!("fuzz_results/distributivity_PASS_{}.log", std::any::type_name::<utils_integrated::InputType>()) | ||
} else { | ||
format!("fuzz_results/distributivity_FAIL_{}.log", std::any::type_name::<utils_integrated::InputType>()) | ||
}; | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.append(true) | ||
.open(log_file) | ||
.expect("Unable to open file"); | ||
writeln!(file, "Input: {:?}", input).expect("Unable to write to file"); | ||
} | ||
Err(_) => { | ||
let log_file = format!("fuzz_results/distributivity_PANIC_{}.log", std::any::type_name::<utils_integrated::InputType>()); | ||
let mut file = OpenOptions::new() | ||
.create(true) | ||
.append(true) | ||
.open(log_file) | ||
.expect("Unable to open file"); | ||
writeln!(file, "Input: {:?}", input).expect("Unable to write to file"); | ||
println!("A panic occurred during the distributivity test."); | ||
} | ||
} | ||
} | ||
}); |
Oops, something went wrong.