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
94
95
96
mod util;
use util::*;
use anyhow::Result;
use firedbg_rust_debugger::{Bytes, Debugger, Event, EventStream};
use pretty_assertions::assert_eq;
use sea_streamer::{Buffer, Consumer, Message, Producer};
#[tokio::test]
async fn main() -> Result<()> {
let testcase = "thread_1";
let (producer, consumer) = setup(testcase).await?;
let debugger_params = debugger_params_from_file(testcase);
// println!("{:#?}", debugger_params.breakpoints);
Debugger::run(debugger_params, producer.clone());
producer.end().await?;
let mut thread_0 = None;
let mut thread_1 = None;
let mut tick = 0;
for i in 0..26 {
let payload = consumer.next().await?.message().into_bytes();
let event = EventStream::read_from(Bytes::from(payload));
println!("#{i} {:?}", event);
match &event {
Event::Breakpoint { .. } => (),
Event::FunctionCall {
thread_id,
function_name,
arguments,
..
} => {
assert_eq!(
function_name,
match i {
0 => {
thread_0 = Some(*thread_id);
"thread_1::main"
}
1 => {
assert_eq!(thread_0, Some(*thread_id));
"thread_1::run"
}
2 => {
thread_1 = Some(*thread_id);
"thread_1::thread_1"
}
_ => {
assert_eq!(arguments[0].1.to_string(), format!("{tick}usize"));
assert_eq!(thread_1, Some(*thread_id));
tick += 1;
"thread_1::tick"
}
}
);
}
Event::FunctionReturn {
thread_id,
function_name,
return_value,
..
} => {
assert_eq!(return_value.to_string().as_str(), "()");
assert_eq!(
function_name,
match i {
23 => {
assert_eq!(thread_1, Some(*thread_id));
"thread_1::thread_1"
}
24 => {
assert_eq!(thread_0, Some(*thread_id));
"thread_1::run"
}
25 => {
assert_eq!(thread_0, Some(*thread_id));
"thread_1::main"
}
_ => {
assert_eq!(thread_1, Some(*thread_id));
"thread_1::tick"
}
}
);
}
}
}
Ok(())
}