summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/default/src/cros_cbi.c
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/drivers/default/src/cros_cbi.c')
-rw-r--r--zephyr/test/drivers/default/src/cros_cbi.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/src/cros_cbi.c b/zephyr/test/drivers/default/src/cros_cbi.c
new file mode 100644
index 0000000000..e92765cb52
--- /dev/null
+++ b/zephyr/test/drivers/default/src/cros_cbi.c
@@ -0,0 +1,55 @@
+/* Copyright 2021 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/device.h>
+#include <zephyr/ztest.h>
+
+#include "cros_cbi.h"
+#include "test/drivers/test_state.h"
+
+ZTEST(cros_cbi, test_check_match)
+{
+ int value;
+
+ value = cros_cbi_ssfc_check_match(
+ 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(
+ 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(CBI_SSFC_VALUE_COUNT);
+ zassert_false(value, "Expected cbi ssfc to fail on invalid enum");
+}
+
+ZTEST(cros_cbi, test_fail_check_match)
+{
+ int value;
+
+ value = cros_cbi_ssfc_check_match(CBI_SSFC_VALUE_COUNT);
+ zassert_false(value,
+ "Expected cbi ssfc to never match CBI_SSFC_VALUE_COUNT");
+}
+
+ZTEST(cros_cbi, test_fw_config)
+{
+ uint32_t value;
+ int ret;
+
+ ret = cros_cbi_get_fw_config(FW_CONFIG_FIELD_1, &value);
+ zassert_true(ret == 0,
+ "Expected no error return from cros_cbi_get_fw_config");
+ zassert_true(value == FW_FIELD_1_B,
+ "Expected field value to match FW_FIELD_1_B as default");
+
+ ret = cros_cbi_get_fw_config(FW_CONFIG_FIELD_2, &value);
+ zassert_true(ret == 0,
+ "Expected no error return from cros_cbi_get_fw_config");
+ zassert_false(value == FW_FIELD_2_X,
+ "Expected field value to not match FW_FIELD_2_X");
+}
+
+ZTEST_SUITE(cros_cbi, drivers_predicate_post_main, NULL, NULL, NULL, NULL);