diff options
author | Tristan Honscheid <honscheid@google.com> | 2021-10-25 16:18:31 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-11-02 22:58:26 +0000 |
commit | 4b52aca1fdfca558ffe4934f8f7987cbaa9d8948 (patch) | |
tree | 47020c7041ed88f7ad67405771d0b92904ab59b8 | |
parent | 82be0a6d7c78ef3ea10cb5f9269fc337f9fc3409 (diff) | |
download | chrome-ec-4b52aca1fdfca558ffe4934f8f7987cbaa9d8948.tar.gz |
zephyr: Test unsupported chip in `bmi_config_load()`
Test what occurs when we try to configure a chip that is
turned off in Kconfig (BMI220). This test assumes that
CONFIG_ACCELGYRO_BMI220 is NOT define
BRANCH=None
BUG=b:184856157
TEST=zmake configure --test zephyr/test/drivers
Signed-off-by: Tristan Honscheid <honscheid@google.com>
Change-Id: I4c2e821788b22d3b7142f915e610793b72cfe0ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3242209
Reviewed-by: Wai-Hong Tam <waihong@google.com>
-rw-r--r-- | zephyr/test/drivers/src/bmi260.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/zephyr/test/drivers/src/bmi260.c b/zephyr/test/drivers/src/bmi260.c index 38e090785b..9c4a4dc507 100644 --- a/zephyr/test/drivers/src/bmi260.c +++ b/zephyr/test/drivers/src/bmi260.c @@ -2042,6 +2042,35 @@ void test_bmi_config_load_no_mapped_flash(void) i2c_common_emul_set_read_func(emul, NULL, NULL); } +void test_bmi_config_unsupported_chip(void) +{ + /* Test what occurs when we try to configure a chip that is + * turned off in Kconfig (BMI220). This test assumes that + * CONFIG_ACCELGYRO_BMI220 is NOT defined. + */ + +#if defined(CONFIG_ACCELGYRO_BMI220) +#error "Test test_bmi_config_unsupported_chip will not work properly with " \ + "CONFIG_ACCELGYRO_BMI220 defined." +#endif + + struct i2c_emul *emul = bmi_emul_get(BMI_ORD); + struct motion_sensor_t ms_fake; + + /* Set up struct and emaulator to be a BMI220 chip, which + * `bmi_config_load()` does not support in the current configuration + */ + + memcpy(&ms_fake, &motion_sensors[BMI_ACC_SENSOR_ID], sizeof(ms_fake)); + ms_fake.chip = MOTIONSENSE_CHIP_BMI220; + bmi_emul_set_reg(emul, BMI260_CHIP_ID, BMI220_CHIP_ID_MAJOR); + + int ret = ms_fake.drv->init(&ms_fake); + + zassert_equal(ret, EC_ERROR_INVALID_CONFIG, "Expected %d but got %d", + EC_ERROR_INVALID_CONFIG, ret); +} + void test_suite_bmi260(void) { ztest_test_suite(bmi260, @@ -2067,6 +2096,8 @@ void test_suite_bmi260(void) ztest_user_unit_test(test_interrupt_handler), ztest_user_unit_test(test_bmi_init_chip_id), ztest_user_unit_test( - test_bmi_config_load_no_mapped_flash)); + test_bmi_config_load_no_mapped_flash), + ztest_user_unit_test( + test_bmi_config_unsupported_chip)); ztest_run_test_suite(bmi260); } |