From patchwork Thu May 1 08:19:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 887683 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE84C1411DE; Thu, 1 May 2025 08:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746087568; cv=none; b=JX1iiSDHI4DfrY/FpKSUPuy4NmDj0BuVjwoOpnvpEORA4jcw7PIzXlYskUlCwWfmjXH55/++7pD7LwmWonw4Pv4tgJYIx70y2tPfi7ZTfT9/e+pN8H8+NMbWjNyBkMsRJFaMUWlzPsUKOX29KXtB7EdNwIn7BN6VB8IuTM3UWaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746087568; c=relaxed/simple; bh=nsILDRc0lseFd1tlQC6e7X/eWY6LuFYiZUFOmwhwPYE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hx4sGZc9Cf1CbFbsDoNI7bJ8rOxGhKTTTAbdhvvys+0tnZP/mLBRPjRtJwJcHG12FuhNAkonJ5xCAbWkecKL5mOiAyqsLz4hYrAFKWskZKtuGYVbJ2OJF0iW044mNI230SnO0lSJBXZqYAMCxGCsj4cb10doDrEV0RTqwf5Ck0A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ijsjpsQa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ijsjpsQa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EC08C4CEE3; Thu, 1 May 2025 08:19:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746087568; bh=nsILDRc0lseFd1tlQC6e7X/eWY6LuFYiZUFOmwhwPYE=; h=From:To:Cc:Subject:Date:From; b=ijsjpsQa9nUP09i3NbUmko8kELXkwW6d9SJiLSpNUXPUYsHYqsINtbFuSCVKl+R9R /4D23oAObhilbCbnah9nycKPdp0BUQj3ydJnWJ2n+Q9mJ4ztNxH5SopBxx4MB99gqm vlTYwGLT26LyH3N57k398jsxW1w2Jbqh+tsxYT6fa/6q3mvNZI8psXxXyzBLLTj/mN bRwKUZektBBG1Pr8hsNj718tXNaEote2dnkgv+XEBagNrEiW2Xbq57AW8Jaz3k/PHU i8rCQTSwSFcds8QBegQzK9o6OHjMupejjvClocFDCnIlyFVVQi45bvIwwlAneXqaeO rjvU7pAtKgQMQ== From: Lee Jones To: lee@kernel.org, Pavel Machek , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: bettyzhou@google.com, ynaffit@google.com, tkjos@google.com, jacek.anaszewski@gmail.com Subject: [PATCH 1/3] led: led-test: Remove standard error checking after KUNIT_ASSERT_*() Date: Thu, 1 May 2025 09:19:11 +0100 Message-ID: <20250501081918.3621432-1-lee@kernel.org> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If a KUNIT_ASSERT_*() call ends up in an assertion, the test is marked as a failure and the subsequent error checking is never executed, making it superfluous. Remove it for simplicity and to avoid confusion. Signed-off-by: Lee Jones --- drivers/leds/led-test.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/leds/led-test.c b/drivers/leds/led-test.c index 068c9d0eb683..23820189abe3 100644 --- a/drivers/leds/led-test.c +++ b/drivers/leds/led-test.c @@ -26,8 +26,6 @@ static void led_test_class_register(struct kunit *test) ret = devm_led_classdev_register(dev, cdev); KUNIT_ASSERT_EQ(test, ret, 0); - if (ret) - return; } static struct kunit_case led_test_cases[] = { From patchwork Thu May 1 08:19:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 886592 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14348210185; Thu, 1 May 2025 08:19:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746087571; cv=none; b=ZxKaxWkzQma4N3TzX3CrYf8G1wEdJoYTbmzzinxXWnsK8VltXrAKVAH5g5Vm4ibGHrhUphmmybKh8XzIfzOKURNGclkzuMPA1LsG36Q4h2aINFSVwPHXXhFwglNo9gHQxgFvuT+FvPljLOYcou5F8yl1DehiHHMvX8ovjCauquM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746087571; c=relaxed/simple; bh=t1pnfiKto4qeBxz+EzHMk3dVj2dz+fuwX8MxSCnMMpE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pJPXt6djYNYBecPfenx+gXzefKacMsQj4auYbVrVFbbRaRSb8zb069DJ6wEQ8JqCNS40F7MIJGdAq+vY7nxHDuz6x13sBBN5CVmBiWrRJFoK56zrBsmRQI7KO9knER+HJVEGUStJqA0guJHwubTv64VGnug5CoM1nW7a1Epy9P4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=noamudyD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="noamudyD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE8E3C4CEE9; Thu, 1 May 2025 08:19:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746087570; bh=t1pnfiKto4qeBxz+EzHMk3dVj2dz+fuwX8MxSCnMMpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=noamudyDuZybK3LQFIkTik4g0nwR1gokUKS4p5w9BcARzj1YdEVfuJX2xmiM3QhR/ nnV6XLx01CXBWoxe9qL4pReYxh2CYtIaGo8Y7YaLUI/etJenUGaF2+X9Cr29BQ71A+ Of0eBl48AVsZyfg/UlwZ9P22OQukG6G+NFYLmQvl68s6Z/w72SxpFgB5xddxeldtot U2TxD3/AOoZHQitpn0bpognGv5bsz6zBt+IVUjeFAfUc0yGYXc1tbPwCucLOmwyKMt KewWrpFrg+pcnNZF6Jg2RQNaKnj0XmrTJXQGAP/eJhSBO1gWXxibwvQBfDMYkee6Dv 4cw1kdE2uYoZA== From: Lee Jones To: lee@kernel.org, Pavel Machek , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: bettyzhou@google.com, ynaffit@google.com, tkjos@google.com, jacek.anaszewski@gmail.com Subject: [PATCH 2/3] leds: led-test: Fill out the registration test to cover more test cases Date: Thu, 1 May 2025 09:19:12 +0100 Message-ID: <20250501081918.3621432-2-lee@kernel.org> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog In-Reply-To: <20250501081918.3621432-1-lee@kernel.org> References: <20250501081918.3621432-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Upon successful LED class device registration, it is expected that certain attributes are filled out in pre-defined ways. For instance, if provided, the .brightness_get() call-back should be called to populate the class device 'brightness' attribute, 'max_brightness' should be initialised as LED_FULL (at least until we can rid these pesky enums) and the sysfs group should be created with the class device name supplied by the caller. If subsequent registrations take place that would result in name conflicts, various outcomes are expected depending on which flags are set. If LED_REJECT_NAME_CONFLICT is disabled, registration should succeed resulting in an iteration on the provided name. Conversely, if it's enabled, then registration is expected to fail outright. We test for all of these scenarios here. Signed-off-by: Lee Jones --- drivers/leds/led-test.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/leds/led-test.c b/drivers/leds/led-test.c index 23820189abe3..bc85e4513745 100644 --- a/drivers/leds/led-test.c +++ b/drivers/leds/led-test.c @@ -10,22 +10,51 @@ #include #include +#define LED_TEST_POST_REG_BRIGHTNESS 10 + struct led_test_ddata { struct led_classdev cdev; struct device *dev; }; +static enum led_brightness led_test_brightness_get(struct led_classdev *cdev) +{ + return LED_TEST_POST_REG_BRIGHTNESS; +} + static void led_test_class_register(struct kunit *test) { struct led_test_ddata *ddata = test->priv; - struct led_classdev *cdev = &ddata->cdev; + struct led_classdev *cdev_clash, *cdev = &ddata->cdev; struct device *dev = ddata->dev; int ret; + /* Register a LED class device */ cdev->name = "led-test"; + cdev->brightness_get = led_test_brightness_get; + cdev->brightness = 0; ret = devm_led_classdev_register(dev, cdev); KUNIT_ASSERT_EQ(test, ret, 0); + + KUNIT_EXPECT_EQ(test, cdev->max_brightness, LED_FULL); + KUNIT_EXPECT_EQ(test, cdev->brightness, LED_TEST_POST_REG_BRIGHTNESS); + KUNIT_EXPECT_STREQ(test, cdev->dev->kobj.name, "led-test"); + + /* Register again with the same name - expect it to pass with the LED renamed */ + cdev_clash = devm_kmemdup(dev, cdev, sizeof(*cdev), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cdev_clash); + + ret = devm_led_classdev_register(dev, cdev_clash); + KUNIT_ASSERT_EQ(test, ret, 0); + + KUNIT_EXPECT_STREQ(test, cdev_clash->dev->kobj.name, "led-test_1"); + KUNIT_EXPECT_STREQ(test, cdev_clash->name, "led-test"); + + /* Enable name conflict rejection and register with the same name again - expect failure */ + cdev_clash->flags |= LED_REJECT_NAME_CONFLICT; + ret = devm_led_classdev_register(dev, cdev_clash); + KUNIT_EXPECT_EQ(test, ret, -EEXIST); } static struct kunit_case led_test_cases[] = { From patchwork Thu May 1 08:19:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 887682 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76F32265631; Thu, 1 May 2025 08:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746087573; cv=none; b=pAWcWfo9Xa9n6L5IpcUHzyTG3iOzBQR2apSso5g5XXWdzRH+6p34A/GBozn4pVcDAXvW8XZ6+VKJRFcvh4mtujpNYUOO+g9+cjMR7sD6ztPovdCawduCxT5tTUu5Z7bylQNbEpxJtlQU17HofJ36ZkHY9GEkfF0FyU4BIh4GKKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746087573; c=relaxed/simple; bh=0BH3ciCfuZ0knwyAOCd0nOJ6sgV/JlonC0enoP5+gn0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mUcpjsR46eAkXr7BkU4MjFJ+hwByNZ+Jgnr2vIkg1/mT5eEt1AupiAB3qDhl6GLCn0YzEjbsUncSzPzc1vNMnjyCkDI4WLn3RRu/jeGKiY0VmeW5dKL7jmebszFEO7byGc/GT0D43frqRVtPSwAGTMzTNVC6+WKUsr1pY/GzQzg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rnW7nMG0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rnW7nMG0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B7CEC4CEED; Thu, 1 May 2025 08:19:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746087572; bh=0BH3ciCfuZ0knwyAOCd0nOJ6sgV/JlonC0enoP5+gn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rnW7nMG0AWHMcGYkAG+cmhO23kkBt5miwVyC37B6SZpcqPm6aYDFVfzkgrEQXtyzS VdQt19PRlrTzC4mrA9OPLZ4vASXV29hODmAoOXcAVb7caw+MfRT4Ofl7o0UYgNO/N/ JzZc62wz5tN8l+xmFwlvUchMDvB8OqfIQRGVJXH0Iqxy8KK9Er4uX1lWx4u39rdXnM Hjk4QrmqpMlCmcIx3sUawsBjIivni+Rby3nnR3K6LE8PkNgEUIcuJN1McPyBbBN2DP uEIIKSWSBeKGHwd6p3dWnhJe6nnKI0yzjbr0MU7GzfYQi7Z5emWkuUAe+JCyiTabGm pBeaaFRc2qxrA== From: Lee Jones To: lee@kernel.org, Pavel Machek , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: bettyzhou@google.com, ynaffit@google.com, tkjos@google.com, jacek.anaszewski@gmail.com Subject: [PATCH 3/3] leds: led-test: Provide tests for the lookup and get infrastructure Date: Thu, 1 May 2025 09:19:13 +0100 Message-ID: <20250501081918.3621432-3-lee@kernel.org> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog In-Reply-To: <20250501081918.3621432-1-lee@kernel.org> References: <20250501081918.3621432-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Signed-off-by: Lee Jones --- drivers/leds/led-test.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/leds/led-test.c b/drivers/leds/led-test.c index bc85e4513745..ddf9aa967a6a 100644 --- a/drivers/leds/led-test.c +++ b/drivers/leds/led-test.c @@ -57,8 +57,37 @@ static void led_test_class_register(struct kunit *test) KUNIT_EXPECT_EQ(test, ret, -EEXIST); } +static void led_test_class_add_lookup_and_get(struct kunit *test) +{ + struct led_test_ddata *ddata = test->priv; + struct led_classdev *cdev = &ddata->cdev, *cdev_get; + struct device *dev = ddata->dev; + struct led_lookup_data lookup; + int ret; + + /* First, register a LED class device */ + cdev->name = "led-test"; + ret = devm_led_classdev_register(dev, cdev); + KUNIT_ASSERT_EQ(test, ret, 0); + + /* Then make the LED available for lookup */ + lookup.provider = cdev->name; + lookup.dev_id = dev_name(dev); + lookup.con_id = "led-test-1"; + led_add_lookup(&lookup); + + /* Finally, attempt to look it up via the API - imagine this was an orthogonal driver */ + cdev_get = devm_led_get(dev, "led-test-1"); + KUNIT_ASSERT_FALSE(test, IS_ERR(cdev_get)); + + KUNIT_EXPECT_STREQ(test, cdev_get->name, cdev->name); + + led_remove_lookup(&lookup); +} + static struct kunit_case led_test_cases[] = { KUNIT_CASE(led_test_class_register), + KUNIT_CASE(led_test_class_add_lookup_and_get), { } };