Skip to content

Commit ba8945f

Browse files
committed
Add QEMU tests
1 parent 0811180 commit ba8945f

File tree

15 files changed

+697
-3
lines changed

15 files changed

+697
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ jobs:
2929
toolchain: ${{ matrix.rust }}
3030
override: true
3131
- name: Run tests
32-
run: cargo test --all --exclude cortex-m-rt
32+
run: cargo test --all --exclude cortex-m-rt --exclude testsuite
3333

3434
# FIXME: test on macOS and Windows

.github/workflows/qemu.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
on:
2+
push:
3+
branches: [ staging, trying, master ]
4+
pull_request:
5+
6+
name: QEMU
7+
8+
jobs:
9+
qemu:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
submodules: true
15+
- uses: actions-rs/toolchain@v1
16+
with:
17+
profile: minimal
18+
toolchain: stable
19+
override: true
20+
target: thumbv7m-none-eabi
21+
- name: Build testsuite
22+
run: RUSTFLAGS='-C link-arg=-Tlink.x -D warnings' cargo build -p testsuite --target thumbv7m-none-eabi --features testsuite/semihosting
23+
- name: Install QEMU
24+
run: sudo apt-get update && sudo apt-get install qemu qemu-system-arm
25+
- name: Run testsuite
26+
run: |
27+
qemu-system-arm \
28+
-cpu cortex-m3 \
29+
-machine lm3s6965evb \
30+
-nographic \
31+
-semihosting-config enable=on,target=native \
32+
-kernel target/thumbv7m-none-eabi/debug/testsuite

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ std = []
3535

3636
[workspace]
3737
members = [
38-
"xtask",
3938
"cortex-m-rt",
4039
"cortex-m-semihosting",
40+
"panic-itm",
4141
"panic-semihosting",
42-
"panic-itm"
42+
"testsuite",
43+
"testsuite/minitest",
44+
"testsuite/minitest/macros",
45+
"xtask",
4346
]
4447

4548
[package.metadata.docs.rs]

testsuite/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
authors = ["The Cortex-M Team <[email protected]>"]
3+
name = "testsuite"
4+
publish = false
5+
edition = "2018"
6+
version = "0.1.0"
7+
8+
[features]
9+
rtt = ["rtt-target", "minitest/rtt"]
10+
semihosting = ["cortex-m-semihosting", "minitest/semihosting"]
11+
12+
[dependencies]
13+
cortex-m-rt.path = "../cortex-m-rt"
14+
cortex-m.path = ".."
15+
minitest.path = "minitest"
16+
17+
[dependencies.rtt-target]
18+
version = "0.3.1"
19+
optional = true
20+
21+
[dependencies.cortex-m-semihosting]
22+
path = "../cortex-m-semihosting"
23+
optional = true

