From 3a9e6930874ee771c09d9768d59515674a871e6c Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Thu, 28 Nov 2024 18:03:26 +1000 Subject: [PATCH] tests: lib: devicetree: api: test `DT_ANY_INST_HAS_BOOL_STATUS_OKAY` Add tests for the new `DT_ANY_INST_HAS_BOOL_STATUS_OKAY` macro. Signed-off-by: Jordan Yates --- dts/bindings/test/vnd,device-with-props.yaml | 9 ++++++ tests/lib/devicetree/api/app.overlay | 4 +++ tests/lib/devicetree/api/src/main.c | 29 ++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/dts/bindings/test/vnd,device-with-props.yaml b/dts/bindings/test/vnd,device-with-props.yaml index f064c6876db..22a09c98c6b 100644 --- a/dts/bindings/test/vnd,device-with-props.yaml +++ b/dts/bindings/test/vnd,device-with-props.yaml @@ -14,3 +14,12 @@ properties: baz: type: int + + bool-foo: + type: boolean + + bool-bar: + type: boolean + + bool-baz: + type: boolean diff --git a/tests/lib/devicetree/api/app.overlay b/tests/lib/devicetree/api/app.overlay index 359f17066a2..ba3af8b7650 100644 --- a/tests/lib/devicetree/api/app.overlay +++ b/tests/lib/devicetree/api/app.overlay @@ -638,18 +638,22 @@ status = "okay"; foo = <1>; bar = <2>; + bool-foo; + bool-bar; }; device-with-props-1 { compatible = "vnd,device-with-props"; status = "okay"; foo = <2>; + bool-foo; }; device-with-props-2 { compatible = "vnd,device-with-props"; status = "disabled"; baz = <1>; + bool-baz; }; test_string_token_0: string-token-0 { diff --git a/tests/lib/devicetree/api/src/main.c b/tests/lib/devicetree/api/src/main.c index 4b39c4571a8..a9b37744a9a 100644 --- a/tests/lib/devicetree/api/src/main.c +++ b/tests/lib/devicetree/api/src/main.c @@ -223,6 +223,35 @@ ZTEST(devicetree_api, test_any_compat_inst_prop) 0, ""); } +#undef DT_DRV_COMPAT +#define DT_DRV_COMPAT vnd_device_with_props +ZTEST(devicetree_api, test_any_inst_bool) +{ + zassert_equal(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_foo), 1, ""); + zassert_equal(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_bar), 1, ""); + zassert_equal(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_baz), 0, ""); + zassert_equal(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(does_not_exist), 0, ""); + + zassert_equal(COND_CODE_1(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_foo), + (5), (6)), + 5, ""); + zassert_equal(COND_CODE_0(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_foo), + (5), (6)), + 6, ""); + zassert_equal(COND_CODE_1(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_baz), + (5), (6)), + 6, ""); + zassert_equal(COND_CODE_0(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_baz), + (5), (6)), + 5, ""); + zassert_true(IS_ENABLED(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_foo)), ""); + zassert_true(!IS_ENABLED(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_baz)), ""); + zassert_equal(IF_ENABLED(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_foo), (1)) + 1, + 2, ""); + zassert_equal(IF_ENABLED(DT_ANY_INST_HAS_BOOL_STATUS_OKAY(bool_baz), (1)) + 1, + 1, ""); +} + ZTEST(devicetree_api, test_default_prop_access) { /*