AvrTesterBuilder

Struct AvrTesterBuilder 

Source
pub struct AvrTesterBuilder { /* private fields */ }

Implementations§

Source§

impl AvrTesterBuilder

Source

pub fn new(mcu: impl ToString) -> Self

Creates AvrTesterBuilder.

To avoid typos, it’s preferred that you use helper functions such as AvrTester::atmega328p() - this constructor is provided just in case.

Source

pub fn with_clock(self, clock: u32) -> Self

Specifies AVR’s clock.

This value doesn’t affect how fast the simulation is run - it’s used mostly so that AvrTester::run_for_s() and similar functions know how long a second, a millisecond etc. should be.

See:

Source

pub fn with_clock_of_1_mhz(self) -> Self

Source

pub fn with_clock_of_4_mhz(self) -> Self

Source

pub fn with_clock_of_8_mhz(self) -> Self

Source

pub fn with_clock_of_12_mhz(self) -> Self

Source

pub fn with_clock_of_16_mhz(self) -> Self

Source

pub fn with_clock_of_20_mhz(self) -> Self

Source

pub fn with_clock_of_24_mhz(self) -> Self

Source

pub fn with_timeout(self, timeout: Duration) -> Self

Specifies a timeout (in AVR’s time¹) after which calling AvrTester::run() (or a similar function) will panic, aborting the test to signal that it has timed out.

This might come handy in tests that wait for AVR to do something:

let mut avr = AvrTester::atmega328p()
    .with_clock_of_16_mhz()
    .with_timeout_of_s(1)
    .load("...");

while avr.pins().pb1().is_low() {
    avr.run_for_ms(1);
}

/* do something else later */

… as otherwise, without specifying the timeout, if the tested firmware misbehaves (and e.g. doesn’t toggle the expected pin), the test would be running in an infinite loop (instead of failing).

¹ using AVR’s time instead of the host’s time allows to assert this reliably - whatever timeout you set here will be consistent across all machines.

Source

pub fn with_timeout_of_s(self, s: u64) -> Self

Specifies a timeout in seconds (of AVR’s time).

See: Self::with_timeout().

Source

pub fn with_timeout_of_ms(self, ms: u64) -> Self

Specifies a timeout in milliseconds (of AVR’s time).

See: Self::with_timeout().

Source

pub fn with_timeout_of_us(self, us: u64) -> Self

Specifies a timeout in microseconds (of AVR’s time).

See: Self::with_timeout().

Source

pub fn load(self, firmware: impl AsRef<Path>) -> AvrTester

Loads given firmware (an *.elf file) and boots the simulator.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.