#[cfg(test)]
pub mod tests {
use crate::tests::util::local_debug;
use wdext::{
breakpoint::WdBreakpoint, data::DebugDisasmFlags, dbgeng::TimeoutQuery,
error::WdErrorKind,
};
mod util;
#[test]
fn test_execution() {
#[cfg(target_arch = "x86")]
let exe_path = r#"./tests/bin/x86/ListEntry.exe"#;
#[cfg(target_arch = "x86_64")]
let exe_path = r#"./tests/bin/x64/ListEntry.exe"#;
let ctx = local_debug(exe_path);
let tmout = TimeoutQuery::from_secs(10);
assert_eq!(
ctx.control().go(tmout).unwrap_err().kind(),
WdErrorKind::EventWaitInvalidState
);
let ctx = local_debug(exe_path);
let ctrl = ctx.control();
let main_offset = ctx
.symbols()
.get_symbol_offset_by_name("ListEntry!main")
.unwrap();
ctx.control().add_software_breakpoint(main_offset).unwrap();
ctrl.go(tmout).unwrap();
let ip = ctx.register_view().read_instruction_offset().unwrap();
assert_eq!(ip, main_offset);
let (_, next_ip) = ctx
.control()
.disassemble(ip, DebugDisasmFlags::empty())
.unwrap();
ctrl.step_over(tmout, None).unwrap();
let ip = ctx.register_view().read_instruction_offset().unwrap();
assert_eq!(ip, next_ip);
let (_, next_ip) = ctx
.control()
.disassemble(ip, DebugDisasmFlags::empty())
.unwrap();
ctrl.step_over(tmout, None).unwrap();
let ip = ctx.register_view().read_instruction_offset().unwrap();
assert_eq!(ip, next_ip);
ctx.control().add_software_breakpoint(0).unwrap();
let v: Vec<WdBreakpoint> = ctx
.control()
.get_breakpoints()
.unwrap()
.map(|x| x.unwrap())
.collect();
assert_eq!(v.len(), 2);
assert_eq!(v[0].get_offset().unwrap(), main_offset);
assert_eq!(v[1].get_offset().unwrap(), 0);
ctx.control().add_software_breakpoint(1).unwrap();
let v: Vec<WdBreakpoint> = ctx
.control()
.get_breakpoints()
.unwrap()
.map(|x| x.unwrap())
.collect();
assert_eq!(v.len(), 3);
assert_eq!(v[0].get_offset().unwrap(), main_offset);
assert_eq!(v[1].get_offset().unwrap(), 0);
assert_eq!(v[2].get_offset().unwrap(), 1);
}
}