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

Function test_backend_event

virtio-devices/src/vsock/device.rs:868–920  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

866
867 #[test]
868 fn test_backend_event() {
869 // Test case:
870 // - a backend event is received; and
871 // - the backend has pending RX data.
872 {
873 let test_ctx = TestContext::new();
874 let mut ctx = test_ctx.create_epoll_handler_context();
875
876 ctx.handler.backend.write().unwrap().set_pending_rx(true);
877
878 let events = epoll::Events::EPOLLIN;
879 let event = epoll::Event::new(events, BACKEND_EVENT as u64);
880 let mut epoll_helper =
881 EpollHelper::new(&ctx.handler.kill_evt, &ctx.handler.pause_evt).unwrap();
882 ctx.handler.handle_event(&mut epoll_helper, &event).unwrap();
883
884 // The backend should've received this event.
885 assert_eq!(
886 ctx.handler.backend.read().unwrap().evset,
887 Some(epoll::Events::EPOLLIN)
888 );
889 // TX queue processing should've been triggered.
890 assert_eq!(ctx.guest_txvq.used.idx.get(), 1);
891 // RX queue processing should've been triggered.
892 assert_eq!(ctx.guest_rxvq.used.idx.get(), 1);
893 }
894
895 // Test case:
896 // - a backend event is received; and
897 // - the backend doesn't have any pending RX data.
898 {
899 let test_ctx = TestContext::new();
900 let mut ctx = test_ctx.create_epoll_handler_context();
901
902 ctx.handler.backend.write().unwrap().set_pending_rx(false);
903
904 let events = epoll::Events::EPOLLIN;
905 let event = epoll::Event::new(events, BACKEND_EVENT as u64);
906 let mut epoll_helper =
907 EpollHelper::new(&ctx.handler.kill_evt, &ctx.handler.pause_evt).unwrap();
908 ctx.handler.handle_event(&mut epoll_helper, &event).unwrap();
909
910 // The backend should've received this event.
911 assert_eq!(
912 ctx.handler.backend.read().unwrap().evset,
913 Some(epoll::Events::EPOLLIN)
914 );
915 // TX queue processing should've been triggered.
916 assert_eq!(ctx.guest_txvq.used.idx.get(), 1);
917 // The RX queue should've been left untouched.
918 assert_eq!(ctx.guest_rxvq.used.idx.get(), 0);
919 }
920 }
921
922 #[test]
923 fn test_unknown_event() {

Callers

nothing calls this directly

Calls 5

newFunction · 0.85
set_pending_rxMethod · 0.80
writeMethod · 0.45
handle_eventMethod · 0.45

Tested by

no test coverage detected