Skip to content

Commit 5ca8be2

Browse files
henrikbrixandersendanieldegrasse
authored andcommitted
tests: kconfig: functions: add tests for dt_compat_enabled_num
Add tests for the dt_compat_enabled_num Kconfig helper function. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
1 parent 08175f8 commit 5ca8be2

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

tests/kconfig/functions/Kconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,22 @@ config KCONFIG_MAX_10_3_2
113113
int
114114
default $(max, 0xa, 3, 0b10)
115115

116+
DT_COMPAT_VND_GPIO := vnd,gpio
117+
118+
config KCONFIG_VND_GPIO_ENABLED_NUM_4
119+
int
120+
default $(dt_compat_enabled_num,$(DT_COMPAT_VND_GPIO))
121+
122+
DT_COMPAT_VND_CAN_CONTROLLER := vnd,can-controller
123+
124+
config KCONFIG_VND_CAN_CONTROLLER_ENABLED_NUM_2
125+
int
126+
default $(dt_compat_enabled_num,$(DT_COMPAT_VND_CAN_CONTROLLER))
127+
128+
DT_COMPAT_VND_PWM := vnd,pwm
129+
130+
config KCONFIG_VND_PWM_ENABLED_NUM_0
131+
int
132+
default $(dt_compat_enabled_num,$(DT_COMPAT_VND_PWM))
133+
116134
source "Kconfig.zephyr"

tests/kconfig/functions/app.overlay

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2025 Vestas Wind Systems A/S
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
test {
9+
#address-cells = <1>;
10+
#size-cells = <1>;
11+
12+
test_gpio_0: gpio@1000 {
13+
compatible = "vnd,gpio";
14+
reg = <0x1000 0x1000>;
15+
gpio-controller;
16+
#gpio-cells = <2>;
17+
status = "okay";
18+
};
19+
20+
test_gpio_1: gpio@2000 {
21+
compatible = "vnd,gpio";
22+
reg = <0x2000 0x1000>;
23+
gpio-controller;
24+
#gpio-cells = <2>;
25+
status = "okay";
26+
};
27+
28+
test_gpio_2: gpio@3000 {
29+
compatible = "vnd,gpio";
30+
reg = <0x3000 0x1000>;
31+
gpio-controller;
32+
#gpio-cells = <2>;
33+
status = "okay";
34+
};
35+
36+
test_gpio_3: gpio@4000 {
37+
compatible = "vnd,gpio";
38+
reg = <0x4000 0x1000>;
39+
gpio-controller;
40+
#gpio-cells = <2>;
41+
status = "okay";
42+
};
43+
44+
test_can_0: gpio@5000 {
45+
compatible = "vnd,can-controller";
46+
reg = <0x5000 0x1000>;
47+
status = "okay";
48+
};
49+
50+
test_can_1: gpio@6000 {
51+
compatible = "vnd,can-controller";
52+
reg = <0x6000 0x1000>;
53+
status = "okay";
54+
};
55+
56+
test_can_2: gpio@7000 {
57+
compatible = "vnd,can-controller";
58+
reg = <0x7000 0x1000>;
59+
status = "disabled";
60+
};
61+
};
62+
};

tests/kconfig/functions/src/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@ ZTEST(test_kconfig_functions, test_min_max)
4545
zassert_equal(CONFIG_KCONFIG_MAX_10_3_2, MAX(MAX(10, 3), 2));
4646
}
4747

48+
ZTEST(test_kconfig_functions, test_dt_num_compat_enabled)
49+
{
50+
zassert_equal(CONFIG_KCONFIG_VND_GPIO_ENABLED_NUM_4, 4);
51+
zassert_equal(CONFIG_KCONFIG_VND_CAN_CONTROLLER_ENABLED_NUM_2, 2);
52+
zassert_equal(CONFIG_KCONFIG_VND_PWM_ENABLED_NUM_0, 0);
53+
}
54+
4855
ZTEST_SUITE(test_kconfig_functions, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)