Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Self tests for device tree subsystem |
| 4 | */ |
| 5 | |
Grant Likely | cabb7d5 | 2013-02-12 21:19:37 +0000 | [diff] [blame] | 6 | #define pr_fmt(fmt) "### dt-test ### " fmt |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 7 | |
Rob Herring | 0fa1c57 | 2018-01-05 15:32:33 -0600 | [diff] [blame] | 8 | #include <linux/bootmem.h> |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 9 | #include <linux/clk.h> |
| 10 | #include <linux/err.h> |
| 11 | #include <linux/errno.h> |
Grant Likely | 841ec21 | 2014-10-02 13:09:15 +0100 | [diff] [blame] | 12 | #include <linux/hashtable.h> |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 13 | #include <linux/libfdt.h> |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 14 | #include <linux/of.h> |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 15 | #include <linux/of_fdt.h> |
Grant Likely | a9f10ca | 2013-10-11 22:04:23 +0100 | [diff] [blame] | 16 | #include <linux/of_irq.h> |
Rob Herring | 82c0f58 | 2014-04-23 17:57:40 -0500 | [diff] [blame] | 17 | #include <linux/of_platform.h> |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 18 | #include <linux/list.h> |
| 19 | #include <linux/mutex.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/device.h> |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 23 | |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 24 | #include <linux/i2c.h> |
| 25 | #include <linux/i2c-mux.h> |
| 26 | |
Pantelis Antoniou | 492a22a | 2015-04-07 22:23:49 +0300 | [diff] [blame] | 27 | #include <linux/bitops.h> |
| 28 | |
Pantelis Antoniou | 6984339 | 2014-07-04 19:58:47 +0300 | [diff] [blame] | 29 | #include "of_private.h" |
| 30 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 31 | static struct unittest_results { |
Grant Likely | a9f10ca | 2013-10-11 22:04:23 +0100 | [diff] [blame] | 32 | int passed; |
| 33 | int failed; |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 34 | } unittest_results; |
Grant Likely | a9f10ca | 2013-10-11 22:04:23 +0100 | [diff] [blame] | 35 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 36 | #define unittest(result, fmt, ...) ({ \ |
Grant Likely | 851da97 | 2014-11-04 13:14:13 +0000 | [diff] [blame] | 37 | bool failed = !(result); \ |
| 38 | if (failed) { \ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 39 | unittest_results.failed++; \ |
Grant Likely | a9f10ca | 2013-10-11 22:04:23 +0100 | [diff] [blame] | 40 | pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \ |
Grant Likely | cabb7d5 | 2013-02-12 21:19:37 +0000 | [diff] [blame] | 41 | } else { \ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 42 | unittest_results.passed++; \ |
Grant Likely | a9f10ca | 2013-10-11 22:04:23 +0100 | [diff] [blame] | 43 | pr_debug("pass %s():%i\n", __func__, __LINE__); \ |
Grant Likely | cabb7d5 | 2013-02-12 21:19:37 +0000 | [diff] [blame] | 44 | } \ |
Grant Likely | 851da97 | 2014-11-04 13:14:13 +0000 | [diff] [blame] | 45 | failed; \ |
| 46 | }) |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 47 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 48 | static void __init of_unittest_find_node_by_name(void) |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 49 | { |
| 50 | struct device_node *np; |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 51 | const char *options, *name; |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 52 | |
| 53 | np = of_find_node_by_path("/testcase-data"); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 54 | name = kasprintf(GFP_KERNEL, "%pOF", np); |
| 55 | unittest(np && !strcmp("/testcase-data", name), |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 56 | "find /testcase-data failed\n"); |
| 57 | of_node_put(np); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 58 | kfree(name); |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 59 | |
| 60 | /* Test if trailing '/' works */ |
| 61 | np = of_find_node_by_path("/testcase-data/"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 62 | unittest(!np, "trailing '/' on /testcase-data/ should fail\n"); |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 63 | |
| 64 | np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 65 | name = kasprintf(GFP_KERNEL, "%pOF", np); |
| 66 | unittest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", name), |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 67 | "find /testcase-data/phandle-tests/consumer-a failed\n"); |
| 68 | of_node_put(np); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 69 | kfree(name); |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 70 | |
| 71 | np = of_find_node_by_path("testcase-alias"); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 72 | name = kasprintf(GFP_KERNEL, "%pOF", np); |
| 73 | unittest(np && !strcmp("/testcase-data", name), |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 74 | "find testcase-alias failed\n"); |
| 75 | of_node_put(np); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 76 | kfree(name); |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 77 | |
| 78 | /* Test if trailing '/' works on aliases */ |
| 79 | np = of_find_node_by_path("testcase-alias/"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 80 | unittest(!np, "trailing '/' on testcase-alias/ should fail\n"); |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 81 | |
| 82 | np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a"); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 83 | name = kasprintf(GFP_KERNEL, "%pOF", np); |
| 84 | unittest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", name), |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 85 | "find testcase-alias/phandle-tests/consumer-a failed\n"); |
| 86 | of_node_put(np); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 87 | kfree(name); |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 88 | |
| 89 | np = of_find_node_by_path("/testcase-data/missing-path"); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 90 | unittest(!np, "non-existent path returned node %pOF\n", np); |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 91 | of_node_put(np); |
| 92 | |
| 93 | np = of_find_node_by_path("missing-alias"); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 94 | unittest(!np, "non-existent alias returned node %pOF\n", np); |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 95 | of_node_put(np); |
| 96 | |
| 97 | np = of_find_node_by_path("testcase-alias/missing-path"); |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 98 | unittest(!np, "non-existent alias with relative path returned node %pOF\n", np); |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 99 | of_node_put(np); |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 100 | |
| 101 | np = of_find_node_opts_by_path("/testcase-data:testoption", &options); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 102 | unittest(np && !strcmp("testoption", options), |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 103 | "option path test failed\n"); |
| 104 | of_node_put(np); |
| 105 | |
Peter Hurley | 8cbba1a | 2015-03-06 13:59:59 -0500 | [diff] [blame] | 106 | np = of_find_node_opts_by_path("/testcase-data:test/option", &options); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 107 | unittest(np && !strcmp("test/option", options), |
Peter Hurley | 8cbba1a | 2015-03-06 13:59:59 -0500 | [diff] [blame] | 108 | "option path test, subcase #1 failed\n"); |
| 109 | of_node_put(np); |
| 110 | |
Brian Norris | 5ca1b0d | 2015-03-17 12:30:32 -0700 | [diff] [blame] | 111 | np = of_find_node_opts_by_path("/testcase-data/testcase-device1:test/option", &options); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 112 | unittest(np && !strcmp("test/option", options), |
Brian Norris | 5ca1b0d | 2015-03-17 12:30:32 -0700 | [diff] [blame] | 113 | "option path test, subcase #2 failed\n"); |
| 114 | of_node_put(np); |
| 115 | |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 116 | np = of_find_node_opts_by_path("/testcase-data:testoption", NULL); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 117 | unittest(np, "NULL option path test failed\n"); |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 118 | of_node_put(np); |
| 119 | |
| 120 | np = of_find_node_opts_by_path("testcase-alias:testaliasoption", |
| 121 | &options); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 122 | unittest(np && !strcmp("testaliasoption", options), |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 123 | "option alias path test failed\n"); |
| 124 | of_node_put(np); |
| 125 | |
Peter Hurley | 8cbba1a | 2015-03-06 13:59:59 -0500 | [diff] [blame] | 126 | np = of_find_node_opts_by_path("testcase-alias:test/alias/option", |
| 127 | &options); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 128 | unittest(np && !strcmp("test/alias/option", options), |
Peter Hurley | 8cbba1a | 2015-03-06 13:59:59 -0500 | [diff] [blame] | 129 | "option alias path test, subcase #1 failed\n"); |
| 130 | of_node_put(np); |
| 131 | |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 132 | np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 133 | unittest(np, "NULL option alias path test failed\n"); |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 134 | of_node_put(np); |
| 135 | |
| 136 | options = "testoption"; |
| 137 | np = of_find_node_opts_by_path("testcase-alias", &options); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 138 | unittest(np && !options, "option clearing test failed\n"); |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 139 | of_node_put(np); |
| 140 | |
| 141 | options = "testoption"; |
| 142 | np = of_find_node_opts_by_path("/", &options); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 143 | unittest(np && !options, "option clearing root node test failed\n"); |
Leif Lindholm | 75c28c0 | 2014-11-28 11:34:28 +0000 | [diff] [blame] | 144 | of_node_put(np); |
Grant Likely | ae91ff7 | 2014-03-14 13:53:10 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 147 | static void __init of_unittest_dynamic(void) |
Grant Likely | 7e66c5c | 2013-11-15 17:19:09 +0000 | [diff] [blame] | 148 | { |
| 149 | struct device_node *np; |
| 150 | struct property *prop; |
| 151 | |
| 152 | np = of_find_node_by_path("/testcase-data"); |
| 153 | if (!np) { |
| 154 | pr_err("missing testcase data\n"); |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | /* Array of 4 properties for the purpose of testing */ |
| 159 | prop = kzalloc(sizeof(*prop) * 4, GFP_KERNEL); |
| 160 | if (!prop) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 161 | unittest(0, "kzalloc() failed\n"); |
Grant Likely | 7e66c5c | 2013-11-15 17:19:09 +0000 | [diff] [blame] | 162 | return; |
| 163 | } |
| 164 | |
| 165 | /* Add a new property - should pass*/ |
| 166 | prop->name = "new-property"; |
| 167 | prop->value = "new-property-data"; |
| 168 | prop->length = strlen(prop->value); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 169 | unittest(of_add_property(np, prop) == 0, "Adding a new property failed\n"); |
Grant Likely | 7e66c5c | 2013-11-15 17:19:09 +0000 | [diff] [blame] | 170 | |
| 171 | /* Try to add an existing property - should fail */ |
| 172 | prop++; |
| 173 | prop->name = "new-property"; |
| 174 | prop->value = "new-property-data-should-fail"; |
| 175 | prop->length = strlen(prop->value); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 176 | unittest(of_add_property(np, prop) != 0, |
Grant Likely | 7e66c5c | 2013-11-15 17:19:09 +0000 | [diff] [blame] | 177 | "Adding an existing property should have failed\n"); |
| 178 | |
| 179 | /* Try to modify an existing property - should pass */ |
| 180 | prop->value = "modify-property-data-should-pass"; |
| 181 | prop->length = strlen(prop->value); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 182 | unittest(of_update_property(np, prop) == 0, |
Grant Likely | 7e66c5c | 2013-11-15 17:19:09 +0000 | [diff] [blame] | 183 | "Updating an existing property should have passed\n"); |
| 184 | |
| 185 | /* Try to modify non-existent property - should pass*/ |
| 186 | prop++; |
| 187 | prop->name = "modify-property"; |
| 188 | prop->value = "modify-missing-property-data-should-pass"; |
| 189 | prop->length = strlen(prop->value); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 190 | unittest(of_update_property(np, prop) == 0, |
Grant Likely | 7e66c5c | 2013-11-15 17:19:09 +0000 | [diff] [blame] | 191 | "Updating a missing property should have passed\n"); |
| 192 | |
| 193 | /* Remove property - should pass */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 194 | unittest(of_remove_property(np, prop) == 0, |
Grant Likely | 7e66c5c | 2013-11-15 17:19:09 +0000 | [diff] [blame] | 195 | "Removing a property should have passed\n"); |
| 196 | |
| 197 | /* Adding very large property - should pass */ |
| 198 | prop++; |
| 199 | prop->name = "large-property-PAGE_SIZEx8"; |
| 200 | prop->length = PAGE_SIZE * 8; |
| 201 | prop->value = kzalloc(prop->length, GFP_KERNEL); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 202 | unittest(prop->value != NULL, "Unable to allocate large buffer\n"); |
Grant Likely | 7e66c5c | 2013-11-15 17:19:09 +0000 | [diff] [blame] | 203 | if (prop->value) |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 204 | unittest(of_add_property(np, prop) == 0, |
Grant Likely | 7e66c5c | 2013-11-15 17:19:09 +0000 | [diff] [blame] | 205 | "Adding a large property should have passed\n"); |
| 206 | } |
| 207 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 208 | static int __init of_unittest_check_node_linkage(struct device_node *np) |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 209 | { |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 210 | struct device_node *child; |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 211 | int count = 0, rc; |
| 212 | |
| 213 | for_each_child_of_node(np, child) { |
| 214 | if (child->parent != np) { |
| 215 | pr_err("Child node %s links to wrong parent %s\n", |
| 216 | child->name, np->name); |
Julia Lawall | 855ff28 | 2015-10-22 11:02:50 +0200 | [diff] [blame] | 217 | rc = -EINVAL; |
| 218 | goto put_child; |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 221 | rc = of_unittest_check_node_linkage(child); |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 222 | if (rc < 0) |
Julia Lawall | 855ff28 | 2015-10-22 11:02:50 +0200 | [diff] [blame] | 223 | goto put_child; |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 224 | count += rc; |
| 225 | } |
| 226 | |
| 227 | return count + 1; |
Julia Lawall | 855ff28 | 2015-10-22 11:02:50 +0200 | [diff] [blame] | 228 | put_child: |
| 229 | of_node_put(child); |
| 230 | return rc; |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 231 | } |
| 232 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 233 | static void __init of_unittest_check_tree_linkage(void) |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 234 | { |
| 235 | struct device_node *np; |
| 236 | int allnode_count = 0, child_count; |
| 237 | |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 238 | if (!of_root) |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 239 | return; |
| 240 | |
| 241 | for_each_of_allnodes(np) |
| 242 | allnode_count++; |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 243 | child_count = of_unittest_check_node_linkage(of_root); |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 244 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 245 | unittest(child_count > 0, "Device node data structure is corrupted\n"); |
Grant Likely | a2166ca | 2015-03-29 08:59:58 +0100 | [diff] [blame] | 246 | unittest(child_count == allnode_count, |
Frank Rowand | a6bb121 | 2015-03-13 23:59:01 -0700 | [diff] [blame] | 247 | "allnodes list size (%i) doesn't match sibling lists size (%i)\n", |
| 248 | allnode_count, child_count); |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 249 | pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count, child_count); |
| 250 | } |
| 251 | |
Pantelis Antoniou | ce4fecf | 2015-01-21 19:06:14 +0200 | [diff] [blame] | 252 | static void __init of_unittest_printf_one(struct device_node *np, const char *fmt, |
| 253 | const char *expected) |
| 254 | { |
| 255 | unsigned char buf[strlen(expected)+10]; |
| 256 | int size, i; |
| 257 | |
| 258 | /* Baseline; check conversion with a large size limit */ |
| 259 | memset(buf, 0xff, sizeof(buf)); |
| 260 | size = snprintf(buf, sizeof(buf) - 2, fmt, np); |
| 261 | |
| 262 | /* use strcmp() instead of strncmp() here to be absolutely sure strings match */ |
| 263 | unittest((strcmp(buf, expected) == 0) && (buf[size+1] == 0xff), |
| 264 | "sprintf failed; fmt='%s' expected='%s' rslt='%s'\n", |
| 265 | fmt, expected, buf); |
| 266 | |
| 267 | /* Make sure length limits work */ |
| 268 | size++; |
| 269 | for (i = 0; i < 2; i++, size--) { |
| 270 | /* Clear the buffer, and make sure it works correctly still */ |
| 271 | memset(buf, 0xff, sizeof(buf)); |
| 272 | snprintf(buf, size+1, fmt, np); |
| 273 | unittest(strncmp(buf, expected, size) == 0 && (buf[size+1] == 0xff), |
| 274 | "snprintf failed; size=%i fmt='%s' expected='%s' rslt='%s'\n", |
| 275 | size, fmt, expected, buf); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | static void __init of_unittest_printf(void) |
| 280 | { |
| 281 | struct device_node *np; |
| 282 | const char *full_name = "/testcase-data/platform-tests/test-device@1/dev@100"; |
| 283 | char phandle_str[16] = ""; |
| 284 | |
| 285 | np = of_find_node_by_path(full_name); |
| 286 | if (!np) { |
| 287 | unittest(np, "testcase data missing\n"); |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | num_to_str(phandle_str, sizeof(phandle_str), np->phandle); |
| 292 | |
| 293 | of_unittest_printf_one(np, "%pOF", full_name); |
| 294 | of_unittest_printf_one(np, "%pOFf", full_name); |
| 295 | of_unittest_printf_one(np, "%pOFp", phandle_str); |
| 296 | of_unittest_printf_one(np, "%pOFP", "dev@100"); |
| 297 | of_unittest_printf_one(np, "ABC %pOFP ABC", "ABC dev@100 ABC"); |
| 298 | of_unittest_printf_one(np, "%10pOFP", " dev@100"); |
| 299 | of_unittest_printf_one(np, "%-10pOFP", "dev@100 "); |
| 300 | of_unittest_printf_one(of_root, "%pOFP", "/"); |
| 301 | of_unittest_printf_one(np, "%pOFF", "----"); |
| 302 | of_unittest_printf_one(np, "%pOFPF", "dev@100:----"); |
| 303 | of_unittest_printf_one(np, "%pOFPFPc", "dev@100:----:dev@100:test-sub-device"); |
| 304 | of_unittest_printf_one(np, "%pOFc", "test-sub-device"); |
| 305 | of_unittest_printf_one(np, "%pOFC", |
| 306 | "\"test-sub-device\",\"test-compat2\",\"test-compat3\""); |
| 307 | } |
| 308 | |
Grant Likely | 841ec21 | 2014-10-02 13:09:15 +0100 | [diff] [blame] | 309 | struct node_hash { |
| 310 | struct hlist_node node; |
| 311 | struct device_node *np; |
| 312 | }; |
| 313 | |
Grant Likely | 2118f4b | 2014-10-07 11:30:31 +0100 | [diff] [blame] | 314 | static DEFINE_HASHTABLE(phandle_ht, 8); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 315 | static void __init of_unittest_check_phandles(void) |
Grant Likely | 841ec21 | 2014-10-02 13:09:15 +0100 | [diff] [blame] | 316 | { |
| 317 | struct device_node *np; |
| 318 | struct node_hash *nh; |
| 319 | struct hlist_node *tmp; |
| 320 | int i, dup_count = 0, phandle_count = 0; |
Grant Likely | 841ec21 | 2014-10-02 13:09:15 +0100 | [diff] [blame] | 321 | |
Grant Likely | 841ec21 | 2014-10-02 13:09:15 +0100 | [diff] [blame] | 322 | for_each_of_allnodes(np) { |
| 323 | if (!np->phandle) |
| 324 | continue; |
| 325 | |
Grant Likely | 2118f4b | 2014-10-07 11:30:31 +0100 | [diff] [blame] | 326 | hash_for_each_possible(phandle_ht, nh, node, np->phandle) { |
Grant Likely | 841ec21 | 2014-10-02 13:09:15 +0100 | [diff] [blame] | 327 | if (nh->np->phandle == np->phandle) { |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 328 | pr_info("Duplicate phandle! %i used by %pOF and %pOF\n", |
| 329 | np->phandle, nh->np, np); |
Grant Likely | 841ec21 | 2014-10-02 13:09:15 +0100 | [diff] [blame] | 330 | dup_count++; |
| 331 | break; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | nh = kzalloc(sizeof(*nh), GFP_KERNEL); |
| 336 | if (WARN_ON(!nh)) |
| 337 | return; |
| 338 | |
| 339 | nh->np = np; |
Grant Likely | 2118f4b | 2014-10-07 11:30:31 +0100 | [diff] [blame] | 340 | hash_add(phandle_ht, &nh->node, np->phandle); |
Grant Likely | 841ec21 | 2014-10-02 13:09:15 +0100 | [diff] [blame] | 341 | phandle_count++; |
| 342 | } |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 343 | unittest(dup_count == 0, "Found %i duplicates in %i phandles\n", |
Grant Likely | 841ec21 | 2014-10-02 13:09:15 +0100 | [diff] [blame] | 344 | dup_count, phandle_count); |
| 345 | |
| 346 | /* Clean up */ |
Grant Likely | 2118f4b | 2014-10-07 11:30:31 +0100 | [diff] [blame] | 347 | hash_for_each_safe(phandle_ht, i, tmp, nh, node) { |
Grant Likely | 841ec21 | 2014-10-02 13:09:15 +0100 | [diff] [blame] | 348 | hash_del(&nh->node); |
| 349 | kfree(nh); |
| 350 | } |
| 351 | } |
| 352 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 353 | static void __init of_unittest_parse_phandle_with_args(void) |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 354 | { |
| 355 | struct device_node *np; |
| 356 | struct of_phandle_args args; |
Grant Likely | cabb7d5 | 2013-02-12 21:19:37 +0000 | [diff] [blame] | 357 | int i, rc; |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 358 | |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 359 | np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); |
| 360 | if (!np) { |
| 361 | pr_err("missing testcase data\n"); |
| 362 | return; |
| 363 | } |
| 364 | |
Grant Likely | bd69f73 | 2013-02-10 22:57:21 +0000 | [diff] [blame] | 365 | rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 366 | unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc); |
Grant Likely | bd69f73 | 2013-02-10 22:57:21 +0000 | [diff] [blame] | 367 | |
Grant Likely | f7f951c | 2013-02-12 17:41:22 +0000 | [diff] [blame] | 368 | for (i = 0; i < 8; i++) { |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 369 | bool passed = true; |
Frank Rowand | 3db316d | 2015-03-14 00:02:31 -0700 | [diff] [blame] | 370 | |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 371 | rc = of_parse_phandle_with_args(np, "phandle-list", |
| 372 | "#phandle-cells", i, &args); |
| 373 | |
| 374 | /* Test the values from tests-phandle.dtsi */ |
| 375 | switch (i) { |
| 376 | case 0: |
| 377 | passed &= !rc; |
| 378 | passed &= (args.args_count == 1); |
| 379 | passed &= (args.args[0] == (i + 1)); |
| 380 | break; |
| 381 | case 1: |
| 382 | passed &= !rc; |
| 383 | passed &= (args.args_count == 2); |
| 384 | passed &= (args.args[0] == (i + 1)); |
| 385 | passed &= (args.args[1] == 0); |
| 386 | break; |
| 387 | case 2: |
| 388 | passed &= (rc == -ENOENT); |
| 389 | break; |
| 390 | case 3: |
| 391 | passed &= !rc; |
| 392 | passed &= (args.args_count == 3); |
| 393 | passed &= (args.args[0] == (i + 1)); |
| 394 | passed &= (args.args[1] == 4); |
| 395 | passed &= (args.args[2] == 3); |
| 396 | break; |
| 397 | case 4: |
| 398 | passed &= !rc; |
| 399 | passed &= (args.args_count == 2); |
| 400 | passed &= (args.args[0] == (i + 1)); |
| 401 | passed &= (args.args[1] == 100); |
| 402 | break; |
| 403 | case 5: |
| 404 | passed &= !rc; |
| 405 | passed &= (args.args_count == 0); |
| 406 | break; |
| 407 | case 6: |
| 408 | passed &= !rc; |
| 409 | passed &= (args.args_count == 1); |
| 410 | passed &= (args.args[0] == (i + 1)); |
| 411 | break; |
| 412 | case 7: |
Grant Likely | cabb7d5 | 2013-02-12 21:19:37 +0000 | [diff] [blame] | 413 | passed &= (rc == -ENOENT); |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 414 | break; |
| 415 | default: |
| 416 | passed = false; |
| 417 | } |
| 418 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 419 | unittest(passed, "index %i - data error on node %pOF rc=%i\n", |
| 420 | i, args.np, rc); |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* Check for missing list property */ |
| 424 | rc = of_parse_phandle_with_args(np, "phandle-list-missing", |
| 425 | "#phandle-cells", 0, &args); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 426 | unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); |
Grant Likely | bd69f73 | 2013-02-10 22:57:21 +0000 | [diff] [blame] | 427 | rc = of_count_phandle_with_args(np, "phandle-list-missing", |
| 428 | "#phandle-cells"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 429 | unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 430 | |
| 431 | /* Check for missing cells property */ |
| 432 | rc = of_parse_phandle_with_args(np, "phandle-list", |
| 433 | "#phandle-cells-missing", 0, &args); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 434 | unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
Grant Likely | bd69f73 | 2013-02-10 22:57:21 +0000 | [diff] [blame] | 435 | rc = of_count_phandle_with_args(np, "phandle-list", |
| 436 | "#phandle-cells-missing"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 437 | unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 438 | |
| 439 | /* Check for bad phandle in list */ |
| 440 | rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle", |
| 441 | "#phandle-cells", 0, &args); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 442 | unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
Grant Likely | bd69f73 | 2013-02-10 22:57:21 +0000 | [diff] [blame] | 443 | rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle", |
| 444 | "#phandle-cells"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 445 | unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 446 | |
| 447 | /* Check for incorrectly formed argument list */ |
| 448 | rc = of_parse_phandle_with_args(np, "phandle-list-bad-args", |
| 449 | "#phandle-cells", 1, &args); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 450 | unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
Grant Likely | bd69f73 | 2013-02-10 22:57:21 +0000 | [diff] [blame] | 451 | rc = of_count_phandle_with_args(np, "phandle-list-bad-args", |
| 452 | "#phandle-cells"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 453 | unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Stephen Boyd | 357aa4b | 2018-01-30 18:36:17 -0800 | [diff] [blame^] | 456 | static void __init of_unittest_parse_phandle_with_args_map(void) |
| 457 | { |
| 458 | struct device_node *np, *p0, *p1, *p2, *p3; |
| 459 | struct of_phandle_args args; |
| 460 | int i, rc; |
| 461 | |
| 462 | np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-b"); |
| 463 | if (!np) { |
| 464 | pr_err("missing testcase data\n"); |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | p0 = of_find_node_by_path("/testcase-data/phandle-tests/provider0"); |
| 469 | if (!p0) { |
| 470 | pr_err("missing testcase data\n"); |
| 471 | return; |
| 472 | } |
| 473 | |
| 474 | p1 = of_find_node_by_path("/testcase-data/phandle-tests/provider1"); |
| 475 | if (!p1) { |
| 476 | pr_err("missing testcase data\n"); |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | p2 = of_find_node_by_path("/testcase-data/phandle-tests/provider2"); |
| 481 | if (!p2) { |
| 482 | pr_err("missing testcase data\n"); |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | p3 = of_find_node_by_path("/testcase-data/phandle-tests/provider3"); |
| 487 | if (!p3) { |
| 488 | pr_err("missing testcase data\n"); |
| 489 | return; |
| 490 | } |
| 491 | |
| 492 | rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells"); |
| 493 | unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc); |
| 494 | |
| 495 | for (i = 0; i < 8; i++) { |
| 496 | bool passed = true; |
| 497 | |
| 498 | rc = of_parse_phandle_with_args_map(np, "phandle-list", |
| 499 | "phandle", i, &args); |
| 500 | |
| 501 | /* Test the values from tests-phandle.dtsi */ |
| 502 | switch (i) { |
| 503 | case 0: |
| 504 | passed &= !rc; |
| 505 | passed &= (args.np == p1); |
| 506 | passed &= (args.args_count == 1); |
| 507 | passed &= (args.args[0] == 1); |
| 508 | break; |
| 509 | case 1: |
| 510 | passed &= !rc; |
| 511 | passed &= (args.np == p3); |
| 512 | passed &= (args.args_count == 3); |
| 513 | passed &= (args.args[0] == 2); |
| 514 | passed &= (args.args[1] == 5); |
| 515 | passed &= (args.args[2] == 3); |
| 516 | break; |
| 517 | case 2: |
| 518 | passed &= (rc == -ENOENT); |
| 519 | break; |
| 520 | case 3: |
| 521 | passed &= !rc; |
| 522 | passed &= (args.np == p0); |
| 523 | passed &= (args.args_count == 0); |
| 524 | break; |
| 525 | case 4: |
| 526 | passed &= !rc; |
| 527 | passed &= (args.np == p1); |
| 528 | passed &= (args.args_count == 1); |
| 529 | passed &= (args.args[0] == 3); |
| 530 | break; |
| 531 | case 5: |
| 532 | passed &= !rc; |
| 533 | passed &= (args.np == p0); |
| 534 | passed &= (args.args_count == 0); |
| 535 | break; |
| 536 | case 6: |
| 537 | passed &= !rc; |
| 538 | passed &= (args.np == p2); |
| 539 | passed &= (args.args_count == 2); |
| 540 | passed &= (args.args[0] == 15); |
| 541 | passed &= (args.args[1] == 0x20); |
| 542 | break; |
| 543 | case 7: |
| 544 | passed &= (rc == -ENOENT); |
| 545 | break; |
| 546 | default: |
| 547 | passed = false; |
| 548 | } |
| 549 | |
| 550 | unittest(passed, "index %i - data error on node %s rc=%i\n", |
| 551 | i, args.np->full_name, rc); |
| 552 | } |
| 553 | |
| 554 | /* Check for missing list property */ |
| 555 | rc = of_parse_phandle_with_args_map(np, "phandle-list-missing", |
| 556 | "phandle", 0, &args); |
| 557 | unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); |
| 558 | |
| 559 | /* Check for missing cells,map,mask property */ |
| 560 | rc = of_parse_phandle_with_args_map(np, "phandle-list", |
| 561 | "phandle-missing", 0, &args); |
| 562 | unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
| 563 | |
| 564 | /* Check for bad phandle in list */ |
| 565 | rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle", |
| 566 | "phandle", 0, &args); |
| 567 | unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
| 568 | |
| 569 | /* Check for incorrectly formed argument list */ |
| 570 | rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args", |
| 571 | "phandle", 1, &args); |
| 572 | unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
| 573 | } |
| 574 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 575 | static void __init of_unittest_property_string(void) |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 576 | { |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 577 | const char *strings[4]; |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 578 | struct device_node *np; |
| 579 | int rc; |
| 580 | |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 581 | np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); |
| 582 | if (!np) { |
| 583 | pr_err("No testcase data in device tree\n"); |
| 584 | return; |
| 585 | } |
| 586 | |
| 587 | rc = of_property_match_string(np, "phandle-list-names", "first"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 588 | unittest(rc == 0, "first expected:0 got:%i\n", rc); |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 589 | rc = of_property_match_string(np, "phandle-list-names", "second"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 590 | unittest(rc == 1, "second expected:1 got:%i\n", rc); |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 591 | rc = of_property_match_string(np, "phandle-list-names", "third"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 592 | unittest(rc == 2, "third expected:2 got:%i\n", rc); |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 593 | rc = of_property_match_string(np, "phandle-list-names", "fourth"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 594 | unittest(rc == -ENODATA, "unmatched string; rc=%i\n", rc); |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 595 | rc = of_property_match_string(np, "missing-property", "blah"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 596 | unittest(rc == -EINVAL, "missing property; rc=%i\n", rc); |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 597 | rc = of_property_match_string(np, "empty-property", "blah"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 598 | unittest(rc == -ENODATA, "empty property; rc=%i\n", rc); |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 599 | rc = of_property_match_string(np, "unterminated-string", "blah"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 600 | unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 601 | |
| 602 | /* of_property_count_strings() tests */ |
| 603 | rc = of_property_count_strings(np, "string-property"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 604 | unittest(rc == 1, "Incorrect string count; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 605 | rc = of_property_count_strings(np, "phandle-list-names"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 606 | unittest(rc == 3, "Incorrect string count; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 607 | rc = of_property_count_strings(np, "unterminated-string"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 608 | unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 609 | rc = of_property_count_strings(np, "unterminated-string-list"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 610 | unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 611 | |
| 612 | /* of_property_read_string_index() tests */ |
| 613 | rc = of_property_read_string_index(np, "string-property", 0, strings); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 614 | unittest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 615 | strings[0] = NULL; |
| 616 | rc = of_property_read_string_index(np, "string-property", 1, strings); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 617 | unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 618 | rc = of_property_read_string_index(np, "phandle-list-names", 0, strings); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 619 | unittest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 620 | rc = of_property_read_string_index(np, "phandle-list-names", 1, strings); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 621 | unittest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 622 | rc = of_property_read_string_index(np, "phandle-list-names", 2, strings); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 623 | unittest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 624 | strings[0] = NULL; |
| 625 | rc = of_property_read_string_index(np, "phandle-list-names", 3, strings); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 626 | unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 627 | strings[0] = NULL; |
| 628 | rc = of_property_read_string_index(np, "unterminated-string", 0, strings); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 629 | unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 630 | rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 631 | unittest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 632 | strings[0] = NULL; |
| 633 | rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 634 | unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 635 | strings[1] = NULL; |
| 636 | |
| 637 | /* of_property_read_string_array() tests */ |
| 638 | rc = of_property_read_string_array(np, "string-property", strings, 4); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 639 | unittest(rc == 1, "Incorrect string count; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 640 | rc = of_property_read_string_array(np, "phandle-list-names", strings, 4); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 641 | unittest(rc == 3, "Incorrect string count; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 642 | rc = of_property_read_string_array(np, "unterminated-string", strings, 4); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 643 | unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 644 | /* -- An incorrectly formed string should cause a failure */ |
| 645 | rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 646 | unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 647 | /* -- parsing the correctly formed strings should still work: */ |
| 648 | strings[2] = NULL; |
| 649 | rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 650 | unittest(rc == 2 && strings[2] == NULL, "of_property_read_string_array() failure; rc=%i\n", rc); |
Grant Likely | a87fa1d | 2014-11-03 15:15:35 +0000 | [diff] [blame] | 651 | strings[1] = NULL; |
| 652 | rc = of_property_read_string_array(np, "phandle-list-names", strings, 1); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 653 | unittest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]); |
Grant Likely | 7aff0fe | 2011-12-12 09:25:58 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Pantelis Antoniou | 6984339 | 2014-07-04 19:58:47 +0300 | [diff] [blame] | 656 | #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \ |
| 657 | (p1)->value && (p2)->value && \ |
| 658 | !memcmp((p1)->value, (p2)->value, (p1)->length) && \ |
| 659 | !strcmp((p1)->name, (p2)->name)) |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 660 | static void __init of_unittest_property_copy(void) |
Pantelis Antoniou | 6984339 | 2014-07-04 19:58:47 +0300 | [diff] [blame] | 661 | { |
| 662 | #ifdef CONFIG_OF_DYNAMIC |
| 663 | struct property p1 = { .name = "p1", .length = 0, .value = "" }; |
| 664 | struct property p2 = { .name = "p2", .length = 5, .value = "abcd" }; |
| 665 | struct property *new; |
| 666 | |
| 667 | new = __of_prop_dup(&p1, GFP_KERNEL); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 668 | unittest(new && propcmp(&p1, new), "empty property didn't copy correctly\n"); |
Pantelis Antoniou | 6984339 | 2014-07-04 19:58:47 +0300 | [diff] [blame] | 669 | kfree(new->value); |
| 670 | kfree(new->name); |
| 671 | kfree(new); |
| 672 | |
| 673 | new = __of_prop_dup(&p2, GFP_KERNEL); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 674 | unittest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n"); |
Pantelis Antoniou | 6984339 | 2014-07-04 19:58:47 +0300 | [diff] [blame] | 675 | kfree(new->value); |
| 676 | kfree(new->name); |
| 677 | kfree(new); |
| 678 | #endif |
| 679 | } |
| 680 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 681 | static void __init of_unittest_changeset(void) |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 682 | { |
| 683 | #ifdef CONFIG_OF_DYNAMIC |
| 684 | struct property *ppadd, padd = { .name = "prop-add", .length = 0, .value = "" }; |
| 685 | struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" }; |
| 686 | struct property *ppremove; |
Grant Likely | e517958 | 2014-11-17 22:31:32 +0000 | [diff] [blame] | 687 | struct device_node *n1, *n2, *n21, *nremove, *parent, *np; |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 688 | struct of_changeset chgset; |
| 689 | |
Grant Likely | e517958 | 2014-11-17 22:31:32 +0000 | [diff] [blame] | 690 | n1 = __of_node_dup(NULL, "/testcase-data/changeset/n1"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 691 | unittest(n1, "testcase setup failure\n"); |
Grant Likely | e517958 | 2014-11-17 22:31:32 +0000 | [diff] [blame] | 692 | n2 = __of_node_dup(NULL, "/testcase-data/changeset/n2"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 693 | unittest(n2, "testcase setup failure\n"); |
Grant Likely | e517958 | 2014-11-17 22:31:32 +0000 | [diff] [blame] | 694 | n21 = __of_node_dup(NULL, "%s/%s", "/testcase-data/changeset/n2", "n21"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 695 | unittest(n21, "testcase setup failure %p\n", n21); |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 696 | nremove = of_find_node_by_path("/testcase-data/changeset/node-remove"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 697 | unittest(nremove, "testcase setup failure\n"); |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 698 | ppadd = __of_prop_dup(&padd, GFP_KERNEL); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 699 | unittest(ppadd, "testcase setup failure\n"); |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 700 | ppupdate = __of_prop_dup(&pupdate, GFP_KERNEL); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 701 | unittest(ppupdate, "testcase setup failure\n"); |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 702 | parent = nremove->parent; |
| 703 | n1->parent = parent; |
| 704 | n2->parent = parent; |
| 705 | n21->parent = n2; |
| 706 | n2->child = n21; |
| 707 | ppremove = of_find_property(parent, "prop-remove", NULL); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 708 | unittest(ppremove, "failed to find removal prop"); |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 709 | |
| 710 | of_changeset_init(&chgset); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 711 | unittest(!of_changeset_attach_node(&chgset, n1), "fail attach n1\n"); |
| 712 | unittest(!of_changeset_attach_node(&chgset, n2), "fail attach n2\n"); |
| 713 | unittest(!of_changeset_detach_node(&chgset, nremove), "fail remove node\n"); |
| 714 | unittest(!of_changeset_attach_node(&chgset, n21), "fail attach n21\n"); |
| 715 | unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop\n"); |
| 716 | unittest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n"); |
| 717 | unittest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n"); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 718 | unittest(!of_changeset_apply(&chgset), "apply failed\n"); |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 719 | |
Grant Likely | e517958 | 2014-11-17 22:31:32 +0000 | [diff] [blame] | 720 | /* Make sure node names are constructed correctly */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 721 | unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")), |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 722 | "'%pOF' not added\n", n21); |
Markus Elfring | c46ca3c | 2014-12-02 13:54:00 +0100 | [diff] [blame] | 723 | of_node_put(np); |
Grant Likely | e517958 | 2014-11-17 22:31:32 +0000 | [diff] [blame] | 724 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 725 | unittest(!of_changeset_revert(&chgset), "revert failed\n"); |
Pantelis Antoniou | 201c910 | 2014-07-04 19:58:49 +0300 | [diff] [blame] | 726 | |
| 727 | of_changeset_destroy(&chgset); |
| 728 | #endif |
| 729 | } |
| 730 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 731 | static void __init of_unittest_parse_interrupts(void) |
Grant Likely | a9f10ca | 2013-10-11 22:04:23 +0100 | [diff] [blame] | 732 | { |
| 733 | struct device_node *np; |
| 734 | struct of_phandle_args args; |
| 735 | int i, rc; |
| 736 | |
| 737 | np = of_find_node_by_path("/testcase-data/interrupts/interrupts0"); |
| 738 | if (!np) { |
| 739 | pr_err("missing testcase data\n"); |
| 740 | return; |
| 741 | } |
| 742 | |
| 743 | for (i = 0; i < 4; i++) { |
| 744 | bool passed = true; |
Frank Rowand | 3db316d | 2015-03-14 00:02:31 -0700 | [diff] [blame] | 745 | |
Grant Likely | a9f10ca | 2013-10-11 22:04:23 +0100 | [diff] [blame] | 746 | args.args_count = 0; |
| 747 | rc = of_irq_parse_one(np, i, &args); |
| 748 | |
| 749 | passed &= !rc; |
| 750 | passed &= (args.args_count == 1); |
| 751 | passed &= (args.args[0] == (i + 1)); |
| 752 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 753 | unittest(passed, "index %i - data error on node %pOF rc=%i\n", |
| 754 | i, args.np, rc); |
Grant Likely | a9f10ca | 2013-10-11 22:04:23 +0100 | [diff] [blame] | 755 | } |
| 756 | of_node_put(np); |
| 757 | |
| 758 | np = of_find_node_by_path("/testcase-data/interrupts/interrupts1"); |
| 759 | if (!np) { |
| 760 | pr_err("missing testcase data\n"); |
| 761 | return; |
| 762 | } |
| 763 | |
| 764 | for (i = 0; i < 4; i++) { |
| 765 | bool passed = true; |
Frank Rowand | 3db316d | 2015-03-14 00:02:31 -0700 | [diff] [blame] | 766 | |
Grant Likely | a9f10ca | 2013-10-11 22:04:23 +0100 | [diff] [blame] | 767 | args.args_count = 0; |
| 768 | rc = of_irq_parse_one(np, i, &args); |
| 769 | |
| 770 | /* Test the values from tests-phandle.dtsi */ |
| 771 | switch (i) { |
| 772 | case 0: |
| 773 | passed &= !rc; |
| 774 | passed &= (args.args_count == 1); |
| 775 | passed &= (args.args[0] == 9); |
| 776 | break; |
| 777 | case 1: |
| 778 | passed &= !rc; |
| 779 | passed &= (args.args_count == 3); |
| 780 | passed &= (args.args[0] == 10); |
| 781 | passed &= (args.args[1] == 11); |
| 782 | passed &= (args.args[2] == 12); |
| 783 | break; |
| 784 | case 2: |
| 785 | passed &= !rc; |
| 786 | passed &= (args.args_count == 2); |
| 787 | passed &= (args.args[0] == 13); |
| 788 | passed &= (args.args[1] == 14); |
| 789 | break; |
| 790 | case 3: |
| 791 | passed &= !rc; |
| 792 | passed &= (args.args_count == 2); |
| 793 | passed &= (args.args[0] == 15); |
| 794 | passed &= (args.args[1] == 16); |
| 795 | break; |
| 796 | default: |
| 797 | passed = false; |
| 798 | } |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 799 | unittest(passed, "index %i - data error on node %pOF rc=%i\n", |
| 800 | i, args.np, rc); |
Grant Likely | a9f10ca | 2013-10-11 22:04:23 +0100 | [diff] [blame] | 801 | } |
| 802 | of_node_put(np); |
| 803 | } |
| 804 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 805 | static void __init of_unittest_parse_interrupts_extended(void) |
Grant Likely | 79d9701 | 2013-09-19 16:47:37 -0500 | [diff] [blame] | 806 | { |
| 807 | struct device_node *np; |
| 808 | struct of_phandle_args args; |
| 809 | int i, rc; |
| 810 | |
| 811 | np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0"); |
| 812 | if (!np) { |
| 813 | pr_err("missing testcase data\n"); |
| 814 | return; |
| 815 | } |
| 816 | |
| 817 | for (i = 0; i < 7; i++) { |
| 818 | bool passed = true; |
Frank Rowand | 3db316d | 2015-03-14 00:02:31 -0700 | [diff] [blame] | 819 | |
Grant Likely | 79d9701 | 2013-09-19 16:47:37 -0500 | [diff] [blame] | 820 | rc = of_irq_parse_one(np, i, &args); |
| 821 | |
| 822 | /* Test the values from tests-phandle.dtsi */ |
| 823 | switch (i) { |
| 824 | case 0: |
| 825 | passed &= !rc; |
| 826 | passed &= (args.args_count == 1); |
| 827 | passed &= (args.args[0] == 1); |
| 828 | break; |
| 829 | case 1: |
| 830 | passed &= !rc; |
| 831 | passed &= (args.args_count == 3); |
| 832 | passed &= (args.args[0] == 2); |
| 833 | passed &= (args.args[1] == 3); |
| 834 | passed &= (args.args[2] == 4); |
| 835 | break; |
| 836 | case 2: |
| 837 | passed &= !rc; |
| 838 | passed &= (args.args_count == 2); |
| 839 | passed &= (args.args[0] == 5); |
| 840 | passed &= (args.args[1] == 6); |
| 841 | break; |
| 842 | case 3: |
| 843 | passed &= !rc; |
| 844 | passed &= (args.args_count == 1); |
| 845 | passed &= (args.args[0] == 9); |
| 846 | break; |
| 847 | case 4: |
| 848 | passed &= !rc; |
| 849 | passed &= (args.args_count == 3); |
| 850 | passed &= (args.args[0] == 10); |
| 851 | passed &= (args.args[1] == 11); |
| 852 | passed &= (args.args[2] == 12); |
| 853 | break; |
| 854 | case 5: |
| 855 | passed &= !rc; |
| 856 | passed &= (args.args_count == 2); |
| 857 | passed &= (args.args[0] == 13); |
| 858 | passed &= (args.args[1] == 14); |
| 859 | break; |
| 860 | case 6: |
| 861 | passed &= !rc; |
| 862 | passed &= (args.args_count == 1); |
| 863 | passed &= (args.args[0] == 15); |
| 864 | break; |
| 865 | default: |
| 866 | passed = false; |
| 867 | } |
| 868 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 869 | unittest(passed, "index %i - data error on node %pOF rc=%i\n", |
| 870 | i, args.np, rc); |
Grant Likely | 79d9701 | 2013-09-19 16:47:37 -0500 | [diff] [blame] | 871 | } |
| 872 | of_node_put(np); |
| 873 | } |
| 874 | |
Frank Rowand | afaed7a | 2015-03-14 00:00:36 -0700 | [diff] [blame] | 875 | static const struct of_device_id match_node_table[] = { |
Grant Likely | 1f42e5d | 2014-02-18 21:38:55 +0000 | [diff] [blame] | 876 | { .data = "A", .name = "name0", }, /* Name alone is lowest priority */ |
| 877 | { .data = "B", .type = "type1", }, /* followed by type alone */ |
| 878 | |
| 879 | { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */ |
| 880 | { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */ |
| 881 | { .data = "Cc", .name = "name2", .type = "type2", }, |
| 882 | |
| 883 | { .data = "E", .compatible = "compat3" }, |
| 884 | { .data = "G", .compatible = "compat2", }, |
| 885 | { .data = "H", .compatible = "compat2", .name = "name5", }, |
| 886 | { .data = "I", .compatible = "compat2", .type = "type1", }, |
| 887 | { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", }, |
| 888 | { .data = "K", .compatible = "compat2", .name = "name9", }, |
| 889 | {} |
| 890 | }; |
| 891 | |
| 892 | static struct { |
| 893 | const char *path; |
| 894 | const char *data; |
| 895 | } match_node_tests[] = { |
| 896 | { .path = "/testcase-data/match-node/name0", .data = "A", }, |
| 897 | { .path = "/testcase-data/match-node/name1", .data = "B", }, |
| 898 | { .path = "/testcase-data/match-node/a/name2", .data = "Ca", }, |
| 899 | { .path = "/testcase-data/match-node/b/name2", .data = "Cb", }, |
| 900 | { .path = "/testcase-data/match-node/c/name2", .data = "Cc", }, |
| 901 | { .path = "/testcase-data/match-node/name3", .data = "E", }, |
| 902 | { .path = "/testcase-data/match-node/name4", .data = "G", }, |
| 903 | { .path = "/testcase-data/match-node/name5", .data = "H", }, |
| 904 | { .path = "/testcase-data/match-node/name6", .data = "G", }, |
| 905 | { .path = "/testcase-data/match-node/name7", .data = "I", }, |
| 906 | { .path = "/testcase-data/match-node/name8", .data = "J", }, |
| 907 | { .path = "/testcase-data/match-node/name9", .data = "K", }, |
| 908 | }; |
| 909 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 910 | static void __init of_unittest_match_node(void) |
Grant Likely | 1f42e5d | 2014-02-18 21:38:55 +0000 | [diff] [blame] | 911 | { |
| 912 | struct device_node *np; |
| 913 | const struct of_device_id *match; |
| 914 | int i; |
| 915 | |
| 916 | for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) { |
| 917 | np = of_find_node_by_path(match_node_tests[i].path); |
| 918 | if (!np) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 919 | unittest(0, "missing testcase node %s\n", |
Grant Likely | 1f42e5d | 2014-02-18 21:38:55 +0000 | [diff] [blame] | 920 | match_node_tests[i].path); |
| 921 | continue; |
| 922 | } |
| 923 | |
| 924 | match = of_match_node(match_node_table, np); |
| 925 | if (!match) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 926 | unittest(0, "%s didn't match anything\n", |
Grant Likely | 1f42e5d | 2014-02-18 21:38:55 +0000 | [diff] [blame] | 927 | match_node_tests[i].path); |
| 928 | continue; |
| 929 | } |
| 930 | |
| 931 | if (strcmp(match->data, match_node_tests[i].data) != 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 932 | unittest(0, "%s got wrong match. expected %s, got %s\n", |
Grant Likely | 1f42e5d | 2014-02-18 21:38:55 +0000 | [diff] [blame] | 933 | match_node_tests[i].path, match_node_tests[i].data, |
| 934 | (const char *)match->data); |
| 935 | continue; |
| 936 | } |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 937 | unittest(1, "passed"); |
Grant Likely | 1f42e5d | 2014-02-18 21:38:55 +0000 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | |
Grant Likely | d2329fb | 2016-01-04 13:13:21 +0100 | [diff] [blame] | 941 | static struct resource test_bus_res = { |
| 942 | .start = 0xfffffff8, |
| 943 | .end = 0xfffffff9, |
| 944 | .flags = IORESOURCE_MEM, |
| 945 | }; |
Grant Likely | 37791b6 | 2015-03-27 20:30:04 -0700 | [diff] [blame] | 946 | static const struct platform_device_info test_bus_info = { |
| 947 | .name = "unittest-bus", |
Grant Likely | 851da97 | 2014-11-04 13:14:13 +0000 | [diff] [blame] | 948 | }; |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 949 | static void __init of_unittest_platform_populate(void) |
Rob Herring | 82c0f58 | 2014-04-23 17:57:40 -0500 | [diff] [blame] | 950 | { |
Grant Likely | 851da97 | 2014-11-04 13:14:13 +0000 | [diff] [blame] | 951 | int irq, rc; |
| 952 | struct device_node *np, *child, *grandchild; |
Grant Likely | 37791b6 | 2015-03-27 20:30:04 -0700 | [diff] [blame] | 953 | struct platform_device *pdev, *test_bus; |
Frank Rowand | afaed7a | 2015-03-14 00:00:36 -0700 | [diff] [blame] | 954 | const struct of_device_id match[] = { |
Rob Herring | fb2caa5 | 2014-05-13 10:07:54 -0500 | [diff] [blame] | 955 | { .compatible = "test-device", }, |
| 956 | {} |
| 957 | }; |
Rob Herring | 82c0f58 | 2014-04-23 17:57:40 -0500 | [diff] [blame] | 958 | |
| 959 | np = of_find_node_by_path("/testcase-data"); |
Kefeng Wang | 146dedb | 2016-06-01 14:53:10 +0800 | [diff] [blame] | 960 | of_platform_default_populate(np, NULL, NULL); |
Rob Herring | 82c0f58 | 2014-04-23 17:57:40 -0500 | [diff] [blame] | 961 | |
| 962 | /* Test that a missing irq domain returns -EPROBE_DEFER */ |
| 963 | np = of_find_node_by_path("/testcase-data/testcase-device1"); |
| 964 | pdev = of_find_device_by_node(np); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 965 | unittest(pdev, "device 1 creation failed\n"); |
Rob Herring | 7d1cdc8 | 2014-05-13 10:07:29 -0500 | [diff] [blame] | 966 | |
Rob Herring | 82c0f58 | 2014-04-23 17:57:40 -0500 | [diff] [blame] | 967 | irq = platform_get_irq(pdev, 0); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 968 | unittest(irq == -EPROBE_DEFER, "device deferred probe failed - %d\n", irq); |
Rob Herring | 82c0f58 | 2014-04-23 17:57:40 -0500 | [diff] [blame] | 969 | |
| 970 | /* Test that a parsing failure does not return -EPROBE_DEFER */ |
| 971 | np = of_find_node_by_path("/testcase-data/testcase-device2"); |
| 972 | pdev = of_find_device_by_node(np); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 973 | unittest(pdev, "device 2 creation failed\n"); |
Rob Herring | 82c0f58 | 2014-04-23 17:57:40 -0500 | [diff] [blame] | 974 | irq = platform_get_irq(pdev, 0); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 975 | unittest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq); |
Rob Herring | 82c0f58 | 2014-04-23 17:57:40 -0500 | [diff] [blame] | 976 | |
Frank Rowand | 716e1d4 | 2015-03-13 23:57:40 -0700 | [diff] [blame] | 977 | np = of_find_node_by_path("/testcase-data/platform-tests"); |
Grant Likely | a2166ca | 2015-03-29 08:59:58 +0100 | [diff] [blame] | 978 | unittest(np, "No testcase data in device tree\n"); |
Frank Rowand | 716e1d4 | 2015-03-13 23:57:40 -0700 | [diff] [blame] | 979 | if (!np) |
Rob Herring | fb2caa5 | 2014-05-13 10:07:54 -0500 | [diff] [blame] | 980 | return; |
Grant Likely | 851da97 | 2014-11-04 13:14:13 +0000 | [diff] [blame] | 981 | |
Grant Likely | 37791b6 | 2015-03-27 20:30:04 -0700 | [diff] [blame] | 982 | test_bus = platform_device_register_full(&test_bus_info); |
| 983 | rc = PTR_ERR_OR_ZERO(test_bus); |
Grant Likely | a2166ca | 2015-03-29 08:59:58 +0100 | [diff] [blame] | 984 | unittest(!rc, "testbus registration failed; rc=%i\n", rc); |
Frank Rowand | 716e1d4 | 2015-03-13 23:57:40 -0700 | [diff] [blame] | 985 | if (rc) |
Grant Likely | 851da97 | 2014-11-04 13:14:13 +0000 | [diff] [blame] | 986 | return; |
Grant Likely | 37791b6 | 2015-03-27 20:30:04 -0700 | [diff] [blame] | 987 | test_bus->dev.of_node = np; |
Rob Herring | fb2caa5 | 2014-05-13 10:07:54 -0500 | [diff] [blame] | 988 | |
Grant Likely | d2329fb | 2016-01-04 13:13:21 +0100 | [diff] [blame] | 989 | /* |
| 990 | * Add a dummy resource to the test bus node after it is |
| 991 | * registered to catch problems with un-inserted resources. The |
| 992 | * DT code doesn't insert the resources, and it has caused the |
| 993 | * kernel to oops in the past. This makes sure the same bug |
| 994 | * doesn't crop up again. |
| 995 | */ |
| 996 | platform_device_add_resources(test_bus, &test_bus_res, 1); |
| 997 | |
Grant Likely | 37791b6 | 2015-03-27 20:30:04 -0700 | [diff] [blame] | 998 | of_platform_populate(np, match, NULL, &test_bus->dev); |
Rob Herring | fb2caa5 | 2014-05-13 10:07:54 -0500 | [diff] [blame] | 999 | for_each_child_of_node(np, child) { |
Rob Herring | fb2caa5 | 2014-05-13 10:07:54 -0500 | [diff] [blame] | 1000 | for_each_child_of_node(child, grandchild) |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1001 | unittest(of_find_device_by_node(grandchild), |
Rob Herring | fb2caa5 | 2014-05-13 10:07:54 -0500 | [diff] [blame] | 1002 | "Could not create device for node '%s'\n", |
| 1003 | grandchild->name); |
| 1004 | } |
Grant Likely | 851da97 | 2014-11-04 13:14:13 +0000 | [diff] [blame] | 1005 | |
Grant Likely | 37791b6 | 2015-03-27 20:30:04 -0700 | [diff] [blame] | 1006 | of_platform_depopulate(&test_bus->dev); |
Grant Likely | 851da97 | 2014-11-04 13:14:13 +0000 | [diff] [blame] | 1007 | for_each_child_of_node(np, child) { |
| 1008 | for_each_child_of_node(child, grandchild) |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1009 | unittest(!of_find_device_by_node(grandchild), |
Grant Likely | 851da97 | 2014-11-04 13:14:13 +0000 | [diff] [blame] | 1010 | "device didn't get destroyed '%s'\n", |
| 1011 | grandchild->name); |
| 1012 | } |
| 1013 | |
Grant Likely | 37791b6 | 2015-03-27 20:30:04 -0700 | [diff] [blame] | 1014 | platform_device_unregister(test_bus); |
Grant Likely | 851da97 | 2014-11-04 13:14:13 +0000 | [diff] [blame] | 1015 | of_node_put(np); |
Rob Herring | 82c0f58 | 2014-04-23 17:57:40 -0500 | [diff] [blame] | 1016 | } |
| 1017 | |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1018 | /** |
| 1019 | * update_node_properties - adds the properties |
| 1020 | * of np into dup node (present in live tree) and |
| 1021 | * updates parent of children of np to dup. |
| 1022 | * |
| 1023 | * @np: node already present in live tree |
| 1024 | * @dup: node present in live tree to be updated |
| 1025 | */ |
| 1026 | static void update_node_properties(struct device_node *np, |
| 1027 | struct device_node *dup) |
| 1028 | { |
| 1029 | struct property *prop; |
| 1030 | struct device_node *child; |
| 1031 | |
| 1032 | for_each_property_of_node(np, prop) |
| 1033 | of_add_property(dup, prop); |
| 1034 | |
| 1035 | for_each_child_of_node(np, child) |
| 1036 | child->parent = dup; |
| 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * attach_node_and_children - attaches nodes |
| 1041 | * and its children to live tree |
| 1042 | * |
| 1043 | * @np: Node to attach to live tree |
| 1044 | */ |
| 1045 | static int attach_node_and_children(struct device_node *np) |
| 1046 | { |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 1047 | struct device_node *next, *dup, *child; |
Gaurav Minocha | 3ce04b4 | 2015-01-10 23:19:51 -0800 | [diff] [blame] | 1048 | unsigned long flags; |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 1049 | const char *full_name; |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1050 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 1051 | full_name = kasprintf(GFP_KERNEL, "%pOF", np); |
| 1052 | dup = of_find_node_by_path(full_name); |
| 1053 | kfree(full_name); |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 1054 | if (dup) { |
| 1055 | update_node_properties(np, dup); |
| 1056 | return 0; |
| 1057 | } |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1058 | |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 1059 | child = np->child; |
| 1060 | np->child = NULL; |
Gaurav Minocha | 3ce04b4 | 2015-01-10 23:19:51 -0800 | [diff] [blame] | 1061 | |
| 1062 | mutex_lock(&of_mutex); |
| 1063 | raw_spin_lock_irqsave(&devtree_lock, flags); |
| 1064 | np->sibling = np->parent->child; |
| 1065 | np->parent->child = np; |
| 1066 | of_node_clear_flag(np, OF_DETACHED); |
| 1067 | raw_spin_unlock_irqrestore(&devtree_lock, flags); |
| 1068 | |
| 1069 | __of_attach_node_sysfs(np); |
| 1070 | mutex_unlock(&of_mutex); |
| 1071 | |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 1072 | while (child) { |
| 1073 | next = child->sibling; |
| 1074 | attach_node_and_children(child); |
| 1075 | child = next; |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
| 1081 | /** |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1082 | * unittest_data_add - Reads, copies data from |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1083 | * linked tree and attaches it to the live tree |
| 1084 | */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1085 | static int __init unittest_data_add(void) |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1086 | { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1087 | void *unittest_data; |
| 1088 | struct device_node *unittest_data_node, *np; |
Frank Rowand | c854711 | 2015-03-14 00:04:24 -0700 | [diff] [blame] | 1089 | /* |
| 1090 | * __dtb_testcases_begin[] and __dtb_testcases_end[] are magically |
| 1091 | * created by cmd_dt_S_dtb in scripts/Makefile.lib |
| 1092 | */ |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1093 | extern uint8_t __dtb_testcases_begin[]; |
| 1094 | extern uint8_t __dtb_testcases_end[]; |
| 1095 | const int size = __dtb_testcases_end - __dtb_testcases_begin; |
Grant Likely | 2eb46da | 2014-10-02 14:36:46 +0100 | [diff] [blame] | 1096 | int rc; |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1097 | |
Gaurav Minocha | b951f9d | 2014-07-26 12:48:50 -0700 | [diff] [blame] | 1098 | if (!size) { |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1099 | pr_warn("%s: No testcase data to attach; not running tests\n", |
| 1100 | __func__); |
| 1101 | return -ENODATA; |
| 1102 | } |
| 1103 | |
| 1104 | /* creating copy */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1105 | unittest_data = kmemdup(__dtb_testcases_begin, size, GFP_KERNEL); |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1106 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1107 | if (!unittest_data) { |
| 1108 | pr_warn("%s: Failed to allocate memory for unittest_data; " |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1109 | "not running tests\n", __func__); |
| 1110 | return -ENOMEM; |
| 1111 | } |
Gavin Shan | c426323 | 2016-05-03 23:22:50 +1000 | [diff] [blame] | 1112 | of_fdt_unflatten_tree(unittest_data, NULL, &unittest_data_node); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1113 | if (!unittest_data_node) { |
Gaurav Minocha | b951f9d | 2014-07-26 12:48:50 -0700 | [diff] [blame] | 1114 | pr_warn("%s: No tree to attach; not running tests\n", __func__); |
| 1115 | return -ENODATA; |
| 1116 | } |
Frank Rowand | f948d6d | 2017-10-17 16:36:29 -0700 | [diff] [blame] | 1117 | |
| 1118 | /* |
| 1119 | * This lock normally encloses of_overlay_apply() as well as |
| 1120 | * of_resolve_phandles(). |
| 1121 | */ |
| 1122 | of_overlay_mutex_lock(); |
| 1123 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1124 | rc = of_resolve_phandles(unittest_data_node); |
Grant Likely | 2eb46da | 2014-10-02 14:36:46 +0100 | [diff] [blame] | 1125 | if (rc) { |
| 1126 | pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc); |
Frank Rowand | f948d6d | 2017-10-17 16:36:29 -0700 | [diff] [blame] | 1127 | of_overlay_mutex_unlock(); |
Grant Likely | 2eb46da | 2014-10-02 14:36:46 +0100 | [diff] [blame] | 1128 | return -EINVAL; |
| 1129 | } |
Gaurav Minocha | b951f9d | 2014-07-26 12:48:50 -0700 | [diff] [blame] | 1130 | |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 1131 | if (!of_root) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1132 | of_root = unittest_data_node; |
Gaurav Minocha | b951f9d | 2014-07-26 12:48:50 -0700 | [diff] [blame] | 1133 | for_each_of_allnodes(np) |
| 1134 | __of_attach_node_sysfs(np); |
| 1135 | of_aliases = of_find_node_by_path("/aliases"); |
| 1136 | of_chosen = of_find_node_by_path("/chosen"); |
Frank Rowand | f948d6d | 2017-10-17 16:36:29 -0700 | [diff] [blame] | 1137 | of_overlay_mutex_unlock(); |
Gaurav Minocha | b951f9d | 2014-07-26 12:48:50 -0700 | [diff] [blame] | 1138 | return 0; |
| 1139 | } |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1140 | |
| 1141 | /* attach the sub-tree to live tree */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1142 | np = unittest_data_node->child; |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 1143 | while (np) { |
| 1144 | struct device_node *next = np->sibling; |
Frank Rowand | 3db316d | 2015-03-14 00:02:31 -0700 | [diff] [blame] | 1145 | |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 1146 | np->parent = of_root; |
| 1147 | attach_node_and_children(np); |
| 1148 | np = next; |
| 1149 | } |
Frank Rowand | f948d6d | 2017-10-17 16:36:29 -0700 | [diff] [blame] | 1150 | |
| 1151 | of_overlay_mutex_unlock(); |
| 1152 | |
Grant Likely | 5063e25 | 2014-10-03 16:28:27 +0100 | [diff] [blame] | 1153 | return 0; |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1156 | #ifdef CONFIG_OF_OVERLAY |
| 1157 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1158 | static int unittest_probe(struct platform_device *pdev) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1159 | { |
| 1160 | struct device *dev = &pdev->dev; |
| 1161 | struct device_node *np = dev->of_node; |
| 1162 | |
| 1163 | if (np == NULL) { |
| 1164 | dev_err(dev, "No OF data for device\n"); |
| 1165 | return -EINVAL; |
| 1166 | |
| 1167 | } |
| 1168 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 1169 | dev_dbg(dev, "%s for node @%pOF\n", __func__, np); |
Pantelis Antoniou | 6b1271d | 2014-12-19 14:34:34 +0200 | [diff] [blame] | 1170 | |
| 1171 | of_platform_populate(np, NULL, NULL, &pdev->dev); |
| 1172 | |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1173 | return 0; |
| 1174 | } |
| 1175 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1176 | static int unittest_remove(struct platform_device *pdev) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1177 | { |
| 1178 | struct device *dev = &pdev->dev; |
| 1179 | struct device_node *np = dev->of_node; |
| 1180 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 1181 | dev_dbg(dev, "%s for node @%pOF\n", __func__, np); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
| 1184 | |
Grant Likely | a2166ca | 2015-03-29 08:59:58 +0100 | [diff] [blame] | 1185 | static const struct of_device_id unittest_match[] = { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1186 | { .compatible = "unittest", }, |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1187 | {}, |
| 1188 | }; |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1189 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1190 | static struct platform_driver unittest_driver = { |
| 1191 | .probe = unittest_probe, |
| 1192 | .remove = unittest_remove, |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1193 | .driver = { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1194 | .name = "unittest", |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1195 | .of_match_table = of_match_ptr(unittest_match), |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1196 | }, |
| 1197 | }; |
| 1198 | |
| 1199 | /* get the platform device instantiated at the path */ |
| 1200 | static struct platform_device *of_path_to_platform_device(const char *path) |
| 1201 | { |
| 1202 | struct device_node *np; |
| 1203 | struct platform_device *pdev; |
| 1204 | |
| 1205 | np = of_find_node_by_path(path); |
| 1206 | if (np == NULL) |
| 1207 | return NULL; |
| 1208 | |
| 1209 | pdev = of_find_device_by_node(np); |
| 1210 | of_node_put(np); |
| 1211 | |
| 1212 | return pdev; |
| 1213 | } |
| 1214 | |
| 1215 | /* find out if a platform device exists at that path */ |
| 1216 | static int of_path_platform_device_exists(const char *path) |
| 1217 | { |
| 1218 | struct platform_device *pdev; |
| 1219 | |
| 1220 | pdev = of_path_to_platform_device(path); |
| 1221 | platform_device_put(pdev); |
| 1222 | return pdev != NULL; |
| 1223 | } |
| 1224 | |
Arnd Bergmann | 4252de3 | 2015-03-04 20:49:47 +0100 | [diff] [blame] | 1225 | #if IS_BUILTIN(CONFIG_I2C) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1226 | |
| 1227 | /* get the i2c client device instantiated at the path */ |
| 1228 | static struct i2c_client *of_path_to_i2c_client(const char *path) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1229 | { |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1230 | struct device_node *np; |
| 1231 | struct i2c_client *client; |
| 1232 | |
| 1233 | np = of_find_node_by_path(path); |
| 1234 | if (np == NULL) |
| 1235 | return NULL; |
| 1236 | |
| 1237 | client = of_find_i2c_device_by_node(np); |
| 1238 | of_node_put(np); |
| 1239 | |
| 1240 | return client; |
| 1241 | } |
| 1242 | |
| 1243 | /* find out if a i2c client device exists at that path */ |
| 1244 | static int of_path_i2c_client_exists(const char *path) |
| 1245 | { |
| 1246 | struct i2c_client *client; |
| 1247 | |
| 1248 | client = of_path_to_i2c_client(path); |
| 1249 | if (client) |
| 1250 | put_device(&client->dev); |
| 1251 | return client != NULL; |
| 1252 | } |
| 1253 | #else |
| 1254 | static int of_path_i2c_client_exists(const char *path) |
| 1255 | { |
| 1256 | return 0; |
| 1257 | } |
| 1258 | #endif |
| 1259 | |
| 1260 | enum overlay_type { |
| 1261 | PDEV_OVERLAY, |
| 1262 | I2C_OVERLAY |
| 1263 | }; |
| 1264 | |
| 1265 | static int of_path_device_type_exists(const char *path, |
| 1266 | enum overlay_type ovtype) |
| 1267 | { |
| 1268 | switch (ovtype) { |
| 1269 | case PDEV_OVERLAY: |
| 1270 | return of_path_platform_device_exists(path); |
| 1271 | case I2C_OVERLAY: |
| 1272 | return of_path_i2c_client_exists(path); |
| 1273 | } |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1277 | static const char *unittest_path(int nr, enum overlay_type ovtype) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1278 | { |
| 1279 | const char *base; |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1280 | static char buf[256]; |
| 1281 | |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1282 | switch (ovtype) { |
| 1283 | case PDEV_OVERLAY: |
| 1284 | base = "/testcase-data/overlay-node/test-bus"; |
| 1285 | break; |
| 1286 | case I2C_OVERLAY: |
| 1287 | base = "/testcase-data/overlay-node/test-bus/i2c-test-bus"; |
| 1288 | break; |
| 1289 | default: |
| 1290 | buf[0] = '\0'; |
| 1291 | return buf; |
| 1292 | } |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1293 | snprintf(buf, sizeof(buf) - 1, "%s/test-unittest%d", base, nr); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1294 | buf[sizeof(buf) - 1] = '\0'; |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1295 | return buf; |
| 1296 | } |
| 1297 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1298 | static int of_unittest_device_exists(int unittest_nr, enum overlay_type ovtype) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1299 | { |
| 1300 | const char *path; |
| 1301 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1302 | path = unittest_path(unittest_nr, ovtype); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1303 | |
| 1304 | switch (ovtype) { |
| 1305 | case PDEV_OVERLAY: |
| 1306 | return of_path_platform_device_exists(path); |
| 1307 | case I2C_OVERLAY: |
| 1308 | return of_path_i2c_client_exists(path); |
| 1309 | } |
| 1310 | return 0; |
| 1311 | } |
| 1312 | |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1313 | static const char *overlay_path(int nr) |
| 1314 | { |
| 1315 | static char buf[256]; |
| 1316 | |
| 1317 | snprintf(buf, sizeof(buf) - 1, |
| 1318 | "/testcase-data/overlay%d", nr); |
| 1319 | buf[sizeof(buf) - 1] = '\0'; |
| 1320 | |
| 1321 | return buf; |
| 1322 | } |
| 1323 | |
| 1324 | static const char *bus_path = "/testcase-data/overlay-node/test-bus"; |
| 1325 | |
Pantelis Antoniou | 492a22a | 2015-04-07 22:23:49 +0300 | [diff] [blame] | 1326 | /* it is guaranteed that overlay ids are assigned in sequence */ |
| 1327 | #define MAX_UNITTEST_OVERLAYS 256 |
| 1328 | static unsigned long overlay_id_bits[BITS_TO_LONGS(MAX_UNITTEST_OVERLAYS)]; |
| 1329 | static int overlay_first_id = -1; |
| 1330 | |
| 1331 | static void of_unittest_track_overlay(int id) |
| 1332 | { |
| 1333 | if (overlay_first_id < 0) |
| 1334 | overlay_first_id = id; |
| 1335 | id -= overlay_first_id; |
| 1336 | |
| 1337 | /* we shouldn't need that many */ |
| 1338 | BUG_ON(id >= MAX_UNITTEST_OVERLAYS); |
| 1339 | overlay_id_bits[BIT_WORD(id)] |= BIT_MASK(id); |
| 1340 | } |
| 1341 | |
| 1342 | static void of_unittest_untrack_overlay(int id) |
| 1343 | { |
| 1344 | if (overlay_first_id < 0) |
| 1345 | return; |
| 1346 | id -= overlay_first_id; |
| 1347 | BUG_ON(id >= MAX_UNITTEST_OVERLAYS); |
| 1348 | overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id); |
| 1349 | } |
| 1350 | |
| 1351 | static void of_unittest_destroy_tracked_overlays(void) |
| 1352 | { |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1353 | int id, ret, defers, ovcs_id; |
Pantelis Antoniou | 492a22a | 2015-04-07 22:23:49 +0300 | [diff] [blame] | 1354 | |
| 1355 | if (overlay_first_id < 0) |
| 1356 | return; |
| 1357 | |
| 1358 | /* try until no defers */ |
| 1359 | do { |
| 1360 | defers = 0; |
| 1361 | /* remove in reverse order */ |
| 1362 | for (id = MAX_UNITTEST_OVERLAYS - 1; id >= 0; id--) { |
| 1363 | if (!(overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id))) |
| 1364 | continue; |
| 1365 | |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1366 | ovcs_id = id + overlay_first_id; |
| 1367 | ret = of_overlay_remove(&ovcs_id); |
Sergey Senozhatsky | 815d74b | 2016-03-02 20:24:49 +0900 | [diff] [blame] | 1368 | if (ret == -ENODEV) { |
| 1369 | pr_warn("%s: no overlay to destroy for #%d\n", |
| 1370 | __func__, id + overlay_first_id); |
| 1371 | continue; |
| 1372 | } |
Pantelis Antoniou | 492a22a | 2015-04-07 22:23:49 +0300 | [diff] [blame] | 1373 | if (ret != 0) { |
| 1374 | defers++; |
| 1375 | pr_warn("%s: overlay destroy failed for #%d\n", |
| 1376 | __func__, id + overlay_first_id); |
| 1377 | continue; |
| 1378 | } |
| 1379 | |
| 1380 | overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id); |
| 1381 | } |
| 1382 | } while (defers > 0); |
| 1383 | } |
| 1384 | |
Alexander Sverdlin | ca7b896 | 2017-01-19 11:06:16 +0100 | [diff] [blame] | 1385 | static int of_unittest_apply_overlay(int overlay_nr, int unittest_nr, |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1386 | int *overlay_id) |
| 1387 | { |
| 1388 | struct device_node *np = NULL; |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1389 | int ret; |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1390 | |
| 1391 | np = of_find_node_by_path(overlay_path(overlay_nr)); |
| 1392 | if (np == NULL) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1393 | unittest(0, "could not find overlay node @\"%s\"\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1394 | overlay_path(overlay_nr)); |
| 1395 | ret = -EINVAL; |
| 1396 | goto out; |
| 1397 | } |
| 1398 | |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1399 | *overlay_id = 0; |
| 1400 | ret = of_overlay_apply(np, overlay_id); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1401 | if (ret < 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1402 | unittest(0, "could not create overlay from \"%s\"\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1403 | overlay_path(overlay_nr)); |
| 1404 | goto out; |
| 1405 | } |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1406 | of_unittest_track_overlay(*overlay_id); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1407 | |
| 1408 | ret = 0; |
| 1409 | |
| 1410 | out: |
| 1411 | of_node_put(np); |
| 1412 | |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1413 | return ret; |
| 1414 | } |
| 1415 | |
| 1416 | /* apply an overlay while checking before and after states */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1417 | static int of_unittest_apply_overlay_check(int overlay_nr, int unittest_nr, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1418 | int before, int after, enum overlay_type ovtype) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1419 | { |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1420 | int ret, ovcs_id; |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1421 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1422 | /* unittest device must not be in before state */ |
| 1423 | if (of_unittest_device_exists(unittest_nr, ovtype) != before) { |
| 1424 | unittest(0, "overlay @\"%s\" with device @\"%s\" %s\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1425 | overlay_path(overlay_nr), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1426 | unittest_path(unittest_nr, ovtype), |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1427 | !before ? "enabled" : "disabled"); |
| 1428 | return -EINVAL; |
| 1429 | } |
| 1430 | |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1431 | ovcs_id = 0; |
| 1432 | ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1433 | if (ret != 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1434 | /* of_unittest_apply_overlay already called unittest() */ |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1435 | return ret; |
| 1436 | } |
| 1437 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1438 | /* unittest device must be to set to after state */ |
| 1439 | if (of_unittest_device_exists(unittest_nr, ovtype) != after) { |
| 1440 | unittest(0, "overlay @\"%s\" failed to create @\"%s\" %s\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1441 | overlay_path(overlay_nr), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1442 | unittest_path(unittest_nr, ovtype), |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1443 | !after ? "enabled" : "disabled"); |
| 1444 | return -EINVAL; |
| 1445 | } |
| 1446 | |
| 1447 | return 0; |
| 1448 | } |
| 1449 | |
| 1450 | /* apply an overlay and then revert it while checking before, after states */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1451 | static int of_unittest_apply_revert_overlay_check(int overlay_nr, |
| 1452 | int unittest_nr, int before, int after, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1453 | enum overlay_type ovtype) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1454 | { |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1455 | int ret, ovcs_id; |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1456 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1457 | /* unittest device must be in before state */ |
| 1458 | if (of_unittest_device_exists(unittest_nr, ovtype) != before) { |
| 1459 | unittest(0, "overlay @\"%s\" with device @\"%s\" %s\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1460 | overlay_path(overlay_nr), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1461 | unittest_path(unittest_nr, ovtype), |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1462 | !before ? "enabled" : "disabled"); |
| 1463 | return -EINVAL; |
| 1464 | } |
| 1465 | |
| 1466 | /* apply the overlay */ |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1467 | ovcs_id = 0; |
| 1468 | ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1469 | if (ret != 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1470 | /* of_unittest_apply_overlay already called unittest() */ |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1471 | return ret; |
| 1472 | } |
| 1473 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1474 | /* unittest device must be in after state */ |
| 1475 | if (of_unittest_device_exists(unittest_nr, ovtype) != after) { |
| 1476 | unittest(0, "overlay @\"%s\" failed to create @\"%s\" %s\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1477 | overlay_path(overlay_nr), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1478 | unittest_path(unittest_nr, ovtype), |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1479 | !after ? "enabled" : "disabled"); |
| 1480 | return -EINVAL; |
| 1481 | } |
| 1482 | |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1483 | ret = of_overlay_remove(&ovcs_id); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1484 | if (ret != 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1485 | unittest(0, "overlay @\"%s\" failed to be destroyed @\"%s\"\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1486 | overlay_path(overlay_nr), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1487 | unittest_path(unittest_nr, ovtype)); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1488 | return ret; |
| 1489 | } |
| 1490 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1491 | /* unittest device must be again in before state */ |
| 1492 | if (of_unittest_device_exists(unittest_nr, PDEV_OVERLAY) != before) { |
| 1493 | unittest(0, "overlay @\"%s\" with device @\"%s\" %s\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1494 | overlay_path(overlay_nr), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1495 | unittest_path(unittest_nr, ovtype), |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1496 | !before ? "enabled" : "disabled"); |
| 1497 | return -EINVAL; |
| 1498 | } |
| 1499 | |
| 1500 | return 0; |
| 1501 | } |
| 1502 | |
| 1503 | /* test activation of device */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1504 | static void of_unittest_overlay_0(void) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1505 | { |
| 1506 | int ret; |
| 1507 | |
| 1508 | /* device should enable */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1509 | ret = of_unittest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1510 | if (ret != 0) |
| 1511 | return; |
| 1512 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1513 | unittest(1, "overlay test %d passed\n", 0); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | /* test deactivation of device */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1517 | static void of_unittest_overlay_1(void) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1518 | { |
| 1519 | int ret; |
| 1520 | |
| 1521 | /* device should disable */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1522 | ret = of_unittest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1523 | if (ret != 0) |
| 1524 | return; |
| 1525 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1526 | unittest(1, "overlay test %d passed\n", 1); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | /* test activation of device */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1530 | static void of_unittest_overlay_2(void) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1531 | { |
| 1532 | int ret; |
| 1533 | |
| 1534 | /* device should enable */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1535 | ret = of_unittest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1536 | if (ret != 0) |
| 1537 | return; |
| 1538 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1539 | unittest(1, "overlay test %d passed\n", 2); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | /* test deactivation of device */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1543 | static void of_unittest_overlay_3(void) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1544 | { |
| 1545 | int ret; |
| 1546 | |
| 1547 | /* device should disable */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1548 | ret = of_unittest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1549 | if (ret != 0) |
| 1550 | return; |
| 1551 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1552 | unittest(1, "overlay test %d passed\n", 3); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | /* test activation of a full device node */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1556 | static void of_unittest_overlay_4(void) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1557 | { |
| 1558 | int ret; |
| 1559 | |
| 1560 | /* device should disable */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1561 | ret = of_unittest_apply_overlay_check(4, 4, 0, 1, PDEV_OVERLAY); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1562 | if (ret != 0) |
| 1563 | return; |
| 1564 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1565 | unittest(1, "overlay test %d passed\n", 4); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | /* test overlay apply/revert sequence */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1569 | static void of_unittest_overlay_5(void) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1570 | { |
| 1571 | int ret; |
| 1572 | |
| 1573 | /* device should disable */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1574 | ret = of_unittest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1575 | if (ret != 0) |
| 1576 | return; |
| 1577 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1578 | unittest(1, "overlay test %d passed\n", 5); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | /* test overlay application in sequence */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1582 | static void of_unittest_overlay_6(void) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1583 | { |
| 1584 | struct device_node *np; |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1585 | int ret, i, ov_id[2], ovcs_id; |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1586 | int overlay_nr = 6, unittest_nr = 6; |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1587 | int before = 0, after = 1; |
| 1588 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1589 | /* unittest device must be in before state */ |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1590 | for (i = 0; i < 2; i++) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1591 | if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1592 | != before) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1593 | unittest(0, "overlay @\"%s\" with device @\"%s\" %s\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1594 | overlay_path(overlay_nr + i), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1595 | unittest_path(unittest_nr + i, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1596 | PDEV_OVERLAY), |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1597 | !before ? "enabled" : "disabled"); |
| 1598 | return; |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | /* apply the overlays */ |
| 1603 | for (i = 0; i < 2; i++) { |
| 1604 | |
| 1605 | np = of_find_node_by_path(overlay_path(overlay_nr + i)); |
| 1606 | if (np == NULL) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1607 | unittest(0, "could not find overlay node @\"%s\"\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1608 | overlay_path(overlay_nr + i)); |
| 1609 | return; |
| 1610 | } |
| 1611 | |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1612 | ovcs_id = 0; |
| 1613 | ret = of_overlay_apply(np, &ovcs_id); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1614 | if (ret < 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1615 | unittest(0, "could not create overlay from \"%s\"\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1616 | overlay_path(overlay_nr + i)); |
| 1617 | return; |
| 1618 | } |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1619 | ov_id[i] = ovcs_id; |
Pantelis Antoniou | 492a22a | 2015-04-07 22:23:49 +0300 | [diff] [blame] | 1620 | of_unittest_track_overlay(ov_id[i]); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | for (i = 0; i < 2; i++) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1624 | /* unittest device must be in after state */ |
| 1625 | if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1626 | != after) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1627 | unittest(0, "overlay @\"%s\" failed @\"%s\" %s\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1628 | overlay_path(overlay_nr + i), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1629 | unittest_path(unittest_nr + i, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1630 | PDEV_OVERLAY), |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1631 | !after ? "enabled" : "disabled"); |
| 1632 | return; |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | for (i = 1; i >= 0; i--) { |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1637 | ovcs_id = ov_id[i]; |
| 1638 | ret = of_overlay_remove(&ovcs_id); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1639 | if (ret != 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1640 | unittest(0, "overlay @\"%s\" failed destroy @\"%s\"\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1641 | overlay_path(overlay_nr + i), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1642 | unittest_path(unittest_nr + i, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1643 | PDEV_OVERLAY)); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1644 | return; |
| 1645 | } |
Pantelis Antoniou | 492a22a | 2015-04-07 22:23:49 +0300 | [diff] [blame] | 1646 | of_unittest_untrack_overlay(ov_id[i]); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | for (i = 0; i < 2; i++) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1650 | /* unittest device must be again in before state */ |
| 1651 | if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1652 | != before) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1653 | unittest(0, "overlay @\"%s\" with device @\"%s\" %s\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1654 | overlay_path(overlay_nr + i), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1655 | unittest_path(unittest_nr + i, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1656 | PDEV_OVERLAY), |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1657 | !before ? "enabled" : "disabled"); |
| 1658 | return; |
| 1659 | } |
| 1660 | } |
| 1661 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1662 | unittest(1, "overlay test %d passed\n", 6); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | /* test overlay application in sequence */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1666 | static void of_unittest_overlay_8(void) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1667 | { |
| 1668 | struct device_node *np; |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1669 | int ret, i, ov_id[2], ovcs_id; |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1670 | int overlay_nr = 8, unittest_nr = 8; |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1671 | |
| 1672 | /* we don't care about device state in this test */ |
| 1673 | |
| 1674 | /* apply the overlays */ |
| 1675 | for (i = 0; i < 2; i++) { |
| 1676 | |
| 1677 | np = of_find_node_by_path(overlay_path(overlay_nr + i)); |
| 1678 | if (np == NULL) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1679 | unittest(0, "could not find overlay node @\"%s\"\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1680 | overlay_path(overlay_nr + i)); |
| 1681 | return; |
| 1682 | } |
| 1683 | |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1684 | ovcs_id = 0; |
| 1685 | ret = of_overlay_apply(np, &ovcs_id); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1686 | if (ret < 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1687 | unittest(0, "could not create overlay from \"%s\"\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1688 | overlay_path(overlay_nr + i)); |
| 1689 | return; |
| 1690 | } |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1691 | ov_id[i] = ovcs_id; |
Pantelis Antoniou | 492a22a | 2015-04-07 22:23:49 +0300 | [diff] [blame] | 1692 | of_unittest_track_overlay(ov_id[i]); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | /* now try to remove first overlay (it should fail) */ |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1696 | ovcs_id = ov_id[0]; |
| 1697 | ret = of_overlay_remove(&ovcs_id); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1698 | if (ret == 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1699 | unittest(0, "overlay @\"%s\" was destroyed @\"%s\"\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1700 | overlay_path(overlay_nr + 0), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1701 | unittest_path(unittest_nr, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1702 | PDEV_OVERLAY)); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1703 | return; |
| 1704 | } |
| 1705 | |
| 1706 | /* removing them in order should work */ |
| 1707 | for (i = 1; i >= 0; i--) { |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 1708 | ovcs_id = ov_id[i]; |
| 1709 | ret = of_overlay_remove(&ovcs_id); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1710 | if (ret != 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1711 | unittest(0, "overlay @\"%s\" not destroyed @\"%s\"\n", |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1712 | overlay_path(overlay_nr + i), |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1713 | unittest_path(unittest_nr, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1714 | PDEV_OVERLAY)); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1715 | return; |
| 1716 | } |
Pantelis Antoniou | 492a22a | 2015-04-07 22:23:49 +0300 | [diff] [blame] | 1717 | of_unittest_untrack_overlay(ov_id[i]); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1718 | } |
| 1719 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1720 | unittest(1, "overlay test %d passed\n", 8); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 1721 | } |
| 1722 | |
Pantelis Antoniou | 6b1271d | 2014-12-19 14:34:34 +0200 | [diff] [blame] | 1723 | /* test insertion of a bus with parent devices */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1724 | static void of_unittest_overlay_10(void) |
Pantelis Antoniou | 6b1271d | 2014-12-19 14:34:34 +0200 | [diff] [blame] | 1725 | { |
| 1726 | int ret; |
| 1727 | char *child_path; |
| 1728 | |
| 1729 | /* device should disable */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1730 | ret = of_unittest_apply_overlay_check(10, 10, 0, 1, PDEV_OVERLAY); |
| 1731 | if (unittest(ret == 0, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1732 | "overlay test %d failed; overlay application\n", 10)) |
Pantelis Antoniou | 6b1271d | 2014-12-19 14:34:34 +0200 | [diff] [blame] | 1733 | return; |
| 1734 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1735 | child_path = kasprintf(GFP_KERNEL, "%s/test-unittest101", |
| 1736 | unittest_path(10, PDEV_OVERLAY)); |
| 1737 | if (unittest(child_path, "overlay test %d failed; kasprintf\n", 10)) |
Pantelis Antoniou | 6b1271d | 2014-12-19 14:34:34 +0200 | [diff] [blame] | 1738 | return; |
| 1739 | |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1740 | ret = of_path_device_type_exists(child_path, PDEV_OVERLAY); |
Pantelis Antoniou | 6b1271d | 2014-12-19 14:34:34 +0200 | [diff] [blame] | 1741 | kfree(child_path); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1742 | if (unittest(ret, "overlay test %d failed; no child device\n", 10)) |
Pantelis Antoniou | 6b1271d | 2014-12-19 14:34:34 +0200 | [diff] [blame] | 1743 | return; |
| 1744 | } |
| 1745 | |
| 1746 | /* test insertion of a bus with parent devices (and revert) */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1747 | static void of_unittest_overlay_11(void) |
Pantelis Antoniou | 6b1271d | 2014-12-19 14:34:34 +0200 | [diff] [blame] | 1748 | { |
| 1749 | int ret; |
| 1750 | |
| 1751 | /* device should disable */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1752 | ret = of_unittest_apply_revert_overlay_check(11, 11, 0, 1, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1753 | PDEV_OVERLAY); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1754 | if (unittest(ret == 0, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1755 | "overlay test %d failed; overlay application\n", 11)) |
Pantelis Antoniou | 6b1271d | 2014-12-19 14:34:34 +0200 | [diff] [blame] | 1756 | return; |
| 1757 | } |
| 1758 | |
Arnd Bergmann | 4252de3 | 2015-03-04 20:49:47 +0100 | [diff] [blame] | 1759 | #if IS_BUILTIN(CONFIG_I2C) && IS_ENABLED(CONFIG_OF_OVERLAY) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1760 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1761 | struct unittest_i2c_bus_data { |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1762 | struct platform_device *pdev; |
| 1763 | struct i2c_adapter adap; |
| 1764 | }; |
| 1765 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1766 | static int unittest_i2c_master_xfer(struct i2c_adapter *adap, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1767 | struct i2c_msg *msgs, int num) |
| 1768 | { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1769 | struct unittest_i2c_bus_data *std = i2c_get_adapdata(adap); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1770 | |
| 1771 | (void)std; |
| 1772 | |
| 1773 | return num; |
| 1774 | } |
| 1775 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1776 | static u32 unittest_i2c_functionality(struct i2c_adapter *adap) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1777 | { |
| 1778 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
| 1779 | } |
| 1780 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1781 | static const struct i2c_algorithm unittest_i2c_algo = { |
| 1782 | .master_xfer = unittest_i2c_master_xfer, |
| 1783 | .functionality = unittest_i2c_functionality, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1784 | }; |
| 1785 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1786 | static int unittest_i2c_bus_probe(struct platform_device *pdev) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1787 | { |
| 1788 | struct device *dev = &pdev->dev; |
| 1789 | struct device_node *np = dev->of_node; |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1790 | struct unittest_i2c_bus_data *std; |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1791 | struct i2c_adapter *adap; |
| 1792 | int ret; |
| 1793 | |
| 1794 | if (np == NULL) { |
| 1795 | dev_err(dev, "No OF data for device\n"); |
| 1796 | return -EINVAL; |
| 1797 | |
| 1798 | } |
| 1799 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 1800 | dev_dbg(dev, "%s for node @%pOF\n", __func__, np); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1801 | |
| 1802 | std = devm_kzalloc(dev, sizeof(*std), GFP_KERNEL); |
| 1803 | if (!std) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1804 | dev_err(dev, "Failed to allocate unittest i2c data\n"); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1805 | return -ENOMEM; |
| 1806 | } |
| 1807 | |
| 1808 | /* link them together */ |
| 1809 | std->pdev = pdev; |
| 1810 | platform_set_drvdata(pdev, std); |
| 1811 | |
| 1812 | adap = &std->adap; |
| 1813 | i2c_set_adapdata(adap, std); |
| 1814 | adap->nr = -1; |
| 1815 | strlcpy(adap->name, pdev->name, sizeof(adap->name)); |
| 1816 | adap->class = I2C_CLASS_DEPRECATED; |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1817 | adap->algo = &unittest_i2c_algo; |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1818 | adap->dev.parent = dev; |
| 1819 | adap->dev.of_node = dev->of_node; |
| 1820 | adap->timeout = 5 * HZ; |
| 1821 | adap->retries = 3; |
| 1822 | |
| 1823 | ret = i2c_add_numbered_adapter(adap); |
| 1824 | if (ret != 0) { |
| 1825 | dev_err(dev, "Failed to add I2C adapter\n"); |
| 1826 | return ret; |
| 1827 | } |
| 1828 | |
| 1829 | return 0; |
| 1830 | } |
| 1831 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1832 | static int unittest_i2c_bus_remove(struct platform_device *pdev) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1833 | { |
| 1834 | struct device *dev = &pdev->dev; |
| 1835 | struct device_node *np = dev->of_node; |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1836 | struct unittest_i2c_bus_data *std = platform_get_drvdata(pdev); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1837 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 1838 | dev_dbg(dev, "%s for node @%pOF\n", __func__, np); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1839 | i2c_del_adapter(&std->adap); |
| 1840 | |
| 1841 | return 0; |
| 1842 | } |
| 1843 | |
Grant Likely | a2166ca | 2015-03-29 08:59:58 +0100 | [diff] [blame] | 1844 | static const struct of_device_id unittest_i2c_bus_match[] = { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1845 | { .compatible = "unittest-i2c-bus", }, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1846 | {}, |
| 1847 | }; |
| 1848 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1849 | static struct platform_driver unittest_i2c_bus_driver = { |
| 1850 | .probe = unittest_i2c_bus_probe, |
| 1851 | .remove = unittest_i2c_bus_remove, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1852 | .driver = { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1853 | .name = "unittest-i2c-bus", |
| 1854 | .of_match_table = of_match_ptr(unittest_i2c_bus_match), |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1855 | }, |
| 1856 | }; |
| 1857 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1858 | static int unittest_i2c_dev_probe(struct i2c_client *client, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1859 | const struct i2c_device_id *id) |
| 1860 | { |
| 1861 | struct device *dev = &client->dev; |
| 1862 | struct device_node *np = client->dev.of_node; |
| 1863 | |
| 1864 | if (!np) { |
| 1865 | dev_err(dev, "No OF node\n"); |
| 1866 | return -EINVAL; |
| 1867 | } |
| 1868 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 1869 | dev_dbg(dev, "%s for node @%pOF\n", __func__, np); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1870 | |
| 1871 | return 0; |
| 1872 | }; |
| 1873 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1874 | static int unittest_i2c_dev_remove(struct i2c_client *client) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1875 | { |
| 1876 | struct device *dev = &client->dev; |
| 1877 | struct device_node *np = client->dev.of_node; |
| 1878 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 1879 | dev_dbg(dev, "%s for node @%pOF\n", __func__, np); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1880 | return 0; |
| 1881 | } |
| 1882 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1883 | static const struct i2c_device_id unittest_i2c_dev_id[] = { |
| 1884 | { .name = "unittest-i2c-dev" }, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1885 | { } |
| 1886 | }; |
| 1887 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1888 | static struct i2c_driver unittest_i2c_dev_driver = { |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1889 | .driver = { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1890 | .name = "unittest-i2c-dev", |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1891 | }, |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1892 | .probe = unittest_i2c_dev_probe, |
| 1893 | .remove = unittest_i2c_dev_remove, |
| 1894 | .id_table = unittest_i2c_dev_id, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1895 | }; |
| 1896 | |
Arnd Bergmann | 4252de3 | 2015-03-04 20:49:47 +0100 | [diff] [blame] | 1897 | #if IS_BUILTIN(CONFIG_I2C_MUX) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1898 | |
Peter Rosin | b6e3b71 | 2016-04-20 08:42:47 +0200 | [diff] [blame] | 1899 | static int unittest_i2c_mux_select_chan(struct i2c_mux_core *muxc, u32 chan) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1900 | { |
| 1901 | return 0; |
| 1902 | } |
| 1903 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1904 | static int unittest_i2c_mux_probe(struct i2c_client *client, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1905 | const struct i2c_device_id *id) |
| 1906 | { |
Peter Rosin | b6e3b71 | 2016-04-20 08:42:47 +0200 | [diff] [blame] | 1907 | int ret, i, nchans; |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1908 | struct device *dev = &client->dev; |
| 1909 | struct i2c_adapter *adap = to_i2c_adapter(dev->parent); |
| 1910 | struct device_node *np = client->dev.of_node, *child; |
Peter Rosin | b6e3b71 | 2016-04-20 08:42:47 +0200 | [diff] [blame] | 1911 | struct i2c_mux_core *muxc; |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1912 | u32 reg, max_reg; |
| 1913 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 1914 | dev_dbg(dev, "%s for node @%pOF\n", __func__, np); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1915 | |
| 1916 | if (!np) { |
| 1917 | dev_err(dev, "No OF node\n"); |
| 1918 | return -EINVAL; |
| 1919 | } |
| 1920 | |
| 1921 | max_reg = (u32)-1; |
| 1922 | for_each_child_of_node(np, child) { |
| 1923 | ret = of_property_read_u32(child, "reg", ®); |
| 1924 | if (ret) |
| 1925 | continue; |
| 1926 | if (max_reg == (u32)-1 || reg > max_reg) |
| 1927 | max_reg = reg; |
| 1928 | } |
| 1929 | nchans = max_reg == (u32)-1 ? 0 : max_reg + 1; |
| 1930 | if (nchans == 0) { |
| 1931 | dev_err(dev, "No channels\n"); |
| 1932 | return -EINVAL; |
| 1933 | } |
| 1934 | |
Peter Rosin | b6e3b71 | 2016-04-20 08:42:47 +0200 | [diff] [blame] | 1935 | muxc = i2c_mux_alloc(adap, dev, nchans, 0, 0, |
| 1936 | unittest_i2c_mux_select_chan, NULL); |
| 1937 | if (!muxc) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1938 | return -ENOMEM; |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1939 | for (i = 0; i < nchans; i++) { |
Peter Rosin | b6e3b71 | 2016-04-20 08:42:47 +0200 | [diff] [blame] | 1940 | ret = i2c_mux_add_adapter(muxc, 0, i, 0); |
| 1941 | if (ret) { |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1942 | dev_err(dev, "Failed to register mux #%d\n", i); |
Peter Rosin | b6e3b71 | 2016-04-20 08:42:47 +0200 | [diff] [blame] | 1943 | i2c_mux_del_adapters(muxc); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1944 | return -ENODEV; |
| 1945 | } |
| 1946 | } |
| 1947 | |
Peter Rosin | b6e3b71 | 2016-04-20 08:42:47 +0200 | [diff] [blame] | 1948 | i2c_set_clientdata(client, muxc); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1949 | |
| 1950 | return 0; |
| 1951 | }; |
| 1952 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1953 | static int unittest_i2c_mux_remove(struct i2c_client *client) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1954 | { |
| 1955 | struct device *dev = &client->dev; |
| 1956 | struct device_node *np = client->dev.of_node; |
Peter Rosin | b6e3b71 | 2016-04-20 08:42:47 +0200 | [diff] [blame] | 1957 | struct i2c_mux_core *muxc = i2c_get_clientdata(client); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1958 | |
Rob Herring | 0d638a0 | 2017-06-01 15:50:55 -0500 | [diff] [blame] | 1959 | dev_dbg(dev, "%s for node @%pOF\n", __func__, np); |
Peter Rosin | b6e3b71 | 2016-04-20 08:42:47 +0200 | [diff] [blame] | 1960 | i2c_mux_del_adapters(muxc); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1961 | return 0; |
| 1962 | } |
| 1963 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1964 | static const struct i2c_device_id unittest_i2c_mux_id[] = { |
| 1965 | { .name = "unittest-i2c-mux" }, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1966 | { } |
| 1967 | }; |
| 1968 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1969 | static struct i2c_driver unittest_i2c_mux_driver = { |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1970 | .driver = { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1971 | .name = "unittest-i2c-mux", |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1972 | }, |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1973 | .probe = unittest_i2c_mux_probe, |
| 1974 | .remove = unittest_i2c_mux_remove, |
| 1975 | .id_table = unittest_i2c_mux_id, |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1976 | }; |
| 1977 | |
| 1978 | #endif |
| 1979 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1980 | static int of_unittest_overlay_i2c_init(void) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1981 | { |
| 1982 | int ret; |
| 1983 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1984 | ret = i2c_add_driver(&unittest_i2c_dev_driver); |
| 1985 | if (unittest(ret == 0, |
| 1986 | "could not register unittest i2c device driver\n")) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1987 | return ret; |
| 1988 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1989 | ret = platform_driver_register(&unittest_i2c_bus_driver); |
| 1990 | if (unittest(ret == 0, |
| 1991 | "could not register unittest i2c bus driver\n")) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1992 | return ret; |
| 1993 | |
Arnd Bergmann | 4252de3 | 2015-03-04 20:49:47 +0100 | [diff] [blame] | 1994 | #if IS_BUILTIN(CONFIG_I2C_MUX) |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 1995 | ret = i2c_add_driver(&unittest_i2c_mux_driver); |
| 1996 | if (unittest(ret == 0, |
| 1997 | "could not register unittest i2c mux driver\n")) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 1998 | return ret; |
| 1999 | #endif |
| 2000 | |
| 2001 | return 0; |
| 2002 | } |
| 2003 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2004 | static void of_unittest_overlay_i2c_cleanup(void) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2005 | { |
Arnd Bergmann | 4252de3 | 2015-03-04 20:49:47 +0100 | [diff] [blame] | 2006 | #if IS_BUILTIN(CONFIG_I2C_MUX) |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2007 | i2c_del_driver(&unittest_i2c_mux_driver); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2008 | #endif |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2009 | platform_driver_unregister(&unittest_i2c_bus_driver); |
| 2010 | i2c_del_driver(&unittest_i2c_dev_driver); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2011 | } |
| 2012 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2013 | static void of_unittest_overlay_i2c_12(void) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2014 | { |
| 2015 | int ret; |
| 2016 | |
| 2017 | /* device should enable */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2018 | ret = of_unittest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2019 | if (ret != 0) |
| 2020 | return; |
| 2021 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2022 | unittest(1, "overlay test %d passed\n", 12); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | /* test deactivation of device */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2026 | static void of_unittest_overlay_i2c_13(void) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2027 | { |
| 2028 | int ret; |
| 2029 | |
| 2030 | /* device should disable */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2031 | ret = of_unittest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2032 | if (ret != 0) |
| 2033 | return; |
| 2034 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2035 | unittest(1, "overlay test %d passed\n", 13); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | /* just check for i2c mux existence */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2039 | static void of_unittest_overlay_i2c_14(void) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2040 | { |
| 2041 | } |
| 2042 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2043 | static void of_unittest_overlay_i2c_15(void) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2044 | { |
| 2045 | int ret; |
| 2046 | |
| 2047 | /* device should enable */ |
Alexander Sverdlin | ca7b896 | 2017-01-19 11:06:16 +0100 | [diff] [blame] | 2048 | ret = of_unittest_apply_overlay_check(15, 15, 0, 1, I2C_OVERLAY); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2049 | if (ret != 0) |
| 2050 | return; |
| 2051 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2052 | unittest(1, "overlay test %d passed\n", 15); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | #else |
| 2056 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2057 | static inline void of_unittest_overlay_i2c_14(void) { } |
| 2058 | static inline void of_unittest_overlay_i2c_15(void) { } |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2059 | |
| 2060 | #endif |
| 2061 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2062 | static void __init of_unittest_overlay(void) |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2063 | { |
| 2064 | struct device_node *bus_np = NULL; |
| 2065 | int ret; |
| 2066 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2067 | ret = platform_driver_register(&unittest_driver); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2068 | if (ret != 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2069 | unittest(0, "could not register unittest driver\n"); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2070 | goto out; |
| 2071 | } |
| 2072 | |
| 2073 | bus_np = of_find_node_by_path(bus_path); |
| 2074 | if (bus_np == NULL) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2075 | unittest(0, "could not find bus_path \"%s\"\n", bus_path); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2076 | goto out; |
| 2077 | } |
| 2078 | |
Kefeng Wang | 146dedb | 2016-06-01 14:53:10 +0800 | [diff] [blame] | 2079 | ret = of_platform_default_populate(bus_np, NULL, NULL); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2080 | if (ret != 0) { |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2081 | unittest(0, "could not populate bus @ \"%s\"\n", bus_path); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2082 | goto out; |
| 2083 | } |
| 2084 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2085 | if (!of_unittest_device_exists(100, PDEV_OVERLAY)) { |
| 2086 | unittest(0, "could not find unittest0 @ \"%s\"\n", |
| 2087 | unittest_path(100, PDEV_OVERLAY)); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2088 | goto out; |
| 2089 | } |
| 2090 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2091 | if (of_unittest_device_exists(101, PDEV_OVERLAY)) { |
| 2092 | unittest(0, "unittest1 @ \"%s\" should not exist\n", |
| 2093 | unittest_path(101, PDEV_OVERLAY)); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2094 | goto out; |
| 2095 | } |
| 2096 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2097 | unittest(1, "basic infrastructure of overlays passed"); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2098 | |
| 2099 | /* tests in sequence */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2100 | of_unittest_overlay_0(); |
| 2101 | of_unittest_overlay_1(); |
| 2102 | of_unittest_overlay_2(); |
| 2103 | of_unittest_overlay_3(); |
| 2104 | of_unittest_overlay_4(); |
| 2105 | of_unittest_overlay_5(); |
| 2106 | of_unittest_overlay_6(); |
| 2107 | of_unittest_overlay_8(); |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2108 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2109 | of_unittest_overlay_10(); |
| 2110 | of_unittest_overlay_11(); |
Pantelis Antoniou | 6b1271d | 2014-12-19 14:34:34 +0200 | [diff] [blame] | 2111 | |
Arnd Bergmann | 4252de3 | 2015-03-04 20:49:47 +0100 | [diff] [blame] | 2112 | #if IS_BUILTIN(CONFIG_I2C) |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2113 | if (unittest(of_unittest_overlay_i2c_init() == 0, "i2c init failed\n")) |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2114 | goto out; |
| 2115 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2116 | of_unittest_overlay_i2c_12(); |
| 2117 | of_unittest_overlay_i2c_13(); |
| 2118 | of_unittest_overlay_i2c_14(); |
| 2119 | of_unittest_overlay_i2c_15(); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2120 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2121 | of_unittest_overlay_i2c_cleanup(); |
Pantelis Antoniou | d5e7550 | 2015-01-12 19:02:49 +0200 | [diff] [blame] | 2122 | #endif |
| 2123 | |
Pantelis Antoniou | 492a22a | 2015-04-07 22:23:49 +0300 | [diff] [blame] | 2124 | of_unittest_destroy_tracked_overlays(); |
| 2125 | |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2126 | out: |
| 2127 | of_node_put(bus_np); |
| 2128 | } |
| 2129 | |
| 2130 | #else |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2131 | static inline void __init of_unittest_overlay(void) { } |
Pantelis Antoniou | 177d271 | 2014-10-28 22:35:59 +0200 | [diff] [blame] | 2132 | #endif |
| 2133 | |
Frank Rowand | 60a0004 | 2017-07-19 09:25:20 -0700 | [diff] [blame] | 2134 | #ifdef CONFIG_OF_OVERLAY |
| 2135 | |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2136 | /* |
| 2137 | * __dtb_ot_begin[] and __dtb_ot_end[] are created by cmd_dt_S_dtb |
| 2138 | * in scripts/Makefile.lib |
| 2139 | */ |
| 2140 | |
| 2141 | #define OVERLAY_INFO_EXTERN(name) \ |
| 2142 | extern uint8_t __dtb_##name##_begin[]; \ |
| 2143 | extern uint8_t __dtb_##name##_end[] |
| 2144 | |
| 2145 | #define OVERLAY_INFO(name, expected) \ |
| 2146 | { .dtb_begin = __dtb_##name##_begin, \ |
| 2147 | .dtb_end = __dtb_##name##_end, \ |
| 2148 | .expected_result = expected, \ |
| 2149 | } |
| 2150 | |
| 2151 | struct overlay_info { |
| 2152 | uint8_t *dtb_begin; |
| 2153 | uint8_t *dtb_end; |
| 2154 | void *data; |
| 2155 | struct device_node *np_overlay; |
| 2156 | int expected_result; |
| 2157 | int overlay_id; |
| 2158 | }; |
| 2159 | |
| 2160 | OVERLAY_INFO_EXTERN(overlay_base); |
| 2161 | OVERLAY_INFO_EXTERN(overlay); |
| 2162 | OVERLAY_INFO_EXTERN(overlay_bad_phandle); |
Frank Rowand | 60a0004 | 2017-07-19 09:25:20 -0700 | [diff] [blame] | 2163 | OVERLAY_INFO_EXTERN(overlay_bad_symbol); |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2164 | |
| 2165 | /* order of entries is hard-coded into users of overlays[] */ |
| 2166 | static struct overlay_info overlays[] = { |
| 2167 | OVERLAY_INFO(overlay_base, -9999), |
| 2168 | OVERLAY_INFO(overlay, 0), |
| 2169 | OVERLAY_INFO(overlay_bad_phandle, -EINVAL), |
Frank Rowand | 60a0004 | 2017-07-19 09:25:20 -0700 | [diff] [blame] | 2170 | OVERLAY_INFO(overlay_bad_symbol, -EINVAL), |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2171 | {} |
| 2172 | }; |
| 2173 | |
| 2174 | static struct device_node *overlay_base_root; |
| 2175 | |
Rob Herring | 0fa1c57 | 2018-01-05 15:32:33 -0600 | [diff] [blame] | 2176 | static void * __init dt_alloc_memory(u64 size, u64 align) |
| 2177 | { |
| 2178 | return memblock_virt_alloc(size, align); |
| 2179 | } |
| 2180 | |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2181 | /* |
| 2182 | * Create base device tree for the overlay unittest. |
| 2183 | * |
| 2184 | * This is called from very early boot code. |
| 2185 | * |
| 2186 | * Do as much as possible the same way as done in __unflatten_device_tree |
| 2187 | * and other early boot steps for the normal FDT so that the overlay base |
| 2188 | * unflattened tree will have the same characteristics as the real tree |
| 2189 | * (such as having memory allocated by the early allocator). The goal |
| 2190 | * is to test "the real thing" as much as possible, and test "test setup |
| 2191 | * code" as little as possible. |
| 2192 | * |
| 2193 | * Have to stop before resolving phandles, because that uses kmalloc. |
| 2194 | */ |
| 2195 | void __init unittest_unflatten_overlay_base(void) |
| 2196 | { |
| 2197 | struct overlay_info *info; |
| 2198 | u32 data_size; |
| 2199 | u32 size; |
| 2200 | |
| 2201 | info = &overlays[0]; |
| 2202 | |
| 2203 | if (info->expected_result != -9999) { |
| 2204 | pr_err("No dtb 'overlay_base' to attach\n"); |
| 2205 | return; |
| 2206 | } |
| 2207 | |
| 2208 | data_size = info->dtb_end - info->dtb_begin; |
| 2209 | if (!data_size) { |
| 2210 | pr_err("No dtb 'overlay_base' to attach\n"); |
| 2211 | return; |
| 2212 | } |
| 2213 | |
| 2214 | size = fdt_totalsize(info->dtb_begin); |
| 2215 | if (size != data_size) { |
| 2216 | pr_err("dtb 'overlay_base' header totalsize != actual size"); |
| 2217 | return; |
| 2218 | } |
| 2219 | |
Rob Herring | 0fa1c57 | 2018-01-05 15:32:33 -0600 | [diff] [blame] | 2220 | info->data = dt_alloc_memory(size, roundup_pow_of_two(FDT_V17_SIZE)); |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2221 | if (!info->data) { |
| 2222 | pr_err("alloc for dtb 'overlay_base' failed"); |
| 2223 | return; |
| 2224 | } |
| 2225 | |
| 2226 | memcpy(info->data, info->dtb_begin, size); |
| 2227 | |
| 2228 | __unflatten_device_tree(info->data, NULL, &info->np_overlay, |
Rob Herring | 0fa1c57 | 2018-01-05 15:32:33 -0600 | [diff] [blame] | 2229 | dt_alloc_memory, true); |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2230 | overlay_base_root = info->np_overlay; |
| 2231 | } |
| 2232 | |
| 2233 | /* |
| 2234 | * The purpose of of_unittest_overlay_data_add is to add an |
| 2235 | * overlay in the normal fashion. This is a test of the whole |
| 2236 | * picture, instead of testing individual elements. |
| 2237 | * |
| 2238 | * A secondary purpose is to be able to verify that the contents of |
| 2239 | * /proc/device-tree/ contains the updated structure and values from |
| 2240 | * the overlay. That must be verified separately in user space. |
| 2241 | * |
| 2242 | * Return 0 on unexpected error. |
| 2243 | */ |
| 2244 | static int __init overlay_data_add(int onum) |
| 2245 | { |
| 2246 | struct overlay_info *info; |
| 2247 | int k; |
| 2248 | int ret; |
| 2249 | u32 size; |
| 2250 | u32 size_from_header; |
| 2251 | |
| 2252 | for (k = 0, info = overlays; info; info++, k++) { |
| 2253 | if (k == onum) |
| 2254 | break; |
| 2255 | } |
| 2256 | if (onum > k) |
| 2257 | return 0; |
| 2258 | |
| 2259 | size = info->dtb_end - info->dtb_begin; |
| 2260 | if (!size) { |
| 2261 | pr_err("no overlay to attach, %d\n", onum); |
| 2262 | ret = 0; |
| 2263 | } |
| 2264 | |
| 2265 | size_from_header = fdt_totalsize(info->dtb_begin); |
| 2266 | if (size_from_header != size) { |
| 2267 | pr_err("overlay header totalsize != actual size, %d", onum); |
| 2268 | return 0; |
| 2269 | } |
| 2270 | |
| 2271 | /* |
| 2272 | * Must create permanent copy of FDT because of_fdt_unflatten_tree() |
| 2273 | * will create pointers to the passed in FDT in the EDT. |
| 2274 | */ |
| 2275 | info->data = kmemdup(info->dtb_begin, size, GFP_KERNEL); |
| 2276 | if (!info->data) { |
| 2277 | pr_err("unable to allocate memory for data, %d\n", onum); |
| 2278 | return 0; |
| 2279 | } |
| 2280 | |
| 2281 | of_fdt_unflatten_tree(info->data, NULL, &info->np_overlay); |
| 2282 | if (!info->np_overlay) { |
| 2283 | pr_err("unable to unflatten overlay, %d\n", onum); |
| 2284 | ret = 0; |
| 2285 | goto out_free_data; |
| 2286 | } |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2287 | |
Frank Rowand | 24789c5 | 2017-10-17 16:36:26 -0700 | [diff] [blame] | 2288 | info->overlay_id = 0; |
| 2289 | ret = of_overlay_apply(info->np_overlay, &info->overlay_id); |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2290 | if (ret < 0) { |
Frank Rowand | 0290c4c | 2017-10-17 16:36:23 -0700 | [diff] [blame] | 2291 | pr_err("of_overlay_apply() (ret=%d), %d\n", ret, onum); |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2292 | goto out_free_np_overlay; |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | pr_debug("__dtb_overlay_begin applied, overlay id %d\n", ret); |
| 2296 | |
| 2297 | goto out; |
| 2298 | |
| 2299 | out_free_np_overlay: |
| 2300 | /* |
| 2301 | * info->np_overlay is the unflattened device tree |
| 2302 | * It has not been spliced into the live tree. |
| 2303 | */ |
| 2304 | |
| 2305 | /* todo: function to free unflattened device tree */ |
| 2306 | |
| 2307 | out_free_data: |
| 2308 | kfree(info->data); |
| 2309 | |
| 2310 | out: |
| 2311 | return (ret == info->expected_result); |
| 2312 | } |
| 2313 | |
| 2314 | /* |
| 2315 | * The purpose of of_unittest_overlay_high_level is to add an overlay |
| 2316 | * in the normal fashion. This is a test of the whole picture, |
| 2317 | * instead of individual elements. |
| 2318 | * |
| 2319 | * The first part of the function is _not_ normal overlay usage; it is |
| 2320 | * finishing splicing the base overlay device tree into the live tree. |
| 2321 | */ |
| 2322 | static __init void of_unittest_overlay_high_level(void) |
| 2323 | { |
| 2324 | struct device_node *last_sibling; |
| 2325 | struct device_node *np; |
| 2326 | struct device_node *of_symbols; |
| 2327 | struct device_node *overlay_base_symbols; |
| 2328 | struct device_node **pprev; |
| 2329 | struct property *prop; |
| 2330 | int ret; |
| 2331 | |
| 2332 | if (!overlay_base_root) { |
| 2333 | unittest(0, "overlay_base_root not initialized\n"); |
| 2334 | return; |
| 2335 | } |
| 2336 | |
| 2337 | /* |
| 2338 | * Could not fixup phandles in unittest_unflatten_overlay_base() |
| 2339 | * because kmalloc() was not yet available. |
| 2340 | */ |
Frank Rowand | f948d6d | 2017-10-17 16:36:29 -0700 | [diff] [blame] | 2341 | of_overlay_mutex_lock(); |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2342 | of_resolve_phandles(overlay_base_root); |
Frank Rowand | f948d6d | 2017-10-17 16:36:29 -0700 | [diff] [blame] | 2343 | of_overlay_mutex_unlock(); |
| 2344 | |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2345 | |
| 2346 | /* |
| 2347 | * do not allow overlay_base to duplicate any node already in |
| 2348 | * tree, this greatly simplifies the code |
| 2349 | */ |
| 2350 | |
| 2351 | /* |
| 2352 | * remove overlay_base_root node "__local_fixups", after |
| 2353 | * being used by of_resolve_phandles() |
| 2354 | */ |
| 2355 | pprev = &overlay_base_root->child; |
| 2356 | for (np = overlay_base_root->child; np; np = np->sibling) { |
| 2357 | if (!of_node_cmp(np->name, "__local_fixups__")) { |
| 2358 | *pprev = np->sibling; |
| 2359 | break; |
| 2360 | } |
| 2361 | pprev = &np->sibling; |
| 2362 | } |
| 2363 | |
| 2364 | /* remove overlay_base_root node "__symbols__" if in live tree */ |
| 2365 | of_symbols = of_get_child_by_name(of_root, "__symbols__"); |
| 2366 | if (of_symbols) { |
| 2367 | /* will have to graft properties from node into live tree */ |
| 2368 | pprev = &overlay_base_root->child; |
| 2369 | for (np = overlay_base_root->child; np; np = np->sibling) { |
| 2370 | if (!of_node_cmp(np->name, "__symbols__")) { |
| 2371 | overlay_base_symbols = np; |
| 2372 | *pprev = np->sibling; |
| 2373 | break; |
| 2374 | } |
| 2375 | pprev = &np->sibling; |
| 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | for (np = overlay_base_root->child; np; np = np->sibling) { |
| 2380 | if (of_get_child_by_name(of_root, np->name)) { |
| 2381 | unittest(0, "illegal node name in overlay_base %s", |
| 2382 | np->name); |
| 2383 | return; |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | /* |
| 2388 | * overlay 'overlay_base' is not allowed to have root |
| 2389 | * properties, so only need to splice nodes into main device tree. |
| 2390 | * |
| 2391 | * root node of *overlay_base_root will not be freed, it is lost |
| 2392 | * memory. |
| 2393 | */ |
| 2394 | |
| 2395 | for (np = overlay_base_root->child; np; np = np->sibling) |
| 2396 | np->parent = of_root; |
| 2397 | |
| 2398 | mutex_lock(&of_mutex); |
| 2399 | |
Arnd Bergmann | ee320b3 | 2017-04-28 11:44:11 +0200 | [diff] [blame] | 2400 | for (last_sibling = np = of_root->child; np; np = np->sibling) |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2401 | last_sibling = np; |
| 2402 | |
| 2403 | if (last_sibling) |
| 2404 | last_sibling->sibling = overlay_base_root->child; |
| 2405 | else |
| 2406 | of_root->child = overlay_base_root->child; |
| 2407 | |
| 2408 | for_each_of_allnodes_from(overlay_base_root, np) |
| 2409 | __of_attach_node_sysfs(np); |
| 2410 | |
| 2411 | if (of_symbols) { |
| 2412 | for_each_property_of_node(overlay_base_symbols, prop) { |
| 2413 | ret = __of_add_property(of_symbols, prop); |
| 2414 | if (ret) { |
| 2415 | unittest(0, |
| 2416 | "duplicate property '%s' in overlay_base node __symbols__", |
| 2417 | prop->name); |
Dan Carpenter | 8756cd1 | 2017-05-03 22:49:50 +0300 | [diff] [blame] | 2418 | goto err_unlock; |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2419 | } |
| 2420 | ret = __of_add_property_sysfs(of_symbols, prop); |
| 2421 | if (ret) { |
| 2422 | unittest(0, |
| 2423 | "unable to add property '%s' in overlay_base node __symbols__ to sysfs", |
| 2424 | prop->name); |
Dan Carpenter | 8756cd1 | 2017-05-03 22:49:50 +0300 | [diff] [blame] | 2425 | goto err_unlock; |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | mutex_unlock(&of_mutex); |
| 2431 | |
| 2432 | |
| 2433 | /* now do the normal overlay usage test */ |
| 2434 | |
| 2435 | unittest(overlay_data_add(1), |
| 2436 | "Adding overlay 'overlay' failed\n"); |
| 2437 | |
| 2438 | unittest(overlay_data_add(2), |
| 2439 | "Adding overlay 'overlay_bad_phandle' failed\n"); |
Frank Rowand | 60a0004 | 2017-07-19 09:25:20 -0700 | [diff] [blame] | 2440 | |
| 2441 | unittest(overlay_data_add(3), |
| 2442 | "Adding overlay 'overlay_bad_symbol' failed\n"); |
| 2443 | |
Dan Carpenter | 8756cd1 | 2017-05-03 22:49:50 +0300 | [diff] [blame] | 2444 | return; |
| 2445 | |
| 2446 | err_unlock: |
| 2447 | mutex_unlock(&of_mutex); |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | #else |
| 2451 | |
| 2452 | static inline __init void of_unittest_overlay_high_level(void) {} |
| 2453 | |
| 2454 | #endif |
| 2455 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2456 | static int __init of_unittest(void) |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 2457 | { |
| 2458 | struct device_node *np; |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 2459 | int res; |
| 2460 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2461 | /* adding data for unittest */ |
| 2462 | res = unittest_data_add(); |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 2463 | if (res) |
| 2464 | return res; |
Grant Likely | 788ec2f | 2014-11-19 17:13:44 +0000 | [diff] [blame] | 2465 | if (!of_aliases) |
| 2466 | of_aliases = of_find_node_by_path("/aliases"); |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 2467 | |
| 2468 | np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); |
| 2469 | if (!np) { |
| 2470 | pr_info("No testcase data in device tree; not running tests\n"); |
| 2471 | return 0; |
| 2472 | } |
| 2473 | of_node_put(np); |
| 2474 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2475 | pr_info("start of unittest - you will see error messages\n"); |
| 2476 | of_unittest_check_tree_linkage(); |
| 2477 | of_unittest_check_phandles(); |
| 2478 | of_unittest_find_node_by_name(); |
| 2479 | of_unittest_dynamic(); |
| 2480 | of_unittest_parse_phandle_with_args(); |
Stephen Boyd | 357aa4b | 2018-01-30 18:36:17 -0800 | [diff] [blame^] | 2481 | of_unittest_parse_phandle_with_args_map(); |
Pantelis Antoniou | ce4fecf | 2015-01-21 19:06:14 +0200 | [diff] [blame] | 2482 | of_unittest_printf(); |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2483 | of_unittest_property_string(); |
| 2484 | of_unittest_property_copy(); |
| 2485 | of_unittest_changeset(); |
| 2486 | of_unittest_parse_interrupts(); |
| 2487 | of_unittest_parse_interrupts_extended(); |
| 2488 | of_unittest_match_node(); |
| 2489 | of_unittest_platform_populate(); |
| 2490 | of_unittest_overlay(); |
Gaurav Minocha | ae9304c | 2014-07-16 23:09:39 -0700 | [diff] [blame] | 2491 | |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 2492 | /* Double check linkage after removing testcase data */ |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2493 | of_unittest_check_tree_linkage(); |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 2494 | |
Frank Rowand | 81d0848f | 2017-04-25 17:09:54 -0700 | [diff] [blame] | 2495 | of_unittest_overlay_high_level(); |
| 2496 | |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2497 | pr_info("end of unittest - %i passed, %i failed\n", |
| 2498 | unittest_results.passed, unittest_results.failed); |
Grant Likely | f2051d6 | 2014-10-01 17:40:22 +0100 | [diff] [blame] | 2499 | |
Grant Likely | 53a4209 | 2011-12-12 09:25:57 -0700 | [diff] [blame] | 2500 | return 0; |
| 2501 | } |
Wang Long | 9697a55 | 2015-03-11 08:36:54 +0000 | [diff] [blame] | 2502 | late_initcall(of_unittest); |