()
| 691 | |
| 692 | #[test] |
| 693 | fn test_txq_event() { |
| 694 | // Test case: |
| 695 | // - the driver has something to send (there's data in the TX queue); and |
| 696 | // - the backend has no pending RX data. |
| 697 | { |
| 698 | let test_ctx = TestContext::new(); |
| 699 | let mut ctx = test_ctx.create_epoll_handler_context(); |
| 700 | |
| 701 | ctx.handler.backend.write().unwrap().set_pending_rx(false); |
| 702 | ctx.signal_txq_event(); |
| 703 | |
| 704 | // The available TX descriptor should have been used. |
| 705 | assert_eq!(ctx.guest_txvq.used.idx.get(), 1); |
| 706 | // The available RX descriptor should be untouched. |
| 707 | assert_eq!(ctx.guest_rxvq.used.idx.get(), 0); |
| 708 | } |
| 709 | |
| 710 | // Test case: |
| 711 | // - the driver has something to send (there's data in the TX queue); and |
| 712 | // - the backend also has some pending RX data. |
| 713 | { |
| 714 | let test_ctx = TestContext::new(); |
| 715 | let mut ctx = test_ctx.create_epoll_handler_context(); |
| 716 | |
| 717 | ctx.handler.backend.write().unwrap().set_pending_rx(true); |
| 718 | ctx.signal_txq_event(); |
| 719 | |
| 720 | // Both available RX and TX descriptors should have been used. |
| 721 | assert_eq!(ctx.guest_txvq.used.idx.get(), 1); |
| 722 | assert_eq!(ctx.guest_rxvq.used.idx.get(), 1); |
| 723 | } |
| 724 | |
| 725 | // Test case: |
| 726 | // - the driver has something to send (there's data in the TX queue); and |
| 727 | // - the backend errors out and cannot process the TX queue. |
| 728 | { |
| 729 | let test_ctx = TestContext::new(); |
| 730 | let mut ctx = test_ctx.create_epoll_handler_context(); |
| 731 | |
| 732 | ctx.handler.backend.write().unwrap().set_pending_rx(false); |
| 733 | ctx.handler |
| 734 | .backend |
| 735 | .write() |
| 736 | .unwrap() |
| 737 | .set_tx_err(Some(VsockError::NoData)); |
| 738 | ctx.signal_txq_event(); |
| 739 | |
| 740 | // Both RX and TX queues should be untouched. |
| 741 | assert_eq!(ctx.guest_txvq.used.idx.get(), 0); |
| 742 | assert_eq!(ctx.guest_rxvq.used.idx.get(), 0); |
| 743 | } |
| 744 | |
| 745 | // Test case: |
| 746 | // - the driver supplied a malformed TX buffer. |
| 747 | { |
| 748 | let test_ctx = TestContext::new(); |
| 749 | let mut ctx = test_ctx.create_epoll_handler_context(); |
| 750 |
nothing calls this directly
no test coverage detected