|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2 | 2 |
|
| 3 | +#include <kunit/platform_device.h> |
3 | 4 | #include <kunit/resource.h> |
4 | 5 |
|
5 | 6 | #include <linux/device.h> |
| 7 | +#include <linux/device/bus.h> |
| 8 | +#include <linux/of_platform.h> |
6 | 9 | #include <linux/platform_device.h> |
7 | 10 |
|
8 | 11 | #define DEVICE_NAME "test" |
@@ -217,7 +220,43 @@ static struct kunit_suite platform_device_devm_test_suite = { |
217 | 220 | .test_cases = platform_device_devm_tests, |
218 | 221 | }; |
219 | 222 |
|
220 | | -kunit_test_suite(platform_device_devm_test_suite); |
| 223 | +static void platform_device_find_by_null_test(struct kunit *test) |
| 224 | +{ |
| 225 | + struct platform_device *pdev; |
| 226 | + int ret; |
| 227 | + |
| 228 | + pdev = kunit_platform_device_alloc(test, DEVICE_NAME, PLATFORM_DEVID_NONE); |
| 229 | + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pdev); |
| 230 | + |
| 231 | + ret = kunit_platform_device_add(test, pdev); |
| 232 | + KUNIT_ASSERT_EQ(test, ret, 0); |
| 233 | + |
| 234 | + KUNIT_EXPECT_PTR_EQ(test, of_find_device_by_node(NULL), NULL); |
| 235 | + |
| 236 | + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_of_node(&platform_bus_type, NULL), NULL); |
| 237 | + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_fwnode(&platform_bus_type, NULL), NULL); |
| 238 | + KUNIT_EXPECT_PTR_EQ(test, bus_find_device_by_acpi_dev(&platform_bus_type, NULL), NULL); |
| 239 | + |
| 240 | + KUNIT_EXPECT_FALSE(test, device_match_of_node(&pdev->dev, NULL)); |
| 241 | + KUNIT_EXPECT_FALSE(test, device_match_fwnode(&pdev->dev, NULL)); |
| 242 | + KUNIT_EXPECT_FALSE(test, device_match_acpi_dev(&pdev->dev, NULL)); |
| 243 | + KUNIT_EXPECT_FALSE(test, device_match_acpi_handle(&pdev->dev, NULL)); |
| 244 | +} |
| 245 | + |
| 246 | +static struct kunit_case platform_device_match_tests[] = { |
| 247 | + KUNIT_CASE(platform_device_find_by_null_test), |
| 248 | + {} |
| 249 | +}; |
| 250 | + |
| 251 | +static struct kunit_suite platform_device_match_test_suite = { |
| 252 | + .name = "platform-device-match", |
| 253 | + .test_cases = platform_device_match_tests, |
| 254 | +}; |
| 255 | + |
| 256 | +kunit_test_suites( |
| 257 | + &platform_device_devm_test_suite, |
| 258 | + &platform_device_match_test_suite, |
| 259 | +); |
221 | 260 |
|
222 | 261 | MODULE_DESCRIPTION("Test module for platform devices"); |
223 | 262 | MODULE_AUTHOR("Maxime Ripard <mripard@kernel.org>"); |
|
0 commit comments