platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result()
authorTzung-Bi Shih <tzungbi@kernel.org>
Wed, 18 May 2022 09:18:14 +0000 (17:18 +0800)
committerTzung-Bi Shih <tzungbi@kernel.org>
Mon, 6 Jun 2022 03:11:37 +0000 (03:11 +0000)
cros_ec_check_result() is used to check if the EC communication success but
EC responded EC_RES_IN_PROGRESS.  It should return 0 even if EC wasn't
happy about the host command.

Add Kunit tests for cros_ec_check_result().

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
Link: https://lore.kernel.org/r/20220518091814.2028579-5-tzungbi@kernel.org
drivers/platform/chrome/cros_ec_proto_test.c

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