()
| 776 | |
| 777 | #[test] |
| 778 | fn test_rxq_event() { |
| 779 | // Test case: |
| 780 | // - there is pending RX data in the backend; and |
| 781 | // - the driver makes RX buffers available; and |
| 782 | // - the backend successfully places its RX data into the queue. |
| 783 | { |
| 784 | let test_ctx = TestContext::new(); |
| 785 | let mut ctx = test_ctx.create_epoll_handler_context(); |
| 786 | |
| 787 | ctx.handler.backend.write().unwrap().set_pending_rx(true); |
| 788 | ctx.handler |
| 789 | .backend |
| 790 | .write() |
| 791 | .unwrap() |
| 792 | .set_rx_err(Some(VsockError::NoData)); |
| 793 | ctx.signal_rxq_event(); |
| 794 | |
| 795 | // The available RX buffer should've been left untouched. |
| 796 | assert_eq!(ctx.guest_rxvq.used.idx.get(), 0); |
| 797 | } |
| 798 | |
| 799 | // Test case: |
| 800 | // - there is pending RX data in the backend; and |
| 801 | // - the driver makes RX buffers available; and |
| 802 | // - the backend errors out, when attempting to receive data. |
| 803 | { |
| 804 | let test_ctx = TestContext::new(); |
| 805 | let mut ctx = test_ctx.create_epoll_handler_context(); |
| 806 | |
| 807 | ctx.handler.backend.write().unwrap().set_pending_rx(true); |
| 808 | ctx.signal_rxq_event(); |
| 809 | |
| 810 | // The available RX buffer should have been used. |
| 811 | assert_eq!(ctx.guest_rxvq.used.idx.get(), 1); |
| 812 | } |
| 813 | |
| 814 | // Test case: the driver provided a malformed RX descriptor chain. |
| 815 | { |
| 816 | let test_ctx = TestContext::new(); |
| 817 | let mut ctx = test_ctx.create_epoll_handler_context(); |
| 818 | |
| 819 | // Invalidate the packet header descriptor, by setting its length to 0. |
| 820 | ctx.guest_rxvq.dtable[0].len.set(0); |
| 821 | |
| 822 | // The chain should've been processed, without employing the backend. |
| 823 | ctx.handler.process_rx().unwrap(); |
| 824 | assert_eq!(ctx.guest_rxvq.used.idx.get(), 1); |
| 825 | assert_eq!(ctx.handler.backend.read().unwrap().rx_ok_cnt, 0); |
| 826 | } |
| 827 | |
| 828 | // Test case: spurious RXQ_EVENT. |
| 829 | { |
| 830 | let test_ctx = TestContext::new(); |
| 831 | let mut ctx = test_ctx.create_epoll_handler_context(); |
| 832 | ctx.handler.backend.write().unwrap().set_pending_rx(false); |
| 833 | |
| 834 | let events = epoll::Events::EPOLLIN; |
| 835 | let event = epoll::Event::new(events, RX_QUEUE_EVENT as u64); |
nothing calls this directly
no test coverage detected