Skip to content

Commit

Permalink
Add PicoW test suite (#53)
Browse files Browse the repository at this point in the history
* cold start tests are now generic

* setting register tests now generic

* updated CI to use Linux Tests

* fixed markdown lint issue

* refactored into test crate

* updated CI and tests documentation

* restructured tests and now use common folder. Paths work and can call tests from the top folder

* added breaking changes. Cant seem to get the i2c shared bus to work investigating changing traits

* reverted change

* fixed bus mutex example

* fixed readme links

* added first stab at esp test harness

* Attempting to pass i2c

* rearranging dependencies

* cargo test runs but cant link rust-lld

* Start from scratch

* removed old workspace

* test framework works using
cargo test inside the esp32c3 tests folder

* removed unecessary log feature

* removed extra dependancies

* doc changes

* added first esp32 i2c test

* removed unused aliases

* restructured tests to make reusable tests

* Seperated workspaces as the MCU environemnts might have different lock files

* removed them from library workspace

* removed unecessary noise

* Updated docs

* updated examples

* cold_start_tests confirmed working

* added setting_register_tests

* added CI updated tests

* Fixed broken links

* updated lint checks for new tests directory

* moved esp32c3 example

* fixed workflows

* fixed rust analyser

* Fixed Links

* addressing clippy warning

* Updated docs

* added probe-rs to pipeline

* [MegaLinter] Apply linters automatic fixes (#49)

* fixing install

* Added missing dependencies

* removing bininstall

* debugging

* adding probe-rs

* Added back in tests

* [MegaLinter] Apply linters automatic fixes (#50)

* fixed apt in workflow
and changed imports back to original

* fixed mut and imports

* fixed public

* added probe specifics

* added probe reset

* updating probe-rs install

* fixing cmd

* cahnging runner to use debian instead of ubuntu

* swapping to bookworm

* tagging bookworm docker version

* tagged version

* added missing installs

* Splitting tests up

* adding missing source

* correcting order

* disabled faulty test

* fixed comment string

* removed duplicated project

* added config variable

* fixed double quoting

* formatting

* Attempt at adding rp pico

* cant seem to clear up i2c generics

* added working rp pico example!!

* tested and runs

* updated workflow

* update cargo dependencies

* added missing toolchain

* added short readme

* updating structure and readme docs

* Added docs updates

* clippy issues and adding it to the CI

* fixing names

* Fixed names

* investigate this

* getting rid of probe resets

* updated broken link

* fixed rust analyser issue

* minor tidying

* further tidy up

* removed todos

* fixed docs

* add space

* spelling fix

* added H

* removing import

* Bug Fix for naming

* reducing boiler plate

* fixing clippy issue

* reduced boiler plate

* adding target for clippy

* making clippy happy

* fixed clippy warning

* agreed removed :)

* fixed extra #

* removed unecessary comments
  • Loading branch information
ScottGibb authored Jan 13, 2025
1 parent 45342f2 commit c3b67ba
Show file tree
Hide file tree
Showing 23 changed files with 544 additions and 82 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/continuous_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ jobs:
source "$HOME"/.cargo/env
cargo build -p utils --features=rpi
# Due to issues around installing windows driver in CI, we are not compiling the FTDI examples on Windows
FTDI_Examples:
name: FTDI Examples
# Due to issues around installing windows driver in CI, we are not compiling the FT232 examples on Windows
FT232_Examples:
name: FT232 Examples
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -82,19 +82,19 @@ jobs:
if: runner.os == 'MacOS'
run: |
brew install libftdi
- name: Building FTDI Example 1
- name: Building FT232 Example 1
run: |
echo "Building Example 1"
cargo build --example example_1_basic_readings --features=std
- name: Building FTDI Example 2
- name: Building FT232 Example 2
run: |
echo "Building Example 2"
cargo build --example example_2_interrupts --features=std
- name: Building FTDI Example 3
- name: Building FT232 Example 3
run: |
echo "Building Example 3"
cargo build --example example_3_angle_calculations --features=std
- name: Building FTDI Example 4
- name: Building FT232 Example 4
run: |
echo "Building Example 4"
cargo build --example example_4_i2c_settings --features=std
Expand Down
27 changes: 22 additions & 5 deletions .github/workflows/continuous_integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
- main
workflow_call:

env:
ESP32C3_UUID: 303a:1001:A0:76:4E:17:0B:90

jobs:
Linux_Tests:
name: Linux Tests
Expand All @@ -25,7 +22,7 @@ jobs:
echo "Running FT232H Tests"
source "$HOME"/.cargo/env
cd tests
cargo test --test linux --features=std -- --test-threads=1 # Run Linux Tests using FTD232
cargo test --test linux --features=std -- --test-threads=1 # Run Linux Tests using FT232H
Raspberry_Pi_Tests:
name: Raspberry Pi Tests
Expand Down Expand Up @@ -62,5 +59,25 @@ jobs:
echo "Running ESP32C3 Tests"
source "$HOME"/.cargo/env
cd tests/esp32c3
probe-rs reset --probe="$ESP32C3_UUID"
cargo test # Probe UUID defined in .cargo/config.toml
PiPico_Tests:
name: RP2040W Pico Tests
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust and probe-rs
run: |
apt-get install --yes clang curl git libudev-dev libssl-dev pkg-config python3-pip
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/probe-rs/probe-rs/releases/latest/download/probe-rs-tools-installer.sh | sh
source "$HOME"/.cargo/env
rustup toolchain install nightly --component rust-src
rustup target add thumbv6m-none-eabi
- name: RP2040W Pi Pico Tests
run: |
echo "Running RP2040W Pi Pico Tests"
source "$HOME"/.cargo/env
cd tests/pipico
cargo test # Probe UUID defined in .cargo/config.toml
7 changes: 7 additions & 0 deletions .github/workflows/mega-linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ jobs:
run: cargo fmt --manifest-path examples/esp32c3/Cargo.toml -- --check
- name: Rustfmt check on esp32 tests
run: cargo fmt --manifest-path tests/esp32c3/Cargo.toml -- --check
- name: Rustfmt check on pipico tests
run: cargo fmt --manifest-path tests/pipico/Cargo.toml -- --check

cargo_clippy:
name: Cargo Clippy
Expand All @@ -188,3 +190,8 @@ jobs:
run: |
cd tests/esp32c3/
cargo clippy -- -D warnings
- name: Clippy on Pi Pico Tests
run: |
rustup target add thumbv6m-none-eabi
cd tests/pipico
cargo clippy -- -D warnings
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Compiled files
/target/
utils/target/
target

# Dependency directories
Cargo.lock
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"rust-analyzer.linkedProjects": [
"utils/Cargo.toml",
"examples/esp32c3/Cargo.toml",
"tests/esp32c3/Cargo.toml"
"tests/esp32c3/Cargo.toml",
"tests/pipico/Cargo.toml"
],
"[rust]": {
"editor.formatOnSave": true
Expand Down
216 changes: 180 additions & 36 deletions docs/ci pipeline diagram.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/esp32c3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "esp32-c3-example"
name = "esp32c3-example"
version = "0.1.0"
authors = [
"Scott Gibb <[email protected]",
Expand All @@ -23,7 +23,7 @@ esp-println = { version = "0.12.0", features = ["esp32c3", "log"] }
log = { version = "0.4.21" }

[[bin]]
name = "esp32-c3-example"
name = "esp32c3-example"
path = "src/main.rs"
test = false
doctest = false
Expand Down
2 changes: 1 addition & 1 deletion tests-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"

[dependencies]
tmag5273 = { path = "../" }
embedded-hal-bus = { version = "0.2.0" }
embedded-hal-bus = { version = "0.2.0"}
embedded-hal = { version = "1.0.0" }
arbitrary-int = "1.2.7"
3 changes: 1 addition & 2 deletions tests-common/src/generic_cold_start_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! This test suite is for the SparkFun breakout board for the TMAG5273 sensor on Mac OS.
//! It tests from a cold boot in which the configuration registers should be at their defaults
use core::assert_eq;
use registers::*;
use tmag5273::*;
use types::*;
Expand All @@ -22,7 +21,7 @@ where
{
let mut mag_sensor = TMag5273::new(i2c, SENSOR_PART).unwrap();
let device_id = mag_sensor.get_device_id().expect("Failed to get device id");
assert_eq!(device_id, DeviceId::TMAG5273X1); // Ensure DeviceId derives PartialEq
assert_eq!(device_id, DeviceId::TMAG5273X1);
}

pub fn generic_test_manufacturer_id<I2C>(i2c: I2C)
Expand Down
1 change: 0 additions & 1 deletion tests-common/src/generic_setting_registers_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use core::assert_eq;
use core::cell::RefCell;
use embedded_hal_bus::i2c::RefCellDevice;
use registers::*;
Expand Down
15 changes: 12 additions & 3 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@ interacting with the hardware. As such we must run our tests with one thread:

```bash
cargo test -- --test-threads=1 # Run all tests (Will need to be on a Pi with MCUs and others plugged in)
cargo test --test linux --features=std -- --test-threads=1 # Run Linux Tests using FTD232
cargo test --test linux --features=rpi -- --test-threads=1 #Run Linux Tests using Raspberry Pi I2C
cargo test --test linux --features=std -- --test-threads=1 # Run Linux Tests using FT232H
cargo test --test linux --features=rpi -- --test-threads=1 # Run Linux Tests using Raspberry Pi I2C
```

### ESP32C3 Tests

Since we are using an MCU target we require a seperate cargo workspace in order to set up the embedded test suite. More on this can be found in the following [README](./esp32c3/README.md). To run the tests on the ESP32C3 use the following code snippet:
Since we are using an MCU target we require a separate cargo workspace in order to set up the embedded test suite. More on this can be found in the following [README](./esp32c3/README.md). To run the tests on the ESP32C3 use the following code snippet:

```bash
cd tests/esp32c3
cargo test # Will run all tests one after the other
```

### Pi Pico

The same setup as the ESP32C3 is also applied to the Pi Pico. More information on this can be found in the following [README](./pipico/README.md) You can run the tests using the [Pico Probe](https://thepihut.com/products/raspberry-pi-debug-probe) like so:

```bash
cd tests/pipico
cargo test # Will run all tests one after the other
```

## Test Environments

Currently we support testing on the following environments:
Expand Down
3 changes: 2 additions & 1 deletion tests/esp32c3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dependencies]

# # dependencies for defmt
# Dependencies for defmt
defmt = { version = "0.3.8"}
defmt-rtt = { version = "0.4.1"}

Expand All @@ -25,6 +25,7 @@ tmag5273 = { path = "../../" }
[dev-dependencies]
embedded-test = { version = "0.5.0", features =["defmt"] }
tests-common = { path = "../../tests-common" }

# Test Files
[[test]]
name = "cold_start_tests"
Expand Down
1 change: 0 additions & 1 deletion tests/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use tests_common as common;

#[cfg(test)]
pub mod linux {
// Reference the correct path to the test files
pub mod cold_start_tests;
pub mod setting_registers_tests;
}
22 changes: 11 additions & 11 deletions tests/linux/cold_start_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,65 @@ use utils::setup_i2c;
#[test]
pub fn test_device_id() {
let i2c = setup_i2c().unwrap();
generic_test_device_id(i2c); // Pass the i2c variable to the inner test function
generic_test_device_id(i2c);
}

#[test]
fn test_manufacturer_id() {
let i2c = setup_i2c().unwrap();
generic_test_manufacturer_id(i2c); // Pass the i2c variable to the inner test function
generic_test_manufacturer_id(i2c);
}

#[test]
fn test_registers() {
let i2c = setup_i2c().unwrap();
generic_test_registers(i2c); // Pass the i2c variable to the inner test function
generic_test_registers(i2c);
}

#[test]
fn test_default_i2c_address() {
let i2c = setup_i2c().unwrap();
generic_test_default_i2c_address(i2c); // Pass the i2c variable to the inner test function
generic_test_default_i2c_address(i2c);
}

#[test]
fn test_get_magnitude_first_boot() {
let i2c = setup_i2c().unwrap();
generic_test_get_magnitude_first_boot(i2c); // Pass the i2c variable to the inner test function
generic_test_get_magnitude_first_boot(i2c);
}

#[test]
fn test_get_xyz_thresholds_first_boot() {
let i2c = setup_i2c().unwrap();
generic_test_get_xyz_thresholds_first_boot(i2c); // Pass the i2c variable to the inner test function
generic_test_get_xyz_thresholds_first_boot(i2c);
}

#[test]
fn test_magnetic_gain() {
let i2c = setup_i2c().unwrap();
generic_test_magnetic_gain(i2c); // Pass the i2c variable to the inner test function
generic_test_magnetic_gain(i2c);
}

#[test]
fn test_magnetic_offset_invalid_at_boot() {
let i2c = setup_i2c().unwrap();
generic_test_magnetic_offset_invalid_at_boot(i2c); // Pass the i2c variable to the inner test function
generic_test_magnetic_offset_invalid_at_boot(i2c);
}

#[test]
fn test_temperature_invalid_at_boot() {
let i2c = setup_i2c().unwrap();
generic_test_temperature_invalid_at_boot(i2c); // Pass the i2c variable to the inner test function
generic_test_temperature_invalid_at_boot(i2c);
}

#[test]
fn test_get_data_methods() {
let i2c = setup_i2c().unwrap();
generic_test_get_data_methods(i2c); // Pass the i2c variable to the inner test function
generic_test_get_data_methods(i2c);
}

#[test]
fn test_get_angle() {
let i2c = setup_i2c().unwrap();
generic_test_get_angle(i2c); // Pass the i2c variable to the inner test function
generic_test_get_angle(i2c);
}
18 changes: 9 additions & 9 deletions tests/linux/setting_registers_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,53 @@ pub fn test_i2c_setup_success() {
#[test]
fn test_is_connected() {
let i2c = setup_i2c().unwrap();
generic_test_is_connected(i2c); // Pass the i2c variable to the inner test function
generic_test_is_connected(i2c);
}

#[test]
fn test_create_tmag5273() {
let i2c = setup_i2c().unwrap();
generic_test_create_tmag5273(i2c); // Pass the i2c variable to the inner test function
generic_test_create_tmag5273(i2c);
}

#[test]
fn test_set_reset_device_config_1_register() {
let i2c = setup_i2c().unwrap();
generic_test_set_reset_device_config_1_register(i2c); // Pass the i2c variable to the inner test function
generic_test_set_reset_device_config_1_register(i2c);
}

#[test]
fn test_set_reset_device_config_2_register() {
let i2c = setup_i2c().unwrap();
generic_test_reset_device_config_2_register(i2c); // Pass the i2c variable to the inner test function
generic_test_reset_device_config_2_register(i2c);
}

#[test]
fn test_set_reset_i2c_address_register() {
let i2c = setup_i2c().unwrap();
generic_test_set_reset_i2c_address_register(i2c); // Pass the i2c variable to the inner test function
generic_test_set_reset_i2c_address_register(i2c);
}

#[test]
fn test_set_reset_int_config_1_register() {
let i2c = setup_i2c().unwrap();
generic_test_set_reset_int_config_1_register(i2c); // Pass the i2c variable to the inner test function
generic_test_set_reset_int_config_1_register(i2c);
}

#[test]
fn test_set_reset_sensor_config_1_register() {
let i2c = setup_i2c().unwrap();
generic_test_set_reset_sensor_config_1_register(i2c); // Pass the i2c variable to the inner test function
generic_test_set_reset_sensor_config_1_register(i2c);
}

#[test]
fn test_set_reset_sensor_config_2_register() {
let i2c = setup_i2c().unwrap();
generic_test_set_reset_sensor_config_2_register(i2c); // Pass the i2c variable to the inner test function
generic_test_set_reset_sensor_config_2_register(i2c);
}

#[test]
fn test_set_reset_t_config_register() {
let i2c = setup_i2c().unwrap();
generic_test_set_reset_t_config_register(i2c); // Pass the i2c variable to the inner test function
generic_test_set_reset_t_config_register(i2c);
}
Loading

0 comments on commit c3b67ba

Please sign in to comment.