MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / test_loop

Function test_loop

crates/test-programs/src/bin/debugger_component.rs:91–126  ·  view source on GitHub ↗

Interrupt test: continue an infinite-loop debuggee, interrupt it, verify the interrupt, then set the exit flag in memory and continue to completion. Tests against `debugger_debuggee_loop.wat`.

(d: &Debuggee)

Source from the content-addressed store, hash-verified

89///
90/// Tests against `debugger_debuggee_loop.wat`.
91fn test_loop(d: &Debuggee) {
92 // Continue execution (the debuggee should loop).
93 let r = Resumption::continue_(d);
94
95 // Yield to the event loop and let it run for a bit.
96 std::thread::sleep(Duration::from_millis(100));
97
98 // Request interrupt.
99 d.interrupt();
100
101 // Wait for the interrupt event.
102 let event = r.result(d).unwrap();
103 assert!(
104 matches!(event, Event::Interrupted),
105 "expected Interrupted, got {event:?}"
106 );
107
108 // Set the exit-flag to kill the infinite loop in the guest (the
109 // debugger environment will not otherwise end until the guest
110 // ends; we have no way of forcing an early exit yet).
111 for inst in &d.all_instances() {
112 if let Ok(mem) = inst.get_memory(d, 0) {
113 mem.set_bytes(d, 0, &[1]).unwrap();
114 }
115 }
116
117 // Continue; the debuggee should exit normally now.
118 let r = Resumption::continue_(d);
119 let event = r.result(d).unwrap();
120 assert!(
121 matches!(event, Event::Complete),
122 "expected Complete, got {event:?}"
123 );
124
125 eprintln!("OK");
126}
127
128fn main() {}

Callers 1

debugMethod · 0.85

Calls 6

interruptMethod · 0.80
set_bytesMethod · 0.80
unwrapMethod · 0.45
resultMethod · 0.45
all_instancesMethod · 0.45
get_memoryMethod · 0.45

Tested by

no test coverage detected