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
it seems to, kinda work
  • Loading branch information
Katelyn Martin committed Jun 22, 2020
commit e53824224d25d713080a53db283a83e69c87c581
23 changes: 10 additions & 13 deletions ir/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,19 @@ 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);
let size = item.size;

// --- --- 8< --- ---
if !old_value {
dbg!(dbg_clone);
panic!("value with id {:?} parsed into multiple items!", id);
match self.items.get_mut(&id) {
None => {
self.size_added += size;
self.items.insert(id, item);
self.parsed.insert(id);
}
Some(prev) => {
prev.size += size;
}
}
// --- --- 8< --- ---

id
}
Expand Down
13 changes: 13 additions & 0 deletions twiggy/tests/all/expectations/top_threaded_module
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Shallow Bytes β”‚ Shallow % β”‚ Item
───────────────┼───────────┼───────────────────────
8 β”Š 18.18% β”Š wasm magic bytes
7 β”Š 15.91% β”Š code[0]
6 β”Š 13.64% β”Š code section headers
5 β”Š 11.36% β”Š data[0]
3 β”Š 6.82% β”Š type[0]: () -> nil
3 β”Š 6.82% β”Š type section headers
3 β”Š 6.82% β”Š memory[0]
3 β”Š 6.82% β”Š memory section headers
3 β”Š 6.82% β”Š "data count" section
3 β”Š 6.82% β”Š data section headers
44 β”Š 100.00% β”Š Ξ£ [10 Total Rows]
1 change: 1 addition & 0 deletions twiggy/tests/all/fixtures/threads.wat
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
;; Built with `wat2wasm --enable-bulk-memory --enable-threads`
(module
(memory $0 1 1)
(data (i32.const 0) "")
Expand Down
48 changes: 8 additions & 40 deletions twiggy/tests/all/top_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,43 +80,11 @@ 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
);
}
// Threaded modules should not cause a panic.
test!(
top_threaded_module,
"top",
"-n",
"25",
"./fixtures/threads.wasm"
);