testsuite/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Testsuite
2+
3+
This workspace contains tests that run on physical and simulated Cortex-M CPUs.
4+
5+
## Building
6+
7+
Exactly one of these features are required:
8+
9+
* `semihosting` Use semihosting for logging, this is used for QEMU.
10+
* `rtt` Use RTT for logging, this is used with physical cortex-m CPUs.
11+
12+
Assuming you are at the root of the repository you can build like this:
13+
14+
```console
15+
$ cargo build -p testsuite --target thumbv6m-none-eabi --features testsuite/rtt
16+
Compiling testsuite v0.1.0 (cortex-m/testsuite)
17+
Finished dev [unoptimized + debuginfo] target(s) in 0.08
18+
```
19+
20+
## Running with QEMU
21+
22+
* Use the `semihosting` feature for logging, QEMU does not have native support for RTT
23+
* Build for the `thumbv7m-none-eabi` target to match the Cortex-M3 lm3s6965evb machine
24+
25+
For more information on QEMU reference the QEMU section in [The Embedded Rust Book].
26+
27+
```console
28+
$ RUSTFLAGS='-C link-arg=-Tlink.x' cargo build -p testsuite --target thumbv7m-none-eabi --features testsuite/semihosting
29+
Compiling testsuite v0.1.0 (cortex-m/testsuite)
30+
Finished dev [unoptimized + debuginfo] target(s) in 0.08
31+
$ qemu-system-arm \
32+
-cpu cortex-m3 \
33+
-machine lm3s6965evb \
34+
-nographic \
35+
-semihosting-config enable=on,target=native \
36+
-kernel target/thumbv7m-none-eabi/debug/testsuite
37+
Timer with period zero, disabling
38+
(1/3) running `assert_true`...
39+
(2/3) running `assert_flag`...
40+
(3/3) running `printing`...
41+
Hello, World!
42+
all tests passed!
43+
```
44+
45+
## Running with Physical Hardware
46+
47+
No implementation-specific features are tested right now; any physical `thumbv6m-none-eabi` target should work.
48+
49+
Tests are executed with [probe-run](https://github.com/knurling-rs/probe-run).
50+
51+
This example is provided for the `STM32F070RBTx`, if using a different target:
52+
53+
* Change the `probe-run` chip argument to match your chip, supported chips can be found with `probe-run --list-chips`
54+
* Modify `stm32-memory.x` to match the memory layout of your target
55+
* Change the build target to match your CPU
56+
57+
```console
58+
$ RUSTFLAGS='-C link-arg=-Tlink.x' cargo build -p testsuite --target thumbv6m-none-eabi --features testsuite/rtt
59+
Compiling testsuite v0.1.0 (cortex-m/testsuite)
60+
Finished dev [unoptimized + debuginfo] target(s) in 0.08
61+
$ probe-run --chip STM32F070RBTx --connect-under-reset target/thumbv6m-none-eabi/debug/testsuite
62+
(HOST) INFO flashing program (14.26 KiB)
63+
(HOST) INFO success!
64+
────────────────────────────────────────────────────────────────────────────────
65+
(1/3) running `assert_true`...
66+
(2/3) running `assert_flag`...
67+
(3/3) running `printing`...
68+
Hello, World!
69+
all tests passed!
70+
────────────────────────────────────────────────────────────────────────────────
71+
stack backtrace:
72+
0: lib::inline::__bkpt
73+
at ./asm/inline.rs:13:5
74+
1: __bkpt
75+
at ./asm/lib.rs:49:17
76+
2: minitest::exit
77+
at testsuite/minitest/src/lib.rs:55:9
78+
3: testsuite::tests::__cortex_m_rt___minitest_entry
79+
at testsuite/src/main.rs:19:1
80+
4: main
81+
at testsuite/src/main.rs:19:1
82+
5: Reset
83+
(HOST) WARN call stack was corrupted; unwinding could not be completed
84+
(HOST) INFO device halted without error
85+
```
86+
87+
[The Embedded Rust Book]: https://docs.rust-embedded.org/book/start/qemu.html
88+
[probe-run]: https://github.com/knurling-rs/probe-run

testsuite/build.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use std::{env, path::PathBuf};
2+
3+
fn main() {
4+
#[cfg(any(
5+
not(any(feature = "semihosting", feature = "rtt")),
6+
all(feature = "semihosting", feature = "rtt")
7+
))]
8+
{
9+
eprintln!("Exactly one of these features must be enabled: rtt, semihosting");
10+
std::process::exit(1);
11+
}
12+
13+
#[allow(unreachable_code)]
14+
{
15+
println!("cargo:rerun-if-changed=qemu-memory.x");
16+
println!("cargo:rerun-if-changed=stm32-memory.x");
17+
18+
let out_dir: PathBuf =
19+
PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR environment variable not set"));
20+
21+
println!("cargo:rustc-link-search={}", out_dir.display());
22+
23+
#[cfg(feature = "semihosting")]
24+
std::fs::copy("qemu-memory.x", out_dir.join("memory.x")).unwrap();
25+
26+
#[cfg(feature = "rtt")]
27+
std::fs::copy("stm32-memory.x", out_dir.join("memory.x")).unwrap();
28+
}
29+
}

testsuite/minitest/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
authors = ["The Cortex-M Team <[email protected]>"]
3+
name = "minitest"
4+
publish = false
5+
edition = "2018"
6+
version = "0.1.0"
7+
8+
[features]
9+
semihosting = ["cortex-m-semihosting", "minitest-macros/semihosting"]
10+
rtt = ["rtt-target", "minitest-macros/rtt"]
11+
12+
[dependencies]
13+
cortex-m.path = "../.."
14+
cortex-m-rt.path = "../../cortex-m-rt"
15+
minitest-macros.path = "macros"
16+
17+
[dependencies.rtt-target]
18+
version = "0.3.1"
19+
optional = true
20+
21+
[dependencies.cortex-m-semihosting]
22+
path = "../../cortex-m-semihosting"
23+
optional = true

testsuite/minitest/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# mini-test
2+
3+
This is an embedded test framework forked from knurling's excellent [`defmt-test`] crate.
4+
5+
This even more minimal than [`defmt-test`] to allow for for testing of this crate without dependency cycles.
6+
7+
[`defmt-test`]: https://crates.io/crates/defmt-test/

testsuite/minitest/macros/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
authors = ["The Cortex-M Team <[email protected]>"]
3+
name = "minitest-macros"
4+
publish = false
5+
edition = "2018"
6+
version = "0.1.0"
7+
8+
[lib]
9+
proc-macro = true
10+
11+
[features]
12+
semihosting = []
13+
rtt = []
14+
15+
[dependencies]
16+
proc-macro2 = "1.0.29"
17+
quote = "1.0.10"
18+
syn = { version = "1.0.80", features = ["extra-traits", "full"] }

0 commit comments

Comments
 (0)