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...
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

Bolt is a desktop application that is designed to make the process of developing and testing APIs easier and more efficient.

Bolt ⚡ Bolt is a desktop application that is designed to make the process of developing and testing APIs easier and more efficient. Quick start 👩‍💻

Fox Ear is a Linux process behavior trace tool powered by eBPF
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

An asynchronous IO utilities crate powered by tokio.

An asynchronous IO utilities crate powered by tokio.

Extensions for x64dbg written in Rust: Telescope and Unicorn powered disassembly
Extensions for x64dbg written in Rust: Telescope and Unicorn powered disassembly

This is the library that extends x64dbg with new features: Telescope. It's basically recursive dereferencerer of memory view which looks at the pointe

Web-wrapped Supabase desktop app for macOS, Windows & Linux powered by Tauri
Web-wrapped Supabase desktop app for macOS, Windows & Linux powered by Tauri

Supabase Desktop App What is it? It's a cross-platform web-wrapped Supabase desktop app powered by Tauri. You can install it on your macOS, Windows (u

TaurApp is a WhatsApp desktop client powered by Tauri and Rust.
TaurApp is a WhatsApp desktop client powered by Tauri and Rust.

TaurApp TaurApp is a WhatsApp desktop client powered by Tauri and Rust. TaurApp is an experimental client and is initially created to test out Tauri i

A GPT-powered daily newsletter bot, written in Rust
A GPT-powered daily newsletter bot, written in Rust

AI Newsie 1. Introduction Meet AI Newsie - your personalized GPT-powered bot that delivers daily newsletters tailored to your interests. The bot is po

A dead-simple AI-powered CLI tool for effortlessly crafting meaningful Git commit messages
A dead-simple AI-powered CLI tool for effortlessly crafting meaningful Git commit messages

AI Commit Message acm A dead-simple AI-powered CLI tool for effortlessly crafting meaningful Git commit messages. Features Effortlessly create meaning

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 15 Nov 20, 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 776 Jan 1, 2023
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 103 Dec 23, 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 32 Dec 28, 2022
Stdto provides a set of functional traits for conversion between various data representations.

Stdto stdto provides a set of functional traits for conversion between various data representations. | Examples | Docs | Latest Note | stdto = "0.13.0

Doha Lee 5 Dec 21, 2022
A modular and blazing fast runtime security framework for the IoT, powered by eBPF.

Pulsar is a security tool for monitoring the activity of Linux devices at runtime, powered by eBPF. The Pulsar core modules use eBPF probes to collect

Exein.io 319 Jul 8, 2023
A 3dprinter/cnc firmware framework powered by rust embassy

Printhor: The highly reliable but not necessarily functional 3D printer firmware If you are using this product or like the project, please ★ this repo

Carlos Barrales 26 Nov 15, 2023
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 229 Dec 28, 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