2022-06-22 04:29:37

by Tzung-Bi Shih

[permalink] [raw]
Subject: [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests

The series add Kunit tests for the rest of exported functions.

The series applies after
https://patchwork.kernel.org/project/chrome-platform/cover/[email protected]/.

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


2022-06-22 04:53:53

by Tzung-Bi Shih

[permalink] [raw]
Subject: [PATCH 4/7] platform/chrome: cros_ec_proto: add Kunit tests for get_host_event

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 <[email protected]>
---
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

2022-06-22 04:54:26

by Tzung-Bi Shih

[permalink] [raw]
Subject: [PATCH 1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status

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 <[email protected]>
---
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

2022-06-23 16:47:41

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 1/7] platform/chrome: cros_ec_proto: add Kunit tests for cmd_xfer_status

On Tue, Jun 21, 2022 at 9:11 PM Tzung-Bi Shih <[email protected]> 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 <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
> 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
>

2022-06-23 16:48:13

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 4/7] platform/chrome: cros_ec_proto: add Kunit tests for get_host_event

On Tue, Jun 21, 2022 at 9:11 PM Tzung-Bi Shih <[email protected]> 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 <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
> 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
>

Subject: Re: [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests

Hello:

This series was applied to chrome-platform/linux.git (for-kernelci)
by Tzung-Bi Shih <[email protected]>:

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/[email protected]/.
>
> 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


Subject: Re: [PATCH 0/7] platform/chrome: cros_ec_proto: add Kunit tests

Hello:

This series was applied to chrome-platform/linux.git (for-next)
by Tzung-Bi Shih <[email protected]>:

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/[email protected]/.
>
> 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