Skip to content

Commit

Permalink
Enable fuzz-testing of importize
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Sep 12, 2024
1 parent 43121d6 commit 01cc0b0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion fuzz/src/roundtrip_wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ pub fn run(u: &mut Unstructured<'_>) -> Result<()> {
// to avoid timing out this fuzzer with asan enabled.
let mut decoded_worlds = Vec::new();
for (id, world) in resolve.worlds.iter().take(20) {
log::debug!("testing world {}", world.name);
log::debug!("embedding world {} as in a dummy module", world.name);
let mut dummy = wit_component::dummy_module(&resolve, id);
wit_component::embed_component_metadata(&mut dummy, &resolve, id, StringEncoding::UTF8)
.unwrap();
write_file("dummy.wasm", &dummy);

// Decode what was just created and record it later for testing merging
// worlds together.
let (_, decoded) = wit_component::metadata::decode(&dummy).unwrap();
decoded_worlds.push(decoded.resolve);

log::debug!("... componentizing the world into a binary component");
let wasm = wit_component::ComponentEncoder::default()
.module(&dummy)
.unwrap()
Expand All @@ -55,7 +58,15 @@ pub fn run(u: &mut Unstructured<'_>) -> Result<()> {
.validate_all(&wasm)
.unwrap();

log::debug!("... decoding the component itself");
wit_component::decode(&wasm).unwrap();

// Test out importizing the world and then assert the world is still
// valid.
log::debug!("... importizing this world");
let mut resolve2 = resolve.clone();
let _ = resolve2.importize(id);
resolve.assert_valid();
}

if decoded_worlds.len() < 2 {
Expand Down

0 comments on commit 01cc0b0

Please sign in to comment.