Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions vhost-device-vsock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,40 @@ application running on the host. Assuming the applications listening on port 900
now run the applications that connect to port 9001 and 9002 (you need to modify the CID they connect to be the host CID i.e. 1)
on the host machine.

## Testing

This crate contains several tests that can be run with `cargo test`.

If `backend_vsock` feature is enabled (true by default), some of the tests use
the AF_VSOCK loopback address [CID = 1] to run the tests, so you must have
loaded the kernel module that handles it (`modprobe vsock_loopback`).

Otherwise you may experience the following failures:
```
...
test thread_backend::tests::test_vsock_thread_backend_vsock ... FAILED
...
test vhu_vsock_thread::tests::test_vsock_thread_vsock_backend ... FAILED

failures:


---- thread_backend::tests::test_vsock_thread_backend_vsock stdout ----
thread 'thread_backend::tests::test_vsock_thread_backend_vsock' panicked at vhost-device-vsock/src/thread_backend.rs:607:84:
This test uses VMADDR_CID_LOCAL, so the vsock_loopback kernel module must be loaded: Os { code: 99, kind: AddrNotAvailable, message: "Cannot assign requested address" }

---- vhu_vsock_thread::tests::test_vsock_thread_vsock_backend stdout ----
thread 'vhu_vsock_thread::tests::test_vsock_thread_vsock_backend' panicked at vhost-device-vsock/src/vhu_vsock_thread.rs:1044:84:
This test uses VMADDR_CID_LOCAL, so the vsock_loopback kernel module must be loaded: Os { code: 99, kind: AddrNotAvailable, message: "Cannot assign requested address" }

failures:
thread_backend::tests::test_vsock_thread_backend_vsock
vhu_vsock_thread::tests::test_vsock_thread_vsock_backend
```

With the `vsock_loopback` kernel module loaded in your system, all the tests
should pass.

## License

This project is licensed under either of
Expand Down
8 changes: 6 additions & 2 deletions vhost-device-vsock/src/thread_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ mod tests {
use tempfile::tempdir;
use virtio_vsock::packet::{VsockPacket, PKT_HEADER_SIZE};
#[cfg(feature = "backend_vsock")]
use vsock::{VsockListener, VMADDR_CID_ANY};
use vsock::{VsockListener, VMADDR_CID_ANY, VMADDR_CID_LOCAL};

const DATA_LEN: usize = 16;
const CONN_TX_BUF_SIZE: u32 = 64 * 1024;
Expand Down Expand Up @@ -604,9 +604,13 @@ 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: 1,
forward_cid: VMADDR_CID_LOCAL,
listen_ports: vec![],
});

Expand Down
12 changes: 8 additions & 4 deletions vhost-device-vsock/src/vhu_vsock_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ mod tests {
use vm_memory::GuestAddress;
use vmm_sys_util::eventfd::EventFd;
#[cfg(feature = "backend_vsock")]
use vsock::VsockStream;
use vsock::{VsockStream, VMADDR_CID_LOCAL};

const CONN_TX_BUF_SIZE: u32 = 64 * 1024;

Expand Down Expand Up @@ -1041,12 +1041,16 @@ 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<String> = vec![String::from("default")];
let cid_map: Arc<RwLock<CidMap>> = Arc::new(RwLock::new(HashMap::new()));

let t = VhostUserVsockThread::new(
BackendType::Vsock(VsockProxyInfo {
forward_cid: 1,
forward_cid: VMADDR_CID_LOCAL,
listen_ports: vec![9003, 9004],
}),
3,
Expand All @@ -1063,8 +1067,8 @@ mod tests {

t.mem = Some(mem.clone());

let mut vs1 = VsockStream::connect_with_cid_port(1, 9003).unwrap();
let mut vs2 = VsockStream::connect_with_cid_port(1, 9004).unwrap();
let mut vs1 = VsockStream::connect_with_cid_port(VMADDR_CID_LOCAL, 9003).unwrap();
let mut vs2 = VsockStream::connect_with_cid_port(VMADDR_CID_LOCAL, 9004).unwrap();
t.process_backend_evt(EventSet::empty());

vs1.write_all(b"some data").unwrap();
Expand Down