1 // SPDX-License-Identifier: GPL-2.0
3 * Self tests for device tree subsystem
6 #define pr_fmt(fmt) "### dt-test ### " fmt
8 #include <linux/memblock.h>
10 #include <linux/dma-direct.h> /* to test phys_to_dma/dma_to_phys */
11 #include <linux/err.h>
12 #include <linux/errno.h>
13 #include <linux/hashtable.h>
14 #include <linux/libfdt.h>
16 #include <linux/of_address.h>
17 #include <linux/of_fdt.h>
18 #include <linux/of_irq.h>
19 #include <linux/of_platform.h>
20 #include <linux/list.h>
21 #include <linux/mutex.h>
22 #include <linux/slab.h>
23 #include <linux/device.h>
24 #include <linux/platform_device.h>
25 #include <linux/kernel.h>
27 #include <linux/i2c.h>
28 #include <linux/i2c-mux.h>
29 #include <linux/gpio/driver.h>
31 #include <linux/bitops.h>
33 #include "of_private.h"
35 static struct unittest_results {
40 #define unittest(result, fmt, ...) ({ \
41 bool failed = !(result); \
43 unittest_results.failed++; \
44 pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \
46 unittest_results.passed++; \
47 pr_info("pass %s():%i\n", __func__, __LINE__); \
53 * Expected message may have a message level other than KERN_INFO.
54 * Print the expected message only if the current loglevel will allow
55 * the actual message to print.
57 * Do not use EXPECT_BEGIN(), EXPECT_END(), EXPECT_NOT_BEGIN(), or
58 * EXPECT_NOT_END() to report messages expected to be reported or not
59 * reported by pr_debug().
61 #define EXPECT_BEGIN(level, fmt, ...) \
62 printk(level pr_fmt("EXPECT \\ : ") fmt, ##__VA_ARGS__)
64 #define EXPECT_END(level, fmt, ...) \
65 printk(level pr_fmt("EXPECT / : ") fmt, ##__VA_ARGS__)
67 #define EXPECT_NOT_BEGIN(level, fmt, ...) \
68 printk(level pr_fmt("EXPECT_NOT \\ : ") fmt, ##__VA_ARGS__)
70 #define EXPECT_NOT_END(level, fmt, ...) \
71 printk(level pr_fmt("EXPECT_NOT / : ") fmt, ##__VA_ARGS__)
73 static void __init of_unittest_find_node_by_name(void)
75 struct device_node *np;
76 const char *options, *name;
78 np = of_find_node_by_path("/testcase-data");
79 name = kasprintf(GFP_KERNEL, "%pOF", np);
80 unittest(np && !strcmp("/testcase-data", name),
81 "find /testcase-data failed\n");
85 /* Test if trailing '/' works */
86 np = of_find_node_by_path("/testcase-data/");
87 unittest(!np, "trailing '/' on /testcase-data/ should fail\n");
89 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
90 name = kasprintf(GFP_KERNEL, "%pOF", np);
91 unittest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
92 "find /testcase-data/phandle-tests/consumer-a failed\n");
96 np = of_find_node_by_path("testcase-alias");
97 name = kasprintf(GFP_KERNEL, "%pOF", np);
98 unittest(np && !strcmp("/testcase-data", name),
99 "find testcase-alias failed\n");
103 /* Test if trailing '/' works on aliases */
104 np = of_find_node_by_path("testcase-alias/");
105 unittest(!np, "trailing '/' on testcase-alias/ should fail\n");
107 np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
108 name = kasprintf(GFP_KERNEL, "%pOF", np);
109 unittest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
110 "find testcase-alias/phandle-tests/consumer-a failed\n");
114 np = of_find_node_by_path("/testcase-data/missing-path");
115 unittest(!np, "non-existent path returned node %pOF\n", np);
118 np = of_find_node_by_path("missing-alias");
119 unittest(!np, "non-existent alias returned node %pOF\n", np);
122 np = of_find_node_by_path("testcase-alias/missing-path");
123 unittest(!np, "non-existent alias with relative path returned node %pOF\n", np);
126 np = of_find_node_opts_by_path("/testcase-data:testoption", &options);
127 unittest(np && !strcmp("testoption", options),
128 "option path test failed\n");
131 np = of_find_node_opts_by_path("/testcase-data:test/option", &options);
132 unittest(np && !strcmp("test/option", options),
133 "option path test, subcase #1 failed\n");
136 np = of_find_node_opts_by_path("/testcase-data/testcase-device1:test/option", &options);
137 unittest(np && !strcmp("test/option", options),
138 "option path test, subcase #2 failed\n");
141 np = of_find_node_opts_by_path("/testcase-data:testoption", NULL);
142 unittest(np, "NULL option path test failed\n");
145 np = of_find_node_opts_by_path("testcase-alias:testaliasoption",
147 unittest(np && !strcmp("testaliasoption", options),
148 "option alias path test failed\n");
151 np = of_find_node_opts_by_path("testcase-alias:test/alias/option",
153 unittest(np && !strcmp("test/alias/option", options),
154 "option alias path test, subcase #1 failed\n");
157 np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL);
158 unittest(np, "NULL option alias path test failed\n");
161 options = "testoption";
162 np = of_find_node_opts_by_path("testcase-alias", &options);
163 unittest(np && !options, "option clearing test failed\n");
166 options = "testoption";
167 np = of_find_node_opts_by_path("/", &options);
168 unittest(np && !options, "option clearing root node test failed\n");
172 static void __init of_unittest_dynamic(void)
174 struct device_node *np;
175 struct property *prop;
177 np = of_find_node_by_path("/testcase-data");
179 pr_err("missing testcase data\n");
183 /* Array of 4 properties for the purpose of testing */
184 prop = kcalloc(4, sizeof(*prop), GFP_KERNEL);
186 unittest(0, "kzalloc() failed\n");
190 /* Add a new property - should pass*/
191 prop->name = "new-property";
192 prop->value = "new-property-data";
193 prop->length = strlen(prop->value) + 1;
194 unittest(of_add_property(np, prop) == 0, "Adding a new property failed\n");
196 /* Try to add an existing property - should fail */
198 prop->name = "new-property";
199 prop->value = "new-property-data-should-fail";
200 prop->length = strlen(prop->value) + 1;
201 unittest(of_add_property(np, prop) != 0,
202 "Adding an existing property should have failed\n");
204 /* Try to modify an existing property - should pass */
205 prop->value = "modify-property-data-should-pass";
206 prop->length = strlen(prop->value) + 1;
207 unittest(of_update_property(np, prop) == 0,
208 "Updating an existing property should have passed\n");
210 /* Try to modify non-existent property - should pass*/
212 prop->name = "modify-property";
213 prop->value = "modify-missing-property-data-should-pass";
214 prop->length = strlen(prop->value) + 1;
215 unittest(of_update_property(np, prop) == 0,
216 "Updating a missing property should have passed\n");
218 /* Remove property - should pass */
219 unittest(of_remove_property(np, prop) == 0,
220 "Removing a property should have passed\n");
222 /* Adding very large property - should pass */
224 prop->name = "large-property-PAGE_SIZEx8";
225 prop->length = PAGE_SIZE * 8;
226 prop->value = kzalloc(prop->length, GFP_KERNEL);
227 unittest(prop->value != NULL, "Unable to allocate large buffer\n");
229 unittest(of_add_property(np, prop) == 0,
230 "Adding a large property should have passed\n");
233 static int __init of_unittest_check_node_linkage(struct device_node *np)
235 struct device_node *child;
238 for_each_child_of_node(np, child) {
239 if (child->parent != np) {
240 pr_err("Child node %pOFn links to wrong parent %pOFn\n",
246 rc = of_unittest_check_node_linkage(child);
258 static void __init of_unittest_check_tree_linkage(void)
260 struct device_node *np;
261 int allnode_count = 0, child_count;
266 for_each_of_allnodes(np)
268 child_count = of_unittest_check_node_linkage(of_root);
270 unittest(child_count > 0, "Device node data structure is corrupted\n");
271 unittest(child_count == allnode_count,
272 "allnodes list size (%i) doesn't match sibling lists size (%i)\n",
273 allnode_count, child_count);
274 pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count, child_count);
277 static void __init of_unittest_printf_one(struct device_node *np, const char *fmt,
278 const char *expected)
284 buf_size = strlen(expected) + 10;
285 buf = kmalloc(buf_size, GFP_KERNEL);
289 /* Baseline; check conversion with a large size limit */
290 memset(buf, 0xff, buf_size);
291 size = snprintf(buf, buf_size - 2, fmt, np);
293 /* use strcmp() instead of strncmp() here to be absolutely sure strings match */
294 unittest((strcmp(buf, expected) == 0) && (buf[size+1] == 0xff),
295 "sprintf failed; fmt='%s' expected='%s' rslt='%s'\n",
298 /* Make sure length limits work */
300 for (i = 0; i < 2; i++, size--) {
301 /* Clear the buffer, and make sure it works correctly still */
302 memset(buf, 0xff, buf_size);
303 snprintf(buf, size+1, fmt, np);
304 unittest(strncmp(buf, expected, size) == 0 && (buf[size+1] == 0xff),
305 "snprintf failed; size=%i fmt='%s' expected='%s' rslt='%s'\n",
306 size, fmt, expected, buf);
311 static void __init of_unittest_printf(void)
313 struct device_node *np;
314 const char *full_name = "/testcase-data/platform-tests/test-device@1/dev@100";
315 char phandle_str[16] = "";
317 np = of_find_node_by_path(full_name);
319 unittest(np, "testcase data missing\n");
323 num_to_str(phandle_str, sizeof(phandle_str), np->phandle, 0);
325 of_unittest_printf_one(np, "%pOF", full_name);
326 of_unittest_printf_one(np, "%pOFf", full_name);
327 of_unittest_printf_one(np, "%pOFn", "dev");
328 of_unittest_printf_one(np, "%2pOFn", "dev");
329 of_unittest_printf_one(np, "%5pOFn", " dev");
330 of_unittest_printf_one(np, "%pOFnc", "dev:test-sub-device");
331 of_unittest_printf_one(np, "%pOFp", phandle_str);
332 of_unittest_printf_one(np, "%pOFP", "dev@100");
333 of_unittest_printf_one(np, "ABC %pOFP ABC", "ABC dev@100 ABC");
334 of_unittest_printf_one(np, "%10pOFP", " dev@100");
335 of_unittest_printf_one(np, "%-10pOFP", "dev@100 ");
336 of_unittest_printf_one(of_root, "%pOFP", "/");
337 of_unittest_printf_one(np, "%pOFF", "----");
338 of_unittest_printf_one(np, "%pOFPF", "dev@100:----");
339 of_unittest_printf_one(np, "%pOFPFPc", "dev@100:----:dev@100:test-sub-device");
340 of_unittest_printf_one(np, "%pOFc", "test-sub-device");
341 of_unittest_printf_one(np, "%pOFC",
342 "\"test-sub-device\",\"test-compat2\",\"test-compat3\"");
346 struct hlist_node node;
347 struct device_node *np;
350 static DEFINE_HASHTABLE(phandle_ht, 8);
351 static void __init of_unittest_check_phandles(void)
353 struct device_node *np;
354 struct node_hash *nh;
355 struct hlist_node *tmp;
356 int i, dup_count = 0, phandle_count = 0;
358 for_each_of_allnodes(np) {
362 hash_for_each_possible(phandle_ht, nh, node, np->phandle) {
363 if (nh->np->phandle == np->phandle) {
364 pr_info("Duplicate phandle! %i used by %pOF and %pOF\n",
365 np->phandle, nh->np, np);
371 nh = kzalloc(sizeof(*nh), GFP_KERNEL);
376 hash_add(phandle_ht, &nh->node, np->phandle);
379 unittest(dup_count == 0, "Found %i duplicates in %i phandles\n",
380 dup_count, phandle_count);
383 hash_for_each_safe(phandle_ht, i, tmp, nh, node) {
389 static void __init of_unittest_parse_phandle_with_args(void)
391 struct device_node *np;
392 struct of_phandle_args args;
395 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
397 pr_err("missing testcase data\n");
401 rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
402 unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc);
404 for (i = 0; i < 8; i++) {
407 memset(&args, 0, sizeof(args));
408 rc = of_parse_phandle_with_args(np, "phandle-list",
409 "#phandle-cells", i, &args);
411 /* Test the values from tests-phandle.dtsi */
415 passed &= (args.args_count == 1);
416 passed &= (args.args[0] == (i + 1));
420 passed &= (args.args_count == 2);
421 passed &= (args.args[0] == (i + 1));
422 passed &= (args.args[1] == 0);
425 passed &= (rc == -ENOENT);
429 passed &= (args.args_count == 3);
430 passed &= (args.args[0] == (i + 1));
431 passed &= (args.args[1] == 4);
432 passed &= (args.args[2] == 3);
436 passed &= (args.args_count == 2);
437 passed &= (args.args[0] == (i + 1));
438 passed &= (args.args[1] == 100);
442 passed &= (args.args_count == 0);
446 passed &= (args.args_count == 1);
447 passed &= (args.args[0] == (i + 1));
450 passed &= (rc == -ENOENT);
456 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
460 /* Check for missing list property */
461 memset(&args, 0, sizeof(args));
462 rc = of_parse_phandle_with_args(np, "phandle-list-missing",
463 "#phandle-cells", 0, &args);
464 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
465 rc = of_count_phandle_with_args(np, "phandle-list-missing",
467 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
469 /* Check for missing cells property */
470 memset(&args, 0, sizeof(args));
472 EXPECT_BEGIN(KERN_INFO,
473 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
475 rc = of_parse_phandle_with_args(np, "phandle-list",
476 "#phandle-cells-missing", 0, &args);
478 EXPECT_END(KERN_INFO,
479 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
481 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
483 EXPECT_BEGIN(KERN_INFO,
484 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
486 rc = of_count_phandle_with_args(np, "phandle-list",
487 "#phandle-cells-missing");
489 EXPECT_END(KERN_INFO,
490 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
492 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
494 /* Check for bad phandle in list */
495 memset(&args, 0, sizeof(args));
497 EXPECT_BEGIN(KERN_INFO,
498 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
500 rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
501 "#phandle-cells", 0, &args);
503 EXPECT_END(KERN_INFO,
504 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
506 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
508 EXPECT_BEGIN(KERN_INFO,
509 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
511 rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle",
514 EXPECT_END(KERN_INFO,
515 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
517 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
519 /* Check for incorrectly formed argument list */
520 memset(&args, 0, sizeof(args));
522 EXPECT_BEGIN(KERN_INFO,
523 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
525 rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
526 "#phandle-cells", 1, &args);
528 EXPECT_END(KERN_INFO,
529 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
531 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
533 EXPECT_BEGIN(KERN_INFO,
534 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
536 rc = of_count_phandle_with_args(np, "phandle-list-bad-args",
539 EXPECT_END(KERN_INFO,
540 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
542 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
545 static void __init of_unittest_parse_phandle_with_args_map(void)
547 struct device_node *np, *p0, *p1, *p2, *p3;
548 struct of_phandle_args args;
551 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-b");
553 pr_err("missing testcase data\n");
557 p0 = of_find_node_by_path("/testcase-data/phandle-tests/provider0");
559 pr_err("missing testcase data\n");
563 p1 = of_find_node_by_path("/testcase-data/phandle-tests/provider1");
565 pr_err("missing testcase data\n");
569 p2 = of_find_node_by_path("/testcase-data/phandle-tests/provider2");
571 pr_err("missing testcase data\n");
575 p3 = of_find_node_by_path("/testcase-data/phandle-tests/provider3");
577 pr_err("missing testcase data\n");
581 rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
582 unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc);
584 for (i = 0; i < 8; i++) {
587 memset(&args, 0, sizeof(args));
588 rc = of_parse_phandle_with_args_map(np, "phandle-list",
589 "phandle", i, &args);
591 /* Test the values from tests-phandle.dtsi */
595 passed &= (args.np == p1);
596 passed &= (args.args_count == 1);
597 passed &= (args.args[0] == 1);
601 passed &= (args.np == p3);
602 passed &= (args.args_count == 3);
603 passed &= (args.args[0] == 2);
604 passed &= (args.args[1] == 5);
605 passed &= (args.args[2] == 3);
608 passed &= (rc == -ENOENT);
612 passed &= (args.np == p0);
613 passed &= (args.args_count == 0);
617 passed &= (args.np == p1);
618 passed &= (args.args_count == 1);
619 passed &= (args.args[0] == 3);
623 passed &= (args.np == p0);
624 passed &= (args.args_count == 0);
628 passed &= (args.np == p2);
629 passed &= (args.args_count == 2);
630 passed &= (args.args[0] == 15);
631 passed &= (args.args[1] == 0x20);
634 passed &= (rc == -ENOENT);
640 unittest(passed, "index %i - data error on node %s rc=%i\n",
641 i, args.np->full_name, rc);
644 /* Check for missing list property */
645 memset(&args, 0, sizeof(args));
646 rc = of_parse_phandle_with_args_map(np, "phandle-list-missing",
647 "phandle", 0, &args);
648 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
650 /* Check for missing cells,map,mask property */
651 memset(&args, 0, sizeof(args));
653 EXPECT_BEGIN(KERN_INFO,
654 "OF: /testcase-data/phandle-tests/consumer-b: could not get #phandle-missing-cells for /testcase-data/phandle-tests/provider1");
656 rc = of_parse_phandle_with_args_map(np, "phandle-list",
657 "phandle-missing", 0, &args);
658 EXPECT_END(KERN_INFO,
659 "OF: /testcase-data/phandle-tests/consumer-b: could not get #phandle-missing-cells for /testcase-data/phandle-tests/provider1");
661 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
663 /* Check for bad phandle in list */
664 memset(&args, 0, sizeof(args));
666 EXPECT_BEGIN(KERN_INFO,
667 "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle");
669 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle",
670 "phandle", 0, &args);
671 EXPECT_END(KERN_INFO,
672 "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle");
674 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
676 /* Check for incorrectly formed argument list */
677 memset(&args, 0, sizeof(args));
679 EXPECT_BEGIN(KERN_INFO,
680 "OF: /testcase-data/phandle-tests/consumer-b: #phandle-cells = 2 found 1");
682 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args",
683 "phandle", 1, &args);
684 EXPECT_END(KERN_INFO,
685 "OF: /testcase-data/phandle-tests/consumer-b: #phandle-cells = 2 found 1");
687 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
690 static void __init of_unittest_property_string(void)
692 const char *strings[4];
693 struct device_node *np;
696 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
698 pr_err("No testcase data in device tree\n");
702 rc = of_property_match_string(np, "phandle-list-names", "first");
703 unittest(rc == 0, "first expected:0 got:%i\n", rc);
704 rc = of_property_match_string(np, "phandle-list-names", "second");
705 unittest(rc == 1, "second expected:1 got:%i\n", rc);
706 rc = of_property_match_string(np, "phandle-list-names", "third");
707 unittest(rc == 2, "third expected:2 got:%i\n", rc);
708 rc = of_property_match_string(np, "phandle-list-names", "fourth");
709 unittest(rc == -ENODATA, "unmatched string; rc=%i\n", rc);
710 rc = of_property_match_string(np, "missing-property", "blah");
711 unittest(rc == -EINVAL, "missing property; rc=%i\n", rc);
712 rc = of_property_match_string(np, "empty-property", "blah");
713 unittest(rc == -ENODATA, "empty property; rc=%i\n", rc);
714 rc = of_property_match_string(np, "unterminated-string", "blah");
715 unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
717 /* of_property_count_strings() tests */
718 rc = of_property_count_strings(np, "string-property");
719 unittest(rc == 1, "Incorrect string count; rc=%i\n", rc);
720 rc = of_property_count_strings(np, "phandle-list-names");
721 unittest(rc == 3, "Incorrect string count; rc=%i\n", rc);
722 rc = of_property_count_strings(np, "unterminated-string");
723 unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
724 rc = of_property_count_strings(np, "unterminated-string-list");
725 unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
727 /* of_property_read_string_index() tests */
728 rc = of_property_read_string_index(np, "string-property", 0, strings);
729 unittest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc);
731 rc = of_property_read_string_index(np, "string-property", 1, strings);
732 unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
733 rc = of_property_read_string_index(np, "phandle-list-names", 0, strings);
734 unittest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
735 rc = of_property_read_string_index(np, "phandle-list-names", 1, strings);
736 unittest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc);
737 rc = of_property_read_string_index(np, "phandle-list-names", 2, strings);
738 unittest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc);
740 rc = of_property_read_string_index(np, "phandle-list-names", 3, strings);
741 unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
743 rc = of_property_read_string_index(np, "unterminated-string", 0, strings);
744 unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
745 rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings);
746 unittest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
748 rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */
749 unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
752 /* of_property_read_string_array() tests */
753 rc = of_property_read_string_array(np, "string-property", strings, 4);
754 unittest(rc == 1, "Incorrect string count; rc=%i\n", rc);
755 rc = of_property_read_string_array(np, "phandle-list-names", strings, 4);
756 unittest(rc == 3, "Incorrect string count; rc=%i\n", rc);
757 rc = of_property_read_string_array(np, "unterminated-string", strings, 4);
758 unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
759 /* -- An incorrectly formed string should cause a failure */
760 rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4);
761 unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
762 /* -- parsing the correctly formed strings should still work: */
764 rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2);
765 unittest(rc == 2 && strings[2] == NULL, "of_property_read_string_array() failure; rc=%i\n", rc);
767 rc = of_property_read_string_array(np, "phandle-list-names", strings, 1);
768 unittest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]);
771 #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
772 (p1)->value && (p2)->value && \
773 !memcmp((p1)->value, (p2)->value, (p1)->length) && \
774 !strcmp((p1)->name, (p2)->name))
775 static void __init of_unittest_property_copy(void)
777 #ifdef CONFIG_OF_DYNAMIC
778 struct property p1 = { .name = "p1", .length = 0, .value = "" };
779 struct property p2 = { .name = "p2", .length = 5, .value = "abcd" };
780 struct property *new;
782 new = __of_prop_dup(&p1, GFP_KERNEL);
783 unittest(new && propcmp(&p1, new), "empty property didn't copy correctly\n");
788 new = __of_prop_dup(&p2, GFP_KERNEL);
789 unittest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
796 static void __init of_unittest_changeset(void)
798 #ifdef CONFIG_OF_DYNAMIC
799 struct property *ppadd, padd = { .name = "prop-add", .length = 1, .value = "" };
800 struct property *ppname_n1, pname_n1 = { .name = "name", .length = 3, .value = "n1" };
801 struct property *ppname_n2, pname_n2 = { .name = "name", .length = 3, .value = "n2" };
802 struct property *ppname_n21, pname_n21 = { .name = "name", .length = 3, .value = "n21" };
803 struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" };
804 struct property *ppremove;
805 struct device_node *n1, *n2, *n21, *nchangeset, *nremove, *parent, *np;
806 struct of_changeset chgset;
808 n1 = __of_node_dup(NULL, "n1");
809 unittest(n1, "testcase setup failure\n");
811 n2 = __of_node_dup(NULL, "n2");
812 unittest(n2, "testcase setup failure\n");
814 n21 = __of_node_dup(NULL, "n21");
815 unittest(n21, "testcase setup failure %p\n", n21);
817 nchangeset = of_find_node_by_path("/testcase-data/changeset");
818 nremove = of_get_child_by_name(nchangeset, "node-remove");
819 unittest(nremove, "testcase setup failure\n");
821 ppadd = __of_prop_dup(&padd, GFP_KERNEL);
822 unittest(ppadd, "testcase setup failure\n");
824 ppname_n1 = __of_prop_dup(&pname_n1, GFP_KERNEL);
825 unittest(ppname_n1, "testcase setup failure\n");
827 ppname_n2 = __of_prop_dup(&pname_n2, GFP_KERNEL);
828 unittest(ppname_n2, "testcase setup failure\n");
830 ppname_n21 = __of_prop_dup(&pname_n21, GFP_KERNEL);
831 unittest(ppname_n21, "testcase setup failure\n");
833 ppupdate = __of_prop_dup(&pupdate, GFP_KERNEL);
834 unittest(ppupdate, "testcase setup failure\n");
841 ppremove = of_find_property(parent, "prop-remove", NULL);
842 unittest(ppremove, "failed to find removal prop");
844 of_changeset_init(&chgset);
846 unittest(!of_changeset_attach_node(&chgset, n1), "fail attach n1\n");
847 unittest(!of_changeset_add_property(&chgset, n1, ppname_n1), "fail add prop name\n");
849 unittest(!of_changeset_attach_node(&chgset, n2), "fail attach n2\n");
850 unittest(!of_changeset_add_property(&chgset, n2, ppname_n2), "fail add prop name\n");
852 unittest(!of_changeset_detach_node(&chgset, nremove), "fail remove node\n");
853 unittest(!of_changeset_add_property(&chgset, n21, ppname_n21), "fail add prop name\n");
855 unittest(!of_changeset_attach_node(&chgset, n21), "fail attach n21\n");
857 unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop prop-add\n");
858 unittest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n");
859 unittest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n");
861 unittest(!of_changeset_apply(&chgset), "apply failed\n");
863 of_node_put(nchangeset);
865 /* Make sure node names are constructed correctly */
866 unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")),
867 "'%pOF' not added\n", n21);
870 unittest(!of_changeset_revert(&chgset), "revert failed\n");
872 of_changeset_destroy(&chgset);
880 static void __init of_unittest_dma_get_max_cpu_address(void)
882 struct device_node *np;
883 phys_addr_t cpu_addr;
885 if (!IS_ENABLED(CONFIG_OF_ADDRESS))
888 np = of_find_node_by_path("/testcase-data/address-tests");
890 pr_err("missing testcase data\n");
894 cpu_addr = of_dma_get_max_cpu_address(np);
895 unittest(cpu_addr == 0x4fffffff,
896 "of_dma_get_max_cpu_address: wrong CPU addr %pad (expecting %x)\n",
897 &cpu_addr, 0x4fffffff);
900 static void __init of_unittest_dma_ranges_one(const char *path,
901 u64 expect_dma_addr, u64 expect_paddr)
903 #ifdef CONFIG_HAS_DMA
904 struct device_node *np;
905 const struct bus_dma_region *map = NULL;
908 np = of_find_node_by_path(path);
910 pr_err("missing testcase data\n");
914 rc = of_dma_get_range(np, &map);
916 unittest(!rc, "of_dma_get_range failed on node %pOF rc=%i\n", np, rc);
921 struct device *dev_bogus;
923 dev_bogus = kzalloc(sizeof(struct device), GFP_KERNEL);
925 unittest(0, "kzalloc() failed\n");
930 dev_bogus->dma_range_map = map;
931 paddr = dma_to_phys(dev_bogus, expect_dma_addr);
932 dma_addr = phys_to_dma(dev_bogus, expect_paddr);
934 unittest(paddr == expect_paddr,
935 "of_dma_get_range: wrong phys addr %pap (expecting %llx) on node %pOF\n",
936 &paddr, expect_paddr, np);
937 unittest(dma_addr == expect_dma_addr,
938 "of_dma_get_range: wrong DMA addr %pad (expecting %llx) on node %pOF\n",
939 &dma_addr, expect_dma_addr, np);
948 static void __init of_unittest_parse_dma_ranges(void)
950 of_unittest_dma_ranges_one("/testcase-data/address-tests/device@70000000",
952 if (IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT))
953 of_unittest_dma_ranges_one("/testcase-data/address-tests/bus@80000000/device@1000",
954 0x100000000, 0x20000000);
955 of_unittest_dma_ranges_one("/testcase-data/address-tests/pci@90000000",
956 0x80000000, 0x20000000);
959 static void __init of_unittest_pci_dma_ranges(void)
961 struct device_node *np;
962 struct of_pci_range range;
963 struct of_pci_range_parser parser;
966 if (!IS_ENABLED(CONFIG_PCI))
969 np = of_find_node_by_path("/testcase-data/address-tests/pci@90000000");
971 pr_err("missing testcase data\n");
975 if (of_pci_dma_range_parser_init(&parser, np)) {
976 pr_err("missing dma-ranges property\n");
981 * Get the dma-ranges from the device tree
983 for_each_of_pci_range(&parser, &range) {
985 unittest(range.size == 0x10000000,
986 "for_each_of_pci_range wrong size on node %pOF size=%llx\n",
988 unittest(range.cpu_addr == 0x20000000,
989 "for_each_of_pci_range wrong CPU addr (%llx) on node %pOF",
991 unittest(range.pci_addr == 0x80000000,
992 "for_each_of_pci_range wrong DMA addr (%llx) on node %pOF",
995 unittest(range.size == 0x10000000,
996 "for_each_of_pci_range wrong size on node %pOF size=%llx\n",
998 unittest(range.cpu_addr == 0x40000000,
999 "for_each_of_pci_range wrong CPU addr (%llx) on node %pOF",
1000 range.cpu_addr, np);
1001 unittest(range.pci_addr == 0xc0000000,
1002 "for_each_of_pci_range wrong DMA addr (%llx) on node %pOF",
1003 range.pci_addr, np);
1011 static void __init of_unittest_bus_ranges(void)
1013 struct device_node *np;
1014 struct of_range range;
1015 struct of_range_parser parser;
1016 struct resource res;
1017 int ret, count, i = 0;
1019 np = of_find_node_by_path("/testcase-data/address-tests");
1021 pr_err("missing testcase data\n");
1025 if (of_range_parser_init(&parser, np)) {
1026 pr_err("missing ranges property\n");
1030 ret = of_range_to_resource(np, 1, &res);
1031 unittest(!ret, "of_range_to_resource returned error (%d) node %pOF\n",
1033 unittest(resource_type(&res) == IORESOURCE_MEM,
1034 "of_range_to_resource wrong resource type on node %pOF res=%pR\n",
1036 unittest(res.start == 0xd0000000,
1037 "of_range_to_resource wrong resource start address on node %pOF res=%pR\n",
1039 unittest(resource_size(&res) == 0x20000000,
1040 "of_range_to_resource wrong resource start address on node %pOF res=%pR\n",
1043 count = of_range_count(&parser);
1044 unittest(count == 2,
1045 "of_range_count wrong size on node %pOF count=%d\n",
1049 * Get the "ranges" from the device tree
1051 for_each_of_range(&parser, &range) {
1052 unittest(range.flags == IORESOURCE_MEM,
1053 "for_each_of_range wrong flags on node %pOF flags=%x (expected %x)\n",
1054 np, range.flags, IORESOURCE_MEM);
1056 unittest(range.size == 0x50000000,
1057 "for_each_of_range wrong size on node %pOF size=%llx\n",
1059 unittest(range.cpu_addr == 0x70000000,
1060 "for_each_of_range wrong CPU addr (%llx) on node %pOF",
1061 range.cpu_addr, np);
1062 unittest(range.bus_addr == 0x70000000,
1063 "for_each_of_range wrong bus addr (%llx) on node %pOF",
1064 range.pci_addr, np);
1066 unittest(range.size == 0x20000000,
1067 "for_each_of_range wrong size on node %pOF size=%llx\n",
1069 unittest(range.cpu_addr == 0xd0000000,
1070 "for_each_of_range wrong CPU addr (%llx) on node %pOF",
1071 range.cpu_addr, np);
1072 unittest(range.bus_addr == 0x00000000,
1073 "for_each_of_range wrong bus addr (%llx) on node %pOF",
1074 range.pci_addr, np);
1082 static void __init of_unittest_bus_3cell_ranges(void)
1084 struct device_node *np;
1085 struct of_range range;
1086 struct of_range_parser parser;
1089 np = of_find_node_by_path("/testcase-data/address-tests/bus@a0000000");
1091 pr_err("missing testcase data\n");
1095 if (of_range_parser_init(&parser, np)) {
1096 pr_err("missing ranges property\n");
1101 * Get the "ranges" from the device tree
1103 for_each_of_range(&parser, &range) {
1105 unittest(range.flags == 0xf00baa,
1106 "for_each_of_range wrong flags on node %pOF flags=%x\n",
1108 unittest(range.size == 0x100000,
1109 "for_each_of_range wrong size on node %pOF size=%llx\n",
1111 unittest(range.cpu_addr == 0xa0000000,
1112 "for_each_of_range wrong CPU addr (%llx) on node %pOF",
1113 range.cpu_addr, np);
1114 unittest(range.bus_addr == 0x0,
1115 "for_each_of_range wrong bus addr (%llx) on node %pOF",
1116 range.pci_addr, np);
1118 unittest(range.flags == 0xf00bee,
1119 "for_each_of_range wrong flags on node %pOF flags=%x\n",
1121 unittest(range.size == 0x200000,
1122 "for_each_of_range wrong size on node %pOF size=%llx\n",
1124 unittest(range.cpu_addr == 0xb0000000,
1125 "for_each_of_range wrong CPU addr (%llx) on node %pOF",
1126 range.cpu_addr, np);
1127 unittest(range.bus_addr == 0x100000000,
1128 "for_each_of_range wrong bus addr (%llx) on node %pOF",
1129 range.pci_addr, np);
1137 static void __init of_unittest_reg(void)
1139 struct device_node *np;
1143 np = of_find_node_by_path("/testcase-data/address-tests/bus@80000000/device@1000");
1145 pr_err("missing testcase data\n");
1149 ret = of_property_read_reg(np, 0, &addr, &size);
1150 unittest(!ret, "of_property_read_reg(%pOF) returned error %d\n",
1152 unittest(addr == 0x1000, "of_property_read_reg(%pOF) untranslated address (%llx) incorrect\n",
1158 static void __init of_unittest_parse_interrupts(void)
1160 struct device_node *np;
1161 struct of_phandle_args args;
1164 if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC)
1167 np = of_find_node_by_path("/testcase-data/interrupts/interrupts0");
1169 pr_err("missing testcase data\n");
1173 for (i = 0; i < 4; i++) {
1176 memset(&args, 0, sizeof(args));
1177 rc = of_irq_parse_one(np, i, &args);
1180 passed &= (args.args_count == 1);
1181 passed &= (args.args[0] == (i + 1));
1183 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
1188 np = of_find_node_by_path("/testcase-data/interrupts/interrupts1");
1190 pr_err("missing testcase data\n");
1194 for (i = 0; i < 4; i++) {
1197 memset(&args, 0, sizeof(args));
1198 rc = of_irq_parse_one(np, i, &args);
1200 /* Test the values from tests-phandle.dtsi */
1204 passed &= (args.args_count == 1);
1205 passed &= (args.args[0] == 9);
1209 passed &= (args.args_count == 3);
1210 passed &= (args.args[0] == 10);
1211 passed &= (args.args[1] == 11);
1212 passed &= (args.args[2] == 12);
1216 passed &= (args.args_count == 2);
1217 passed &= (args.args[0] == 13);
1218 passed &= (args.args[1] == 14);
1222 passed &= (args.args_count == 2);
1223 passed &= (args.args[0] == 15);
1224 passed &= (args.args[1] == 16);
1229 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
1235 static void __init of_unittest_parse_interrupts_extended(void)
1237 struct device_node *np;
1238 struct of_phandle_args args;
1241 if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC)
1244 np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0");
1246 pr_err("missing testcase data\n");
1250 for (i = 0; i < 7; i++) {
1253 memset(&args, 0, sizeof(args));
1254 rc = of_irq_parse_one(np, i, &args);
1256 /* Test the values from tests-phandle.dtsi */
1260 passed &= (args.args_count == 1);
1261 passed &= (args.args[0] == 1);
1265 passed &= (args.args_count == 3);
1266 passed &= (args.args[0] == 2);
1267 passed &= (args.args[1] == 3);
1268 passed &= (args.args[2] == 4);
1272 passed &= (args.args_count == 2);
1273 passed &= (args.args[0] == 5);
1274 passed &= (args.args[1] == 6);
1278 passed &= (args.args_count == 1);
1279 passed &= (args.args[0] == 9);
1283 passed &= (args.args_count == 3);
1284 passed &= (args.args[0] == 10);
1285 passed &= (args.args[1] == 11);
1286 passed &= (args.args[2] == 12);
1290 passed &= (args.args_count == 2);
1291 passed &= (args.args[0] == 13);
1292 passed &= (args.args[1] == 14);
1296 * Tests child node that is missing property
1297 * #address-cells. See the comments in
1298 * drivers/of/unittest-data/tests-interrupts.dtsi
1299 * nodes intmap1 and interrupts-extended0
1302 passed &= (args.args_count == 1);
1303 passed &= (args.args[0] == 15);
1309 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
1315 static const struct of_device_id match_node_table[] = {
1316 { .data = "A", .name = "name0", }, /* Name alone is lowest priority */
1317 { .data = "B", .type = "type1", }, /* followed by type alone */
1319 { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */
1320 { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */
1321 { .data = "Cc", .name = "name2", .type = "type2", },
1323 { .data = "E", .compatible = "compat3" },
1324 { .data = "G", .compatible = "compat2", },
1325 { .data = "H", .compatible = "compat2", .name = "name5", },
1326 { .data = "I", .compatible = "compat2", .type = "type1", },
1327 { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", },
1328 { .data = "K", .compatible = "compat2", .name = "name9", },
1335 } match_node_tests[] = {
1336 { .path = "/testcase-data/match-node/name0", .data = "A", },
1337 { .path = "/testcase-data/match-node/name1", .data = "B", },
1338 { .path = "/testcase-data/match-node/a/name2", .data = "Ca", },
1339 { .path = "/testcase-data/match-node/b/name2", .data = "Cb", },
1340 { .path = "/testcase-data/match-node/c/name2", .data = "Cc", },
1341 { .path = "/testcase-data/match-node/name3", .data = "E", },
1342 { .path = "/testcase-data/match-node/name4", .data = "G", },
1343 { .path = "/testcase-data/match-node/name5", .data = "H", },
1344 { .path = "/testcase-data/match-node/name6", .data = "G", },
1345 { .path = "/testcase-data/match-node/name7", .data = "I", },
1346 { .path = "/testcase-data/match-node/name8", .data = "J", },
1347 { .path = "/testcase-data/match-node/name9", .data = "K", },
1350 static void __init of_unittest_match_node(void)
1352 struct device_node *np;
1353 const struct of_device_id *match;
1356 for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) {
1357 np = of_find_node_by_path(match_node_tests[i].path);
1359 unittest(0, "missing testcase node %s\n",
1360 match_node_tests[i].path);
1364 match = of_match_node(match_node_table, np);
1366 unittest(0, "%s didn't match anything\n",
1367 match_node_tests[i].path);
1371 if (strcmp(match->data, match_node_tests[i].data) != 0) {
1372 unittest(0, "%s got wrong match. expected %s, got %s\n",
1373 match_node_tests[i].path, match_node_tests[i].data,
1374 (const char *)match->data);
1377 unittest(1, "passed");
1381 static struct resource test_bus_res = DEFINE_RES_MEM(0xfffffff8, 2);
1382 static const struct platform_device_info test_bus_info = {
1383 .name = "unittest-bus",
1385 static void __init of_unittest_platform_populate(void)
1388 struct device_node *np, *child, *grandchild;
1389 struct platform_device *pdev, *test_bus;
1390 const struct of_device_id match[] = {
1391 { .compatible = "test-device", },
1395 np = of_find_node_by_path("/testcase-data");
1396 of_platform_default_populate(np, NULL, NULL);
1398 /* Test that a missing irq domain returns -EPROBE_DEFER */
1399 np = of_find_node_by_path("/testcase-data/testcase-device1");
1400 pdev = of_find_device_by_node(np);
1401 unittest(pdev, "device 1 creation failed\n");
1403 if (!(of_irq_workarounds & OF_IMAP_OLDWORLD_MAC)) {
1404 irq = platform_get_irq(pdev, 0);
1405 unittest(irq == -EPROBE_DEFER,
1406 "device deferred probe failed - %d\n", irq);
1408 /* Test that a parsing failure does not return -EPROBE_DEFER */
1409 np = of_find_node_by_path("/testcase-data/testcase-device2");
1410 pdev = of_find_device_by_node(np);
1411 unittest(pdev, "device 2 creation failed\n");
1413 EXPECT_BEGIN(KERN_INFO,
1414 "platform testcase-data:testcase-device2: error -ENXIO: IRQ index 0 not found");
1416 irq = platform_get_irq(pdev, 0);
1418 EXPECT_END(KERN_INFO,
1419 "platform testcase-data:testcase-device2: error -ENXIO: IRQ index 0 not found");
1421 unittest(irq < 0 && irq != -EPROBE_DEFER,
1422 "device parsing error failed - %d\n", irq);
1425 np = of_find_node_by_path("/testcase-data/platform-tests");
1426 unittest(np, "No testcase data in device tree\n");
1430 test_bus = platform_device_register_full(&test_bus_info);
1431 rc = PTR_ERR_OR_ZERO(test_bus);
1432 unittest(!rc, "testbus registration failed; rc=%i\n", rc);
1437 test_bus->dev.of_node = np;
1440 * Add a dummy resource to the test bus node after it is
1441 * registered to catch problems with un-inserted resources. The
1442 * DT code doesn't insert the resources, and it has caused the
1443 * kernel to oops in the past. This makes sure the same bug
1444 * doesn't crop up again.
1446 platform_device_add_resources(test_bus, &test_bus_res, 1);
1448 of_platform_populate(np, match, NULL, &test_bus->dev);
1449 for_each_child_of_node(np, child) {
1450 for_each_child_of_node(child, grandchild) {
1451 pdev = of_find_device_by_node(grandchild);
1453 "Could not create device for node '%pOFn'\n",
1455 platform_device_put(pdev);
1459 of_platform_depopulate(&test_bus->dev);
1460 for_each_child_of_node(np, child) {
1461 for_each_child_of_node(child, grandchild)
1462 unittest(!of_find_device_by_node(grandchild),
1463 "device didn't get destroyed '%pOFn'\n",
1467 platform_device_unregister(test_bus);
1472 * update_node_properties - adds the properties
1473 * of np into dup node (present in live tree) and
1474 * updates parent of children of np to dup.
1476 * @np: node whose properties are being added to the live tree
1477 * @dup: node present in live tree to be updated
1479 static void update_node_properties(struct device_node *np,
1480 struct device_node *dup)
1482 struct property *prop;
1483 struct property *save_next;
1484 struct device_node *child;
1487 for_each_child_of_node(np, child)
1488 child->parent = dup;
1491 * "unittest internal error: unable to add testdata property"
1493 * If this message reports a property in node '/__symbols__' then
1494 * the respective unittest overlay contains a label that has the
1495 * same name as a label in the live devicetree. The label will
1496 * be in the live devicetree only if the devicetree source was
1497 * compiled with the '-@' option. If you encounter this error,
1498 * please consider renaming __all__ of the labels in the unittest
1499 * overlay dts files with an odd prefix that is unlikely to be
1500 * used in a real devicetree.
1504 * open code for_each_property_of_node() because of_add_property()
1505 * sets prop->next to NULL
1507 for (prop = np->properties; prop != NULL; prop = save_next) {
1508 save_next = prop->next;
1509 ret = of_add_property(dup, prop);
1511 if (ret == -EEXIST && !strcmp(prop->name, "name"))
1513 pr_err("unittest internal error: unable to add testdata property %pOF/%s",
1520 * attach_node_and_children - attaches nodes
1521 * and its children to live tree.
1522 * CAUTION: misleading function name - if node @np already exists in
1523 * the live tree then children of @np are *not* attached to the live
1524 * tree. This works for the current test devicetree nodes because such
1525 * nodes do not have child nodes.
1527 * @np: Node to attach to live tree
1529 static void attach_node_and_children(struct device_node *np)
1531 struct device_node *next, *dup, *child;
1532 unsigned long flags;
1533 const char *full_name;
1535 full_name = kasprintf(GFP_KERNEL, "%pOF", np);
1537 if (!strcmp(full_name, "/__local_fixups__") ||
1538 !strcmp(full_name, "/__fixups__")) {
1543 dup = of_find_node_by_path(full_name);
1546 update_node_properties(np, dup);
1553 mutex_lock(&of_mutex);
1554 raw_spin_lock_irqsave(&devtree_lock, flags);
1555 np->sibling = np->parent->child;
1556 np->parent->child = np;
1557 of_node_clear_flag(np, OF_DETACHED);
1558 raw_spin_unlock_irqrestore(&devtree_lock, flags);
1560 __of_attach_node_sysfs(np);
1561 mutex_unlock(&of_mutex);
1564 next = child->sibling;
1565 attach_node_and_children(child);
1571 * unittest_data_add - Reads, copies data from
1572 * linked tree and attaches it to the live tree
1574 static int __init unittest_data_add(void)
1576 void *unittest_data;
1577 void *unittest_data_align;
1578 struct device_node *unittest_data_node = NULL, *np;
1580 * __dtbo_testcases_begin[] and __dtbo_testcases_end[] are magically
1581 * created by cmd_dt_S_dtbo in scripts/Makefile.lib
1583 extern uint8_t __dtbo_testcases_begin[];
1584 extern uint8_t __dtbo_testcases_end[];
1585 const int size = __dtbo_testcases_end - __dtbo_testcases_begin;
1590 pr_warn("%s: testcases is empty\n", __func__);
1595 unittest_data = kmalloc(size + FDT_ALIGN_SIZE, GFP_KERNEL);
1599 unittest_data_align = PTR_ALIGN(unittest_data, FDT_ALIGN_SIZE);
1600 memcpy(unittest_data_align, __dtbo_testcases_begin, size);
1602 ret = of_fdt_unflatten_tree(unittest_data_align, NULL, &unittest_data_node);
1604 pr_warn("%s: unflatten testcases tree failed\n", __func__);
1605 kfree(unittest_data);
1608 if (!unittest_data_node) {
1609 pr_warn("%s: testcases tree is empty\n", __func__);
1610 kfree(unittest_data);
1615 * This lock normally encloses of_resolve_phandles()
1617 of_overlay_mutex_lock();
1619 rc = of_resolve_phandles(unittest_data_node);
1621 pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
1622 of_overlay_mutex_unlock();
1627 of_root = unittest_data_node;
1628 for_each_of_allnodes(np)
1629 __of_attach_node_sysfs(np);
1630 of_aliases = of_find_node_by_path("/aliases");
1631 of_chosen = of_find_node_by_path("/chosen");
1632 of_overlay_mutex_unlock();
1636 EXPECT_BEGIN(KERN_INFO,
1637 "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
1639 /* attach the sub-tree to live tree */
1640 np = unittest_data_node->child;
1642 struct device_node *next = np->sibling;
1644 np->parent = of_root;
1645 /* this will clear OF_DETACHED in np and children */
1646 attach_node_and_children(np);
1650 EXPECT_END(KERN_INFO,
1651 "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
1653 of_overlay_mutex_unlock();
1658 #ifdef CONFIG_OF_OVERLAY
1659 static int __init overlay_data_apply(const char *overlay_name, int *ovcs_id);
1661 static int unittest_probe(struct platform_device *pdev)
1663 struct device *dev = &pdev->dev;
1664 struct device_node *np = dev->of_node;
1667 dev_err(dev, "No OF data for device\n");
1672 dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
1674 of_platform_populate(np, NULL, NULL, &pdev->dev);
1679 static void unittest_remove(struct platform_device *pdev)
1681 struct device *dev = &pdev->dev;
1682 struct device_node *np = dev->of_node;
1684 dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
1687 static const struct of_device_id unittest_match[] = {
1688 { .compatible = "unittest", },
1692 static struct platform_driver unittest_driver = {
1693 .probe = unittest_probe,
1694 .remove_new = unittest_remove,
1697 .of_match_table = of_match_ptr(unittest_match),
1701 /* get the platform device instantiated at the path */
1702 static struct platform_device *of_path_to_platform_device(const char *path)
1704 struct device_node *np;
1705 struct platform_device *pdev;
1707 np = of_find_node_by_path(path);
1711 pdev = of_find_device_by_node(np);
1717 /* find out if a platform device exists at that path */
1718 static int of_path_platform_device_exists(const char *path)
1720 struct platform_device *pdev;
1722 pdev = of_path_to_platform_device(path);
1723 platform_device_put(pdev);
1724 return pdev != NULL;
1727 #ifdef CONFIG_OF_GPIO
1729 struct unittest_gpio_dev {
1730 struct gpio_chip chip;
1733 static int unittest_gpio_chip_request_count;
1734 static int unittest_gpio_probe_count;
1735 static int unittest_gpio_probe_pass_count;
1737 static int unittest_gpio_chip_request(struct gpio_chip *chip, unsigned int offset)
1739 unittest_gpio_chip_request_count++;
1741 pr_debug("%s(): %s %d %d\n", __func__, chip->label, offset,
1742 unittest_gpio_chip_request_count);
1746 static int unittest_gpio_probe(struct platform_device *pdev)
1748 struct unittest_gpio_dev *devptr;
1751 unittest_gpio_probe_count++;
1753 devptr = kzalloc(sizeof(*devptr), GFP_KERNEL);
1757 platform_set_drvdata(pdev, devptr);
1759 devptr->chip.fwnode = dev_fwnode(&pdev->dev);
1760 devptr->chip.label = "of-unittest-gpio";
1761 devptr->chip.base = -1; /* dynamic allocation */
1762 devptr->chip.ngpio = 5;
1763 devptr->chip.request = unittest_gpio_chip_request;
1765 ret = gpiochip_add_data(&devptr->chip, NULL);
1768 "gpiochip_add_data() for node @%pfw failed, ret = %d\n", devptr->chip.fwnode, ret);
1771 unittest_gpio_probe_pass_count++;
1775 static void unittest_gpio_remove(struct platform_device *pdev)
1777 struct unittest_gpio_dev *devptr = platform_get_drvdata(pdev);
1778 struct device *dev = &pdev->dev;
1780 dev_dbg(dev, "%s for node @%pfw\n", __func__, devptr->chip.fwnode);
1782 if (devptr->chip.base != -1)
1783 gpiochip_remove(&devptr->chip);
1788 static const struct of_device_id unittest_gpio_id[] = {
1789 { .compatible = "unittest-gpio", },
1793 static struct platform_driver unittest_gpio_driver = {
1794 .probe = unittest_gpio_probe,
1795 .remove_new = unittest_gpio_remove,
1797 .name = "unittest-gpio",
1798 .of_match_table = of_match_ptr(unittest_gpio_id),
1802 static void __init of_unittest_overlay_gpio(void)
1804 int chip_request_count;
1805 int probe_pass_count;
1809 * tests: apply overlays before registering driver
1810 * Similar to installing a driver as a module, the
1811 * driver is registered after applying the overlays.
1813 * The overlays are applied by overlay_data_apply()
1814 * instead of of_unittest_apply_overlay() so that they
1815 * will not be tracked. Thus they will not be removed
1816 * by of_unittest_remove_tracked_overlays().
1818 * - apply overlay_gpio_01
1819 * - apply overlay_gpio_02a
1820 * - apply overlay_gpio_02b
1823 * register driver will result in
1824 * - probe and processing gpio hog for overlay_gpio_01
1825 * - probe for overlay_gpio_02a
1826 * - processing gpio for overlay_gpio_02b
1829 probe_pass_count = unittest_gpio_probe_pass_count;
1830 chip_request_count = unittest_gpio_chip_request_count;
1833 * overlay_gpio_01 contains gpio node and child gpio hog node
1834 * overlay_gpio_02a contains gpio node
1835 * overlay_gpio_02b contains child gpio hog node
1838 unittest(overlay_data_apply("overlay_gpio_01", NULL),
1839 "Adding overlay 'overlay_gpio_01' failed\n");
1841 unittest(overlay_data_apply("overlay_gpio_02a", NULL),
1842 "Adding overlay 'overlay_gpio_02a' failed\n");
1844 unittest(overlay_data_apply("overlay_gpio_02b", NULL),
1845 "Adding overlay 'overlay_gpio_02b' failed\n");
1848 * messages are the result of the probes, after the
1849 * driver is registered
1852 EXPECT_BEGIN(KERN_INFO,
1853 "gpio-<<int>> (line-B-input): hogged as input\n");
1855 EXPECT_BEGIN(KERN_INFO,
1856 "gpio-<<int>> (line-A-input): hogged as input\n");
1858 ret = platform_driver_register(&unittest_gpio_driver);
1859 if (unittest(ret == 0, "could not register unittest gpio driver\n"))
1862 EXPECT_END(KERN_INFO,
1863 "gpio-<<int>> (line-A-input): hogged as input\n");
1864 EXPECT_END(KERN_INFO,
1865 "gpio-<<int>> (line-B-input): hogged as input\n");
1867 unittest(probe_pass_count + 2 == unittest_gpio_probe_pass_count,
1868 "unittest_gpio_probe() failed or not called\n");
1870 unittest(chip_request_count + 2 == unittest_gpio_chip_request_count,
1871 "unittest_gpio_chip_request() called %d times (expected 1 time)\n",
1872 unittest_gpio_chip_request_count - chip_request_count);
1875 * tests: apply overlays after registering driver
1877 * Similar to a driver built-in to the kernel, the
1878 * driver is registered before applying the overlays.
1880 * overlay_gpio_03 contains gpio node and child gpio hog node
1882 * - apply overlay_gpio_03
1884 * apply overlay will result in
1885 * - probe and processing gpio hog.
1888 probe_pass_count = unittest_gpio_probe_pass_count;
1889 chip_request_count = unittest_gpio_chip_request_count;
1891 EXPECT_BEGIN(KERN_INFO,
1892 "gpio-<<int>> (line-D-input): hogged as input\n");
1894 /* overlay_gpio_03 contains gpio node and child gpio hog node */
1896 unittest(overlay_data_apply("overlay_gpio_03", NULL),
1897 "Adding overlay 'overlay_gpio_03' failed\n");
1899 EXPECT_END(KERN_INFO,
1900 "gpio-<<int>> (line-D-input): hogged as input\n");
1902 unittest(probe_pass_count + 1 == unittest_gpio_probe_pass_count,
1903 "unittest_gpio_probe() failed or not called\n");
1905 unittest(chip_request_count + 1 == unittest_gpio_chip_request_count,
1906 "unittest_gpio_chip_request() called %d times (expected 1 time)\n",
1907 unittest_gpio_chip_request_count - chip_request_count);
1910 * overlay_gpio_04a contains gpio node
1912 * - apply overlay_gpio_04a
1914 * apply the overlay will result in
1915 * - probe for overlay_gpio_04a
1918 probe_pass_count = unittest_gpio_probe_pass_count;
1919 chip_request_count = unittest_gpio_chip_request_count;
1921 /* overlay_gpio_04a contains gpio node */
1923 unittest(overlay_data_apply("overlay_gpio_04a", NULL),
1924 "Adding overlay 'overlay_gpio_04a' failed\n");
1926 unittest(probe_pass_count + 1 == unittest_gpio_probe_pass_count,
1927 "unittest_gpio_probe() failed or not called\n");
1930 * overlay_gpio_04b contains child gpio hog node
1932 * - apply overlay_gpio_04b
1934 * apply the overlay will result in
1935 * - processing gpio for overlay_gpio_04b
1938 EXPECT_BEGIN(KERN_INFO,
1939 "gpio-<<int>> (line-C-input): hogged as input\n");
1941 /* overlay_gpio_04b contains child gpio hog node */
1943 unittest(overlay_data_apply("overlay_gpio_04b", NULL),
1944 "Adding overlay 'overlay_gpio_04b' failed\n");
1946 EXPECT_END(KERN_INFO,
1947 "gpio-<<int>> (line-C-input): hogged as input\n");
1949 unittest(chip_request_count + 1 == unittest_gpio_chip_request_count,
1950 "unittest_gpio_chip_request() called %d times (expected 1 time)\n",
1951 unittest_gpio_chip_request_count - chip_request_count);
1956 static void __init of_unittest_overlay_gpio(void)
1963 #if IS_BUILTIN(CONFIG_I2C)
1965 /* get the i2c client device instantiated at the path */
1966 static struct i2c_client *of_path_to_i2c_client(const char *path)
1968 struct device_node *np;
1969 struct i2c_client *client;
1971 np = of_find_node_by_path(path);
1975 client = of_find_i2c_device_by_node(np);
1981 /* find out if a i2c client device exists at that path */
1982 static int of_path_i2c_client_exists(const char *path)
1984 struct i2c_client *client;
1986 client = of_path_to_i2c_client(path);
1988 put_device(&client->dev);
1989 return client != NULL;
1992 static int of_path_i2c_client_exists(const char *path)
2003 static int of_path_device_type_exists(const char *path,
2004 enum overlay_type ovtype)
2008 return of_path_platform_device_exists(path);
2010 return of_path_i2c_client_exists(path);
2015 static const char *unittest_path(int nr, enum overlay_type ovtype)
2018 static char buf[256];
2022 base = "/testcase-data/overlay-node/test-bus";
2025 base = "/testcase-data/overlay-node/test-bus/i2c-test-bus";
2031 snprintf(buf, sizeof(buf) - 1, "%s/test-unittest%d", base, nr);
2032 buf[sizeof(buf) - 1] = '\0';
2036 static int of_unittest_device_exists(int unittest_nr, enum overlay_type ovtype)
2040 path = unittest_path(unittest_nr, ovtype);
2044 return of_path_platform_device_exists(path);
2046 return of_path_i2c_client_exists(path);
2051 static const char *overlay_name_from_nr(int nr)
2053 static char buf[256];
2055 snprintf(buf, sizeof(buf) - 1,
2057 buf[sizeof(buf) - 1] = '\0';
2062 static const char *bus_path = "/testcase-data/overlay-node/test-bus";
2064 #define MAX_TRACK_OVCS_IDS 256
2066 static int track_ovcs_id[MAX_TRACK_OVCS_IDS];
2067 static int track_ovcs_id_overlay_nr[MAX_TRACK_OVCS_IDS];
2068 static int track_ovcs_id_cnt;
2070 static void of_unittest_track_overlay(int ovcs_id, int overlay_nr)
2072 if (WARN_ON(track_ovcs_id_cnt >= MAX_TRACK_OVCS_IDS))
2075 track_ovcs_id[track_ovcs_id_cnt] = ovcs_id;
2076 track_ovcs_id_overlay_nr[track_ovcs_id_cnt] = overlay_nr;
2077 track_ovcs_id_cnt++;
2080 static void of_unittest_untrack_overlay(int ovcs_id)
2082 if (WARN_ON(track_ovcs_id_cnt < 1))
2085 track_ovcs_id_cnt--;
2087 /* If out of synch then test is broken. Do not try to recover. */
2088 WARN_ON(track_ovcs_id[track_ovcs_id_cnt] != ovcs_id);
2091 static void of_unittest_remove_tracked_overlays(void)
2093 int ret, ovcs_id, overlay_nr, save_ovcs_id;
2094 const char *overlay_name;
2096 while (track_ovcs_id_cnt > 0) {
2098 ovcs_id = track_ovcs_id[track_ovcs_id_cnt - 1];
2099 overlay_nr = track_ovcs_id_overlay_nr[track_ovcs_id_cnt - 1];
2100 save_ovcs_id = ovcs_id;
2101 ret = of_overlay_remove(&ovcs_id);
2102 if (ret == -ENODEV) {
2103 overlay_name = overlay_name_from_nr(overlay_nr);
2104 pr_warn("%s: of_overlay_remove() for overlay \"%s\" failed, ret = %d\n",
2105 __func__, overlay_name, ret);
2107 of_unittest_untrack_overlay(save_ovcs_id);
2112 static int __init of_unittest_apply_overlay(int overlay_nr, int *ovcs_id)
2115 * The overlay will be tracked, thus it will be removed
2116 * by of_unittest_remove_tracked_overlays().
2119 const char *overlay_name;
2121 overlay_name = overlay_name_from_nr(overlay_nr);
2123 if (!overlay_data_apply(overlay_name, ovcs_id)) {
2124 unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2127 of_unittest_track_overlay(*ovcs_id, overlay_nr);
2132 /* apply an overlay while checking before and after states */
2133 static int __init of_unittest_apply_overlay_check(int overlay_nr,
2134 int unittest_nr, int before, int after,
2135 enum overlay_type ovtype)
2139 /* unittest device must not be in before state */
2140 if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
2141 unittest(0, "%s with device @\"%s\" %s\n",
2142 overlay_name_from_nr(overlay_nr),
2143 unittest_path(unittest_nr, ovtype),
2144 !before ? "enabled" : "disabled");
2149 ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
2151 /* of_unittest_apply_overlay already called unittest() */
2155 /* unittest device must be to set to after state */
2156 if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
2157 unittest(0, "%s failed to create @\"%s\" %s\n",
2158 overlay_name_from_nr(overlay_nr),
2159 unittest_path(unittest_nr, ovtype),
2160 !after ? "enabled" : "disabled");
2167 /* apply an overlay and then revert it while checking before, after states */
2168 static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
2169 int unittest_nr, int before, int after,
2170 enum overlay_type ovtype)
2172 int ret, ovcs_id, save_ovcs_id;
2174 /* unittest device must be in before state */
2175 if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
2176 unittest(0, "%s with device @\"%s\" %s\n",
2177 overlay_name_from_nr(overlay_nr),
2178 unittest_path(unittest_nr, ovtype),
2179 !before ? "enabled" : "disabled");
2183 /* apply the overlay */
2185 ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
2187 /* of_unittest_apply_overlay already called unittest() */
2191 /* unittest device must be in after state */
2192 if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
2193 unittest(0, "%s failed to create @\"%s\" %s\n",
2194 overlay_name_from_nr(overlay_nr),
2195 unittest_path(unittest_nr, ovtype),
2196 !after ? "enabled" : "disabled");
2200 save_ovcs_id = ovcs_id;
2201 ret = of_overlay_remove(&ovcs_id);
2203 unittest(0, "%s failed to be destroyed @\"%s\"\n",
2204 overlay_name_from_nr(overlay_nr),
2205 unittest_path(unittest_nr, ovtype));
2208 of_unittest_untrack_overlay(save_ovcs_id);
2210 /* unittest device must be again in before state */
2211 if (of_unittest_device_exists(unittest_nr, PDEV_OVERLAY) != before) {
2212 unittest(0, "%s with device @\"%s\" %s\n",
2213 overlay_name_from_nr(overlay_nr),
2214 unittest_path(unittest_nr, ovtype),
2215 !before ? "enabled" : "disabled");
2222 /* test activation of device */
2223 static void __init of_unittest_overlay_0(void)
2227 EXPECT_BEGIN(KERN_INFO,
2228 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest0/status");
2230 /* device should enable */
2231 ret = of_unittest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY);
2233 EXPECT_END(KERN_INFO,
2234 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest0/status");
2239 unittest(1, "overlay test %d passed\n", 0);
2242 /* test deactivation of device */
2243 static void __init of_unittest_overlay_1(void)
2247 EXPECT_BEGIN(KERN_INFO,
2248 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest1/status");
2250 /* device should disable */
2251 ret = of_unittest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY);
2253 EXPECT_END(KERN_INFO,
2254 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest1/status");
2259 unittest(1, "overlay test %d passed\n", 1);
2263 /* test activation of device */
2264 static void __init of_unittest_overlay_2(void)
2268 EXPECT_BEGIN(KERN_INFO,
2269 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest2/status");
2271 /* device should enable */
2272 ret = of_unittest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY);
2274 EXPECT_END(KERN_INFO,
2275 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest2/status");
2279 unittest(1, "overlay test %d passed\n", 2);
2282 /* test deactivation of device */
2283 static void __init of_unittest_overlay_3(void)
2287 EXPECT_BEGIN(KERN_INFO,
2288 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest3/status");
2290 /* device should disable */
2291 ret = of_unittest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY);
2293 EXPECT_END(KERN_INFO,
2294 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest3/status");
2299 unittest(1, "overlay test %d passed\n", 3);
2302 /* test activation of a full device node */
2303 static void __init of_unittest_overlay_4(void)
2305 /* device should disable */
2306 if (of_unittest_apply_overlay_check(4, 4, 0, 1, PDEV_OVERLAY))
2309 unittest(1, "overlay test %d passed\n", 4);
2312 /* test overlay apply/revert sequence */
2313 static void __init of_unittest_overlay_5(void)
2317 EXPECT_BEGIN(KERN_INFO,
2318 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest5/status");
2320 /* device should disable */
2321 ret = of_unittest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY);
2323 EXPECT_END(KERN_INFO,
2324 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest5/status");
2329 unittest(1, "overlay test %d passed\n", 5);
2332 /* test overlay application in sequence */
2333 static void __init of_unittest_overlay_6(void)
2335 int i, save_ovcs_id[2], ovcs_id;
2336 int overlay_nr = 6, unittest_nr = 6;
2337 int before = 0, after = 1;
2338 const char *overlay_name;
2342 /* unittest device must be in before state */
2343 for (i = 0; i < 2; i++) {
2344 if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
2346 unittest(0, "%s with device @\"%s\" %s\n",
2347 overlay_name_from_nr(overlay_nr + i),
2348 unittest_path(unittest_nr + i,
2350 !before ? "enabled" : "disabled");
2355 /* apply the overlays */
2357 EXPECT_BEGIN(KERN_INFO,
2358 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest6/status");
2360 overlay_name = overlay_name_from_nr(overlay_nr + 0);
2362 ret = overlay_data_apply(overlay_name, &ovcs_id);
2365 unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2368 save_ovcs_id[0] = ovcs_id;
2369 of_unittest_track_overlay(ovcs_id, overlay_nr + 0);
2371 EXPECT_END(KERN_INFO,
2372 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest6/status");
2374 EXPECT_BEGIN(KERN_INFO,
2375 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest7/status");
2377 overlay_name = overlay_name_from_nr(overlay_nr + 1);
2379 ret = overlay_data_apply(overlay_name, &ovcs_id);
2382 unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2385 save_ovcs_id[1] = ovcs_id;
2386 of_unittest_track_overlay(ovcs_id, overlay_nr + 1);
2388 EXPECT_END(KERN_INFO,
2389 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest7/status");
2392 for (i = 0; i < 2; i++) {
2393 /* unittest device must be in after state */
2394 if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
2396 unittest(0, "overlay @\"%s\" failed @\"%s\" %s\n",
2397 overlay_name_from_nr(overlay_nr + i),
2398 unittest_path(unittest_nr + i,
2400 !after ? "enabled" : "disabled");
2405 for (i = 1; i >= 0; i--) {
2406 ovcs_id = save_ovcs_id[i];
2407 if (of_overlay_remove(&ovcs_id)) {
2408 unittest(0, "%s failed destroy @\"%s\"\n",
2409 overlay_name_from_nr(overlay_nr + i),
2410 unittest_path(unittest_nr + i,
2414 of_unittest_untrack_overlay(save_ovcs_id[i]);
2417 for (i = 0; i < 2; i++) {
2418 /* unittest device must be again in before state */
2419 if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
2421 unittest(0, "%s with device @\"%s\" %s\n",
2422 overlay_name_from_nr(overlay_nr + i),
2423 unittest_path(unittest_nr + i,
2425 !before ? "enabled" : "disabled");
2430 unittest(1, "overlay test %d passed\n", 6);
2434 /* test overlay application in sequence */
2435 static void __init of_unittest_overlay_8(void)
2437 int i, save_ovcs_id[2], ovcs_id;
2438 int overlay_nr = 8, unittest_nr = 8;
2439 const char *overlay_name;
2442 /* we don't care about device state in this test */
2444 EXPECT_BEGIN(KERN_INFO,
2445 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/status");
2447 overlay_name = overlay_name_from_nr(overlay_nr + 0);
2449 ret = overlay_data_apply(overlay_name, &ovcs_id);
2451 unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2453 EXPECT_END(KERN_INFO,
2454 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/status");
2459 save_ovcs_id[0] = ovcs_id;
2460 of_unittest_track_overlay(ovcs_id, overlay_nr + 0);
2462 overlay_name = overlay_name_from_nr(overlay_nr + 1);
2464 EXPECT_BEGIN(KERN_INFO,
2465 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/property-foo");
2467 /* apply the overlays */
2468 ret = overlay_data_apply(overlay_name, &ovcs_id);
2470 EXPECT_END(KERN_INFO,
2471 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/property-foo");
2474 unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2478 save_ovcs_id[1] = ovcs_id;
2479 of_unittest_track_overlay(ovcs_id, overlay_nr + 1);
2481 /* now try to remove first overlay (it should fail) */
2482 ovcs_id = save_ovcs_id[0];
2484 EXPECT_BEGIN(KERN_INFO,
2485 "OF: overlay: node_overlaps_later_cs: #6 overlaps with #7 @/testcase-data/overlay-node/test-bus/test-unittest8");
2487 EXPECT_BEGIN(KERN_INFO,
2488 "OF: overlay: overlay #6 is not topmost");
2490 ret = of_overlay_remove(&ovcs_id);
2492 EXPECT_END(KERN_INFO,
2493 "OF: overlay: overlay #6 is not topmost");
2495 EXPECT_END(KERN_INFO,
2496 "OF: overlay: node_overlaps_later_cs: #6 overlaps with #7 @/testcase-data/overlay-node/test-bus/test-unittest8");
2500 * Should never get here. If we do, expect a lot of
2501 * subsequent tracking and overlay removal related errors.
2503 unittest(0, "%s was destroyed @\"%s\"\n",
2504 overlay_name_from_nr(overlay_nr + 0),
2505 unittest_path(unittest_nr,
2510 /* removing them in order should work */
2511 for (i = 1; i >= 0; i--) {
2512 ovcs_id = save_ovcs_id[i];
2513 if (of_overlay_remove(&ovcs_id)) {
2514 unittest(0, "%s not destroyed @\"%s\"\n",
2515 overlay_name_from_nr(overlay_nr + i),
2516 unittest_path(unittest_nr,
2520 of_unittest_untrack_overlay(save_ovcs_id[i]);
2523 unittest(1, "overlay test %d passed\n", 8);
2526 /* test insertion of a bus with parent devices */
2527 static void __init of_unittest_overlay_10(void)
2532 /* device should disable */
2533 ret = of_unittest_apply_overlay_check(10, 10, 0, 1, PDEV_OVERLAY);
2535 if (unittest(ret == 0,
2536 "overlay test %d failed; overlay application\n", 10))
2539 child_path = kasprintf(GFP_KERNEL, "%s/test-unittest101",
2540 unittest_path(10, PDEV_OVERLAY));
2541 if (unittest(child_path, "overlay test %d failed; kasprintf\n", 10))
2544 ret = of_path_device_type_exists(child_path, PDEV_OVERLAY);
2547 unittest(ret, "overlay test %d failed; no child device\n", 10);
2550 /* test insertion of a bus with parent devices (and revert) */
2551 static void __init of_unittest_overlay_11(void)
2555 /* device should disable */
2556 ret = of_unittest_apply_revert_overlay_check(11, 11, 0, 1,
2559 unittest(ret == 0, "overlay test %d failed; overlay apply\n", 11);
2562 #if IS_BUILTIN(CONFIG_I2C) && IS_ENABLED(CONFIG_OF_OVERLAY)
2564 struct unittest_i2c_bus_data {
2565 struct platform_device *pdev;
2566 struct i2c_adapter adap;
2569 static int unittest_i2c_master_xfer(struct i2c_adapter *adap,
2570 struct i2c_msg *msgs, int num)
2572 struct unittest_i2c_bus_data *std = i2c_get_adapdata(adap);
2579 static u32 unittest_i2c_functionality(struct i2c_adapter *adap)
2581 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
2584 static const struct i2c_algorithm unittest_i2c_algo = {
2585 .master_xfer = unittest_i2c_master_xfer,
2586 .functionality = unittest_i2c_functionality,
2589 static int unittest_i2c_bus_probe(struct platform_device *pdev)
2591 struct device *dev = &pdev->dev;
2592 struct device_node *np = dev->of_node;
2593 struct unittest_i2c_bus_data *std;
2594 struct i2c_adapter *adap;
2598 dev_err(dev, "No OF data for device\n");
2603 dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
2605 std = devm_kzalloc(dev, sizeof(*std), GFP_KERNEL);
2609 /* link them together */
2611 platform_set_drvdata(pdev, std);
2614 i2c_set_adapdata(adap, std);
2616 strscpy(adap->name, pdev->name, sizeof(adap->name));
2617 adap->class = I2C_CLASS_DEPRECATED;
2618 adap->algo = &unittest_i2c_algo;
2619 adap->dev.parent = dev;
2620 adap->dev.of_node = dev->of_node;
2621 adap->timeout = 5 * HZ;
2624 ret = i2c_add_numbered_adapter(adap);
2626 dev_err(dev, "Failed to add I2C adapter\n");
2633 static void unittest_i2c_bus_remove(struct platform_device *pdev)
2635 struct device *dev = &pdev->dev;
2636 struct device_node *np = dev->of_node;
2637 struct unittest_i2c_bus_data *std = platform_get_drvdata(pdev);
2639 dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
2640 i2c_del_adapter(&std->adap);
2643 static const struct of_device_id unittest_i2c_bus_match[] = {
2644 { .compatible = "unittest-i2c-bus", },
2648 static struct platform_driver unittest_i2c_bus_driver = {
2649 .probe = unittest_i2c_bus_probe,
2650 .remove_new = unittest_i2c_bus_remove,
2652 .name = "unittest-i2c-bus",
2653 .of_match_table = of_match_ptr(unittest_i2c_bus_match),
2657 static int unittest_i2c_dev_probe(struct i2c_client *client)
2659 struct device *dev = &client->dev;
2660 struct device_node *np = client->dev.of_node;
2663 dev_err(dev, "No OF node\n");
2667 dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
2672 static void unittest_i2c_dev_remove(struct i2c_client *client)
2674 struct device *dev = &client->dev;
2675 struct device_node *np = client->dev.of_node;
2677 dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
2680 static const struct i2c_device_id unittest_i2c_dev_id[] = {
2681 { .name = "unittest-i2c-dev" },
2685 static struct i2c_driver unittest_i2c_dev_driver = {
2687 .name = "unittest-i2c-dev",
2689 .probe_new = unittest_i2c_dev_probe,
2690 .remove = unittest_i2c_dev_remove,
2691 .id_table = unittest_i2c_dev_id,
2694 #if IS_BUILTIN(CONFIG_I2C_MUX)
2696 static int unittest_i2c_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
2701 static int unittest_i2c_mux_probe(struct i2c_client *client)
2704 struct device *dev = &client->dev;
2705 struct i2c_adapter *adap = client->adapter;
2706 struct device_node *np = client->dev.of_node, *child;
2707 struct i2c_mux_core *muxc;
2710 dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
2713 dev_err(dev, "No OF node\n");
2718 for_each_child_of_node(np, child) {
2719 if (of_property_read_u32(child, "reg", ®))
2721 if (max_reg == (u32)-1 || reg > max_reg)
2724 nchans = max_reg == (u32)-1 ? 0 : max_reg + 1;
2726 dev_err(dev, "No channels\n");
2730 muxc = i2c_mux_alloc(adap, dev, nchans, 0, 0,
2731 unittest_i2c_mux_select_chan, NULL);
2734 for (i = 0; i < nchans; i++) {
2735 if (i2c_mux_add_adapter(muxc, 0, i, 0)) {
2736 dev_err(dev, "Failed to register mux #%d\n", i);
2737 i2c_mux_del_adapters(muxc);
2742 i2c_set_clientdata(client, muxc);
2747 static void unittest_i2c_mux_remove(struct i2c_client *client)
2749 struct device *dev = &client->dev;
2750 struct device_node *np = client->dev.of_node;
2751 struct i2c_mux_core *muxc = i2c_get_clientdata(client);
2753 dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
2754 i2c_mux_del_adapters(muxc);
2757 static const struct i2c_device_id unittest_i2c_mux_id[] = {
2758 { .name = "unittest-i2c-mux" },
2762 static struct i2c_driver unittest_i2c_mux_driver = {
2764 .name = "unittest-i2c-mux",
2766 .probe_new = unittest_i2c_mux_probe,
2767 .remove = unittest_i2c_mux_remove,
2768 .id_table = unittest_i2c_mux_id,
2773 static int of_unittest_overlay_i2c_init(void)
2777 ret = i2c_add_driver(&unittest_i2c_dev_driver);
2778 if (unittest(ret == 0,
2779 "could not register unittest i2c device driver\n"))
2782 ret = platform_driver_register(&unittest_i2c_bus_driver);
2784 if (unittest(ret == 0,
2785 "could not register unittest i2c bus driver\n"))
2788 #if IS_BUILTIN(CONFIG_I2C_MUX)
2790 EXPECT_BEGIN(KERN_INFO,
2791 "i2c i2c-1: Added multiplexed i2c bus 2");
2793 ret = i2c_add_driver(&unittest_i2c_mux_driver);
2795 EXPECT_END(KERN_INFO,
2796 "i2c i2c-1: Added multiplexed i2c bus 2");
2798 if (unittest(ret == 0,
2799 "could not register unittest i2c mux driver\n"))
2806 static void of_unittest_overlay_i2c_cleanup(void)
2808 #if IS_BUILTIN(CONFIG_I2C_MUX)
2809 i2c_del_driver(&unittest_i2c_mux_driver);
2811 platform_driver_unregister(&unittest_i2c_bus_driver);
2812 i2c_del_driver(&unittest_i2c_dev_driver);
2815 static void __init of_unittest_overlay_i2c_12(void)
2819 /* device should enable */
2820 EXPECT_BEGIN(KERN_INFO,
2821 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12/status");
2823 ret = of_unittest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY);
2825 EXPECT_END(KERN_INFO,
2826 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12/status");
2831 unittest(1, "overlay test %d passed\n", 12);
2834 /* test deactivation of device */
2835 static void __init of_unittest_overlay_i2c_13(void)
2839 EXPECT_BEGIN(KERN_INFO,
2840 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13/status");
2842 /* device should disable */
2843 ret = of_unittest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY);
2845 EXPECT_END(KERN_INFO,
2846 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13/status");
2851 unittest(1, "overlay test %d passed\n", 13);
2854 /* just check for i2c mux existence */
2855 static void of_unittest_overlay_i2c_14(void)
2859 static void __init of_unittest_overlay_i2c_15(void)
2863 /* device should enable */
2864 EXPECT_BEGIN(KERN_INFO,
2865 "i2c i2c-1: Added multiplexed i2c bus 3");
2867 ret = of_unittest_apply_overlay_check(15, 15, 0, 1, I2C_OVERLAY);
2869 EXPECT_END(KERN_INFO,
2870 "i2c i2c-1: Added multiplexed i2c bus 3");
2875 unittest(1, "overlay test %d passed\n", 15);
2880 static inline void of_unittest_overlay_i2c_14(void) { }
2881 static inline void of_unittest_overlay_i2c_15(void) { }
2885 static int of_notify(struct notifier_block *nb, unsigned long action,
2888 struct of_overlay_notify_data *nd = arg;
2889 struct device_node *found;
2893 * For overlay_16 .. overlay_19, check that returning an error
2894 * works for each of the actions by setting an arbitrary return
2895 * error number that matches the test number. e.g. for unittest16,
2896 * ret = -EBUSY which is -16.
2898 * OVERLAY_INFO() for the overlays is declared to expect the same
2899 * error number, so overlay_data_apply() will return no error.
2901 * overlay_20 will return NOTIFY_DONE
2905 of_node_get(nd->overlay);
2909 case OF_OVERLAY_PRE_APPLY:
2910 found = of_find_node_by_name(nd->overlay, "test-unittest16");
2917 case OF_OVERLAY_POST_APPLY:
2918 found = of_find_node_by_name(nd->overlay, "test-unittest17");
2925 case OF_OVERLAY_PRE_REMOVE:
2926 found = of_find_node_by_name(nd->overlay, "test-unittest18");
2933 case OF_OVERLAY_POST_REMOVE:
2934 found = of_find_node_by_name(nd->overlay, "test-unittest19");
2941 default: /* should not happen */
2942 of_node_put(nd->overlay);
2948 return notifier_from_errno(ret);
2953 static struct notifier_block of_nb = {
2954 .notifier_call = of_notify,
2957 static void __init of_unittest_overlay_notify(void)
2962 ret = of_overlay_notifier_register(&of_nb);
2964 "of_overlay_notifier_register() failed, ret = %d\n", ret);
2969 * The overlays are applied by overlay_data_apply()
2970 * instead of of_unittest_apply_overlay() so that they
2971 * will not be tracked. Thus they will not be removed
2972 * by of_unittest_remove_tracked_overlays().
2974 * Applying overlays 16 - 19 will each trigger an error for a
2975 * different action in of_notify().
2977 * Applying overlay 20 will not trigger any error in of_notify().
2980 /* --- overlay 16 --- */
2982 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset pre-apply notifier error -16, target: /testcase-data/overlay-node/test-bus");
2984 unittest(overlay_data_apply("overlay_16", &ovcs_id),
2985 "test OF_OVERLAY_PRE_APPLY notify injected error\n");
2987 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset pre-apply notifier error -16, target: /testcase-data/overlay-node/test-bus");
2989 unittest(ovcs_id, "ovcs_id not created for overlay_16\n");
2991 /* --- overlay 17 --- */
2993 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset post-apply notifier error -17, target: /testcase-data/overlay-node/test-bus");
2995 unittest(overlay_data_apply("overlay_17", &ovcs_id),
2996 "test OF_OVERLAY_POST_APPLY notify injected error\n");
2998 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset post-apply notifier error -17, target: /testcase-data/overlay-node/test-bus");
3000 unittest(ovcs_id, "ovcs_id not created for overlay_17\n");
3003 ret = of_overlay_remove(&ovcs_id);
3005 "overlay_17 of_overlay_remove(), ret = %d\n", ret);
3008 /* --- overlay 18 --- */
3010 unittest(overlay_data_apply("overlay_18", &ovcs_id),
3011 "OF_OVERLAY_PRE_REMOVE notify injected error\n");
3013 unittest(ovcs_id, "ovcs_id not created for overlay_18\n");
3016 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset pre-remove notifier error -18, target: /testcase-data/overlay-node/test-bus");
3018 ret = of_overlay_remove(&ovcs_id);
3019 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset pre-remove notifier error -18, target: /testcase-data/overlay-node/test-bus");
3020 if (ret == -EXDEV) {
3022 * change set ovcs_id should still exist
3024 unittest(1, "overlay_18 of_overlay_remove() injected error for OF_OVERLAY_PRE_REMOVE\n");
3026 unittest(0, "overlay_18 of_overlay_remove() injected error for OF_OVERLAY_PRE_REMOVE not returned\n");
3029 unittest(1, "ovcs_id not created for overlay_18\n");
3032 unittest(ovcs_id, "ovcs_id removed for overlay_18\n");
3034 /* --- overlay 19 --- */
3036 unittest(overlay_data_apply("overlay_19", &ovcs_id),
3037 "OF_OVERLAY_POST_REMOVE notify injected error\n");
3039 unittest(ovcs_id, "ovcs_id not created for overlay_19\n");
3042 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset post-remove notifier error -19, target: /testcase-data/overlay-node/test-bus");
3043 ret = of_overlay_remove(&ovcs_id);
3044 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset post-remove notifier error -19, target: /testcase-data/overlay-node/test-bus");
3046 unittest(1, "overlay_19 of_overlay_remove() injected error for OF_OVERLAY_POST_REMOVE\n");
3048 unittest(0, "overlay_19 of_overlay_remove() injected error for OF_OVERLAY_POST_REMOVE not returned\n");
3050 unittest(1, "ovcs_id removed for overlay_19\n");
3053 unittest(!ovcs_id, "changeset ovcs_id = %d not removed for overlay_19\n",
3056 /* --- overlay 20 --- */
3058 unittest(overlay_data_apply("overlay_20", &ovcs_id),
3059 "overlay notify no injected error\n");
3062 ret = of_overlay_remove(&ovcs_id);
3064 unittest(1, "overlay_20 failed to be destroyed, ret = %d\n",
3067 unittest(1, "ovcs_id not created for overlay_20\n");
3070 unittest(!of_overlay_notifier_unregister(&of_nb),
3071 "of_overlay_notifier_unregister() failed, ret = %d\n", ret);
3074 static void __init of_unittest_overlay(void)
3076 struct device_node *bus_np = NULL;
3078 if (platform_driver_register(&unittest_driver)) {
3079 unittest(0, "could not register unittest driver\n");
3083 bus_np = of_find_node_by_path(bus_path);
3084 if (bus_np == NULL) {
3085 unittest(0, "could not find bus_path \"%s\"\n", bus_path);
3089 if (of_platform_default_populate(bus_np, NULL, NULL)) {
3090 unittest(0, "could not populate bus @ \"%s\"\n", bus_path);
3094 if (!of_unittest_device_exists(100, PDEV_OVERLAY)) {
3095 unittest(0, "could not find unittest0 @ \"%s\"\n",
3096 unittest_path(100, PDEV_OVERLAY));
3100 if (of_unittest_device_exists(101, PDEV_OVERLAY)) {
3101 unittest(0, "unittest1 @ \"%s\" should not exist\n",
3102 unittest_path(101, PDEV_OVERLAY));
3106 unittest(1, "basic infrastructure of overlays passed");
3108 /* tests in sequence */
3109 of_unittest_overlay_0();
3110 of_unittest_overlay_1();
3111 of_unittest_overlay_2();
3112 of_unittest_overlay_3();
3113 of_unittest_overlay_4();
3114 of_unittest_overlay_5();
3115 of_unittest_overlay_6();
3116 of_unittest_overlay_8();
3118 of_unittest_overlay_10();
3119 of_unittest_overlay_11();
3121 #if IS_BUILTIN(CONFIG_I2C)
3122 if (unittest(of_unittest_overlay_i2c_init() == 0, "i2c init failed\n"))
3125 of_unittest_overlay_i2c_12();
3126 of_unittest_overlay_i2c_13();
3127 of_unittest_overlay_i2c_14();
3128 of_unittest_overlay_i2c_15();
3130 of_unittest_overlay_i2c_cleanup();
3133 of_unittest_overlay_gpio();
3135 of_unittest_remove_tracked_overlays();
3137 of_unittest_overlay_notify();
3140 of_node_put(bus_np);
3144 static inline void __init of_unittest_overlay(void) { }
3147 static void __init of_unittest_lifecycle(void)
3149 #ifdef CONFIG_OF_DYNAMIC
3150 unsigned int refcount;
3151 int found_refcount_one = 0;
3153 struct device_node *np;
3154 struct device_node *prev_sibling, *next_sibling;
3155 const char *refcount_path = "/testcase-data/refcount-node";
3156 const char *refcount_parent_path = "/testcase-data";
3159 * Node lifecycle tests, non-dynamic node:
3161 * - Decrementing refcount to zero via of_node_put() should cause the
3162 * attempt to free the node memory by of_node_release() to fail
3163 * because the node is not a dynamic node.
3165 * - Decrementing refcount past zero should result in additional
3169 np = of_find_node_by_path(refcount_path);
3170 unittest(np, "find refcount_path \"%s\"\n", refcount_path);
3172 goto out_skip_tests;
3174 while (!found_refcount_one) {
3176 if (put_count++ > 10) {
3177 unittest(0, "guardrail to avoid infinite loop\n");
3178 goto out_skip_tests;
3181 refcount = kref_read(&np->kobj.kref);
3183 found_refcount_one = 1;
3188 EXPECT_BEGIN(KERN_INFO, "OF: ERROR: of_node_release() detected bad of_node_put() on /testcase-data/refcount-node");
3191 * refcount is now one, decrementing to zero will result in a call to
3192 * of_node_release() to free the node's memory, which should result
3195 unittest(1, "/testcase-data/refcount-node is one");
3198 EXPECT_END(KERN_INFO, "OF: ERROR: of_node_release() detected bad of_node_put() on /testcase-data/refcount-node");
3202 * expect stack trace for subsequent of_node_put():
3203 * __refcount_sub_and_test() calls:
3204 * refcount_warn_saturate(r, REFCOUNT_SUB_UAF)
3206 * Not capturing entire WARN_ONCE() trace with EXPECT_*(), just
3207 * the first three lines, and the last line.
3209 EXPECT_BEGIN(KERN_INFO, "------------[ cut here ]------------");
3210 EXPECT_BEGIN(KERN_INFO, "WARNING: <<all>>");
3211 EXPECT_BEGIN(KERN_INFO, "refcount_t: underflow; use-after-free.");
3212 EXPECT_BEGIN(KERN_INFO, "---[ end trace <<int>> ]---");
3214 /* refcount is now zero, this should fail */
3215 unittest(1, "/testcase-data/refcount-node is zero");
3218 EXPECT_END(KERN_INFO, "---[ end trace <<int>> ]---");
3219 EXPECT_END(KERN_INFO, "refcount_t: underflow; use-after-free.");
3220 EXPECT_END(KERN_INFO, "WARNING: <<all>>");
3221 EXPECT_END(KERN_INFO, "------------[ cut here ]------------");
3224 * Q. do we expect to get yet another warning?
3225 * A. no, the WARNING is from WARN_ONCE()
3227 EXPECT_NOT_BEGIN(KERN_INFO, "------------[ cut here ]------------");
3228 EXPECT_NOT_BEGIN(KERN_INFO, "WARNING: <<all>>");
3229 EXPECT_NOT_BEGIN(KERN_INFO, "refcount_t: underflow; use-after-free.");
3230 EXPECT_NOT_BEGIN(KERN_INFO, "---[ end trace <<int>> ]---");
3232 unittest(1, "/testcase-data/refcount-node is zero, second time");
3235 EXPECT_NOT_END(KERN_INFO, "---[ end trace <<int>> ]---");
3236 EXPECT_NOT_END(KERN_INFO, "refcount_t: underflow; use-after-free.");
3237 EXPECT_NOT_END(KERN_INFO, "WARNING: <<all>>");
3238 EXPECT_NOT_END(KERN_INFO, "------------[ cut here ]------------");
3241 * refcount of zero will trigger stack traces from any further
3242 * attempt to of_node_get() node "refcount-node". One example of
3243 * this is where of_unittest_check_node_linkage() will recursively
3244 * scan the tree, with 'for_each_child_of_node()' doing an
3245 * of_node_get() of the children of a node.
3247 * Prevent the stack trace by removing node "refcount-node" from
3248 * its parent's child list.
3250 * WARNING: EVIL, EVIL, EVIL:
3252 * Directly manipulate the child list of node /testcase-data to
3253 * remove child refcount-node. This is ignoring all proper methods
3254 * of removing a child and will leak a small amount of memory.
3257 np = of_find_node_by_path(refcount_parent_path);
3258 unittest(np, "find refcount_parent_path \"%s\"\n", refcount_parent_path);
3259 unittest(np, "ERROR: devicetree live tree left in a 'bad state' if test fail\n");
3263 prev_sibling = np->child;
3264 next_sibling = prev_sibling->sibling;
3265 if (!strcmp(prev_sibling->full_name, "refcount-node")) {
3266 np->child = next_sibling;
3267 next_sibling = next_sibling->sibling;
3269 while (next_sibling) {
3270 if (!strcmp(next_sibling->full_name, "refcount-node"))
3271 prev_sibling->sibling = next_sibling->sibling;
3272 prev_sibling = next_sibling;
3273 next_sibling = next_sibling->sibling;
3281 unittest(0, "One or more lifecycle tests skipped\n");
3284 #ifdef CONFIG_OF_OVERLAY
3287 * __dtbo_##overlay_name##_begin[] and __dtbo_##overlay_name##_end[] are
3288 * created by cmd_dt_S_dtbo in scripts/Makefile.lib
3291 #define OVERLAY_INFO_EXTERN(overlay_name) \
3292 extern uint8_t __dtbo_##overlay_name##_begin[]; \
3293 extern uint8_t __dtbo_##overlay_name##_end[]
3295 #define OVERLAY_INFO(overlay_name, expected) \
3296 { .dtbo_begin = __dtbo_##overlay_name##_begin, \
3297 .dtbo_end = __dtbo_##overlay_name##_end, \
3298 .expected_result = expected, \
3299 .name = #overlay_name, \
3302 struct overlay_info {
3303 uint8_t *dtbo_begin;
3305 int expected_result;
3310 OVERLAY_INFO_EXTERN(overlay_base);
3311 OVERLAY_INFO_EXTERN(overlay);
3312 OVERLAY_INFO_EXTERN(overlay_0);
3313 OVERLAY_INFO_EXTERN(overlay_1);
3314 OVERLAY_INFO_EXTERN(overlay_2);
3315 OVERLAY_INFO_EXTERN(overlay_3);
3316 OVERLAY_INFO_EXTERN(overlay_4);
3317 OVERLAY_INFO_EXTERN(overlay_5);
3318 OVERLAY_INFO_EXTERN(overlay_6);
3319 OVERLAY_INFO_EXTERN(overlay_7);
3320 OVERLAY_INFO_EXTERN(overlay_8);
3321 OVERLAY_INFO_EXTERN(overlay_9);
3322 OVERLAY_INFO_EXTERN(overlay_10);
3323 OVERLAY_INFO_EXTERN(overlay_11);
3324 OVERLAY_INFO_EXTERN(overlay_12);
3325 OVERLAY_INFO_EXTERN(overlay_13);
3326 OVERLAY_INFO_EXTERN(overlay_15);
3327 OVERLAY_INFO_EXTERN(overlay_16);
3328 OVERLAY_INFO_EXTERN(overlay_17);
3329 OVERLAY_INFO_EXTERN(overlay_18);
3330 OVERLAY_INFO_EXTERN(overlay_19);
3331 OVERLAY_INFO_EXTERN(overlay_20);
3332 OVERLAY_INFO_EXTERN(overlay_gpio_01);
3333 OVERLAY_INFO_EXTERN(overlay_gpio_02a);
3334 OVERLAY_INFO_EXTERN(overlay_gpio_02b);
3335 OVERLAY_INFO_EXTERN(overlay_gpio_03);
3336 OVERLAY_INFO_EXTERN(overlay_gpio_04a);
3337 OVERLAY_INFO_EXTERN(overlay_gpio_04b);
3338 OVERLAY_INFO_EXTERN(overlay_bad_add_dup_node);
3339 OVERLAY_INFO_EXTERN(overlay_bad_add_dup_prop);
3340 OVERLAY_INFO_EXTERN(overlay_bad_phandle);
3341 OVERLAY_INFO_EXTERN(overlay_bad_symbol);
3343 /* entries found by name */
3344 static struct overlay_info overlays[] = {
3345 OVERLAY_INFO(overlay_base, -9999),
3346 OVERLAY_INFO(overlay, 0),
3347 OVERLAY_INFO(overlay_0, 0),
3348 OVERLAY_INFO(overlay_1, 0),
3349 OVERLAY_INFO(overlay_2, 0),
3350 OVERLAY_INFO(overlay_3, 0),
3351 OVERLAY_INFO(overlay_4, 0),
3352 OVERLAY_INFO(overlay_5, 0),
3353 OVERLAY_INFO(overlay_6, 0),
3354 OVERLAY_INFO(overlay_7, 0),
3355 OVERLAY_INFO(overlay_8, 0),
3356 OVERLAY_INFO(overlay_9, 0),
3357 OVERLAY_INFO(overlay_10, 0),
3358 OVERLAY_INFO(overlay_11, 0),
3359 OVERLAY_INFO(overlay_12, 0),
3360 OVERLAY_INFO(overlay_13, 0),
3361 OVERLAY_INFO(overlay_15, 0),
3362 OVERLAY_INFO(overlay_16, -EBUSY),
3363 OVERLAY_INFO(overlay_17, -EEXIST),
3364 OVERLAY_INFO(overlay_18, 0),
3365 OVERLAY_INFO(overlay_19, 0),
3366 OVERLAY_INFO(overlay_20, 0),
3367 OVERLAY_INFO(overlay_gpio_01, 0),
3368 OVERLAY_INFO(overlay_gpio_02a, 0),
3369 OVERLAY_INFO(overlay_gpio_02b, 0),
3370 OVERLAY_INFO(overlay_gpio_03, 0),
3371 OVERLAY_INFO(overlay_gpio_04a, 0),
3372 OVERLAY_INFO(overlay_gpio_04b, 0),
3373 OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL),
3374 OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL),
3375 OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
3376 OVERLAY_INFO(overlay_bad_symbol, -EINVAL),
3378 {.dtbo_begin = NULL, .dtbo_end = NULL, .expected_result = 0, .name = NULL}
3381 static struct device_node *overlay_base_root;
3383 static void * __init dt_alloc_memory(u64 size, u64 align)
3385 void *ptr = memblock_alloc(size, align);
3388 panic("%s: Failed to allocate %llu bytes align=0x%llx\n",
3389 __func__, size, align);
3395 * Create base device tree for the overlay unittest.
3397 * This is called from very early boot code.
3399 * Do as much as possible the same way as done in __unflatten_device_tree
3400 * and other early boot steps for the normal FDT so that the overlay base
3401 * unflattened tree will have the same characteristics as the real tree
3402 * (such as having memory allocated by the early allocator). The goal
3403 * is to test "the real thing" as much as possible, and test "test setup
3404 * code" as little as possible.
3406 * Have to stop before resolving phandles, because that uses kmalloc.
3408 void __init unittest_unflatten_overlay_base(void)
3410 struct overlay_info *info;
3415 const char *overlay_name = "overlay_base";
3417 for (info = overlays; info && info->name; info++) {
3418 if (!strcmp(overlay_name, info->name)) {
3424 pr_err("no overlay data for %s\n", overlay_name);
3428 info = &overlays[0];
3430 if (info->expected_result != -9999) {
3431 pr_err("No dtb 'overlay_base' to attach\n");
3435 data_size = info->dtbo_end - info->dtbo_begin;
3437 pr_err("No dtb 'overlay_base' to attach\n");
3441 size = fdt_totalsize(info->dtbo_begin);
3442 if (size != data_size) {
3443 pr_err("dtb 'overlay_base' header totalsize != actual size");
3447 new_fdt = dt_alloc_memory(size, roundup_pow_of_two(FDT_V17_SIZE));
3449 pr_err("alloc for dtb 'overlay_base' failed");
3453 memcpy(new_fdt, info->dtbo_begin, size);
3455 __unflatten_device_tree(new_fdt, NULL, &overlay_base_root,
3456 dt_alloc_memory, true);
3460 * The purpose of of_unittest_overlay_data_add is to add an
3461 * overlay in the normal fashion. This is a test of the whole
3462 * picture, instead of testing individual elements.
3464 * A secondary purpose is to be able to verify that the contents of
3465 * /proc/device-tree/ contains the updated structure and values from
3466 * the overlay. That must be verified separately in user space.
3468 * Return 0 on unexpected error.
3470 static int __init overlay_data_apply(const char *overlay_name, int *ovcs_id)
3472 struct overlay_info *info;
3477 for (info = overlays; info && info->name; info++) {
3478 if (!strcmp(overlay_name, info->name)) {
3484 pr_err("no overlay data for %s\n", overlay_name);
3488 size = info->dtbo_end - info->dtbo_begin;
3490 pr_err("no overlay data for %s\n", overlay_name);
3492 ret = of_overlay_fdt_apply(info->dtbo_begin, size, &info->ovcs_id);
3494 *ovcs_id = info->ovcs_id;
3498 pr_debug("%s applied\n", overlay_name);
3501 if (ret != info->expected_result)
3502 pr_err("of_overlay_fdt_apply() expected %d, ret=%d, %s\n",
3503 info->expected_result, ret, overlay_name);
3505 return (ret == info->expected_result);
3509 * The purpose of of_unittest_overlay_high_level is to add an overlay
3510 * in the normal fashion. This is a test of the whole picture,
3511 * instead of individual elements.
3513 * The first part of the function is _not_ normal overlay usage; it is
3514 * finishing splicing the base overlay device tree into the live tree.
3516 static __init void of_unittest_overlay_high_level(void)
3518 struct device_node *last_sibling;
3519 struct device_node *np;
3520 struct device_node *of_symbols;
3521 struct device_node *overlay_base_symbols;
3522 struct device_node **pprev;
3523 struct property *prop;
3526 if (!overlay_base_root) {
3527 unittest(0, "overlay_base_root not initialized\n");
3532 * Could not fixup phandles in unittest_unflatten_overlay_base()
3533 * because kmalloc() was not yet available.
3535 of_overlay_mutex_lock();
3536 of_resolve_phandles(overlay_base_root);
3537 of_overlay_mutex_unlock();
3541 * do not allow overlay_base to duplicate any node already in
3542 * tree, this greatly simplifies the code
3546 * remove overlay_base_root node "__local_fixups", after
3547 * being used by of_resolve_phandles()
3549 pprev = &overlay_base_root->child;
3550 for (np = overlay_base_root->child; np; np = np->sibling) {
3551 if (of_node_name_eq(np, "__local_fixups__")) {
3552 *pprev = np->sibling;
3555 pprev = &np->sibling;
3558 /* remove overlay_base_root node "__symbols__" if in live tree */
3559 of_symbols = of_get_child_by_name(of_root, "__symbols__");
3561 /* will have to graft properties from node into live tree */
3562 pprev = &overlay_base_root->child;
3563 for (np = overlay_base_root->child; np; np = np->sibling) {
3564 if (of_node_name_eq(np, "__symbols__")) {
3565 overlay_base_symbols = np;
3566 *pprev = np->sibling;
3569 pprev = &np->sibling;
3573 for_each_child_of_node(overlay_base_root, np) {
3574 struct device_node *base_child;
3575 for_each_child_of_node(of_root, base_child) {
3576 if (!strcmp(np->full_name, base_child->full_name)) {
3577 unittest(0, "illegal node name in overlay_base %pOFn",
3580 of_node_put(base_child);
3587 * overlay 'overlay_base' is not allowed to have root
3588 * properties, so only need to splice nodes into main device tree.
3590 * root node of *overlay_base_root will not be freed, it is lost
3594 for (np = overlay_base_root->child; np; np = np->sibling)
3595 np->parent = of_root;
3597 mutex_lock(&of_mutex);
3599 for (last_sibling = np = of_root->child; np; np = np->sibling)
3603 last_sibling->sibling = overlay_base_root->child;
3605 of_root->child = overlay_base_root->child;
3607 for_each_of_allnodes_from(overlay_base_root, np)
3608 __of_attach_node_sysfs(np);
3611 struct property *new_prop;
3612 for_each_property_of_node(overlay_base_symbols, prop) {
3614 new_prop = __of_prop_dup(prop, GFP_KERNEL);
3616 unittest(0, "__of_prop_dup() of '%s' from overlay_base node __symbols__",
3620 if (__of_add_property(of_symbols, new_prop)) {
3621 kfree(new_prop->name);
3622 kfree(new_prop->value);
3624 /* "name" auto-generated by unflatten */
3625 if (!strcmp(prop->name, "name"))
3627 unittest(0, "duplicate property '%s' in overlay_base node __symbols__",
3631 if (__of_add_property_sysfs(of_symbols, new_prop)) {
3632 unittest(0, "unable to add property '%s' in overlay_base node __symbols__ to sysfs",
3639 mutex_unlock(&of_mutex);
3642 /* now do the normal overlay usage test */
3644 EXPECT_BEGIN(KERN_ERR,
3645 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/status");
3646 EXPECT_BEGIN(KERN_ERR,
3647 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/status");
3648 EXPECT_BEGIN(KERN_ERR,
3649 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@30/incline-up");
3650 EXPECT_BEGIN(KERN_ERR,
3651 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@40/incline-up");
3652 EXPECT_BEGIN(KERN_ERR,
3653 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/status");
3654 EXPECT_BEGIN(KERN_ERR,
3655 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/color");
3656 EXPECT_BEGIN(KERN_ERR,
3657 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/rate");
3658 EXPECT_BEGIN(KERN_ERR,
3659 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/hvac_2");
3660 EXPECT_BEGIN(KERN_ERR,
3661 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200");
3662 EXPECT_BEGIN(KERN_ERR,
3663 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_left");
3664 EXPECT_BEGIN(KERN_ERR,
3665 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_right");
3667 ret = overlay_data_apply("overlay", NULL);
3669 EXPECT_END(KERN_ERR,
3670 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_right");
3671 EXPECT_END(KERN_ERR,
3672 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_left");
3673 EXPECT_END(KERN_ERR,
3674 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200");
3675 EXPECT_END(KERN_ERR,
3676 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/hvac_2");
3677 EXPECT_END(KERN_ERR,
3678 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/rate");
3679 EXPECT_END(KERN_ERR,
3680 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/color");
3681 EXPECT_END(KERN_ERR,
3682 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/status");
3683 EXPECT_END(KERN_ERR,
3684 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@40/incline-up");
3685 EXPECT_END(KERN_ERR,
3686 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@30/incline-up");
3687 EXPECT_END(KERN_ERR,
3688 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/status");
3689 EXPECT_END(KERN_ERR,
3690 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/status");
3692 unittest(ret, "Adding overlay 'overlay' failed\n");
3694 EXPECT_BEGIN(KERN_ERR,
3695 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
3696 EXPECT_BEGIN(KERN_ERR,
3697 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
3699 unittest(overlay_data_apply("overlay_bad_add_dup_node", NULL),
3700 "Adding overlay 'overlay_bad_add_dup_node' failed\n");
3702 EXPECT_END(KERN_ERR,
3703 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
3704 EXPECT_END(KERN_ERR,
3705 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
3707 EXPECT_BEGIN(KERN_ERR,
3708 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
3709 EXPECT_BEGIN(KERN_ERR,
3710 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
3711 EXPECT_BEGIN(KERN_ERR,
3712 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
3714 unittest(overlay_data_apply("overlay_bad_add_dup_prop", NULL),
3715 "Adding overlay 'overlay_bad_add_dup_prop' failed\n");
3717 EXPECT_END(KERN_ERR,
3718 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
3719 EXPECT_END(KERN_ERR,
3720 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
3721 EXPECT_END(KERN_ERR,
3722 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
3724 unittest(overlay_data_apply("overlay_bad_phandle", NULL),
3725 "Adding overlay 'overlay_bad_phandle' failed\n");
3727 unittest(overlay_data_apply("overlay_bad_symbol", NULL),
3728 "Adding overlay 'overlay_bad_symbol' failed\n");
3733 mutex_unlock(&of_mutex);
3738 static inline __init void of_unittest_overlay_high_level(void) {}
3742 static int __init of_unittest(void)
3744 struct device_node *np;
3747 pr_info("start of unittest - you will see error messages\n");
3749 /* Taint the kernel so we know we've run tests. */
3750 add_taint(TAINT_TEST, LOCKDEP_STILL_OK);
3752 /* adding data for unittest */
3754 if (IS_ENABLED(CONFIG_UML))
3755 unittest_unflatten_overlay_base();
3757 res = unittest_data_add();
3761 of_aliases = of_find_node_by_path("/aliases");
3763 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
3765 pr_info("No testcase data in device tree; not running tests\n");
3770 of_unittest_check_tree_linkage();
3771 of_unittest_check_phandles();
3772 of_unittest_find_node_by_name();
3773 of_unittest_dynamic();
3774 of_unittest_parse_phandle_with_args();
3775 of_unittest_parse_phandle_with_args_map();
3776 of_unittest_printf();
3777 of_unittest_property_string();
3778 of_unittest_property_copy();
3779 of_unittest_changeset();
3780 of_unittest_parse_interrupts();
3781 of_unittest_parse_interrupts_extended();
3782 of_unittest_dma_get_max_cpu_address();
3783 of_unittest_parse_dma_ranges();
3784 of_unittest_pci_dma_ranges();
3785 of_unittest_bus_ranges();
3786 of_unittest_bus_3cell_ranges();
3788 of_unittest_match_node();
3789 of_unittest_platform_populate();
3790 of_unittest_overlay();
3791 of_unittest_lifecycle();
3793 /* Double check linkage after removing testcase data */
3794 of_unittest_check_tree_linkage();
3796 of_unittest_overlay_high_level();
3798 pr_info("end of unittest - %i passed, %i failed\n",
3799 unittest_results.passed, unittest_results.failed);
3803 late_initcall(of_unittest);