diff options
author | Yuval Peress <peress@google.com> | 2022-03-14 16:42:46 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2022-03-18 06:12:34 +0000 |
commit | 119be7cfc5f54052c5903900737632f5d4efa182 (patch) | |
tree | 9c882f4f576711956f34cddc668f15b0349c7180 | |
parent | d6ba5787e7f02e4e9e61a7cf439b8307ba2f9c90 (diff) | |
download | chrome-ec-119be7cfc5f54052c5903900737632f5d4efa182.tar.gz |
zephyr: Add tests for motion_sense.h inline static functions
Get the motion_sense header to 100% coverage by testing a simple copy
function and a clamp function.
BRANCH=none
BUG=b:224614211
TEST=zmake test test-drivers
Signed-off-by: Yuval Peress <peress@google.com>
Change-Id: Ibe254e04ad93f3014d64355fd5a281b1ce98e2c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3530113
Reviewed-by: Aaron Massey <aaronmassey@google.com>
-rw-r--r-- | zephyr/test/drivers/src/motion_sense/motion_sense.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/zephyr/test/drivers/src/motion_sense/motion_sense.c b/zephyr/test/drivers/src/motion_sense/motion_sense.c new file mode 100644 index 0000000000..606440b5c5 --- /dev/null +++ b/zephyr/test/drivers/src/motion_sense/motion_sense.c @@ -0,0 +1,35 @@ +/* Copyright 2022 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 "motion_sense.h" +#include "test_state.h" + +ZTEST_SUITE(motion_sense, drivers_predicate_post_main, NULL, NULL, NULL, NULL); + +ZTEST_USER(motion_sense, ec_motion_sensor_fill_values) +{ + struct ec_response_motion_sensor_data dst = { + .data = { 1, 2, 3 }, + }; + const int32_t v[] = { 4, 5, 6 }; + + ec_motion_sensor_fill_values(&dst, v); + zassert_equal(dst.data[0], v[0], NULL); + zassert_equal(dst.data[1], v[1], NULL); + zassert_equal(dst.data[2], v[2], NULL); +} + +ZTEST_USER(motion_sense, ec_motion_sensor_clamp_i16) +{ + zassert_equal(ec_motion_sensor_clamp_i16(0), 0, NULL); + zassert_equal(ec_motion_sensor_clamp_i16(200), 200, NULL); + zassert_equal(ec_motion_sensor_clamp_i16(-512), -512, NULL); + zassert_equal(ec_motion_sensor_clamp_i16(INT16_MAX + 1), INT16_MAX, + NULL); + zassert_equal(ec_motion_sensor_clamp_i16(INT16_MIN - 1), INT16_MIN, + NULL); +} |