Add i2c blocking timeout test, unwrap results (#3567)

* Add blocking timeout test

* Don't ignore return values
This commit is contained in:
Dániel Buga 2025-05-29 12:51:49 +02:00 committed by GitHub
parent 13b46968f3
commit f5305a6686
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -112,12 +112,12 @@ mod tests {
// state
ctx.i2c
.write_read(NON_EXISTENT_ADDRESS, &[0xaa], &mut read_data)
.ok();
.expect_err("Expected error for non-existent address");
// do the real read which should succeed
ctx.i2c
.write_read(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
.ok();
.unwrap();
assert_ne!(read_data, [0u8; 22])
}
@ -135,7 +135,7 @@ mod tests {
Operation::Read(&mut read_data),
],
)
.ok();
.unwrap();
assert_ne!(read_data, [0u8; 22])
}
@ -167,12 +167,12 @@ mod tests {
// state
i2c.write_read_async(NON_EXISTENT_ADDRESS, &[0xaa], &mut read_data)
.await
.ok();
.expect_err("Expected error for non-existent address");
// do the real read which should succeed
i2c.write_read_async(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
.await
.ok();
.unwrap();
assert_ne!(read_data, [0u8; 22])
}
@ -191,11 +191,25 @@ mod tests {
],
)
.await
.ok();
.unwrap();
assert_ne!(read_data, [0u8; 22])
}
// This is still an issue on ESP32-S2
#[cfg(not(esp32s2))]
#[test]
async fn test_timeout_when_scl_kept_low(ctx: Context) {
let mut i2c = ctx.i2c.into_async();
esp_hal::gpio::InputSignal::I2CEXT0_SCL.connect_to(&esp_hal::gpio::Level::Low);
let mut read_data = [0u8; 22];
// will run into an error but it should return at least
i2c.write_read(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
.expect_err("Expected timeout error");
}
// This is still an issue on ESP32-S2
#[cfg(not(esp32s2))]
#[test]
@ -208,7 +222,7 @@ mod tests {
// will run into an error but it should return at least
i2c.write_read_async(DUT_ADDRESS, READ_DATA_COMMAND, &mut read_data)
.await
.ok();
.expect_err("Expected timeout error");
}
#[test]