#test-cases #unit-testing #case #bare-metal #test

bare-test

A test framework for bare metal

9 releases

0.1.3 Nov 14, 2024
0.1.2 Nov 14, 2024
0.0.5 Nov 5, 2024
0.0.3 Oct 31, 2024

#215 in Testing

Download history 333/week @ 2024-10-28 225/week @ 2024-11-04 449/week @ 2024-11-11 45/week @ 2024-11-18

1,052 downloads per month
Used in 2 crates

MPL-2.0 license

57KB
1.5K SLoC

Rust 1K SLoC // 0.0% comments GNU Style Assembly 187 SLoC // 0.1% comments

Bare Test

A test framework for testing the bare metal.

Usage

  1. Install ostool.

    cargo install ostool
    
  2. setup .cargo/config.toml

    [target.'cfg(all(target_os = "none"))']
    runner = "ostool cargo-test"
    [build]
    target = "aarch64-unknown-none"
    
  3. setup cargo.toml.

    [dev-dependencies]
    bare-test = "0.0.1"
    
    [build-dependencies]
    sparreal-macros = "0.0.1"
    
  4. setup build.rs.

    fn main() {
        sparreal_macros::build_test_setup!();
    }
    
  5. new tests dir and add tests.rs.

    #![no_std]
    #![no_main]
    #![feature(custom_test_frameworks)]
    #![test_runner(bare_test::test_runner)]
    #![reexport_test_harness_main = "test_main"]
    
    extern crate bare_test;
    
    #[bare_test::entry]
    fn main() {
        test_main();
    }
    
    use bare_test::println;
    #[test_case]
    fn it_not_works() {
        println!("test2... ");
        assert_eq!(1, 2);
    }
    #[test_case]
    fn it_works1() {
        println!("test1... ");
        assert_eq!(1, 1);
    }
    #[test_case]
    fn test_uart(){
        // map uart data register for using.
        let uart_data_reg = iomap(0x9000000.into(), 0x1000);
    
        // write to uart, then it will be print to the screen.
        unsafe{
            uart_data_reg.write_volatile(b'A');
            uart_data_reg.write_volatile(b'\n');
        }
    
        println!("uart test passed!");
    }
    
  6. run cargo test --test tests -- --show-output.

Dependencies

~1.7–2.7MB
~53K SLoC