All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Benson Leung <bleung@chromium.org>
Cc: tzungbi@kernel.org, chrome-platform@lists.linux.dev
Subject: [PATCH 7/9] platform/chrome: KUnit: Add test cases for protocol fallback
Date: Tue, 24 Nov 2026 08:21:10 +0000	[thread overview]
Message-ID: <20261124082112.3361229-8-tzungbi@kernel.org> (raw)
In-Reply-To: <20261124082112.3361229-1-tzungbi@kernel.org>

Add new test cases verifying cros_ec_query_all() does not fall back to
protocol v2 when:
- The device is already registered with `pkt_xfer` (known v3+ EC).
- `ec_dev->cmd_xfer` is not supported (doesn't support v2).
- The v3 query failed with a transient error (-ENOMEM or -EAGAIN).

Also rename the existing protocol v3-to-v2 fallback tests to
cros_ec_proto_test_query_all_fallback_v3_* for clarity.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
 drivers/platform/chrome/cros_ec_proto_test.c | 123 ++++++++++++++++++-
 1 file changed, 119 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index c31d0ef87fb2..43c0b265db24 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -474,7 +474,7 @@ static void cros_ec_proto_test_query_all_no_pd_return0(struct kunit *test)
 	}
 }
 
-static void cros_ec_proto_test_query_all_legacy_normal_v3_return_error(struct kunit *test)
+static void cros_ec_proto_test_query_all_fallback_v3_return_error(struct kunit *test)
 {
 	struct cros_ec_proto_test_priv *priv = test->priv;
 	struct cros_ec_device *ec_dev = &priv->ec_dev;
@@ -539,7 +539,7 @@ static void cros_ec_proto_test_query_all_legacy_normal_v3_return_error(struct ku
 	}
 }
 
-static void cros_ec_proto_test_query_all_legacy_normal_v3_return0(struct kunit *test)
+static void cros_ec_proto_test_query_all_fallback_v3_return0(struct kunit *test)
 {
 	struct cros_ec_proto_test_priv *priv = test->priv;
 	struct cros_ec_device *ec_dev = &priv->ec_dev;
@@ -604,6 +604,117 @@ static void cros_ec_proto_test_query_all_legacy_normal_v3_return0(struct kunit *
 	}
 }
 
