All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests
@ 2022-05-18  9:18 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
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Tzung-Bi Shih @ 2022-05-18  9:18 UTC (permalink / raw)
  To: bleung, groeck; +Cc: chrome-platform, linux-kernel, tzungbi, dianders

The series adds some early Kunit tests for ChromeOS EC protocol.

The 2nd patch is a refactor.

The 3rd patch updates code comment.

The 1st and 4th patches add Kunit tests.

Use the following example commands to run the Kunit tests:
$ ./tools/testing/kunit/kunit.py run \
        --arch=x86_64 \
        --kconfig_add CONFIG_CHROME_PLATFORMS=y \
        --kconfig_add CONFIG_CROS_EC=y \
        cros_ec*
$ ./tools/testing/kunit/kunit.py run \
        --arch=arm64 --cross_compile aarch64-linux-gnu- \
        --kconfig_add CONFIG_CHROME_PLATFORMS=y \
        --kconfig_add CONFIG_CROS_EC=y \
        cros_ec*

Tzung-Bi Shih (4):
  platform/chrome: cros_ec_proto: add Kunit tests for
    cros_ec_prepare_tx()
  platform/chrome: cros_ec_proto: factor legacy out from
    cros_ec_prepare_tx()
  platform/chrome: cros_ec_proto: update cros_ec_check_result() comment
  platform/chrome: cros_ec_proto: add Kunit tests for
    cros_ec_check_result()

 drivers/platform/chrome/Kconfig              |   9 +
 drivers/platform/chrome/Makefile             |   3 +
 drivers/platform/chrome/cros_ec_proto.c      |  58 ++---
 drivers/platform/chrome/cros_ec_proto_test.c | 214 +++++++++++++++++++
 4 files changed, 259 insertions(+), 25 deletions(-)
 create mode 100644 drivers/platform/chrome/cros_ec_proto_test.c


