1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
mod util;
use util::*;
use anyhow::Result;
use firedbg_rust_debugger::{Bytes, Debugger, Event, EventStream, PValue, RValue};
use pretty_assertions::assert_eq;
use sea_streamer::{Buffer, Consumer, Message, Producer};
#[tokio::test]
async fn main() -> Result<()> {
let testcase = "call_chain";
let (producer, consumer) = setup(testcase).await?;
let debugger_params = debugger_params_from_file(testcase);
Debugger::run(debugger_params, producer.clone());
producer.end().await?;
for i in 0..10 {
let payload = consumer.next().await?.message().into_bytes();
let event = EventStream::read_from(Bytes::from(payload));
println!("#{i} {:?}", event);
match event {
Event::Breakpoint { .. } => unreachable!(),
Event::FunctionCall {
function_name,
arguments,
..
} => {
assert_eq!(
&function_name,
match i {
0 => "call_chain::main",
1 => "call_chain::head",
2 => "call_chain::inter",
3 => "call_chain::tail",
4 => "call_chain::end",
_ => panic!("Unexpected i {i}"),
}
);
if i == 0 {
assert_eq!(arguments.len(), 0);
} else {
assert_eq!(arguments.len(), 1);
assert_eq!(
arguments[0].1,
RValue::Prim(PValue::i32(match i {
1 => 1,
2 => 2,
3 => 2,
4 => 2,
_ => panic!("Unexpected i {i}"),
}))
);
}
}
Event::FunctionReturn {
function_name,
return_value,
..
} => {
assert_eq!(
&function_name,
match i {
5 => "call_chain::end",
6 => "call_chain::tail",
7 => "call_chain::inter",
8 => "call_chain::head",
9 => "call_chain::main",
_ => panic!("Unexpected i {i}"),
}
);
if i == 9 {
assert_eq!(return_value, RValue::Unit);
} else {
assert_eq!(
return_value,
RValue::Prim(PValue::i32(match i {
5 => 2,
6 => 3,
7 => 3,
8 => 3,
_ => panic!("Unexpected i {i}"),
}))
);
}
}
}
}
Ok(())
}