mirror of
https://github.com/rust-vmm/vhost-device.git
synced 2025-12-29 00:41:19 +00:00
Add more tests in vhost-device-vsock to increase the coverage.
Some of them are really simple and perhaps nonsensical (tests for
Debug, Clone, etc.), but for now we don't know how to disable this
in the tool, so let's cover these cases.
The vhost-device-vsock functions coverage increases from 70.73% to
90.45%:
Filename Functions Missed Functions Executed
----------------------------------------------------------
main.rs 51 12 76.47%
rxops.rs 8 0 100.00%
rxqueue.rs 20 0 100.00%
thread_backend.rs 20 3 85.00%
txbuf.rs 17 0 100.00%
vhu_vsock.rs 37 1 97.30%
vhu_vsock_thread.rs 40 5 87.50%
vsock_conn.rs 27 0 100.00%
----------------------------------------------------------
TOTAL 220 21 90.45%
Closes #229
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
45 lines
1012 B
Rust
45 lines
1012 B
Rust
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
|
|
|
|
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
|
pub(crate) enum RxOps {
|
|
/// VSOCK_OP_REQUEST
|
|
Request = 0,
|
|
/// VSOCK_OP_RW
|
|
Rw = 1,
|
|
/// VSOCK_OP_RESPONSE
|
|
Response = 2,
|
|
/// VSOCK_OP_CREDIT_UPDATE
|
|
CreditUpdate = 3,
|
|
/// VSOCK_OP_RST
|
|
Reset = 4,
|
|
}
|
|
|
|
impl RxOps {
|
|
/// Convert enum value into bitmask.
|
|
pub fn bitmask(self) -> u8 {
|
|
1u8 << (self as u8)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_rxops() {
|
|
let rx = RxOps::Request;
|
|
// Increase coverage testing Clone and Debug traits
|
|
assert_eq!(rx, rx.clone());
|
|
assert_eq!(format!("{rx:?}"), "Request");
|
|
}
|
|
|
|
#[test]
|
|
fn test_bitmask() {
|
|
assert_eq!(1, RxOps::Request.bitmask());
|
|
assert_eq!(2, RxOps::Rw.bitmask());
|
|
assert_eq!(4, RxOps::Response.bitmask());
|
|
assert_eq!(8, RxOps::CreditUpdate.bitmask());
|
|
assert_eq!(16, RxOps::Reset.bitmask());
|
|
}
|
|
}
|