From 67fb2159fb3438359fa0fc3f8cb491ffe8d57c0f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:42 -0600 Subject: dm: core: Add a way to delete a node Add a function to delete a node in an existing tree. Signed-off-by: Simon Glass --- test/dm/ofnode.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test/dm/ofnode.c') diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 5459a9afbb9..845cded449a 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -1425,3 +1425,34 @@ static int dm_test_ofnode_copy_node_ot(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_ofnode_copy_node_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT); + +static int dm_test_ofnode_delete(struct unit_test_state *uts) +{ + ofnode node; + + /* + * At present the livetree is not restored after changes made in tests. + * See test_pre_run() for how this is done with the other FDT and + * dm_test_pre_run() where it sets up the root-tree pointer. So use + * nodes which don't matter to other tests. + * + * We could fix this by detecting livetree changes and regenerating it + * before the next test if needed. + */ + node = ofnode_path("/leds/iracibble"); + ut_assert(ofnode_valid(node)); + ut_assertok(ofnode_delete(&node)); + ut_assert(!ofnode_valid(node)); + ut_assert(!ofnode_valid(ofnode_path("/leds/iracibble"))); + + node = ofnode_path("/leds/default_on"); + ut_assert(ofnode_valid(node)); + ut_assertok(ofnode_delete(&node)); + ut_assert(!ofnode_valid(node)); + ut_assert(!ofnode_valid(ofnode_path("/leds/default_on"))); + + ut_asserteq(2, ofnode_get_child_count(ofnode_path("/leds"))); + + return 0; +} +DM_TEST(dm_test_ofnode_delete, UT_TESTF_SCAN_FDT); -- cgit v1.2.3