pub struct DeviceTestDmaClient<C>where
C: DeviceTestDmaClientCallbacks,{ /* private fields */ }Expand description
A DMA client that uses a [PagePoolAllocator] as the backing. It can be customized through the use of
DeviceTestDmaClientCallbacks to modify its behaviour for testing purposes.
§Example
use std::sync::Arc;
use user_driver::DmaClient;
use user_driver_emulated_mock::DeviceTestDmaClient;
use page_pool_alloc::PagePoolAllocator;
struct MyCallbacks;
impl user_driver_emulated_mock::DeviceTestDmaClientCallbacks for MyCallbacks {
fn allocate_dma_buffer(
&self,
allocator: &page_pool_alloc::PagePoolAllocator,
total_size: usize,
) -> anyhow::Result<user_driver::memory::MemoryBlock> {
// Custom test logic here, for example:
anyhow::bail!("allocation failed for testing");
}
fn attach_pending_buffers(
&self,
allocator: &page_pool_alloc::PagePoolAllocator,
) -> anyhow::Result<Vec<user_driver::memory::MemoryBlock>> {
// Custom test logic here, for example:
anyhow::bail!("attachment failed for testing");
}
}
// Use the above in a test ...
fn test_dma_client() {
let pages = 1000;
let device_test_memory = user_driver_emulated_mock::DeviceTestMemory::new(
pages,
true,
"test_dma_client",
);
let page_pool_allocator = device_test_memory.dma_client();
let dma_client = DeviceTestDmaClient::new(page_pool_allocator, MyCallbacks);
// Use dma_client in tests...
assert!(dma_client.allocate_dma_buffer(4096).is_err());
}Implementations§
Source§impl<C: DeviceTestDmaClientCallbacks> DeviceTestDmaClient<C>
impl<C: DeviceTestDmaClientCallbacks> DeviceTestDmaClient<C>
Sourcepub fn new(inner: Arc<PagePoolAllocator>, callbacks: C) -> Self
pub fn new(inner: Arc<PagePoolAllocator>, callbacks: C) -> Self
Creates a new DeviceTestDmaClient with the given inner allocator.
Trait Implementations§
Source§impl<C: DeviceTestDmaClientCallbacks> DmaClient for DeviceTestDmaClient<C>
impl<C: DeviceTestDmaClientCallbacks> DmaClient for DeviceTestDmaClient<C>
Source§impl<C> Inspect for DeviceTestDmaClient<C>where
C: DeviceTestDmaClientCallbacks,
impl<C> Inspect for DeviceTestDmaClient<C>where
C: DeviceTestDmaClientCallbacks,
Auto Trait Implementations§
impl<C> Freeze for DeviceTestDmaClient<C>where
C: Freeze,
impl<C> !RefUnwindSafe for DeviceTestDmaClient<C>
impl<C> Send for DeviceTestDmaClient<C>
impl<C> Sync for DeviceTestDmaClient<C>
impl<C> Unpin for DeviceTestDmaClient<C>where
C: Unpin,
impl<C> !UnwindSafe for DeviceTestDmaClient<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more