Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit-Testing with RTIC v2 #959

Open
robamu opened this issue Jul 5, 2024 · 0 comments
Open

Unit-Testing with RTIC v2 #959

robamu opened this issue Jul 5, 2024 · 0 comments

Comments

@robamu
Copy link

robamu commented Jul 5, 2024

Hello,

I have some components in my application which I'd like to unit-test. However, I am not sure how to do this, especially in the presence
of shared resources.

Normally, I would mock some components so I have fine-grained control over input and output. I do not know how to do that with RTIC v2 idiomatically.

Would this be possible by somehow implementing lock for my mock data structures? Maybe some examples would help here as well.

Another problem I found is that I simply can not run even a simple test harness on my host computer.
I get errors like this:

va416xx-rs/flashloader on  bootloader-flashloader [$!+?] is 📦 v0.1.0 via 🦀 v1.78.0
❯ cargo ut -p flashloader
   Compiling flashloader v0.1.0 (/home/rmueller/Rust/va416xx-rs/flashloader)
error[E0412]: cannot find type `Peripherals` in module `rtic::export`
  --> flashloader/src/main.rs:86:1
   |
86 | #[rtic::app(device = pac, dispatchers = [U1])]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `rtic::export`
   |
   = note: this error originates in the attribute macro `rtic::app` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
   |
88 +     use cortex_m::Peripherals;
   |
88 +     use crate::pac::Peripherals;
   |

I also get linker errors which I try a regular cargo test --<host-triplet>, so what I did now was to define an additional library like this

#![no_std]
#[cfg(test)]
extern crate std;

#[cfg(test)]
mod tests {
    #[test]
    fn simple() {
        assert_eq!(1 + 1, 2);
    }
}

and now I can run tests using cargo test --<host-triplet> --lib . Some documentation related to unit-testing/automated testing might be useful. Embedded apps can have complex components where automated testing might be really useful, and ideally I'd like to do that inside the application without the need to create a new library just for that.

Kind Regards
Robin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant