Functional testing framework for AVR binaries, powered by simavr.

Overview

avr-tester   crates-badge docs-badge

Functional testing framework for AVR binaries, powered by simavr.

tl;dr get your microcontroller's firmware black-box-tested in seconds!

Status: alpha; work in progress.

Getting Started

Create a crate dedicated to your project's tests:

$ cargo new yourproject-tests --lib

... add avr-tester as its dependency:

# yourproject-tests/Cargo.toml

[dependencies]
avr-tester = "0.1"

... and, just like that, start writing tests:

()); } #[test] fn long_text() { let mut avr = avr(); avr.run_for_ms(1); avr.uart0().send("Lorem ipsum dolor sit amet, consectetur adipiscing elit"); avr.run_for_ms(1); assert_eq!( "Yberz vcfhz qbybe fvg nzrg, pbafrpgrghe nqvcvfpvat ryvg", avr.uart0().recv::(), ); }">
// yourproject-tests/src/lib.rs

use avr_tester::AvrTester;

fn avr() -> AvrTester {
    AvrTester::atmega328p()
        .with_clock_of_16_mhz()
        .load("../../yourproject/target/atmega328p/release/yourproject.elf")
}

// Assuming `yourproject` implements an 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().send("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().recv::<String>());
}

#[test]
fn long_text() {
    let mut avr = avr();

    avr.run_for_ms(1);
    avr.uart0().send("Lorem ipsum dolor sit amet, consectetur adipiscing elit");
    avr.run_for_ms(1);

    assert_eq!(
        "Yberz vcfhz qbybe fvg nzrg, pbafrpgrghe nqvcvfpvat ryvg",
        avr.uart0().recv::<String>(),
    );
}

... having the tests ready (and requirements met!), just run cargo test inside yourproject-tests :-)

Note that because AvrTester simulates an actual AVR, you don't have to modify yourproject at all - it's free to use timers, GPIOs etc. and everything should just work.

In fact, yourproject doesn't even have to be written in Rust - you can create Rust-based tests for a firmware written in C, Zig or anything else!

Usage

Requirements & supported platforms

See: simavr-ffi.

Roadmap

Following features seem to be supported by simavr, but haven't been yet exposed in AvrTester:

(i.e. your firmware can use those features, but you won't be able to test them.)

Caveats

  • Triggering AVR's sleep mode will cause the Rust code to gracefully panic!(), because the only way to wake an AVR is to trigger an interrupt and those are not yet supported.

Contributing

Pull requests are very much welcome!

Tests

AvrTester's integration tests lay in avr-tester/tests - you can run them with:

$ cd avr-tester
$ cargo test

Note that for those tests to work, you might need some additional dependencies:

... on Nix

$ nix-shell
# and then `cargo test`

... on Ubuntu

$ sudo apt install avr-libc gcc-avr
# and then `cargo test`

License

Copyright (c) 2022, Patryk Wychowaniec [email protected].
Licensed under the MIT license.

You might also like...
Framework is a detector for different frameworks in one projects

Framework is a detector for different frameworks in one projects Usage use

Minimal, flexible framework for implementing solutions to Advent of Code in Rust

This is advent_of_code_traits, a minimal, flexible framework for implementing solutions to Advent of Code in Rust.

A new comfortable back end framework for rustaceans.

Black Tea is a new Rust back end framework based on hyper. We are enthusiastic to provide developers some enhanced features and comfortable coding experience.

A framework for iterating over collections of types implementing a trait without virtual dispatch
A framework for iterating over collections of types implementing a trait without virtual dispatch

zero_v Zero_V is an experiment in defining behavior over collections of objects implementing some trait without dynamic polymorphism.

Doku is a framework for building documentation with code-as-data methodology in mind.
Doku is a framework for building documentation with code-as-data methodology in mind.

Doku is a framework for building documentation with code-as-data methodology in mind. Say goodbye to stale, hand-written documentation - with D

Another Async IO Framework based on io_uring

kbio, the Async IO Framework based on io_uring, is used in KuiBaDB to implement async io. Features Support multi-threading concurrent task submission.

Better error messages for axum framework.

axum-debug This is a debugging crate that provides better error messages for axum framework. axum is a great framework for developing web applications

Rust implementation of the Edge IoT framework

A Rust-based implementation of Edge-rs for the Raspberry Pi Pico Getting started For more details see the following article on getting started for get

tracing - a framework for instrumenting Rust programs to collect structured, event-based diagnostic information

tracing-appender Writers for logging events and spans Documentation | Chat Overview tracing is a framework for instrumenting Rust programs to collect

Owner
Patryk Wychowaniec
doing (hopefully useful) computer things | he, him
Patryk Wychowaniec
Progmem utility for the AVR architecture

avr-progmem Progmem utilities for the AVR architectures. This crate provides unsafe utilities for working with data stored in the program memory of an

null 14 Sep 14, 2022
Register access crate for AVR microcontrollers

avr-device Auto-generated wrappers around registers for AVR microcontrollers. Usage Add the following to Cargo.toml: [dependencies.avr-device] version

Rahix 91 Sep 29, 2022
Hardware Abstraction Layer for AVR microcontrollers and common boards

avr-hal Hardware Abstraction Layer for AVR microcontrollers and common boards (for example Arduino). Based on the avr-device crate. This is a new vers

Rahix 657 Sep 27, 2022
AVR device definitions

avrd AVR device definitons in Rust. Documentation This crate exposes information about different AVR microcontrollers so it can be used pragmatically.

The AVR-Rust project 28 Sep 21, 2022
Cargo subcommand for optimizing binaries with PGO and BOLT.

cargo-pgo Cargo subcommand that makes it easier to use PGO and BOLT to optimize Rust binaries. Installation $ cargo install cargo-pgo You will also ne

Jakub Beránek 143 Sep 27, 2022
Fox Ear is a Linux process behavior trace tool powered by eBPF

Fox Ear Fox Ear is a Linux process behavior trace tool powered by eBPF. Banner image by Birger Strahl on Unsplash. Features Log process and its subpro

Rui Li 76 Sep 22, 2022
An asynchronous IO utilities crate powered by tokio.

An asynchronous IO utilities crate powered by tokio.

Harry 2 Aug 18, 2022
Mobile safari / webview remote debugging and e2e testing libraries

Canter (WIP) (WIP) Mobile safari / webview remote debugging and e2e testing libraries. Developed for safari/webview e2e testing on iPhone. Works only

Han Lee 9 Aug 16, 2022
Parses COVID-19 testing data from DC government ArcGIS APIs

covid-dc Parses COVID-19 testing data from DC government ArcGIS APIs Example debug output from cargo run RapidSite { attributes: RapidSiteAttribut

Mike Morris 1 Jan 8, 2022
Noir Pay - Fork of the Light Protocol Program for local testing / optimisation.

Noir Pay v0 Built on Light Protocol Noir Pay will be directly built ontop of the Light Protocol SDK and provide users with a beautifully simple privat

0xNico 1 Feb 12, 2022