summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Massey <aaronmassey@google.com>2022-10-19 13:38:32 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-20 21:01:38 +0000
commita64566ebbad3160c36b8c991e476e2dd2c4c5917 (patch)
tree6853bdda5ba09cafd8bd87014af0777f7406b0ef
parent97be2786bf6cfed2847d950a9c1d622e6606019b (diff)
downloadchrome-ec-a64566ebbad3160c36b8c991e476e2dd2c4c5917.tar.gz
test: EC_CMD_GET_CMD_VERSIONS
Add tests that validate the following scenarios when invoking the EC_CMD_GET_CMD_VERSIONS host command: Test Scenarios: * v0 of command retrieving versions for v0 | v1 cmd * v1 of command retrieving versions for only v0 * v1 of command retrieving versions for bad cmd BRANCH=none BUG=b:236074903 TEST=twister -i -s zephyr/test/drivers/drivers.host_cmd --coverage' Signed-off-by: Aaron Massey <aaronmassey@google.com> Change-Id: I8d36d32416fbdab61e23a612fb8937d8a3bf299f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3967306 Reviewed-by: Keith Short <keithshort@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--zephyr/test/drivers/host_cmd/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/host_cmd/src/get_cmd_versions.c55
2 files changed, 56 insertions, 0 deletions
diff --git a/zephyr/test/drivers/host_cmd/CMakeLists.txt b/zephyr/test/drivers/host_cmd/CMakeLists.txt
index 191c50d427..3ea78731f7 100644
--- a/zephyr/test/drivers/host_cmd/CMakeLists.txt
+++ b/zephyr/test/drivers/host_cmd/CMakeLists.txt
@@ -6,6 +6,7 @@ target_sources(app PRIVATE
src/adc.c
src/battery_cut_off.c
src/battery_display_soc.c
+ src/get_cmd_versions.c
src/get_panic_info.c
src/get_pd_port_caps.c
src/host_command_test_protocol.c
diff --git a/zephyr/test/drivers/host_cmd/src/get_cmd_versions.c b/zephyr/test/drivers/host_cmd/src/get_cmd_versions.c
new file mode 100644
index 0000000000..b935b69e46
--- /dev/null
+++ b/zephyr/test/drivers/host_cmd/src/get_cmd_versions.c
@@ -0,0 +1,55 @@
+/* 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 "battery.h"
+#include "charge_state.h"
+#include "host_command.h"
+#include "test/drivers/test_state.h"
+
+ZTEST_USER(hc_get_cmd_versions, test_v0__both_versions)
+{
+ struct ec_params_get_cmd_versions params = {
+ .cmd = EC_CMD_GET_CMD_VERSIONS,
+ };
+ struct ec_response_get_cmd_versions response;
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
+ EC_CMD_GET_CMD_VERSIONS, 0, response, params);
+
+ zassert_ok(host_command_process(&args));
+ zassert_equal(args.response_size, sizeof(response));
+ zassert_equal(response.version_mask, EC_VER_MASK(0) | EC_VER_MASK(1));
+}
+
+ZTEST_USER(hc_get_cmd_versions, test_v1__only_v0)
+{
+ struct ec_params_get_cmd_versions_v1 params = {
+ .cmd = EC_CMD_HELLO,
+ };
+ struct ec_response_get_cmd_versions response;
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
+ EC_CMD_GET_CMD_VERSIONS, 1, response, params);
+
+ zassert_ok(host_command_process(&args));
+ zassert_equal(args.response_size, sizeof(response));
+ zassert_equal(response.version_mask, EC_VER_MASK(0));
+}
+
+ZTEST_USER(hc_get_cmd_versions, test_v1__bad_cmd)
+{
+ struct ec_params_get_cmd_versions_v1 params = {
+ /* Non-existent host-command */
+ .cmd = UINT16_MAX,
+ };
+ struct ec_response_get_cmd_versions response;
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
+ EC_CMD_GET_CMD_VERSIONS, 1, response, params);
+
+ zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM);
+}
+
+ZTEST_SUITE(hc_get_cmd_versions, drivers_predicate_post_main, NULL, NULL, NULL,
+ NULL);