diff options
author | Tzung-Bi Shih <tzungbi@kernel.org> | 2022-06-22 07:10:40 +0300 |
---|---|---|
committer | Tzung-Bi Shih <tzungbi@kernel.org> | 2022-07-20 04:22:59 +0300 |
commit | 9399b2cb20702fde2a5f9c6aec9cd70d21d40a00 (patch) | |
tree | 3b36b7bb50284f06347d9f84d99f4e89ad1947ea /drivers/platform/chrome | |
parent | 33f0fdba6066b504ee0b5f1480b1f93b06050df6 (diff) | |
download | linux-9399b2cb20702fde2a5f9c6aec9cd70d21d40a00.tar.xz |
platform/chrome: cros_ec_proto: add Kunit test for cros_ec_cmd()
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>
Link: https://lore.kernel.org/r/20220622041040.202737-8-tzungbi@kernel.org
Diffstat (limited to 'drivers/platform/chrome')
-rw-r--r-- | drivers/platform/chrome/cros_ec_proto_test.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c index 7e6c606a5fda..c6a83df91ae1 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), {} }; |