Git Product home page Git Product logo

cortest's Introduction

Status

This project has been DEPRECATED in favor of utest, which is a more general no-std testing framework.

-- @japaric, 2017-04-01


cortest

Minimal re-implementation of std for testing (q)emulated Cortex-M processors

This library gives you access to some of std functionality, like standard I/O, on the following targets

  • thumbv6m-none-eabi
  • thumbv7em-none-eabi
  • thumbv7em-none-eabihf
  • thumbv7m-none-eabi

Programs linked to this library are meant to be executed using QEMU (in user emulation mode) and won't work when flashed on a microcontroller.

Examples

Hello, world!

Here's the classic "Hello, world!" program

#![no_main]
#![no_std]

#[macro_use]
extern crate cortest;

#[no_mangle]
pub fn main() -> i32 {
    println!("Hello, world!");
    0
}

Note that main returns an i32 value. That's the exit code of the program.

$ xargo rustc --target thumbv7m-none-eabi -- -C link-arg=-nostartfiles

$ qemu-arm -cpu cortex-m3 target/thumbv7m-none-eabi/debug/examples/hello
Hello, world!

Panicking

panic! works and gives you information about where the panic! originated.

#![no_main]
#![no_std]

extern crate cortest;

#[no_mangle]
pub fn main() -> i32 {
    panic!()
}
$ qemu-arm -cpu cortex-m3 target/thumbv7m-none-eabi/debug/examples/panic
panicked at 'explicit panic', examples/panic.rs:8

Testing

This crate provides a test! macro that you can use to define unit tests.

#![no_main]
#![no_std]

#[macro_use]
extern crate cortest;

test! {
    fn equal() -> bool {
        42 == 42
    }

    fn different() -> bool {
        42 != 24
    }

    fn failed() -> bool {
        false
    }
}

Each unit test must return a bool value that indicates whether the test succeeded (true) or failed (false).

$ qemu-arm -cpu cortex-m3 target/thumbv7m-none-eabi/debug/examples/test
running 3 tests
test equal ... ok
test different ... ok
test failed ... FAILED

test result: FAILED. 2 passed; 1 failed

$ echo $?
101

Note that there is no unwinding support in this crate so an failed assert! will "take down" the test runner and the rest of tests won't run.

Known limitations

  • QEMU user emulation mode doesn't emulate "hardware" so programs linked to this library can't use Cortex-M peripherals like SysTick.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

cortest's People

Contributors

bobo1239 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.