diff options
author | Yuval Peress <peress@chromium.org> | 2021-09-17 00:02:34 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-09-17 21:00:15 +0000 |
commit | 78d947267857710daa7338fdcffcddb2f21c6d54 (patch) | |
tree | 1b4d550cfe4c6880fe3b588fff444de7a765fb87 /zephyr/test/drivers/src/lis2dw12.c | |
parent | 256b26922dc7446260a4ec22538fc5574e8503f3 (diff) | |
download | chrome-ec-78d947267857710daa7338fdcffcddb2f21c6d54.tar.gz |
zephyr: test: Add tests for lis2dw12 driver
Add a single test for the lis2dw12 driver that checks the who-am-i
register.
BRANCH=none
BUG=b:200046770
TEST=zmake configure --test zephyr/test/drivers
Signed-off-by: Yuval Peress <peress@chromium.org>
Change-Id: I8dba62f941d74cca025645b81512b4e0c9e04908
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3168035
Tested-by: Yuval Peress <peress@google.com>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Commit-Queue: Yuval Peress <peress@google.com>
Diffstat (limited to 'zephyr/test/drivers/src/lis2dw12.c')
-rw-r--r-- | zephyr/test/drivers/src/lis2dw12.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/zephyr/test/drivers/src/lis2dw12.c b/zephyr/test/drivers/src/lis2dw12.c new file mode 100644 index 0000000000..204c259bdc --- /dev/null +++ b/zephyr/test/drivers/src/lis2dw12.c @@ -0,0 +1,41 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <ztest.h> +#include <drivers/emul.h> +#include "driver/accel_lis2dw12.h" +#include "emul/emul_lis2dw12.h" + +#define LIS2DW12_NODELABEL DT_NODELABEL(ms_lis2dw12_accel) +#define LIS2DW12_SENSOR_ID SENSOR_ID(LIS2DW12_NODELABEL) +#define EMUL_LABEL DT_LABEL(DT_NODELABEL(lis2dw12_emul)) + +#include <stdio.h> +static void lis2dw12_setup(void) +{ + lis2dw12_emul_reset(emul_get_binding(EMUL_LABEL)); +} + +static void test_lis2dw12_init__fail_who_am_i(void) +{ + const struct emul *emul = emul_get_binding(EMUL_LABEL); + struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID]; + int rv; + + lis2dw12_emul_set_who_am_i(emul, ~LIS2DW12_WHO_AM_I); + + rv = ms->drv->init(ms); + zassert_equal(EC_ERROR_ACCESS_DENIED, rv, + "init returned %d but was expecting %d", rv, + EC_ERROR_ACCESS_DENIED); +} + +void test_suite_lis2dw12(void) +{ + ztest_test_suite(lis2dw12, ztest_unit_test_setup_teardown( + test_lis2dw12_init__fail_who_am_i, + lis2dw12_setup, unit_test_noop)); + ztest_run_test_suite(lis2dw12); +} |