summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-08-30 22:11:27 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-01 00:04:11 +0000
commitb2a302b1bef67dd322762feb8e344d45987c30f2 (patch)
treee7deccdec2d350d70a8d8026d40b36b407997326
parent976092f8a33bb2d961c1e8beff92aba44ea15f26 (diff)
downloadchrome-ec-b2a302b1bef67dd322762feb8e344d45987c30f2.tar.gz
test: add tests for host command PD get/write log entry
Verify that the boundary conditions are met for the PD get and write log entry commands as well as verify that the log entries are added to the log FIFO. BRANCH=none BUG=b:236075606 TEST=twister -s zephyr/test/drivers/driver.host_cmd Signed-off-by: Yuval Peress <peress@google.com> Change-Id: Ifb246ad6e964dac25d3f70868cb031d80585d99a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3863942 Reviewed-by: Al Semjonovs <asemjonovs@google.com> Commit-Queue: Al Semjonovs <asemjonovs@google.com>
-rw-r--r--test/test_config.h4
-rw-r--r--zephyr/test/drivers/host_cmd/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/host_cmd/src/pd_log.c135
-rw-r--r--zephyr/test/drivers/testcase.yaml1
4 files changed, 141 insertions, 0 deletions
diff --git a/test/test_config.h b/test/test_config.h
index 536146a452..004cfe315d 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -20,7 +20,11 @@
/* Don't compile features unless specifically testing for them */
#undef CONFIG_VBOOT_HASH
+
+/* Only disable this if we didn't explicitly enable it in Kconfig */
+#ifndef CONFIG_PLATFORM_EC_USB_PD_LOGGING
#undef CONFIG_USB_PD_LOGGING
+#endif
#if defined(TEST_AES) || defined(TEST_CRYPTO_BENCHMARK)
#define CONFIG_AES
diff --git a/zephyr/test/drivers/host_cmd/CMakeLists.txt b/zephyr/test/drivers/host_cmd/CMakeLists.txt
index cdeb57a279..f274cadb3d 100644
--- a/zephyr/test/drivers/host_cmd/CMakeLists.txt
+++ b/zephyr/test/drivers/host_cmd/CMakeLists.txt
@@ -11,5 +11,6 @@ target_sources(app PRIVATE
src/motion_sense.c
src/pd_control.c
src/pd_chip_info.c
+ src/pd_log.c
src/usb_pd_control.c
)
diff --git a/zephyr/test/drivers/host_cmd/src/pd_log.c b/zephyr/test/drivers/host_cmd/src/pd_log.c
new file mode 100644
index 0000000000..642e5c99db
--- /dev/null
+++ b/zephyr/test/drivers/host_cmd/src/pd_log.c
@@ -0,0 +1,135 @@
+/* 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/kernel.h>
+#include <zephyr/ztest.h>
+
+#include "event_log.h"
+#include "host_command.h"
+#include "test/drivers/test_state.h"
+#include "usb_pd.h"
+
+/**
+ * @brief This is the maximum size of a single log entry.
+ *
+ * Each entry must contain some common data + up to 16 bytes of additional type
+ * specific data.
+ */
+#define MAX_EVENT_LOG_ENTRY_SIZE (sizeof(struct event_log_entry) + 16)
+
+/**
+ * @brief The size of the PD log entry data
+ *
+ * Logs from the PD include an additional 8 bytes of data to be sent to the AP.
+ */
+#define PD_LOG_ENTRY_DATA_SIZE (8)
+
+struct pd_log_fixture {
+ union {
+ uint8_t event_log_buffer[MAX_EVENT_LOG_ENTRY_SIZE];
+ struct event_log_entry log_entry;
+ };
+};
+
+static void *pd_log_setup(void)
+{
+ static struct pd_log_fixture fixture;
+
+ return &fixture;
+}
+
+static void pd_log_before(void *f)
+{
+ struct pd_log_fixture *fixture = f;
+
+ while (log_dequeue_event(&fixture->log_entry) != 0) {
+ if (fixture->log_entry.type == EVENT_LOG_NO_ENTRY) {
+ break;
+ }
+ }
+}
+
+ZTEST_SUITE(pd_log, drivers_predicate_post_main, pd_log_setup, pd_log_before,
+ NULL, NULL);
+
+ZTEST_USER(pd_log, test_bad_type)
+{
+ struct ec_params_pd_write_log_entry params = {
+ .type = PD_EVENT_ACC_BASE,
+ };
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS(
+ EC_CMD_PD_WRITE_LOG_ENTRY, UINT8_C(0), params);
+
+ zassert_equal(EC_RES_INVALID_PARAM, host_command_process(&args), NULL);
+}
+
+ZTEST_USER(pd_log, test_bad_port)
+{
+ struct ec_params_pd_write_log_entry params = {
+ .type = PD_EVENT_MCU_BASE,
+ };
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS(
+ EC_CMD_PD_WRITE_LOG_ENTRY, UINT8_C(0), params);
+
+ params.port = board_get_usb_pd_port_count() + 1;
+ zassert_equal(EC_RES_INVALID_PARAM, host_command_process(&args), NULL);
+}
+
+ZTEST_USER_F(pd_log, test_mcu_charge)
+{
+ struct ec_params_pd_write_log_entry params = {
+ .type = PD_EVENT_MCU_CHARGE,
+ .port = 0,
+ };
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS(
+ EC_CMD_PD_WRITE_LOG_ENTRY, UINT8_C(0), params);
+
+ zassert_ok(host_command_process(&args), NULL);
+ zassert_equal(sizeof(struct event_log_entry) + PD_LOG_ENTRY_DATA_SIZE,
+ log_dequeue_event(&fixture->log_entry), NULL);
+ zassert_equal(params.type, fixture->log_entry.type, NULL);
+ zassert_equal(PD_LOG_ENTRY_DATA_SIZE, fixture->log_entry.size, NULL);
+ zassert_equal(0, fixture->log_entry.data, NULL);
+ zassert_within(0, (int64_t)fixture->log_entry.timestamp, 10,
+ "Expected timestamp %" PRIi64
+ " to be within 10 ms of now",
+ (int64_t)fixture->log_entry.timestamp);
+}
+ZTEST_USER_F(pd_log, test_mcu_connect)
+{
+ struct ec_params_pd_write_log_entry params = {
+ .type = PD_EVENT_MCU_CONNECT,
+ .port = 0,
+ };
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS(
+ EC_CMD_PD_WRITE_LOG_ENTRY, UINT8_C(0), params);
+
+ zassert_ok(host_command_process(&args), NULL);
+ zassert_equal(sizeof(struct event_log_entry),
+ log_dequeue_event(&fixture->log_entry), NULL);
+ zassert_equal(params.type, fixture->log_entry.type, NULL);
+ zassert_equal(0, fixture->log_entry.size, NULL);
+ zassert_equal(0, fixture->log_entry.data, NULL);
+ zassert_within(0, (int64_t)fixture->log_entry.timestamp, 10,
+ "Expected timestamp %" PRIi64
+ " to be within 10 ms of now",
+ (int64_t)fixture->log_entry.timestamp);
+}
+
+ZTEST_USER_F(pd_log, test_read_log_entry)
+{
+ uint8_t response_buffer[sizeof(struct ec_response_pd_log) + 16];
+ struct ec_response_pd_log *response =
+ (struct ec_response_pd_log *)response_buffer;
+ struct host_cmd_handler_args args =
+ BUILD_HOST_COMMAND_SIMPLE(EC_CMD_PD_GET_LOG_ENTRY, UINT8_C(0));
+
+ args.response = response;
+ args.response_max = sizeof(response_buffer);
+
+ zassert_ok(host_command_process(&args), NULL);
+ zassert_equal(sizeof(struct event_log_entry), args.response_size, NULL);
+ zassert_equal(PD_EVENT_NO_ENTRY, response->type, NULL);
+}
diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml
index 8354432cb6..eb88b14a54 100644
--- a/zephyr/test/drivers/testcase.yaml
+++ b/zephyr/test/drivers/testcase.yaml
@@ -20,6 +20,7 @@ tests:
extra_configs:
- CONFIG_LINK_TEST_SUITE_HOST_COMMANDS=y
- CONFIG_PLATFORM_EC_BATTERY_CUT_OFF=y
+ - CONFIG_PLATFORM_EC_USB_PD_LOGGING=y
drivers.ap_mux_control:
extra_args: CONF_FILE="prj.conf;ap_mux_control/prj.conf"
extra_configs: