From 0cd34a69ab8f572c70cc72bdcb405b54f71caa7e Mon Sep 17 00:00:00 2001 From: Stefano Garzarella Date: Thu, 5 Dec 2024 16:47:37 +0100 Subject: [PATCH] vsock/tests: panic if vsock_loopback is not available test_vsock_thread_backend_vsock() and test_vsock_thread_vsock_backend() tests use VMADDR_CID_LOCAL which is provided by the `vsock_loopback` kernel module. If `vsock_loopback` kernel module is not loaded, these tests will fail later with unclear messages, so it can be hard to debug. Let's fail early and print a message with the requirement. Signed-off-by: Stefano Garzarella --- vhost-device-vsock/src/thread_backend.rs | 4 ++++ vhost-device-vsock/src/vhu_vsock_thread.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/vhost-device-vsock/src/thread_backend.rs b/vhost-device-vsock/src/thread_backend.rs index 039e033..6965683 100644 --- a/vhost-device-vsock/src/thread_backend.rs +++ b/vhost-device-vsock/src/thread_backend.rs @@ -604,6 +604,10 @@ mod tests { #[cfg(feature = "backend_vsock")] #[test] fn test_vsock_thread_backend_vsock() { + VsockListener::bind_with_cid_port(VMADDR_CID_LOCAL, libc::VMADDR_PORT_ANY).expect( + "This test uses VMADDR_CID_LOCAL, so the vsock_loopback kernel module must be loaded", + ); + let _listener = VsockListener::bind_with_cid_port(VMADDR_CID_ANY, VSOCK_PEER_PORT).unwrap(); let backend_info = BackendType::Vsock(VsockProxyInfo { forward_cid: VMADDR_CID_LOCAL, diff --git a/vhost-device-vsock/src/vhu_vsock_thread.rs b/vhost-device-vsock/src/vhu_vsock_thread.rs index bfaff57..1db9f09 100644 --- a/vhost-device-vsock/src/vhu_vsock_thread.rs +++ b/vhost-device-vsock/src/vhu_vsock_thread.rs @@ -1041,6 +1041,10 @@ mod tests { #[cfg(feature = "backend_vsock")] #[test] fn test_vsock_thread_vsock_backend() { + VsockListener::bind_with_cid_port(VMADDR_CID_LOCAL, libc::VMADDR_PORT_ANY).expect( + "This test uses VMADDR_CID_LOCAL, so the vsock_loopback kernel module must be loaded", + ); + let groups: Vec = vec![String::from("default")]; let cid_map: Arc> = Arc::new(RwLock::new(HashMap::new()));