Skip to content

Commit cfa40f2

Browse files
committed
leds: led-test: Provide tests for the lookup and get infrastructure
This API allows providers to offer an specific LED to be looked-up by a consumer. Consumers are then able to describe the aforementioned LED and take a reference on it. For convenience, we're testing both sides of the API in just one test function here. In reality, both the provider and the consumer would be logistically orthogonal. CMD: tools/testing/kunit/kunit.py run --kunitconfig drivers/leds RESULTS: [16:38:57] Configuring KUnit Kernel ... [16:38:57] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=20 [16:39:02] Starting KUnit Kernel (1/1)... [16:39:02] ============================================================ Running tests with: $ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt [16:39:03] ===================== led (2 subtests) ===================== [16:39:03] [PASSED] led_test_class_register [16:39:03] [PASSED] led_test_class_add_lookup_and_get [16:39:03] ======================= [PASSED] led ======================= [16:39:03] ============================================================ [16:39:03] Testing complete. Ran 2 tests: passed: 2 [16:39:03] Elapsed time: 6.255s total, 0.001s configuring, 5.131s building, 1.106s running Link: https://lore.kernel.org/r/20250501081918.3621432-3-lee@kernel.org Signed-off-by: Lee Jones <lee@kernel.org>
1 parent eb58933 commit cfa40f2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

drivers/leds/led-test.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,37 @@ static void led_test_class_register(struct kunit *test)
5757
KUNIT_EXPECT_EQ(test, ret, -EEXIST);
5858
}
5959

60+
static void led_test_class_add_lookup_and_get(struct kunit *test)
61+
{
62+
struct led_test_ddata *ddata = test->priv;
63+
struct led_classdev *cdev = &ddata->cdev, *cdev_get;
64+
struct device *dev = ddata->dev;
65+
struct led_lookup_data lookup;
66+
int ret;
67+
68+
/* First, register a LED class device */
69+
cdev->name = "led-test";
70+
ret = devm_led_classdev_register(dev, cdev);
71+
KUNIT_ASSERT_EQ(test, ret, 0);
72+
73+
/* Then make the LED available for lookup */
74+
lookup.provider = cdev->name;
75+
lookup.dev_id = dev_name(dev);
76+
lookup.con_id = "led-test-1";
77+
led_add_lookup(&lookup);
78+
79+
/* Finally, attempt to look it up via the API - imagine this was an orthogonal driver */
80+
cdev_get = devm_led_get(dev, "led-test-1");
81+
KUNIT_ASSERT_FALSE(test, IS_ERR(cdev_get));
82+
83+
KUNIT_EXPECT_STREQ(test, cdev_get->name, cdev->name);
84+
85+
led_remove_lookup(&lookup);
86+
}
87+
6088
static struct kunit_case led_test_cases[] = {
6189
KUNIT_CASE(led_test_class_register),
90+
KUNIT_CASE(led_test_class_add_lookup_and_get),
6291
{ }
6392
};
6493

0 commit comments

Comments
 (0)