summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2022-11-22 12:59:29 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-24 00:16:54 +0000
commit9b5fb3a59f1f062c74846676aa23e8e5ed8bb940 (patch)
treeec7ebcad3055a9feab076b1ace20810a580f4775
parentc137fc572c065f5b484729d95b63c5f88bc2bb83 (diff)
downloadchrome-ec-9b5fb3a59f1f062c74846676aa23e8e5ed8bb940.tar.gz
test: i2c: Verify I2C transfers with PEC rejected
Verify that I2C transfers with PEC (packet error checking) are rejected when CONFIG_PLATFORM_EC_SMBUS_PEC=n. BUG=none BRANCH=none TEST=twister Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I6897ba3f65f28356a91f84bd872fcd013fa7b358 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4048916 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--zephyr/test/drivers/i2c_controller/src/i2c_controller.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/zephyr/test/drivers/i2c_controller/src/i2c_controller.c b/zephyr/test/drivers/i2c_controller/src/i2c_controller.c
index e58aad0903..594c3e6888 100644
--- a/zephyr/test/drivers/i2c_controller/src/i2c_controller.c
+++ b/zephyr/test/drivers/i2c_controller/src/i2c_controller.c
@@ -304,6 +304,48 @@ ZTEST_F(i2c_controller, write_offset16_block)
expected);
}
+ZTEST_F(i2c_controller, pec_disabled)
+{
+ uint16_t addr_flags;
+ uint8_t write_data[] = {
+ 0xAA,
+ 0xBB,
+ 0xCC,
+ 0xDD,
+ };
+ int write_data32 = 0x11223344;
+ uint8_t read_data[4];
+ int actual_read_len;
+ uint16_t reg = 0x01;
+
+ /*
+ * Verify I2C reads and writes through the various APIs fail when
+ * CONFIG_PLATFORM_EC_SMBUS_PEC=n
+ */
+ if (IS_ENABLED(CONFIG_PLATFORM_EC_SMBUS_PEC)) {
+ ztest_test_skip();
+ return;
+ }
+
+ addr_flags = fixture->addr | I2C_FLAG_PEC;
+
+ zassert_equal(i2c_read32(fixture->port, addr_flags, reg,
+ (int *)read_data),
+ EC_ERROR_UNIMPLEMENTED);
+ zassert_equal(i2c_write32(fixture->port, addr_flags, reg, write_data32),
+ EC_ERROR_UNIMPLEMENTED);
+ zassert_equal(i2c_read_sized_block(fixture->port, addr_flags, reg,
+ read_data, sizeof(read_data),
+ &actual_read_len),
+ EC_ERROR_UNIMPLEMENTED);
+ zassert_equal(i2c_read_sized_block(fixture->port, addr_flags, reg,
+ read_data, 0, &actual_read_len),
+ EC_ERROR_INVAL);
+ zassert_equal(i2c_write_block(fixture->port, addr_flags, reg,
+ write_data, sizeof(write_data)),
+ EC_ERROR_UNIMPLEMENTED);
+}
+
ZTEST_F(i2c_controller, i2c_xfer_unlocked__error_paths)
{
uint8_t out_buffer[1];