Skip to content

Commit 9e1afbc

Browse files
committed
Add basic smoke test
1 parent 5654f2a commit 9e1afbc

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

.cargo/config.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[target.thumbv7m-none-eabi]
2+
# used to run the qemu_test.rs example with QEMU
3+
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
4+
rustflags = ["-C", "link-arg=-Tlink.x"]

.github/workflows/ci.yml

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ jobs:
2828
- if: ${{ matrix.toolchain == 'nightly' }}
2929
run: cargo check --target=${{ matrix.target }} --examples --all-features
3030

31+
test:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: dtolnay/rust-toolchain@master
36+
with:
37+
targets: thumbv7m-none-eabi
38+
toolchain: stable
39+
- name: Install QEMU
40+
run: |
41+
sudo apt update
42+
sudo apt install qemu-system-arm
43+
- run: qemu-system-arm --version
44+
- run: cargo run --target thumbv7m-none-eabi --example integration_test
45+
3146
clippy:
3247
name: Clippy
3348
runs-on: ubuntu-latest

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ version = "0.10.5"
3333
[dev-dependencies]
3434
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
3535
cortex-m-rt = "0.7"
36+
cortex-m-semihosting = "0.5"
37+
panic-semihosting = { version = "0.6", features = ["exit"] }

examples/integration_test.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//! This is a very basic smoke test that runs in QEMU
2+
//! Reference the QEMU section of the [Embedded Rust Book] for more information
3+
//!
4+
//! This only tests integration of the allocator on an embedded target.
5+
//! Comprehensive allocator tests are located in the allocator dependency.
6+
//!
7+
//! After toolchain installation this test can be run with:
8+
//!
9+
//! ```bash
10+
//! cargo run --target thumbv7m-none-eabi --example integration_test
11+
//! ```
12+
//!
13+
//! [Embedded Rust Book]: https://docs.rust-embedded.org/book/intro/index.html
14+
15+
#![no_main]
16+
#![no_std]
17+
18+
extern crate alloc;
19+
extern crate panic_semihosting;
20+
21+
use alloc::vec;
22+
use core::mem::MaybeUninit;
23+
use cortex_m_rt::entry;
24+
use cortex_m_semihosting::{debug, hprintln};
25+
use embedded_alloc::Heap;
26+
27+
#[global_allocator]
28+
static HEAP: Heap = Heap::empty();
29+
30+
#[entry]
31+
fn main() -> ! {
32+
hprintln!("Test start");
33+
34+
{
35+
const HEAP_SIZE: usize = 1024;
36+
static mut HEAP_MEM: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
37+
unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }
38+
}
39+
40+
let mut xs = vec![1];
41+
xs.push(2);
42+
xs.extend(&[3, 4]);
43+
44+
// do not optimize xs
45+
core::hint::black_box(&mut xs);
46+
47+
assert_eq!(xs.as_slice(), &[1, 2, 3, 4]);
48+
49+
hprintln!("Pass");
50+
51+
// exit QEMU with a success status
52+
debug::exit(debug::EXIT_SUCCESS);
53+
#[allow(clippy::empty_loop)]
54+
loop {}
55+
}

memory.x

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MEMORY
2+
{
3+
/* These values correspond to the LM3S6965, one of the few devices QEMU can emulate */
4+
FLASH : ORIGIN = 0x00000000, LENGTH = 256K
5+
RAM : ORIGIN = 0x20000000, LENGTH = 64K
6+
}

0 commit comments

Comments
 (0)