2 * Self tests for device tree subsystem
5 #define pr_fmt(fmt) "### dt-test ### " fmt
9 #include <linux/errno.h>
10 #include <linux/hashtable.h>
11 #include <linux/module.h>
13 #include <linux/of_fdt.h>
14 #include <linux/of_irq.h>
15 #include <linux/of_platform.h>
16 #include <linux/list.h>
17 #include <linux/mutex.h>
18 #include <linux/slab.h>
19 #include <linux/device.h>
21 #include "of_private.h"
23 static struct selftest_results
{
29 static struct device_node
*nodes
[NO_OF_NODES
];
30 static int last_node_index
;
31 static bool selftest_live_tree
;
33 #define selftest(result, fmt, ...) { \
35 selftest_results.failed++; \
36 pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \
38 selftest_results.passed++; \
39 pr_debug("pass %s():%i\n", __func__, __LINE__); \
43 static void __init
of_selftest_find_node_by_name(void)
45 struct device_node
*np
;
47 np
= of_find_node_by_path("/testcase-data");
48 selftest(np
&& !strcmp("/testcase-data", np
->full_name
),
49 "find /testcase-data failed\n");
52 /* Test if trailing '/' works */
53 np
= of_find_node_by_path("/testcase-data/");
54 selftest(!np
, "trailing '/' on /testcase-data/ should fail\n");
56 np
= of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
57 selftest(np
&& !strcmp("/testcase-data/phandle-tests/consumer-a", np
->full_name
),
58 "find /testcase-data/phandle-tests/consumer-a failed\n");
61 np
= of_find_node_by_path("testcase-alias");
62 selftest(np
&& !strcmp("/testcase-data", np
->full_name
),
63 "find testcase-alias failed\n");
66 /* Test if trailing '/' works on aliases */
67 np
= of_find_node_by_path("testcase-alias/");
68 selftest(!np
, "trailing '/' on testcase-alias/ should fail\n");
70 np
= of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
71 selftest(np
&& !strcmp("/testcase-data/phandle-tests/consumer-a", np
->full_name
),
72 "find testcase-alias/phandle-tests/consumer-a failed\n");
75 np
= of_find_node_by_path("/testcase-data/missing-path");
76 selftest(!np
, "non-existent path returned node %s\n", np
->full_name
);
79 np
= of_find_node_by_path("missing-alias");
80 selftest(!np
, "non-existent alias returned node %s\n", np
->full_name
);
83 np
= of_find_node_by_path("testcase-alias/missing-path");
84 selftest(!np
, "non-existent alias with relative path returned node %s\n", np
->full_name
);
88 static void __init
of_selftest_dynamic(void)
90 struct device_node
*np
;
91 struct property
*prop
;
93 np
= of_find_node_by_path("/testcase-data");
95 pr_err("missing testcase data\n");
99 /* Array of 4 properties for the purpose of testing */
100 prop
= kzalloc(sizeof(*prop
) * 4, GFP_KERNEL
);
102 selftest(0, "kzalloc() failed\n");
106 /* Add a new property - should pass*/
107 prop
->name
= "new-property";
108 prop
->value
= "new-property-data";
109 prop
->length
= strlen(prop
->value
);
110 selftest(of_add_property(np
, prop
) == 0, "Adding a new property failed\n");
112 /* Try to add an existing property - should fail */
114 prop
->name
= "new-property";
115 prop
->value
= "new-property-data-should-fail";
116 prop
->length
= strlen(prop
->value
);
117 selftest(of_add_property(np
, prop
) != 0,
118 "Adding an existing property should have failed\n");
120 /* Try to modify an existing property - should pass */
121 prop
->value
= "modify-property-data-should-pass";
122 prop
->length
= strlen(prop
->value
);
123 selftest(of_update_property(np
, prop
) == 0,
124 "Updating an existing property should have passed\n");
126 /* Try to modify non-existent property - should pass*/
128 prop
->name
= "modify-property";
129 prop
->value
= "modify-missing-property-data-should-pass";
130 prop
->length
= strlen(prop
->value
);
131 selftest(of_update_property(np
, prop
) == 0,
132 "Updating a missing property should have passed\n");
134 /* Remove property - should pass */
135 selftest(of_remove_property(np
, prop
) == 0,
136 "Removing a property should have passed\n");
138 /* Adding very large property - should pass */
140 prop
->name
= "large-property-PAGE_SIZEx8";
141 prop
->length
= PAGE_SIZE
* 8;
142 prop
->value
= kzalloc(prop
->length
, GFP_KERNEL
);
143 selftest(prop
->value
!= NULL
, "Unable to allocate large buffer\n");
145 selftest(of_add_property(np
, prop
) == 0,
146 "Adding a large property should have passed\n");
149 static int __init
of_selftest_check_node_linkage(struct device_node
*np
)
151 struct device_node
*child
, *allnext_index
= np
;
154 for_each_child_of_node(np
, child
) {
155 if (child
->parent
!= np
) {
156 pr_err("Child node %s links to wrong parent %s\n",
157 child
->name
, np
->name
);
161 while (allnext_index
&& allnext_index
!= child
)
162 allnext_index
= allnext_index
->allnext
;
163 if (allnext_index
!= child
) {
164 pr_err("Node %s is ordered differently in sibling and allnode lists\n",
169 rc
= of_selftest_check_node_linkage(child
);
178 static void __init
of_selftest_check_tree_linkage(void)
180 struct device_node
*np
;
181 int allnode_count
= 0, child_count
;
186 for_each_of_allnodes(np
)
188 child_count
= of_selftest_check_node_linkage(of_allnodes
);
190 selftest(child_count
> 0, "Device node data structure is corrupted\n");
191 selftest(child_count
== allnode_count
, "allnodes list size (%i) doesn't match"
192 "sibling lists size (%i)\n", allnode_count
, child_count
);
193 pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count
, child_count
);
197 struct hlist_node node
;
198 struct device_node
*np
;
201 static void __init
of_selftest_check_phandles(void)
203 struct device_node
*np
;
204 struct node_hash
*nh
;
205 struct hlist_node
*tmp
;
206 int i
, dup_count
= 0, phandle_count
= 0;
207 DECLARE_HASHTABLE(ht
, 8);
210 for_each_of_allnodes(np
) {
214 hash_for_each_possible(ht
, nh
, node
, np
->phandle
) {
215 if (nh
->np
->phandle
== np
->phandle
) {
216 pr_info("Duplicate phandle! %i used by %s and %s\n",
217 np
->phandle
, nh
->np
->full_name
, np
->full_name
);
223 nh
= kzalloc(sizeof(*nh
), GFP_KERNEL
);
228 hash_add(ht
, &nh
->node
, np
->phandle
);
231 selftest(dup_count
== 0, "Found %i duplicates in %i phandles\n",
232 dup_count
, phandle_count
);
235 hash_for_each_safe(ht
, i
, tmp
, nh
, node
) {
241 static void __init
of_selftest_parse_phandle_with_args(void)
243 struct device_node
*np
;
244 struct of_phandle_args args
;
247 np
= of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
249 pr_err("missing testcase data\n");
253 rc
= of_count_phandle_with_args(np
, "phandle-list", "#phandle-cells");
254 selftest(rc
== 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc
);
256 for (i
= 0; i
< 8; i
++) {
258 rc
= of_parse_phandle_with_args(np
, "phandle-list",
259 "#phandle-cells", i
, &args
);
261 /* Test the values from tests-phandle.dtsi */
265 passed
&= (args
.args_count
== 1);
266 passed
&= (args
.args
[0] == (i
+ 1));
270 passed
&= (args
.args_count
== 2);
271 passed
&= (args
.args
[0] == (i
+ 1));
272 passed
&= (args
.args
[1] == 0);
275 passed
&= (rc
== -ENOENT
);
279 passed
&= (args
.args_count
== 3);
280 passed
&= (args
.args
[0] == (i
+ 1));
281 passed
&= (args
.args
[1] == 4);
282 passed
&= (args
.args
[2] == 3);
286 passed
&= (args
.args_count
== 2);
287 passed
&= (args
.args
[0] == (i
+ 1));
288 passed
&= (args
.args
[1] == 100);
292 passed
&= (args
.args_count
== 0);
296 passed
&= (args
.args_count
== 1);
297 passed
&= (args
.args
[0] == (i
+ 1));
300 passed
&= (rc
== -ENOENT
);
306 selftest(passed
, "index %i - data error on node %s rc=%i\n",
307 i
, args
.np
->full_name
, rc
);
310 /* Check for missing list property */
311 rc
= of_parse_phandle_with_args(np
, "phandle-list-missing",
312 "#phandle-cells", 0, &args
);
313 selftest(rc
== -ENOENT
, "expected:%i got:%i\n", -ENOENT
, rc
);
314 rc
= of_count_phandle_with_args(np
, "phandle-list-missing",
316 selftest(rc
== -ENOENT
, "expected:%i got:%i\n", -ENOENT
, rc
);
318 /* Check for missing cells property */
319 rc
= of_parse_phandle_with_args(np
, "phandle-list",
320 "#phandle-cells-missing", 0, &args
);
321 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
322 rc
= of_count_phandle_with_args(np
, "phandle-list",
323 "#phandle-cells-missing");
324 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
326 /* Check for bad phandle in list */
327 rc
= of_parse_phandle_with_args(np
, "phandle-list-bad-phandle",
328 "#phandle-cells", 0, &args
);
329 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
330 rc
= of_count_phandle_with_args(np
, "phandle-list-bad-phandle",
332 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
334 /* Check for incorrectly formed argument list */
335 rc
= of_parse_phandle_with_args(np
, "phandle-list-bad-args",
336 "#phandle-cells", 1, &args
);
337 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
338 rc
= of_count_phandle_with_args(np
, "phandle-list-bad-args",
340 selftest(rc
== -EINVAL
, "expected:%i got:%i\n", -EINVAL
, rc
);
343 static void __init
of_selftest_property_match_string(void)
345 struct device_node
*np
;
348 np
= of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
350 pr_err("No testcase data in device tree\n");
354 rc
= of_property_match_string(np
, "phandle-list-names", "first");
355 selftest(rc
== 0, "first expected:0 got:%i\n", rc
);
356 rc
= of_property_match_string(np
, "phandle-list-names", "second");
357 selftest(rc
== 1, "second expected:0 got:%i\n", rc
);
358 rc
= of_property_match_string(np
, "phandle-list-names", "third");
359 selftest(rc
== 2, "third expected:0 got:%i\n", rc
);
360 rc
= of_property_match_string(np
, "phandle-list-names", "fourth");
361 selftest(rc
== -ENODATA
, "unmatched string; rc=%i", rc
);
362 rc
= of_property_match_string(np
, "missing-property", "blah");
363 selftest(rc
== -EINVAL
, "missing property; rc=%i", rc
);
364 rc
= of_property_match_string(np
, "empty-property", "blah");
365 selftest(rc
== -ENODATA
, "empty property; rc=%i", rc
);
366 rc
= of_property_match_string(np
, "unterminated-string", "blah");
367 selftest(rc
== -EILSEQ
, "unterminated string; rc=%i", rc
);
370 #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
371 (p1)->value && (p2)->value && \
372 !memcmp((p1)->value, (p2)->value, (p1)->length) && \
373 !strcmp((p1)->name, (p2)->name))
374 static void __init
of_selftest_property_copy(void)
376 #ifdef CONFIG_OF_DYNAMIC
377 struct property p1
= { .name
= "p1", .length
= 0, .value
= "" };
378 struct property p2
= { .name
= "p2", .length
= 5, .value
= "abcd" };
379 struct property
*new;
381 new = __of_prop_dup(&p1
, GFP_KERNEL
);
382 selftest(new && propcmp(&p1
, new), "empty property didn't copy correctly\n");
387 new = __of_prop_dup(&p2
, GFP_KERNEL
);
388 selftest(new && propcmp(&p2
, new), "non-empty property didn't copy correctly\n");
395 static void __init
of_selftest_changeset(void)
397 #ifdef CONFIG_OF_DYNAMIC
398 struct property
*ppadd
, padd
= { .name
= "prop-add", .length
= 0, .value
= "" };
399 struct property
*ppupdate
, pupdate
= { .name
= "prop-update", .length
= 5, .value
= "abcd" };
400 struct property
*ppremove
;
401 struct device_node
*n1
, *n2
, *n21
, *nremove
, *parent
;
402 struct of_changeset chgset
;
404 of_changeset_init(&chgset
);
405 n1
= __of_node_alloc("/testcase-data/changeset/n1", GFP_KERNEL
);
406 selftest(n1
, "testcase setup failure\n");
407 n2
= __of_node_alloc("/testcase-data/changeset/n2", GFP_KERNEL
);
408 selftest(n2
, "testcase setup failure\n");
409 n21
= __of_node_alloc("/testcase-data/changeset/n2/n21", GFP_KERNEL
);
410 selftest(n21
, "testcase setup failure %p\n", n21
);
411 nremove
= of_find_node_by_path("/testcase-data/changeset/node-remove");
412 selftest(nremove
, "testcase setup failure\n");
413 ppadd
= __of_prop_dup(&padd
, GFP_KERNEL
);
414 selftest(ppadd
, "testcase setup failure\n");
415 ppupdate
= __of_prop_dup(&pupdate
, GFP_KERNEL
);
416 selftest(ppupdate
, "testcase setup failure\n");
417 parent
= nremove
->parent
;
422 ppremove
= of_find_property(parent
, "prop-remove", NULL
);
423 selftest(ppremove
, "failed to find removal prop");
425 of_changeset_init(&chgset
);
426 selftest(!of_changeset_attach_node(&chgset
, n1
), "fail attach n1\n");
427 selftest(!of_changeset_attach_node(&chgset
, n2
), "fail attach n2\n");
428 selftest(!of_changeset_detach_node(&chgset
, nremove
), "fail remove node\n");
429 selftest(!of_changeset_attach_node(&chgset
, n21
), "fail attach n21\n");
430 selftest(!of_changeset_add_property(&chgset
, parent
, ppadd
), "fail add prop\n");
431 selftest(!of_changeset_update_property(&chgset
, parent
, ppupdate
), "fail update prop\n");
432 selftest(!of_changeset_remove_property(&chgset
, parent
, ppremove
), "fail remove prop\n");
433 mutex_lock(&of_mutex
);
434 selftest(!of_changeset_apply(&chgset
), "apply failed\n");
435 mutex_unlock(&of_mutex
);
437 mutex_lock(&of_mutex
);
438 selftest(!of_changeset_revert(&chgset
), "revert failed\n");
439 mutex_unlock(&of_mutex
);
441 of_changeset_destroy(&chgset
);
445 static void __init
of_selftest_parse_interrupts(void)
447 struct device_node
*np
;
448 struct of_phandle_args args
;
451 np
= of_find_node_by_path("/testcase-data/interrupts/interrupts0");
453 pr_err("missing testcase data\n");
457 for (i
= 0; i
< 4; i
++) {
460 rc
= of_irq_parse_one(np
, i
, &args
);
463 passed
&= (args
.args_count
== 1);
464 passed
&= (args
.args
[0] == (i
+ 1));
466 selftest(passed
, "index %i - data error on node %s rc=%i\n",
467 i
, args
.np
->full_name
, rc
);
471 np
= of_find_node_by_path("/testcase-data/interrupts/interrupts1");
473 pr_err("missing testcase data\n");
477 for (i
= 0; i
< 4; i
++) {
480 rc
= of_irq_parse_one(np
, i
, &args
);
482 /* Test the values from tests-phandle.dtsi */
486 passed
&= (args
.args_count
== 1);
487 passed
&= (args
.args
[0] == 9);
491 passed
&= (args
.args_count
== 3);
492 passed
&= (args
.args
[0] == 10);
493 passed
&= (args
.args
[1] == 11);
494 passed
&= (args
.args
[2] == 12);
498 passed
&= (args
.args_count
== 2);
499 passed
&= (args
.args
[0] == 13);
500 passed
&= (args
.args
[1] == 14);
504 passed
&= (args
.args_count
== 2);
505 passed
&= (args
.args
[0] == 15);
506 passed
&= (args
.args
[1] == 16);
511 selftest(passed
, "index %i - data error on node %s rc=%i\n",
512 i
, args
.np
->full_name
, rc
);
517 static void __init
of_selftest_parse_interrupts_extended(void)
519 struct device_node
*np
;
520 struct of_phandle_args args
;
523 np
= of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0");
525 pr_err("missing testcase data\n");
529 for (i
= 0; i
< 7; i
++) {
531 rc
= of_irq_parse_one(np
, i
, &args
);
533 /* Test the values from tests-phandle.dtsi */
537 passed
&= (args
.args_count
== 1);
538 passed
&= (args
.args
[0] == 1);
542 passed
&= (args
.args_count
== 3);
543 passed
&= (args
.args
[0] == 2);
544 passed
&= (args
.args
[1] == 3);
545 passed
&= (args
.args
[2] == 4);
549 passed
&= (args
.args_count
== 2);
550 passed
&= (args
.args
[0] == 5);
551 passed
&= (args
.args
[1] == 6);
555 passed
&= (args
.args_count
== 1);
556 passed
&= (args
.args
[0] == 9);
560 passed
&= (args
.args_count
== 3);
561 passed
&= (args
.args
[0] == 10);
562 passed
&= (args
.args
[1] == 11);
563 passed
&= (args
.args
[2] == 12);
567 passed
&= (args
.args_count
== 2);
568 passed
&= (args
.args
[0] == 13);
569 passed
&= (args
.args
[1] == 14);
573 passed
&= (args
.args_count
== 1);
574 passed
&= (args
.args
[0] == 15);
580 selftest(passed
, "index %i - data error on node %s rc=%i\n",
581 i
, args
.np
->full_name
, rc
);
586 static struct of_device_id match_node_table
[] = {
587 { .data
= "A", .name
= "name0", }, /* Name alone is lowest priority */
588 { .data
= "B", .type
= "type1", }, /* followed by type alone */
590 { .data
= "Ca", .name
= "name2", .type
= "type1", }, /* followed by both together */
591 { .data
= "Cb", .name
= "name2", }, /* Only match when type doesn't match */
592 { .data
= "Cc", .name
= "name2", .type
= "type2", },
594 { .data
= "E", .compatible
= "compat3" },
595 { .data
= "G", .compatible
= "compat2", },
596 { .data
= "H", .compatible
= "compat2", .name
= "name5", },
597 { .data
= "I", .compatible
= "compat2", .type
= "type1", },
598 { .data
= "J", .compatible
= "compat2", .type
= "type1", .name
= "name8", },
599 { .data
= "K", .compatible
= "compat2", .name
= "name9", },
606 } match_node_tests
[] = {
607 { .path
= "/testcase-data/match-node/name0", .data
= "A", },
608 { .path
= "/testcase-data/match-node/name1", .data
= "B", },
609 { .path
= "/testcase-data/match-node/a/name2", .data
= "Ca", },
610 { .path
= "/testcase-data/match-node/b/name2", .data
= "Cb", },
611 { .path
= "/testcase-data/match-node/c/name2", .data
= "Cc", },
612 { .path
= "/testcase-data/match-node/name3", .data
= "E", },
613 { .path
= "/testcase-data/match-node/name4", .data
= "G", },
614 { .path
= "/testcase-data/match-node/name5", .data
= "H", },
615 { .path
= "/testcase-data/match-node/name6", .data
= "G", },
616 { .path
= "/testcase-data/match-node/name7", .data
= "I", },
617 { .path
= "/testcase-data/match-node/name8", .data
= "J", },
618 { .path
= "/testcase-data/match-node/name9", .data
= "K", },
621 static void __init
of_selftest_match_node(void)
623 struct device_node
*np
;
624 const struct of_device_id
*match
;
627 for (i
= 0; i
< ARRAY_SIZE(match_node_tests
); i
++) {
628 np
= of_find_node_by_path(match_node_tests
[i
].path
);
630 selftest(0, "missing testcase node %s\n",
631 match_node_tests
[i
].path
);
635 match
= of_match_node(match_node_table
, np
);
637 selftest(0, "%s didn't match anything\n",
638 match_node_tests
[i
].path
);
642 if (strcmp(match
->data
, match_node_tests
[i
].data
) != 0) {
643 selftest(0, "%s got wrong match. expected %s, got %s\n",
644 match_node_tests
[i
].path
, match_node_tests
[i
].data
,
645 (const char *)match
->data
);
648 selftest(1, "passed");
652 static void __init
of_selftest_platform_populate(void)
655 struct device_node
*np
, *child
;
656 struct platform_device
*pdev
;
657 struct of_device_id match
[] = {
658 { .compatible
= "test-device", },
662 np
= of_find_node_by_path("/testcase-data");
663 of_platform_populate(np
, of_default_bus_match_table
, NULL
, NULL
);
665 /* Test that a missing irq domain returns -EPROBE_DEFER */
666 np
= of_find_node_by_path("/testcase-data/testcase-device1");
667 pdev
= of_find_device_by_node(np
);
668 selftest(pdev
, "device 1 creation failed\n");
670 irq
= platform_get_irq(pdev
, 0);
671 selftest(irq
== -EPROBE_DEFER
, "device deferred probe failed - %d\n", irq
);
673 /* Test that a parsing failure does not return -EPROBE_DEFER */
674 np
= of_find_node_by_path("/testcase-data/testcase-device2");
675 pdev
= of_find_device_by_node(np
);
676 selftest(pdev
, "device 2 creation failed\n");
677 irq
= platform_get_irq(pdev
, 0);
678 selftest(irq
< 0 && irq
!= -EPROBE_DEFER
, "device parsing error failed - %d\n", irq
);
680 np
= of_find_node_by_path("/testcase-data/platform-tests");
682 pr_err("No testcase data in device tree\n");
686 for_each_child_of_node(np
, child
) {
687 struct device_node
*grandchild
;
688 of_platform_populate(child
, match
, NULL
, NULL
);
689 for_each_child_of_node(child
, grandchild
)
690 selftest(of_find_device_by_node(grandchild
),
691 "Could not create device for node '%s'\n",
697 * update_node_properties - adds the properties
698 * of np into dup node (present in live tree) and
699 * updates parent of children of np to dup.
701 * @np: node already present in live tree
702 * @dup: node present in live tree to be updated
704 static void update_node_properties(struct device_node
*np
,
705 struct device_node
*dup
)
707 struct property
*prop
;
708 struct device_node
*child
;
710 for_each_property_of_node(np
, prop
)
711 of_add_property(dup
, prop
);
713 for_each_child_of_node(np
, child
)
718 * attach_node_and_children - attaches nodes
719 * and its children to live tree
721 * @np: Node to attach to live tree
723 static int attach_node_and_children(struct device_node
*np
)
725 struct device_node
*next
, *root
= np
, *dup
;
729 /* storing a copy in temporary node */
733 if (WARN_ON(last_node_index
>= NO_OF_NODES
))
735 nodes
[last_node_index
++] = dup
;
742 dup
= of_find_node_by_path(np
->full_name
);
744 update_node_properties(np
, dup
);
747 if (np
->parent
== root
)
748 np
->parent
= of_allnodes
;
758 * selftest_data_add - Reads, copies data from
759 * linked tree and attaches it to the live tree
761 static int __init
selftest_data_add(void)
764 struct device_node
*selftest_data_node
, *np
;
765 extern uint8_t __dtb_testcases_begin
[];
766 extern uint8_t __dtb_testcases_end
[];
767 const int size
= __dtb_testcases_end
- __dtb_testcases_begin
;
770 pr_warn("%s: No testcase data to attach; not running tests\n",
776 selftest_data
= kmemdup(__dtb_testcases_begin
, size
, GFP_KERNEL
);
778 if (!selftest_data
) {
779 pr_warn("%s: Failed to allocate memory for selftest_data; "
780 "not running tests\n", __func__
);
783 of_fdt_unflatten_tree(selftest_data
, &selftest_data_node
);
784 if (!selftest_data_node
) {
785 pr_warn("%s: No tree to attach; not running tests\n", __func__
);
790 /* enabling flag for removing nodes */
791 selftest_live_tree
= true;
792 of_allnodes
= selftest_data_node
;
794 for_each_of_allnodes(np
)
795 __of_attach_node_sysfs(np
);
796 of_aliases
= of_find_node_by_path("/aliases");
797 of_chosen
= of_find_node_by_path("/chosen");
801 /* attach the sub-tree to live tree */
802 return attach_node_and_children(selftest_data_node
);
806 * detach_node_and_children - detaches node
807 * and its children from live tree
809 * @np: Node to detach from live tree
811 static void detach_node_and_children(struct device_node
*np
)
814 detach_node_and_children(np
->child
);
819 * selftest_data_remove - removes the selftest data
820 * nodes from the live tree
822 static void selftest_data_remove(void)
824 struct device_node
*np
;
825 struct property
*prop
;
827 if (selftest_live_tree
) {
828 of_node_put(of_aliases
);
829 of_node_put(of_chosen
);
832 for_each_child_of_node(of_allnodes
, np
)
833 detach_node_and_children(np
);
834 __of_detach_node_sysfs(of_allnodes
);
839 while (last_node_index
>= 0) {
840 if (nodes
[last_node_index
]) {
841 np
= of_find_node_by_path(nodes
[last_node_index
]->full_name
);
842 if (strcmp(np
->full_name
, "/aliases") != 0) {
843 detach_node_and_children(np
);
845 for_each_property_of_node(np
, prop
) {
846 if (strcmp(prop
->name
, "testcase-alias") == 0)
847 of_remove_property(np
, prop
);
855 static int __init
of_selftest(void)
857 struct device_node
*np
;
860 /* adding data for selftest */
861 res
= selftest_data_add();
865 np
= of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
867 pr_info("No testcase data in device tree; not running tests\n");
872 pr_info("start of selftest - you will see error messages\n");
873 of_selftest_check_tree_linkage();
874 of_selftest_check_phandles();
875 of_selftest_find_node_by_name();
876 of_selftest_dynamic();
877 of_selftest_parse_phandle_with_args();
878 of_selftest_property_match_string();
879 of_selftest_property_copy();
880 of_selftest_changeset();
881 of_selftest_parse_interrupts();
882 of_selftest_parse_interrupts_extended();
883 of_selftest_match_node();
884 of_selftest_platform_populate();
886 /* removing selftest data from live tree */
887 selftest_data_remove();
889 /* Double check linkage after removing testcase data */
890 of_selftest_check_tree_linkage();
892 pr_info("end of selftest - %i passed, %i failed\n",
893 selftest_results
.passed
, selftest_results
.failed
);
897 late_initcall(of_selftest
);