All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: bleung@chromium.org, groeck@chromium.org
Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org,
	tzungbi@kernel.org, dianders@chromium.org
Subject: [PATCH 4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result()
Date: Wed, 18 May 2022 17:18:14 +0800	[thread overview]
Message-ID: <20220518091814.2028579-5-tzungbi@kernel.org> (raw)
In-Reply-To: <20220518091814.2028579-1-tzungbi@kernel.org>

cros_ec_check_result() is used to check if the EC communication success but
EC responded EC_RES_IN_PROGRESS.  It should return 0 even if EC wasn't
happy about the host command.

Add Kunit tests for cros_ec_check_result().

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

diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index 61abb18ac00b..25c4fca5c165 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -132,6 +132,46 @@ static void cros_ec_proto_test_prepare_tx_bad_msg_outsize(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
 }
 
+static void cros_ec_proto_test_check_result(struct kunit *test)
+{
+	struct cros_ec_proto_test_priv *priv = test->priv;
+	struct cros_ec_device *ec_dev = &priv->ec_dev;
+	struct cros_ec_command *msg = priv->msg;
+	int ret, i;
+	static enum ec_status status[] = {
+		EC_RES_SUCCESS,
+		EC_RES_INVALID_COMMAND,
+		EC_RES_ERROR,
+		EC_RES_INVALID_PARAM,
+		EC_RES_ACCESS_DENIED,
+		EC_RES_INVALID_RESPONSE,
+		EC_RES_INVALID_VERSION,
+		EC_RES_INVALID_CHECKSUM,
+		EC_RES_UNAVAILABLE,
+		EC_RES_TIMEOUT,
+		EC_RES_OVERFLOW,
+		EC_RES_INVALID_HEADER,
+		EC_RES_REQUEST_TRUNCATED,
+		EC_RES_RESPONSE_TOO_BIG,
+		EC_RES_BUS_ERROR,
+		EC_RES_BUSY,
+		EC_RES_INVALID_HEADER_VERSION,
+		EC_RES_INVALID_HEADER_CRC,
+		EC_RES_INVALID_DATA_CRC,
+		EC_RES_DUP_UNAVAILABLE,
+	};
+
+	for (i = 0; i < ARRAY_SIZE(status); ++i) {
+		msg->result = status[i];
+		ret = cros_ec_check_result(ec_dev, msg);
+		KUNIT_EXPECT_EQ(test, ret, 0);
+	}
+
+	msg->result = EC_RES_IN_PROGRESS;
+	ret = cros_ec_check_result(ec_dev, msg);
+	KUNIT_EXPECT_EQ(test, ret, -EAGAIN);
+}
+
 static int cros_ec_proto_test_init(struct kunit *test)
 {
 	struct cros_ec_proto_test_priv *priv;
@@ -159,6 +199,7 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
 	KUNIT_CASE(cros_ec_proto_test_prepare_tx_legacy_bad_msg_outsize),
 	KUNIT_CASE(cros_ec_proto_test_prepare_tx_normal),
 	KUNIT_CASE(cros_ec_proto_test_prepare_tx_bad_msg_outsize),
+	KUNIT_CASE(cros_ec_proto_test_check_result),
 	{}
 };
 
-- 
2.36.0.550.gb090851708-goog


  parent reply	other threads:[~2022-05-18  9:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-18  9:18 [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests Tzung-Bi Shih
2022-05-18  9:18 ` [PATCH 1/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_prepare_tx() Tzung-Bi Shih
2022-05-18 16:23   ` Guenter Roeck
2022-05-18  9:18 ` [PATCH 2/4] platform/chrome: cros_ec_proto: factor legacy out from cros_ec_prepare_tx() Tzung-Bi Shih
2022-05-18 16:26   ` Guenter Roeck
2022-05-18  9:18 ` [PATCH 3/4] platform/chrome: cros_ec_proto: update cros_ec_check_result() comment Tzung-Bi Shih
2022-05-18 16:28   ` Guenter Roeck
2022-05-18  9:18 ` Tzung-Bi Shih [this message]
2022-05-18 16:31   ` [PATCH 4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result() Guenter Roeck
2022-05-19  1:50 ` [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests patchwork-bot+chrome-platform
2022-05-24  0:50 ` patchwork-bot+chrome-platform
2022-06-06  4:08 ` patchwork-bot+chrome-platform

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=20220518091814.2028579-5-tzungbi@kernel.org \
    --to=tzungbi@kernel.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=dianders@chromium.org \
    --cc=groeck@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    /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.