summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2021-10-12 10:09:44 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-13 03:44:32 +0000
commitf5f1b176c6104d7b99d4656d19b7a4ad07859a1a (patch)
tree3ff9442334b05047f147524773c0573264fc8e0b
parent955ba0a2850446db4337ac6b3d16f0ceff502ab7 (diff)
downloadchrome-ec-f5f1b176c6104d7b99d4656d19b7a4ad07859a1a.tar.gz
zephyr: cros_cbi: test all code paths
BRANCH=none BUG=b:202789410 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: Ie61e0549f65a27eede00920763cc61207b6046be Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3218254 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--zephyr/test/drivers/overlay.dts19
-rw-r--r--zephyr/test/drivers/src/cros_cbi.c34
-rw-r--r--zephyr/test/drivers/src/main.c2
3 files changed, 55 insertions, 0 deletions
diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts
index 0ab9392773..24e6ca53e3 100644
--- a/zephyr/test/drivers/overlay.dts
+++ b/zephyr/test/drivers/overlay.dts
@@ -113,6 +113,25 @@
};
};
+ cbi-ssfc {
+ compatible = "named-cbi-ssfc";
+ cbi_ssfc_base_sensor: base_sensor {
+ enum-name = "BASE_SENSOR";
+ size = <2>;
+ base_sensor_0: base0 {
+ compatible = "named-cbi-ssfc-value";
+ status = "okay";
+ value = <1>;
+ default;
+ };
+ base_sensor_1: base1 {
+ compatible = "named-cbi-ssfc-value";
+ status = "okay";
+ value = <2>;
+ };
+ };
+ };
+
adc0: adc {
compatible = "zephyr,adc-emul";
nchannels = <4>;
diff --git a/zephyr/test/drivers/src/cros_cbi.c b/zephyr/test/drivers/src/cros_cbi.c
new file mode 100644
index 0000000000..dde215f6a1
--- /dev/null
+++ b/zephyr/test/drivers/src/cros_cbi.c
@@ -0,0 +1,34 @@
+/* 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 <device.h>
+#include <ztest.h>
+
+#include "drivers/cros_cbi.h"
+
+static void test_check_match(void)
+{
+ const struct device *dev = device_get_binding(CROS_CBI_LABEL);
+ int value;
+
+ zassert_not_null(dev, NULL);
+
+ value = cros_cbi_ssfc_check_match(
+ dev, CBI_SSFC_VALUE_ID(DT_NODELABEL(base_sensor_0)));
+ zassert_true(value, "Expected cbi ssfc to match base_sensor_0");
+
+ value = cros_cbi_ssfc_check_match(
+ dev, CBI_SSFC_VALUE_ID(DT_NODELABEL(base_sensor_1)));
+ zassert_false(value, "Expected cbi ssfc not to match base_sensor_1");
+
+ value = cros_cbi_ssfc_check_match(dev, CBI_SSFC_VALUE_COUNT);
+ zassert_false(value, "Expected cbi ssfc to fail on invalid enum");
+}
+
+void test_suite_cros_cbi(void)
+{
+ ztest_test_suite(cros_cbi, ztest_unit_test(test_check_match));
+ ztest_run_test_suite(cros_cbi);
+}
diff --git a/zephyr/test/drivers/src/main.c b/zephyr/test/drivers/src/main.c
index 979dffea0a..2762ac7726 100644
--- a/zephyr/test/drivers/src/main.c
+++ b/zephyr/test/drivers/src/main.c
@@ -26,6 +26,7 @@ extern void test_suite_stm_mems_common(void);
extern void test_suite_isl923x(void);
extern void test_suite_usb_mux(void);
extern void test_suite_ppc_syv682c(void);
+extern void test_suite_cros_cbi(void);
void test_main(void)
{
@@ -53,4 +54,5 @@ void test_main(void)
test_suite_isl923x();
test_suite_usb_mux();
test_suite_ppc_syv682c();
+ test_suite_cros_cbi();
}