Skip to content

Commit

Permalink
Add tests for default impls of Frontend req handlers
Browse files Browse the repository at this point in the history
Add tests to assert return values (and existence) of default implemenation
of VhostUserFrontendReqHandler and VhostUserFrontendReqHandlerMut trait
methods.

Signed-off-by: Matej Hrica <mhrica@redhat.com>
  • Loading branch information
mtjhrc committed Aug 28, 2024
1 parent e0c1a35 commit 2692156
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions vhost/src/vhost_user/frontend_req_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ mod tests {
use super::*;

use std::collections::HashSet;
use std::io::ErrorKind;

use uuid::Uuid;

Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 2692156

Please sign in to comment.