Skip to content

Commit 9399b2c

Browse files
author
Tzung-Bi Shih
committed
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
1 parent 33f0fdb commit 9399b2c

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

drivers/platform/chrome/cros_ec_proto_test.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,6 +2592,53 @@ static void cros_ec_proto_test_get_sensor_count_legacy(struct kunit *test)
25922592
}
25932593
}
25942594

2595+
static void cros_ec_proto_test_ec_cmd(struct kunit *test)
2596+
{
2597+
struct cros_ec_proto_test_priv *priv = test->priv;
2598+
struct cros_ec_device *ec_dev = &priv->ec_dev;
2599+
struct ec_xfer_mock *mock;
2600+
int ret;
2601+
u8 out[3], in[2];
2602+
2603+
ec_dev->max_request = 0xff;
2604+
ec_dev->max_response = 0xee;
2605+
2606+
out[0] = 0xdd;
2607+
out[1] = 0xcc;
2608+
out[2] = 0xbb;
2609+
2610+
{
2611+
u8 *data;
2612+
2613+
mock = cros_kunit_ec_xfer_mock_add(test, 2);
2614+
KUNIT_ASSERT_PTR_NE(test, mock, NULL);
2615+
2616+
data = (u8 *)mock->o_data;
2617+
data[0] = 0xaa;
2618+
data[1] = 0x99;
2619+
}
2620+
2621+
ret = cros_ec_cmd(ec_dev, 0x88, 0x77, out, ARRAY_SIZE(out), in, ARRAY_SIZE(in));
2622+
KUNIT_EXPECT_EQ(test, ret, 2);
2623+
2624+
{
2625+
u8 *data;
2626+
2627+
mock = cros_kunit_ec_xfer_mock_next();
2628+
KUNIT_EXPECT_PTR_NE(test, mock, NULL);
2629+
2630+
KUNIT_EXPECT_EQ(test, mock->msg.version, 0x88);
2631+
KUNIT_EXPECT_EQ(test, mock->msg.command, 0x77);
2632+
KUNIT_EXPECT_EQ(test, mock->msg.insize, ARRAY_SIZE(in));
2633+
KUNIT_EXPECT_EQ(test, mock->msg.outsize, ARRAY_SIZE(out));
2634+
2635+
data = (u8 *)mock->i_data;
2636+
KUNIT_EXPECT_EQ(test, data[0], 0xdd);
2637+
KUNIT_EXPECT_EQ(test, data[1], 0xcc);
2638+
KUNIT_EXPECT_EQ(test, data[2], 0xbb);
2639+
}
2640+
}
2641+
25952642
static void cros_ec_proto_test_release(struct device *dev)
25962643
{
25972644
}
@@ -2690,6 +2737,7 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
26902737
KUNIT_CASE(cros_ec_proto_test_get_sensor_count_normal),
26912738
KUNIT_CASE(cros_ec_proto_test_get_sensor_count_xfer_error),
26922739
KUNIT_CASE(cros_ec_proto_test_get_sensor_count_legacy),
2740+
KUNIT_CASE(cros_ec_proto_test_ec_cmd),
26932741
{}
26942742
};
26952743

0 commit comments

Comments
 (0)