aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@linaro.org>2014-10-01 12:40:22 -0400
committerGrant Likely <grant.likely@linaro.org>2014-10-04 16:20:13 -0400
commitf2051d6a88cd03f74221da887f56d778a1b2f1f1 (patch)
tree9a50f845ed67fff6a37f801e8e3d1275b99a2520 /drivers/of
parente66c98c7a0eacc33a9369a3ec086740044eb986c (diff)
of/selftest: Test structure of device tree
Add a testcase to verify that the device tree is properly constructed and the lists are in a correct order. The new testcase gets run twice; once after adding the testcase data, and once after removing it again. It is run twice to make sure adding and removing the testcase data doesn't corrupt the data structure. Signed-off-by: Grant Likely <grant.likely@linaro.org> Cc: Gaurav Minocha <gaurav.minocha.os@gmail.com>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/selftest.c56
1 files changed, 54 insertions, 2 deletions
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c
index 883e60b04eb5..252a7eda8d6a 100644
--- a/drivers/of/selftest.c
+++ b/drivers/of/selftest.c
@@ -145,6 +145,53 @@ static void __init of_selftest_dynamic(void)
145 "Adding a large property should have passed\n"); 145 "Adding a large property should have passed\n");
146} 146}
147 147
148static int __init of_selftest_check_node_linkage(struct device_node *np)
149{
150 struct device_node *child, *allnext_index = np;
151 int count = 0, rc;
152
153 for_each_child_of_node(np, child) {
154 if (child->parent != np) {
155 pr_err("Child node %s links to wrong parent %s\n",
156 child->name, np->name);
157 return -EINVAL;
158 }
159
160 while (allnext_index && allnext_index != child)
161 allnext_index = allnext_index->allnext;
162 if (allnext_index != child) {
163 pr_err("Node %s is ordered differently in sibling and allnode lists\n",
164 child->name);
165 return -EINVAL;
166 }
167
168 rc = of_selftest_check_node_linkage(child);
169 if (rc < 0)
170 return rc;
171 count += rc;
172 }
173
174 return count + 1;
175}
176
177static void __init of_selftest_check_tree_linkage(void)
178{
179 struct device_node *np;
180 int allnode_count = 0, child_count;
181
182 if (!of_allnodes)
183 return;
184
185 for_each_of_allnodes(np)
186 allnode_count++;
187 child_count = of_selftest_check_node_linkage(of_allnodes);
188
189 selftest(child_count > 0, "Device node data structure is corrupted\n");
190 selftest(child_count == allnode_count, "allnodes list size (%i) doesn't match"
191 "sibling lists size (%i)\n", allnode_count, child_count);
192 pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count, child_count);
193}
194
148static void __init of_selftest_parse_phandle_with_args(void) 195static void __init of_selftest_parse_phandle_with_args(void)
149{ 196{
150 struct device_node *np; 197 struct device_node *np;
@@ -777,6 +824,7 @@ static int __init of_selftest(void)
777 of_node_put(np); 824 of_node_put(np);
778 825
779 pr_info("start of selftest - you will see error messages\n"); 826 pr_info("start of selftest - you will see error messages\n");
827 of_selftest_check_tree_linkage();
780 of_selftest_find_node_by_name(); 828 of_selftest_find_node_by_name();
781 of_selftest_dynamic(); 829 of_selftest_dynamic();
782 of_selftest_parse_phandle_with_args(); 830 of_selftest_parse_phandle_with_args();
@@ -787,12 +835,16 @@ static int __init of_selftest(void)
787 of_selftest_parse_interrupts_extended(); 835 of_selftest_parse_interrupts_extended();
788 of_selftest_match_node(); 836 of_selftest_match_node();
789 of_selftest_platform_populate(); 837 of_selftest_platform_populate();
790 pr_info("end of selftest - %i passed, %i failed\n",
791 selftest_results.passed, selftest_results.failed);
792 838
793 /* removing selftest data from live tree */ 839 /* removing selftest data from live tree */
794 selftest_data_remove(); 840 selftest_data_remove();
795 841
842 /* Double check linkage after removing testcase data */
843 of_selftest_check_tree_linkage();
844
845 pr_info("end of selftest - %i passed, %i failed\n",
846 selftest_results.passed, selftest_results.failed);
847
796 return 0; 848 return 0;
797} 849}
798late_initcall(of_selftest); 850late_initcall(of_selftest);