MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / serial_input

Function serial_input

devices/src/legacy/serial.rs:425–461  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

423
424 #[test]
425 fn serial_input() {
426 let intr_evt = EventFd::new(0).unwrap();
427 let serial_out = SharedBuffer::new();
428 let mut serial = Serial::new_out(
429 String::from(SERIAL_NAME),
430 Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())),
431 Box::new(serial_out),
432 None,
433 );
434
435 // write 1 to the interrupt event fd, so that read doesn't block in case the event fd
436 // counter doesn't change (for 0 it blocks)
437 intr_evt.write(1).unwrap();
438 serial.write(0, IER as u64, &[IER_RECV_BIT]);
439 serial.queue_input_bytes(b"abc").unwrap();
440
441 assert_eq!(intr_evt.read().unwrap(), 2);
442
443 // check if reading in a 2-length array doesn't have side effects
444 let mut data = [0u8, 0u8];
445 serial.read(0, DATA as u64, &mut data[..]);
446 assert_eq!(data, [0u8, 0u8]);
447
448 let mut data = [0u8];
449 serial.read(0, LSR as u64, &mut data[..]);
450 assert_ne!(data[0] & LSR_DATA_BIT, 0);
451 serial.read(0, DATA as u64, &mut data[..]);
452 assert_eq!(data[0], b'a');
453 serial.read(0, DATA as u64, &mut data[..]);
454 assert_eq!(data[0], b'b');
455 serial.read(0, DATA as u64, &mut data[..]);
456 assert_eq!(data[0], b'c');
457
458 // check if reading from the largest u8 offset returns 0
459 serial.read(0, 0xff, &mut data[..]);
460 assert_eq!(data[0], 0);
461 }
462
463 #[test]
464 fn serial_thr() {

Callers

nothing calls this directly

Calls 5

newFunction · 0.85
try_cloneMethod · 0.45
writeMethod · 0.45
queue_input_bytesMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected