Lines Matching +full:0 +full:x40000000 +full:- +full:0 +full:x4fffffff
1 // SPDX-License-Identifier: GPL-2.0
6 #define pr_fmt(fmt) "### dt-test ### " fmt
10 #include <linux/dma-direct.h> /* to test phys_to_dma/dma_to_phys */
29 #include <linux/i2c-mux.h>
54 #define OF_KREF_READ(NODE) kref_read(&(NODE)->kobj.kref)
85 np = of_find_node_by_path("/testcase-data");
87 unittest(np && name && !strcmp("/testcase-data", name),
88 "find /testcase-data failed\n");
93 np = of_find_node_by_path("/testcase-data/");
94 unittest(!np, "trailing '/' on /testcase-data/ should fail\n");
96 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
98 unittest(np && name && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
99 "find /testcase-data/phandle-tests/consumer-a failed\n");
103 np = of_find_node_by_path("testcase-alias");
105 unittest(np && name && !strcmp("/testcase-data", name),
106 "find testcase-alias failed\n");
111 np = of_find_node_by_path("testcase-alias/");
112 unittest(!np, "trailing '/' on testcase-alias/ should fail\n");
114 np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
116 unittest(np && name && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
117 "find testcase-alias/phandle-tests/consumer-a failed\n");
121 np = of_find_node_by_path("/testcase-data/missing-path");
122 unittest(!np, "non-existent path returned node %pOF\n", np);
125 np = of_find_node_by_path("missing-alias");
126 unittest(!np, "non-existent alias returned node %pOF\n", np);
129 np = of_find_node_by_path("testcase-alias/missing-path");
130 unittest(!np, "non-existent alias with relative path returned node %pOF\n", np);
133 np = of_find_node_opts_by_path("/testcase-data:testoption", &options);
138 np = of_find_node_opts_by_path("/testcase-data:test/option", &options);
143 np = of_find_node_opts_by_path("/testcase-data/testcase-device1:test/option", &options);
148 np = of_find_node_opts_by_path("/testcase-data:testoption", NULL);
152 np = of_find_node_opts_by_path("testcase-alias:testaliasoption",
158 np = of_find_node_opts_by_path("testcase-alias:test/alias/option",
164 np = of_find_node_opts_by_path("testcase-alias/phandle-tests/consumer-a:testaliasoption",
167 unittest(np && name && !strcmp("/testcase-data/phandle-tests/consumer-a", name) &&
173 np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL);
178 np = of_find_node_opts_by_path("testcase-alias", &options);
193 np = of_find_node_by_path("/testcase-data");
202 unittest(0, "kzalloc() failed\n");
206 /* Add a new property - should pass*/
207 prop->name = "new-property";
208 prop->value = "new-property-data";
209 prop->length = strlen(prop->value) + 1;
210 unittest(of_add_property(np, prop) == 0, "Adding a new property failed\n");
212 /* Try to add an existing property - should fail */
214 prop->name = "new-property";
215 prop->value = "new-property-data-should-fail";
216 prop->length = strlen(prop->value) + 1;
217 unittest(of_add_property(np, prop) != 0,
220 /* Try to modify an existing property - should pass */
221 prop->value = "modify-property-data-should-pass";
222 prop->length = strlen(prop->value) + 1;
223 unittest(of_update_property(np, prop) == 0,
226 /* Try to modify non-existent property - should pass*/
228 prop->name = "modify-property";
229 prop->value = "modify-missing-property-data-should-pass";
230 prop->length = strlen(prop->value) + 1;
231 unittest(of_update_property(np, prop) == 0,
234 /* Remove property - should pass */
235 unittest(of_remove_property(np, prop) == 0,
238 /* Adding very large property - should pass */
240 prop->name = "large-property-PAGE_SIZEx8";
241 prop->length = PAGE_SIZE * 8;
242 prop->value = kzalloc(prop->length, GFP_KERNEL);
243 unittest(prop->value != NULL, "Unable to allocate large buffer\n");
244 if (prop->value)
245 unittest(of_add_property(np, prop) == 0,
251 int count = 0, rc;
254 if (child->parent != np) {
257 return -EINVAL;
261 if (rc < 0)
272 int allnode_count = 0, child_count;
281 unittest(child_count > 0, "Device node data structure is corrupted\n");
301 memset(buf, 0xff, buf_size);
302 size = snprintf(buf, buf_size - 2, fmt, np);
305 unittest((strcmp(buf, expected) == 0) && (buf[size+1] == 0xff),
311 for (i = 0; i < 2; i++, size--) {
313 memset(buf, 0xff, buf_size);
315 unittest(strncmp(buf, expected, size) == 0 && (buf[size+1] == 0xff),
325 const char *full_name = "/testcase-data/platform-tests/test-device@1/dev@100";
334 num_to_str(phandle_str, sizeof(phandle_str), np->phandle, 0);
341 of_unittest_printf_one(np, "%pOFnc", "dev:test-sub-device");
346 of_unittest_printf_one(np, "%-10pOFP", "dev@100 ");
348 of_unittest_printf_one(np, "%pOFF", "----");
349 of_unittest_printf_one(np, "%pOFPF", "dev@100:----");
350 of_unittest_printf_one(np, "%pOFPFPc", "dev@100:----:dev@100:test-sub-device");
351 of_unittest_printf_one(np, "%pOFc", "test-sub-device");
353 "\"test-sub-device\",\"test-compat2\",\"test-compat3\"");
367 int i, dup_count = 0, phandle_count = 0;
370 if (!np->phandle)
373 hash_for_each_possible(phandle_ht, nh, node, np->phandle) {
374 if (nh->np->phandle == np->phandle) {
376 np->phandle, nh->np, np);
386 nh->np = np;
387 hash_add(phandle_ht, &nh->node, np->phandle);
390 unittest(dup_count == 0, "Found %i duplicates in %i phandles\n",
395 hash_del(&nh->node);
406 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
412 rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
415 for (i = 0; i < 8; i++) {
418 memset(&args, 0, sizeof(args));
419 rc = of_parse_phandle_with_args(np, "phandle-list",
420 "#phandle-cells", i, &args);
422 /* Test the values from tests-phandle.dtsi */
424 case 0:
427 passed &= (args.args[0] == (i + 1));
432 passed &= (args.args[0] == (i + 1));
433 passed &= (args.args[1] == 0);
436 passed &= (rc == -ENOENT);
441 passed &= (args.args[0] == (i + 1));
448 passed &= (args.args[0] == (i + 1));
453 passed &= (args.args_count == 0);
458 passed &= (args.args[0] == (i + 1));
461 passed &= (rc == -ENOENT);
467 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
470 if (rc == 0)
475 memset(&args, 0, sizeof(args));
476 rc = of_parse_phandle_with_args(np, "phandle-list-missing",
477 "#phandle-cells", 0, &args);
478 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
479 rc = of_count_phandle_with_args(np, "phandle-list-missing",
480 "#phandle-cells");
481 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
484 memset(&args, 0, sizeof(args));
487 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
489 rc = of_parse_phandle_with_args(np, "phandle-list",
490 "#phandle-cells-missing", 0, &args);
493 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
495 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
498 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
500 rc = of_count_phandle_with_args(np, "phandle-list",
501 "#phandle-cells-missing");
504 "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
506 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
509 memset(&args, 0, sizeof(args));
512 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
514 rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
515 "#phandle-cells", 0, &args);
518 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
520 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
523 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
525 rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle",
526 "#phandle-cells");
529 "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
531 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
534 memset(&args, 0, sizeof(args));
537 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
539 rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
540 "#phandle-cells", 1, &args);
543 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
545 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
548 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
550 rc = of_count_phandle_with_args(np, "phandle-list-bad-args",
551 "#phandle-cells");
554 "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found 1");
556 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
566 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-b");
572 p[0] = of_find_node_by_path("/testcase-data/phandle-tests/provider0");
573 p[1] = of_find_node_by_path("/testcase-data/phandle-tests/provider1");
574 p[2] = of_find_node_by_path("/testcase-data/phandle-tests/provider2");
575 p[3] = of_find_node_by_path("/testcase-data/phandle-tests/provider3");
576 p[4] = of_find_node_by_path("/testcase-data/phandle-tests/provider4");
577 p[5] = of_find_node_by_path("/testcase-data/phandle-tests/provider5");
578 for (i = 0; i < ARRAY_SIZE(p); ++i) {
586 rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
589 for (i = 0; i < 9; i++) {
592 memset(&args, 0, sizeof(args));
593 rc = of_parse_phandle_with_args_map(np, "phandle-list",
596 /* Test the values from tests-phandle.dtsi */
598 case 0:
602 passed &= (args.args[0] == 1);
608 passed &= (args.args[0] == 2);
613 passed &= (rc == -ENOENT);
617 passed &= (args.np == p[0]);
618 passed &= (args.args_count == 0);
624 passed &= (args.args[0] == 3);
628 passed &= (args.np == p[0]);
629 passed &= (args.args_count == 0);
635 passed &= (args.args[0] == 15);
636 passed &= (args.args[1] == 0x20);
642 passed &= (args.args[0] == 2);
647 passed &= (rc == -ENOENT);
653 unittest(passed, "index %i - data error on node %s rc=%i\n",
654 i, args.np->full_name, rc);
656 if (rc == 0)
661 memset(&args, 0, sizeof(args));
662 rc = of_parse_phandle_with_args_map(np, "phandle-list-missing",
663 "phandle", 0, &args);
664 unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
667 memset(&args, 0, sizeof(args));
670 "OF: /testcase-data/phandle-tests/consumer-b: could not get #phandle-missing-cells for /testcase-data/phandle-tests/provider1");
672 rc = of_parse_phandle_with_args_map(np, "phandle-list",
673 "phandle-missing", 0, &args);
675 "OF: /testcase-data/phandle-tests/consumer-b: could not get #phandle-missing-cells for /testcase-data/phandle-tests/provider1");
677 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
680 memset(&args, 0, sizeof(args));
683 "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle 12345678");
685 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle",
686 "phandle", 0, &args);
688 "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle 12345678");
690 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
693 memset(&args, 0, sizeof(args));
696 "OF: /testcase-data/phandle-tests/consumer-b: #phandle-cells = 2 found 1");
698 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args",
701 "OF: /testcase-data/phandle-tests/consumer-b: #phandle-cells = 2 found 1");
703 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
705 for (i = 0; i < ARRAY_SIZE(p); ++i) {
719 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
725 rc = of_property_match_string(np, "phandle-list-names", "first");
726 unittest(rc == 0, "first expected:0 got:%i\n", rc);
727 rc = of_property_match_string(np, "phandle-list-names", "second");
729 rc = of_property_match_string(np, "phandle-list-names", "third");
731 rc = of_property_match_string(np, "phandle-list-names", "fourth");
732 unittest(rc == -ENODATA, "unmatched string; rc=%i\n", rc);
733 rc = of_property_match_string(np, "missing-property", "blah");
734 unittest(rc == -EINVAL, "missing property; rc=%i\n", rc);
735 rc = of_property_match_string(np, "empty-property", "blah");
736 unittest(rc == -ENODATA, "empty property; rc=%i\n", rc);
737 rc = of_property_match_string(np, "unterminated-string", "blah");
738 unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
741 rc = of_property_count_strings(np, "string-property");
743 rc = of_property_count_strings(np, "phandle-list-names");
745 rc = of_property_count_strings(np, "unterminated-string");
746 unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
747 rc = of_property_count_strings(np, "unterminated-string-list");
748 unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
751 rc = of_property_read_string_index(np, "string-property", 0, strings);
752 unittest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc);
753 strings[0] = NULL;
754 rc = of_property_read_string_index(np, "string-property", 1, strings);
755 unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
756 rc = of_property_read_string_index(np, "phandle-list-names", 0, strings);
757 unittest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
758 rc = of_property_read_string_index(np, "phandle-list-names", 1, strings);
759 unittest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc);
760 rc = of_property_read_string_index(np, "phandle-list-names", 2, strings);
761 unittest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc);
762 strings[0] = NULL;
763 rc = of_property_read_string_index(np, "phandle-list-names", 3, strings);
764 unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
765 strings[0] = NULL;
766 rc = of_property_read_string_index(np, "unterminated-string", 0, strings);
767 unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
768 rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings);
769 unittest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
770 strings[0] = NULL;
771 rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */
772 unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
776 rc = of_property_read_string_array(np, "string-property", strings, 4);
778 rc = of_property_read_string_array(np, "phandle-list-names", strings, 4);
780 rc = of_property_read_string_array(np, "unterminated-string", strings, 4);
781 unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
782 /* -- An incorrectly formed string should cause a failure */
783 rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4);
784 unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
785 /* -- parsing the correctly formed strings should still work: */
787 rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2);
790 rc = of_property_read_string_array(np, "phandle-list-names", strings, 1);
794 #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
795 (p1)->value && (p2)->value && \
796 !memcmp((p1)->value, (p2)->value, (p1)->length) && \
797 !strcmp((p1)->name, (p2)->name))
801 struct property p1 = { .name = "p1", .length = 0, .value = "" };
810 unittest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
819 struct property *ppadd, padd = { .name = "prop-add", .length = 1, .value = "" };
823 struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" };
840 nchangeset = of_find_node_by_path("/testcase-data/changeset");
841 nremove = of_get_child_by_name(nchangeset, "node-remove");
860 n1->parent = parent;
861 n2->parent = parent;
862 n21->parent = n2;
864 ppremove = of_find_property(parent, "prop-remove", NULL);
880 unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop prop-add\n");
885 unittest(!of_changeset_add_prop_string(&chgset, n22, "prop-str", "abcd"),
886 "fail add prop prop-str");
887 unittest(!of_changeset_add_prop_string_array(&chgset, n22, "prop-str-array",
890 "fail add prop prop-str-array");
891 unittest(!of_changeset_add_prop_u32_array(&chgset, n22, "prop-u32-array",
893 "fail add prop prop-u32-array");
900 unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")),
903 unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n22")),
909 unittest(!of_find_node_by_path("/testcase-data/changeset/n2/n21"),
912 unittest(of_property_present(parent, "prop-remove"),
915 ret = of_property_read_string(parent, "prop-update", &propstr);
918 unittest(strcmp(propstr, "hello") == 0, "original value not in updated property after revert");
937 if (unittest(ret == 0, "failed to read %s\n", prop_name))
940 unittest(strcmp(str, expected_str) == 0,
956 if (unittest(cnt >= 0, "failed to get %s count\n", prop_name))
964 for (i = 0; i < count; i++) {
966 if (unittest(ret == 0, "failed to read %s[%d]\n", prop_name, i))
969 unittest(strcmp(str, expected_array[i]) == 0,
983 if (unittest(ret == 0, "failed to read %s\n", prop_name))
1002 if (unittest(cnt >= 0, "failed to get %s count\n", prop_name))
1010 for (i = 0; i < count; i++) {
1012 if (unittest(ret == 0, "failed to read %s[%d]\n", prop_name, i))
1037 nchangeset = of_find_node_by_path("/testcase-data/changeset");
1045 np = of_changeset_create_node(&chgset, nchangeset, "test-prop");
1046 if (unittest(np, "failed to create test-prop node\n"))
1049 ret = of_changeset_add_prop_string(&chgset, np, "prop-string", "abcde");
1050 unittest(ret == 0, "failed to add prop-string\n");
1052 ret = of_changeset_add_prop_string_array(&chgset, np, "prop-string-array",
1054 unittest(ret == 0, "failed to add prop-string-array\n");
1056 ret = of_changeset_add_prop_u32(&chgset, np, "prop-u32", 1234);
1057 unittest(ret == 0, "failed to add prop-u32\n");
1059 ret = of_changeset_add_prop_u32_array(&chgset, np, "prop-u32-array",
1061 unittest(ret == 0, "failed to add prop-u32-array\n");
1063 ret = of_changeset_add_prop_bool(&chgset, np, "prop-bool");
1064 unittest(ret == 0, "failed to add prop-bool\n");
1069 if (unittest(ret == 0, "failed to apply changeset\n"))
1072 np = of_find_node_by_path("/testcase-data/changeset/test-prop");
1073 if (unittest(np, "failed to find test-prop node\n"))
1076 changeset_check_string(np, "prop-string", "abcde");
1077 changeset_check_string_array(np, "prop-string-array", str_array, ARRAY_SIZE(str_array));
1078 changeset_check_u32(np, "prop-u32", 1234);
1079 changeset_check_u32_array(np, "prop-u32-array", u32_array, ARRAY_SIZE(u32_array));
1080 changeset_check_bool(np, "prop-bool");
1086 unittest(ret == 0, "failed to revert changeset\n");
1102 np = of_find_node_by_path("/testcase-data/address-tests");
1109 unittest(cpu_addr == 0x4fffffff,
1111 &cpu_addr, 0x4fffffff);
1139 unittest(0, "kzalloc() failed\n");
1144 dev_bogus->dma_range_map = map;
1164 of_unittest_dma_ranges_one("/testcase-data/address-tests/device@70000000",
1165 0x0, 0x20000000);
1167 of_unittest_dma_ranges_one("/testcase-data/address-tests/bus@80000000/device@1000",
1168 0x100000000, 0x20000000);
1169 of_unittest_dma_ranges_one("/testcase-data/address-tests/pci@90000000",
1170 0x80000000, 0x20000000);
1178 int i = 0;
1183 np = of_find_node_by_path("/testcase-data/address-tests/pci@90000000");
1190 pr_err("missing dma-ranges property\n");
1195 * Get the dma-ranges from the device tree
1199 unittest(range.size == 0x10000000,
1202 unittest(range.cpu_addr == 0x20000000,
1205 unittest(range.pci_addr == 0x80000000,
1209 unittest(range.size == 0x10000000,
1212 unittest(range.cpu_addr == 0x40000000,
1215 unittest(range.pci_addr == 0xc0000000,
1234 np = of_find_node_by_path("/testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0");
1241 pr_err("missing dma-ranges property\n");
1246 * Get the dma-ranges from the device tree
1249 unittest(range.size == 0x10000000,
1252 unittest(range.cpu_addr == 0x00000000,
1255 unittest(range.pci_addr == 0xc0000000,
1269 int ret, count, i = 0;
1271 np = of_find_node_by_path("/testcase-data/address-tests");
1288 unittest(res.start == 0xd0000000,
1291 unittest(resource_size(&res) == 0x20000000,
1308 unittest(range.size == 0x50000000,
1311 unittest(range.cpu_addr == 0x70000000,
1314 unittest(range.bus_addr == 0x70000000,
1318 unittest(range.size == 0x20000000,
1321 unittest(range.cpu_addr == 0xd0000000,
1324 unittest(range.bus_addr == 0x00000000,
1339 int i = 0;
1341 np = of_find_node_by_path("/testcase-data/address-tests/bus@a0000000");
1357 unittest(range.flags == 0xf00baa,
1360 unittest(range.size == 0x100000,
1363 unittest(range.cpu_addr == 0xa0000000,
1366 unittest(range.bus_addr == 0x0,
1370 unittest(range.flags == 0xf00bee,
1373 unittest(range.size == 0x200000,
1376 unittest(range.cpu_addr == 0xb0000000,
1379 unittest(range.bus_addr == 0x100000000,
1396 np = of_find_node_by_path("/testcase-data/address-tests/bus@80000000/device@1000");
1402 ret = of_property_read_reg(np, 0, &addr, &size);
1405 unittest(addr == 0x1000, "of_property_read_reg(%pOF) untranslated address (%llx) incorrect\n",
1410 np = of_find_node_by_path("/testcase-data/platform-tests-2/node/test-device@100");
1416 ret = of_address_to_resource(np, 0, &res);
1417 unittest(ret == -EINVAL, "of_address_to_resource(%pOF) expected error on untranslatable address\n",
1450 while (count--) {
1451 ret = of_address_to_resource(np, expected->index, &res);
1453 np, expected->index, ret);
1454 unittest(resource_type(&res) == resource_type(&expected->res) &&
1455 res.start == expected->res.start &&
1456 resource_size(&res) == resource_size(&expected->res),
1458 np, expected->index, &res, &expected->res);
1466 {.index = 0, .res = DEFINE_RES_MEM(0xa0a01000, 0x100) },
1467 {.index = 1, .res = DEFINE_RES_MEM(0xa0a02000, 0x100) },
1468 {.index = 2, .res = DEFINE_RES_MEM(0xc0c01000, 0x100) },
1469 {.index = 3, .res = DEFINE_RES_MEM(0xd0d01000, 0x100) },
1473 {.index = 0, .res = DEFINE_RES_MEM(0xa0a01000, 0x100) },
1474 {.index = 1, .res = DEFINE_RES_MEM(0xa0b02000, 0x100) },
1475 {.index = 2, .res = DEFINE_RES_MEM(0xc0c01000, 0x100) },
1476 {.index = 3, .res = DEFINE_RES_MEM(0xc0c09000, 0x100) },
1477 {.index = 4, .res = DEFINE_RES_MEM(0xd0d01000, 0x100) },
1481 {.index = 0, .res = DEFINE_RES_MEM(0xe8001000, 0x1000) },
1482 {.index = 1, .res = DEFINE_RES_MEM(0xea002000, 0x2000) },
1487 of_unittest_check_addr("/testcase-data/address-tests2/bus-2cell@10000000/device@100000",
1491 of_unittest_check_addr("/testcase-data/address-tests2/bus-3cell@20000000/local-bus@100000/device@f1001000",
1495 of_unittest_check_addr("/testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0/dev@e0000000",
1509 np = of_find_node_by_path("/testcase-data/interrupts/interrupts0");
1515 for (i = 0; i < 4; i++) {
1518 memset(&args, 0, sizeof(args));
1523 passed &= (args.args[0] == (i + 1));
1525 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
1530 np = of_find_node_by_path("/testcase-data/interrupts/interrupts1");
1536 for (i = 0; i < 4; i++) {
1539 memset(&args, 0, sizeof(args));
1542 /* Test the values from tests-phandle.dtsi */
1544 case 0:
1547 passed &= (args.args[0] == 9);
1552 passed &= (args.args[0] == 10);
1559 passed &= (args.args[0] == 13);
1565 passed &= (args.args[0] == 15);
1571 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
1586 np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0");
1592 for (i = 0; i < 7; i++) {
1595 memset(&args, 0, sizeof(args));
1598 /* Test the values from tests-phandle.dtsi */
1600 case 0:
1603 passed &= (args.args[0] == 1);
1608 passed &= (args.args[0] == 2);
1615 passed &= (args.args[0] == 5);
1621 passed &= (args.args[0] == 9);
1626 passed &= (args.args[0] == 10);
1633 passed &= (args.args[0] == 13);
1639 * #address-cells. See the comments in
1640 * drivers/of/unittest-data/tests-interrupts.dtsi
1641 * nodes intmap1 and interrupts-extended0
1645 passed &= (args.args[0] == 15);
1651 unittest(passed, "index %i - data error on node %pOF rc=%i\n",
1678 { .path = "/testcase-data/match-node/name0", .data = "A", },
1679 { .path = "/testcase-data/match-node/name1", .data = "B", },
1680 { .path = "/testcase-data/match-node/a/name2", .data = "Ca", },
1681 { .path = "/testcase-data/match-node/b/name2", .data = "Cb", },
1682 { .path = "/testcase-data/match-node/c/name2", .data = "Cc", },
1683 { .path = "/testcase-data/match-node/name3", .data = "E", },
1684 { .path = "/testcase-data/match-node/name4", .data = "G", },
1685 { .path = "/testcase-data/match-node/name5", .data = "H", },
1686 { .path = "/testcase-data/match-node/name6", .data = "G", },
1687 { .path = "/testcase-data/match-node/name7", .data = "I", },
1688 { .path = "/testcase-data/match-node/name8", .data = "J", },
1689 { .path = "/testcase-data/match-node/name9", .data = "K", },
1698 for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) {
1701 unittest(0, "missing testcase node %s\n",
1708 unittest(0, "%s didn't match anything\n",
1713 if (strcmp(match->data, match_node_tests[i].data) != 0) {
1714 unittest(0, "%s got wrong match. expected %s, got %s\n",
1716 (const char *)match->data);
1723 static struct resource test_bus_res = DEFINE_RES_MEM(0xfffffff8, 2);
1725 .name = "unittest-bus",
1733 { .compatible = "test-device", },
1737 np = of_find_node_by_path("/testcase-data");
1740 /* Test that a missing irq domain returns -EPROBE_DEFER */
1741 np = of_find_node_by_path("/testcase-data/testcase-device1");
1746 irq = platform_get_irq(pdev, 0);
1747 unittest(irq == -EPROBE_DEFER,
1748 "device deferred probe failed - %d\n", irq);
1750 /* Test that a parsing failure does not return -EPROBE_DEFER */
1751 np = of_find_node_by_path("/testcase-data/testcase-device2");
1756 "platform testcase-data:testcase-device2: error -ENXIO: IRQ index 0 not found");
1758 irq = platform_get_irq(pdev, 0);
1761 "platform testcase-data:testcase-device2: error -ENXIO: IRQ index 0 not found");
1763 unittest(irq < 0 && irq != -EPROBE_DEFER,
1764 "device parsing error failed - %d\n", irq);
1767 np = of_find_node_by_path("/testcase-data/platform-tests");
1779 test_bus->dev.of_node = np;
1783 * registered to catch problems with un-inserted resources. The
1790 of_platform_populate(np, match, NULL, &test_bus->dev);
1801 of_platform_depopulate(&test_bus->dev);
1814 * update_node_properties - adds the properties
1830 child->parent = dup;
1839 * compiled with the '-@' option. If you encounter this error,
1847 * sets prop->next to NULL
1849 for (prop = np->properties; prop != NULL; prop = save_next) {
1850 save_next = prop->next;
1853 if (ret == -EEXIST && !strcmp(prop->name, "name"))
1856 np, prop->name);
1862 * attach_node_and_children - attaches nodes
1864 * CAUTION: misleading function name - if node @np already exists in
1894 child = np->child;
1895 np->child = NULL;
1899 np->sibling = np->parent->child;
1900 np->parent->child = np;
1908 next = child->sibling;
1915 * unittest_data_add - Reads, copies data from
1929 const int size = __dtbo_testcases_end - __dtbo_testcases_begin;
1935 return -ENODATA;
1941 return -ENOMEM;
1950 return -ENODATA;
1955 return -ENODATA;
1967 return -EINVAL;
1970 /* attach the sub-tree to live tree */
1972 pr_warn("%s: no live tree to attach sub-tree\n", __func__);
1974 return -ENODEV;
1978 "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
1980 np = unittest_data_node->child;
1982 struct device_node *next = np->sibling;
1984 np->parent = of_root;
1991 "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
1995 return 0;
2003 struct device *dev = &pdev->dev;
2004 struct device_node *np = dev->of_node;
2008 return -EINVAL;
2014 of_platform_populate(np, NULL, NULL, &pdev->dev);
2016 return 0;
2021 struct device *dev = &pdev->dev;
2022 struct device_node *np = dev->of_node;
2081 pr_debug("%s(): %s %d %d\n", __func__, chip->label, offset,
2083 return 0;
2095 return -ENOMEM;
2099 devptr->chip.fwnode = dev_fwnode(&pdev->dev);
2100 devptr->chip.label = "of-unittest-gpio";
2101 devptr->chip.base = -1; /* dynamic allocation */
2102 devptr->chip.ngpio = 5;
2103 devptr->chip.request = unittest_gpio_chip_request;
2105 ret = gpiochip_add_data(&devptr->chip, NULL);
2108 "gpiochip_add_data() for node @%pfw failed, ret = %d\n", devptr->chip.fwnode, ret);
2118 struct device *dev = &pdev->dev;
2120 dev_dbg(dev, "%s for node @%pfw\n", __func__, devptr->chip.fwnode);
2122 if (devptr->chip.base != -1)
2123 gpiochip_remove(&devptr->chip);
2129 { .compatible = "unittest-gpio", },
2137 .name = "unittest-gpio",
2158 * - apply overlay_gpio_01
2159 * - apply overlay_gpio_02a
2160 * - apply overlay_gpio_02b
2161 * - register driver
2164 * - probe and processing gpio hog for overlay_gpio_01
2165 * - probe for overlay_gpio_02a
2166 * - processing gpio for overlay_gpio_02b
2188 if (unittest(ret == 0, "could not register unittest gpio driver\n"))
2196 unittest_gpio_chip_request_count - chip_request_count);
2201 * Similar to a driver built-in to the kernel, the
2206 * - apply overlay_gpio_03
2209 * - probe and processing gpio hog.
2225 unittest_gpio_chip_request_count - chip_request_count);
2230 * - apply overlay_gpio_04a
2233 * - probe for overlay_gpio_04a
2250 * - apply overlay_gpio_04b
2253 * - processing gpio for overlay_gpio_04b
2263 unittest_gpio_chip_request_count - chip_request_count);
2300 put_device(&client->dev);
2306 return 0;
2324 return 0;
2334 base = "/testcase-data/overlay-node/test-bus";
2337 base = "/testcase-data/overlay-node/test-bus/i2c-test-bus";
2340 buf[0] = '\0';
2343 snprintf(buf, sizeof(buf) - 1, "%s/test-unittest%d", base, nr);
2344 buf[sizeof(buf) - 1] = '\0';
2360 return 0;
2367 snprintf(buf, sizeof(buf) - 1,
2369 buf[sizeof(buf) - 1] = '\0';
2374 static const char *bus_path = "/testcase-data/overlay-node/test-bus";
2397 track_ovcs_id_cnt--;
2408 while (track_ovcs_id_cnt > 0) {
2410 ovcs_id = track_ovcs_id[track_ovcs_id_cnt - 1];
2411 overlay_nr = track_ovcs_id_overlay_nr[track_ovcs_id_cnt - 1];
2414 if (ret == -ENODEV) {
2436 unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2437 return -EFAULT;
2441 return 0;
2452 unittest(0, "%s with device @\"%s\" %s\n",
2456 return -EINVAL;
2460 ovcs_id = 0;
2462 if (ret != 0) {
2469 unittest(0, "%s with device @\"%s\" %s\n",
2473 return -EINVAL;
2486 if (ovcs_id < 0)
2489 return 0;
2501 if (ovcs_id < 0)
2507 if (ret != 0) {
2508 unittest(0, "%s failed to be destroyed @\"%s\"\n",
2517 unittest(0, "%s with device @\"%s\" %s\n",
2521 return -EINVAL;
2524 return 0;
2533 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest0/status");
2536 ret = of_unittest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY);
2539 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest0/status");
2544 unittest(1, "overlay test %d passed\n", 0);
2553 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest1/status");
2556 ret = of_unittest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY);
2559 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest1/status");
2574 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest2/status");
2577 ret = of_unittest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY);
2580 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest2/status");
2593 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest3/status");
2596 ret = of_unittest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY);
2599 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest3/status");
2611 if (of_unittest_apply_overlay_check(4, 4, 0, 1, PDEV_OVERLAY))
2623 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest5/status");
2626 ret = of_unittest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY);
2629 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest5/status");
2642 int before = 0, after = 1;
2648 for (i = 0; i < 2; i++) {
2651 unittest(0, "%s with device @\"%s\" %s\n",
2663 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest6/status");
2665 overlay_name = overlay_name_from_nr(overlay_nr + 0);
2670 unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2673 save_ovcs_id[0] = ovcs_id;
2674 of_unittest_track_overlay(ovcs_id, overlay_nr + 0);
2677 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest6/status");
2680 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest7/status");
2687 unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2694 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest7/status");
2697 for (i = 0; i < 2; i++) {
2701 unittest(0, "overlay @\"%s\" failed @\"%s\" %s\n",
2710 for (i = 1; i >= 0; i--) {
2713 unittest(0, "%s failed destroy @\"%s\"\n",
2722 for (i = 0; i < 2; i++) {
2726 unittest(0, "%s with device @\"%s\" %s\n",
2750 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/status");
2752 overlay_name = overlay_name_from_nr(overlay_nr + 0);
2756 unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2759 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/status");
2764 save_ovcs_id[0] = ovcs_id;
2765 of_unittest_track_overlay(ovcs_id, overlay_nr + 0);
2770 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/property-foo");
2776 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/property-foo");
2779 unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2787 ovcs_id = save_ovcs_id[0];
2790 "OF: overlay: node_overlaps_later_cs: #6 overlaps with #7 @/testcase-data/overlay-node/test-bus/test-unittest8");
2801 "OF: overlay: node_overlaps_later_cs: #6 overlaps with #7 @/testcase-data/overlay-node/test-bus/test-unittest8");
2808 unittest(0, "%s was destroyed @\"%s\"\n",
2809 overlay_name_from_nr(overlay_nr + 0),
2816 for (i = 1; i >= 0; i--) {
2819 unittest(0, "%s not destroyed @\"%s\"\n",
2838 ret = of_unittest_apply_overlay_check(10, 10, 0, 1, PDEV_OVERLAY);
2840 if (unittest(ret == 0,
2844 child_path = kasprintf(GFP_KERNEL, "%s/test-unittest101",
2861 ret = of_unittest_apply_revert_overlay_check(11, 11, 0, 1,
2864 unittest(ret == 0, "overlay test %d failed; overlay apply\n", 11);
2896 struct device *dev = &pdev->dev;
2897 struct device_node *np = dev->of_node;
2904 return -EINVAL;
2912 return -ENOMEM;
2915 std->pdev = pdev;
2918 adap = &std->adap;
2920 adap->nr = -1;
2921 strscpy(adap->name, pdev->name, sizeof(adap->name));
2922 adap->class = I2C_CLASS_DEPRECATED;
2923 adap->algo = &unittest_i2c_algo;
2924 adap->dev.parent = dev;
2925 adap->dev.of_node = dev->of_node;
2926 adap->timeout = 5 * HZ;
2927 adap->retries = 3;
2930 if (ret != 0) {
2935 return 0;
2940 struct device *dev = &pdev->dev;
2941 struct device_node *np = dev->of_node;
2945 i2c_del_adapter(&std->adap);
2949 { .compatible = "unittest-i2c-bus", },
2957 .name = "unittest-i2c-bus",
2964 struct device *dev = &client->dev;
2965 struct device_node *np = client->dev.of_node;
2969 return -EINVAL;
2974 return 0;
2979 struct device *dev = &client->dev;
2980 struct device_node *np = client->dev.of_node;
2986 { .name = "unittest-i2c-dev" },
2992 .name = "unittest-i2c-dev",
3003 return 0;
3009 struct device *dev = &client->dev;
3010 struct i2c_adapter *adap = client->adapter;
3011 struct device_node *np = client->dev.of_node, *child;
3019 return -EINVAL;
3022 max_reg = (u32)-1;
3026 if (max_reg == (u32)-1 || reg > max_reg)
3029 nchans = max_reg == (u32)-1 ? 0 : max_reg + 1;
3030 if (nchans == 0) {
3032 return -EINVAL;
3035 muxc = i2c_mux_alloc(adap, dev, nchans, 0, 0,
3038 return -ENOMEM;
3039 for (i = 0; i < nchans; i++) {
3040 if (i2c_mux_add_adapter(muxc, 0, i)) {
3043 return -ENODEV;
3049 return 0;
3054 struct device *dev = &client->dev;
3055 struct device_node *np = client->dev.of_node;
3063 { .name = "unittest-i2c-mux" },
3069 .name = "unittest-i2c-mux",
3083 if (unittest(ret == 0,
3089 if (unittest(ret == 0,
3096 "i2c i2c-1: Added multiplexed i2c bus 2");
3101 "i2c i2c-1: Added multiplexed i2c bus 2");
3103 if (unittest(ret == 0,
3108 return 0;
3126 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12/status");
3128 ret = of_unittest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY);
3131 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12/status");
3145 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13/status");
3148 ret = of_unittest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY);
3151 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13/status");
3170 "i2c i2c-1: Added multiplexed i2c bus 3");
3172 ret = of_unittest_apply_overlay_check(15, 15, 0, 1, I2C_OVERLAY);
3175 "i2c i2c-1: Added multiplexed i2c bus 3");
3201 * ret = -EBUSY which is -16.
3209 ret = 0;
3210 of_node_get(nd->overlay);
3215 found = of_find_node_by_name(nd->overlay, "test-unittest16");
3218 ret = -EBUSY;
3223 found = of_find_node_by_name(nd->overlay, "test-unittest17");
3226 ret = -EEXIST;
3231 found = of_find_node_by_name(nd->overlay, "test-unittest18");
3234 ret = -EXDEV;
3239 found = of_find_node_by_name(nd->overlay, "test-unittest19");
3242 ret = -ENODEV;
3247 of_node_put(nd->overlay);
3248 ret = -EINVAL;
3279 * Applying overlays 16 - 19 will each trigger an error for a
3285 /* --- overlay 16 --- */
3287 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset pre-apply notifier error -16, target: /testcase-data/overlay-node/test-bus");
3292 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset pre-apply notifier error -16, target: /testcase-data/overlay-node/test-bus");
3296 /* --- overlay 17 --- */
3298 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset post-apply notifier error -17, target: /testcase-data/overlay-node/test-bus");
3303 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset post-apply notifier error -17, target: /testcase-data/overlay-node/test-bus");
3307 /* --- overlay 18 --- */
3315 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset pre-remove notifier error -18, target: /testcase-data/overlay-node/test-bus");
3318 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset pre-remove notifier error -18, target: /testcase-data/overlay-node/test-bus");
3319 if (ret == -EXDEV) {
3325 unittest(0, "overlay_18 of_overlay_remove() injected error for OF_OVERLAY_PRE_REMOVE not returned\n");
3333 /* --- overlay 19 --- */
3341 EXPECT_BEGIN(KERN_INFO, "OF: overlay: overlay changeset post-remove notifier error -19, target: /testcase-data/overlay-node/test-bus");
3343 EXPECT_END(KERN_INFO, "OF: overlay: overlay changeset post-remove notifier error -19, target: /testcase-data/overlay-node/test-bus");
3344 if (ret == -ENODEV)
3347 unittest(0, "overlay_19 of_overlay_remove() injected error for OF_OVERLAY_POST_REMOVE not returned\n");
3355 /* --- overlay 20 --- */
3379 unittest(0, "could not register unittest driver\n");
3385 unittest(0, "could not find bus_path \"%s\"\n", bus_path);
3390 unittest(0, "could not populate bus @ \"%s\"\n", bus_path);
3395 unittest(0, "could not find unittest0 @ \"%s\"\n",
3401 unittest(0, "unittest1 @ \"%s\" should not exist\n",
3414 for (i = 0; i < 3; i++)
3423 if (unittest(of_unittest_overlay_i2c_init() == 0, "i2c init failed\n"))
3452 int found_refcount_one = 0;
3453 int put_count = 0;
3456 const char *refcount_path = "/testcase-data/refcount-node";
3457 const char *refcount_parent_path = "/testcase-data";
3460 * Node lifecycle tests, non-dynamic node:
3462 * - Decrementing refcount to zero via of_node_put() should cause the
3466 * - Decrementing refcount past zero should result in additional
3478 unittest(0, "guardrail to avoid infinite loop\n");
3482 refcount = kref_read(&np->kobj.kref);
3489 EXPECT_BEGIN(KERN_INFO, "OF: ERROR: of_node_release() detected bad of_node_put() on /testcase-data/refcount-node");
3496 unittest(1, "/testcase-data/refcount-node is one");
3499 EXPECT_END(KERN_INFO, "OF: ERROR: of_node_release() detected bad of_node_put() on /testcase-data/refcount-node");
3510 EXPECT_BEGIN(KERN_INFO, "------------[ cut here ]------------");
3512 EXPECT_BEGIN(KERN_INFO, "refcount_t: underflow; use-after-free.");
3513 EXPECT_BEGIN(KERN_INFO, "---[ end trace <<int>> ]---");
3516 unittest(1, "/testcase-data/refcount-node is zero");
3519 EXPECT_END(KERN_INFO, "---[ end trace <<int>> ]---");
3520 EXPECT_END(KERN_INFO, "refcount_t: underflow; use-after-free.");
3522 EXPECT_END(KERN_INFO, "------------[ cut here ]------------");
3528 EXPECT_NOT_BEGIN(KERN_INFO, "------------[ cut here ]------------");
3530 EXPECT_NOT_BEGIN(KERN_INFO, "refcount_t: underflow; use-after-free.");
3531 EXPECT_NOT_BEGIN(KERN_INFO, "---[ end trace <<int>> ]---");
3533 unittest(1, "/testcase-data/refcount-node is zero, second time");
3536 EXPECT_NOT_END(KERN_INFO, "---[ end trace <<int>> ]---");
3537 EXPECT_NOT_END(KERN_INFO, "refcount_t: underflow; use-after-free.");
3539 EXPECT_NOT_END(KERN_INFO, "------------[ cut here ]------------");
3543 * attempt to of_node_get() node "refcount-node". One example of
3548 * Prevent the stack trace by removing node "refcount-node" from
3553 * Directly manipulate the child list of node /testcase-data to
3554 * remove child refcount-node. This is ignoring all proper methods
3564 prev_sibling = np->child;
3565 next_sibling = prev_sibling->sibling;
3566 if (!strcmp(prev_sibling->full_name, "refcount-node")) {
3567 np->child = next_sibling;
3568 next_sibling = next_sibling->sibling;
3571 if (!strcmp(next_sibling->full_name, "refcount-node"))
3572 prev_sibling->sibling = next_sibling->sibling;
3574 next_sibling = next_sibling->sibling;
3582 unittest(0, "One or more lifecycle tests skipped\n");
3650 OVERLAY_INFO(overlay_base, -9999, 0),
3651 OVERLAY_INFO(overlay, 0, 0),
3652 OVERLAY_INFO(overlay_0, 0, 0),
3653 OVERLAY_INFO(overlay_1, 0, 0),
3654 OVERLAY_INFO(overlay_2, 0, 0),
3655 OVERLAY_INFO(overlay_3, 0, 0),
3656 OVERLAY_INFO(overlay_4, 0, 0),
3657 OVERLAY_INFO(overlay_5, 0, 0),
3658 OVERLAY_INFO(overlay_6, 0, 0),
3659 OVERLAY_INFO(overlay_7, 0, 0),
3660 OVERLAY_INFO(overlay_8, 0, 0),
3661 OVERLAY_INFO(overlay_9, 0, 0),
3662 OVERLAY_INFO(overlay_10, 0, 0),
3663 OVERLAY_INFO(overlay_11, 0, 0),
3664 OVERLAY_INFO(overlay_12, 0, 0),
3665 OVERLAY_INFO(overlay_13, 0, 0),
3666 OVERLAY_INFO(overlay_15, 0, 0),
3667 OVERLAY_INFO(overlay_16, -EBUSY, 0),
3668 OVERLAY_INFO(overlay_17, -EEXIST, 0),
3669 OVERLAY_INFO(overlay_18, 0, 0),
3670 OVERLAY_INFO(overlay_19, 0, 0),
3671 OVERLAY_INFO(overlay_20, 0, 0),
3672 OVERLAY_INFO(overlay_gpio_01, 0, 0),
3673 OVERLAY_INFO(overlay_gpio_02a, 0, 0),
3674 OVERLAY_INFO(overlay_gpio_02b, 0, 0),
3675 OVERLAY_INFO(overlay_gpio_03, 0, 0),
3676 OVERLAY_INFO(overlay_gpio_04a, 0, 0),
3677 OVERLAY_INFO(overlay_gpio_04b, 0, 0),
3678 OVERLAY_INFO(overlay_pci_node, 0, 0),
3679 OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL, -ENODEV),
3680 OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL, -ENODEV),
3681 OVERLAY_INFO(overlay_bad_phandle, -EINVAL, 0),
3682 OVERLAY_INFO(overlay_bad_symbol, -EINVAL, -ENODEV),
3683 OVERLAY_INFO(overlay_bad_unresolved, -EINVAL, 0),
3715 int found = 0;
3718 for (info = overlays; info && info->name; info++) {
3719 if (!strcmp(overlay_name, info->name)) {
3729 info = &overlays[0];
3731 if (info->expected_result != -9999) {
3736 data_size = info->dtbo_end - info->dtbo_begin;
3742 size = fdt_totalsize(info->dtbo_begin);
3754 memcpy(new_fdt, info->dtbo_begin, size);
3766 * /proc/device-tree/ contains the updated structure and values from
3769 * Return 0 on unexpected error.
3775 int found = 0;
3779 for (info = overlays; info && info->name; info++) {
3780 if (!strcmp(overlay_name, info->name)) {
3787 return 0;
3790 size = info->dtbo_end - info->dtbo_begin;
3794 ret = of_overlay_fdt_apply(info->dtbo_begin, size, &info->ovcs_id,
3797 *ovcs_id = info->ovcs_id;
3798 if (ret < 0)
3804 if (ret != info->expected_result) {
3806 info->expected_result, ret, overlay_name);
3807 passed = 0;
3810 if (ret < 0) {
3812 ret2 = of_overlay_remove(&info->ovcs_id);
3813 if (ret2 != info->expected_result_remove) {
3815 info->expected_result_remove, ret2,
3817 passed = 0;
3843 unittest(0, "overlay_base_root not initialized\n");
3865 pprev = &overlay_base_root->child;
3866 for (np = overlay_base_root->child; np; np = np->sibling) {
3868 *pprev = np->sibling;
3871 pprev = &np->sibling;
3878 pprev = &overlay_base_root->child;
3879 for (np = overlay_base_root->child; np; np = np->sibling) {
3882 *pprev = np->sibling;
3885 pprev = &np->sibling;
3892 if (!strcmp(np->full_name, base_child->full_name)) {
3893 unittest(0, "illegal node name in overlay_base %pOFn",
3910 for (np = overlay_base_root->child; np; np = np->sibling)
3911 np->parent = of_root;
3915 for (last_sibling = np = of_root->child; np; np = np->sibling)
3919 last_sibling->sibling = overlay_base_root->child;
3921 of_root->child = overlay_base_root->child;
3932 unittest(0, "__of_prop_dup() of '%s' from overlay_base node __symbols__",
3933 prop->name);
3938 /* "name" auto-generated by unflatten */
3939 if (!strcmp(prop->name, "name"))
3941 unittest(0, "duplicate property '%s' in overlay_base node __symbols__",
3942 prop->name);
3946 unittest(0, "unable to add property '%s' in overlay_base node __symbols__ to sysfs",
3947 prop->name);
3958 /* --- overlay --- */
3961 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/status");
3963 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/status");
3965 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@30/incline-up");
3967 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@40/incline-up");
3969 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/status");
3971 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/color");
3973 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/rate");
3994 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/rate");
3996 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/color");
3998 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/status");
4000 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@40/incline-up");
4002 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@30/incline-up");
4004 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/status");
4006 "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/status");
4010 /* --- overlay_bad_add_dup_node --- */
4013 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
4015 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
4017 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/controller:name");
4019 "OF: Error reverting changeset (-19)");
4025 "OF: Error reverting changeset (-19)");
4027 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/controller:name");
4029 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
4031 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
4033 /* --- overlay_bad_add_dup_prop --- */
4036 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
4038 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
4040 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
4042 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/electric:name");
4044 "OF: Error reverting changeset (-19)");
4050 "OF: Error reverting changeset (-19)");
4052 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/electric:name");
4054 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
4056 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
4058 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
4060 /* --- overlay_bad_phandle --- */
4065 /* --- overlay_bad_symbol --- */
4068 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/hvac-medium-2:name");
4070 "OF: Error reverting changeset (-19)");
4076 "OF: Error reverting changeset (-19)");
4078 "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/hvac-medium-2:name");
4080 /* --- overlay_bad_unresolved --- */
4085 "OF: resolver: overlay phandle fixup failed: -22");
4091 "OF: resolver: overlay phandle fixup failed: -22");
4108 { PCI_DEVICE(PCI_VENDOR_ID_REDHAT, 0x5), }, /* PCI_VENDOR_ID_REDHAT */
4109 { 0, }
4119 dn = pdev->dev.of_node;
4121 dev_err(&pdev->dev, "does not find bus endpoint");
4122 return -EINVAL;
4125 for (info = overlays; info && info->name; info++) {
4126 if (!strcmp(info->name, "overlay_pci_node"))
4129 if (!info || !info->name) {
4130 dev_err(&pdev->dev, "no overlay data for overlay_pci_node");
4131 return -ENODEV;
4134 size = info->dtbo_end - info->dtbo_begin;
4135 ret = of_overlay_fdt_apply(info->dtbo_begin, size, &ovcs_id, dn);
4140 of_platform_default_populate(dn, NULL, &pdev->dev);
4143 return 0;
4150 of_platform_depopulate(&pdev->dev);
4167 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4169 return -ENODEV;
4171 dev = &pdev->dev;
4173 dev = dev->parent;
4176 return -ENODEV;
4179 exp_addr = pci_resource_start(to_pci_dev(dev), 0) + 0x100;
4180 unittest(res->start == exp_addr, "Incorrect translated address %llx, expected %llx\n",
4181 (u64)res->start, exp_addr);
4185 return 0;
4189 { .compatible = "unittest-pci" },
4196 .name = "unittest-pci",
4207 int rc = 0;
4209 pnp = pdev->dev.of_node;
4212 return -ENODEV;
4215 path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0/unittest-pci@100", pnp);
4217 unittest(np, "Failed to get unittest-pci node under PCI node\n");
4219 rc = -ENODEV;
4226 rc = -ENODEV;
4228 path = kasprintf(GFP_KERNEL, "%pOF/pci-ep-bus@0", pnp);
4231 child_dev = device_find_any_child(&pdev->dev);
4262 while ((pdev = pci_get_device(PCI_VENDOR_ID_REDHAT, 0x5, pdev)) != NULL) {
4270 "No test PCI device been found. Please run QEMU with '-device pci-testdev'\n");
4278 while ((pdev = pci_get_device(PCI_VENDOR_ID_REDHAT, 0x5, pdev)) != NULL)
4295 pr_info("start of unittest - you will see error messages\n");
4307 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
4310 return 0;
4346 pr_info("end of unittest - %i passed, %i failed\n",
4349 return 0;