base-commit: a0e7d2f65fa706a106dae4b52a7cfe48e0ddfdff
-- 
2.36.0.550.gb090851708-goog


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_prepare_tx()
  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 ` 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
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Tzung-Bi Shih @ 2022-05-18  9:18 UTC (permalink / raw)
  To: bleung, groeck; +Cc: chrome-platform, linux-kernel, tzungbi, dianders

cros_ec_prepare_tx() is used to fill the protocol headers according to
the requested protocol version.

Add Kunit tests cros_ec_prepare_tx() for each version.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
 drivers/platform/chrome/Kconfig              |   9 +
 drivers/platform/chrome/Makefile             |   3 +
 drivers/platform/chrome/cros_ec_proto_test.c | 173 +++++++++++++++++++
 3 files changed, 185 insertions(+)
 create mode 100644 drivers/platform/chrome/cros_ec_proto_test.c

diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig
index 717299cbccac..4b3d2427e8dd 100644
--- a/drivers/platform/chrome/Kconfig
+++ b/drivers/platform/chrome/Kconfig
@@ -267,4 +267,13 @@ config CHROMEOS_PRIVACY_SCREEN
 
 source "drivers/platform/chrome/wilco_ec/Kconfig"
 
+# Kunit test cases
+config CROS_EC_PROTO_KUNIT_TEST
+	tristate "Kunit tests for ChromeOS EC protocol" if !KUNIT_ALL_TESTS
+	depends on KUNIT && CROS_EC
+	default KUNIT_ALL_TESTS
+	select CROS_EC_PROTO
+	help
+	  Kunit tests for the ChromeOS Embedded Controller protocol.
+
 endif # CHROMEOS_PLATFORMS
diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile
index 52f5a2dde8b8..3c380066c6b6 100644
--- a/drivers/platform/chrome/Makefile
+++ b/drivers/platform/chrome/Makefile
@@ -30,3 +30,6 @@ obj-$(CONFIG_CROS_USBPD_LOGGER)		+= cros_usbpd_logger.o
 obj-$(CONFIG_CROS_USBPD_NOTIFY)		+= cros_usbpd_notify.o
 
 obj-$(CONFIG_WILCO_EC)			+= wilco_ec/
+
+# Kunit test cases
+obj-$(CONFIG_CROS_EC_PROTO_KUNIT_TEST)	+= cros_ec_proto_test.o
diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
new file mode 100644
index 000000000000..61abb18ac00b
--- /dev/null
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Kunit tests for ChromeOS Embedded Controller protocol.
+ */
+
+#include <kunit/test.h>
+
+#include <linux/platform_data/cros_ec_commands.h>
+#include <linux/platform_data/cros_ec_proto.h>
+
+#include "cros_ec.h"
+
+#define BUFSIZE 512
+
+struct cros_ec_proto_test_priv {
+	struct cros_ec_device ec_dev;
+	u8 dout[BUFSIZE];
+	u8 din[BUFSIZE];
+	struct cros_ec_command *msg;
+	u8 _msg[BUFSIZE];
+};
+
+static void cros_ec_proto_test_prepare_tx_legacy_normal(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;
+	u8 csum;
+
+	ec_dev->proto_version = 2;
+
+	msg->command = EC_CMD_HELLO;
+	msg->outsize = EC_PROTO2_MAX_PARAM_SIZE;
+	msg->data[0] = 0xde;
+	msg->data[1] = 0xad;
+	msg->data[2] = 0xbe;
+	msg->data[3] = 0xef;
+
+	ret = cros_ec_prepare_tx(ec_dev, msg);
+
+	KUNIT_EXPECT_EQ(test, ret, EC_MSG_TX_PROTO_BYTES + EC_PROTO2_MAX_PARAM_SIZE);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[0], EC_CMD_VERSION0);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[1], EC_CMD_HELLO);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[2], EC_PROTO2_MAX_PARAM_SIZE);
+	KUNIT_EXPECT_EQ(test, EC_MSG_TX_HEADER_BYTES, 3);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 0], 0xde);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 1], 0xad);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 2], 0xbe);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 3], 0xef);
+	for (i = 4; i < EC_PROTO2_MAX_PARAM_SIZE; ++i)
+		KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + i], 0);
+
+	csum = EC_CMD_VERSION0;
+	csum += EC_CMD_HELLO;
+	csum += EC_PROTO2_MAX_PARAM_SIZE;
+	csum += 0xde;
+	csum += 0xad;
+	csum += 0xbe;
+	csum += 0xef;
+	KUNIT_EXPECT_EQ(test,
+			ec_dev->dout[EC_MSG_TX_HEADER_BYTES + EC_PROTO2_MAX_PARAM_SIZE],
+			csum);
+}
+
+static void cros_ec_proto_test_prepare_tx_legacy_bad_msg_outsize(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;
+
+	ec_dev->proto_version = 2;
+
+	msg->outsize = EC_PROTO2_MAX_PARAM_SIZE + 1;
+
+	ret = cros_ec_prepare_tx(ec_dev, msg);
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+}
+
+static void cros_ec_proto_test_prepare_tx_normal(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;
+	struct ec_host_request *request = (struct ec_host_request *)ec_dev->dout;
+	int ret, i;
+	u8 csum;
+
+	msg->command = EC_CMD_HELLO;
+	msg->outsize = 0x88;
+	msg->data[0] = 0xde;
+	msg->data[1] = 0xad;
+	msg->data[2] = 0xbe;
+	msg->data[3] = 0xef;
+
+	ret = cros_ec_prepare_tx(ec_dev, msg);
+
+	KUNIT_EXPECT_EQ(test, ret, sizeof(*request) + 0x88);
+
+	KUNIT_EXPECT_EQ(test, request->struct_version, EC_HOST_REQUEST_VERSION);
+	KUNIT_EXPECT_EQ(test, request->command, EC_CMD_HELLO);
+	KUNIT_EXPECT_EQ(test, request->command_version, 0);
+	KUNIT_EXPECT_EQ(test, request->data_len, 0x88);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[sizeof(*request) + 0], 0xde);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[sizeof(*request) + 1], 0xad);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[sizeof(*request) + 2], 0xbe);
+	KUNIT_EXPECT_EQ(test, ec_dev->dout[sizeof(*request) + 3], 0xef);
+	for (i = 4; i < 0x88; ++i)
+		KUNIT_EXPECT_EQ(test, ec_dev->dout[sizeof(*request) + i], 0);
+
+	csum = EC_HOST_REQUEST_VERSION;
+	csum += EC_CMD_HELLO;
+	csum += 0x88;
+	csum += 0xde;
+	csum += 0xad;
+	csum += 0xbe;
+	csum += 0xef;
+	KUNIT_EXPECT_EQ(test, request->checksum, (u8)-csum);
+}
+
+static void cros_ec_proto_test_prepare_tx_bad_msg_outsize(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;
+
+	msg->outsize = ec_dev->dout_size - sizeof(struct ec_host_request) + 1;
+
+	ret = cros_ec_prepare_tx(ec_dev, msg);
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+}
+
+static int cros_ec_proto_test_init(struct kunit *test)
+{
+	struct cros_ec_proto_test_priv *priv;
+	struct cros_ec_device *ec_dev;
+
+	priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+	test->priv = priv;
+
+	ec_dev = &priv->ec_dev;
+	ec_dev->dout = (u8 *)priv->dout;
+	ec_dev->dout_size = ARRAY_SIZE(priv->dout);
+	ec_dev->din = (u8 *)priv->din;
+	ec_dev->din_size = ARRAY_SIZE(priv->din);
+	ec_dev->proto_version = EC_HOST_REQUEST_VERSION;
+
+	priv->msg = (struct cros_ec_command *)priv->_msg;
+
+	return 0;
+}
+
+static struct kunit_case cros_ec_proto_test_cases[] = {
+	KUNIT_CASE(cros_ec_proto_test_prepare_tx_legacy_normal),
+	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),
+	{}
+};
+
+static struct kunit_suite cros_ec_proto_test_suite = {
+	.name = "cros_ec_proto_test",
+	.init = cros_ec_proto_test_init,
+	.test_cases = cros_ec_proto_test_cases,
+};
+
+kunit_test_suite(cros_ec_proto_test_suite);
+
+MODULE_LICENSE("GPL");
-- 
2.36.0.550.gb090851708-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/4] platform/chrome: cros_ec_proto: factor legacy out from cros_ec_prepare_tx()
  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  9:18 ` 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
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Tzung-Bi Shih @ 2022-05-18  9:18 UTC (permalink / raw)
  To: bleung, groeck; +Cc: chrome-platform, linux-kernel, tzungbi, dianders

