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 <swift.tian@ambiq.com>
This commit is contained in:
Swift Tian 2024-04-26 14:08:08 +08:00 committed by Carles Cufí
parent 5871ff010b
commit 74ddfbc8a2
1 changed files with 10 additions and 0 deletions

View File

@ -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, "");