diff options
author | Yuval Peress <peress@google.com> | 2021-09-30 11:02:32 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-02 02:27:49 +0000 |
commit | b3c535fcd0c7d0df3c2aa6a1fb827b106534146c (patch) | |
tree | d871cef3820aaa56a9ea20cbb4a4b7adcf3dbd0f | |
parent | 4bcdfecae714b175c1dc65549a33c71d55badb20 (diff) | |
download | chrome-ec-b3c535fcd0c7d0df3c2aa6a1fb827b106534146c.tar.gz |
zephyr: test: verify isl923x manufacturer ID code path
BRANCH=none
BUG=b:201602829
TEST=zmake configure --test zephyr/test/drivers
Signed-off-by: Yuval Peress <peress@google.com>
Change-Id: I2000ea7ea73a311184c5f66c3aa16518261b065d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3198236
Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
Reviewed-by: Aaron Massey <aaronmassey@google.com>
-rw-r--r-- | zephyr/emul/emul_isl923x.c | 18 | ||||
-rw-r--r-- | zephyr/include/emul/emul_isl923x.h | 9 | ||||
-rw-r--r-- | zephyr/test/drivers/src/isl923x.c | 24 |
3 files changed, 50 insertions, 1 deletions
diff --git a/zephyr/emul/emul_isl923x.c b/zephyr/emul/emul_isl923x.c index d841d73aa6..edec034874 100644 --- a/zephyr/emul/emul_isl923x.c +++ b/zephyr/emul/emul_isl923x.c @@ -48,6 +48,8 @@ struct isl923x_emul_data { uint16_t adapter_current_limit2_reg; /** Emulated max voltage register */ uint16_t max_volt_reg; + /** Emulated manufacturer ID register */ + uint16_t manufacturer_id_reg; }; struct isl923x_emul_cfg { @@ -62,6 +64,14 @@ struct i2c_emul *isl923x_emul_get_i2c_emul(const struct emul *emulator) return &(data->common.emul); } +void isl923x_emul_set_manufacturer_id(const struct emul *emulator, + uint16_t manufacturer_id) +{ + struct isl923x_emul_data *data = emulator->data; + + data->manufacturer_id_reg = manufacturer_id; +} + static int isl923x_emul_read_byte(struct i2c_emul *emul, int reg, uint8_t *val, int bytes) { @@ -102,6 +112,14 @@ static int isl923x_emul_read_byte(struct i2c_emul *emul, int reg, uint8_t *val, 8) & 0xff); break; + case ISL923X_REG_MANUFACTURER_ID: + __ASSERT_NO_MSG(bytes == 0 || bytes == 1); + if (bytes == 0) + *val = (uint8_t)(data->manufacturer_id_reg & 0xff); + else + *val = (uint8_t)((data->manufacturer_id_reg >> 8) & + 0xff); + break; default: return -EINVAL; } diff --git a/zephyr/include/emul/emul_isl923x.h b/zephyr/include/emul/emul_isl923x.h index ffd3d52112..c3706be03c 100644 --- a/zephyr/include/emul/emul_isl923x.h +++ b/zephyr/include/emul/emul_isl923x.h @@ -19,4 +19,13 @@ */ struct i2c_emul *isl923x_emul_get_i2c_emul(const struct emul *emulator); +/** + * @brief Set the manufacturer ID + * + * @param emulator The emulator to modify + * @param manufacturer_id The new manufacturer ID + */ +void isl923x_emul_set_manufacturer_id(const struct emul *emulator, + uint16_t manufacturer_id); + #endif /* ZEPHYR_INCLUDE_EMUL_EMUL_ISL923X_H_ */ diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c index 0eb261d837..17c87ea651 100644 --- a/zephyr/test/drivers/src/isl923x.c +++ b/zephyr/test/drivers/src/isl923x.c @@ -158,11 +158,33 @@ void test_isl923x_set_input_current_limit(void) } } +void test_manufacturer_id(void) +{ + const struct emul *isl923x_emul = ISL923X_EMUL; + struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul); + int id; + + isl923x_emul_set_manufacturer_id(isl923x_emul, 0x1234); + zassert_ok(isl923x_drv.manufacturer_id(CHARGER_NUM, &id), NULL); + zassert_equal(0x1234, id, NULL); + + /* Test read error */ + i2c_common_emul_set_read_fail_reg(i2c_emul, + ISL923X_REG_MANUFACTURER_ID); + zassert_equal(EC_ERROR_INVAL, + isl923x_drv.manufacturer_id(CHARGER_NUM, &id), NULL); + + /* Reset fail register */ + i2c_common_emul_set_read_fail_reg(i2c_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); +} + void test_suite_isl923x(void) { ztest_test_suite(isl923x, ztest_unit_test(test_isl923x_set_current), ztest_unit_test(test_isl923x_set_voltage), - ztest_unit_test(test_isl923x_set_input_current_limit)); + ztest_unit_test(test_isl923x_set_input_current_limit), + ztest_unit_test(test_manufacturer_id)); ztest_run_test_suite(isl923x); } |