cros_ec_prepare_tx() mixed the code for both versions.  To be neat and to
make it clear, factor the legacy part out as a separate function, rename
the function, and update the comments.

Specifically,
- prepare_tx(), for current protocol version (i.e. 3).
- prepare_tx_legacy(), for protocol version <= 2.

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

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index ff767dccdf0f..01ab58b3269b 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -52,8 +52,8 @@ static int cros_ec_map_error(uint32_t result)
 	return ret;
 }
 
-static int prepare_packet(struct cros_ec_device *ec_dev,
-			  struct cros_ec_command *msg)
+static int prepare_tx(struct cros_ec_device *ec_dev,
+		      struct cros_ec_command *msg)
 {
 	struct ec_host_request *request;
 	u8 *out;
@@ -85,6 +85,28 @@ static int prepare_packet(struct cros_ec_device *ec_dev,
 	return sizeof(*request) + msg->outsize;
 }
 
+static int prepare_tx_legacy(struct cros_ec_device *ec_dev,
+			     struct cros_ec_command *msg)
+{
+	u8 *out;
+	u8 csum;
+	int i;
+
+	if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE)
+		return -EINVAL;
+
+	out = ec_dev->dout;
+	out[0] = EC_CMD_VERSION0 + msg->version;
+	out[1] = msg->command;
+	out[2] = msg->outsize;
+	csum = out[0] + out[1] + out[2];
+	for (i = 0; i < msg->outsize; i++)
+		csum += out[EC_MSG_TX_HEADER_BYTES + i] = msg->data[i];
+	out[EC_MSG_TX_HEADER_BYTES + msg->outsize] = csum;
+
+	return EC_MSG_TX_PROTO_BYTES + msg->outsize;
+}
+
 static int send_command(struct cros_ec_device *ec_dev,
 			struct cros_ec_command *msg)
 {
@@ -161,35 +183,18 @@ static int send_command(struct cros_ec_device *ec_dev,
  * @ec_dev: Device to register.
  * @msg: Message to write.
  *
- * This is intended to be used by all ChromeOS EC drivers, but at present
- * only SPI uses it. Once LPC uses the same protocol it can start using it.
- * I2C could use it now, with a refactor of the existing code.
+ * This is used by all ChromeOS EC drivers to prepare the outgoing message
+ * according to different protocol versions.
  *
  * Return: number of prepared bytes on success or negative error code.
  */
 int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
 		       struct cros_ec_command *msg)
 {
-	u8 *out;
-	u8 csum;
-	int i;
-
 	if (ec_dev->proto_version > 2)
-		return prepare_packet(ec_dev, msg);
-
-	if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE)
-		return -EINVAL;
-
-	out = ec_dev->dout;
-	out[0] = EC_CMD_VERSION0 + msg->version;
-	out[1] = msg->command;
-	out[2] = msg->outsize;
-	csum = out[0] + out[1] + out[2];
-	for (i = 0; i < msg->outsize; i++)
-		csum += out[EC_MSG_TX_HEADER_BYTES + i] = msg->data[i];
-	out[EC_MSG_TX_HEADER_BYTES + msg->outsize] = csum;
+		return prepare_tx(ec_dev, msg);
 
-	return EC_MSG_TX_PROTO_BYTES + msg->outsize;
+	return prepare_tx_legacy(ec_dev, msg);
 }
 EXPORT_SYMBOL(cros_ec_prepare_tx);
 
