summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew McRae <amcrae@google.com>2022-08-24 15:51:28 +1000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-08-25 00:06:00 +0000
commit832c26b2eeb07700b754d28d9c567e18e34fc57d (patch)
tree65207e3285e99ed74533a2c5c34dacd7df828667
parent01e90e3e76e5d11e214be6d2e4da11defc450638 (diff)
downloadchrome-ec-832c26b2eeb07700b754d28d9c567e18e34fc57d.tar.gz
port80: Add port 80 unit tests
Add port 80 writes Zephyr unit tests. BUG=b:243613249 TEST=./twister -T zephyr/test/drivers BRANCH=none Signed-off-by: Andrew McRae <amcrae@google.com> Change-Id: I1a532f825454a8156b4aff7ac81913a93c0ba66d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3853772 Reviewed-by: Aaron Massey <aaronmassey@google.com> Commit-Queue: Aaron Massey <aaronmassey@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--zephyr/test/drivers/default/CMakeLists.txt2
-rw-r--r--zephyr/test/drivers/default/src/console_cmd/port80.c46
-rw-r--r--zephyr/test/drivers/default/src/port80.c111
-rw-r--r--zephyr/test/drivers/prj.conf1
4 files changed, 160 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/CMakeLists.txt b/zephyr/test/drivers/default/CMakeLists.txt
index 3f55e20275..5ba4f95a7d 100644
--- a/zephyr/test/drivers/default/CMakeLists.txt
+++ b/zephyr/test/drivers/default/CMakeLists.txt
@@ -23,6 +23,7 @@ target_sources(app PRIVATE
src/console_cmd/gpio.c
src/console_cmd/md.c
src/console_cmd/panic_output.c
+ src/console_cmd/port80.c
src/console_cmd/rw.c
src/console_cmd/tcpci_dump.c
src/console_cmd/usb_pd_console.c
@@ -54,6 +55,7 @@ target_sources(app PRIVATE
src/ln9310.c
src/motion_sense/motion_sense.c
src/panic.c
+ src/port80.c
src/power_common.c
src/ppc_sn5s330.c
src/ppc_syv682x.c
diff --git a/zephyr/test/drivers/default/src/console_cmd/port80.c b/zephyr/test/drivers/default/src/console_cmd/port80.c
new file mode 100644
index 0000000000..4f1a7ac195
--- /dev/null
+++ b/zephyr/test/drivers/default/src/console_cmd/port80.c
@@ -0,0 +1,46 @@
+/* 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.
+ */
+
+/**
+ * @file
+ * @brief Unit Tests for ESPI port 80 console command
+ */
+
+#include <zephyr/logging/log.h>
+#include <zephyr/shell/shell.h>
+#include <zephyr/zephyr.h>
+#include <zephyr/ztest.h>
+
+#include "console.h"
+#include "ec_commands.h"
+#include "port80.h"
+
+#include "test/drivers/test_state.h"
+#include "test/drivers/utils.h"
+
+/**
+ * @brief TestPurpose: Verify port 80 console commands
+ *
+ * @details
+ * Validate that the port 80 console commands work.
+ *
+ * Expected Results
+ * - The port 80 console commands return the appropriate result
+ */
+ZTEST(port80, test_port80_console)
+{
+ zassert_ok(shell_execute_cmd(get_ec_shell(), "port80"), NULL);
+ zassert_ok(shell_execute_cmd(get_ec_shell(), "port80 flush"), NULL);
+ zassert_ok(shell_execute_cmd(get_ec_shell(), "port80 scroll"), NULL);
+ zassert_ok(shell_execute_cmd(get_ec_shell(), "port80 intprint"), NULL);
+ zassert_ok(!shell_execute_cmd(get_ec_shell(), "port80 unknown_param"),
+ NULL);
+}
+
+/**
+ * @brief Test Suite: Verifies port 80 console commands.
+ */
+ZTEST_SUITE(console_cmd_port80, drivers_predicate_post_main, NULL, NULL, NULL,
+ NULL);
diff --git a/zephyr/test/drivers/default/src/port80.c b/zephyr/test/drivers/default/src/port80.c
new file mode 100644
index 0000000000..3f100f15b2
--- /dev/null
+++ b/zephyr/test/drivers/default/src/port80.c
@@ -0,0 +1,111 @@
+/* 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.
+ */
+
+/**
+ * @file
+ * @brief Unit Tests for ESPI port 80 writes
+ */
+
+#include <zephyr/logging/log.h>
+#include <zephyr/shell/shell.h>
+#include <zephyr/zephyr.h>
+#include <zephyr/ztest.h>
+
+#include "console.h"
+#include "ec_commands.h"
+#include "host_command.h"
+#include "port80.h"
+
+#include "test/drivers/test_state.h"
+#include "test/drivers/utils.h"
+
+/*
+ * Flush any existing writes.
+ */
+static void port80_flush(void)
+{
+ zassert_ok(shell_execute_cmd(get_ec_shell(), "port80 flush"), NULL);
+}
+
+/**
+ * @brief TestPurpose: Verify port 80 writes
+ *
+ * @details
+ * Validate that the port 80 writes are processed correctly.
+ *
+ * Expected Results
+ * - The port 80 writes are received
+ */
+ZTEST(port80, test_port80_write)
+{
+ struct ec_response_port80_read response;
+ struct ec_params_port80_read params;
+ struct host_cmd_handler_args args =
+ BUILD_HOST_COMMAND_SIMPLE(EC_CMD_PORT80_READ, 1);
+
+ port80_flush();
+ port_80_write(0x12);
+ port_80_write(0x34);
+ /* Check the buffer using the host cmd */
+
+ args.params = &params;
+ args.params_size = sizeof(params);
+ args.response = &response;
+ args.response_max = sizeof(response);
+ /* Get the buffer info */
+ params.subcmd = EC_PORT80_GET_INFO;
+ zassert_ok(host_command_process(&args), NULL);
+ zassert_ok(args.result, NULL);
+ zassert_equal(args.response_size, sizeof(response.get_info), NULL);
+ zassert_equal(response.get_info.writes, 2, NULL);
+ /* Read the buffer */
+ params.subcmd = EC_PORT80_READ_BUFFER;
+ params.read_buffer.offset = 0;
+ params.read_buffer.num_entries = 2;
+ zassert_ok(host_command_process(&args), NULL);
+ zassert_ok(args.result, NULL);
+ zassert_equal(args.response_size, sizeof(uint16_t) * 2, NULL);
+ zassert_equal(response.data.codes[0], 0x12, NULL);
+ zassert_equal(response.data.codes[1], 0x34, NULL);
+}
+
+/**
+ * @brief TestPurpose: Verify port 80 read parameters
+ *
+ * @details
+ * Validate that the port 80 read parameters are checked
+ *
+ * Expected Results
+ * - The port 80 parameters are verified
+ */
+ZTEST(port80, test_port80_offset)
+{
+ struct ec_response_port80_read response;
+ struct ec_params_port80_read params;
+ struct host_cmd_handler_args args =
+ BUILD_HOST_COMMAND_SIMPLE(EC_CMD_PORT80_READ, 1);
+
+ port80_flush();
+
+ args.params = &params;
+ args.params_size = sizeof(params);
+ args.response = &response;
+ args.response_max = sizeof(response);
+ params.subcmd = EC_PORT80_READ_BUFFER;
+ params.read_buffer.offset = 0;
+ params.read_buffer.num_entries = 0;
+ zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM, NULL);
+ params.read_buffer.offset = 0xFFFF;
+ params.read_buffer.num_entries = 2;
+ zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM, NULL);
+ params.read_buffer.offset = 0;
+ params.read_buffer.num_entries = 0xFFFF;
+ zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM, NULL);
+}
+
+/**
+ * @brief Test Suite: Verifies port 80 writes.
+ */
+ZTEST_SUITE(port80, drivers_predicate_post_main, NULL, NULL, NULL, NULL);
diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf
index a02e1bf85a..c7c4a97ef4 100644
--- a/zephyr/test/drivers/prj.conf
+++ b/zephyr/test/drivers/prj.conf
@@ -148,6 +148,7 @@ CONFIG_PLATFORM_EC_POWERSEQ_HOST_SLEEP=y
CONFIG_PLATFORM_EC_LID_SWITCH=y
CONFIG_PLATFORM_EC_POWER_BUTTON=y
CONFIG_PLATFORM_EC_HOST_INTERFACE_ESPI=y
+CONFIG_PLATFORM_EC_PORT80=y
CONFIG_WATCHDOG=y
CONFIG_WDT_DISABLE_AT_BOOT=y