defmt icon indicating copy to clipboard operation
defmt copied to clipboard

defmt-test: module support; per module #[init] function

Open japaric opened this issue 4 years ago • 0 comments

context:

  • one test file maps to one firmware image
  • one of the main use cases of having several test files is that you can entirely reconfigure the HW in the #[init] function (one per test file) -- because the target is reset before each test file is run
  • flashing a firmware image takes a while -- way longer that it takes to run the test functions.

goal: allow full HW reconfiguration within a single test file (firmware image)

how:

  • allow modules inside the #[tests] module
  • each module can have a different #[init] function (plus #[test] functions)
  • a software reset happens before each module is executed
#[defmt_test::tests]
mod tests {
  mod foo {
    struct State { }

    #[init]
    fn setup() -> State {
        // ..
    }

    #[test]
    fn a(state: &mut State) {}
  }

  // software reset between `foo::*`  tests and `bar::*` tests

  mod bar {
    struct State { }

    #[init]
    fn setup() -> State {
        // ..
    }

    #[test]
    fn a(state: &mut State) {}

    #[test]
    fn b(state: &mut State) {}
  }
}

TBD: how to tell the target to run the next module group between each test group (module)

japaric avatar Feb 23 '21 19:02 japaric