-- 
2.36.0.550.gb090851708-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/4] platform/chrome: cros_ec_proto: update cros_ec_check_result() comment
  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  9:18 ` [PATCH 2/4] platform/chrome: cros_ec_proto: factor legacy out from cros_ec_prepare_tx() Tzung-Bi Shih
@ 2022-05-18  9:18 ` Tzung-Bi Shih
  2022-05-18 16:28   ` Guenter Roeck
  2022-05-18  9:18 ` [PATCH 4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result() Tzung-Bi Shih
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Tzung-Bi Shih @ 2022-05-18  9:18 UTC (permalink / raw)
  To: bleung, groeck; +Cc: chrome-platform, linux-kernel, tzungbi, dianders

At first glance, cros_ec_check_result() is quite like cros_ec_map_error().
They check for `ec_msg->result` and return corresponding errors.  However,
as calling from `pkt_xfer` and `cmd_xfer`, cros_ec_check_result() should
not report furthermore errors.  -EAGAIN is the only exception.

See [1][2][3] for some known userland programs' code.  The return code
from ioctl only denotes the EC communication status.  Userland programs
would further analyze the `result` in struct cros_ec_command* for
follow-up actions (e.g. [4]).

To clarify, update the function comment.

[1]: https://crrev.com/54400e93a75ef440a83d6eaac2cec066daf99cf0/util/comm-dev.c#154
[2]: https://crrev.com/fe32670a89bf59e1aff84bba9dd3295657b85e9b/cros_ec_dev.c#296
[3]: https://crrev.com/4e19eb1d89de0422ff1bbd3f7260b131c761098c/drivers/google/cros_ec_dev.c#120
[4]: https://crrev.com/54400e93a75ef440a83d6eaac2cec066daf99cf0/util/comm-dev.c#164

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
Changes from previous version:
(https://patchwork.kernel.org/project/chrome-platform/patch/20220517082817.1591526-1-tzungbi@kernel.org/)
- Update the link of [3].

 drivers/platform/chrome/cros_ec_proto.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index 01ab58b3269b..13ced9d2dd71 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -204,9 +204,12 @@ EXPORT_SYMBOL(cros_ec_prepare_tx);
  * @msg: Message to check.
  *
  * This is used by ChromeOS EC drivers to check the ec_msg->result for
- * errors and to warn about them.
+ * EC_RES_IN_PROGRESS and to warn about them.
  *
- * Return: 0 on success or negative error code.
+ * The function should not check for furthermore error codes.  Otherwise,
+ * it would break the ABI.
+ *
+ * Return: -EAGAIN if ec_msg->result == EC_RES_IN_PROGRESS.  Otherwise, 0.
  */
 int cros_ec_check_result(struct cros_ec_device *ec_dev,
 			 struct cros_ec_command *msg)
-- 
2.36.0.550.gb090851708-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result()
  2022-05-18  9:18 [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests Tzung-Bi Shih
                   ` (2 preceding siblings ...)
  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  9:18 ` Tzung-Bi Shih
  2022-05-18 16:31   ` Guenter Roeck
  2022-05-19  1:50 ` [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests patchwork-bot+chrome-platform
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Tzung-Bi Shih @ 2022-05-18  9:18 UTC (permalink / raw)
  To: bleung, groeck; +Cc: chrome-platform, linux-kernel, tzungbi, dianders

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


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_prepare_tx()
  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
  0 siblings, 0 replies; 12+ messages in thread
From: Guenter Roeck @ 2022-05-18 16:23 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: Benson Leung, Guenter Roeck, chrome-platform, linux-kernel,
	Doug Anderson

On Wed, May 18, 2022 at 2:18 AM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> cros_ec_prepare_tx() is used to fill the protocol headers according to
> the requested protocol version.
>
> Add Kunit tests cros_ec_prepare_tx() for each version.
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

Reviewed-by: Guenter Roeck <groeck@chromium.org>

> ---
>  drivers/platform/chrome/Kconfig              |   9 +
>  drivers/platform/chrome/Makefile             |   3 +
>  drivers/platform/chrome/cros_ec_proto_test.c | 173 +++++++++++++++++++
>  3 files changed, 185 insertions(+)
>  create mode 100644 drivers/platform/chrome/cros_ec_proto_test.c
>
> diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig
> index 717299cbccac..4b3d2427e8dd 100644
> --- a/drivers/platform/chrome/Kconfig
> +++ b/drivers/platform/chrome/Kconfig
> @@ -267,4 +267,13 @@ config CHROMEOS_PRIVACY_SCREEN
>
>  source "drivers/platform/chrome/wilco_ec/Kconfig"
>
> +# Kunit test cases
> +config CROS_EC_PROTO_KUNIT_TEST
> +       tristate "Kunit tests for ChromeOS EC protocol" if !KUNIT_ALL_TESTS
> +       depends on KUNIT && CROS_EC
> +       default KUNIT_ALL_TESTS
> +       select CROS_EC_PROTO
> +       help
> +         Kunit tests for the ChromeOS Embedded Controller protocol.
> +
>  endif # CHROMEOS_PLATFORMS
> diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile
> index 52f5a2dde8b8..3c380066c6b6 100644
> --- a/drivers/platform/chrome/Makefile
> +++ b/drivers/platform/chrome/Makefile
> @@ -30,3 +30,6 @@ obj-$(CONFIG_CROS_USBPD_LOGGER)               += cros_usbpd_logger.o
>  obj-$(CONFIG_CROS_USBPD_NOTIFY)                += cros_usbpd_notify.o
>
>  obj-$(CONFIG_WILCO_EC)                 += wilco_ec/
> +
> +# Kunit test cases
> +obj-$(CONFIG_CROS_EC_PROTO_KUNIT_TEST) += cros_ec_proto_test.o
> diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
> new file mode 100644
> index 000000000000..61abb18ac00b
> --- /dev/null
> +++ b/drivers/platform/chrome/cros_ec_proto_test.c
> @@ -0,0 +1,173 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Kunit tests for ChromeOS Embedded Controller protocol.
> + */
> +
> +#include <kunit/test.h>
> +
> +#include <linux/platform_data/cros_ec_commands.h>
> +#include <linux/platform_data/cros_ec_proto.h>
> +
> +#include "cros_ec.h"
> +
> +#define BUFSIZE 512
> +
> +struct cros_ec_proto_test_priv {
> +       struct cros_ec_device ec_dev;
> +       u8 dout[BUFSIZE];
> +       u8 din[BUFSIZE];
> +       struct cros_ec_command *msg;
> +       u8 _msg[BUFSIZE];
> +};
> +
> +static void cros_ec_proto_test_prepare_tx_legacy_normal(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;
> +       u8 csum;
> +
> +       ec_dev->proto_version = 2;
> +
> +       msg->command = EC_CMD_HELLO;
> +       msg->outsize = EC_PROTO2_MAX_PARAM_SIZE;
> +       msg->data[0] = 0xde;
> +       msg->data[1] = 0xad;
> +       msg->data[2] = 0xbe;
> +       msg->data[3] = 0xef;
> +
> +       ret = cros_ec_prepare_tx(ec_dev, msg);
> +
> +       KUNIT_EXPECT_EQ(test, ret, EC_MSG_TX_PROTO_BYTES + EC_PROTO2_MAX_PARAM_SIZE);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[0], EC_CMD_VERSION0);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[1], EC_CMD_HELLO);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[2], EC_PROTO2_MAX_PARAM_SIZE);
> +       KUNIT_EXPECT_EQ(test, EC_MSG_TX_HEADER_BYTES, 3);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 0], 0xde);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 1], 0xad);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 2], 0xbe);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + 3], 0xef);
> +       for (i = 4; i < EC_PROTO2_MAX_PARAM_SIZE; ++i)
> +               KUNIT_EXPECT_EQ(test, ec_dev->dout[EC_MSG_TX_HEADER_BYTES + i], 0);
> +
> +       csum = EC_CMD_VERSION0;
> +       csum += EC_CMD_HELLO;
> +       csum += EC_PROTO2_MAX_PARAM_SIZE;
> +       csum += 0xde;
> +       csum += 0xad;
> +       csum += 0xbe;
> +       csum += 0xef;
> +       KUNIT_EXPECT_EQ(test,
> +                       ec_dev->dout[EC_MSG_TX_HEADER_BYTES + EC_PROTO2_MAX_PARAM_SIZE],
> +                       csum);
> +}
> +
> +static void cros_ec_proto_test_prepare_tx_legacy_bad_msg_outsize(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;
> +
> +       ec_dev->proto_version = 2;
> +
> +       msg->outsize = EC_PROTO2_MAX_PARAM_SIZE + 1;
> +
> +       ret = cros_ec_prepare_tx(ec_dev, msg);
> +       KUNIT_EXPECT_EQ(test, ret, -EINVAL);
> +}
> +
> +static void cros_ec_proto_test_prepare_tx_normal(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;
> +       struct ec_host_request *request = (struct ec_host_request *)ec_dev->dout;
> +       int ret, i;
> +       u8 csum;
> +
> +       msg->command = EC_CMD_HELLO;
> +       msg->outsize = 0x88;
> +       msg->data[0] = 0xde;
> +       msg->data[1] = 0xad;
> +       msg->data[2] = 0xbe;
> +       msg->data[3] = 0xef;
> +
> +       ret = cros_ec_prepare_tx(ec_dev, msg);
> +
> +       KUNIT_EXPECT_EQ(test, ret, sizeof(*request) + 0x88);
> +
> +       KUNIT_EXPECT_EQ(test, request->struct_version, EC_HOST_REQUEST_VERSION);
> +       KUNIT_EXPECT_EQ(test, request->command, EC_CMD_HELLO);
> +       KUNIT_EXPECT_EQ(test, request->command_version, 0);
> +       KUNIT_EXPECT_EQ(test, request->data_len, 0x88);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[sizeof(*request) + 0], 0xde);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[sizeof(*request) + 1], 0xad);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[sizeof(*request) + 2], 0xbe);
> +       KUNIT_EXPECT_EQ(test, ec_dev->dout[sizeof(*request) + 3], 0xef);
> +       for (i = 4; i < 0x88; ++i)
> +               KUNIT_EXPECT_EQ(test, ec_dev->dout[sizeof(*request) + i], 0);
> +
> +       csum = EC_HOST_REQUEST_VERSION;
> +       csum += EC_CMD_HELLO;
> +       csum += 0x88;
> +       csum += 0xde;
> +       csum += 0xad;
> +       csum += 0xbe;
> +       csum += 0xef;
> +       KUNIT_EXPECT_EQ(test, request->checksum, (u8)-csum);
> +}
> +
> +static void cros_ec_proto_test_prepare_tx_bad_msg_outsize(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;
> +
> +       msg->outsize = ec_dev->dout_size - sizeof(struct ec_host_request) + 1;
> +
> +       ret = cros_ec_prepare_tx(ec_dev, msg);
> +       KUNIT_EXPECT_EQ(test, ret, -EINVAL);
> +}
> +
> +static int cros_ec_proto_test_init(struct kunit *test)
> +{
> +       struct cros_ec_proto_test_priv *priv;
> +       struct cros_ec_device *ec_dev;
> +
> +       priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
> +       if (!priv)
> +               return -ENOMEM;
> +       test->priv = priv;
> +
> +       ec_dev = &priv->ec_dev;
> +       ec_dev->dout = (u8 *)priv->dout;
> +       ec_dev->dout_size = ARRAY_SIZE(priv->dout);
> +       ec_dev->din = (u8 *)priv->din;
> +       ec_dev->din_size = ARRAY_SIZE(priv->din);
> +       ec_dev->proto_version = EC_HOST_REQUEST_VERSION;
> +
> +       priv->msg = (struct cros_ec_command *)priv->_msg;
> +
> +       return 0;
> +}
> +
> +static struct kunit_case cros_ec_proto_test_cases[] = {
> +       KUNIT_CASE(cros_ec_proto_test_prepare_tx_legacy_normal),
> +       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),
> +       {}
> +};
> +
> +static struct kunit_suite cros_ec_proto_test_suite = {
> +       .name = "cros_ec_proto_test",
> +       .init = cros_ec_proto_test_init,
> +       .test_cases = cros_ec_proto_test_cases,
> +};
> +
> +kunit_test_suite(cros_ec_proto_test_suite);
> +
> +MODULE_LICENSE("GPL");
> --
> 2.36.0.550.gb090851708-goog
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/4] platform/chrome: cros_ec_proto: factor legacy out from cros_ec_prepare_tx()
  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
  0 siblings, 0 replies; 12+ messages in thread
