|
18 | 18 | #define DUMMY_PORT_2 "dummy_driver"
|
19 | 19 | #define DUMMY_NOINIT "dummy_noinit"
|
20 | 20 | #define BAD_DRIVER "bad_driver"
|
| 21 | +#define DUMMY_DEINIT "dummy_deinit" |
21 | 22 |
|
22 | 23 | #define MY_DRIVER_A "my_driver_A"
|
23 | 24 | #define MY_DRIVER_B "my_driver_B"
|
@@ -441,6 +442,40 @@ ZTEST_USER(device, test_deferred_init_user)
|
441 | 442 | zassert_true(device_is_ready(FAKEDEFERDRIVER1));
|
442 | 443 | }
|
443 | 444 |
|
| 445 | +ZTEST(device, test_deinit_not_supported) |
| 446 | +{ |
| 447 | + const struct device *dev = device_get_binding(DUMMY_NOINIT); |
| 448 | + int ret; |
| 449 | + |
| 450 | + zassert_not_null(dev); |
| 451 | + |
| 452 | + ret = device_deinit(dev); |
| 453 | + zassert_equal(ret, -ENOTSUP, "Expected -ENOTSUP for device_deinit when not supported"); |
| 454 | +} |
| 455 | + |
| 456 | +static int dummy_deinit(const struct device *dev) |
| 457 | +{ |
| 458 | + return 0; |
| 459 | +} |
| 460 | + |
| 461 | +/* A device with de-initialization function */ |
| 462 | +DEVICE_DEINIT_DEFINE(dummy_deinit, DUMMY_DEINIT, NULL, dummy_deinit, NULL, NULL, NULL, POST_KERNEL, |
| 463 | + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); |
| 464 | + |
| 465 | +ZTEST(device, test_deinit_success_and_redeinit) |
| 466 | +{ |
| 467 | + const struct device *dev = device_get_binding(DUMMY_DEINIT); |
| 468 | + int ret; |
| 469 | + |
| 470 | + zassert_not_null(dev); |
| 471 | + |
| 472 | + ret = device_deinit(dev); |
| 473 | + zassert_equal(ret, 0, "device_deinit should succeed"); |
| 474 | + |
| 475 | + ret = device_deinit(dev); |
| 476 | + zassert_equal(ret, -EPERM, "device_deinit should fail when not init or already deinit"); |
| 477 | +} |
| 478 | + |
444 | 479 | void *user_setup(void)
|
445 | 480 | {
|
446 | 481 | #ifdef CONFIG_USERSPACE
|
|
0 commit comments