From 74ddfbc8a2e4f1932bf2b6a160f83a27a6c135a5 Mon Sep 17 00:00:00 2001 From: Swift Tian Date: Fri, 26 Apr 2024 14:08:08 +0800 Subject: [PATCH] tests: devicetree: Add a test test_child_nodes_number The test uses DT_CHILD_NUM and DT_INST_CHILD_NUM to get the number of child nodes of a given node from generated macro. The test uses DT_CHILD_NUM_STATUS_OKAY and DT_INST_CHILD_NUM_STATUS_OKAY to get the number of child nodes of a given node which children's status are "okay" from generated macro. Signed-off-by: Swift Tian --- tests/lib/devicetree/api/src/main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/lib/devicetree/api/src/main.c b/tests/lib/devicetree/api/src/main.c index 340ff1edbf6..c57a280670f 100644 --- a/tests/lib/devicetree/api/src/main.c +++ b/tests/lib/devicetree/api/src/main.c @@ -2214,6 +2214,16 @@ ZTEST(devicetree_api, test_child_nodes_list_varg) #undef TEST_FUNC } +#undef DT_DRV_COMPAT +#define DT_DRV_COMPAT vnd_child_bindings +ZTEST(devicetree_api, test_child_nodes_number) +{ + zassert_equal(DT_CHILD_NUM(TEST_CHILDREN), 3, ""); + zassert_equal(DT_INST_CHILD_NUM(0), 3, ""); + zassert_equal(DT_CHILD_NUM_STATUS_OKAY(TEST_CHILDREN), 2, ""); + zassert_equal(DT_INST_CHILD_NUM_STATUS_OKAY(0), 2, ""); +} + ZTEST(devicetree_api, test_great_grandchild) { zassert_equal(DT_PROP(DT_NODELABEL(test_ggc), ggc_prop), 42, "");