summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2021-10-26 17:05:38 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-02 22:58:30 +0000
commit50fd26402af45541fc7b216b6e7ed29f0547de35 (patch)
treea21ae709deca6958568111dedc33611ca6d1a149
parent4b52aca1fdfca558ffe4934f8f7987cbaa9d8948 (diff)
downloadchrome-ec-50fd26402af45541fc7b216b6e7ed29f0547de35.tar.gz
zephyr: Complete coverage for bmi_config_load() in accelgyro_bmi260.c
Add a few parts to test_bmi_config_load_no_mapped_flash() that complete coverage of bmi_config_load() in accelgyro_bmi260.c Use FFF for init_rom_copy mock BRANCH=None BUG=b:184856157 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: I77975e5fb8d8661867c5274975380b5ee11e840b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3245318 Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r--zephyr/test/drivers/src/bmi260.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/zephyr/test/drivers/src/bmi260.c b/zephyr/test/drivers/src/bmi260.c
index 9c4a4dc507..9c89245e8c 100644
--- a/zephyr/test/drivers/src/bmi260.c
+++ b/zephyr/test/drivers/src/bmi260.c
@@ -2013,9 +2013,13 @@ void test_bmi_config_load_no_mapped_flash(void)
int ret, num_status_reg_reads;
/* Force bmi_config_load() to have to manually copy from memory */
- RESET_FAKE(init_rom_map)
+ RESET_FAKE(init_rom_map);
init_rom_map_fake.return_val = NULL;
+ /* Force init_rom_copy() to succeed */
+ RESET_FAKE(init_rom_copy);
+ init_rom_copy_fake.return_val = 0;
+
/* Set proper chip ID and raise the INIT_OK flag to signal that config
* succeeded.
*/
@@ -2026,6 +2030,7 @@ void test_bmi_config_load_no_mapped_flash(void)
bmi_config_load_no_mapped_flash_mock_read_fn_fake.custom_fake =
bmi_config_load_no_mapped_flash_mock_read_fn_helper;
+ /* Part 1: successful path */
ret = ms_acc->drv->init(ms_acc);
zassert_equal(ret, EC_RES_SUCCESS, "Got %d but expected %d", ret,
@@ -2039,6 +2044,34 @@ void test_bmi_config_load_no_mapped_flash(void)
"Accessed status reg %d times but expected %d.",
num_status_reg_reads, 1);
+ /* Part 2: write to `BMI260_INIT_ADDR_0` fails */
+ i2c_common_emul_set_write_fail_reg(emul, BMI260_INIT_ADDR_0);
+
+ ret = ms_acc->drv->init(ms_acc);
+ zassert_equal(ret, EC_ERROR_INVALID_CONFIG, "Got %d but expected %d",
+ ret, EC_ERROR_INVALID_CONFIG);
+
+ i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG);
+
+ /* Part 3: init_rom_copy() fails w/ a non-zero return code of 255. */
+ init_rom_copy_fake.return_val = 255;
+
+ ret = ms_acc->drv->init(ms_acc);
+ zassert_equal(ret, EC_ERROR_INVALID_CONFIG, "Got %d but expected %d",
+ ret, EC_ERROR_INVALID_CONFIG);
+
+ init_rom_copy_fake.return_val = 0;
+
+ /* Part 4: write to `BMI260_INIT_DATA` fails */
+ i2c_common_emul_set_write_fail_reg(emul, BMI260_INIT_DATA);
+
+ ret = ms_acc->drv->init(ms_acc);
+ zassert_equal(ret, EC_ERROR_INVALID_CONFIG, "Got %d but expected %d",
+ ret, EC_ERROR_INVALID_CONFIG);
+
+ i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG);
+
+ /* Cleanup */
i2c_common_emul_set_read_func(emul, NULL, NULL);
}