Skip to content

Commit

Permalink
Add testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSprenger committed Sep 30, 2024
1 parent 993fa68 commit 5456d8e
Show file tree
Hide file tree
Showing 17 changed files with 312 additions and 68 deletions.
18 changes: 4 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ version = "0.7.16"
version = "0.5.0"

[workspace.dependencies.messages]
git = "https://github.com/uorocketry/messages"
git = "https://github.com/uorocketry/messages"

[workspace.dependencies.defmt-test]
version = "0.3.2"
19 changes: 17 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ default_to_workspace = false

[tasks.test-host]
dependencies = [
"test-messages",
# "test-messages",
]

# -----------------------
Expand All @@ -19,9 +19,24 @@ dependencies = [

[tasks.test-device]
dependencies = [
"test-temperature-board",
"test-pressure-board",
"test-strain-board",
"test-common-arm",
]

[tasks.test-common-arm]
command = "cargo"
args = ["test", "-p", "common-arm-test", "${@}"]
args = ["test", "-p", "common-arm", "${@}"]

[tasks.test-temperature-board]
command = "cargo"
args = ["test", "-p", "temperature", "${@}"]

[tasks.test-pressure-board]
command = "cargo"
args = ["test", "-p", "pressure", "${@}"]

[tasks.test-strain-board]
command = "cargo"
args = ["test", "-p", "strain", "${@}"]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ uORocketry's rocket instrumentation system.

## Running code
`cargo run --bin {board}`

## Tests
- To run device tests `cargo make test-device`
- - `cargo make test-temperature-board`
- To run host tests `cargo make test-host`
13 changes: 12 additions & 1 deletion boards/pressure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ rtic-sync = { workspace = true }
defmt-rtt = { workspace = true }
panic-probe = { workspace = true }
chrono = { workspace = true }
messages = {workspace = true}
messages = {workspace = true}

[dev-dependencies]
defmt-test = { workspace = true }

[[test]]
name = "sd"
harness = false

[[bin]]
name = "pressure"
harness = false
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
use common_arm::SdManager;
use defmt::info;
use panic_probe as _;
use stm32h7xx_hal::gpio::{Output, PushPull, PA4};
use stm32h7xx_hal::pac;
use stm32h7xx_hal::prelude::*;
use stm32h7xx_hal::gpio::{PA4, Output, PushPull};
use stm32h7xx_hal::spi;
use stm32h7xx_hal::spi;

struct State {
sd_manager: SdManager<
stm32h7xx_hal::spi::Spi<stm32h7xx_hal::pac::SPI1, stm32h7xx_hal::spi::Enabled>,
PA4<Output<PushPull>>,
>,
stm32h7xx_hal::spi::Spi<stm32h7xx_hal::pac::SPI1, stm32h7xx_hal::spi::Enabled>,
PA4<Output<PushPull>>,
>,
}

#[defmt_test::tests]
Expand Down
13 changes: 12 additions & 1 deletion boards/strain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ rtic-sync = { workspace = true }
defmt-rtt = { workspace = true }
panic-probe = { workspace = true }
chrono = { workspace = true }
messages = {workspace = true}
messages = {workspace = true}

[dev-dependencies]
defmt-test = { workspace = true }

[[test]]
name = "sd"
harness = false

[[bin]]
name = "strain"
harness = false
85 changes: 85 additions & 0 deletions boards/strain/tests/sd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#![no_std]
#![no_main]

use common_arm::SdManager;
use defmt::info;
use panic_probe as _;
use stm32h7xx_hal::gpio::{Output, PushPull, PA4};
use stm32h7xx_hal::pac;
use stm32h7xx_hal::prelude::*;
use stm32h7xx_hal::spi;

struct State {
sd_manager: SdManager<
stm32h7xx_hal::spi::Spi<stm32h7xx_hal::pac::SPI1, stm32h7xx_hal::spi::Enabled>,
PA4<Output<PushPull>>,
>,
}

#[defmt_test::tests]
mod tests {
use super::*;

#[init]
fn init() -> State {
let _cp = cortex_m::Peripherals::take().unwrap();
let dp = pac::Peripherals::take().unwrap();

let pwr = dp.PWR.constrain();
let pwrcfg = pwr.freeze();

info!("Power enabled");
// RCC
let mut rcc = dp.RCC.constrain();
let reset = rcc.get_reset_reason();

info!("Reset reason: {:?}", reset);

let ccdr = rcc
.use_hse(48.MHz()) // check the clock hardware
.sys_ck(200.MHz())
.freeze(pwrcfg, &dp.SYSCFG);
info!("RCC configured");

let gpioa = dp.GPIOA.split(ccdr.peripheral.GPIOA);

let spi_sd: stm32h7xx_hal::spi::Spi<
stm32h7xx_hal::stm32::SPI1,
stm32h7xx_hal::spi::Enabled,
u8,
> = dp.SPI1.spi(
(
gpioa.pa5.into_alternate::<5>(),
gpioa.pa6.into_alternate(),
gpioa.pa7.into_alternate(),
),
spi::Config::new(spi::MODE_0),
16.MHz(),
ccdr.peripheral.SPI1,
&ccdr.clocks,
);

let cs_sd = gpioa.pa4.into_push_pull_output();

let sd_manager = SdManager::new(spi_sd, cs_sd);
State { sd_manager }
}

#[test]
fn writing_file(state: &mut State) {
let sd_manager = &mut state.sd_manager;

let mut test_file = sd_manager
.open_file("testing.txt")
.expect("Cannot open file");
sd_manager
.write(&mut test_file, b"Hello this is a test!")
.expect("Could not write file.");
sd_manager
.write_str(&mut test_file, "Testing Strings")
.expect("Could not write string");
sd_manager
.close_file(test_file)
.expect("Could not close file."); // we are done with the file so destroy it
}
}
13 changes: 12 additions & 1 deletion boards/temperature/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ rtic-sync = { workspace = true }
defmt-rtt = { workspace = true }
panic-probe = { workspace = true }
chrono = { workspace = true }
messages = {workspace = true}
messages = {workspace = true}

[dev-dependencies]
defmt-test = { workspace = true }

[[test]]
name = "sd"
harness = false

[[bin]]
name = "temperature"
harness = false
2 changes: 1 addition & 1 deletion boards/temperature/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,4 @@ mod app {
sbg.set_low();
});
}
}
}
85 changes: 85 additions & 0 deletions boards/temperature/tests/sd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#![no_std]
#![no_main]

