Skip to content

Commit ddbc7ef

Browse files
JarmouniAdanieldegrasse
authored andcommitted
tests: kernel: device: expand device api coverage
Add test coverage for device device_get_by_dt_nodelabel() API Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
1 parent 1f4e78e commit ddbc7ef

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

tests/kernel/device/app.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#address-cells = <1>;
1818
#size-cells = <1>;
1919

20-
fakedriver@E0000000 {
20+
fake_driver_label: fakedriver@E0000000 {
2121
compatible = "fakedriver";
2222
reg = <0xE0000000 0x2000>;
2323
status = "okay";

tests/kernel/device/src/main.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#define FAKEDEFERDRIVER0 DEVICE_DT_GET(DT_PATH(fakedeferdriver_e7000000))
2727
#define FAKEDEFERDRIVER1 DEVICE_DT_GET(DT_PATH(fakedeferdriver_e8000000))
2828

29+
#define FAKEDRIVER0_NODEID DT_PATH(fakedriver_e0000000)
30+
#define FAKEDRIVER0_NODELABEL "fake_driver_label"
31+
2932
/* A device without init call */
3033
DEVICE_DEFINE(dummy_noinit, DUMMY_NOINIT, NULL, NULL, NULL, NULL,
3134
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
@@ -476,6 +479,26 @@ ZTEST(device, test_deinit_success_and_redeinit)
476479
zassert_equal(ret, -EPERM, "device_deinit should fail when not init or already deinit");
477480
}
478481

482+
#ifdef CONFIG_DEVICE_DT_METADATA
483+
DEVICE_DT_DEFINE(FAKEDRIVER0_NODEID, NULL, NULL, NULL, NULL, POST_KERNEL,
484+
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
485+
486+
ZTEST(device, test_device_get_by_dt_nodelabel)
487+
{
488+
const struct device *dev = DEVICE_DT_GET(FAKEDRIVER0_NODEID);
489+
490+
zassert_not_null(dev);
491+
492+
const struct device *valid = device_get_by_dt_nodelabel(FAKEDRIVER0_NODELABEL);
493+
494+
zassert_not_null(valid, "Valid DT nodelabel should return a device");
495+
496+
const struct device *invalid = device_get_by_dt_nodelabel("does_not_exist");
497+
498+
zassert_is_null(invalid, "Invalid DT nodelabel should return NULL");
499+
}
500+
#endif
501+
479502
void *user_setup(void)
480503
{
481504
#ifdef CONFIG_USERSPACE

tests/kernel/device/testcase.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tests:
1313
kernel.device.metadata:
1414
platform_allow:
1515
- qemu_x86
16+
- native_sim
1617
extra_configs:
1718
- CONFIG_DEVICE_DT_METADATA=y
1819
kernel.device.minimallibc:

0 commit comments

Comments
 (0)