mirror of https://github.com/torvalds/linux.git
drivers: base: test: Add ...find_device_by...(... NULL) tests
We recently updated these device_match*() (and therefore, various
*find_device_by*()) functions to return a consistent 'false' value when
trying to match a NULL handle. Add tests for this.
This provides regression-testing coverage for the sorts of bugs that
underly commit 5c8418cf40 ("PCI/pwrctrl: Unregister platform device
only if one actually exists").
Reviewed-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Brian Norris <briannorris@chromium.org>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: David Gow <davidgow@google.com>
Link: https://lore.kernel.org/r/20241216201148.535115-4-briannorris@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
55b7aee990
commit
86a5f32ed8
|
|
@ -1,8 +1,11 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include <kunit/platform_device.h>
|
||||
#include <kunit/resource.h>
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/device/bus.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#define DEVICE_NAME "test"
|
||||
|
|
@ -217,7 +220,43 @@ static struct kunit_suite platform_device_devm_test_suite = {
|
|||
.test_cases = platform_device_devm_tests,
|
||||
};
|
||||
|
||||
kunit_test_suite(platform_device_devm_test_suite);
|
||||
static void platform_device_find_by_null_test(struct kunit *test)
|
||||
{
|
||||
struct platform_device *pdev;
|
||||
int ret;
|
||||
|
||||
pdev = kunit_platform_device_alloc(test, DEVICE_NAME, PLATFORM_DEVID_NONE);
|
||||
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev);
|
||||
|
||||
ret = kunit_platform_device_add(test, pdev);
|
||||
KUNIT_ASSERT_EQ(test, ret, 0);
|
||||
|
||||
KUNIT_EXPECT_PTR_EQ(test, of_find_device_by_node(NULL), NULL);
|
||||
|
||||
KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_of_node(&platform_bus_type, NULL), NULL);
|
||||
KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_fwnode(&platform_bus_type, NULL), NULL);
|
||||
KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_acpi_dev(&platform_bus_type, NULL), NULL);
|
||||
|
||||
KUNIT_EXPECT_FALSE(test, device_match_of_node(&pdev->dev, NULL));
|
||||
KUNIT_EXPECT_FALSE(test, device_match_fwnode(&pdev->dev, NULL));
|
||||
KUNIT_EXPECT_FALSE(test, device_match_acpi_dev(&pdev->dev, NULL));
|
||||
KUNIT_EXPECT_FALSE(test, device_match_acpi_handle(&pdev->dev, NULL));
|
||||
}
|
||||
|
||||
static struct kunit_case platform_device_match_tests[] = {
|
||||
KUNIT_CASE(platform_device_find_by_null_test),
|
||||
{}
|
||||
};
|
||||
|
||||
static struct kunit_suite platform_device_match_test_suite = {
|
||||
.name = "platform-device-match",
|
||||
.test_cases = platform_device_match_tests,
|
||||
};
|
||||
|
||||
kunit_test_suites(
|
||||
&platform_device_devm_test_suite,
|
||||
&platform_device_match_test_suite,
|
||||
);
|
||||
|
||||
MODULE_DESCRIPTION("Test module for platform devices");
|
||||
MODULE_AUTHOR("Maxime Ripard <mripard@kernel.org>");
|
||||
|
|
|
|||
Loading…
Reference in New Issue