* [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests
@ 2022-06-22 4:10 Tzung-Bi Shih
2022-06-22 4:10 ` [PATCH 1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status Tzung-Bi Shih
` (8 more replies)
0 siblings, 9 replies; 17+ messages in thread
From: Tzung-Bi Shih @ 2022-06-22 4:10 UTC (permalink / raw)
To: bleung, groeck; +Cc: chrome-platform, tzungbi, linux-kernel
The series add Kunit tests for the rest of exported functions.
The series applies after
https://patchwork.kernel.org/project/chrome-platform/cover/20220615051248.1628156-1-tzungbi@kernel.org/.
Tzung-Bi Shih (7):
platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status
platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error()
platform/chrome: cros_ec_proto: add Kunit tests for get_next_event
platform/chrome: cros_ec_proto: add Kunit tests for get_host_event
platform/chrome: cros_ec_proto: add Kunit tests for check_features
platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count
platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd()
drivers/platform/chrome/cros_ec_proto_test.c | 694 +++++++++++++++++++
drivers/platform/chrome/cros_kunit_util.c | 22 +
drivers/platform/chrome/cros_kunit_util.h | 7 +
3 files changed, 723 insertions(+)
--
2.37.0.rc0.104.g0611611a94-goog
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status
2022-06-22 4:10 [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests Tzung-Bi Shih
@ 2022-06-22 4:10 ` Tzung-Bi Shih
2022-06-23 16:36 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 2/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error() Tzung-Bi Shih
` (7 subsequent siblings)
8 siblings, 1 reply; 17+ messages in thread
From: Tzung-Bi Shih @ 2022-06-22 4:10 UTC (permalink / raw)
To: bleung, groeck; +Cc: chrome-platform, tzungbi, linux-kernel
cros_ec_cmd_xfer_status() calls cros_ec_cmd_xfer() and cros_ec_map_error().
Given that there are already test cases for cros_ec_cmd_xfer(), only add
basic Kunit tests for cros_ec_cmd_xfer_status().
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/cros_ec_proto_test.c | 42 ++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index 7d45e5022221..6464f6101fd3 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -1964,6 +1964,46 @@ static void cros_ec_proto_test_cmd_xfer_in_progress_return0(struct kunit *test)
KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 2);
}
+static void cros_ec_proto_test_cmd_xfer_status_normal(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;
+ struct cros_ec_command msg;
+
+ memset(&msg, 0, sizeof(msg));
+
+ /* For cros_ec_cmd_xfer(). */
+ {
+ mock = cros_kunit_ec_xfer_mock_add(test, 0);
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+ }
+
+ ret = cros_ec_cmd_xfer_status(ec_dev, &msg);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+}
+
+static void cros_ec_proto_test_cmd_xfer_status_xfer_error(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;
+ struct cros_ec_command msg;
+
+ memset(&msg, 0, sizeof(msg));
+
+ /* For cros_ec_cmd_xfer(). */
+ {
+ mock = cros_kunit_ec_xfer_mock_addx(test, -EPROTO, EC_RES_SUCCESS, 0);
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+ }
+
+ ret = cros_ec_cmd_xfer_status(ec_dev, &msg);
+ KUNIT_EXPECT_EQ(test, ret, -EPROTO);
+}
+
static void cros_ec_proto_test_release(struct device *dev)
{
}
@@ -2044,6 +2084,8 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_xfer_error),
KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_return_error),
KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_return0),
+ KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_normal),
+ KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_xfer_error),
{}
};
--
2.37.0.rc0.104.g0611611a94-goog
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 2/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error()
2022-06-22 4:10 [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests Tzung-Bi Shih
2022-06-22 4:10 ` [PATCH 1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status Tzung-Bi Shih
@ 2022-06-22 4:10 ` Tzung-Bi Shih
2022-06-23 16:36 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 3/7] platform/chrome: cros_ec_proto: add Kunit tests for get_next_event Tzung-Bi Shih
` (6 subsequent siblings)
8 siblings, 1 reply; 17+ messages in thread
From: Tzung-Bi Shih @ 2022-06-22 4:10 UTC (permalink / raw)
To: bleung, groeck; +Cc: chrome-platform, tzungbi, linux-kernel
cros_ec_cmd_xfer_status() is the only exported function that calls
static function cros_ec_map_error().
Add Kunit test for cros_ec_map_error() through calling
cros_ec_cmd_xfer_status().
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/cros_ec_proto_test.c | 49 ++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index 6464f6101fd3..be3ac77abdf9 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -2004,6 +2004,54 @@ static void cros_ec_proto_test_cmd_xfer_status_xfer_error(struct kunit *test)
KUNIT_EXPECT_EQ(test, ret, -EPROTO);
}
+static void cros_ec_proto_test_cmd_xfer_status_return_error(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, i;
+ struct cros_ec_command msg;
+ static const int map[] = {
+ [EC_RES_SUCCESS] = 0,
+ [EC_RES_INVALID_COMMAND] = -EOPNOTSUPP,
+ [EC_RES_ERROR] = -EIO,
+ [EC_RES_INVALID_PARAM] = -EINVAL,
+ [EC_RES_ACCESS_DENIED] = -EACCES,
+ [EC_RES_INVALID_RESPONSE] = -EPROTO,
+ [EC_RES_INVALID_VERSION] = -ENOPROTOOPT,
+ [EC_RES_INVALID_CHECKSUM] = -EBADMSG,
+ /*
+ * EC_RES_IN_PROGRESS is special because cros_ec_send_command() has extra logic to
+ * handle it. Note that default cros_kunit_ec_xfer_mock_default_ret == 0 thus
+ * cros_ec_xfer_command() in cros_ec_wait_until_complete() returns 0. As a result,
+ * it returns -EPROTO without calling cros_ec_map_error().
+ */
+ [EC_RES_IN_PROGRESS] = -EPROTO,
+ [EC_RES_UNAVAILABLE] = -ENODATA,
+ [EC_RES_TIMEOUT] = -ETIMEDOUT,
+ [EC_RES_OVERFLOW] = -EOVERFLOW,
+ [EC_RES_INVALID_HEADER] = -EBADR,
+ [EC_RES_REQUEST_TRUNCATED] = -EBADR,
+ [EC_RES_RESPONSE_TOO_BIG] = -EFBIG,
+ [EC_RES_BUS_ERROR] = -EFAULT,
+ [EC_RES_BUSY] = -EBUSY,
+ [EC_RES_INVALID_HEADER_VERSION] = -EBADMSG,
+ [EC_RES_INVALID_HEADER_CRC] = -EBADMSG,
+ [EC_RES_INVALID_DATA_CRC] = -EBADMSG,
+ [EC_RES_DUP_UNAVAILABLE] = -ENODATA,
+ };
+
+ memset(&msg, 0, sizeof(msg));
+
+ for (i = 0; i < ARRAY_SIZE(map); ++i) {
+ mock = cros_kunit_ec_xfer_mock_addx(test, 0, i, 0);
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+
+ ret = cros_ec_cmd_xfer_status(ec_dev, &msg);
+ KUNIT_EXPECT_EQ(test, ret, map[i]);
+ }
+}
+
static void cros_ec_proto_test_release(struct device *dev)
{
}
@@ -2086,6 +2134,7 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_return0),
KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_normal),
KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_xfer_error),
+ KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_return_error),
{}
};
--
2.37.0.rc0.104.g0611611a94-goog
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 3/7] platform/chrome: cros_ec_proto: add Kunit tests for get_next_event
2022-06-22 4:10 [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests Tzung-Bi Shih
2022-06-22 4:10 ` [PATCH 1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status Tzung-Bi Shih
2022-06-22 4:10 ` [PATCH 2/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error() Tzung-Bi Shih
@ 2022-06-22 4:10 ` Tzung-Bi Shih
2022-06-23 16:37 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 4/7] platform/chrome: cros_ec_proto: add Kunit tests for get_host_event Tzung-Bi Shih
` (5 subsequent siblings)
8 siblings, 1 reply; 17+ messages in thread
From: Tzung-Bi Shih @ 2022-06-22 4:10 UTC (permalink / raw)
To: bleung, groeck; +Cc: chrome-platform, tzungbi, linux-kernel
cros_ec_get_next_event() gets events from EC. It consists of 3
versions of event retrieval:
1. No MKBP event.
2. MKBP event version 0.
3. MKBP event version >0.
Add Kunit tests for cros_ec_get_next_event().
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/cros_ec_proto_test.c | 266 +++++++++++++++++++
1 file changed, 266 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index be3ac77abdf9..64c4b79f7a0c 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -5,6 +5,7 @@
#include <kunit/test.h>
+#include <asm-generic/unaligned.h>
#include <linux/platform_data/cros_ec_commands.h>
#include <linux/platform_data/cros_ec_proto.h>
@@ -2052,6 +2053,265 @@ static void cros_ec_proto_test_cmd_xfer_status_return_error(struct kunit *test)
}
}
+static void cros_ec_proto_test_get_next_event_no_mkbp_event(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;
+ bool wake_event, more_events;
+
+ ec_dev->max_request = 0xff;
+ ec_dev->max_response = 0xee;
+ ec_dev->mkbp_event_supported = 0;
+
+ /* Set some garbage bytes. */
+ wake_event = false;
+ more_events = true;
+
+ /* For get_keyboard_state_event(). */
+ {
+ union ec_response_get_next_data_v1 *data;
+
+ mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+
+ data = (union ec_response_get_next_data_v1 *)mock->o_data;
+ data->host_event = 0xbeef;
+ }
+
+ ret = cros_ec_get_next_event(ec_dev, &wake_event, &more_events);
+ KUNIT_EXPECT_EQ(test, ret, sizeof(union ec_response_get_next_data_v1));
+
+ KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_KEY_MATRIX);
+ KUNIT_EXPECT_EQ(test, ec_dev->event_data.data.host_event, 0xbeef);
+
+ KUNIT_EXPECT_TRUE(test, wake_event);
+ KUNIT_EXPECT_FALSE(test, more_events);
+
+ /* For get_keyboard_state_event(). */
+ {
+ 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_MKBP_STATE);
+ KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(union ec_response_get_next_data_v1));
+ KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
+ }
+}
+
+static void cros_ec_proto_test_get_next_event_mkbp_event_ec_suspended(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->mkbp_event_supported = 1;
+ ec_dev->suspended = true;
+
+ ret = cros_ec_get_next_event(ec_dev, NULL, NULL);
+ KUNIT_EXPECT_EQ(test, ret, -EHOSTDOWN);
+}
+
+static void cros_ec_proto_test_get_next_event_mkbp_event_version0(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;
+ bool wake_event, more_events;
+
+ ec_dev->max_request = 0xff;
+ ec_dev->max_response = 0xee;
+ ec_dev->mkbp_event_supported = 1;
+
+ /* Set some garbage bytes. */
+ wake_event = true;
+ more_events = false;
+
+ /* For get_next_event_xfer(). */
+ {
+ struct ec_response_get_next_event *data;
+
+ mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+
+ data = (struct ec_response_get_next_event *)mock->o_data;
+ data->event_type = EC_MKBP_EVENT_SENSOR_FIFO | EC_MKBP_HAS_MORE_EVENTS;
+ data->data.sysrq = 0xbeef;
+ }
+
+ ret = cros_ec_get_next_event(ec_dev, &wake_event, &more_events);
+ KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_next_event));
+
+ KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_SENSOR_FIFO);
+ KUNIT_EXPECT_EQ(test, ec_dev->event_data.data.sysrq, 0xbeef);
+
+ KUNIT_EXPECT_FALSE(test, wake_event);
+ KUNIT_EXPECT_TRUE(test, more_events);
+
+ /* For get_next_event_xfer(). */
+ {
+ 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_NEXT_EVENT);
+ KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_get_next_event));
+ KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
+ }
+}
+
+static void cros_ec_proto_test_get_next_event_mkbp_event_version2(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;
+ bool wake_event, more_events;
+
+ ec_dev->max_request = 0xff;
+ ec_dev->max_response = 0xee;
+ ec_dev->mkbp_event_supported = 3;
+
+ /* Set some garbage bytes. */
+ wake_event = false;
+ more_events = true;
+
+ /* For get_next_event_xfer(). */
+ {
+ struct ec_response_get_next_event_v1 *data;
+
+ mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+
+ data = (struct ec_response_get_next_event_v1 *)mock->o_data;
+ data->event_type = EC_MKBP_EVENT_FINGERPRINT;
+ data->data.sysrq = 0xbeef;
+ }
+
+ ret = cros_ec_get_next_event(ec_dev, &wake_event, &more_events);
+ KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_next_event_v1));
+
+ KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_FINGERPRINT);
+ KUNIT_EXPECT_EQ(test, ec_dev->event_data.data.sysrq, 0xbeef);
+
+ KUNIT_EXPECT_TRUE(test, wake_event);
+ KUNIT_EXPECT_FALSE(test, more_events);
+
+ /* For get_next_event_xfer(). */
+ {
+ mock = cros_kunit_ec_xfer_mock_next();
+ KUNIT_EXPECT_PTR_NE(test, mock, NULL);
+
+ KUNIT_EXPECT_EQ(test, mock->msg.version, 2);
+ KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_NEXT_EVENT);
+ KUNIT_EXPECT_EQ(test, mock->msg.insize,
+ sizeof(struct ec_response_get_next_event_v1));
+ KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
+ }
+}
+
+static void cros_ec_proto_test_get_next_event_mkbp_event_host_event_rtc(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;
+ bool wake_event;
+ struct ec_response_get_next_event_v1 *data;
+
+ ec_dev->max_request = 0xff;
+ ec_dev->max_response = 0xee;
+ ec_dev->mkbp_event_supported = 3;
+ ec_dev->host_event_wake_mask = U32_MAX;
+
+ /* Set some garbage bytes. */
+ wake_event = true;
+
+ /* For get_next_event_xfer(). */
+ {
+ mock = cros_kunit_ec_xfer_mock_add(test,
+ sizeof(data->event_type) +
+ sizeof(data->data.host_event));
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+
+ data = (struct ec_response_get_next_event_v1 *)mock->o_data;
+ data->event_type = EC_MKBP_EVENT_HOST_EVENT;
+ put_unaligned_le32(EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC), &data->data.host_event);
+ }
+
+ ret = cros_ec_get_next_event(ec_dev, &wake_event, NULL);
+ KUNIT_EXPECT_EQ(test, ret, sizeof(data->event_type) + sizeof(data->data.host_event));
+
+ KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_HOST_EVENT);
+
+ KUNIT_EXPECT_FALSE(test, wake_event);
+
+ /* For get_next_event_xfer(). */
+ {
+ mock = cros_kunit_ec_xfer_mock_next();
+ KUNIT_EXPECT_PTR_NE(test, mock, NULL);
+
+ KUNIT_EXPECT_EQ(test, mock->msg.version, 2);
+ KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_NEXT_EVENT);
+ KUNIT_EXPECT_EQ(test, mock->msg.insize,
+ sizeof(struct ec_response_get_next_event_v1));
+ KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
+ }
+}
+
+static void cros_ec_proto_test_get_next_event_mkbp_event_host_event_masked(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;
+ bool wake_event;
+ struct ec_response_get_next_event_v1 *data;
+
+ ec_dev->max_request = 0xff;
+ ec_dev->max_response = 0xee;
+ ec_dev->mkbp_event_supported = 3;
+ ec_dev->host_event_wake_mask = U32_MAX & ~EC_HOST_EVENT_MASK(EC_HOST_EVENT_AC_DISCONNECTED);
+
+ /* Set some garbage bytes. */
+ wake_event = true;
+
+ /* For get_next_event_xfer(). */
+ {
+ mock = cros_kunit_ec_xfer_mock_add(test,
+ sizeof(data->event_type) +
+ sizeof(data->data.host_event));
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+
+ data = (struct ec_response_get_next_event_v1 *)mock->o_data;
+ data->event_type = EC_MKBP_EVENT_HOST_EVENT;
+ put_unaligned_le32(EC_HOST_EVENT_MASK(EC_HOST_EVENT_AC_DISCONNECTED),
+ &data->data.host_event);
+ }
+
+ ret = cros_ec_get_next_event(ec_dev, &wake_event, NULL);
+ KUNIT_EXPECT_EQ(test, ret, sizeof(data->event_type) + sizeof(data->data.host_event));
+
+ KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_HOST_EVENT);
+
+ KUNIT_EXPECT_FALSE(test, wake_event);
+
+ /* For get_next_event_xfer(). */
+ {
+ mock = cros_kunit_ec_xfer_mock_next();
+ KUNIT_EXPECT_PTR_NE(test, mock, NULL);
+
+ KUNIT_EXPECT_EQ(test, mock->msg.version, 2);
+ KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_NEXT_EVENT);
+ KUNIT_EXPECT_EQ(test, mock->msg.insize,
+ sizeof(struct ec_response_get_next_event_v1));
+ KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
+ }
+}
+
static void cros_ec_proto_test_release(struct device *dev)
{
}
@@ -2135,6 +2395,12 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_normal),
KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_xfer_error),
KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_return_error),
+ KUNIT_CASE(cros_ec_proto_test_get_next_event_no_mkbp_event),
+ KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_ec_suspended),
+ KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_version0),
+ KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_version2),
+ KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_host_event_rtc),
+ KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_host_event_masked),
{}
};
--
2.37.0.rc0.104.g0611611a94-goog
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 4/7] platform/chrome: cros_ec_proto: add Kunit tests for get_host_event
2022-06-22 4:10 [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests Tzung-Bi Shih
` (2 preceding siblings ...)
2022-06-22 4:10 ` [PATCH 3/7] platform/chrome: cros_ec_proto: add Kunit tests for get_next_event Tzung-Bi Shih
@ 2022-06-22 4:10 ` Tzung-Bi Shih
2022-06-23 16:38 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 5/7] platform/chrome: cros_ec_proto: add Kunit tests for check_features Tzung-Bi Shih
` (4 subsequent siblings)
8 siblings, 1 reply; 17+ messages in thread
From: Tzung-Bi Shih @ 2022-06-22 4:10 UTC (permalink / raw)
To: bleung, groeck; +Cc: chrome-platform, tzungbi, linux-kernel
cros_ec_get_host_event() performs some sanity checks, parses
`ec_dev->event_data.data.host_event`, and returns bitmap of
EC_HOST_EVENT_*.
Add Kunit tests for cros_ec_get_host_event().
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/cros_ec_proto_test.c | 59 ++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index 64c4b79f7a0c..dce9fa3b9c8d 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -2312,6 +2312,61 @@ static void cros_ec_proto_test_get_next_event_mkbp_event_host_event_masked(struc
}
}
+static void cros_ec_proto_test_get_host_event_no_mkbp_event(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->mkbp_event_supported = 0;
+
+ ret = cros_ec_get_host_event(ec_dev);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+}
+
+static void cros_ec_proto_test_get_host_event_not_host_event(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->mkbp_event_supported = 1;
+ ec_dev->event_data.event_type = EC_MKBP_EVENT_FINGERPRINT;
+
+ ret = cros_ec_get_host_event(ec_dev);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+}
+
+static void cros_ec_proto_test_get_host_event_wrong_event_size(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->mkbp_event_supported = 1;
+ ec_dev->event_data.event_type = EC_MKBP_EVENT_HOST_EVENT;
+ ec_dev->event_size = 0xff;
+
+ ret = cros_ec_get_host_event(ec_dev);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+}
+
+static void cros_ec_proto_test_get_host_event_normal(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->mkbp_event_supported = 1;
+ ec_dev->event_data.event_type = EC_MKBP_EVENT_HOST_EVENT;
+ ec_dev->event_size = sizeof(ec_dev->event_data.data.host_event);
+ put_unaligned_le32(EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC),
+ &ec_dev->event_data.data.host_event);
+
+ ret = cros_ec_get_host_event(ec_dev);
+ KUNIT_EXPECT_EQ(test, ret, EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC));
+}
+
static void cros_ec_proto_test_release(struct device *dev)
{
}
@@ -2401,6 +2456,10 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_version2),
KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_host_event_rtc),
KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_host_event_masked),
+ KUNIT_CASE(cros_ec_proto_test_get_host_event_no_mkbp_event),
+ KUNIT_CASE(cros_ec_proto_test_get_host_event_not_host_event),
+ KUNIT_CASE(cros_ec_proto_test_get_host_event_wrong_event_size),
+ KUNIT_CASE(cros_ec_proto_test_get_host_event_normal),
{}
};
--
2.37.0.rc0.104.g0611611a94-goog
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 5/7] platform/chrome: cros_ec_proto: add Kunit tests for check_features
2022-06-22 4:10 [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests Tzung-Bi Shih
` (3 preceding siblings ...)
2022-06-22 4:10 ` [PATCH 4/7] platform/chrome: cros_ec_proto: add Kunit tests for get_host_event Tzung-Bi Shih
@ 2022-06-22 4:10 ` Tzung-Bi Shih
2022-06-23 16:38 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 6/7] platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count Tzung-Bi Shih
` (3 subsequent siblings)
8 siblings, 1 reply; 17+ messages in thread
From: Tzung-Bi Shih @ 2022-06-22 4:10 UTC (permalink / raw)
To: bleung, groeck; +Cc: chrome-platform, tzungbi, linux-kernel
cros_ec_check_features() gets EC features if it hasn't had cache, and
checks whether the given EC_FEATURE_* is supported or not.
Add Kunit tests for cros_ec_check_features().
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/cros_ec_proto_test.c | 77 ++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index dce9fa3b9c8d..93c1700deaef 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -2367,6 +2367,81 @@ static void cros_ec_proto_test_get_host_event_normal(struct kunit *test)
KUNIT_EXPECT_EQ(test, ret, EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC));
}
+static void cros_ec_proto_test_check_features_cached(struct kunit *test)
+{
+ int ret, i;
+ struct cros_ec_dev ec;
+
+ ec.features.flags[0] = EC_FEATURE_MASK_0(EC_FEATURE_FINGERPRINT);
+ ec.features.flags[1] = EC_FEATURE_MASK_0(EC_FEATURE_SCP);
+
+ for (i = 0; i < EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK; ++i) {
+ ret = cros_ec_check_features(&ec, i);
+ switch (i) {
+ case EC_FEATURE_FINGERPRINT:
+ case EC_FEATURE_SCP:
+ KUNIT_EXPECT_TRUE(test, ret);
+ break;
+ default:
+ KUNIT_EXPECT_FALSE(test, ret);
+ break;
+ }
+ }
+}
+
+static void cros_ec_proto_test_check_features_not_cached(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, i;
+ struct cros_ec_dev ec;
+
+ ec_dev->max_request = 0xff;
+ ec_dev->max_response = 0xee;
+ ec.ec_dev = ec_dev;
+ ec.dev = ec_dev->dev;
+ ec.cmd_offset = 0;
+ ec.features.flags[0] = -1;
+ ec.features.flags[1] = -1;
+
+ /* For EC_CMD_GET_FEATURES. */
+ {
+ struct ec_response_get_features *data;
+
+ mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+
+ data = (struct ec_response_get_features *)mock->o_data;
+ data->flags[0] = EC_FEATURE_MASK_0(EC_FEATURE_FINGERPRINT);
+ data->flags[1] = EC_FEATURE_MASK_0(EC_FEATURE_SCP);
+ }
+
+ for (i = 0; i < EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK; ++i) {
+ ret = cros_ec_check_features(&ec, i);
+ switch (i) {
+ case EC_FEATURE_FINGERPRINT:
+ case EC_FEATURE_SCP:
+ KUNIT_EXPECT_TRUE(test, ret);
+ break;
+ default:
+ KUNIT_EXPECT_FALSE(test, ret);
+ break;
+ }
+ }
+
+ /* For EC_CMD_GET_FEATURES. */
+ {
+ 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_FEATURES);
+ KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_get_features));
+ KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
+ }
+}
+
static void cros_ec_proto_test_release(struct device *dev)
{
}
@@ -2460,6 +2535,8 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
KUNIT_CASE(cros_ec_proto_test_get_host_event_not_host_event),
KUNIT_CASE(cros_ec_proto_test_get_host_event_wrong_event_size),
KUNIT_CASE(cros_ec_proto_test_get_host_event_normal),
+ KUNIT_CASE(cros_ec_proto_test_check_features_cached),
+ KUNIT_CASE(cros_ec_proto_test_check_features_not_cached),
{}
};
--
2.37.0.rc0.104.g0611611a94-goog
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 6/7] platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count
2022-06-22 4:10 [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests Tzung-Bi Shih
` (4 preceding siblings ...)
2022-06-22 4:10 ` [PATCH 5/7] platform/chrome: cros_ec_proto: add Kunit tests for check_features Tzung-Bi Shih
@ 2022-06-22 4:10 ` Tzung-Bi Shih
2022-06-23 16:39 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 7/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd() Tzung-Bi Shih
` (2 subsequent siblings)
8 siblings, 1 reply; 17+ messages in thread
From: Tzung-Bi Shih @ 2022-06-22 4:10 UTC (permalink / raw)
To: bleung, groeck; +Cc: chrome-platform, tzungbi, linux-kernel
cros_ec_get_sensor_count() gets number of MEMS sensors.
Add Kunit tests for cros_ec_get_sensor_count().
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/cros_ec_proto_test.c | 153 +++++++++++++++++++
drivers/platform/chrome/cros_kunit_util.c | 22 +++
drivers/platform/chrome/cros_kunit_util.h | 7 +
3 files changed, 182 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index 93c1700deaef..6b26ce3104f4 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -2442,6 +2442,156 @@ static void cros_ec_proto_test_check_features_not_cached(struct kunit *test)
}
}
+static void cros_ec_proto_test_get_sensor_count_normal(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;
+ struct cros_ec_dev ec;
+
+ ec_dev->max_request = 0xff;
+ ec_dev->max_response = 0xee;
+ ec.ec_dev = ec_dev;
+ ec.dev = ec_dev->dev;
+ ec.cmd_offset = 0;
+
+ /* For EC_CMD_MOTION_SENSE_CMD. */
+ {
+ struct ec_response_motion_sense *data;
+
+ mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+
+ data = (struct ec_response_motion_sense *)mock->o_data;
+ data->dump.sensor_count = 0xbf;
+ }
+
+ ret = cros_ec_get_sensor_count(&ec);
+ KUNIT_EXPECT_EQ(test, ret, 0xbf);
+
+ /* For EC_CMD_MOTION_SENSE_CMD. */
+ {
+ struct ec_params_motion_sense *data;
+
+ mock = cros_kunit_ec_xfer_mock_next();
+ KUNIT_EXPECT_PTR_NE(test, mock, NULL);
+
+ KUNIT_EXPECT_EQ(test, mock->msg.version, 1);
+ KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_MOTION_SENSE_CMD);
+ KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_motion_sense));
+ KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(*data));
+
+ data = (struct ec_params_motion_sense *)mock->i_data;
+ KUNIT_EXPECT_EQ(test, data->cmd, MOTIONSENSE_CMD_DUMP);
+ }
+}
+
+static void cros_ec_proto_test_get_sensor_count_xfer_error(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;
+ struct cros_ec_dev ec;
+
+ ec_dev->max_request = 0xff;
+ ec_dev->max_response = 0xee;
+ ec.ec_dev = ec_dev;
+ ec.dev = ec_dev->dev;
+ ec.cmd_offset = 0;
+
+ /* For EC_CMD_MOTION_SENSE_CMD. */
+ {
+ mock = cros_kunit_ec_xfer_mock_addx(test, -EPROTO, EC_RES_SUCCESS, 0);
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+ }
+
+ ret = cros_ec_get_sensor_count(&ec);
+ KUNIT_EXPECT_EQ(test, ret, -EPROTO);
+
+ /* For EC_CMD_MOTION_SENSE_CMD. */
+ {
+ struct ec_params_motion_sense *data;
+
+ mock = cros_kunit_ec_xfer_mock_next();
+ KUNIT_EXPECT_PTR_NE(test, mock, NULL);
+
+ KUNIT_EXPECT_EQ(test, mock->msg.version, 1);
+ KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_MOTION_SENSE_CMD);
+ KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_motion_sense));
+ KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(*data));
+
+ data = (struct ec_params_motion_sense *)mock->i_data;
+ KUNIT_EXPECT_EQ(test, data->cmd, MOTIONSENSE_CMD_DUMP);
+ }
+}
+
+static void cros_ec_proto_test_get_sensor_count_legacy(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, i;
+ struct cros_ec_dev ec;
+ struct {
+ u8 readmem_data;
+ int expected_result;
+ } test_data[] = {
+ { 0, 0 },
+ { EC_MEMMAP_ACC_STATUS_PRESENCE_BIT, 2 },
+ };
+
+ ec_dev->max_request = 0xff;
+ ec_dev->max_response = 0xee;
+ ec_dev->cmd_readmem = cros_kunit_readmem_mock;
+ ec.ec_dev = ec_dev;
+ ec.dev = ec_dev->dev;
+ ec.cmd_offset = 0;
+
+ for (i = 0; i < ARRAY_SIZE(test_data); ++i) {
+ /* For EC_CMD_MOTION_SENSE_CMD. */
+ {
+ mock = cros_kunit_ec_xfer_mock_addx(test, -EPROTO, EC_RES_SUCCESS, 0);
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+ }
+
+ /* For readmem. */
+ {
+ cros_kunit_readmem_mock_data = kunit_kzalloc(test, 1, GFP_KERNEL);
+ KUNIT_ASSERT_PTR_NE(test, cros_kunit_readmem_mock_data, NULL);
+ cros_kunit_readmem_mock_data[0] = test_data[i].readmem_data;
+
+ cros_kunit_ec_xfer_mock_default_ret = 1;
+ }
+
+ ret = cros_ec_get_sensor_count(&ec);
+ KUNIT_EXPECT_EQ(test, ret, test_data[i].expected_result);
+
+ /* For EC_CMD_MOTION_SENSE_CMD. */
+ {
+ struct ec_params_motion_sense *data;
+
+ mock = cros_kunit_ec_xfer_mock_next();
+ KUNIT_EXPECT_PTR_NE(test, mock, NULL);
+
+ KUNIT_EXPECT_EQ(test, mock->msg.version, 1);
+ KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_MOTION_SENSE_CMD);
+ KUNIT_EXPECT_EQ(test, mock->msg.insize,
+ sizeof(struct ec_response_motion_sense));
+ KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(*data));
+
+ data = (struct ec_params_motion_sense *)mock->i_data;
+ KUNIT_EXPECT_EQ(test, data->cmd, MOTIONSENSE_CMD_DUMP);
+ }
+
+ /* For readmem. */
+ {
+ KUNIT_EXPECT_EQ(test, cros_kunit_readmem_mock_offset, EC_MEMMAP_ACC_STATUS);
+ }
+ }
+}
+
static void cros_ec_proto_test_release(struct device *dev)
{
}
@@ -2537,6 +2687,9 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
KUNIT_CASE(cros_ec_proto_test_get_host_event_normal),
KUNIT_CASE(cros_ec_proto_test_check_features_cached),
KUNIT_CASE(cros_ec_proto_test_check_features_not_cached),
+ KUNIT_CASE(cros_ec_proto_test_get_sensor_count_normal),
+ KUNIT_CASE(cros_ec_proto_test_get_sensor_count_xfer_error),
+ KUNIT_CASE(cros_ec_proto_test_get_sensor_count_legacy),
{}
};
diff --git a/drivers/platform/chrome/cros_kunit_util.c b/drivers/platform/chrome/cros_kunit_util.c
index 3ede971e82ee..d37c334b416d 100644
--- a/drivers/platform/chrome/cros_kunit_util.c
+++ b/drivers/platform/chrome/cros_kunit_util.c
@@ -105,6 +105,24 @@ struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void)
}
EXPORT_SYMBOL_GPL(cros_kunit_ec_xfer_mock_next);
+int cros_kunit_readmem_mock_offset;
+EXPORT_SYMBOL_GPL(cros_kunit_readmem_mock_offset);
+u8 *cros_kunit_readmem_mock_data;
+EXPORT_SYMBOL_GPL(cros_kunit_readmem_mock_data);
+int cros_kunit_readmem_mock_ret;
+EXPORT_SYMBOL_GPL(cros_kunit_readmem_mock_ret);
+
+int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset,
+ unsigned int bytes, void *dest)
+{
+ cros_kunit_readmem_mock_offset = offset;
+
+ memcpy(dest, cros_kunit_readmem_mock_data, bytes);
+
+ return cros_kunit_readmem_mock_ret;
+}
+EXPORT_SYMBOL_GPL(cros_kunit_readmem_mock);
+
void cros_kunit_mock_reset(void)
{
cros_kunit_ec_xfer_mock_default_ret = 0;
@@ -112,6 +130,10 @@ void cros_kunit_mock_reset(void)
cros_kunit_ec_pkt_xfer_mock_called = 0;
INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_in);
INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_out);
+
+ cros_kunit_readmem_mock_offset = 0;
+ cros_kunit_readmem_mock_data = NULL;
+ cros_kunit_readmem_mock_ret = 0;
}
EXPORT_SYMBOL_GPL(cros_kunit_mock_reset);
diff --git a/drivers/platform/chrome/cros_kunit_util.h b/drivers/platform/chrome/cros_kunit_util.h
index ae4080cb13f1..88134c9f1acf 100644
--- a/drivers/platform/chrome/cros_kunit_util.h
+++ b/drivers/platform/chrome/cros_kunit_util.h
@@ -35,6 +35,13 @@ struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test,
int ret, int result, size_t size);
struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void);
+extern int cros_kunit_readmem_mock_offset;
+extern u8 *cros_kunit_readmem_mock_data;
+extern int cros_kunit_readmem_mock_ret;
+
+int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset,
+ unsigned int bytes, void *dest);
+
void cros_kunit_mock_reset(void);
#endif
--
2.37.0.rc0.104.g0611611a94-goog
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 7/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd()
2022-06-22 4:10 [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests Tzung-Bi Shih
` (5 preceding siblings ...)
2022-06-22 4:10 ` [PATCH 6/7] platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count Tzung-Bi Shih
@ 2022-06-22 4:10 ` Tzung-Bi Shih
2022-06-23 16:40 ` Guenter Roeck
2022-07-20 1:30 ` [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests patchwork-bot+chrome-platform
2022-07-21 8:50 ` patchwork-bot+chrome-platform
8 siblings, 1 reply; 17+ messages in thread
From: Tzung-Bi Shih @ 2022-06-22 4:10 UTC (permalink / raw)
To: bleung, groeck; +Cc: chrome-platform, tzungbi, linux-kernel
cros_ec_cmd() is a wrapper of cros_ec_cmd_xfer_status().
Add Kunit test for cros_ec_cmd().
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
drivers/platform/chrome/cros_ec_proto_test.c | 48 ++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
index 6b26ce3104f4..2ff2783fedfb 100644
--- a/drivers/platform/chrome/cros_ec_proto_test.c
+++ b/drivers/platform/chrome/cros_ec_proto_test.c
@@ -2592,6 +2592,53 @@ static void cros_ec_proto_test_get_sensor_count_legacy(struct kunit *test)
}
}
+static void cros_ec_proto_test_ec_cmd(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;
+ u8 out[3], in[2];
+
+ ec_dev->max_request = 0xff;
+ ec_dev->max_response = 0xee;
+
+ out[0] = 0xdd;
+ out[1] = 0xcc;
+ out[2] = 0xbb;
+
+ {
+ u8 *data;
+
+ mock = cros_kunit_ec_xfer_mock_add(test, 2);
+ KUNIT_ASSERT_PTR_NE(test, mock, NULL);
+
+ data = (u8 *)mock->o_data;
+ data[0] = 0xaa;
+ data[1] = 0x99;
+ }
+
+ ret = cros_ec_cmd(ec_dev, 0x88, 0x77, out, ARRAY_SIZE(out), in, ARRAY_SIZE(in));
+ KUNIT_EXPECT_EQ(test, ret, 2);
+
+ {
+ u8 *data;
+
+ mock = cros_kunit_ec_xfer_mock_next();
+ KUNIT_EXPECT_PTR_NE(test, mock, NULL);
+
+ KUNIT_EXPECT_EQ(test, mock->msg.version, 0x88);
+ KUNIT_EXPECT_EQ(test, mock->msg.command, 0x77);
+ KUNIT_EXPECT_EQ(test, mock->msg.insize, ARRAY_SIZE(in));
+ KUNIT_EXPECT_EQ(test, mock->msg.outsize, ARRAY_SIZE(out));
+
+ data = (u8 *)mock->i_data;
+ KUNIT_EXPECT_EQ(test, data[0], 0xdd);
+ KUNIT_EXPECT_EQ(test, data[1], 0xcc);
+ KUNIT_EXPECT_EQ(test, data[2], 0xbb);
+ }
+}
+
static void cros_ec_proto_test_release(struct device *dev)
{
}
@@ -2690,6 +2737,7 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
KUNIT_CASE(cros_ec_proto_test_get_sensor_count_normal),
KUNIT_CASE(cros_ec_proto_test_get_sensor_count_xfer_error),
KUNIT_CASE(cros_ec_proto_test_get_sensor_count_legacy),
+ KUNIT_CASE(cros_ec_proto_test_ec_cmd),
{}
};
--
2.37.0.rc0.104.g0611611a94-goog
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH 1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status
2022-06-22 4:10 ` [PATCH 1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status Tzung-Bi Shih
@ 2022-06-23 16:36 ` Guenter Roeck
0 siblings, 0 replies; 17+ messages in thread
From: Guenter Roeck @ 2022-06-23 16:36 UTC (permalink / raw)
To: Tzung-Bi Shih
Cc: Benson Leung, Guenter Roeck,
open list:CHROME HARDWARE PLATFORM SUPPORT, linux-kernel
On Tue, Jun 21, 2022 at 9:11 PM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> cros_ec_cmd_xfer_status() calls cros_ec_cmd_xfer() and cros_ec_map_error().
>
> Given that there are already test cases for cros_ec_cmd_xfer(), only add
> basic Kunit tests for cros_ec_cmd_xfer_status().
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
> ---
> drivers/platform/chrome/cros_ec_proto_test.c | 42 ++++++++++++++++++++
> 1 file changed, 42 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
> index 7d45e5022221..6464f6101fd3 100644
> --- a/drivers/platform/chrome/cros_ec_proto_test.c
> +++ b/drivers/platform/chrome/cros_ec_proto_test.c
> @@ -1964,6 +1964,46 @@ static void cros_ec_proto_test_cmd_xfer_in_progress_return0(struct kunit *test)
> KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 2);
> }
>
> +static void cros_ec_proto_test_cmd_xfer_status_normal(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;
> + struct cros_ec_command msg;
> +
> + memset(&msg, 0, sizeof(msg));
> +
> + /* For cros_ec_cmd_xfer(). */
> + {
> + mock = cros_kunit_ec_xfer_mock_add(test, 0);
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> + }
> +
> + ret = cros_ec_cmd_xfer_status(ec_dev, &msg);
> + KUNIT_EXPECT_EQ(test, ret, 0);
> +}
> +
> +static void cros_ec_proto_test_cmd_xfer_status_xfer_error(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;
> + struct cros_ec_command msg;
> +
> + memset(&msg, 0, sizeof(msg));
> +
> + /* For cros_ec_cmd_xfer(). */
> + {
> + mock = cros_kunit_ec_xfer_mock_addx(test, -EPROTO, EC_RES_SUCCESS, 0);
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> + }
> +
> + ret = cros_ec_cmd_xfer_status(ec_dev, &msg);
> + KUNIT_EXPECT_EQ(test, ret, -EPROTO);
> +}
> +
> static void cros_ec_proto_test_release(struct device *dev)
> {
> }
> @@ -2044,6 +2084,8 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
> KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_xfer_error),
> KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_return_error),
> KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_return0),
> + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_normal),
> + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_xfer_error),
> {}
> };
>
> --
> 2.37.0.rc0.104.g0611611a94-goog
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error()
2022-06-22 4:10 ` [PATCH 2/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error() Tzung-Bi Shih
@ 2022-06-23 16:36 ` Guenter Roeck
0 siblings, 0 replies; 17+ messages in thread
From: Guenter Roeck @ 2022-06-23 16:36 UTC (permalink / raw)
To: Tzung-Bi Shih
Cc: Benson Leung, Guenter Roeck,
open list:CHROME HARDWARE PLATFORM SUPPORT, linux-kernel
On Tue, Jun 21, 2022 at 9:11 PM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> cros_ec_cmd_xfer_status() is the only exported function that calls
> static function cros_ec_map_error().
>
> Add Kunit test for cros_ec_map_error() through calling
> cros_ec_cmd_xfer_status().
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
> ---
> drivers/platform/chrome/cros_ec_proto_test.c | 49 ++++++++++++++++++++
> 1 file changed, 49 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
> index 6464f6101fd3..be3ac77abdf9 100644
> --- a/drivers/platform/chrome/cros_ec_proto_test.c
> +++ b/drivers/platform/chrome/cros_ec_proto_test.c
> @@ -2004,6 +2004,54 @@ static void cros_ec_proto_test_cmd_xfer_status_xfer_error(struct kunit *test)
> KUNIT_EXPECT_EQ(test, ret, -EPROTO);
> }
>
> +static void cros_ec_proto_test_cmd_xfer_status_return_error(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, i;
> + struct cros_ec_command msg;
> + static const int map[] = {
> + [EC_RES_SUCCESS] = 0,
> + [EC_RES_INVALID_COMMAND] = -EOPNOTSUPP,
> + [EC_RES_ERROR] = -EIO,
> + [EC_RES_INVALID_PARAM] = -EINVAL,
> + [EC_RES_ACCESS_DENIED] = -EACCES,
> + [EC_RES_INVALID_RESPONSE] = -EPROTO,
> + [EC_RES_INVALID_VERSION] = -ENOPROTOOPT,
> + [EC_RES_INVALID_CHECKSUM] = -EBADMSG,
> + /*
> + * EC_RES_IN_PROGRESS is special because cros_ec_send_command() has extra logic to
> + * handle it. Note that default cros_kunit_ec_xfer_mock_default_ret == 0 thus
> + * cros_ec_xfer_command() in cros_ec_wait_until_complete() returns 0. As a result,
> + * it returns -EPROTO without calling cros_ec_map_error().
> + */
> + [EC_RES_IN_PROGRESS] = -EPROTO,
> + [EC_RES_UNAVAILABLE] = -ENODATA,
> + [EC_RES_TIMEOUT] = -ETIMEDOUT,
> + [EC_RES_OVERFLOW] = -EOVERFLOW,
> + [EC_RES_INVALID_HEADER] = -EBADR,
> + [EC_RES_REQUEST_TRUNCATED] = -EBADR,
> + [EC_RES_RESPONSE_TOO_BIG] = -EFBIG,
> + [EC_RES_BUS_ERROR] = -EFAULT,
> + [EC_RES_BUSY] = -EBUSY,
> + [EC_RES_INVALID_HEADER_VERSION] = -EBADMSG,
> + [EC_RES_INVALID_HEADER_CRC] = -EBADMSG,
> + [EC_RES_INVALID_DATA_CRC] = -EBADMSG,
> + [EC_RES_DUP_UNAVAILABLE] = -ENODATA,
> + };
> +
> + memset(&msg, 0, sizeof(msg));
> +
> + for (i = 0; i < ARRAY_SIZE(map); ++i) {
> + mock = cros_kunit_ec_xfer_mock_addx(test, 0, i, 0);
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> +
> + ret = cros_ec_cmd_xfer_status(ec_dev, &msg);
> + KUNIT_EXPECT_EQ(test, ret, map[i]);
> + }
> +}
> +
> static void cros_ec_proto_test_release(struct device *dev)
> {
> }
> @@ -2086,6 +2134,7 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
> KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_return0),
> KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_normal),
> KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_xfer_error),
> + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_return_error),
> {}
> };
>
> --
> 2.37.0.rc0.104.g0611611a94-goog
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/7] platform/chrome: cros_ec_proto: add Kunit tests for get_next_event
2022-06-22 4:10 ` [PATCH 3/7] platform/chrome: cros_ec_proto: add Kunit tests for get_next_event Tzung-Bi Shih
@ 2022-06-23 16:37 ` Guenter Roeck
0 siblings, 0 replies; 17+ messages in thread
From: Guenter Roeck @ 2022-06-23 16:37 UTC (permalink / raw)
To: Tzung-Bi Shih
Cc: Benson Leung, Guenter Roeck,
open list:CHROME HARDWARE PLATFORM SUPPORT, linux-kernel
On Tue, Jun 21, 2022 at 9:11 PM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> cros_ec_get_next_event() gets events from EC. It consists of 3
> versions of event retrieval:
>
> 1. No MKBP event.
> 2. MKBP event version 0.
> 3. MKBP event version >0.
>
> Add Kunit tests for cros_ec_get_next_event().
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
> ---
> drivers/platform/chrome/cros_ec_proto_test.c | 266 +++++++++++++++++++
> 1 file changed, 266 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
> index be3ac77abdf9..64c4b79f7a0c 100644
> --- a/drivers/platform/chrome/cros_ec_proto_test.c
> +++ b/drivers/platform/chrome/cros_ec_proto_test.c
> @@ -5,6 +5,7 @@
>
> #include <kunit/test.h>
>
> +#include <asm-generic/unaligned.h>
> #include <linux/platform_data/cros_ec_commands.h>
> #include <linux/platform_data/cros_ec_proto.h>
>
> @@ -2052,6 +2053,265 @@ static void cros_ec_proto_test_cmd_xfer_status_return_error(struct kunit *test)
> }
> }
>
> +static void cros_ec_proto_test_get_next_event_no_mkbp_event(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;
> + bool wake_event, more_events;
> +
> + ec_dev->max_request = 0xff;
> + ec_dev->max_response = 0xee;
> + ec_dev->mkbp_event_supported = 0;
> +
> + /* Set some garbage bytes. */
> + wake_event = false;
> + more_events = true;
> +
> + /* For get_keyboard_state_event(). */
> + {
> + union ec_response_get_next_data_v1 *data;
> +
> + mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> +
> + data = (union ec_response_get_next_data_v1 *)mock->o_data;
> + data->host_event = 0xbeef;
> + }
> +
> + ret = cros_ec_get_next_event(ec_dev, &wake_event, &more_events);
> + KUNIT_EXPECT_EQ(test, ret, sizeof(union ec_response_get_next_data_v1));
> +
> + KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_KEY_MATRIX);
> + KUNIT_EXPECT_EQ(test, ec_dev->event_data.data.host_event, 0xbeef);
> +
> + KUNIT_EXPECT_TRUE(test, wake_event);
> + KUNIT_EXPECT_FALSE(test, more_events);
> +
> + /* For get_keyboard_state_event(). */
> + {
> + 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_MKBP_STATE);
> + KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(union ec_response_get_next_data_v1));
> + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
> + }
> +}
> +
> +static void cros_ec_proto_test_get_next_event_mkbp_event_ec_suspended(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->mkbp_event_supported = 1;
> + ec_dev->suspended = true;
> +
> + ret = cros_ec_get_next_event(ec_dev, NULL, NULL);
> + KUNIT_EXPECT_EQ(test, ret, -EHOSTDOWN);
> +}
> +
> +static void cros_ec_proto_test_get_next_event_mkbp_event_version0(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;
> + bool wake_event, more_events;
> +
> + ec_dev->max_request = 0xff;
> + ec_dev->max_response = 0xee;
> + ec_dev->mkbp_event_supported = 1;
> +
> + /* Set some garbage bytes. */
> + wake_event = true;
> + more_events = false;
> +
> + /* For get_next_event_xfer(). */
> + {
> + struct ec_response_get_next_event *data;
> +
> + mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> +
> + data = (struct ec_response_get_next_event *)mock->o_data;
> + data->event_type = EC_MKBP_EVENT_SENSOR_FIFO | EC_MKBP_HAS_MORE_EVENTS;
> + data->data.sysrq = 0xbeef;
> + }
> +
> + ret = cros_ec_get_next_event(ec_dev, &wake_event, &more_events);
> + KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_next_event));
> +
> + KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_SENSOR_FIFO);
> + KUNIT_EXPECT_EQ(test, ec_dev->event_data.data.sysrq, 0xbeef);
> +
> + KUNIT_EXPECT_FALSE(test, wake_event);
> + KUNIT_EXPECT_TRUE(test, more_events);
> +
> + /* For get_next_event_xfer(). */
> + {
> + 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_NEXT_EVENT);
> + KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_get_next_event));
> + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
> + }
> +}
> +
> +static void cros_ec_proto_test_get_next_event_mkbp_event_version2(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;
> + bool wake_event, more_events;
> +
> + ec_dev->max_request = 0xff;
> + ec_dev->max_response = 0xee;
> + ec_dev->mkbp_event_supported = 3;
> +
> + /* Set some garbage bytes. */
> + wake_event = false;
> + more_events = true;
> +
> + /* For get_next_event_xfer(). */
> + {
> + struct ec_response_get_next_event_v1 *data;
> +
> + mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> +
> + data = (struct ec_response_get_next_event_v1 *)mock->o_data;
> + data->event_type = EC_MKBP_EVENT_FINGERPRINT;
> + data->data.sysrq = 0xbeef;
> + }
> +
> + ret = cros_ec_get_next_event(ec_dev, &wake_event, &more_events);
> + KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_next_event_v1));
> +
> + KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_FINGERPRINT);
> + KUNIT_EXPECT_EQ(test, ec_dev->event_data.data.sysrq, 0xbeef);
> +
> + KUNIT_EXPECT_TRUE(test, wake_event);
> + KUNIT_EXPECT_FALSE(test, more_events);
> +
> + /* For get_next_event_xfer(). */
> + {
> + mock = cros_kunit_ec_xfer_mock_next();
> + KUNIT_EXPECT_PTR_NE(test, mock, NULL);
> +
> + KUNIT_EXPECT_EQ(test, mock->msg.version, 2);
> + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_NEXT_EVENT);
> + KUNIT_EXPECT_EQ(test, mock->msg.insize,
> + sizeof(struct ec_response_get_next_event_v1));
> + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
> + }
> +}
> +
> +static void cros_ec_proto_test_get_next_event_mkbp_event_host_event_rtc(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;
> + bool wake_event;
> + struct ec_response_get_next_event_v1 *data;
> +
> + ec_dev->max_request = 0xff;
> + ec_dev->max_response = 0xee;
> + ec_dev->mkbp_event_supported = 3;
> + ec_dev->host_event_wake_mask = U32_MAX;
> +
> + /* Set some garbage bytes. */
> + wake_event = true;
> +
> + /* For get_next_event_xfer(). */
> + {
> + mock = cros_kunit_ec_xfer_mock_add(test,
> + sizeof(data->event_type) +
> + sizeof(data->data.host_event));
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> +
> + data = (struct ec_response_get_next_event_v1 *)mock->o_data;
> + data->event_type = EC_MKBP_EVENT_HOST_EVENT;
> + put_unaligned_le32(EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC), &data->data.host_event);
> + }
> +
> + ret = cros_ec_get_next_event(ec_dev, &wake_event, NULL);
> + KUNIT_EXPECT_EQ(test, ret, sizeof(data->event_type) + sizeof(data->data.host_event));
> +
> + KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_HOST_EVENT);
> +
> + KUNIT_EXPECT_FALSE(test, wake_event);
> +
> + /* For get_next_event_xfer(). */
> + {
> + mock = cros_kunit_ec_xfer_mock_next();
> + KUNIT_EXPECT_PTR_NE(test, mock, NULL);
> +
> + KUNIT_EXPECT_EQ(test, mock->msg.version, 2);
> + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_NEXT_EVENT);
> + KUNIT_EXPECT_EQ(test, mock->msg.insize,
> + sizeof(struct ec_response_get_next_event_v1));
> + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
> + }
> +}
> +
> +static void cros_ec_proto_test_get_next_event_mkbp_event_host_event_masked(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;
> + bool wake_event;
> + struct ec_response_get_next_event_v1 *data;
> +
> + ec_dev->max_request = 0xff;
> + ec_dev->max_response = 0xee;
> + ec_dev->mkbp_event_supported = 3;
> + ec_dev->host_event_wake_mask = U32_MAX & ~EC_HOST_EVENT_MASK(EC_HOST_EVENT_AC_DISCONNECTED);
> +
> + /* Set some garbage bytes. */
> + wake_event = true;
> +
> + /* For get_next_event_xfer(). */
> + {
> + mock = cros_kunit_ec_xfer_mock_add(test,
> + sizeof(data->event_type) +
> + sizeof(data->data.host_event));
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> +
> + data = (struct ec_response_get_next_event_v1 *)mock->o_data;
> + data->event_type = EC_MKBP_EVENT_HOST_EVENT;
> + put_unaligned_le32(EC_HOST_EVENT_MASK(EC_HOST_EVENT_AC_DISCONNECTED),
> + &data->data.host_event);
> + }
> +
> + ret = cros_ec_get_next_event(ec_dev, &wake_event, NULL);
> + KUNIT_EXPECT_EQ(test, ret, sizeof(data->event_type) + sizeof(data->data.host_event));
> +
> + KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_HOST_EVENT);
> +
> + KUNIT_EXPECT_FALSE(test, wake_event);
> +
> + /* For get_next_event_xfer(). */
> + {
> + mock = cros_kunit_ec_xfer_mock_next();
> + KUNIT_EXPECT_PTR_NE(test, mock, NULL);
> +
> + KUNIT_EXPECT_EQ(test, mock->msg.version, 2);
> + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_NEXT_EVENT);
> + KUNIT_EXPECT_EQ(test, mock->msg.insize,
> + sizeof(struct ec_response_get_next_event_v1));
> + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
> + }
> +}
> +
> static void cros_ec_proto_test_release(struct device *dev)
> {
> }
> @@ -2135,6 +2395,12 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
> KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_normal),
> KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_xfer_error),
> KUNIT_CASE(cros_ec_proto_test_cmd_xfer_status_return_error),
> + KUNIT_CASE(cros_ec_proto_test_get_next_event_no_mkbp_event),
> + KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_ec_suspended),
> + KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_version0),
> + KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_version2),
> + KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_host_event_rtc),
> + KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_host_event_masked),
> {}
> };
>
> --
> 2.37.0.rc0.104.g0611611a94-goog
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 4/7] platform/chrome: cros_ec_proto: add Kunit tests for get_host_event
2022-06-22 4:10 ` [PATCH 4/7] platform/chrome: cros_ec_proto: add Kunit tests for get_host_event Tzung-Bi Shih
@ 2022-06-23 16:38 ` Guenter Roeck
0 siblings, 0 replies; 17+ messages in thread
From: Guenter Roeck @ 2022-06-23 16:38 UTC (permalink / raw)
To: Tzung-Bi Shih
Cc: Benson Leung, Guenter Roeck,
open list:CHROME HARDWARE PLATFORM SUPPORT, linux-kernel
On Tue, Jun 21, 2022 at 9:11 PM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> cros_ec_get_host_event() performs some sanity checks, parses
> `ec_dev->event_data.data.host_event`, and returns bitmap of
> EC_HOST_EVENT_*.
>
> Add Kunit tests for cros_ec_get_host_event().
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
> ---
> drivers/platform/chrome/cros_ec_proto_test.c | 59 ++++++++++++++++++++
> 1 file changed, 59 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
> index 64c4b79f7a0c..dce9fa3b9c8d 100644
> --- a/drivers/platform/chrome/cros_ec_proto_test.c
> +++ b/drivers/platform/chrome/cros_ec_proto_test.c
> @@ -2312,6 +2312,61 @@ static void cros_ec_proto_test_get_next_event_mkbp_event_host_event_masked(struc
> }
> }
>
> +static void cros_ec_proto_test_get_host_event_no_mkbp_event(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->mkbp_event_supported = 0;
> +
> + ret = cros_ec_get_host_event(ec_dev);
> + KUNIT_EXPECT_EQ(test, ret, 0);
> +}
> +
> +static void cros_ec_proto_test_get_host_event_not_host_event(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->mkbp_event_supported = 1;
> + ec_dev->event_data.event_type = EC_MKBP_EVENT_FINGERPRINT;
> +
> + ret = cros_ec_get_host_event(ec_dev);
> + KUNIT_EXPECT_EQ(test, ret, 0);
> +}
> +
> +static void cros_ec_proto_test_get_host_event_wrong_event_size(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->mkbp_event_supported = 1;
> + ec_dev->event_data.event_type = EC_MKBP_EVENT_HOST_EVENT;
> + ec_dev->event_size = 0xff;
> +
> + ret = cros_ec_get_host_event(ec_dev);
> + KUNIT_EXPECT_EQ(test, ret, 0);
> +}
> +
> +static void cros_ec_proto_test_get_host_event_normal(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->mkbp_event_supported = 1;
> + ec_dev->event_data.event_type = EC_MKBP_EVENT_HOST_EVENT;
> + ec_dev->event_size = sizeof(ec_dev->event_data.data.host_event);
> + put_unaligned_le32(EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC),
> + &ec_dev->event_data.data.host_event);
> +
> + ret = cros_ec_get_host_event(ec_dev);
> + KUNIT_EXPECT_EQ(test, ret, EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC));
> +}
> +
> static void cros_ec_proto_test_release(struct device *dev)
> {
> }
> @@ -2401,6 +2456,10 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
> KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_version2),
> KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_host_event_rtc),
> KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_host_event_masked),
> + KUNIT_CASE(cros_ec_proto_test_get_host_event_no_mkbp_event),
> + KUNIT_CASE(cros_ec_proto_test_get_host_event_not_host_event),
> + KUNIT_CASE(cros_ec_proto_test_get_host_event_wrong_event_size),
> + KUNIT_CASE(cros_ec_proto_test_get_host_event_normal),
> {}
> };
>
> --
> 2.37.0.rc0.104.g0611611a94-goog
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 5/7] platform/chrome: cros_ec_proto: add Kunit tests for check_features
2022-06-22 4:10 ` [PATCH 5/7] platform/chrome: cros_ec_proto: add Kunit tests for check_features Tzung-Bi Shih
@ 2022-06-23 16:38 ` Guenter Roeck
0 siblings, 0 replies; 17+ messages in thread
From: Guenter Roeck @ 2022-06-23 16:38 UTC (permalink / raw)
To: Tzung-Bi Shih
Cc: Benson Leung, Guenter Roeck,
open list:CHROME HARDWARE PLATFORM SUPPORT, linux-kernel
On Tue, Jun 21, 2022 at 9:11 PM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> cros_ec_check_features() gets EC features if it hasn't had cache, and
> checks whether the given EC_FEATURE_* is supported or not.
>
> Add Kunit tests for cros_ec_check_features().
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
> ---
> drivers/platform/chrome/cros_ec_proto_test.c | 77 ++++++++++++++++++++
> 1 file changed, 77 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
> index dce9fa3b9c8d..93c1700deaef 100644
> --- a/drivers/platform/chrome/cros_ec_proto_test.c
> +++ b/drivers/platform/chrome/cros_ec_proto_test.c
> @@ -2367,6 +2367,81 @@ static void cros_ec_proto_test_get_host_event_normal(struct kunit *test)
> KUNIT_EXPECT_EQ(test, ret, EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC));
> }
>
> +static void cros_ec_proto_test_check_features_cached(struct kunit *test)
> +{
> + int ret, i;
> + struct cros_ec_dev ec;
> +
> + ec.features.flags[0] = EC_FEATURE_MASK_0(EC_FEATURE_FINGERPRINT);
> + ec.features.flags[1] = EC_FEATURE_MASK_0(EC_FEATURE_SCP);
> +
> + for (i = 0; i < EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK; ++i) {
> + ret = cros_ec_check_features(&ec, i);
> + switch (i) {
> + case EC_FEATURE_FINGERPRINT:
> + case EC_FEATURE_SCP:
> + KUNIT_EXPECT_TRUE(test, ret);
> + break;
> + default:
> + KUNIT_EXPECT_FALSE(test, ret);
> + break;
> + }
> + }
> +}
> +
> +static void cros_ec_proto_test_check_features_not_cached(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, i;
> + struct cros_ec_dev ec;
> +
> + ec_dev->max_request = 0xff;
> + ec_dev->max_response = 0xee;
> + ec.ec_dev = ec_dev;
> + ec.dev = ec_dev->dev;
> + ec.cmd_offset = 0;
> + ec.features.flags[0] = -1;
> + ec.features.flags[1] = -1;
> +
> + /* For EC_CMD_GET_FEATURES. */
> + {
> + struct ec_response_get_features *data;
> +
> + mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> +
> + data = (struct ec_response_get_features *)mock->o_data;
> + data->flags[0] = EC_FEATURE_MASK_0(EC_FEATURE_FINGERPRINT);
> + data->flags[1] = EC_FEATURE_MASK_0(EC_FEATURE_SCP);
> + }
> +
> + for (i = 0; i < EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK; ++i) {
> + ret = cros_ec_check_features(&ec, i);
> + switch (i) {
> + case EC_FEATURE_FINGERPRINT:
> + case EC_FEATURE_SCP:
> + KUNIT_EXPECT_TRUE(test, ret);
> + break;
> + default:
> + KUNIT_EXPECT_FALSE(test, ret);
> + break;
> + }
> + }
> +
> + /* For EC_CMD_GET_FEATURES. */
> + {
> + 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_FEATURES);
> + KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_get_features));
> + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
> + }
> +}
> +
> static void cros_ec_proto_test_release(struct device *dev)
> {
> }
> @@ -2460,6 +2535,8 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
> KUNIT_CASE(cros_ec_proto_test_get_host_event_not_host_event),
> KUNIT_CASE(cros_ec_proto_test_get_host_event_wrong_event_size),
> KUNIT_CASE(cros_ec_proto_test_get_host_event_normal),
> + KUNIT_CASE(cros_ec_proto_test_check_features_cached),
> + KUNIT_CASE(cros_ec_proto_test_check_features_not_cached),
> {}
> };
>
> --
> 2.37.0.rc0.104.g0611611a94-goog
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 6/7] platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count
2022-06-22 4:10 ` [PATCH 6/7] platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count Tzung-Bi Shih
@ 2022-06-23 16:39 ` Guenter Roeck
0 siblings, 0 replies; 17+ messages in thread
From: Guenter Roeck @ 2022-06-23 16:39 UTC (permalink / raw)
To: Tzung-Bi Shih
Cc: Benson Leung, Guenter Roeck,
open list:CHROME HARDWARE PLATFORM SUPPORT, linux-kernel
On Tue, Jun 21, 2022 at 9:11 PM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> cros_ec_get_sensor_count() gets number of MEMS sensors.
>
> Add Kunit tests for cros_ec_get_sensor_count().
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
> ---
> drivers/platform/chrome/cros_ec_proto_test.c | 153 +++++++++++++++++++
> drivers/platform/chrome/cros_kunit_util.c | 22 +++
> drivers/platform/chrome/cros_kunit_util.h | 7 +
> 3 files changed, 182 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
> index 93c1700deaef..6b26ce3104f4 100644
> --- a/drivers/platform/chrome/cros_ec_proto_test.c
> +++ b/drivers/platform/chrome/cros_ec_proto_test.c
> @@ -2442,6 +2442,156 @@ static void cros_ec_proto_test_check_features_not_cached(struct kunit *test)
> }
> }
>
> +static void cros_ec_proto_test_get_sensor_count_normal(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;
> + struct cros_ec_dev ec;
> +
> + ec_dev->max_request = 0xff;
> + ec_dev->max_response = 0xee;
> + ec.ec_dev = ec_dev;
> + ec.dev = ec_dev->dev;
> + ec.cmd_offset = 0;
> +
> + /* For EC_CMD_MOTION_SENSE_CMD. */
> + {
> + struct ec_response_motion_sense *data;
> +
> + mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> +
> + data = (struct ec_response_motion_sense *)mock->o_data;
> + data->dump.sensor_count = 0xbf;
> + }
> +
> + ret = cros_ec_get_sensor_count(&ec);
> + KUNIT_EXPECT_EQ(test, ret, 0xbf);
> +
> + /* For EC_CMD_MOTION_SENSE_CMD. */
> + {
> + struct ec_params_motion_sense *data;
> +
> + mock = cros_kunit_ec_xfer_mock_next();
> + KUNIT_EXPECT_PTR_NE(test, mock, NULL);
> +
> + KUNIT_EXPECT_EQ(test, mock->msg.version, 1);
> + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_MOTION_SENSE_CMD);
> + KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_motion_sense));
> + KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(*data));
> +
> + data = (struct ec_params_motion_sense *)mock->i_data;
> + KUNIT_EXPECT_EQ(test, data->cmd, MOTIONSENSE_CMD_DUMP);
> + }
> +}
> +
> +static void cros_ec_proto_test_get_sensor_count_xfer_error(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;
> + struct cros_ec_dev ec;
> +
> + ec_dev->max_request = 0xff;
> + ec_dev->max_response = 0xee;
> + ec.ec_dev = ec_dev;
> + ec.dev = ec_dev->dev;
> + ec.cmd_offset = 0;
> +
> + /* For EC_CMD_MOTION_SENSE_CMD. */
> + {
> + mock = cros_kunit_ec_xfer_mock_addx(test, -EPROTO, EC_RES_SUCCESS, 0);
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> + }
> +
> + ret = cros_ec_get_sensor_count(&ec);
> + KUNIT_EXPECT_EQ(test, ret, -EPROTO);
> +
> + /* For EC_CMD_MOTION_SENSE_CMD. */
> + {
> + struct ec_params_motion_sense *data;
> +
> + mock = cros_kunit_ec_xfer_mock_next();
> + KUNIT_EXPECT_PTR_NE(test, mock, NULL);
> +
> + KUNIT_EXPECT_EQ(test, mock->msg.version, 1);
> + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_MOTION_SENSE_CMD);
> + KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_motion_sense));
> + KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(*data));
> +
> + data = (struct ec_params_motion_sense *)mock->i_data;
> + KUNIT_EXPECT_EQ(test, data->cmd, MOTIONSENSE_CMD_DUMP);
> + }
> +}
> +
> +static void cros_ec_proto_test_get_sensor_count_legacy(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, i;
> + struct cros_ec_dev ec;
> + struct {
> + u8 readmem_data;
> + int expected_result;
> + } test_data[] = {
> + { 0, 0 },
> + { EC_MEMMAP_ACC_STATUS_PRESENCE_BIT, 2 },
> + };
> +
> + ec_dev->max_request = 0xff;
> + ec_dev->max_response = 0xee;
> + ec_dev->cmd_readmem = cros_kunit_readmem_mock;
> + ec.ec_dev = ec_dev;
> + ec.dev = ec_dev->dev;
> + ec.cmd_offset = 0;
> +
> + for (i = 0; i < ARRAY_SIZE(test_data); ++i) {
> + /* For EC_CMD_MOTION_SENSE_CMD. */
> + {
> + mock = cros_kunit_ec_xfer_mock_addx(test, -EPROTO, EC_RES_SUCCESS, 0);
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> + }
> +
> + /* For readmem. */
> + {
> + cros_kunit_readmem_mock_data = kunit_kzalloc(test, 1, GFP_KERNEL);
> + KUNIT_ASSERT_PTR_NE(test, cros_kunit_readmem_mock_data, NULL);
> + cros_kunit_readmem_mock_data[0] = test_data[i].readmem_data;
> +
> + cros_kunit_ec_xfer_mock_default_ret = 1;
> + }
> +
> + ret = cros_ec_get_sensor_count(&ec);
> + KUNIT_EXPECT_EQ(test, ret, test_data[i].expected_result);
> +
> + /* For EC_CMD_MOTION_SENSE_CMD. */
> + {
> + struct ec_params_motion_sense *data;
> +
> + mock = cros_kunit_ec_xfer_mock_next();
> + KUNIT_EXPECT_PTR_NE(test, mock, NULL);
> +
> + KUNIT_EXPECT_EQ(test, mock->msg.version, 1);
> + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_MOTION_SENSE_CMD);
> + KUNIT_EXPECT_EQ(test, mock->msg.insize,
> + sizeof(struct ec_response_motion_sense));
> + KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(*data));
> +
> + data = (struct ec_params_motion_sense *)mock->i_data;
> + KUNIT_EXPECT_EQ(test, data->cmd, MOTIONSENSE_CMD_DUMP);
> + }
> +
> + /* For readmem. */
> + {
> + KUNIT_EXPECT_EQ(test, cros_kunit_readmem_mock_offset, EC_MEMMAP_ACC_STATUS);
> + }
> + }
> +}
> +
> static void cros_ec_proto_test_release(struct device *dev)
> {
> }
> @@ -2537,6 +2687,9 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
> KUNIT_CASE(cros_ec_proto_test_get_host_event_normal),
> KUNIT_CASE(cros_ec_proto_test_check_features_cached),
> KUNIT_CASE(cros_ec_proto_test_check_features_not_cached),
> + KUNIT_CASE(cros_ec_proto_test_get_sensor_count_normal),
> + KUNIT_CASE(cros_ec_proto_test_get_sensor_count_xfer_error),
> + KUNIT_CASE(cros_ec_proto_test_get_sensor_count_legacy),
> {}
> };
>
> diff --git a/drivers/platform/chrome/cros_kunit_util.c b/drivers/platform/chrome/cros_kunit_util.c
> index 3ede971e82ee..d37c334b416d 100644
> --- a/drivers/platform/chrome/cros_kunit_util.c
> +++ b/drivers/platform/chrome/cros_kunit_util.c
> @@ -105,6 +105,24 @@ struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void)
> }
> EXPORT_SYMBOL_GPL(cros_kunit_ec_xfer_mock_next);
>
> +int cros_kunit_readmem_mock_offset;
> +EXPORT_SYMBOL_GPL(cros_kunit_readmem_mock_offset);
> +u8 *cros_kunit_readmem_mock_data;
> +EXPORT_SYMBOL_GPL(cros_kunit_readmem_mock_data);
> +int cros_kunit_readmem_mock_ret;
> +EXPORT_SYMBOL_GPL(cros_kunit_readmem_mock_ret);
> +
> +int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset,
> + unsigned int bytes, void *dest)
> +{
> + cros_kunit_readmem_mock_offset = offset;
> +
> + memcpy(dest, cros_kunit_readmem_mock_data, bytes);
> +
> + return cros_kunit_readmem_mock_ret;
> +}
> +EXPORT_SYMBOL_GPL(cros_kunit_readmem_mock);
> +
> void cros_kunit_mock_reset(void)
> {
> cros_kunit_ec_xfer_mock_default_ret = 0;
> @@ -112,6 +130,10 @@ void cros_kunit_mock_reset(void)
> cros_kunit_ec_pkt_xfer_mock_called = 0;
> INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_in);
> INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_out);
> +
> + cros_kunit_readmem_mock_offset = 0;
> + cros_kunit_readmem_mock_data = NULL;
> + cros_kunit_readmem_mock_ret = 0;
> }
> EXPORT_SYMBOL_GPL(cros_kunit_mock_reset);
>
> diff --git a/drivers/platform/chrome/cros_kunit_util.h b/drivers/platform/chrome/cros_kunit_util.h
> index ae4080cb13f1..88134c9f1acf 100644
> --- a/drivers/platform/chrome/cros_kunit_util.h
> +++ b/drivers/platform/chrome/cros_kunit_util.h
> @@ -35,6 +35,13 @@ struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test,
> int ret, int result, size_t size);
> struct ec_xfer_mock *cros_kunit_ec_xfer_mock_next(void);
>
> +extern int cros_kunit_readmem_mock_offset;
> +extern u8 *cros_kunit_readmem_mock_data;
> +extern int cros_kunit_readmem_mock_ret;
> +
> +int cros_kunit_readmem_mock(struct cros_ec_device *ec_dev, unsigned int offset,
> + unsigned int bytes, void *dest);
> +
> void cros_kunit_mock_reset(void);
>
> #endif
> --
> 2.37.0.rc0.104.g0611611a94-goog
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 7/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd()
2022-06-22 4:10 ` [PATCH 7/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd() Tzung-Bi Shih
@ 2022-06-23 16:40 ` Guenter Roeck
0 siblings, 0 replies; 17+ messages in thread
From: Guenter Roeck @ 2022-06-23 16:40 UTC (permalink / raw)
To: Tzung-Bi Shih
Cc: Benson Leung, Guenter Roeck,
open list:CHROME HARDWARE PLATFORM SUPPORT, linux-kernel
On Tue, Jun 21, 2022 at 9:11 PM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> cros_ec_cmd() is a wrapper of cros_ec_cmd_xfer_status().
>
> Add Kunit test for cros_ec_cmd().
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
> ---
> drivers/platform/chrome/cros_ec_proto_test.c | 48 ++++++++++++++++++++
> 1 file changed, 48 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c
> index 6b26ce3104f4..2ff2783fedfb 100644
> --- a/drivers/platform/chrome/cros_ec_proto_test.c
> +++ b/drivers/platform/chrome/cros_ec_proto_test.c
> @@ -2592,6 +2592,53 @@ static void cros_ec_proto_test_get_sensor_count_legacy(struct kunit *test)
> }
> }
>
> +static void cros_ec_proto_test_ec_cmd(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;
> + u8 out[3], in[2];
> +
> + ec_dev->max_request = 0xff;
> + ec_dev->max_response = 0xee;
> +
> + out[0] = 0xdd;
> + out[1] = 0xcc;
> + out[2] = 0xbb;
> +
> + {
> + u8 *data;
> +
> + mock = cros_kunit_ec_xfer_mock_add(test, 2);
> + KUNIT_ASSERT_PTR_NE(test, mock, NULL);
> +
> + data = (u8 *)mock->o_data;
> + data[0] = 0xaa;
> + data[1] = 0x99;
> + }
> +
> + ret = cros_ec_cmd(ec_dev, 0x88, 0x77, out, ARRAY_SIZE(out), in, ARRAY_SIZE(in));
> + KUNIT_EXPECT_EQ(test, ret, 2);
> +
> + {
> + u8 *data;
> +
> + mock = cros_kunit_ec_xfer_mock_next();
> + KUNIT_EXPECT_PTR_NE(test, mock, NULL);
> +
> + KUNIT_EXPECT_EQ(test, mock->msg.version, 0x88);
> + KUNIT_EXPECT_EQ(test, mock->msg.command, 0x77);
> + KUNIT_EXPECT_EQ(test, mock->msg.insize, ARRAY_SIZE(in));
> + KUNIT_EXPECT_EQ(test, mock->msg.outsize, ARRAY_SIZE(out));
> +
> + data = (u8 *)mock->i_data;
> + KUNIT_EXPECT_EQ(test, data[0], 0xdd);
> + KUNIT_EXPECT_EQ(test, data[1], 0xcc);
> + KUNIT_EXPECT_EQ(test, data[2], 0xbb);
> + }
> +}
> +
> static void cros_ec_proto_test_release(struct device *dev)
> {
> }
> @@ -2690,6 +2737,7 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
> KUNIT_CASE(cros_ec_proto_test_get_sensor_count_normal),
> KUNIT_CASE(cros_ec_proto_test_get_sensor_count_xfer_error),
> KUNIT_CASE(cros_ec_proto_test_get_sensor_count_legacy),
> + KUNIT_CASE(cros_ec_proto_test_ec_cmd),
> {}
> };
>
> --
> 2.37.0.rc0.104.g0611611a94-goog
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests
2022-06-22 4:10 [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests Tzung-Bi Shih
` (6 preceding siblings ...)
2022-06-22 4:10 ` [PATCH 7/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd() Tzung-Bi Shih
@ 2022-07-20 1:30 ` patchwork-bot+chrome-platform
2022-07-21 8:50 ` patchwork-bot+chrome-platform
8 siblings, 0 replies; 17+ messages in thread
From: patchwork-bot+chrome-platform @ 2022-07-20 1:30 UTC (permalink / raw)
To: Tzung-Bi Shih; +Cc: bleung, groeck, chrome-platform, linux-kernel
Hello:
This series was applied to chrome-platform/linux.git (for-kernelci)
by Tzung-Bi Shih <tzungbi@kernel.org>:
On Wed, 22 Jun 2022 04:10:33 +0000 you wrote:
> The series add Kunit tests for the rest of exported functions.
>
> The series applies after
> https://patchwork.kernel.org/project/chrome-platform/cover/20220615051248.1628156-1-tzungbi@kernel.org/.
>
> Tzung-Bi Shih (7):
> platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status
> platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error()
> platform/chrome: cros_ec_proto: add Kunit tests for get_next_event
> platform/chrome: cros_ec_proto: add Kunit tests for get_host_event
> platform/chrome: cros_ec_proto: add Kunit tests for check_features
> platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count
> platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd()
>
> [...]
Here is the summary with links:
- [1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status
https://git.kernel.org/chrome-platform/c/74bed42fd5fa
- [2/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error()
https://git.kernel.org/chrome-platform/c/1242688fc2f0
- [3/7] platform/chrome: cros_ec_proto: add Kunit tests for get_next_event
https://git.kernel.org/chrome-platform/c/2b7ed927953f
- [4/7] platform/chrome: cros_ec_proto: add Kunit tests for get_host_event
https://git.kernel.org/chrome-platform/c/7cb1eb82642b
- [5/7] platform/chrome: cros_ec_proto: add Kunit tests for check_features
https://git.kernel.org/chrome-platform/c/00238864435f
- [6/7] platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count
https://git.kernel.org/chrome-platform/c/33f0fdba6066
- [7/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd()
https://git.kernel.org/chrome-platform/c/9399b2cb2070
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] 17+ messages in thread
* Re: [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests
2022-06-22 4:10 [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests Tzung-Bi Shih
` (7 preceding siblings ...)
2022-07-20 1:30 ` [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests patchwork-bot+chrome-platform
@ 2022-07-21 8:50 ` patchwork-bot+chrome-platform
8 siblings, 0 replies; 17+ messages in thread
From: patchwork-bot+chrome-platform @ 2022-07-21 8:50 UTC (permalink / raw)
To: Tzung-Bi Shih; +Cc: bleung, groeck, chrome-platform, linux-kernel
Hello:
This series was applied to chrome-platform/linux.git (for-next)
by Tzung-Bi Shih <tzungbi@kernel.org>:
On Wed, 22 Jun 2022 04:10:33 +0000 you wrote:
> The series add Kunit tests for the rest of exported functions.
>
> The series applies after
> https://patchwork.kernel.org/project/chrome-platform/cover/20220615051248.1628156-1-tzungbi@kernel.org/.
>
> Tzung-Bi Shih (7):
> platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status
> platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error()
> platform/chrome: cros_ec_proto: add Kunit tests for get_next_event
> platform/chrome: cros_ec_proto: add Kunit tests for get_host_event
> platform/chrome: cros_ec_proto: add Kunit tests for check_features
> platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count
> platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd()
>
> [...]
Here is the summary with links:
- [1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status
https://git.kernel.org/chrome-platform/c/74bed42fd5fa
- [2/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error()
https://git.kernel.org/chrome-platform/c/1242688fc2f0
- [3/7] platform/chrome: cros_ec_proto: add Kunit tests for get_next_event
https://git.kernel.org/chrome-platform/c/2b7ed927953f
- [4/7] platform/chrome: cros_ec_proto: add Kunit tests for get_host_event
https://git.kernel.org/chrome-platform/c/7cb1eb82642b
- [5/7] platform/chrome: cros_ec_proto: add Kunit tests for check_features
https://git.kernel.org/chrome-platform/c/00238864435f
- [6/7] platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count
https://git.kernel.org/chrome-platform/c/33f0fdba6066
- [7/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd()
https://git.kernel.org/chrome-platform/c/9399b2cb2070
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] 17+ messages in thread
end of thread, other threads:[~2022-07-21 8:50 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22 4:10 [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests Tzung-Bi Shih
2022-06-22 4:10 ` [PATCH 1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status Tzung-Bi Shih
2022-06-23 16:36 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 2/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_map_error() Tzung-Bi Shih
2022-06-23 16:36 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 3/7] platform/chrome: cros_ec_proto: add Kunit tests for get_next_event Tzung-Bi Shih
2022-06-23 16:37 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 4/7] platform/chrome: cros_ec_proto: add Kunit tests for get_host_event Tzung-Bi Shih
2022-06-23 16:38 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 5/7] platform/chrome: cros_ec_proto: add Kunit tests for check_features Tzung-Bi Shih
2022-06-23 16:38 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 6/7] platform/chrome: cros_ec_proto: add Kunit tests for get_sensor_count Tzung-Bi Shih
2022-06-23 16:39 ` Guenter Roeck
2022-06-22 4:10 ` [PATCH 7/7] platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd() Tzung-Bi Shih
2022-06-23 16:40 ` Guenter Roeck
2022-07-20 1:30 ` [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests patchwork-bot+chrome-platform
2022-07-21 8:50 ` 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.