Skip to content

Commit

Permalink
tests: disable esp32 hil and fix false passing test
Browse files Browse the repository at this point in the history
  • Loading branch information
lulf committed Jan 19, 2025
1 parent c5c2eab commit e7f5567
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
2 changes: 1 addition & 1 deletion examples/esp32/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Size of L2CAP packets
#[cfg(not(any(feature = "esp32c2", feature = "esp32c6", feature = "esp32h2")))]
pub const L2CAP_MTU: usize = 128;
pub const L2CAP_MTU: usize = 251;
// Some esp chips only accept an MTU >= 255
#[cfg(any(feature = "esp32c2", feature = "esp32c6", feature = "esp32h2"))]
pub const L2CAP_MTU: usize = 255;
34 changes: 23 additions & 11 deletions examples/tests/src/probe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,28 @@ impl<'d> DeviceUnderTest<'d> {
}

pub async fn run(self, firmware: String) -> Result<FirmwareLogs, anyhow::Error> {
let mut flasher = Command::new("probe-rs")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.arg("run")
.arg(&firmware)
.arg("--chip")
.arg(&self.target.config().chip)
.arg("--probe")
.arg(&self.target.config().probe)
.spawn()
.unwrap();
let mut flasher = if self.target.config().chip.starts_with("esp32") {
Command::new("espflash")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.arg("flash")
.arg(&firmware)
.arg("--monitor")
.spawn()
.unwrap()
} else {
Command::new("probe-rs")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.arg("run")
.arg(&firmware)
.arg("--chip")
.arg(&self.target.config().chip)
.arg("--probe")
.arg(&self.target.config().probe)
.spawn()
.unwrap()
};

let stdout = flasher.stdout.take().unwrap();
let stderr = flasher.stderr.take().unwrap();
Expand All @@ -53,6 +64,7 @@ impl<'d> DeviceUnderTest<'d> {
let mut lines: Vec<String> = Vec::new();
select! {
r = flasher.wait() => {
log::warn!("flasher exited unexpectedly: {:?}", r);
for line in lines {
log::warn!("{}", line);
}
Expand Down
24 changes: 15 additions & 9 deletions examples/tests/tests/ble_l2cap_central.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::future::select;
use futures::future::join;
use std::time::Duration;
use tokio::select;
use trouble_example_tests::{serial, TestContext};
Expand All @@ -17,6 +17,7 @@ async fn ble_l2cap_central_nrf52() {
.await;
}

/*
#[tokio::test]
async fn ble_l2cap_central_esp32c3() {
let _ = pretty_env_logger::try_init();
Expand All @@ -29,18 +30,18 @@ async fn ble_l2cap_central_esp32c3() {
))
.await;
}
*/

async fn run_l2cap_central_test(labels: &[(&str, &str)], firmware: &str) {
let ctx = TestContext::new();
let peripheral = ctx.serial_adapters[0].clone();

let dut = ctx.find_dut(labels).unwrap();

// Flash the binary to the target
let token = dut.token();
let token2 = token.clone();

// Spawn a runner for the target
let central = tokio::task::spawn_local(dut.run(firmware.to_string()));
let mut dut = tokio::task::spawn_local(dut.run(firmware.to_string()));

// Run the central in the test using the serial adapter to verify
let peripheral_address: Address = Address::random([0xff, 0x8f, 0x1a, 0x05, 0xe4, 0xff]);
Expand Down Expand Up @@ -107,11 +108,16 @@ async fn run_l2cap_central_test(labels: &[(&str, &str)], firmware: &str) {
}
});

tokio::time::timeout(Duration::from_secs(60), select(central, peripheral))
.await
.map_err(|_| {
match tokio::time::timeout(Duration::from_secs(30), join(&mut dut, peripheral)).await {
Err(_) => {
println!("Test timed out");
token2.cancel();
let _ = tokio::time::timeout(Duration::from_secs(1), dut).await;
assert!(false);
})
.unwrap();
}
Ok((c, p)) => {
p.expect("peripheral failed").unwrap();
c.expect("central failed").unwrap();
}
}
}
26 changes: 15 additions & 11 deletions examples/tests/tests/ble_l2cap_peripheral.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::future::select;
use futures::future::join;
use std::time::Duration;
use tokio::select;
use trouble_example_tests::{serial, TestContext};
Expand All @@ -17,7 +17,7 @@ async fn ble_l2cap_peripheral_nrf52() {
.await;
}

#[tokio::test]
/*#[tokio::test]
async fn ble_l2cap_peripheral_esp32c3() {
let _ = pretty_env_logger::try_init();
let firmware = "bins/esp32/ble_l2cap_peripheral";
Expand All @@ -28,19 +28,18 @@ async fn ble_l2cap_peripheral_esp32c3() {
firmware,
))
.await;
}
}*/

async fn run_l2cap_peripheral_test(labels: &[(&str, &str)], firmware: &str) {
let ctx = TestContext::new();
let central = ctx.serial_adapters[0].clone();

let dut = ctx.find_dut(labels).unwrap();

// Flash the binary to the target
let token = dut.token();
let token2 = token.clone();

// Spawn a runner for the target
let peripheral = tokio::task::spawn_local(dut.run(firmware.to_string()));
let mut dut = tokio::task::spawn_local(dut.run(firmware.to_string()));

// Run the central in the test using the serial adapter to verify
let peripheral_address: Address = Address::random([0xff, 0x8f, 0x1a, 0x05, 0xe4, 0xff]);
Expand Down Expand Up @@ -92,11 +91,16 @@ async fn run_l2cap_peripheral_test(labels: &[(&str, &str)], firmware: &str) {
}
});

tokio::time::timeout(Duration::from_secs(60), select(peripheral, central))
.await
.map_err(|_| {
match tokio::time::timeout(Duration::from_secs(30), join(&mut dut, central)).await {
Err(_) => {
println!("Test timed out");
token2.cancel();
let _ = tokio::time::timeout(Duration::from_secs(1), dut).await;
assert!(false);
})
.unwrap();
}
Ok((p, c)) => {
p.expect("peripheral failed").unwrap();
c.expect("central failed").unwrap();
}
}
}

0 comments on commit e7f5567

Please sign in to comment.