Skip to content

Commit 500d451

Browse files
committed
of: unittest: Check tree matches original after reverting a changeset
Enhance the changeset unittest to ensure after a revert, the tree matches the original tree before the changeset was applied. Specifically, check an added node is removed, a removed property is added back, and an updated property has its original value. Signed-off-by: Rob Herring <robh@kernel.org>
1 parent b37c60d commit 500d451

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

drivers/of/unittest.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ static void __init of_unittest_property_copy(void)
797797
static void __init of_unittest_changeset(void)
798798
{
799799
#ifdef CONFIG_OF_DYNAMIC
800+
int ret;
800801
struct property *ppadd, padd = { .name = "prop-add", .length = 1, .value = "" };
801802
struct property *ppname_n1, pname_n1 = { .name = "name", .length = 3, .value = "n1" };
802803
struct property *ppname_n2, pname_n2 = { .name = "name", .length = 3, .value = "n2" };
@@ -807,6 +808,7 @@ static void __init of_unittest_changeset(void)
807808
static const char * const str_array[] = { "str1", "str2", "str3" };
808809
const u32 u32_array[] = { 1, 2, 3 };
809810
struct of_changeset chgset;
811+
const char *propstr = NULL;
810812

811813
n1 = __of_node_dup(NULL, "n1");
812814
unittest(n1, "testcase setup failure\n");
@@ -886,6 +888,17 @@ static void __init of_unittest_changeset(void)
886888

887889
unittest(!of_changeset_revert(&chgset), "revert failed\n");
888890

891+
unittest(!of_find_node_by_path("/testcase-data/changeset/n2/n21"),
892+
"'%pOF' still present after revert\n", n21);
893+
894+
ppremove = of_find_property(parent, "prop-remove", NULL);
895+
unittest(ppremove, "failed to find removed prop after revert\n");
896+
897+
ret = of_property_read_string(parent, "prop-update", &propstr);
898+
unittest(!ret, "failed to find updated prop after revert\n");
899+
if (!ret)
900+
unittest(strcmp(propstr, "hello") == 0, "original value not in updated property after revert");
901+
889902
of_changeset_destroy(&chgset);
890903

891904
of_node_put(n1);

0 commit comments

Comments
 (0)