summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2022-09-29 14:50:28 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-05 00:10:59 +0000
commit7e1a5e9c76050cfca0bcf75b81201efe93ecbd36 (patch)
tree3d6ea9894ffe03b8dd5baa1f5e6e84cc8df2386b
parent8d9485e5413fe68690a1e91821dd15ad24d20eb3 (diff)
downloadchrome-ec-7e1a5e9c76050cfca0bcf75b81201efe93ecbd36.tar.gz
zephyr: tests: Test `common/adc.c` host command
Test the host command for querying an ADC channel BRANCH=None BUG=None TEST=./twister Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: Ifd708fc770881c8c16726d969daf364d7eee4a55 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3925109 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Commit-Queue: Aaron Massey <aaronmassey@google.com> Reviewed-by: Aaron Massey <aaronmassey@google.com>
-rw-r--r--zephyr/shim/src/adc.c2
-rw-r--r--zephyr/test/drivers/host_cmd/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/host_cmd/src/adc.c61
3 files changed, 63 insertions, 1 deletions
diff --git a/zephyr/shim/src/adc.c b/zephyr/shim/src/adc.c
index e14ef9f20f..9d5e64376c 100644
--- a/zephyr/shim/src/adc.c
+++ b/zephyr/shim/src/adc.c
@@ -61,7 +61,7 @@ static int init_device_bindings(const struct device *device)
}
SYS_INIT(init_device_bindings, POST_KERNEL, 51);
-int adc_read_channel(enum adc_channel ch)
+test_mockable int adc_read_channel(enum adc_channel ch)
{
int ret = 0, rv;
struct adc_sequence seq = {
diff --git a/zephyr/test/drivers/host_cmd/CMakeLists.txt b/zephyr/test/drivers/host_cmd/CMakeLists.txt
index cde1dbd524..286685089b 100644
--- a/zephyr/test/drivers/host_cmd/CMakeLists.txt
+++ b/zephyr/test/drivers/host_cmd/CMakeLists.txt
@@ -3,6 +3,7 @@
# found in the LICENSE file.
target_sources(app PRIVATE
+ src/adc.c
src/battery_cut_off.c
src/get_panic_info.c
src/get_pd_port_caps.c
diff --git a/zephyr/test/drivers/host_cmd/src/adc.c b/zephyr/test/drivers/host_cmd/src/adc.c
new file mode 100644
index 0000000000..6b2bef1165
--- /dev/null
+++ b/zephyr/test/drivers/host_cmd/src/adc.c
@@ -0,0 +1,61 @@
+/* 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/drivers/emul.h>
+#include <zephyr/fff.h>
+#include <zephyr/ztest.h>
+
+#include "adc.h"
+#include "host_command.h"
+#include "test/drivers/test_state.h"
+#include "test/drivers/utils.h"
+
+FAKE_VALUE_FUNC(int, adc_read_channel, enum adc_channel);
+
+ZTEST(hc_adc, normal_path)
+{
+ struct ec_params_adc_read params = {
+ .adc_channel = ADC_TEMP_SENSOR_CHARGER,
+ };
+ struct ec_response_adc_read response;
+ uint16_t ret;
+
+ adc_read_channel_fake.return_val = 123;
+
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
+ EC_CMD_ADC_READ, UINT8_C(0), response, params);
+
+ ret = host_command_process(&args);
+
+ zassert_ok(ret, "Host command returned %u", ret);
+ zassert_equal(1, adc_read_channel_fake.call_count);
+ zassert_equal(123, response.adc_value);
+}
+
+ZTEST(hc_adc, bad_ch_number)
+{
+ struct ec_params_adc_read params = {
+ .adc_channel = ADC_CH_COUNT + 1, /* Invalid */
+ };
+ struct ec_response_adc_read response;
+ uint16_t ret;
+
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
+ EC_CMD_ADC_READ, UINT8_C(0), response, params);
+
+ ret = host_command_process(&args);
+
+ zassert_equal(EC_RES_INVALID_PARAM, ret, "Host command returned %u",
+ ret);
+}
+
+static void reset(void *data)
+{
+ ARG_UNUSED(data);
+
+ RESET_FAKE(adc_read_channel);
+}
+
+ZTEST_SUITE(hc_adc, drivers_predicate_post_main, NULL, reset, reset, NULL);