diff --git a/vhost-device-vsock/Cargo.toml b/vhost-device-vsock/Cargo.toml index 149df3a..b361b0c 100644 --- a/vhost-device-vsock/Cargo.toml +++ b/vhost-device-vsock/Cargo.toml @@ -37,3 +37,6 @@ serde = { version = "1", features = ["derive"] } assert_matches = "1.5" virtio-queue = { version = "0.16", features = ["test-utils"] } tempfile = "3.20.0" + +[lints] +workspace = true diff --git a/vhost-device-vsock/src/thread_backend.rs b/vhost-device-vsock/src/thread_backend.rs index 72cf783..44a1f1e 100644 --- a/vhost-device-vsock/src/thread_backend.rs +++ b/vhost-device-vsock/src/thread_backend.rs @@ -563,26 +563,26 @@ mod tests { Error::EmptyBackendRxQ.to_string() ); - assert!(vtp.send_pkt(&packet).is_ok()); + vtp.send_pkt(&packet).unwrap(); packet.set_type(VSOCK_TYPE_STREAM); - assert!(vtp.send_pkt(&packet).is_ok()); + vtp.send_pkt(&packet).unwrap(); packet.set_src_cid(CID); packet.set_dst_cid(VSOCK_HOST_CID); packet.set_dst_port(VSOCK_PEER_PORT); - assert!(vtp.send_pkt(&packet).is_ok()); + vtp.send_pkt(&packet).unwrap(); packet.set_op(VSOCK_OP_REQUEST); - assert!(vtp.send_pkt(&packet).is_ok()); + vtp.send_pkt(&packet).unwrap(); packet.set_op(VSOCK_OP_RW); - assert!(vtp.send_pkt(&packet).is_ok()); + vtp.send_pkt(&packet).unwrap(); packet.set_op(VSOCK_OP_RST); - assert!(vtp.send_pkt(&packet).is_ok()); + vtp.send_pkt(&packet).unwrap(); - assert!(vtp.recv_pkt(&mut packet).is_ok()); + vtp.recv_pkt(&mut packet).unwrap(); // TODO: it is a nop for now vtp.enq_rst(); @@ -714,7 +714,7 @@ mod tests { .unwrap() .copy_from(&[0xCAu8, 0xFEu8, 0xBAu8, 0xBEu8]); - assert!(vtp.send_pkt(&packet).is_ok()); + vtp.send_pkt(&packet).unwrap(); assert!(sibling_backend.threads[0] .lock() .unwrap() @@ -722,7 +722,7 @@ mod tests { .pending_raw_pkts()); packet.set_dst_cid(SIBLING2_CID); - assert!(vtp.send_pkt(&packet).is_ok()); + vtp.send_pkt(&packet).unwrap(); // packet should be discarded since sibling2 is not in the same group assert!(!sibling2_backend.threads[0] .lock() @@ -737,12 +737,12 @@ mod tests { // SAFETY: Safe as recvd_hdr_raw and recvd_data_raw are guaranteed to be valid. unsafe { VsockPacket::new(recvd_hdr_raw, Some(recvd_data_raw)).unwrap() }; - assert!(sibling_backend.threads[0] + sibling_backend.threads[0] .lock() .unwrap() .thread_backend .recv_raw_pkt(&mut recvd_packet) - .is_ok()); + .unwrap(); assert_eq!(recvd_packet.type_(), VSOCK_TYPE_STREAM); assert_eq!(recvd_packet.src_cid(), CID); diff --git a/vhost-device-vsock/src/txbuf.rs b/vhost-device-vsock/src/txbuf.rs index ad6a6f6..77e93c9 100644 --- a/vhost-device-vsock/src/txbuf.rs +++ b/vhost-device-vsock/src/txbuf.rs @@ -147,7 +147,7 @@ mod tests { // push data into empty tx buffer let res_push = loc_tx_buf.push(&data); - assert!(res_push.is_ok()); + res_push.unwrap(); assert_eq!(loc_tx_buf.head, Wrapping(0)); assert_eq!(loc_tx_buf.tail, Wrapping(CONN_TX_BUF_SIZE)); @@ -158,7 +158,7 @@ mod tests { // head and tail wrap at full loc_tx_buf.head = Wrapping(CONN_TX_BUF_SIZE); let res_push = loc_tx_buf.push(&data); - assert!(res_push.is_ok()); + res_push.unwrap(); assert_eq!(loc_tx_buf.tail, Wrapping(CONN_TX_BUF_SIZE * 2)); // only tail wraps at full @@ -168,7 +168,7 @@ mod tests { loc_tx_buf.head = Wrapping(2); loc_tx_buf.tail = Wrapping(CONN_TX_BUF_SIZE - 2); let res_push = loc_tx_buf.push(&data); - assert!(res_push.is_ok()); + res_push.unwrap(); assert_eq!(loc_tx_buf.head, Wrapping(2)); assert_eq!(loc_tx_buf.tail, Wrapping(CONN_TX_BUF_SIZE + 2)); assert_eq!(loc_tx_buf.buf[0..2], buf[2..4]); @@ -197,7 +197,7 @@ mod tests { // flush data of CONN_TX_BUF_SIZE amount let res_push = loc_tx_buf.push(&data); - assert!(res_push.is_ok()); + res_push.unwrap(); let res_flush = loc_tx_buf.flush_to(&mut cmp_vec); if let Ok(n) = res_flush { assert_eq!(loc_tx_buf.head, Wrapping(n as u32)); @@ -215,7 +215,7 @@ mod tests { loc_tx_buf.head = Wrapping(0); loc_tx_buf.tail = Wrapping(0); let res_push = loc_tx_buf.push(&data); - assert!(res_push.is_ok()); + res_push.unwrap(); cmp_vec.clear(); loc_tx_buf.head = Wrapping(CONN_TX_BUF_SIZE / 2); loc_tx_buf.tail = Wrapping(CONN_TX_BUF_SIZE + (CONN_TX_BUF_SIZE / 2)); diff --git a/vhost-device-vsock/src/vhu_vsock.rs b/vhost-device-vsock/src/vhu_vsock.rs index 8e72c2f..00bc9d6 100644 --- a/vhost-device-vsock/src/vhu_vsock.rs +++ b/vhost-device-vsock/src/vhu_vsock.rs @@ -434,7 +434,7 @@ mod tests { vrings[1].set_queue_info(0x1100, 0x1200, 0x1300).unwrap(); vrings[1].set_queue_ready(true); - assert!(backend.update_memory(mem).is_ok()); + backend.update_memory(mem).unwrap(); let queues_per_thread = backend.queues_per_thread(); assert_eq!(queues_per_thread.len(), 1); @@ -450,16 +450,16 @@ mod tests { exit.unwrap().write(1).unwrap(); let ret = backend.handle_event(RX_QUEUE_EVENT, EventSet::IN, &vrings, 0); - assert!(ret.is_ok()); + ret.unwrap(); let ret = backend.handle_event(TX_QUEUE_EVENT, EventSet::IN, &vrings, 0); - assert!(ret.is_ok()); + ret.unwrap(); let ret = backend.handle_event(EVT_QUEUE_EVENT, EventSet::IN, &vrings, 0); - assert!(ret.is_ok()); + ret.unwrap(); let ret = backend.handle_event(BACKEND_EVENT, EventSet::IN, &vrings, 0); - assert!(ret.is_ok()); + ret.unwrap(); } #[test] diff --git a/vhost-device-vsock/src/vhu_vsock_thread.rs b/vhost-device-vsock/src/vhu_vsock_thread.rs index 74b4dba..0799728 100644 --- a/vhost-device-vsock/src/vhu_vsock_thread.rs +++ b/vhost-device-vsock/src/vhu_vsock_thread.rs @@ -861,40 +861,36 @@ mod tests { let dummy_fd = EventFd::new(0).unwrap(); - assert!(VhostUserVsockThread::epoll_register( + VhostUserVsockThread::epoll_register( epoll_fd, dummy_fd.as_raw_fd(), - epoll::Events::EPOLLOUT + epoll::Events::EPOLLOUT, ) - .is_ok()); - assert!(VhostUserVsockThread::epoll_modify( + .unwrap(); + VhostUserVsockThread::epoll_modify(epoll_fd, dummy_fd.as_raw_fd(), epoll::Events::EPOLLIN) + .unwrap(); + VhostUserVsockThread::epoll_unregister(epoll_fd, dummy_fd.as_raw_fd()).unwrap(); + VhostUserVsockThread::epoll_register( epoll_fd, dummy_fd.as_raw_fd(), - epoll::Events::EPOLLIN + epoll::Events::EPOLLIN, ) - .is_ok()); - assert!(VhostUserVsockThread::epoll_unregister(epoll_fd, dummy_fd.as_raw_fd()).is_ok()); - assert!(VhostUserVsockThread::epoll_register( - epoll_fd, - dummy_fd.as_raw_fd(), - epoll::Events::EPOLLIN - ) - .is_ok()); + .unwrap(); let vring = VringRwLock::new(mem, 0x1000).unwrap(); vring.set_queue_info(0x100, 0x200, 0x300).unwrap(); vring.set_queue_ready(true); - assert!(t.process_tx(&vring, false).is_ok()); - assert!(t.process_tx(&vring, true).is_ok()); + t.process_tx(&vring, false).unwrap(); + t.process_tx(&vring, true).unwrap(); // add backend_rxq to avoid that RX processing is skipped t.thread_backend .backend_rxq .push_back(ConnMapKey::new(0, 0)); - assert!(t.process_rx(&vring, false).is_ok()); - assert!(t.process_rx(&vring, true).is_ok()); - assert!(t.process_raw_pkts(&vring, false).is_ok()); - assert!(t.process_raw_pkts(&vring, true).is_ok()); + t.process_rx(&vring, false).unwrap(); + t.process_rx(&vring, true).unwrap(); + t.process_raw_pkts(&vring, false).unwrap(); + t.process_raw_pkts(&vring, true).unwrap(); VhostUserVsockThread::vring_handle_event(EventData { vring: vring.clone(), diff --git a/vhost-device-vsock/src/vsock_conn.rs b/vhost-device-vsock/src/vsock_conn.rs index 39bbba4..aee4fc1 100644 --- a/vhost-device-vsock/src/vsock_conn.rs +++ b/vhost-device-vsock/src/vsock_conn.rs @@ -473,7 +473,7 @@ mod tests { )); mem.write(&header, SplitDescriptor::from(head_desc).addr()) .unwrap(); - assert!(virt_queue.desc_table().store(0, head_desc).is_ok()); + virt_queue.desc_table().store(0, head_desc).unwrap(); next_addr += head_params.head_len as u64; // Put the descriptor index 0 in the first available ring position. @@ -500,8 +500,8 @@ mod tests { )); mem.write(&data, SplitDescriptor::from(data_desc).addr()) .unwrap(); - assert!(virt_queue.desc_table().store(i + 1, data_desc).is_ok()); - next_addr += head_data_len as u64; + virt_queue.desc_table().store(i + 1, data_desc).unwrap(); + next_addr += u64::from(head_data_len); } // Create descriptor chain from pre-filled memory @@ -625,7 +625,7 @@ mod tests { fn test_vsock_conn_init() { // new locally inititated connection let mut dummy_file = VsockDummySocket::new(); - assert!(dummy_file.flush().is_ok()); + dummy_file.flush().unwrap(); let mut conn_local = VsockConnection::new_local_init( dummy_file, VSOCK_HOST_CID, @@ -761,14 +761,14 @@ mod tests { // VSOCK_OP_REQUEST: new local conn request conn_local.rx_queue.enqueue(RxOps::Request); let op_req = conn_local.recv_pkt(&mut pkt); - assert!(op_req.is_ok()); + op_req.unwrap(); assert!(!conn_local.rx_queue.pending_rx()); assert_eq!(pkt.op(), VSOCK_OP_REQUEST); // VSOCK_OP_RST: reset if connection not established conn_local.rx_queue.enqueue(RxOps::Rw); let op_rst = conn_local.recv_pkt(&mut pkt); - assert!(op_rst.is_ok()); + op_rst.unwrap(); assert!(!conn_local.rx_queue.pending_rx()); assert_eq!(pkt.op(), VSOCK_OP_RST); @@ -777,7 +777,7 @@ mod tests { conn_local.rx_queue.enqueue(RxOps::Rw); conn_local.fwd_cnt = Wrapping(1024); let op_credit_update = conn_local.recv_pkt(&mut pkt); - assert!(op_credit_update.is_ok()); + op_credit_update.unwrap(); assert!(!conn_local.rx_queue.pending_rx()); assert_eq!(pkt.op(), VSOCK_OP_CREDIT_REQUEST); assert_eq!(conn_local.last_fwd_cnt, Wrapping(1024)); @@ -786,7 +786,7 @@ mod tests { conn_local.peer_buf_alloc = 65536; conn_local.rx_queue.enqueue(RxOps::Rw); let op_zero_read_shutdown = conn_local.recv_pkt(&mut pkt); - assert!(op_zero_read_shutdown.is_ok()); + op_zero_read_shutdown.unwrap(); assert!(!conn_local.rx_queue.pending_rx()); assert_eq!(conn_local.rx_cnt, Wrapping(0)); assert_eq!(conn_local.last_fwd_cnt, Wrapping(1024)); @@ -801,20 +801,20 @@ mod tests { host_socket.write_all(payload).unwrap(); conn_local.rx_queue.enqueue(RxOps::Rw); let op_zero_read = conn_local.recv_pkt(&mut pkt); - assert!(op_zero_read.is_ok()); + op_zero_read.unwrap(); assert_eq!(pkt.op(), VSOCK_OP_RW); assert!(!conn_local.rx_queue.pending_rx()); assert_eq!(conn_local.rx_cnt, Wrapping(payload.len() as u32)); assert_eq!(conn_local.last_fwd_cnt, Wrapping(1024)); assert_eq!(pkt.len(), 5); let buf = &mut [0u8; 5]; - assert!(pkt.data_slice().unwrap().read_slice(buf, 0).is_ok()); + pkt.data_slice().unwrap().read_slice(buf, 0).unwrap(); assert_eq!(buf, b"hello"); // VSOCK_OP_RESPONSE: response from a locally initiated connection conn_local.rx_queue.enqueue(RxOps::Response); let op_response = conn_local.recv_pkt(&mut pkt); - assert!(op_response.is_ok()); + op_response.unwrap(); assert!(!conn_local.rx_queue.pending_rx()); assert_eq!(pkt.op(), VSOCK_OP_RESPONSE); assert!(conn_local.connect); @@ -823,7 +823,7 @@ mod tests { conn_local.rx_queue.enqueue(RxOps::CreditUpdate); let op_credit_update = conn_local.recv_pkt(&mut pkt); assert!(!conn_local.rx_queue.pending_rx()); - assert!(op_credit_update.is_ok()); + op_credit_update.unwrap(); assert_eq!(pkt.op(), VSOCK_OP_CREDIT_UPDATE); assert_eq!(conn_local.last_fwd_cnt, Wrapping(1024)); @@ -861,7 +861,7 @@ mod tests { // check if peer credit information is updated currently let credit_check = conn_local.send_pkt(&pkt); - assert!(credit_check.is_ok()); + credit_check.unwrap(); assert_eq!(conn_local.peer_buf_alloc, 65536); assert_eq!(conn_local.peer_fwd_cnt, Wrapping(1024)); @@ -869,7 +869,7 @@ mod tests { pkt.set_op(VSOCK_OP_RESPONSE); assert_eq!(conn_local.peer_port, 5001); let peer_response = conn_local.send_pkt(&pkt); - assert!(peer_response.is_ok()); + peer_response.unwrap(); assert!(conn_local.connect); let mut resp_buf = vec![0; 8]; host_socket.read_exact(&mut resp_buf).unwrap(); @@ -878,9 +878,9 @@ mod tests { // VSOCK_OP_RW pkt.set_op(VSOCK_OP_RW); let buf = b"hello"; - assert!(pkt.data_slice().unwrap().write_slice(buf, 0).is_ok()); + pkt.data_slice().unwrap().write_slice(buf, 0).unwrap(); let rw_response = conn_local.send_pkt(&pkt); - assert!(rw_response.is_ok()); + rw_response.unwrap(); let mut resp_buf = vec![0; 5]; host_socket.read_exact(&mut resp_buf).unwrap(); assert_eq!(resp_buf, b"hello"); @@ -888,14 +888,14 @@ mod tests { // VSOCK_OP_CREDIT_REQUEST pkt.set_op(VSOCK_OP_CREDIT_REQUEST); let credit_response = conn_local.send_pkt(&pkt); - assert!(credit_response.is_ok()); + credit_response.unwrap(); assert_eq!(conn_local.rx_queue.peek().unwrap(), RxOps::CreditUpdate); // VSOCK_OP_SHUTDOWN pkt.set_op(VSOCK_OP_SHUTDOWN); pkt.set_flags(VSOCK_FLAGS_SHUTDOWN_RCV | VSOCK_FLAGS_SHUTDOWN_SEND); let shutdown_response = conn_local.send_pkt(&pkt); - assert!(shutdown_response.is_ok()); + shutdown_response.unwrap(); assert!(conn_local.rx_queue.contains(RxOps::Reset.bitmask())); } }