test: Cycle 21 — OOB call_indirect, all-guest integration (100 tests milestone)
Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski
This commit is contained in:
parent
d68bb17a39
commit
53c4f18621
1 changed files with 82 additions and 0 deletions
|
|
@ -3586,3 +3586,85 @@ proptest! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── OOB table access: call_indirect with bad index traps ────────────────────
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn guest_oob_call_indirect_traps_actor_survives() {
|
||||||
|
// Guest uses call_indirect with index 99 on a table of size 1.
|
||||||
|
// This should trap. Actor should survive.
|
||||||
|
let wat = r#"
|
||||||
|
(module
|
||||||
|
(import "swactor" "send" (func $send (param i32 i32 i32)))
|
||||||
|
(memory (export "memory") 1)
|
||||||
|
(type $void (func))
|
||||||
|
(func $noop)
|
||||||
|
(table 1 funcref)
|
||||||
|
(elem (i32.const 0) $noop)
|
||||||
|
|
||||||
|
(func (export "alloc") (param i32) (result i32) i32.const 256)
|
||||||
|
(func (export "handle") (param i32 i32)
|
||||||
|
;; call_indirect with index 99 — out of bounds
|
||||||
|
(call_indirect (type $void) (i32.const 99))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
"#;
|
||||||
|
let wasm = wat::parse_str(wat).unwrap();
|
||||||
|
let engine = SharedEngine::new().unwrap();
|
||||||
|
let actor = WasmActorBuilder::new(engine, wasm).build().unwrap();
|
||||||
|
|
||||||
|
let rt = Runtime::new(RuntimeConfig::default());
|
||||||
|
let addr = rt.spawn(actor).unwrap();
|
||||||
|
|
||||||
|
rt.send_to(addr, ByteMessage(vec![1])).unwrap();
|
||||||
|
rt.tick(); // OOB trap
|
||||||
|
|
||||||
|
// Actor survives
|
||||||
|
rt.send_to(addr, ByteMessage(vec![2])).unwrap();
|
||||||
|
rt.tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 100th test: comprehensive round-trip through all guest modules ──────────
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn all_guest_modules_work_in_same_runtime() {
|
||||||
|
// Spawn one of each guest (echo, double, silent) in the same runtime.
|
||||||
|
// Send messages to all three and verify each behaves correctly.
|
||||||
|
// This is the 100th test — a comprehensive integration checkpoint.
|
||||||
|
let engine = SharedEngine::new().unwrap();
|
||||||
|
|
||||||
|
let echo = WasmActorBuilder::new(engine.clone(), guest_wasm("echo"))
|
||||||
|
.build().unwrap();
|
||||||
|
let double = WasmActorBuilder::new(engine.clone(), guest_wasm("double"))
|
||||||
|
.build().unwrap();
|
||||||
|
let silent = WasmActorBuilder::new(engine, guest_wasm("silent"))
|
||||||
|
.build().unwrap();
|
||||||
|
|
||||||
|
let rt = Runtime::new(RuntimeConfig::default());
|
||||||
|
let inbox = rt.new_inbox::<ByteMessage>().unwrap();
|
||||||
|
|
||||||
|
let echo_addr = rt.spawn(echo).unwrap();
|
||||||
|
let double_addr = rt.spawn(double).unwrap();
|
||||||
|
let silent_addr = rt.spawn(silent).unwrap();
|
||||||
|
|
||||||
|
// Send to all three
|
||||||
|
rt.send_to(echo_addr, framed_msg(inbox.addr(), b"E")).unwrap();
|
||||||
|
rt.send_to(double_addr, framed_msg(inbox.addr(), b"D")).unwrap();
|
||||||
|
rt.send_to(silent_addr, ByteMessage(b"S".to_vec())).unwrap();
|
||||||
|
rt.tick();
|
||||||
|
|
||||||
|
// Collect results
|
||||||
|
let mut messages = Vec::new();
|
||||||
|
while let Some(msg) = inbox.try_recv() {
|
||||||
|
messages.push(msg.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Echo: 1 message, Double: 2 messages, Silent: 0 messages = 3 total
|
||||||
|
assert_eq!(messages.len(), 3, "echo(1) + double(2) + silent(0) = 3 messages");
|
||||||
|
|
||||||
|
// Verify content
|
||||||
|
let echo_count = messages.iter().filter(|m| m.as_slice() == b"E").count();
|
||||||
|
let double_count = messages.iter().filter(|m| m.as_slice() == b"D").count();
|
||||||
|
assert_eq!(echo_count, 1, "echo should send 1 copy");
|
||||||
|
assert_eq!(double_count, 2, "double should send 2 copies");
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue