summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Massey <aaronmassey@google.com>2021-10-05 09:39:45 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-11 17:15:13 +0000
commit8944fae220147d0e839310706866c33cd319211c (patch)
tree92d6a7c46919d305cd76cffc95154b9a75c9f7bd
parent3f47176e6ce368747df41afcbd61199c7be8c292 (diff)
downloadchrome-ec-8944fae220147d0e839310706866c33cd319211c.tar.gz
zephyr test: ln9310 emulator exposes i2c_emul struct
In order to test driver failure paths, the ln9310 emulator now exposes its i2c_emul to be manipulated by unit tests. BRANCH=none BUG=b:184856083 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Aaron Massey <aaronmassey@chromium.org> Change-Id: I2fadec0cd8e4c1d897b38f0d0024a49b50cbf5d9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3205932 Commit-Queue: Aaron Massey <aaronmassey@google.com> Tested-by: Aaron Massey <aaronmassey@google.com> Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r--zephyr/emul/emul_ln9310.c8
-rw-r--r--zephyr/include/emul/emul_ln9310.h10
2 files changed, 17 insertions, 1 deletions
diff --git a/zephyr/emul/emul_ln9310.c b/zephyr/emul/emul_ln9310.c
index 7150fda068..fcab1aba34 100644
--- a/zephyr/emul/emul_ln9310.c
+++ b/zephyr/emul/emul_ln9310.c
@@ -87,6 +87,12 @@ struct ln9310_emul_data {
static const struct emul *singleton;
+struct i2c_emul *ln9310_emul_get_i2c_emul(const struct emul *emulator)
+{
+ struct ln9310_emul_data *data = emulator->data;
+
+ return &(data->common.emul);
+}
static void do_ln9310_interrupt(struct ln9310_emul_data *data)
{
@@ -442,7 +448,7 @@ static int ln9310_emul_read_byte(struct i2c_emul *emul, int reg, uint8_t *val,
static int ln9310_emul_access_reg(struct i2c_emul *emul, int reg, int bytes,
bool read)
{
- return 0;
+ return reg;
}
static int emul_ln9310_init(const struct emul *emul,
diff --git a/zephyr/include/emul/emul_ln9310.h b/zephyr/include/emul/emul_ln9310.h
index dfa03eaa28..72debc22d2 100644
--- a/zephyr/include/emul/emul_ln9310.h
+++ b/zephyr/include/emul/emul_ln9310.h
@@ -70,4 +70,14 @@ void ln9310_emul_set_vin_gt_10v(const struct emul *emulator, bool is_gt_10v);
*/
bool ln9310_emul_is_init(const struct emul *emulator);
+/**
+ * @brief Get the I2C emulator struct
+ *
+ * This is generally coupled with calls to i2c_common_emul_* functions.
+ *
+ * @param emulator The emulator to look-up
+ * @return Pointer to the I2C emulator struct
+ */
+struct i2c_emul *ln9310_emul_get_i2c_emul(const struct emul *emulator);
+
#endif /* ZEPHYR_INCLUDE_EMUL_EMUL_LN9310_H_ */