summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-08-29 23:18:34 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-08-31 19:46:13 +0000
commitc3590674e8b82b71693bb27fac27a4c9837e2a12 (patch)
treefc9f302b90483272d5c59ac4815211d185a8f3f5
parent9887909bf573766504900a04f578e7021004c6a3 (diff)
downloadchrome-ec-c3590674e8b82b71693bb27fac27a4c9837e2a12.tar.gz
test: Add tests for panic info host command
Add tests for the panic info host command including error paths for bad magic number and panic data size 0. BRANCH=none BUG=b:236074360 TEST=twister -s zephyr/test/drivers/drivers.host_cmd Signed-off-by: Yuval Peress <peress@google.com> Change-Id: I9773afab20e3236faa32bd50915e5fb505036cd4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3863929 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Tristan Honscheid <honscheid@google.com>
-rw-r--r--zephyr/test/drivers/host_cmd/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/host_cmd/src/get_panic_info.c98
2 files changed, 99 insertions, 0 deletions
diff --git a/zephyr/test/drivers/host_cmd/CMakeLists.txt b/zephyr/test/drivers/host_cmd/CMakeLists.txt
index d95ce4da2f..cdeb57a279 100644
--- a/zephyr/test/drivers/host_cmd/CMakeLists.txt
+++ b/zephyr/test/drivers/host_cmd/CMakeLists.txt
@@ -4,6 +4,7 @@
target_sources(app PRIVATE
src/battery_cut_off.c
+ src/get_panic_info.c
src/get_pd_port_caps.c
src/host_event_commands.c
src/host_event_commands_deprecated.c
diff --git a/zephyr/test/drivers/host_cmd/src/get_panic_info.c b/zephyr/test/drivers/host_cmd/src/get_panic_info.c
new file mode 100644
index 0000000000..6dc13b463a
--- /dev/null
+++ b/zephyr/test/drivers/host_cmd/src/get_panic_info.c
@@ -0,0 +1,98 @@
+/* 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 "host_command.h"
+#include "panic.h"
+#include "test/drivers/test_state.h"
+
+struct host_cmd_get_panic_info_fixture {
+ struct panic_data saved_pdata;
+};
+
+static void *host_cmd_get_panic_info_setup(void)
+{
+ static struct host_cmd_get_panic_info_fixture fixture = { 0 };
+
+ return &fixture;
+}
+
+static void host_cmd_get_panic_info_before(void *f)
+{
+ struct host_cmd_get_panic_info_fixture *fixture = f;
+ struct panic_data *pdata = get_panic_data_write();
+
+ fixture->saved_pdata = *pdata;
+}
+
+static void host_cmd_get_panic_info_after(void *f)
+{
+ struct host_cmd_get_panic_info_fixture *fixture = f;
+ struct panic_data *pdata = get_panic_data_write();
+
+ *pdata = fixture->saved_pdata;
+}
+
+ZTEST_SUITE(host_cmd_get_panic_info, drivers_predicate_post_main,
+ host_cmd_get_panic_info_setup, host_cmd_get_panic_info_before,
+ host_cmd_get_panic_info_after, NULL);
+
+ZTEST_USER(host_cmd_get_panic_info, test_get_panic_info)
+{
+ struct panic_data *pdata = get_panic_data_write();
+ struct panic_data response = { 0 };
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND_RESPONSE(
+ EC_CMD_GET_PANIC_INFO, UINT8_C(0), response);
+
+ pdata->arch = 0;
+ pdata->struct_version = 1;
+ pdata->flags = 2;
+ pdata->reserved = 3;
+ pdata->struct_size = sizeof(struct panic_data);
+ pdata->magic = PANIC_DATA_MAGIC;
+
+ zassert_ok(host_command_process(&args), NULL);
+ zassert_equal(sizeof(struct panic_data), args.response_size, NULL);
+ zassert_equal(0, response.arch, NULL);
+ zassert_equal(1, response.struct_version, NULL);
+ zassert_equal(2, response.flags, NULL);
+ zassert_equal(3, response.reserved, NULL);
+ zassert_equal(sizeof(struct panic_data), response.struct_size, NULL);
+ zassert_equal(PANIC_DATA_MAGIC, response.magic, NULL);
+ zassert_equal(pdata->flags & PANIC_DATA_FLAG_OLD_HOSTCMD,
+ PANIC_DATA_FLAG_OLD_HOSTCMD, NULL);
+}
+
+ZTEST_USER(host_cmd_get_panic_info, test_get_panic_info_bad_magic)
+{
+ struct panic_data *pdata = get_panic_data_write();
+ struct panic_data expected = { 0 };
+ struct panic_data response = { 0 };
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND_RESPONSE(
+ EC_CMD_GET_PANIC_INFO, UINT8_C(0), response);
+
+ pdata->magic = PANIC_DATA_MAGIC + 1;
+ zassert_ok(host_command_process(&args), NULL);
+ /* Check that nothing was written to response */
+ zassert_mem_equal(&response, &expected, sizeof(struct panic_data),
+ NULL);
+}
+
+ZTEST_USER(host_cmd_get_panic_info, test_get_panic_info_size_is_zero)
+{
+ struct panic_data *pdata = get_panic_data_write();
+ struct panic_data expected = { 0 };
+ struct panic_data response = { 0 };
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND_RESPONSE(
+ EC_CMD_GET_PANIC_INFO, UINT8_C(0), response);
+
+ pdata->magic = PANIC_DATA_MAGIC;
+ pdata->struct_size = 0;
+ zassert_ok(host_command_process(&args), NULL);
+ /* Check that nothing was written to response */
+ zassert_mem_equal(&response, &expected, sizeof(struct panic_data),
+ NULL);
+}