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