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 <sjg@chromium.org>
This commit is contained in:
Simon Glass
2023-09-26 08:14:42 -06:00
committed by Tom Rini
parent c15862ffdd
commit 67fb2159fb
5 changed files with 150 additions and 0 deletions

View File

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