Skip to content

Commit 7cb1eb8

Browse files
author
Tzung-Bi Shih
committed
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 <tzungbi@kernel.org> Reviewed-by: Guenter Roeck <groeck@chromium.org> Link: https://lore.kernel.org/r/20220622041040.202737-5-tzungbi@kernel.org
1 parent 2b7ed92 commit 7cb1eb8

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

drivers/platform/chrome/cros_ec_proto_test.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,61 @@ static void cros_ec_proto_test_get_next_event_mkbp_event_host_event_masked(struc
23122312
}
23132313
}
23142314

2315+
static void cros_ec_proto_test_get_host_event_no_mkbp_event(struct kunit *test)
2316+
{
2317+
struct cros_ec_proto_test_priv *priv = test->priv;
2318+
struct cros_ec_device *ec_dev = &priv->ec_dev;
2319+
int ret;
2320+
2321+
ec_dev->mkbp_event_supported = 0;
2322+
2323+
ret = cros_ec_get_host_event(ec_dev);
2324+
KUNIT_EXPECT_EQ(test, ret, 0);
2325+
}
2326+
2327+
static void cros_ec_proto_test_get_host_event_not_host_event(struct kunit *test)
2328+
{
2329+
struct cros_ec_proto_test_priv *priv = test->priv;
2330+
struct cros_ec_device *ec_dev = &priv->ec_dev;
2331+
int ret;
2332+
2333+
ec_dev->mkbp_event_supported = 1;
2334+
ec_dev->event_data.event_type = EC_MKBP_EVENT_FINGERPRINT;
2335+
2336+
ret = cros_ec_get_host_event(ec_dev);
2337+
KUNIT_EXPECT_EQ(test, ret, 0);
2338+
}
2339+
2340+
static void cros_ec_proto_test_get_host_event_wrong_event_size(struct kunit *test)
2341+
{
2342+
struct cros_ec_proto_test_priv *priv = test->priv;
2343+
struct cros_ec_device *ec_dev = &priv->ec_dev;
2344+
int ret;
2345+
2346+
ec_dev->mkbp_event_supported = 1;
2347+
ec_dev->event_data.event_type = EC_MKBP_EVENT_HOST_EVENT;
2348+
ec_dev->event_size = 0xff;
2349+
2350+
ret = cros_ec_get_host_event(ec_dev);
2351+
KUNIT_EXPECT_EQ(test, ret, 0);
2352+
}
2353+
2354+
static void cros_ec_proto_test_get_host_event_normal(struct kunit *test)
2355+
{
2356+
struct cros_ec_proto_test_priv *priv = test->priv;
2357+
struct cros_ec_device *ec_dev = &priv->ec_dev;
2358+
int ret;
2359+
2360+
ec_dev->mkbp_event_supported = 1;
2361+
ec_dev->event_data.event_type = EC_MKBP_EVENT_HOST_EVENT;
2362+
ec_dev->event_size = sizeof(ec_dev->event_data.data.host_event);
2363+
put_unaligned_le32(EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC),
2364+
&ec_dev->event_data.data.host_event);
2365+
2366+
ret = cros_ec_get_host_event(ec_dev);
2367+
KUNIT_EXPECT_EQ(test, ret, EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC));
2368+
}
2369+
23152370
static void cros_ec_proto_test_release(struct device *dev)
23162371
{
23172372
}
@@ -2401,6 +2456,10 @@ static struct kunit_case cros_ec_proto_test_cases[] = {
24012456
KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_version2),
24022457
KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_host_event_rtc),
24032458
KUNIT_CASE(cros_ec_proto_test_get_next_event_mkbp_event_host_event_masked),
2459+
KUNIT_CASE(cros_ec_proto_test_get_host_event_no_mkbp_event),
2460+
KUNIT_CASE(cros_ec_proto_test_get_host_event_not_host_event),
2461+
KUNIT_CASE(cros_ec_proto_test_get_host_event_wrong_event_size),
2462+
KUNIT_CASE(cros_ec_proto_test_get_host_event_normal),
24042463
{}
24052464
};
24062465

0 commit comments

Comments
 (0)