From e28f3af61b49e88d01e793c13068eaf1c46fd468 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Wed, 27 Oct 2021 12:00:39 +0530 Subject: [PATCH] [i2c] Add a test to check the working of funcs() The funcs() implementation is buggy as it doesn't take "func" by reference and it only defaults to SMBUS and hence the I2C protocol is never chosen as a function. This test fails currently. Suggested-by: Andreea Florescu Signed-off-by: Viresh Kumar --- src/i2c/src/i2c.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/i2c/src/i2c.rs b/src/i2c/src/i2c.rs index b026de6..4b8bb95 100644 --- a/src/i2c/src/i2c.rs +++ b/src/i2c/src/i2c.rs @@ -552,6 +552,23 @@ pub mod tests { } } + #[test] + fn test_funcs() { + let i2c_device = DummyDevice { + funcs_result: I2C_FUNC_SMBUS_ALL as i32, + ..Default::default() + }; + let adapter = I2cAdapter::new(i2c_device).unwrap(); + assert_eq!(adapter.smbus, true); + + let i2c_device = DummyDevice { + funcs_result: I2C_FUNC_I2C as i32, + ..Default::default() + }; + let adapter = I2cAdapter::new(i2c_device).unwrap(); + assert_eq!(adapter.smbus, false); + } + #[test] fn test_i2c_map() { let adapter_config = AdapterConfig::try_from("1:4,2:32:21,5:10:23").unwrap();