virtio-devices: vsock: allow fuzzer to use TestBackend

Instead of reinventing this mock infrastructure in the upcoming fuzzer,
reuse the one that is already available.

However this change makes Clippy complain that TestBackend and
TestContext don't implement Default. This is just test code, we can
suppress Clippy in this case.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2024-05-29 00:03:13 +00:00 committed by Wei Liu
parent c801929fd1
commit d359c8cdce

View File

@ -160,8 +160,8 @@ pub trait VsockChannel {
/// translates guest-side vsock connections to host-side Unix domain socket connections.
pub trait VsockBackend: VsockChannel + VsockEpollListener + Send {}
#[cfg(test)]
mod tests {
#[cfg(any(test, fuzzing))]
pub mod tests {
use std::os::unix::io::AsRawFd;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
@ -200,6 +200,7 @@ mod tests {
pub evset: Option<epoll::Events>,
}
impl TestBackend {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
evfd: EventFd::new(EFD_NONBLOCK).unwrap(),
@ -264,6 +265,7 @@ mod tests {
}
impl TestContext {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
const CID: u32 = 52;
const MEM_SIZE: usize = 1024 * 1024 * 128;