forked from tetratelabs/wazero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fuzz: adds logging_no_diff target (tetratelabs#2077)
Signed-off-by: Takeshi Yoneda <[email protected]>
- Loading branch information
Showing
10 changed files
with
126 additions
and
139 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
7 changes: 7 additions & 0 deletions
7
internal/integration_test/fuzz/fuzz/fuzz_targets/logging_no_diff.rs
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 @@ | ||
#![no_main] | ||
use libfuzzer_sys::fuzz_target; | ||
mod util; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let _ = util::run_nodiff(data, false, true); | ||
}); |
60 changes: 2 additions & 58 deletions
60
internal/integration_test/fuzz/fuzz/fuzz_targets/memory_no_diff.rs
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,63 +1,7 @@ | ||
//! memory_diff fuzzing test is almost the same as basic.rs | ||
//! but this also ensure that there's no difference in the memory buffer | ||
//! state after the execution. | ||
#![no_main] | ||
use libfuzzer_sys::arbitrary::{Result, Unstructured}; | ||
use libfuzzer_sys::fuzz_target; | ||
use wasm_smith::SwarmConfig; | ||
mod wazero_abi; | ||
mod util; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let _ = run(data); | ||
let _ = util::run_nodiff(data, true, false); | ||
}); | ||
|
||
fn run(data: &[u8]) -> Result<()> { | ||
// Create the random source. | ||
let mut u = Unstructured::new(data); | ||
|
||
// Generate the configuration. | ||
let mut config: SwarmConfig = u.arbitrary()?; | ||
|
||
// 64-bit memory won't be supported by wazero. | ||
config.memory64_enabled = false; | ||
// For exactly one memory exists. | ||
config.max_memories = 1; | ||
config.min_memories = 1; | ||
// If we don't set the limit, we will soon reach the OOM and the fuzzing will be killed by OS. | ||
config.max_memory_pages = 10; | ||
config.memory_max_size_required = true; | ||
// Don't test too large tables. | ||
config.max_tables = 2; | ||
config.max_table_elements = 1_000; | ||
config.table_max_size_required = true; | ||
|
||
// max_instructions is set to 100 by default which seems a little bit smaller. | ||
config.max_instructions = 5000; | ||
|
||
// Without canonicalization of NaNs, the results cannot be matched among engines. | ||
config.canonicalize_nans = true; | ||
|
||
// Export all the things so that we can invoke them. | ||
config.export_everything = true; | ||
|
||
// Ensures that at least one function exists. | ||
config.min_funcs = 1; | ||
config.max_funcs = config.max_funcs.max(1); | ||
|
||
// TODO: enable after threads support in wazevo. | ||
config.threads_enabled = false; | ||
|
||
// Generate the random module via wasm-smith. | ||
let mut module = wasm_smith::Module::new(config.clone(), &mut u)?; | ||
module.ensure_termination(1000); | ||
let module_bytes = module.to_bytes(); | ||
|
||
// Pass the randomly generated module to the wazero library. | ||
unsafe { | ||
wazero_abi::require_no_diff(module_bytes.as_ptr(), module_bytes.len(), true); | ||
} | ||
|
||
// We always return Ok as inside require_no_diff, we cause panic if the binary is interesting. | ||
Ok(()) | ||
} |
58 changes: 2 additions & 56 deletions
58
internal/integration_test/fuzz/fuzz/fuzz_targets/no_diff.rs
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,61 +1,7 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::arbitrary::{Result, Unstructured}; | ||
use libfuzzer_sys::fuzz_target; | ||
use wasm_smith::SwarmConfig; | ||
|
||
mod wazero_abi; | ||
mod util; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let _ = run(data); | ||
let _ = util::run_nodiff(data, false, false); | ||
}); | ||
|
||
fn run(data: &[u8]) -> Result<()> { | ||
// Create the random source. | ||
let mut u = Unstructured::new(data); | ||
|
||
// Generate the configuration. | ||
let mut config: SwarmConfig = u.arbitrary()?; | ||
|
||
// 64-bit memory won't be supported by wazero. | ||
config.memory64_enabled = false; | ||
// Also, multiple memories are not supported. | ||
config.max_memories = 1; | ||
config.max_imports = 10; | ||
// If we don't set the limit, we will soon reach the OOM and the fuzzing will be killed by OS. | ||
config.max_memory_pages = 10; | ||
config.memory_max_size_required = true; | ||
// Don't test too large tables. | ||
config.max_tables = 2; | ||
config.max_table_elements = 1_000; | ||
config.table_max_size_required = true; | ||
|
||
// max_instructions is set to 100 by default which seems a little bit smaller. | ||
config.max_instructions = 5000; | ||
|
||
// Without canonicalization of NaNs, the results cannot be matched among engines. | ||
config.canonicalize_nans = true; | ||
|
||
// Export all the things so that we can invoke them. | ||
config.export_everything = true; | ||
|
||
// Ensures that at least one function exists. | ||
config.min_funcs = 1; | ||
config.max_funcs = config.max_funcs.max(1); | ||
|
||
// TODO: enable after threads support in wazevo. | ||
config.threads_enabled = false; | ||
|
||
// Generate the random module via wasm-smith. | ||
let mut module = wasm_smith::Module::new(config.clone(), &mut u)?; | ||
module.ensure_termination(1000); | ||
let module_bytes = module.to_bytes(); | ||
|
||
// Pass the randomly generated module to the wazero library. | ||
unsafe { | ||
wazero_abi::require_no_diff(module_bytes.as_ptr(), module_bytes.len(), false); | ||
} | ||
|
||
// We always return Ok as inside require_no_diff, we cause panic if the binary is interesting. | ||
Ok(()) | ||
} |
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
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
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