From: Guenter Roeck @ 2022-05-18 16:26 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: Benson Leung, Guenter Roeck, chrome-platform, linux-kernel,
	Doug Anderson

On Wed, May 18, 2022 at 2:18 AM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> cros_ec_prepare_tx() mixed the code for both versions.  To be neat and to
> make it clear, factor the legacy part out as a separate function, rename
> the function, and update the comments.
>
> Specifically,
> - prepare_tx(), for current protocol version (i.e. 3).
> - prepare_tx_legacy(), for protocol version <= 2.
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

Reviewed-by: Guenter Roeck <groeck@chromium.org>

> ---
>  drivers/platform/chrome/cros_ec_proto.c | 51 ++++++++++++++-----------
>  1 file changed, 28 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
> index ff767dccdf0f..01ab58b3269b 100644
> --- a/drivers/platform/chrome/cros_ec_proto.c
> +++ b/drivers/platform/chrome/cros_ec_proto.c
> @@ -52,8 +52,8 @@ static int cros_ec_map_error(uint32_t result)
>         return ret;
>  }
>
> -static int prepare_packet(struct cros_ec_device *ec_dev,
> -                         struct cros_ec_command *msg)
> +static int prepare_tx(struct cros_ec_device *ec_dev,
> +                     struct cros_ec_command *msg)
>  {
>         struct ec_host_request *request;
>         u8 *out;
> @@ -85,6 +85,28 @@ static int prepare_packet(struct cros_ec_device *ec_dev,
>         return sizeof(*request) + msg->outsize;
>  }
>
> +static int prepare_tx_legacy(struct cros_ec_device *ec_dev,
> +                            struct cros_ec_command *msg)
> +{
> +       u8 *out;
> +       u8 csum;
> +       int i;
> +
> +       if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE)
> +               return -EINVAL;
> +
> +       out = ec_dev->dout;
> +       out[0] = EC_CMD_VERSION0 + msg->version;
> +       out[1] = msg->command;
> +       out[2] = msg->outsize;
> +       csum = out[0] + out[1] + out[2];
> +       for (i = 0; i < msg->outsize; i++)
> +               csum += out[EC_MSG_TX_HEADER_BYTES + i] = msg->data[i];
> +       out[EC_MSG_TX_HEADER_BYTES + msg->outsize] = csum;
> +
> +       return EC_MSG_TX_PROTO_BYTES + msg->outsize;
> +}
> +
>  static int send_command(struct cros_ec_device *ec_dev,
>                         struct cros_ec_command *msg)
>  {
> @@ -161,35 +183,18 @@ static int send_command(struct cros_ec_device *ec_dev,
>   * @ec_dev: Device to register.
>   * @msg: Message to write.
>   *
> - * This is intended to be used by all ChromeOS EC drivers, but at present
> - * only SPI uses it. Once LPC uses the same protocol it can start using it.
> - * I2C could use it now, with a refactor of the existing code.
> + * This is used by all ChromeOS EC drivers to prepare the outgoing message
> + * according to different protocol versions.
>   *
>   * Return: number of prepared bytes on success or negative error code.
>   */
>  int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
>                        struct cros_ec_command *msg)
>  {
> -       u8 *out;
> -       u8 csum;
> -       int i;
> -
>         if (ec_dev->proto_version > 2)
> -               return prepare_packet(ec_dev, msg);
> -
> -       if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE)
> -               return -EINVAL;
> -
> -       out = ec_dev->dout;
> -       out[0] = EC_CMD_VERSION0 + msg->version;
> -       out[1] = msg->command;
> -       out[2] = msg->outsize;
> -       csum = out[0] + out[1] + out[2];
> -       for (i = 0; i < msg->outsize; i++)
> -               csum += out[EC_MSG_TX_HEADER_BYTES + i] = msg->data[i];
> -       out[EC_MSG_TX_HEADER_BYTES + msg->outsize] = csum;
> +               return prepare_tx(ec_dev, msg);
>
> -       return EC_MSG_TX_PROTO_BYTES + msg->outsize;
> +       return prepare_tx_legacy(ec_dev, msg);
>  }
>  EXPORT_SYMBOL(cros_ec_prepare_tx);
>
> --
> 2.36.0.550.gb090851708-goog
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/4] platform/chrome: cros_ec_proto: update cros_ec_check_result() comment
  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
  0 siblings, 0 replies; 12+ messages in thread
