summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/default/src/motion_sense/motion_sense.c
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/drivers/default/src/motion_sense/motion_sense.c')
-rw-r--r--zephyr/test/drivers/default/src/motion_sense/motion_sense.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/src/motion_sense/motion_sense.c b/zephyr/test/drivers/default/src/motion_sense/motion_sense.c
new file mode 100644
index 0000000000..d39c3ce335
--- /dev/null
+++ b/zephyr/test/drivers/default/src/motion_sense/motion_sense.c
@@ -0,0 +1,35 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <zephyr/ztest.h>
+
+#include "motion_sense.h"
+#include "test/drivers/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);
+}