From 5ca8be264dcc91625c979f8af225ce14cad541cc Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Wed, 25 Jun 2025 15:23:06 +0200 Subject: [PATCH] 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 --- tests/kconfig/functions/Kconfig | 18 +++++++++ tests/kconfig/functions/app.overlay | 62 +++++++++++++++++++++++++++++ tests/kconfig/functions/src/main.c | 7 ++++ 3 files changed, 87 insertions(+) create mode 100644 tests/kconfig/functions/app.overlay diff --git a/tests/kconfig/functions/Kconfig b/tests/kconfig/functions/Kconfig index 1e46730c98a..b38b78598fb 100644 --- a/tests/kconfig/functions/Kconfig +++ b/tests/kconfig/functions/Kconfig @@ -113,4 +113,22 @@ config KCONFIG_MAX_10_3_2 int default $(max, 0xa, 3, 0b10) +DT_COMPAT_VND_GPIO := vnd,gpio + +config KCONFIG_VND_GPIO_ENABLED_NUM_4 + int + default $(dt_compat_enabled_num,$(DT_COMPAT_VND_GPIO)) + +DT_COMPAT_VND_CAN_CONTROLLER := vnd,can-controller + +config KCONFIG_VND_CAN_CONTROLLER_ENABLED_NUM_2 + int + default $(dt_compat_enabled_num,$(DT_COMPAT_VND_CAN_CONTROLLER)) + +DT_COMPAT_VND_PWM := vnd,pwm + +config KCONFIG_VND_PWM_ENABLED_NUM_0 + int + default $(dt_compat_enabled_num,$(DT_COMPAT_VND_PWM)) + source "Kconfig.zephyr" diff --git a/tests/kconfig/functions/app.overlay b/tests/kconfig/functions/app.overlay new file mode 100644 index 00000000000..4a89ddb8a12 --- /dev/null +++ b/tests/kconfig/functions/app.overlay @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Vestas Wind Systems A/S + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + test { + #address-cells = <1>; + #size-cells = <1>; + + test_gpio_0: gpio@1000 { + compatible = "vnd,gpio"; + reg = <0x1000 0x1000>; + gpio-controller; + #gpio-cells = <2>; + status = "okay"; + }; + + test_gpio_1: gpio@2000 { + compatible = "vnd,gpio"; + reg = <0x2000 0x1000>; + gpio-controller; + #gpio-cells = <2>; + status = "okay"; + }; + + test_gpio_2: gpio@3000 { + compatible = "vnd,gpio"; + reg = <0x3000 0x1000>; + gpio-controller; + #gpio-cells = <2>; + status = "okay"; + }; + + test_gpio_3: gpio@4000 { + compatible = "vnd,gpio"; + reg = <0x4000 0x1000>; + gpio-controller; + #gpio-cells = <2>; + status = "okay"; + }; + + test_can_0: gpio@5000 { + compatible = "vnd,can-controller"; + reg = <0x5000 0x1000>; + status = "okay"; + }; + + test_can_1: gpio@6000 { + compatible = "vnd,can-controller"; + reg = <0x6000 0x1000>; + status = "okay"; + }; + + test_can_2: gpio@7000 { + compatible = "vnd,can-controller"; + reg = <0x7000 0x1000>; + status = "disabled"; + }; + }; +}; diff --git a/tests/kconfig/functions/src/main.c b/tests/kconfig/functions/src/main.c index 7492e3b5b93..980447966f8 100644 --- a/tests/kconfig/functions/src/main.c +++ b/tests/kconfig/functions/src/main.c @@ -45,4 +45,11 @@ ZTEST(test_kconfig_functions, test_min_max) zassert_equal(CONFIG_KCONFIG_MAX_10_3_2, MAX(MAX(10, 3), 2)); } +ZTEST(test_kconfig_functions, test_dt_num_compat_enabled) +{ + zassert_equal(CONFIG_KCONFIG_VND_GPIO_ENABLED_NUM_4, 4); + zassert_equal(CONFIG_KCONFIG_VND_CAN_CONTROLLER_ENABLED_NUM_2, 2); + zassert_equal(CONFIG_KCONFIG_VND_PWM_ENABLED_NUM_0, 0); +} + ZTEST_SUITE(test_kconfig_functions, NULL, NULL, NULL, NULL, NULL);