Skip to main content

MockMmioRegionBuilder

Struct MockMmioRegionBuilder 

Source
pub struct MockMmioRegionBuilder { /* private fields */ }
Expand description

Strict thread-safe mock (interaction testing) for MMIO (MmioRegion).

The MmioRegion implementation imposes a global ordering on MMIO accesses performed by multiple threads. If the code under test uses a non-thread-safe MmioRegion implementation, the mock introduces cross-thread synchronization points that do not exist in the code under test.

Expectations are verified after this builder and all the MockMmioRegions it produced are dropped. Tests do not need to keep the builder alive while the code under test uses the regions. Conversely, dropping the builder does not verify expectations while a region is still in use.

Implementations§

Source§

impl MockMmioRegionBuilder

Source

pub fn new(region_size_bytes: usize) -> Self

Creates a new mock MMIO region covering region_size_bytes bytes.

Source

pub fn region_size_bytes(&self) -> usize

Returns the configured region size in bytes.

Source

pub fn expect<F: FnOnce(&mut ExpectedTraceBuilder<'_>)>(&self, f: F)

Posts expectations using the closure trace builder.

ExpectedTraceBuilder implements the expectation API provided to the closure.

Expectations posted by multiple calls are appended to a single global expectation list, in call order.

Source

pub fn build(&self) -> MockMmioRegion

Constructs a splittable, sendable MmioRegion wrapping this mock.

The returned region, and any sub-region split off of it, keeps the expectation list alive. Expectations are verified when the last region and this builder are dropped.

Trait Implementations§

Source§

impl Debug for MockMmioRegionBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.