-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fuzz-testing): doesn't detect input type but works with u8
- Loading branch information
Chae
committed
Oct 16, 2024
1 parent
ebe63c2
commit 15a6c31
Showing
12 changed files
with
199 additions
and
806 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,28 @@ | ||
// #![no_main] | ||
|
||
// extern crate libfuzzer_sys; | ||
// use libfuzzer_sys::fuzz_target; | ||
// use lattices::algebra::associativity_single; | ||
|
||
// // Define your function f outside | ||
// fn wrapping_add(x: u8, y: u8) -> u8 { | ||
// x.wrapping_add(y) | ||
// } | ||
|
||
// fuzz_target!(|data: &[u8]| { | ||
// if data.len() < 3 { | ||
// return; // Ensure there's enough data for the test | ||
// } | ||
|
||
// let a = data[0]; | ||
// let b = data[1]; | ||
// let c = data[2]; | ||
|
||
// // Now you can use your wrapping_add function | ||
// let result = associativity_single(a, b, c, wrapping_add); | ||
// println!("Associativity test result: {}", result); | ||
// }); | ||
#![no_main] | ||
|
||
extern crate libfuzzer_sys; | ||
use libfuzzer_sys::fuzz_target; | ||
use lattices::algebra::associativity_single; | ||
use once_cell::sync::Lazy; | ||
use lattices_fuzz::algebra_functions::FuzzFunctions; | ||
|
||
type InputType = u8; | ||
static FUNCTIONS: Lazy<FuzzFunctions<InputType>> = Lazy::new(|| FuzzFunctions::new( | ||
|a: u8, b: u8| a ^ b, | ||
Some(|a: u8| a), | ||
Some(|a: u8, b: u8| a.wrapping_mul(b)), | ||
)); | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
if data.len() < 3 { | ||
println!("Not enough data for associativity test."); | ||
return; | ||
} | ||
|
||
let a = data[0]; | ||
let b = data[1]; | ||
let c = data[2]; | ||
|
||
pub fn fuzz_target(a: u8, b: u8, c: u8, f: fn(u8, u8) -> u8) { | ||
let result = associativity_single(a, b, c, f); | ||
let result = associativity_single(a, b, c, FUNCTIONS.f); | ||
println!("Associativity test result: {}", result); | ||
} | ||
}); |
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,28 +1,28 @@ | ||
// #![no_main] | ||
#![no_main] | ||
|
||
// extern crate libfuzzer_sys; | ||
// use libfuzzer_sys::fuzz_target; | ||
// use lattices::algebra::commutativity_single; | ||
extern crate libfuzzer_sys; | ||
use lattices::algebra::commutativity_single; | ||
use lattices_fuzz::algebra_functions::FuzzFunctions; | ||
use libfuzzer_sys::fuzz_target; | ||
use once_cell::sync::Lazy; | ||
|
||
// pub fn fuzz_target(data: &[u8], f: fn(u8, u8) -> u8) { | ||
// if data.len() < 2 { | ||
// println!("Not enough data for commutativity test."); | ||
// return; | ||
// } | ||
type InputType = u8; | ||
static FUNCTIONS: Lazy<FuzzFunctions<InputType>> = Lazy::new(|| FuzzFunctions::new( | ||
|a: u8, b: u8| a ^ b, | ||
Some(|a: u8| a), | ||
Some(|a: u8, b: u8| a.wrapping_mul(b)), | ||
)); | ||
|
||
// let a = data[0]; | ||
// let b = data[1]; | ||
fuzz_target!(|data: &[u8]| { | ||
if data.len() < 2 { | ||
println!("Not enough data for commutativity test."); | ||
return; | ||
} | ||
|
||
// let result = commutativity_single(a, b, f); | ||
// println!("Commutativity test result: {}", result); | ||
// } | ||
#![no_main] | ||
let a = data[0]; | ||
let b = data[1]; | ||
|
||
extern crate libfuzzer_sys; | ||
use libfuzzer_sys::fuzz_target; | ||
use lattices::algebra::commutativity_single; | ||
let result = commutativity_single(a, b, FUNCTIONS.f); | ||
|
||
pub fn fuzz_target(a: u8, b: u8, f: fn(u8, u8) -> u8) -> bool { | ||
// Using the provided function f for testing | ||
commutativity_single(a, b, f) | ||
} | ||
println!("Commutativity test result: {}", result); | ||
}); |
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,32 @@ | ||
// #![no_main] | ||
// extern crate libfuzzer_sys; | ||
// use libfuzzer_sys::fuzz_target; | ||
// use lattices::algebra::distributive_single; | ||
|
||
// pub fn fuzz_target(data: &[u8], f: fn(u8, u8) -> u8, g: fn(u8, u8) -> u8) { | ||
|
||
// if data.len() < 3 { | ||
// println!("Not enough data for distributive test."); | ||
// return; | ||
// } | ||
|
||
// let a = data[0]; | ||
// let b = data[1]; | ||
// let c = data[2]; | ||
|
||
// let result = distributive_single(a, b, c, f, g); | ||
// println!("Distributive test result: {}", result); | ||
// } | ||
#![no_main] | ||
|
||
extern crate libfuzzer_sys; | ||
use lattices::algebra::distributive_single; | ||
use lattices_fuzz::algebra_functions::FuzzFunctions; | ||
use libfuzzer_sys::fuzz_target; | ||
use lattices::algebra::distributivity_single; | ||
use once_cell::sync::Lazy; | ||
|
||
type InputType = u8; | ||
static FUNCTIONS: Lazy<FuzzFunctions<InputType>> = Lazy::new(|| FuzzFunctions::new( | ||
|a: u8, b: u8| a ^ b, | ||
Some(|a: u8| a), | ||
Some(|a: u8, b: u8| a.wrapping_mul(b)), | ||
)); | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
if data.len() < 3 { | ||
println!("Not enough data for distributivity test."); | ||
return; | ||
} | ||
|
||
let a = data[0]; | ||
let b = data[1]; | ||
let c = data[2]; | ||
|
||
pub fn fuzz_target(a: u8, b: u8, f: fn(u8, u8) -> u8, g: fn(u8, u8) -> u8) { | ||
let result = distributivity_single(a, b, f, g); | ||
println!("Distributivity test result: {}", result); | ||
} | ||
if let Some(q) = FUNCTIONS.q { | ||
let result = distributive_single(a, b, c, FUNCTIONS.f, q); | ||
println!("Distributivity test result: {}", result); | ||
} else { | ||
println!("Skipping distributivity test because g is not available."); | ||
} | ||
}); |
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,23 +1,32 @@ | ||
#![no_main] | ||
|
||
extern crate libfuzzer_sys; | ||
use lattices::algebra::linearity_single; | ||
use lattices_fuzz::algebra_functions::FuzzFunctions; | ||
use libfuzzer_sys::fuzz_target; | ||
use lattices::algebra::linearity_single; | ||
use once_cell::sync::Lazy; | ||
|
||
type InputType = u8; | ||
static FUNCTIONS: Lazy<FuzzFunctions<InputType>> = Lazy::new(|| FuzzFunctions::new( | ||
|a: u8, b: u8| a ^ b, | ||
Some(|a: u8| a), | ||
Some(|a: u8, b: u8| a.wrapping_mul(b)), | ||
)); | ||
|
||
// Define the fuzz target | ||
pub fn fuzz_target( | ||
data: &[u8], | ||
f: fn(u8, u8) -> u8, | ||
q: fn(u8) -> u8, | ||
g: fn(u8, u8) -> u8, | ||
) { | ||
if data.len() < 3 { | ||
fuzz_target!(|data: &[u8]| { | ||
if data.len() < 2 { | ||
println!("Not enough data for linearity test."); | ||
return; | ||
} | ||
|
||
let a = data[0]; | ||
let b = data[1]; | ||
|
||
let result = linearity_single(a, b, f, q, g); | ||
println!("Linearity test result: {}", result); | ||
} | ||
if let (Some(g), Some(q)) = (FUNCTIONS.g, FUNCTIONS.q) { | ||
let result = linearity_single(a, b, FUNCTIONS.f, g, q); | ||
println!("Linearity test result: {}", result); | ||
} else { | ||
println!("Skipping linearity test because g or q is not available."); | ||
} | ||
}); | ||
|
Oops, something went wrong.