From 119be7cfc5f54052c5903900737632f5d4efa182 Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Mon, 14 Mar 2022 16:42:46 -0600 Subject: 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 Change-Id: Ibe254e04ad93f3014d64355fd5a281b1ce98e2c7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3530113 Reviewed-by: Aaron Massey --- .../test/drivers/src/motion_sense/motion_sense.c | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 zephyr/test/drivers/src/motion_sense/motion_sense.c 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 + +#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); +} -- cgit v1.2.1