Skip to content

Add on-target tests to CI #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ status = [
"rt-ci-linux (1.59.0)",
"rt-ci-other-os (macOS-latest)",
"rt-ci-other-os (windows-latest)",
"hil-qemu",
"hil-compile-rtt",
"rustfmt",
"clippy",
]
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ jobs:
toolchain: ${{ matrix.rust }}
override: true
- name: Run tests
run: cargo test --all --exclude cortex-m-rt
run: cargo test --all --exclude cortex-m-rt --exclude testsuite

# FIXME: test on macOS and Windows
83 changes: 83 additions & 0 deletions .github/workflows/on-target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
on:
push:
branches: [ staging, trying, master ]
pull_request:
# allows manual triggering
workflow_dispatch:

name: cortex-m on-target tests

jobs:

hil-qemu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: thumbv7m-none-eabi
- name: Build testsuite
env:
RUSTFLAGS: -C link-arg=-Tlink.x -D warnings
run: cargo build -p testsuite --target thumbv7m-none-eabi --features testsuite/semihosting
- name: Install QEMU
run: sudo apt-get update && sudo apt-get install qemu qemu-system-arm
- name: Run testsuite
run: |
qemu-system-arm \
-cpu cortex-m3 \
-machine lm3s6965evb \
-nographic \
-semihosting-config enable=on,target=native \
-kernel target/thumbv7m-none-eabi/debug/testsuite

hil-compile-rtt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: thumbv6m-none-eabi
- name: Modify linkerfile
run: |
sed -i 's/FLASH : ORIGIN = 0x00000000, LENGTH = 256K/FLASH : ORIGIN = 0x8000000, LENGTH = 128K/g' memory.x
sed -i 's/RAM : ORIGIN = 0x20000000, LENGTH = 64K/RAM : ORIGIN = 0x20000000, LENGTH = 16K/g' memory.x
- name: Build testsuite
env:
RUSTFLAGS: -C link-arg=-Tlink.x -D warnings
run: cargo build -p testsuite --target thumbv6m-none-eabi --features testsuite/rtt
- name: Upload testsuite binaries
uses: actions/upload-artifact@v2
with:
name: testsuite-bin
if-no-files-found: error
retention-days: 1
path: target/thumbv6m-none-eabi/debug/testsuite

hil-stm32:
runs-on: self-hosted
needs:
- hil-compile-rtt
steps:
- uses: actions/checkout@v2
- name: Display probe-run version
run: probe-run --version
- name: List probes
run: probe-run --list-probes
- uses: actions/download-artifact@v2
with:
name: testsuite-bin
path: testsuite-bin
- name: Run on-target tests
timeout-minutes: 5
run: |
probe-run \
--chip STM32F070RBTx \
--connect-under-reset \
testsuite-bin/testsuite
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ std = []

[workspace]
members = [
"xtask",
"cortex-m-rt",
"cortex-m-semihosting",
"panic-itm",
"panic-semihosting",
"panic-itm"
"testsuite",
"testsuite/minitest",
"testsuite/minitest/macros",
"xtask",
]

[package.metadata.docs.rs]
Expand Down
12 changes: 12 additions & 0 deletions src/peripheral/dwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ impl DWT {
}
}

/// Disables the cycle counter
#[cfg(not(armv6m))]
#[inline]
pub fn disable_cycle_counter(&mut self) {
unsafe {
self.ctrl.modify(|mut r| {
r.set_cyccntena(false);
r
});
}
}

/// Returns `true` if the cycle counter is enabled
#[cfg(not(armv6m))]
#[inline]
Expand Down
6 changes: 6 additions & 0 deletions testsuite/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
rustflags = ["-C", "link-arg=-Tlink.x"]
runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"

[build]
target = "thumbv7m-none-eabi"
23 changes: 23 additions & 0 deletions testsuite/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
authors = ["The Cortex-M Team <[email protected]>"]
name = "testsuite"
publish = false
edition = "2018"
version = "0.1.0"

[features]
rtt = ["rtt-target", "minitest/rtt"]
semihosting = ["cortex-m-semihosting", "minitest/semihosting"]

[dependencies]
cortex-m-rt.path = "../cortex-m-rt"
cortex-m.path = ".."
minitest.path = "minitest"

[dependencies.rtt-target]
version = "0.3.1"
optional = true

[dependencies.cortex-m-semihosting]
path = "../cortex-m-semihosting"
optional = true
69 changes: 69 additions & 0 deletions testsuite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Testsuite

This workspace contains tests that run on physical and simulated Cortex-M CPUs.

## Building

Exactly one of these features are required:

