From 928f270164c2d9cd377b9b52bf953900addaaa4c Mon Sep 17 00:00:00 2001 From: Matej Hrica Date: Wed, 28 Aug 2024 16:20:55 +0200 Subject: [PATCH] Add tests for default impls of Frontend req handlers Add tests to assert return values (and existence) of default implemenation of VhostUserFrontendReqHandler and VhostUserFrontendReqHandlerMut trait methods. Signed-off-by: Matej Hrica --- vhost/src/vhost_user/frontend_req_handler.rs | 67 ++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/vhost/src/vhost_user/frontend_req_handler.rs b/vhost/src/vhost_user/frontend_req_handler.rs index c8cda1e3..1b15ae32 100644 --- a/vhost/src/vhost_user/frontend_req_handler.rs +++ b/vhost/src/vhost_user/frontend_req_handler.rs @@ -396,6 +396,7 @@ mod tests { use super::*; use std::collections::HashSet; + use std::io::ErrorKind; use uuid::Uuid; @@ -449,6 +450,72 @@ mod tests { } } + #[test] + fn test_default_frontend_impl() { + struct Frontend; + impl VhostUserFrontendReqHandler for Frontend {} + + let f = Frontend; + assert_eq!( + f.shared_object_add(&Default::default()).unwrap_err().kind(), + ErrorKind::Unsupported + ); + assert_eq!( + f.shared_object_remove(&Default::default()) + .unwrap_err() + .kind(), + ErrorKind::Unsupported + ); + assert_eq!( + f.shared_object_lookup(&Default::default(), &0) + .unwrap_err() + .kind(), + ErrorKind::Unsupported + ); + + assert_eq!( + f.shmem_map(&Default::default(), &0).unwrap_err().kind(), + ErrorKind::Unsupported + ); + assert_eq!( + f.shmem_unmap(&Default::default()).unwrap_err().kind(), + ErrorKind::Unsupported + ); + } + + #[test] + fn test_default_frontend_impl_mut() { + struct FrontendMut; + impl VhostUserFrontendReqHandlerMut for FrontendMut {} + + let mut f = FrontendMut; + assert_eq!( + f.shared_object_add(&Default::default()).unwrap_err().kind(), + ErrorKind::Unsupported + ); + assert_eq!( + f.shared_object_remove(&Default::default()) + .unwrap_err() + .kind(), + ErrorKind::Unsupported + ); + assert_eq!( + f.shared_object_lookup(&Default::default(), &0) + .unwrap_err() + .kind(), + ErrorKind::Unsupported + ); + + assert_eq!( + f.shmem_map(&Default::default(), &0).unwrap_err().kind(), + ErrorKind::Unsupported + ); + assert_eq!( + f.shmem_unmap(&Default::default()).unwrap_err().kind(), + ErrorKind::Unsupported + ); + } + #[test] fn test_new_frontend_req_handler() { let backend = Arc::new(Mutex::new(MockFrontendReqHandler::new()));