Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip, check in before reduce...
  • Loading branch information
Katelyn Martin committed Jun 22, 2020
commit 928c3b3ef5017e73daee5988af1754a15a33fc57
16 changes: 11 additions & 5 deletions ir/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,22 @@ impl ItemsBuilder {
/// Add the given item to to the graph and return the `Id` that it was
/// assigned.
pub fn add_item(&mut self, item: Item) -> Id {
// --- --- 8< --- ---
let dbg_clone = item.clone();
// --- --- 8< --- ---

let id = item.id;
self.size_added += item.size;
self.items.insert(id, item);

let old_value = self.parsed.insert(id);
// panic happen as this is call 2 times with 7,
assert!(
old_value,
"should not parse the same key into multiple items"
);

// --- --- 8< --- ---
if !old_value {
dbg!(dbg_clone);
panic!("value with id {:?} parsed into multiple items!", id);
}
// --- --- 8< --- ---

id
}
Expand Down
9 changes: 1 addition & 8 deletions parser/wasm_parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,12 @@ impl<'a> Parse<'a> for wasmparser::ModuleReader<'a> {
section.get_data_section_reader()?.parse_items(items, idx)?;
}
wasmparser::SectionCode::DataCount => {
let msg = "the last iteration of the loop take 7 as id";
dbg!(msg, idx);
DataCountSection(section).parse_items(items, idx)?;
}
wasmparser::SectionCode::Code | wasmparser::SectionCode::Function => {
unreachable!("unexpected code or function section found");
}
};
if idx == 7 {
let msg = "At some point just after the debug above this also is 7 so the panic";
dbg!(msg, &idx);
}
let id = Id::section(idx);
let added = items.size_added() - start;
let size = sizes
Expand Down Expand Up @@ -798,17 +792,16 @@ struct DataCountSection<'a>(wasmparser::Section<'a>);
impl<'a> Parse<'a> for DataCountSection<'a> {
type ItemsExtra = usize;

// Worth looking here...
fn parse_items(
&mut self,
items: &mut ir::ItemsBuilder,
idx: usize,
) -> Result<(), traits::Error> {
let range = self.0.range();
let size = (range.end - range.start) as u32;
//dbg!("section", &idx);
let id = Id::section(idx);
let name = "\"data count\" section";
//dbg!("YEAH", &id);
items.add_root(ir::Item::new(id, name, size, ir::Misc::new()));
Ok(())
}
Expand Down
Binary file added twiggy/tests/all/fixtures/threads_test.wasm
Binary file not shown.
Binary file added twiggy/tests/all/fixtures/threads_working.wasm
Binary file not shown.
50 changes: 41 additions & 9 deletions twiggy/tests/all/top_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ test!(
"csv"
);

// Threaded modules should not cause a panic.
test!(
top_threaded_module,
"top",
"-n",
"25",
"./fixtures/threads.wasm"
);

// This should not fail to open and write `whatever-output.txt`.
test!(
output_to_file,
Expand All @@ -88,3 +79,44 @@ test!(

// Regression test for https://github.com/rustwasm/twiggy/issues/151
test!(top_mono, "top", "./fixtures/mono.wasm", "-n", "10");

// // Threaded modules should not cause a panic.
// test!(
// top_threaded_module,
// "top",
// "-n",
// "25",
// "./fixtures/threads.wasm"
// );

// DEV KTM: TEMPORARY WHILE REDUCING BINARY
#[test]
fn top_threaded_module() {
use std::process::Command;

let output = Command::new("cargo")
.arg("run")
.arg("--")
.arg("top")
.arg("-n")
.arg("25")
.arg("./fixtures/threads_test.wasm")
.current_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/all/"))
.output()
.unwrap();

assert_eq!(output.status.code(), Some(101),);
// assert!(output.status.success());

let stderr = String::from_utf8_lossy(&output.stderr);

let is_error_about_data_count_header = stderr
.lines()
.any(|l| l.contains("data count section headers"));
let contains_correct_panic = stderr.lines().any(|l| l.contains("ir.rs:61:13"));
assert!(
contains_correct_panic && is_error_about_data_count_header,
"incorrect panic!:\n{}",
stderr
);
}