Skip to content

Commit

Permalink
More test + removed some printing
Browse files Browse the repository at this point in the history
  • Loading branch information
emoon committed May 21, 2016
1 parent f8d9400 commit a533209
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ impl GdbRemote {
match v[0] {
b'+' => return stream.read(dest),
b'-' => {
println!("retry..");
try!(stream.write_all(resend_data.as_bytes()));
}
_ => {
Expand Down Expand Up @@ -453,6 +452,12 @@ mod tests {
stream.write_all(dest.as_bytes()).unwrap();
}

b's' => {
let mut dest = String::new();
GdbRemote::build_processed_string(&mut dest, "S01");
stream.write_all(dest.as_bytes()).unwrap();
}

_ => (),
}
}
Expand Down Expand Up @@ -649,6 +654,41 @@ mod tests {
update_mutex(&lock, SHOULD_QUIT);
}


#[test]
fn test_step() {
let mut res = [0; 1024];
let port = 6811u16;
let lock = Arc::new(Mutex::new(0));
let thread_lock = lock.clone();

thread::spawn(move || { setup_listener(&thread_lock, READ_DATA, port) });
wait_for_thread_init(&lock);

let mut gdb = GdbRemote::new();
gdb.connect(("127.0.0.1", port)).unwrap();
let size = gdb.step(&mut res).unwrap();

let step_reply = get_string_from_buf(&res, size);

assert_eq!(step_reply, "S01");

update_mutex(&lock, SHOULD_QUIT);
}

#[test]
fn test_memory_send_without_connection() {
let mut gdb = GdbRemote::new();
assert_eq!(gdb.request_no_ack_mode().is_err(), true);
}

#[test]
fn test_memory_read_reply_without_connection() {
let mut res = [0; 1024];
let mut gdb = GdbRemote::new();
assert_eq!(gdb.read_reply(&mut res).is_err(), true);
}

#[test]
fn test_parse_memory_1() {
let data = "m77,22".to_owned();
Expand All @@ -657,6 +697,11 @@ mod tests {
assert_eq!(size, 0x22);
}

#[test]
fn test_validate_mem_wrong_checksum() {
assert_eq!(GdbRemote::validate_checksum(b"$some_data#00", 13).is_err(), true);
}

#[test]
fn test_parse_memory_2() {
let data = "m1177,875".to_owned();
Expand Down

0 comments on commit a533209

Please sign in to comment.