Crates.io | avr-tester |
lib.rs | avr-tester |
version | |
source | src |
created_at | 2022-06-11 17:55:57.178951 |
updated_at | 2024-10-29 19:54:26.042418 |
description | Framework for testing AVR binaries |
homepage | |
repository | https://github.com/Patryk27/avr-tester |
max_upload_size | |
id | 604163 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Framework for testing AVR binaries, powered by simavr.
tl;dr get your microcontroller's firmware black-box-tested in seconds!
Create a crate dedicated to your firmware's tests:
$ cargo new firmware-tests --lib
... add avr-tester
as its dependency:
# firmware-tests/Cargo.toml
[dependencies]
avr-tester = "0.3"
... and start writing tests:
// firmware-tests/src/lib.rs
use avr_tester::*;
fn avr() -> AvrTester {
AvrTester::atmega328p()
.with_clock_of_16_mhz()
.load("../../firmware/target/atmega328p/release/firmware.elf")
}
// Assuming `firmware` implements a ROT-13 encoder:
#[test]
fn short_text() {
let mut avr = avr();
// Let's give our firmware a moment to initialize:
avr.run_for_ms(1);
// Now, let's send the string:
avr.uart0().write("Hello, World!");
// ... give the AVR a moment to retrieve it & send back, encoded:
avr.run_for_ms(1);
// ... and, finally, let's assert the outcome:
assert_eq!("Uryyb, Jbeyq!", avr.uart0().read::<String>());
}
#[test]
fn long_text() {
let mut avr = avr();
avr.run_for_ms(1);
avr.uart0().write("Lorem ipsum dolor sit amet, consectetur adipiscing elit");
avr.run_for_ms(10);
assert_eq!(
"Yberz vcfhz qbybe fvg nzrg, pbafrpgrghe nqvcvfpvat ryvg",
avr.uart0().read::<String>(),
);
}
... having the tests ready, just run cargo test
inside firmware-tests
:-)
Since AvrTester emulates an actual AVR, you don't have to modify your firmware at all - it can use timers, GPIOs etc. and everything should just work ™.
In fact, your project doesn't even have to be written in Rust - you can create Rust tests for a firmware written in C, Zig and anything else!
See more: <./avr-tester/tests/examples>.
See: simavr-ffi.
Following features are supported by simavr, but haven't been yet exposed in AvrTester:
Your firmware can use those features, you just won't be able to test them.
Pull requests are very much welcome!
Use just test
to test AvrTester (so meta!) -- note that you might need some
additional dependencies:
$ nix develop
# and then `just test`
$ sudo apt install avr-libc gcc-avr
# and then `just test`
Copyright (c) 2022 Patryk Wychowaniec pwychowaniec@pm.me.
Licensed under the MIT license.