use common_arm::SdManager;
use defmt::info;
use panic_probe as _;
use stm32h7xx_hal::gpio::{Output, PushPull, PA4};
use stm32h7xx_hal::pac;
use stm32h7xx_hal::prelude::*;
use stm32h7xx_hal::spi;

struct State {
sd_manager: SdManager<
stm32h7xx_hal::spi::Spi<stm32h7xx_hal::pac::SPI1, stm32h7xx_hal::spi::Enabled>,
PA4<Output<PushPull>>,
>,
}

#[defmt_test::tests]
mod tests {
use super::*;

#[init]
fn init() -> State {
let _cp = cortex_m::Peripherals::take().unwrap();
let dp = pac::Peripherals::take().unwrap();

let pwr = dp.PWR.constrain();
let pwrcfg = pwr.freeze();

info!("Power enabled");
// RCC
let mut rcc = dp.RCC.constrain();
let reset = rcc.get_reset_reason();

info!("Reset reason: {:?}", reset);

let ccdr = rcc
.use_hse(48.MHz()) // check the clock hardware
.sys_ck(200.MHz())
.freeze(pwrcfg, &dp.SYSCFG);
info!("RCC configured");

let gpioa = dp.GPIOA.split(ccdr.peripheral.GPIOA);

let spi_sd: stm32h7xx_hal::spi::Spi<
stm32h7xx_hal::stm32::SPI1,
stm32h7xx_hal::spi::Enabled,
u8,
> = dp.SPI1.spi(
(
gpioa.pa5.into_alternate::<5>(),
gpioa.pa6.into_alternate(),
gpioa.pa7.into_alternate(),
),
spi::Config::new(spi::MODE_0),
16.MHz(),
ccdr.peripheral.SPI1,
&ccdr.clocks,
);

let cs_sd = gpioa.pa4.into_push_pull_output();

let sd_manager = SdManager::new(spi_sd, cs_sd);
State { sd_manager }
}

#[test]
fn writing_file(state: &mut State) {
let sd_manager = &mut state.sd_manager;

let mut test_file = sd_manager
.open_file("testing.txt")
.expect("Cannot open file");
sd_manager
.write(&mut test_file, b"Hello this is a test!")
.expect("Could not write file.");
sd_manager
.write_str(&mut test_file, "Testing Strings")
.expect("Could not write string");
sd_manager
.close_file(test_file)
.expect("Could not close file."); // we are done with the file so destroy it
}
}
Loading

0 comments on commit 5456d8e

Please sign in to comment.