+static void cros_ec_proto_test_query_all_no_fallback_registered(struct kunit *test)
+{
+	struct cros_ec_proto_test_priv *priv = test->priv;
+	struct cros_ec_device *ec_dev = &priv->ec_dev;
+	struct ec_xfer_mock *mock;
+	int ret;
+
+	ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock;
+	ec_dev->cmd_xfer = cros_kunit_ec_cmd_xfer_mock;
+	ec_dev->registered = true;
+
+	/* For cros_ec_get_proto_info() without passthru. */
+	{
+		mock = cros_kunit_ec_xfer_mock_add(test, 0);
+		KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+	}
+
+	cros_ec_proto_test_query_all_pretest(test);
+	ret = cros_ec_query_all(ec_dev);
+	KUNIT_EXPECT_EQ(test, ret, -EPROTO);
+	KUNIT_EXPECT_EQ(test, ec_dev->proto_version, EC_PROTO_VERSION_UNKNOWN);
+	KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 1);
+	KUNIT_EXPECT_EQ(test, cros_kunit_ec_cmd_xfer_mock_called, 0);
+
+	/* For cros_ec_get_proto_info() without passthru. */
+	{
+		mock = cros_kunit_ec_xfer_mock_next();
+		KUNIT_EXPECT_PTR_NE(test, mock, NULL);
+
+		KUNIT_EXPECT_EQ(test, mock->msg.version, 0);
+		KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_PROTOCOL_INFO);
+		KUNIT_EXPECT_EQ(test, mock->msg.insize,
+				sizeof(struct ec_response_get_protocol_info));
+		KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
+	}
+}
+
+static void cros_ec_proto_test_query_all_no_fallback_no_cmd_xfer(struct kunit *test)
+{
+	struct cros_ec_proto_test_priv *priv = test->priv;
+	struct cros_ec_device *ec_dev = &priv->ec_dev;
+	struct ec_xfer_mock *mock;
+	int ret;
+
+	ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock;
+	ec_dev->cmd_xfer = NULL;
+
+	/* For cros_ec_get_proto_info() without passthru. */
+	{
+		mock = cros_kunit_ec_xfer_mock_add(test, 0);
+		KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+	}
+
+	cros_ec_proto_test_query_all_pretest(test);
+	ret = cros_ec_query_all(ec_dev);
+	KUNIT_EXPECT_EQ(test, ret, -EPROTO);
+	KUNIT_EXPECT_EQ(test, ec_dev->proto_version, EC_PROTO_VERSION_UNKNOWN);
+	KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 1);
+	KUNIT_EXPECT_EQ(test, cros_kunit_ec_cmd_xfer_mock_called, 0);
+
+	/* For cros_ec_get_proto_info() without passthru. */
+	{
+		mock = cros_kunit_ec_xfer_mock_next();
+		KUNIT_EXPECT_PTR_NE(test, mock, NULL);
+
+		KUNIT_EXPECT_EQ(test, mock->msg.version, 0);
+		KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_PROTOCOL_INFO);
+		KUNIT_EXPECT_EQ(test, mock->msg.insize,
+				sizeof(struct ec_response_get_protocol_info));
+		KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
+	}
+}
+
+static void cros_ec_proto_test_query_all_no_fallback_eagain(struct kunit *test)
+{
+	struct cros_ec_proto_test_priv *priv = test->priv;
+	struct cros_ec_device *ec_dev = &priv->ec_dev;
+	int ret;
+
+	ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock;
+	ec_dev->cmd_xfer = cros_kunit_ec_cmd_xfer_mock;
+
+	cros_kunit_ec_xfer_mock_default_ret = -EAGAIN;
+
+	cros_ec_proto_test_query_all_pretest(test);
+	ret = cros_ec_query_all(ec_dev);
+	KUNIT_EXPECT_EQ(test, ret, -EAGAIN);
+	KUNIT_EXPECT_EQ(test, ec_dev->proto_version, EC_PROTO_VERSION_UNKNOWN);
+	KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 6);
+	KUNIT_EXPECT_EQ(test, cros_kunit_ec_cmd_xfer_mock_called, 0);
+}
+
+static void cros_ec_proto_test_query_all_no_fallback_enomem(struct kunit *test)
+{
+	struct cros_ec_proto_test_priv *priv = test->priv;
+	struct cros_ec_device *ec_dev = &priv->ec_dev;
+	int ret;
+
+	ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock;
+	ec_dev->cmd_xfer = cros_kunit_ec_cmd_xfer_mock;
+
+	cros_kunit_ec_xfer_mock_default_ret = -ENOMEM;
+
+	cros_ec_proto_test_query_all_pretest(test);
+	ret = cros_ec_query_all(ec_dev);
+	KUNIT_EXPECT_EQ(test, ret, -ENOMEM);
+	KUNIT_EXPECT_EQ(test, ec_dev->proto_version, EC_PROTO_VERSION_UNKNOWN);
+	KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 1);
+	KUNIT_EXPECT_EQ(test, cros_kunit_ec_cmd_xfer_mock_called, 0);
+}
+
 static void cros_ec_proto_test_query_all_legacy_xfer_error(struct kunit *test)
 {
 	struct cros_ec_proto_test_priv *priv = test->priv;
@@ -2808,8 +2919,12 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
 	KUNIT_CASE(cros_ec_proto_test_query_all_normal),
 	KUNIT_CASE(cros_ec_proto_test_query_all_no_pd_return_error),
 	KUNIT_CASE(cros_ec_proto_test_query_all_no_pd_return0),
-	KUNIT_CASE(cros_ec_proto_test_query_all_legacy_normal_v3_return_error),
-	KUNIT_CASE(cros_ec_proto_test_query_all_legacy_normal_v3_return0),
+	KUNIT_CASE(cros_ec_proto_test_query_all_fallback_v3_return_error),
+	KUNIT_CASE(cros_ec_proto_test_query_all_fallback_v3_return0),
+	KUNIT_CASE(cros_ec_proto_test_query_all_no_fallback_registered),
+	KUNIT_CASE(cros_ec_proto_test_query_all_no_fallback_no_cmd_xfer),
+	KUNIT_CASE(cros_ec_proto_test_query_all_no_fallback_eagain),
+	KUNIT_CASE(cros_ec_proto_test_query_all_no_fallback_enomem),
 	KUNIT_CASE(cros_ec_proto_test_query_all_legacy_xfer_error),
 	KUNIT_CASE(cros_ec_proto_test_query_all_legacy_return_error),
 	KUNIT_CASE(cros_ec_proto_test_query_all_legacy_data_error),
-- 
2.56.1.831.g720f3f5937-goog


  parent reply	other threads:[~2026-11-24  8:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  8:21 [PATCH 0/9] platform/chrome: cros_ec_proto: Harden query_all() and retries Tzung-Bi Shih
2026-11-24  8:21 ` [PATCH 1/9] platform/chrome: cros_ec_proto: Reset msg->result before sending command Tzung-Bi Shih
2026-11-24  8:21 ` [PATCH 2/9] platform/chrome: cros_ec_proto: Retry sending command on -EAGAIN Tzung-Bi Shih
2026-11-24  8:21 ` [PATCH 3/9] platform/chrome: KUnit: Add tests for retrying commands " Tzung-Bi Shih
2026-11-24  8:21 ` [PATCH 4/9] platform/chrome: cros_ec_proto: Reallocate din/dout buffers atomically Tzung-Bi Shih
2026-11-24  8:21 ` [PATCH 5/9] platform/chrome: cros_ec_proto: Guard protocol v2 fallback Tzung-Bi Shih
2026-11-24  8:21 ` [PATCH 6/9] platform/chrome: KUnit: Update test cases for protocol v2 Tzung-Bi Shih
2026-11-24  8:21 ` Tzung-Bi Shih [this message]
2026-11-24  8:21 ` [PATCH 8/9] platform/chrome: cros_ec_proto: Propagate feature probe errors Tzung-Bi Shih
2026-11-24  8:21 ` [PATCH 9/9] platform/chrome: KUnit: Add feature probe unsupported tests Tzung-Bi Shih
2026-11-27  5:03 ` [PATCH 0/9] platform/chrome: cros_ec_proto: Harden query_all() and retries Tzung-Bi Shih

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124082112.3361229-8-tzungbi@kernel.org \
    --to=tzungbi@kernel.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.