Skip to content

Commit

Permalink
serial: add a test for receive FIFO flushing
Browse files Browse the repository at this point in the history
Add a test that checks that flushing the receive FIFO results in the
correct behavior, i.e. `in_buffer` is cleared.

Signed-off-by: Carlos López <[email protected]>
  • Loading branch information
00xc committed Nov 24, 2023
1 parent 004b807 commit 06644f5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions vm-superio/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,34 @@ mod tests {
assert_eq!(serial.writer().as_slice(), &RAW_INPUT_BUF);
}

#[test]
fn test_serial_rx_flush() {
let intr_evt = EventFd::new(libc::EFD_NONBLOCK).unwrap();
let mut serial = Serial::with_events(intr_evt, ExampleSerialEvents::new(), Vec::new());

// No data yet
let mut lsr = serial.read(LSR_OFFSET);
assert_eq!(lsr & LSR_DATA_READY_BIT, 0);
assert_eq!(serial.fifo_capacity(), FIFO_SIZE);

// Write some bytes and check data is ready
serial.enqueue_raw_bytes(&RAW_INPUT_BUF).unwrap();
lsr = serial.read(LSR_OFFSET);
assert_eq!(lsr & LSR_DATA_READY_BIT, 1);
assert!(serial.fifo_capacity() != FIFO_SIZE);

// Flush the FIFO
serial.write(FCR_OFFSET, FCR_FLUSH_IN_BIT).unwrap();

// No data again
lsr = serial.read(LSR_OFFSET);
assert_eq!(lsr & LSR_DATA_READY_BIT, 0);
assert_eq!(serial.fifo_capacity(), FIFO_SIZE);

// An event should have triggered
assert_eq!(serial.events.buffer_ready_event.read().unwrap(), 1);
}

#[test]
fn test_serial_raw_input() {
let intr_evt = EventFd::new(libc::EFD_NONBLOCK).unwrap();
Expand Down

0 comments on commit 06644f5

Please sign in to comment.