From: Guenter Roeck @ 2022-05-18 16:28 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: Benson Leung, Guenter Roeck, chrome-platform, linux-kernel,
	Doug Anderson

On Wed, May 18, 2022 at 2:18 AM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> At first glance, cros_ec_check_result() is quite like cros_ec_map_error().
> They check for `ec_msg->result` and return corresponding errors.  However,
> as calling from `pkt_xfer` and `cmd_xfer`, cros_ec_check_result() should
> not report furthermore errors.  -EAGAIN is the only exception.
>
> See [1][2][3] for some known userland programs' code.  The return code
> from ioctl only denotes the EC communication status.  Userland programs
> would further analyze the `result` in struct cros_ec_command* for
> follow-up actions (e.g. [4]).
>
> To clarify, update the function comment.
>
> [1]: https://crrev.com/54400e93a75ef440a83d6eaac2cec066daf99cf0/util/comm-dev.c#154
> [2]: https://crrev.com/fe32670a89bf59e1aff84bba9dd3295657b85e9b/cros_ec_dev.c#296
> [3]: https://crrev.com/4e19eb1d89de0422ff1bbd3f7260b131c761098c/drivers/google/cros_ec_dev.c#120
> [4]: https://crrev.com/54400e93a75ef440a83d6eaac2cec066daf99cf0/util/comm-dev.c#164
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
> ---
> Changes from previous version:
> (https://patchwork.kernel.org/project/chrome-platform/patch/20220517082817.1591526-1-tzungbi@kernel.org/)
> - Update the link of [3].

The patch should be marked as v2 if there is a previous version. Other
than that,

Reviewed-by: Guenter Roeck <groeck@chromium.org>

>
>  drivers/platform/chrome/cros_ec_proto.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
> index 01ab58b3269b..13ced9d2dd71 100644
> --- a/drivers/platform/chrome/cros_ec_proto.c
> +++ b/drivers/platform/chrome/cros_ec_proto.c
> @@ -204,9 +204,12 @@ EXPORT_SYMBOL(cros_ec_prepare_tx);
>   * @msg: Message to check.
>   *
>   * This is used by ChromeOS EC drivers to check the ec_msg->result for
> - * errors and to warn about them.
> + * EC_RES_IN_PROGRESS and to warn about them.
>   *
> - * Return: 0 on success or negative error code.
> + * The function should not check for furthermore error codes.  Otherwise,
> + * it would break the ABI.
> + *
> + * Return: -EAGAIN if ec_msg->result == EC_RES_IN_PROGRESS.  Otherwise, 0.
>   */
>  int cros_ec_check_result(struct cros_ec_device *ec_dev,
>                          struct cros_ec_command *msg)
> --
> 2.36.0.550.gb090851708-goog
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result()
  2022-05-18  9:18 ` [PATCH 4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result() Tzung-Bi Shih
@ 2022-05-18 16:31   ` Guenter Roeck
  0 siblings, 0 replies; 12+ messages in thread
From: Guenter Roeck @ 2022-05-18 16:31 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: Benson Leung, Guenter Roeck, chrome-platform, linux-kernel,
	Doug Anderson

On Wed, May 18, 2022 at 2:18 AM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> 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>

Reviewed-by: Guenter Roeck <groeck@chromium.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
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests
  2022-05-18  9:18 [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests Tzung-Bi Shih
                   ` (3 preceding siblings ...)
  2022-05-18  9:18 ` [PATCH 4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result() Tzung-Bi Shih
@ 2022-05-19  1:50 ` patchwork-bot+chrome-platform
  2022-05-24  0:50 ` patchwork-bot+chrome-platform
  2022-06-06  4:08 ` patchwork-bot+chrome-platform
  6 siblings, 0 replies; 12+ messages in thread
From: patchwork-bot+chrome-platform @ 2022-05-19  1:50 UTC (permalink / raw)
  To: Tzung-Bi Shih; +Cc: bleung, groeck, chrome-platform, linux-kernel, dianders

Hello:

This series was applied to chrome-platform/linux.git (for-kernelci)
by Tzung-Bi Shih <tzungbi@kernel.org>:

On Wed, 18 May 2022 17:18:10 +0800 you wrote:
> The series adds some early Kunit tests for ChromeOS EC protocol.
> 
> The 2nd patch is a refactor.
> 
> The 3rd patch updates code comment.
> 
> The 1st and 4th patches add Kunit tests.
> 
> [...]

Here is the summary with links:
  - [1/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_prepare_tx()
    https://git.kernel.org/chrome-platform/c/2c2d9dc1541b
  - [2/4] platform/chrome: cros_ec_proto: factor legacy out from cros_ec_prepare_tx()
    https://git.kernel.org/chrome-platform/c/c81768cb844f
  - [3/4] platform/chrome: cros_ec_proto: update cros_ec_check_result() comment
    https://git.kernel.org/chrome-platform/c/a78a6540e90e
  - [4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result()
    https://git.kernel.org/chrome-platform/c/90ce792231d1

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests
  2022-05-18  9:18 [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests Tzung-Bi Shih
                   ` (4 preceding siblings ...)
  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
  6 siblings, 0 replies; 12+ messages in thread
From: patchwork-bot+chrome-platform @ 2022-05-24  0:50 UTC (permalink / raw)
  To: Tzung-Bi Shih; +Cc: bleung, groeck, chrome-platform, linux-kernel, dianders

Hello:

This series was applied to chrome-platform/linux.git (for-kernelci)
by Tzung-Bi Shih <tzungbi@kernel.org>:

On Wed, 18 May 2022 17:18:10 +0800 you wrote:
> The series adds some early Kunit tests for ChromeOS EC protocol.
> 
> The 2nd patch is a refactor.
> 
> The 3rd patch updates code comment.
> 
> The 1st and 4th patches add Kunit tests.
> 
> [...]

Here is the summary with links:
  - [1/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_prepare_tx()
    https://git.kernel.org/chrome-platform/c/c185ba01c945
  - [2/4] platform/chrome: cros_ec_proto: factor legacy out from cros_ec_prepare_tx()
    https://git.kernel.org/chrome-platform/c/103c883f4ace
  - [3/4] platform/chrome: cros_ec_proto: update cros_ec_check_result() comment
    https://git.kernel.org/chrome-platform/c/3cd0cacd4b64
  - [4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result()
    https://git.kernel.org/chrome-platform/c/3c470e42dd47

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests
  2022-05-18  9:18 [PATCH 0/4] platform/chrome: cros_ec_proto: add initial Kunit tests Tzung-Bi Shih
                   ` (5 preceding siblings ...)
  2022-05-24  0:50 ` patchwork-bot+chrome-platform
@ 2022-06-06  4:08 ` patchwork-bot+chrome-platform
  6 siblings, 0 replies; 12+ messages in thread
From: patchwork-bot+chrome-platform @ 2022-06-06  4:08 UTC (permalink / raw)
  To: Tzung-Bi Shih; +Cc: bleung, groeck, chrome-platform, linux-kernel, dianders

Hello:

This series was applied to chrome-platform/linux.git (for-next)
by Tzung-Bi Shih <tzungbi@kernel.org>:

On Wed, 18 May 2022 17:18:10 +0800 you wrote:
> The series adds some early Kunit tests for ChromeOS EC protocol.
> 
> The 2nd patch is a refactor.
> 
> The 3rd patch updates code comment.
> 
> The 1st and 4th patches add Kunit tests.
> 
> [...]

Here is the summary with links:
  - [1/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_prepare_tx()
    https://git.kernel.org/chrome-platform/c/db681eaf7145
  - [2/4] platform/chrome: cros_ec_proto: factor legacy out from cros_ec_prepare_tx()
    https://git.kernel.org/chrome-platform/c/23a34e3a9d00
  - [3/4] platform/chrome: cros_ec_proto: update cros_ec_check_result() comment
    https://git.kernel.org/chrome-platform/c/97b11dd6350a
  - [4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result()
    https://git.kernel.org/chrome-platform/c/4319cbd4ed99

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-06-06  4:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result() Tzung-Bi Shih
2022-05-18 16:31   ` 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

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.