* `semihosting` Use semihosting for logging, this is used for QEMU.
* `rtt` Use RTT for logging, this is used with physical cortex-m CPUs.

Assuming you are at the root of the repository you can build like this:

```console
$ cd testsuite
$ cargo build --features semihosting
Compiling testsuite v0.1.0 (cortex-m/testsuite)
Finished dev [unoptimized + debuginfo] target(s) in 0.08
```

## Running with QEMU

The runner is already configured for QEMU in `testsuite/.cargo/config.toml`.
Use the `semihosting` feature for logging, QEMU does not have native support for RTT.

For more information on QEMU reference the QEMU section in [The Embedded Rust Book].

```console
$ cd testsuite
$ cargo run --features semihosting
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel /cortex-m/target/thumbv7m-none-eabi/debug/testsuite`
Timer with period zero, disabling
Hello world!
(1/1) running `double_take`...
all tests passed!
```

## Running with Physical Hardware

No implementation-specific features are tested right now; any physical `thumbv7m` target should work.

Tests are executed with [probe-run](https://github.com/knurling-rs/probe-run).

* Update `memory.x` in the root of the repository to match your target memory layout.
* Change the `probe-run` chip argument to match your chip, supported chips can be found with `probe-run --list-chips`
* Change the target to match your CPU

```console
$ sed -i 's/FLASH : ORIGIN = 0x00000000, LENGTH = 256K/FLASH : ORIGIN = 0x8000000, LENGTH = 256K/g' memory.x
$ cd testsuite
$ cargo build --target thumbv7em-none-eabi --features rtt
Compiling minitest v0.1.0 (/cortex-m/testsuite/minitest)
Compiling testsuite v0.1.0 (/cortex-m/testsuite)
Finished dev [unoptimized + debuginfo] target(s) in 0.16s
$ probe-run --chip STM32WLE5JCIx --connect-under-reset ../target/thumbv7em-none-eabi/debug/testsuite
(HOST) INFO flashing program (19 pages / 19.00 KiB)
(HOST) INFO success!
────────────────────────────────────────────────────────────────────────────────
Hello world!
(1/2) running `double_take`...
(2/2) running `cycle_count`...
all tests passed!
────────────────────────────────────────────────────────────────────────────────
(HOST) INFO device halted without error
```

[The Embedded Rust Book]: https://docs.rust-embedded.org/book/start/qemu.html
[probe-run]: https://github.com/knurling-rs/probe-run
18 changes: 18 additions & 0 deletions testsuite/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
fn main() {
let target = std::env::var("TARGET").unwrap();

if target.starts_with("thumbv6m-") {
println!("cargo:rustc-cfg=armv6m");
} else if target.starts_with("thumbv7m-") {
println!("cargo:rustc-cfg=armv7m");
} else if target.starts_with("thumbv7em-") {
println!("cargo:rustc-cfg=armv7m");
println!("cargo:rustc-cfg=armv7em"); // (not currently used)
} else if target.starts_with("thumbv8m.base") {
println!("cargo:rustc-cfg=armv8m");
println!("cargo:rustc-cfg=armv8m_base");
} else if target.starts_with("thumbv8m.main") {
println!("cargo:rustc-cfg=armv8m");
println!("cargo:rustc-cfg=armv8m_main");
}
}
23 changes: 23 additions & 0 deletions testsuite/minitest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
authors = ["The Cortex-M Team <[email protected]>"]
name = "minitest"
publish = false
edition = "2018"
version = "0.1.0"

[features]
semihosting = ["cortex-m-semihosting", "minitest-macros/semihosting"]
rtt = ["rtt-target", "minitest-macros/rtt"]

[dependencies]
cortex-m.path = "../.."
cortex-m-rt.path = "../../cortex-m-rt"
minitest-macros.path = "macros"

[dependencies.rtt-target]
version = "0.3.1"
optional = true

[dependencies.cortex-m-semihosting]
path = "../../cortex-m-semihosting"
optional = true
7 changes: 7 additions & 0 deletions testsuite/minitest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# mini-test

This is an embedded test framework forked from knurling's excellent [`defmt-test`] crate.

This even more minimal than [`defmt-test`] to allow for for testing of this crate without dependency cycles.

[`defmt-test`]: https://crates.io/crates/defmt-test/
18 changes: 18 additions & 0 deletions testsuite/minitest/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
authors = ["The Cortex-M Team <[email protected]>"]
name = "minitest-macros"
publish = false
edition = "2018"
version = "0.1.0"

[lib]
proc-macro = true

[features]
semihosting = []
rtt = []

[dependencies]
proc-macro2 = "1.0.29"
quote = "1.0.10"
syn = { version = "1.0.80", features = ["extra-traits", "full"] }
Loading