hc
2024-05-10 ee930fffee469d076998274a2ca55e13dc1efb67
kernel/drivers/of/unittest.c
....@@ -5,13 +5,15 @@
55
66 #define pr_fmt(fmt) "### dt-test ### " fmt
77
8
-#include <linux/bootmem.h>
8
+#include <linux/memblock.h>
99 #include <linux/clk.h>
10
+#include <linux/dma-direct.h> /* to test phys_to_dma/dma_to_phys */
1011 #include <linux/err.h>
1112 #include <linux/errno.h>
1213 #include <linux/hashtable.h>
1314 #include <linux/libfdt.h>
1415 #include <linux/of.h>
16
+#include <linux/of_address.h>
1517 #include <linux/of_fdt.h>
1618 #include <linux/of_irq.h>
1719 #include <linux/of_platform.h>
....@@ -23,6 +25,7 @@
2325
2426 #include <linux/i2c.h>
2527 #include <linux/i2c-mux.h>
28
+#include <linux/gpio/driver.h>
2629
2730 #include <linux/bitops.h>
2831
....@@ -45,6 +48,20 @@
4548 failed; \
4649 })
4750
51
+/*
52
+ * Expected message may have a message level other than KERN_INFO.
53
+ * Print the expected message only if the current loglevel will allow
54
+ * the actual message to print.
55
+ *
56
+ * Do not use EXPECT_BEGIN() or EXPECT_END() for messages generated by
57
+ * pr_debug().
58
+ */
59
+#define EXPECT_BEGIN(level, fmt, ...) \
60
+ printk(level pr_fmt("EXPECT \\ : ") fmt, ##__VA_ARGS__)
61
+
62
+#define EXPECT_END(level, fmt, ...) \
63
+ printk(level pr_fmt("EXPECT / : ") fmt, ##__VA_ARGS__)
64
+
4865 static void __init of_unittest_find_node_by_name(void)
4966 {
5067 struct device_node *np;
....@@ -52,7 +69,7 @@
5269
5370 np = of_find_node_by_path("/testcase-data");
5471 name = kasprintf(GFP_KERNEL, "%pOF", np);
55
- unittest(np && !strcmp("/testcase-data", name),
72
+ unittest(np && name && !strcmp("/testcase-data", name),
5673 "find /testcase-data failed\n");
5774 of_node_put(np);
5875 kfree(name);
....@@ -63,14 +80,14 @@
6380
6481 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
6582 name = kasprintf(GFP_KERNEL, "%pOF", np);
66
- unittest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
83
+ unittest(np && name && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
6784 "find /testcase-data/phandle-tests/consumer-a failed\n");
6885 of_node_put(np);
6986 kfree(name);
7087
7188 np = of_find_node_by_path("testcase-alias");
7289 name = kasprintf(GFP_KERNEL, "%pOF", np);
73
- unittest(np && !strcmp("/testcase-data", name),
90
+ unittest(np && name && !strcmp("/testcase-data", name),
7491 "find testcase-alias failed\n");
7592 of_node_put(np);
7693 kfree(name);
....@@ -81,7 +98,7 @@
8198
8299 np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
83100 name = kasprintf(GFP_KERNEL, "%pOF", np);
84
- unittest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
101
+ unittest(np && name && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
85102 "find testcase-alias/phandle-tests/consumer-a failed\n");
86103 of_node_put(np);
87104 kfree(name);
....@@ -299,6 +316,10 @@
299316
300317 of_unittest_printf_one(np, "%pOF", full_name);
301318 of_unittest_printf_one(np, "%pOFf", full_name);
319
+ of_unittest_printf_one(np, "%pOFn", "dev");
320
+ of_unittest_printf_one(np, "%2pOFn", "dev");
321
+ of_unittest_printf_one(np, "%5pOFn", " dev");
322
+ of_unittest_printf_one(np, "%pOFnc", "dev:test-sub-device");
302323 of_unittest_printf_one(np, "%pOFp", phandle_str);
303324 of_unittest_printf_one(np, "%pOFP", "dev@100");
304325 of_unittest_printf_one(np, "ABC %pOFP ABC", "ABC dev@100 ABC");
....@@ -340,7 +361,7 @@
340361 }
341362
342363 nh = kzalloc(sizeof(*nh), GFP_KERNEL);
343
- if (WARN_ON(!nh))
364
+ if (!nh)
344365 return;
345366
346367 nh->np = np;
....@@ -439,29 +460,77 @@
439460
440461 /* Check for missing cells property */
441462 memset(&args, 0, sizeof(args));
463
+
464
+ EXPECT_BEGIN(KERN_INFO,
465
+ "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
466
+
442467 rc = of_parse_phandle_with_args(np, "phandle-list",
443468 "#phandle-cells-missing", 0, &args);
469
+
470
+ EXPECT_END(KERN_INFO,
471
+ "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
472
+
444473 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
474
+
475
+ EXPECT_BEGIN(KERN_INFO,
476
+ "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
477
+
445478 rc = of_count_phandle_with_args(np, "phandle-list",
446479 "#phandle-cells-missing");
480
+
481
+ EXPECT_END(KERN_INFO,
482
+ "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
483
+
447484 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
448485
449486 /* Check for bad phandle in list */
450487 memset(&args, 0, sizeof(args));
488
+
489
+ EXPECT_BEGIN(KERN_INFO,
490
+ "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
491
+
451492 rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
452493 "#phandle-cells", 0, &args);
494
+
495
+ EXPECT_END(KERN_INFO,
496
+ "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
497
+
453498 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
499
+
500
+ EXPECT_BEGIN(KERN_INFO,
501
+ "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
502
+
454503 rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle",
455504 "#phandle-cells");
505
+
506
+ EXPECT_END(KERN_INFO,
507
+ "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
508
+
456509 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
457510
458511 /* Check for incorrectly formed argument list */
459512 memset(&args, 0, sizeof(args));
513
+
514
+ EXPECT_BEGIN(KERN_INFO,
515
+ "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found -1");
516
+
460517 rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
461518 "#phandle-cells", 1, &args);
519
+
520
+ EXPECT_END(KERN_INFO,
521
+ "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found -1");
522
+
462523 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
524
+
525
+ EXPECT_BEGIN(KERN_INFO,
526
+ "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found -1");
527
+
463528 rc = of_count_phandle_with_args(np, "phandle-list-bad-args",
464529 "#phandle-cells");
530
+
531
+ EXPECT_END(KERN_INFO,
532
+ "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found -1");
533
+
465534 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
466535 }
467536
....@@ -572,20 +641,41 @@
572641
573642 /* Check for missing cells,map,mask property */
574643 memset(&args, 0, sizeof(args));
644
+
645
+ EXPECT_BEGIN(KERN_INFO,
646
+ "OF: /testcase-data/phandle-tests/consumer-b: could not get #phandle-missing-cells for /testcase-data/phandle-tests/provider1");
647
+
575648 rc = of_parse_phandle_with_args_map(np, "phandle-list",
576649 "phandle-missing", 0, &args);
650
+ EXPECT_END(KERN_INFO,
651
+ "OF: /testcase-data/phandle-tests/consumer-b: could not get #phandle-missing-cells for /testcase-data/phandle-tests/provider1");
652
+
577653 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
578654
579655 /* Check for bad phandle in list */
580656 memset(&args, 0, sizeof(args));
657
+
658
+ EXPECT_BEGIN(KERN_INFO,
659
+ "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle");
660
+
581661 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle",
582662 "phandle", 0, &args);
663
+ EXPECT_END(KERN_INFO,
664
+ "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle");
665
+
583666 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
584667
585668 /* Check for incorrectly formed argument list */
586669 memset(&args, 0, sizeof(args));
670
+
671
+ EXPECT_BEGIN(KERN_INFO,
672
+ "OF: /testcase-data/phandle-tests/consumer-b: #phandle-cells = 2 found -1");
673
+
587674 rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args",
588675 "phandle", 1, &args);
676
+ EXPECT_END(KERN_INFO,
677
+ "OF: /testcase-data/phandle-tests/consumer-b: #phandle-cells = 2 found -1");
678
+
589679 unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
590680 }
591681
....@@ -777,6 +867,137 @@
777867 of_node_put(n2);
778868 of_node_put(n21);
779869 #endif
870
+}
871
+
872
+static void __init of_unittest_dma_get_max_cpu_address(void)
873
+{
874
+ struct device_node *np;
875
+ phys_addr_t cpu_addr;
876
+
877
+ if (!IS_ENABLED(CONFIG_OF_ADDRESS))
878
+ return;
879
+
880
+ np = of_find_node_by_path("/testcase-data/address-tests");
881
+ if (!np) {
882
+ pr_err("missing testcase data\n");
883
+ return;
884
+ }
885
+
886
+ cpu_addr = of_dma_get_max_cpu_address(np);
887
+ unittest(cpu_addr == 0x4fffffff,
888
+ "of_dma_get_max_cpu_address: wrong CPU addr %pad (expecting %x)\n",
889
+ &cpu_addr, 0x4fffffff);
890
+}
891
+
892
+static void __init of_unittest_dma_ranges_one(const char *path,
893
+ u64 expect_dma_addr, u64 expect_paddr)
894
+{
895
+#ifdef CONFIG_HAS_DMA
896
+ struct device_node *np;
897
+ const struct bus_dma_region *map = NULL;
898
+ int rc;
899
+
900
+ np = of_find_node_by_path(path);
901
+ if (!np) {
902
+ pr_err("missing testcase data\n");
903
+ return;
904
+ }
905
+
906
+ rc = of_dma_get_range(np, &map);
907
+
908
+ unittest(!rc, "of_dma_get_range failed on node %pOF rc=%i\n", np, rc);
909
+
910
+ if (!rc) {
911
+ phys_addr_t paddr;
912
+ dma_addr_t dma_addr;
913
+ struct device *dev_bogus;
914
+
915
+ dev_bogus = kzalloc(sizeof(struct device), GFP_KERNEL);
916
+ if (!dev_bogus) {
917
+ unittest(0, "kzalloc() failed\n");
918
+ kfree(map);
919
+ return;
920
+ }
921
+
922
+ dev_bogus->dma_range_map = map;
923
+ paddr = dma_to_phys(dev_bogus, expect_dma_addr);
924
+ dma_addr = phys_to_dma(dev_bogus, expect_paddr);
925
+
926
+ unittest(paddr == expect_paddr,
927
+ "of_dma_get_range: wrong phys addr %pap (expecting %llx) on node %pOF\n",
928
+ &paddr, expect_paddr, np);
929
+ unittest(dma_addr == expect_dma_addr,
930
+ "of_dma_get_range: wrong DMA addr %pad (expecting %llx) on node %pOF\n",
931
+ &dma_addr, expect_dma_addr, np);
932
+
933
+ kfree(map);
934
+ kfree(dev_bogus);
935
+ }
936
+ of_node_put(np);
937
+#endif
938
+}
939
+
940
+static void __init of_unittest_parse_dma_ranges(void)
941
+{
942
+ of_unittest_dma_ranges_one("/testcase-data/address-tests/device@70000000",
943
+ 0x0, 0x20000000);
944
+ if (IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT))
945
+ of_unittest_dma_ranges_one("/testcase-data/address-tests/bus@80000000/device@1000",
946
+ 0x100000000, 0x20000000);
947
+ of_unittest_dma_ranges_one("/testcase-data/address-tests/pci@90000000",
948
+ 0x80000000, 0x20000000);
949
+}
950
+
951
+static void __init of_unittest_pci_dma_ranges(void)
952
+{
953
+ struct device_node *np;
954
+ struct of_pci_range range;
955
+ struct of_pci_range_parser parser;
956
+ int i = 0;
957
+
958
+ if (!IS_ENABLED(CONFIG_PCI))
959
+ return;
960
+
961
+ np = of_find_node_by_path("/testcase-data/address-tests/pci@90000000");
962
+ if (!np) {
963
+ pr_err("missing testcase data\n");
964
+ return;
965
+ }
966
+
967
+ if (of_pci_dma_range_parser_init(&parser, np)) {
968
+ pr_err("missing dma-ranges property\n");
969
+ return;
970
+ }
971
+
972
+ /*
973
+ * Get the dma-ranges from the device tree
974
+ */
975
+ for_each_of_pci_range(&parser, &range) {
976
+ if (!i) {
977
+ unittest(range.size == 0x10000000,
978
+ "for_each_of_pci_range wrong size on node %pOF size=%llx\n",
979
+ np, range.size);
980
+ unittest(range.cpu_addr == 0x20000000,
981
+ "for_each_of_pci_range wrong CPU addr (%llx) on node %pOF",
982
+ range.cpu_addr, np);
983
+ unittest(range.pci_addr == 0x80000000,
984
+ "for_each_of_pci_range wrong DMA addr (%llx) on node %pOF",
985
+ range.pci_addr, np);
986
+ } else {
987
+ unittest(range.size == 0x10000000,
988
+ "for_each_of_pci_range wrong size on node %pOF size=%llx\n",
989
+ np, range.size);
990
+ unittest(range.cpu_addr == 0x40000000,
991
+ "for_each_of_pci_range wrong CPU addr (%llx) on node %pOF",
992
+ range.cpu_addr, np);
993
+ unittest(range.pci_addr == 0xc0000000,
994
+ "for_each_of_pci_range wrong DMA addr (%llx) on node %pOF",
995
+ range.pci_addr, np);
996
+ }
997
+ i++;
998
+ }
999
+
1000
+ of_node_put(np);
7801001 }
7811002
7821003 static void __init of_unittest_parse_interrupts(void)
....@@ -1031,7 +1252,15 @@
10311252 np = of_find_node_by_path("/testcase-data/testcase-device2");
10321253 pdev = of_find_device_by_node(np);
10331254 unittest(pdev, "device 2 creation failed\n");
1255
+
1256
+ EXPECT_BEGIN(KERN_INFO,
1257
+ "platform testcase-data:testcase-device2: IRQ index 0 not found");
1258
+
10341259 irq = platform_get_irq(pdev, 0);
1260
+
1261
+ EXPECT_END(KERN_INFO,
1262
+ "platform testcase-data:testcase-device2: IRQ index 0 not found");
1263
+
10351264 unittest(irq < 0 && irq != -EPROBE_DEFER,
10361265 "device parsing error failed - %d\n", irq);
10371266 }
....@@ -1044,8 +1273,10 @@
10441273 test_bus = platform_device_register_full(&test_bus_info);
10451274 rc = PTR_ERR_OR_ZERO(test_bus);
10461275 unittest(!rc, "testbus registration failed; rc=%i\n", rc);
1047
- if (rc)
1276
+ if (rc) {
1277
+ of_node_put(np);
10481278 return;
1279
+ }
10491280 test_bus->dev.of_node = np;
10501281
10511282 /*
....@@ -1119,15 +1350,22 @@
11191350 for (prop = np->properties; prop != NULL; prop = save_next) {
11201351 save_next = prop->next;
11211352 ret = of_add_property(dup, prop);
1122
- if (ret)
1353
+ if (ret) {
1354
+ if (ret == -EEXIST && !strcmp(prop->name, "name"))
1355
+ continue;
11231356 pr_err("unittest internal error: unable to add testdata property %pOF/%s",
11241357 np, prop->name);
1358
+ }
11251359 }
11261360 }
11271361
11281362 /**
11291363 * attach_node_and_children - attaches nodes
1130
- * and its children to live tree
1364
+ * and its children to live tree.
1365
+ * CAUTION: misleading function name - if node @np already exists in
1366
+ * the live tree then children of @np are *not* attached to the live
1367
+ * tree. This works for the current test devicetree nodes because such
1368
+ * nodes do not have child nodes.
11311369 *
11321370 * @np: Node to attach to live tree
11331371 */
....@@ -1138,6 +1376,8 @@
11381376 const char *full_name;
11391377
11401378 full_name = kasprintf(GFP_KERNEL, "%pOF", np);
1379
+ if (!full_name)
1380
+ return;
11411381
11421382 if (!strcmp(full_name, "/__local_fixups__") ||
11431383 !strcmp(full_name, "/__fixups__")) {
....@@ -1197,12 +1437,9 @@
11971437
11981438 /* creating copy */
11991439 unittest_data = kmemdup(__dtb_testcases_begin, size, GFP_KERNEL);
1200
-
1201
- if (!unittest_data) {
1202
- pr_warn("%s: Failed to allocate memory for unittest_data; "
1203
- "not running tests\n", __func__);
1440
+ if (!unittest_data)
12041441 return -ENOMEM;
1205
- }
1442
+
12061443 of_fdt_unflatten_tree(unittest_data, NULL, &unittest_data_node);
12071444 if (!unittest_data_node) {
12081445 pr_warn("%s: No tree to attach; not running tests\n", __func__);
....@@ -1232,6 +1469,9 @@
12321469 return 0;
12331470 }
12341471
1472
+ EXPECT_BEGIN(KERN_INFO,
1473
+ "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
1474
+
12351475 /* attach the sub-tree to live tree */
12361476 np = unittest_data_node->child;
12371477 while (np) {
....@@ -1241,6 +1481,9 @@
12411481 attach_node_and_children(np);
12421482 np = next;
12431483 }
1484
+
1485
+ EXPECT_END(KERN_INFO,
1486
+ "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
12441487
12451488 of_overlay_mutex_unlock();
12461489
....@@ -1316,6 +1559,249 @@
13161559 platform_device_put(pdev);
13171560 return pdev != NULL;
13181561 }
1562
+
1563
+#ifdef CONFIG_OF_GPIO
1564
+
1565
+struct unittest_gpio_dev {
1566
+ struct gpio_chip chip;
1567
+};
1568
+
1569
+static int unittest_gpio_chip_request_count;
1570
+static int unittest_gpio_probe_count;
1571
+static int unittest_gpio_probe_pass_count;
1572
+
1573
+static int unittest_gpio_chip_request(struct gpio_chip *chip, unsigned int offset)
1574
+{
1575
+ unittest_gpio_chip_request_count++;
1576
+
1577
+ pr_debug("%s(): %s %d %d\n", __func__, chip->label, offset,
1578
+ unittest_gpio_chip_request_count);
1579
+ return 0;
1580
+}
1581
+
1582
+static int unittest_gpio_probe(struct platform_device *pdev)
1583
+{
1584
+ struct unittest_gpio_dev *devptr;
1585
+ int ret;
1586
+
1587
+ unittest_gpio_probe_count++;
1588
+
1589
+ devptr = kzalloc(sizeof(*devptr), GFP_KERNEL);
1590
+ if (!devptr)
1591
+ return -ENOMEM;
1592
+
1593
+ platform_set_drvdata(pdev, devptr);
1594
+
1595
+ devptr->chip.of_node = pdev->dev.of_node;
1596
+ devptr->chip.label = "of-unittest-gpio";
1597
+ devptr->chip.base = -1; /* dynamic allocation */
1598
+ devptr->chip.ngpio = 5;
1599
+ devptr->chip.request = unittest_gpio_chip_request;
1600
+
1601
+ ret = gpiochip_add_data(&devptr->chip, NULL);
1602
+
1603
+ unittest(!ret,
1604
+ "gpiochip_add_data() for node @%pOF failed, ret = %d\n", devptr->chip.of_node, ret);
1605
+
1606
+ if (!ret)
1607
+ unittest_gpio_probe_pass_count++;
1608
+ return ret;
1609
+}
1610
+
1611
+static int unittest_gpio_remove(struct platform_device *pdev)
1612
+{
1613
+ struct unittest_gpio_dev *gdev = platform_get_drvdata(pdev);
1614
+ struct device *dev = &pdev->dev;
1615
+ struct device_node *np = pdev->dev.of_node;
1616
+
1617
+ dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
1618
+
1619
+ if (!gdev)
1620
+ return -EINVAL;
1621
+
1622
+ if (gdev->chip.base != -1)
1623
+ gpiochip_remove(&gdev->chip);
1624
+
1625
+ platform_set_drvdata(pdev, NULL);
1626
+ kfree(gdev);
1627
+
1628
+ return 0;
1629
+}
1630
+
1631
+static const struct of_device_id unittest_gpio_id[] = {
1632
+ { .compatible = "unittest-gpio", },
1633
+ {}
1634
+};
1635
+
1636
+static struct platform_driver unittest_gpio_driver = {
1637
+ .probe = unittest_gpio_probe,
1638
+ .remove = unittest_gpio_remove,
1639
+ .driver = {
1640
+ .name = "unittest-gpio",
1641
+ .of_match_table = of_match_ptr(unittest_gpio_id),
1642
+ },
1643
+};
1644
+
1645
+static void __init of_unittest_overlay_gpio(void)
1646
+{
1647
+ int chip_request_count;
1648
+ int probe_pass_count;
1649
+ int ret;
1650
+
1651
+ /*
1652
+ * tests: apply overlays before registering driver
1653
+ * Similar to installing a driver as a module, the
1654
+ * driver is registered after applying the overlays.
1655
+ *
1656
+ * The overlays are applied by overlay_data_apply()
1657
+ * instead of of_unittest_apply_overlay() so that they
1658
+ * will not be tracked. Thus they will not be removed
1659
+ * by of_unittest_destroy_tracked_overlays().
1660
+ *
1661
+ * - apply overlay_gpio_01
1662
+ * - apply overlay_gpio_02a
1663
+ * - apply overlay_gpio_02b
1664
+ * - register driver
1665
+ *
1666
+ * register driver will result in
1667
+ * - probe and processing gpio hog for overlay_gpio_01
1668
+ * - probe for overlay_gpio_02a
1669
+ * - processing gpio for overlay_gpio_02b
1670
+ */
1671
+
1672
+ probe_pass_count = unittest_gpio_probe_pass_count;
1673
+ chip_request_count = unittest_gpio_chip_request_count;
1674
+
1675
+ /*
1676
+ * overlay_gpio_01 contains gpio node and child gpio hog node
1677
+ * overlay_gpio_02a contains gpio node
1678
+ * overlay_gpio_02b contains child gpio hog node
1679
+ */
1680
+
1681
+ unittest(overlay_data_apply("overlay_gpio_01", NULL),
1682
+ "Adding overlay 'overlay_gpio_01' failed\n");
1683
+
1684
+ unittest(overlay_data_apply("overlay_gpio_02a", NULL),
1685
+ "Adding overlay 'overlay_gpio_02a' failed\n");
1686
+
1687
+ unittest(overlay_data_apply("overlay_gpio_02b", NULL),
1688
+ "Adding overlay 'overlay_gpio_02b' failed\n");
1689
+
1690
+ /*
1691
+ * messages are the result of the probes, after the
1692
+ * driver is registered
1693
+ */
1694
+
1695
+ EXPECT_BEGIN(KERN_INFO,
1696
+ "gpio-<<int>> (line-B-input): hogged as input\n");
1697
+
1698
+ EXPECT_BEGIN(KERN_INFO,
1699
+ "gpio-<<int>> (line-A-input): hogged as input\n");
1700
+
1701
+ ret = platform_driver_register(&unittest_gpio_driver);
1702
+ if (unittest(ret == 0, "could not register unittest gpio driver\n"))
1703
+ return;
1704
+
1705
+ EXPECT_END(KERN_INFO,
1706
+ "gpio-<<int>> (line-A-input): hogged as input\n");
1707
+ EXPECT_END(KERN_INFO,
1708
+ "gpio-<<int>> (line-B-input): hogged as input\n");
1709
+
1710
+ unittest(probe_pass_count + 2 == unittest_gpio_probe_pass_count,
1711
+ "unittest_gpio_probe() failed or not called\n");
1712
+
1713
+ unittest(chip_request_count + 2 == unittest_gpio_chip_request_count,
1714
+ "unittest_gpio_chip_request() called %d times (expected 1 time)\n",
1715
+ unittest_gpio_chip_request_count - chip_request_count);
1716
+
1717
+ /*
1718
+ * tests: apply overlays after registering driver
1719
+ *
1720
+ * Similar to a driver built-in to the kernel, the
1721
+ * driver is registered before applying the overlays.
1722
+ *
1723
+ * overlay_gpio_03 contains gpio node and child gpio hog node
1724
+ *
1725
+ * - apply overlay_gpio_03
1726
+ *
1727
+ * apply overlay will result in
1728
+ * - probe and processing gpio hog.
1729
+ */
1730
+
1731
+ probe_pass_count = unittest_gpio_probe_pass_count;
1732
+ chip_request_count = unittest_gpio_chip_request_count;
1733
+
1734
+ EXPECT_BEGIN(KERN_INFO,
1735
+ "gpio-<<int>> (line-D-input): hogged as input\n");
1736
+
1737
+ /* overlay_gpio_03 contains gpio node and child gpio hog node */
1738
+
1739
+ unittest(overlay_data_apply("overlay_gpio_03", NULL),
1740
+ "Adding overlay 'overlay_gpio_03' failed\n");
1741
+
1742
+ EXPECT_END(KERN_INFO,
1743
+ "gpio-<<int>> (line-D-input): hogged as input\n");
1744
+
1745
+ unittest(probe_pass_count + 1 == unittest_gpio_probe_pass_count,
1746
+ "unittest_gpio_probe() failed or not called\n");
1747
+
1748
+ unittest(chip_request_count + 1 == unittest_gpio_chip_request_count,
1749
+ "unittest_gpio_chip_request() called %d times (expected 1 time)\n",
1750
+ unittest_gpio_chip_request_count - chip_request_count);
1751
+
1752
+ /*
1753
+ * overlay_gpio_04a contains gpio node
1754
+ *
1755
+ * - apply overlay_gpio_04a
1756
+ *
1757
+ * apply the overlay will result in
1758
+ * - probe for overlay_gpio_04a
1759
+ */
1760
+
1761
+ probe_pass_count = unittest_gpio_probe_pass_count;
1762
+ chip_request_count = unittest_gpio_chip_request_count;
1763
+
1764
+ /* overlay_gpio_04a contains gpio node */
1765
+
1766
+ unittest(overlay_data_apply("overlay_gpio_04a", NULL),
1767
+ "Adding overlay 'overlay_gpio_04a' failed\n");
1768
+
1769
+ unittest(probe_pass_count + 1 == unittest_gpio_probe_pass_count,
1770
+ "unittest_gpio_probe() failed or not called\n");
1771
+
1772
+ /*
1773
+ * overlay_gpio_04b contains child gpio hog node
1774
+ *
1775
+ * - apply overlay_gpio_04b
1776
+ *
1777
+ * apply the overlay will result in
1778
+ * - processing gpio for overlay_gpio_04b
1779
+ */
1780
+
1781
+ EXPECT_BEGIN(KERN_INFO,
1782
+ "gpio-<<int>> (line-C-input): hogged as input\n");
1783
+
1784
+ /* overlay_gpio_04b contains child gpio hog node */
1785
+
1786
+ unittest(overlay_data_apply("overlay_gpio_04b", NULL),
1787
+ "Adding overlay 'overlay_gpio_04b' failed\n");
1788
+
1789
+ EXPECT_END(KERN_INFO,
1790
+ "gpio-<<int>> (line-C-input): hogged as input\n");
1791
+
1792
+ unittest(chip_request_count + 1 == unittest_gpio_chip_request_count,
1793
+ "unittest_gpio_chip_request() called %d times (expected 1 time)\n",
1794
+ unittest_gpio_chip_request_count - chip_request_count);
1795
+}
1796
+
1797
+#else
1798
+
1799
+static void __init of_unittest_overlay_gpio(void)
1800
+{
1801
+ /* skip tests */
1802
+}
1803
+
1804
+#endif
13191805
13201806 #if IS_BUILTIN(CONFIG_I2C)
13211807
....@@ -1418,10 +1904,18 @@
14181904
14191905 static const char *bus_path = "/testcase-data/overlay-node/test-bus";
14201906
1421
-/* it is guaranteed that overlay ids are assigned in sequence */
1907
+/* FIXME: it is NOT guaranteed that overlay ids are assigned in sequence */
1908
+
14221909 #define MAX_UNITTEST_OVERLAYS 256
14231910 static unsigned long overlay_id_bits[BITS_TO_LONGS(MAX_UNITTEST_OVERLAYS)];
14241911 static int overlay_first_id = -1;
1912
+
1913
+static long of_unittest_overlay_tracked(int id)
1914
+{
1915
+ if (WARN_ON(id >= MAX_UNITTEST_OVERLAYS))
1916
+ return 0;
1917
+ return overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id);
1918
+}
14251919
14261920 static void of_unittest_track_overlay(int id)
14271921 {
....@@ -1429,8 +1923,8 @@
14291923 overlay_first_id = id;
14301924 id -= overlay_first_id;
14311925
1432
- /* we shouldn't need that many */
1433
- BUG_ON(id >= MAX_UNITTEST_OVERLAYS);
1926
+ if (WARN_ON(id >= MAX_UNITTEST_OVERLAYS))
1927
+ return;
14341928 overlay_id_bits[BIT_WORD(id)] |= BIT_MASK(id);
14351929 }
14361930
....@@ -1439,7 +1933,8 @@
14391933 if (overlay_first_id < 0)
14401934 return;
14411935 id -= overlay_first_id;
1442
- BUG_ON(id >= MAX_UNITTEST_OVERLAYS);
1936
+ if (WARN_ON(id >= MAX_UNITTEST_OVERLAYS))
1937
+ return;
14431938 overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id);
14441939 }
14451940
....@@ -1455,7 +1950,7 @@
14551950 defers = 0;
14561951 /* remove in reverse order */
14571952 for (id = MAX_UNITTEST_OVERLAYS - 1; id >= 0; id--) {
1458
- if (!(overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id)))
1953
+ if (!of_unittest_overlay_tracked(id))
14591954 continue;
14601955
14611956 ovcs_id = id + overlay_first_id;
....@@ -1472,13 +1967,12 @@
14721967 continue;
14731968 }
14741969
1475
- overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id);
1970
+ of_unittest_untrack_overlay(id);
14761971 }
14771972 } while (defers > 0);
14781973 }
14791974
1480
-static int __init of_unittest_apply_overlay(int overlay_nr, int unittest_nr,
1481
- int *overlay_id)
1975
+static int __init of_unittest_apply_overlay(int overlay_nr, int *overlay_id)
14821976 {
14831977 const char *overlay_name;
14841978
....@@ -1511,7 +2005,7 @@
15112005 }
15122006
15132007 ovcs_id = 0;
1514
- ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id);
2008
+ ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
15152009 if (ret != 0) {
15162010 /* of_unittest_apply_overlay already called unittest() */
15172011 return ret;
....@@ -1534,7 +2028,7 @@
15342028 int unittest_nr, int before, int after,
15352029 enum overlay_type ovtype)
15362030 {
1537
- int ret, ovcs_id;
2031
+ int ret, ovcs_id, save_id;
15382032
15392033 /* unittest device must be in before state */
15402034 if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
....@@ -1547,7 +2041,7 @@
15472041
15482042 /* apply the overlay */
15492043 ovcs_id = 0;
1550
- ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id);
2044
+ ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
15512045 if (ret != 0) {
15522046 /* of_unittest_apply_overlay already called unittest() */
15532047 return ret;
....@@ -1562,6 +2056,7 @@
15622056 return -EINVAL;
15632057 }
15642058
2059
+ save_id = ovcs_id;
15652060 ret = of_overlay_remove(&ovcs_id);
15662061 if (ret != 0) {
15672062 unittest(0, "%s failed to be destroyed @\"%s\"\n",
....@@ -1569,9 +2064,10 @@
15692064 unittest_path(unittest_nr, ovtype));
15702065 return ret;
15712066 }
2067
+ of_unittest_untrack_overlay(save_id);
15722068
15732069 /* unittest device must be again in before state */
1574
- if (of_unittest_device_exists(unittest_nr, PDEV_OVERLAY) != before) {
2070
+ if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
15752071 unittest(0, "%s with device @\"%s\" %s\n",
15762072 overlay_name_from_nr(overlay_nr),
15772073 unittest_path(unittest_nr, ovtype),
....@@ -1585,8 +2081,18 @@
15852081 /* test activation of device */
15862082 static void __init of_unittest_overlay_0(void)
15872083 {
2084
+ int ret;
2085
+
2086
+ EXPECT_BEGIN(KERN_INFO,
2087
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest0/status");
2088
+
15882089 /* device should enable */
1589
- if (of_unittest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY))
2090
+ ret = of_unittest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY);
2091
+
2092
+ EXPECT_END(KERN_INFO,
2093
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest0/status");
2094
+
2095
+ if (ret)
15902096 return;
15912097
15922098 unittest(1, "overlay test %d passed\n", 0);
....@@ -1595,28 +2101,58 @@
15952101 /* test deactivation of device */
15962102 static void __init of_unittest_overlay_1(void)
15972103 {
2104
+ int ret;
2105
+
2106
+ EXPECT_BEGIN(KERN_INFO,
2107
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest1/status");
2108
+
15982109 /* device should disable */
1599
- if (of_unittest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY))
2110
+ ret = of_unittest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY);
2111
+
2112
+ EXPECT_END(KERN_INFO,
2113
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest1/status");
2114
+
2115
+ if (ret)
16002116 return;
16012117
16022118 unittest(1, "overlay test %d passed\n", 1);
2119
+
16032120 }
16042121
16052122 /* test activation of device */
16062123 static void __init of_unittest_overlay_2(void)
16072124 {
1608
- /* device should enable */
1609
- if (of_unittest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY))
1610
- return;
2125
+ int ret;
16112126
2127
+ EXPECT_BEGIN(KERN_INFO,
2128
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest2/status");
2129
+
2130
+ /* device should enable */
2131
+ ret = of_unittest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY);
2132
+
2133
+ EXPECT_END(KERN_INFO,
2134
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest2/status");
2135
+
2136
+ if (ret)
2137
+ return;
16122138 unittest(1, "overlay test %d passed\n", 2);
16132139 }
16142140
16152141 /* test deactivation of device */
16162142 static void __init of_unittest_overlay_3(void)
16172143 {
2144
+ int ret;
2145
+
2146
+ EXPECT_BEGIN(KERN_INFO,
2147
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest3/status");
2148
+
16182149 /* device should disable */
1619
- if (of_unittest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY))
2150
+ ret = of_unittest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY);
2151
+
2152
+ EXPECT_END(KERN_INFO,
2153
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest3/status");
2154
+
2155
+ if (ret)
16202156 return;
16212157
16222158 unittest(1, "overlay test %d passed\n", 3);
....@@ -1635,8 +2171,18 @@
16352171 /* test overlay apply/revert sequence */
16362172 static void __init of_unittest_overlay_5(void)
16372173 {
2174
+ int ret;
2175
+
2176
+ EXPECT_BEGIN(KERN_INFO,
2177
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest5/status");
2178
+
16382179 /* device should disable */
1639
- if (of_unittest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY))
2180
+ ret = of_unittest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY);
2181
+
2182
+ EXPECT_END(KERN_INFO,
2183
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest5/status");
2184
+
2185
+ if (ret)
16402186 return;
16412187
16422188 unittest(1, "overlay test %d passed\n", 5);
....@@ -1649,6 +2195,8 @@
16492195 int overlay_nr = 6, unittest_nr = 6;
16502196 int before = 0, after = 1;
16512197 const char *overlay_name;
2198
+
2199
+ int ret;
16522200
16532201 /* unittest device must be in before state */
16542202 for (i = 0; i < 2; i++) {
....@@ -1664,18 +2212,41 @@
16642212 }
16652213
16662214 /* apply the overlays */
1667
- for (i = 0; i < 2; i++) {
16682215
1669
- overlay_name = overlay_name_from_nr(overlay_nr + i);
2216
+ EXPECT_BEGIN(KERN_INFO,
2217
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest6/status");
16702218
1671
- if (!overlay_data_apply(overlay_name, &ovcs_id)) {
1672
- unittest(0, "could not apply overlay \"%s\"\n",
1673
- overlay_name);
2219
+ overlay_name = overlay_name_from_nr(overlay_nr + 0);
2220
+
2221
+ ret = overlay_data_apply(overlay_name, &ovcs_id);
2222
+
2223
+ if (!ret) {
2224
+ unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
16742225 return;
1675
- }
1676
- ov_id[i] = ovcs_id;
1677
- of_unittest_track_overlay(ov_id[i]);
16782226 }
2227
+ ov_id[0] = ovcs_id;
2228
+ of_unittest_track_overlay(ov_id[0]);
2229
+
2230
+ EXPECT_END(KERN_INFO,
2231
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest6/status");
2232
+
2233
+ EXPECT_BEGIN(KERN_INFO,
2234
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest7/status");
2235
+
2236
+ overlay_name = overlay_name_from_nr(overlay_nr + 1);
2237
+
2238
+ ret = overlay_data_apply(overlay_name, &ovcs_id);
2239
+
2240
+ if (!ret) {
2241
+ unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2242
+ return;
2243
+ }
2244
+ ov_id[1] = ovcs_id;
2245
+ of_unittest_track_overlay(ov_id[1]);
2246
+
2247
+ EXPECT_END(KERN_INFO,
2248
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest7/status");
2249
+
16792250
16802251 for (i = 0; i < 2; i++) {
16812252 /* unittest device must be in after state */
....@@ -1716,6 +2287,7 @@
17162287 }
17172288
17182289 unittest(1, "overlay test %d passed\n", 6);
2290
+
17192291 }
17202292
17212293 /* test overlay application in sequence */
....@@ -1724,26 +2296,65 @@
17242296 int i, ov_id[2], ovcs_id;
17252297 int overlay_nr = 8, unittest_nr = 8;
17262298 const char *overlay_name;
2299
+ int ret;
17272300
17282301 /* we don't care about device state in this test */
17292302
2303
+ EXPECT_BEGIN(KERN_INFO,
2304
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/status");
2305
+
2306
+ overlay_name = overlay_name_from_nr(overlay_nr + 0);
2307
+
2308
+ ret = overlay_data_apply(overlay_name, &ovcs_id);
2309
+ if (!ret)
2310
+ unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2311
+
2312
+ EXPECT_END(KERN_INFO,
2313
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/status");
2314
+
2315
+ if (!ret)
2316
+ return;
2317
+
2318
+ ov_id[0] = ovcs_id;
2319
+ of_unittest_track_overlay(ov_id[0]);
2320
+
2321
+ overlay_name = overlay_name_from_nr(overlay_nr + 1);
2322
+
2323
+ EXPECT_BEGIN(KERN_INFO,
2324
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/property-foo");
2325
+
17302326 /* apply the overlays */
1731
- for (i = 0; i < 2; i++) {
2327
+ ret = overlay_data_apply(overlay_name, &ovcs_id);
17322328
1733
- overlay_name = overlay_name_from_nr(overlay_nr + i);
2329
+ EXPECT_END(KERN_INFO,
2330
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/property-foo");
17342331
1735
- if (!overlay_data_apply(overlay_name, &ovcs_id)) {
1736
- unittest(0, "could not apply overlay \"%s\"\n",
1737
- overlay_name);
1738
- return;
1739
- }
1740
- ov_id[i] = ovcs_id;
1741
- of_unittest_track_overlay(ov_id[i]);
2332
+ if (!ret) {
2333
+ unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
2334
+ return;
17422335 }
2336
+
2337
+ ov_id[1] = ovcs_id;
2338
+ of_unittest_track_overlay(ov_id[1]);
17432339
17442340 /* now try to remove first overlay (it should fail) */
17452341 ovcs_id = ov_id[0];
1746
- if (!of_overlay_remove(&ovcs_id)) {
2342
+
2343
+ EXPECT_BEGIN(KERN_INFO,
2344
+ "OF: overlay: node_overlaps_later_cs: #6 overlaps with #7 @/testcase-data/overlay-node/test-bus/test-unittest8");
2345
+
2346
+ EXPECT_BEGIN(KERN_INFO,
2347
+ "OF: overlay: overlay #6 is not topmost");
2348
+
2349
+ ret = of_overlay_remove(&ovcs_id);
2350
+
2351
+ EXPECT_END(KERN_INFO,
2352
+ "OF: overlay: overlay #6 is not topmost");
2353
+
2354
+ EXPECT_END(KERN_INFO,
2355
+ "OF: overlay: node_overlaps_later_cs: #6 overlaps with #7 @/testcase-data/overlay-node/test-bus/test-unittest8");
2356
+
2357
+ if (!ret) {
17472358 unittest(0, "%s was destroyed @\"%s\"\n",
17482359 overlay_name_from_nr(overlay_nr + 0),
17492360 unittest_path(unittest_nr,
....@@ -1775,6 +2386,7 @@
17752386
17762387 /* device should disable */
17772388 ret = of_unittest_apply_overlay_check(10, 10, 0, 1, PDEV_OVERLAY);
2389
+
17782390 if (unittest(ret == 0,
17792391 "overlay test %d failed; overlay application\n", 10))
17802392 return;
....@@ -1798,6 +2410,7 @@
17982410 /* device should disable */
17992411 ret = of_unittest_apply_revert_overlay_check(11, 11, 0, 1,
18002412 PDEV_OVERLAY);
2413
+
18012414 unittest(ret == 0, "overlay test %d failed; overlay apply\n", 11);
18022415 }
18032416
....@@ -1845,10 +2458,8 @@
18452458 dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
18462459
18472460 std = devm_kzalloc(dev, sizeof(*std), GFP_KERNEL);
1848
- if (!std) {
1849
- dev_err(dev, "Failed to allocate unittest i2c data\n");
2461
+ if (!std)
18502462 return -ENOMEM;
1851
- }
18522463
18532464 /* link them together */
18542465 std->pdev = pdev;
....@@ -1951,7 +2562,7 @@
19512562 {
19522563 int i, nchans;
19532564 struct device *dev = &client->dev;
1954
- struct i2c_adapter *adap = to_i2c_adapter(dev->parent);
2565
+ struct i2c_adapter *adap = client->adapter;
19552566 struct device_node *np = client->dev.of_node, *child;
19562567 struct i2c_mux_core *muxc;
19572568 u32 reg, max_reg;
....@@ -2030,12 +2641,21 @@
20302641 return ret;
20312642
20322643 ret = platform_driver_register(&unittest_i2c_bus_driver);
2644
+
20332645 if (unittest(ret == 0,
20342646 "could not register unittest i2c bus driver\n"))
20352647 return ret;
20362648
20372649 #if IS_BUILTIN(CONFIG_I2C_MUX)
2650
+
2651
+ EXPECT_BEGIN(KERN_INFO,
2652
+ "i2c i2c-1: Added multiplexed i2c bus 2");
2653
+
20382654 ret = i2c_add_driver(&unittest_i2c_mux_driver);
2655
+
2656
+ EXPECT_END(KERN_INFO,
2657
+ "i2c i2c-1: Added multiplexed i2c bus 2");
2658
+
20392659 if (unittest(ret == 0,
20402660 "could not register unittest i2c mux driver\n"))
20412661 return ret;
....@@ -2055,8 +2675,18 @@
20552675
20562676 static void __init of_unittest_overlay_i2c_12(void)
20572677 {
2678
+ int ret;
2679
+
20582680 /* device should enable */
2059
- if (of_unittest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY))
2681
+ EXPECT_BEGIN(KERN_INFO,
2682
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12/status");
2683
+
2684
+ ret = of_unittest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY);
2685
+
2686
+ EXPECT_END(KERN_INFO,
2687
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12/status");
2688
+
2689
+ if (ret)
20602690 return;
20612691
20622692 unittest(1, "overlay test %d passed\n", 12);
....@@ -2065,8 +2695,18 @@
20652695 /* test deactivation of device */
20662696 static void __init of_unittest_overlay_i2c_13(void)
20672697 {
2698
+ int ret;
2699
+
2700
+ EXPECT_BEGIN(KERN_INFO,
2701
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13/status");
2702
+
20682703 /* device should disable */
2069
- if (of_unittest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY))
2704
+ ret = of_unittest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY);
2705
+
2706
+ EXPECT_END(KERN_INFO,
2707
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13/status");
2708
+
2709
+ if (ret)
20702710 return;
20712711
20722712 unittest(1, "overlay test %d passed\n", 13);
....@@ -2079,8 +2719,18 @@
20792719
20802720 static void __init of_unittest_overlay_i2c_15(void)
20812721 {
2722
+ int ret;
2723
+
20822724 /* device should enable */
2083
- if (of_unittest_apply_overlay_check(15, 15, 0, 1, I2C_OVERLAY))
2725
+ EXPECT_BEGIN(KERN_INFO,
2726
+ "i2c i2c-1: Added multiplexed i2c bus 3");
2727
+
2728
+ ret = of_unittest_apply_overlay_check(15, 15, 0, 1, I2C_OVERLAY);
2729
+
2730
+ EXPECT_END(KERN_INFO,
2731
+ "i2c i2c-1: Added multiplexed i2c bus 3");
2732
+
2733
+ if (ret)
20842734 return;
20852735
20862736 unittest(1, "overlay test %d passed\n", 15);
....@@ -2152,6 +2802,8 @@
21522802 of_unittest_overlay_i2c_cleanup();
21532803 #endif
21542804
2805
+ of_unittest_overlay_gpio();
2806
+
21552807 of_unittest_destroy_tracked_overlays();
21562808
21572809 out:
....@@ -2205,10 +2857,18 @@
22052857 OVERLAY_INFO_EXTERN(overlay_12);
22062858 OVERLAY_INFO_EXTERN(overlay_13);
22072859 OVERLAY_INFO_EXTERN(overlay_15);
2860
+OVERLAY_INFO_EXTERN(overlay_gpio_01);
2861
+OVERLAY_INFO_EXTERN(overlay_gpio_02a);
2862
+OVERLAY_INFO_EXTERN(overlay_gpio_02b);
2863
+OVERLAY_INFO_EXTERN(overlay_gpio_03);
2864
+OVERLAY_INFO_EXTERN(overlay_gpio_04a);
2865
+OVERLAY_INFO_EXTERN(overlay_gpio_04b);
2866
+OVERLAY_INFO_EXTERN(overlay_bad_add_dup_node);
2867
+OVERLAY_INFO_EXTERN(overlay_bad_add_dup_prop);
22082868 OVERLAY_INFO_EXTERN(overlay_bad_phandle);
22092869 OVERLAY_INFO_EXTERN(overlay_bad_symbol);
22102870
2211
-/* order of entries is hard-coded into users of overlays[] */
2871
+/* entries found by name */
22122872 static struct overlay_info overlays[] = {
22132873 OVERLAY_INFO(overlay_base, -9999),
22142874 OVERLAY_INFO(overlay, 0),
....@@ -2227,16 +2887,31 @@
22272887 OVERLAY_INFO(overlay_12, 0),
22282888 OVERLAY_INFO(overlay_13, 0),
22292889 OVERLAY_INFO(overlay_15, 0),
2890
+ OVERLAY_INFO(overlay_gpio_01, 0),
2891
+ OVERLAY_INFO(overlay_gpio_02a, 0),
2892
+ OVERLAY_INFO(overlay_gpio_02b, 0),
2893
+ OVERLAY_INFO(overlay_gpio_03, 0),
2894
+ OVERLAY_INFO(overlay_gpio_04a, 0),
2895
+ OVERLAY_INFO(overlay_gpio_04b, 0),
2896
+ OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL),
2897
+ OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL),
22302898 OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
22312899 OVERLAY_INFO(overlay_bad_symbol, -EINVAL),
2232
- {}
2900
+ /* end marker */
2901
+ {.dtb_begin = NULL, .dtb_end = NULL, .expected_result = 0, .name = NULL}
22332902 };
22342903
22352904 static struct device_node *overlay_base_root;
22362905
22372906 static void * __init dt_alloc_memory(u64 size, u64 align)
22382907 {
2239
- return memblock_virt_alloc(size, align);
2908
+ void *ptr = memblock_alloc(size, align);
2909
+
2910
+ if (!ptr)
2911
+ panic("%s: Failed to allocate %llu bytes align=0x%llx\n",
2912
+ __func__, size, align);
2913
+
2914
+ return ptr;
22402915 }
22412916
22422917 /*
....@@ -2259,6 +2934,19 @@
22592934 u32 data_size;
22602935 void *new_fdt;
22612936 u32 size;
2937
+ int found = 0;
2938
+ const char *overlay_name = "overlay_base";
2939
+
2940
+ for (info = overlays; info && info->name; info++) {
2941
+ if (!strcmp(overlay_name, info->name)) {
2942
+ found = 1;
2943
+ break;
2944
+ }
2945
+ }
2946
+ if (!found) {
2947
+ pr_err("no overlay data for %s\n", overlay_name);
2948
+ return;
2949
+ }
22622950
22632951 info = &overlays[0];
22642952
....@@ -2306,11 +2994,10 @@
23062994 {
23072995 struct overlay_info *info;
23082996 int found = 0;
2309
- int k;
23102997 int ret;
23112998 u32 size;
23122999
2313
- for (k = 0, info = overlays; info && info->name; info++, k++) {
3000
+ for (info = overlays; info && info->name; info++) {
23143001 if (!strcmp(overlay_name, info->name)) {
23153002 found = 1;
23163003 break;
....@@ -2357,6 +3044,7 @@
23573044 struct device_node *overlay_base_symbols;
23583045 struct device_node **pprev;
23593046 struct property *prop;
3047
+ int ret;
23603048
23613049 if (!overlay_base_root) {
23623050 unittest(0, "overlay_base_root not initialized\n");
....@@ -2383,7 +3071,7 @@
23833071 */
23843072 pprev = &overlay_base_root->child;
23853073 for (np = overlay_base_root->child; np; np = np->sibling) {
2386
- if (!of_node_cmp(np->name, "__local_fixups__")) {
3074
+ if (of_node_name_eq(np, "__local_fixups__")) {
23873075 *pprev = np->sibling;
23883076 break;
23893077 }
....@@ -2396,7 +3084,7 @@
23963084 /* will have to graft properties from node into live tree */
23973085 pprev = &overlay_base_root->child;
23983086 for (np = overlay_base_root->child; np; np = np->sibling) {
2399
- if (!of_node_cmp(np->name, "__symbols__")) {
3087
+ if (of_node_name_eq(np, "__symbols__")) {
24003088 overlay_base_symbols = np;
24013089 *pprev = np->sibling;
24023090 break;
....@@ -2405,11 +3093,14 @@
24053093 }
24063094 }
24073095
2408
- for (np = overlay_base_root->child; np; np = np->sibling) {
2409
- if (of_get_child_by_name(of_root, np->name)) {
2410
- unittest(0, "illegal node name in overlay_base %s",
2411
- np->name);
2412
- return;
3096
+ for_each_child_of_node(overlay_base_root, np) {
3097
+ struct device_node *base_child;
3098
+ for_each_child_of_node(of_root, base_child) {
3099
+ if (!strcmp(np->full_name, base_child->full_name)) {
3100
+ unittest(0, "illegal node name in overlay_base %pOFn",
3101
+ np);
3102
+ return;
3103
+ }
24133104 }
24143105 }
24153106
....@@ -2471,8 +3162,85 @@
24713162
24723163 /* now do the normal overlay usage test */
24733164
2474
- unittest(overlay_data_apply("overlay", NULL),
2475
- "Adding overlay 'overlay' failed\n");
3165
+ EXPECT_BEGIN(KERN_ERR,
3166
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/status");
3167
+ EXPECT_BEGIN(KERN_ERR,
3168
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/status");
3169
+ EXPECT_BEGIN(KERN_ERR,
3170
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@30/incline-up");
3171
+ EXPECT_BEGIN(KERN_ERR,
3172
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@40/incline-up");
3173
+ EXPECT_BEGIN(KERN_ERR,
3174
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/status");
3175
+ EXPECT_BEGIN(KERN_ERR,
3176
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/color");
3177
+ EXPECT_BEGIN(KERN_ERR,
3178
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/rate");
3179
+ EXPECT_BEGIN(KERN_ERR,
3180
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/hvac_2");
3181
+ EXPECT_BEGIN(KERN_ERR,
3182
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200");
3183
+ EXPECT_BEGIN(KERN_ERR,
3184
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_left");
3185
+ EXPECT_BEGIN(KERN_ERR,
3186
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_right");
3187
+
3188
+ ret = overlay_data_apply("overlay", NULL);
3189
+
3190
+ EXPECT_END(KERN_ERR,
3191
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_right");
3192
+ EXPECT_END(KERN_ERR,
3193
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_left");
3194
+ EXPECT_END(KERN_ERR,
3195
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200");
3196
+ EXPECT_END(KERN_ERR,
3197
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/hvac_2");
3198
+ EXPECT_END(KERN_ERR,
3199
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/rate");
3200
+ EXPECT_END(KERN_ERR,
3201
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/color");
3202
+ EXPECT_END(KERN_ERR,
3203
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/status");
3204
+ EXPECT_END(KERN_ERR,
3205
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@40/incline-up");
3206
+ EXPECT_END(KERN_ERR,
3207
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@30/incline-up");
3208
+ EXPECT_END(KERN_ERR,
3209
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/status");
3210
+ EXPECT_END(KERN_ERR,
3211
+ "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/status");
3212
+
3213
+ unittest(ret, "Adding overlay 'overlay' failed\n");
3214
+
3215
+ EXPECT_BEGIN(KERN_ERR,
3216
+ "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
3217
+ EXPECT_BEGIN(KERN_ERR,
3218
+ "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
3219
+
3220
+ unittest(overlay_data_apply("overlay_bad_add_dup_node", NULL),
3221
+ "Adding overlay 'overlay_bad_add_dup_node' failed\n");
3222
+
3223
+ EXPECT_END(KERN_ERR,
3224
+ "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
3225
+ EXPECT_END(KERN_ERR,
3226
+ "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
3227
+
3228
+ EXPECT_BEGIN(KERN_ERR,
3229
+ "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
3230
+ EXPECT_BEGIN(KERN_ERR,
3231
+ "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
3232
+ EXPECT_BEGIN(KERN_ERR,
3233
+ "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
3234
+
3235
+ unittest(overlay_data_apply("overlay_bad_add_dup_prop", NULL),
3236
+ "Adding overlay 'overlay_bad_add_dup_prop' failed\n");
3237
+
3238
+ EXPECT_END(KERN_ERR,
3239
+ "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
3240
+ EXPECT_END(KERN_ERR,
3241
+ "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
3242
+ EXPECT_END(KERN_ERR,
3243
+ "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
24763244
24773245 unittest(overlay_data_apply("overlay_bad_phandle", NULL),
24783246 "Adding overlay 'overlay_bad_phandle' failed\n");
....@@ -2497,7 +3265,13 @@
24973265 struct device_node *np;
24983266 int res;
24993267
3268
+ pr_info("start of unittest - you will see error messages\n");
3269
+
25003270 /* adding data for unittest */
3271
+
3272
+ if (IS_ENABLED(CONFIG_UML))
3273
+ unittest_unflatten_overlay_base();
3274
+
25013275 res = unittest_data_add();
25023276 if (res)
25033277 return res;
....@@ -2511,7 +3285,6 @@
25113285 }
25123286 of_node_put(np);
25133287
2514
- pr_info("start of unittest - you will see error messages\n");
25153288 of_unittest_check_tree_linkage();
25163289 of_unittest_check_phandles();
25173290 of_unittest_find_node_by_name();
....@@ -2524,6 +3297,9 @@
25243297 of_unittest_changeset();
25253298 of_unittest_parse_interrupts();
25263299 of_unittest_parse_interrupts_extended();
3300
+ of_unittest_dma_get_max_cpu_address();
3301
+ of_unittest_parse_dma_ranges();
3302
+ of_unittest_pci_dma_ranges();
25273303 of_unittest_match_node();
25283304 of_unittest_platform_populate();
25293305 of_unittest_overlay();