^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Self tests for device tree subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #define pr_fmt(fmt) "### dt-test ### " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/dma-direct.h> /* to test phys_to_dma/dma_to_phys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/hashtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/libfdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/of_fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/of_irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/i2c-mux.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/gpio/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "of_private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static struct unittest_results {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int passed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) } unittest_results;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define unittest(result, fmt, ...) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) bool failed = !(result); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (failed) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) unittest_results.failed++; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) } else { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unittest_results.passed++; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) pr_debug("pass %s():%i\n", __func__, __LINE__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) failed; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * Expected message may have a message level other than KERN_INFO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Print the expected message only if the current loglevel will allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * the actual message to print.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Do not use EXPECT_BEGIN() or EXPECT_END() for messages generated by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * pr_debug().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define EXPECT_BEGIN(level, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) printk(level pr_fmt("EXPECT \\ : ") fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define EXPECT_END(level, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) printk(level pr_fmt("EXPECT / : ") fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static void __init of_unittest_find_node_by_name(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) const char *options, *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) np = of_find_node_by_path("/testcase-data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) name = kasprintf(GFP_KERNEL, "%pOF", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) unittest(np && !strcmp("/testcase-data", name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) "find /testcase-data failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* Test if trailing '/' works */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) np = of_find_node_by_path("/testcase-data/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unittest(!np, "trailing '/' on /testcase-data/ should fail\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) name = kasprintf(GFP_KERNEL, "%pOF", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) unittest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) "find /testcase-data/phandle-tests/consumer-a failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) np = of_find_node_by_path("testcase-alias");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) name = kasprintf(GFP_KERNEL, "%pOF", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) unittest(np && !strcmp("/testcase-data", name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) "find testcase-alias failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* Test if trailing '/' works on aliases */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) np = of_find_node_by_path("testcase-alias/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unittest(!np, "trailing '/' on testcase-alias/ should fail\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) name = kasprintf(GFP_KERNEL, "%pOF", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unittest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) "find testcase-alias/phandle-tests/consumer-a failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) np = of_find_node_by_path("/testcase-data/missing-path");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unittest(!np, "non-existent path returned node %pOF\n", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) np = of_find_node_by_path("missing-alias");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unittest(!np, "non-existent alias returned node %pOF\n", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) np = of_find_node_by_path("testcase-alias/missing-path");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) unittest(!np, "non-existent alias with relative path returned node %pOF\n", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) np = of_find_node_opts_by_path("/testcase-data:testoption", &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unittest(np && !strcmp("testoption", options),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) "option path test failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) np = of_find_node_opts_by_path("/testcase-data:test/option", &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) unittest(np && !strcmp("test/option", options),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) "option path test, subcase #1 failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) np = of_find_node_opts_by_path("/testcase-data/testcase-device1:test/option", &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unittest(np && !strcmp("test/option", options),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) "option path test, subcase #2 failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) np = of_find_node_opts_by_path("/testcase-data:testoption", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unittest(np, "NULL option path test failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) np = of_find_node_opts_by_path("testcase-alias:testaliasoption",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unittest(np && !strcmp("testaliasoption", options),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) "option alias path test failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) np = of_find_node_opts_by_path("testcase-alias:test/alias/option",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) unittest(np && !strcmp("test/alias/option", options),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) "option alias path test, subcase #1 failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) np = of_find_node_opts_by_path("testcase-alias:testaliasoption", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) unittest(np, "NULL option alias path test failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) options = "testoption";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) np = of_find_node_opts_by_path("testcase-alias", &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) unittest(np && !options, "option clearing test failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) options = "testoption";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) np = of_find_node_opts_by_path("/", &options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) unittest(np && !options, "option clearing root node test failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void __init of_unittest_dynamic(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) np = of_find_node_by_path("/testcase-data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* Array of 4 properties for the purpose of testing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) prop = kcalloc(4, sizeof(*prop), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (!prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) unittest(0, "kzalloc() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Add a new property - should pass*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) prop->name = "new-property";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) prop->value = "new-property-data";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) prop->length = strlen(prop->value) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) unittest(of_add_property(np, prop) == 0, "Adding a new property failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* Try to add an existing property - should fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) prop++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) prop->name = "new-property";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) prop->value = "new-property-data-should-fail";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) prop->length = strlen(prop->value) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) unittest(of_add_property(np, prop) != 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) "Adding an existing property should have failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* Try to modify an existing property - should pass */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) prop->value = "modify-property-data-should-pass";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) prop->length = strlen(prop->value) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) unittest(of_update_property(np, prop) == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) "Updating an existing property should have passed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Try to modify non-existent property - should pass*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) prop++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) prop->name = "modify-property";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) prop->value = "modify-missing-property-data-should-pass";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) prop->length = strlen(prop->value) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) unittest(of_update_property(np, prop) == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) "Updating a missing property should have passed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* Remove property - should pass */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) unittest(of_remove_property(np, prop) == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) "Removing a property should have passed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* Adding very large property - should pass */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) prop++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) prop->name = "large-property-PAGE_SIZEx8";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) prop->length = PAGE_SIZE * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) prop->value = kzalloc(prop->length, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) unittest(prop->value != NULL, "Unable to allocate large buffer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (prop->value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) unittest(of_add_property(np, prop) == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) "Adding a large property should have passed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static int __init of_unittest_check_node_linkage(struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct device_node *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int count = 0, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) for_each_child_of_node(np, child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (child->parent != np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) pr_err("Child node %pOFn links to wrong parent %pOFn\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) child, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) goto put_child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) rc = of_unittest_check_node_linkage(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) goto put_child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) count += rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return count + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) put_child:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static void __init of_unittest_check_tree_linkage(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int allnode_count = 0, child_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (!of_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) for_each_of_allnodes(np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) allnode_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) child_count = of_unittest_check_node_linkage(of_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) unittest(child_count > 0, "Device node data structure is corrupted\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) unittest(child_count == allnode_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) "allnodes list size (%i) doesn't match sibling lists size (%i)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) allnode_count, child_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count, child_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static void __init of_unittest_printf_one(struct device_node *np, const char *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) const char *expected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int size, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) buf_size = strlen(expected) + 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) buf = kmalloc(buf_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /* Baseline; check conversion with a large size limit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) memset(buf, 0xff, buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) size = snprintf(buf, buf_size - 2, fmt, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /* use strcmp() instead of strncmp() here to be absolutely sure strings match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) unittest((strcmp(buf, expected) == 0) && (buf[size+1] == 0xff),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) "sprintf failed; fmt='%s' expected='%s' rslt='%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) fmt, expected, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* Make sure length limits work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) for (i = 0; i < 2; i++, size--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* Clear the buffer, and make sure it works correctly still */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) memset(buf, 0xff, buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) snprintf(buf, size+1, fmt, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) unittest(strncmp(buf, expected, size) == 0 && (buf[size+1] == 0xff),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) "snprintf failed; size=%i fmt='%s' expected='%s' rslt='%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) size, fmt, expected, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static void __init of_unittest_printf(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) const char *full_name = "/testcase-data/platform-tests/test-device@1/dev@100";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) char phandle_str[16] = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) np = of_find_node_by_path(full_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) unittest(np, "testcase data missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) num_to_str(phandle_str, sizeof(phandle_str), np->phandle, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) of_unittest_printf_one(np, "%pOF", full_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) of_unittest_printf_one(np, "%pOFf", full_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) of_unittest_printf_one(np, "%pOFn", "dev");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) of_unittest_printf_one(np, "%2pOFn", "dev");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) of_unittest_printf_one(np, "%5pOFn", " dev");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) of_unittest_printf_one(np, "%pOFnc", "dev:test-sub-device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) of_unittest_printf_one(np, "%pOFp", phandle_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) of_unittest_printf_one(np, "%pOFP", "dev@100");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) of_unittest_printf_one(np, "ABC %pOFP ABC", "ABC dev@100 ABC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) of_unittest_printf_one(np, "%10pOFP", " dev@100");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) of_unittest_printf_one(np, "%-10pOFP", "dev@100 ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) of_unittest_printf_one(of_root, "%pOFP", "/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) of_unittest_printf_one(np, "%pOFF", "----");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) of_unittest_printf_one(np, "%pOFPF", "dev@100:----");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) of_unittest_printf_one(np, "%pOFPFPc", "dev@100:----:dev@100:test-sub-device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) of_unittest_printf_one(np, "%pOFc", "test-sub-device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) of_unittest_printf_one(np, "%pOFC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) "\"test-sub-device\",\"test-compat2\",\"test-compat3\"");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct node_hash {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct hlist_node node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static DEFINE_HASHTABLE(phandle_ht, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static void __init of_unittest_check_phandles(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct node_hash *nh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct hlist_node *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int i, dup_count = 0, phandle_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) for_each_of_allnodes(np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (!np->phandle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) hash_for_each_possible(phandle_ht, nh, node, np->phandle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (nh->np->phandle == np->phandle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) pr_info("Duplicate phandle! %i used by %pOF and %pOF\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) np->phandle, nh->np, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) dup_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) nh = kzalloc(sizeof(*nh), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (!nh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) nh->np = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) hash_add(phandle_ht, &nh->node, np->phandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) phandle_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) unittest(dup_count == 0, "Found %i duplicates in %i phandles\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) dup_count, phandle_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /* Clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) hash_for_each_safe(phandle_ht, i, tmp, nh, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) hash_del(&nh->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) kfree(nh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static void __init of_unittest_parse_phandle_with_args(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) struct of_phandle_args args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) int i, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) bool passed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) rc = of_parse_phandle_with_args(np, "phandle-list",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) "#phandle-cells", i, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /* Test the values from tests-phandle.dtsi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) switch (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) passed &= (args.args_count == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) passed &= (args.args[0] == (i + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) passed &= (args.args_count == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) passed &= (args.args[0] == (i + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) passed &= (args.args[1] == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) passed &= (rc == -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) passed &= (args.args_count == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) passed &= (args.args[0] == (i + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) passed &= (args.args[1] == 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) passed &= (args.args[2] == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) passed &= (args.args_count == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) passed &= (args.args[0] == (i + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) passed &= (args.args[1] == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) passed &= (args.args_count == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) passed &= (args.args_count == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) passed &= (args.args[0] == (i + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) passed &= (rc == -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) passed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) unittest(passed, "index %i - data error on node %pOF rc=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) i, args.np, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* Check for missing list property */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) rc = of_parse_phandle_with_args(np, "phandle-list-missing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) "#phandle-cells", 0, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) rc = of_count_phandle_with_args(np, "phandle-list-missing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) "#phandle-cells");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) /* Check for missing cells property */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) rc = of_parse_phandle_with_args(np, "phandle-list",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) "#phandle-cells-missing", 0, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) rc = of_count_phandle_with_args(np, "phandle-list",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) "#phandle-cells-missing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) "OF: /testcase-data/phandle-tests/consumer-a: could not get #phandle-cells-missing for /testcase-data/phandle-tests/provider1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) /* Check for bad phandle in list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) "#phandle-cells", 0, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) "#phandle-cells");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) "OF: /testcase-data/phandle-tests/consumer-a: could not find phandle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /* Check for incorrectly formed argument list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found -1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) "#phandle-cells", 1, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found -1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found -1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) rc = of_count_phandle_with_args(np, "phandle-list-bad-args",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) "#phandle-cells");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) "OF: /testcase-data/phandle-tests/consumer-a: #phandle-cells = 3 found -1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) static void __init of_unittest_parse_phandle_with_args_map(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) struct device_node *np, *p0, *p1, *p2, *p3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct of_phandle_args args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) int i, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-b");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) p0 = of_find_node_by_path("/testcase-data/phandle-tests/provider0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (!p0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) p1 = of_find_node_by_path("/testcase-data/phandle-tests/provider1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (!p1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) p2 = of_find_node_by_path("/testcase-data/phandle-tests/provider2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (!p2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) p3 = of_find_node_by_path("/testcase-data/phandle-tests/provider3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (!p3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) bool passed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) rc = of_parse_phandle_with_args_map(np, "phandle-list",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) "phandle", i, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) /* Test the values from tests-phandle.dtsi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) switch (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) passed &= (args.np == p1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) passed &= (args.args_count == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) passed &= (args.args[0] == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) passed &= (args.np == p3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) passed &= (args.args_count == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) passed &= (args.args[0] == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) passed &= (args.args[1] == 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) passed &= (args.args[2] == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) passed &= (rc == -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) passed &= (args.np == p0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) passed &= (args.args_count == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) passed &= (args.np == p1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) passed &= (args.args_count == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) passed &= (args.args[0] == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) passed &= (args.np == p0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) passed &= (args.args_count == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) passed &= (args.np == p2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) passed &= (args.args_count == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) passed &= (args.args[0] == 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) passed &= (args.args[1] == 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) passed &= (rc == -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) passed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) unittest(passed, "index %i - data error on node %s rc=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) i, args.np->full_name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /* Check for missing list property */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) rc = of_parse_phandle_with_args_map(np, "phandle-list-missing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) "phandle", 0, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) /* Check for missing cells,map,mask property */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) "OF: /testcase-data/phandle-tests/consumer-b: could not get #phandle-missing-cells for /testcase-data/phandle-tests/provider1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) rc = of_parse_phandle_with_args_map(np, "phandle-list",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) "phandle-missing", 0, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) "OF: /testcase-data/phandle-tests/consumer-b: could not get #phandle-missing-cells for /testcase-data/phandle-tests/provider1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) /* Check for bad phandle in list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) "phandle", 0, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) "OF: /testcase-data/phandle-tests/consumer-b: could not find phandle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* Check for incorrectly formed argument list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) "OF: /testcase-data/phandle-tests/consumer-b: #phandle-cells = 2 found -1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) "phandle", 1, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) "OF: /testcase-data/phandle-tests/consumer-b: #phandle-cells = 2 found -1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) static void __init of_unittest_property_string(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) const char *strings[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) pr_err("No testcase data in device tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) rc = of_property_match_string(np, "phandle-list-names", "first");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) unittest(rc == 0, "first expected:0 got:%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) rc = of_property_match_string(np, "phandle-list-names", "second");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) unittest(rc == 1, "second expected:1 got:%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) rc = of_property_match_string(np, "phandle-list-names", "third");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) unittest(rc == 2, "third expected:2 got:%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) rc = of_property_match_string(np, "phandle-list-names", "fourth");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) unittest(rc == -ENODATA, "unmatched string; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) rc = of_property_match_string(np, "missing-property", "blah");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) unittest(rc == -EINVAL, "missing property; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) rc = of_property_match_string(np, "empty-property", "blah");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) unittest(rc == -ENODATA, "empty property; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) rc = of_property_match_string(np, "unterminated-string", "blah");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) /* of_property_count_strings() tests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) rc = of_property_count_strings(np, "string-property");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) unittest(rc == 1, "Incorrect string count; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) rc = of_property_count_strings(np, "phandle-list-names");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) unittest(rc == 3, "Incorrect string count; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) rc = of_property_count_strings(np, "unterminated-string");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) rc = of_property_count_strings(np, "unterminated-string-list");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) /* of_property_read_string_index() tests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) rc = of_property_read_string_index(np, "string-property", 0, strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) unittest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) strings[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) rc = of_property_read_string_index(np, "string-property", 1, strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) rc = of_property_read_string_index(np, "phandle-list-names", 0, strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) unittest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) rc = of_property_read_string_index(np, "phandle-list-names", 1, strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) unittest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) rc = of_property_read_string_index(np, "phandle-list-names", 2, strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) unittest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) strings[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) rc = of_property_read_string_index(np, "phandle-list-names", 3, strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) unittest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) strings[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) rc = of_property_read_string_index(np, "unterminated-string", 0, strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) unittest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) strings[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) unittest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) strings[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) /* of_property_read_string_array() tests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) rc = of_property_read_string_array(np, "string-property", strings, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) unittest(rc == 1, "Incorrect string count; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) rc = of_property_read_string_array(np, "phandle-list-names", strings, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) unittest(rc == 3, "Incorrect string count; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) rc = of_property_read_string_array(np, "unterminated-string", strings, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) unittest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) /* -- An incorrectly formed string should cause a failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) unittest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) /* -- parsing the correctly formed strings should still work: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) strings[2] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) unittest(rc == 2 && strings[2] == NULL, "of_property_read_string_array() failure; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) strings[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) rc = of_property_read_string_array(np, "phandle-list-names", strings, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) unittest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) (p1)->value && (p2)->value && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) !memcmp((p1)->value, (p2)->value, (p1)->length) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) !strcmp((p1)->name, (p2)->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) static void __init of_unittest_property_copy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) #ifdef CONFIG_OF_DYNAMIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) struct property p1 = { .name = "p1", .length = 0, .value = "" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) struct property p2 = { .name = "p2", .length = 5, .value = "abcd" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) struct property *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) new = __of_prop_dup(&p1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) unittest(new && propcmp(&p1, new), "empty property didn't copy correctly\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) kfree(new->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) kfree(new->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) kfree(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) new = __of_prop_dup(&p2, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) unittest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) kfree(new->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) kfree(new->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) kfree(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) static void __init of_unittest_changeset(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) #ifdef CONFIG_OF_DYNAMIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) struct property *ppadd, padd = { .name = "prop-add", .length = 1, .value = "" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) struct property *ppname_n1, pname_n1 = { .name = "name", .length = 3, .value = "n1" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) struct property *ppname_n2, pname_n2 = { .name = "name", .length = 3, .value = "n2" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) struct property *ppname_n21, pname_n21 = { .name = "name", .length = 3, .value = "n21" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) struct property *ppupdate, pupdate = { .name = "prop-update", .length = 5, .value = "abcd" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) struct property *ppremove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) struct device_node *n1, *n2, *n21, *nchangeset, *nremove, *parent, *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) struct of_changeset chgset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) n1 = __of_node_dup(NULL, "n1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) unittest(n1, "testcase setup failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) n2 = __of_node_dup(NULL, "n2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) unittest(n2, "testcase setup failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) n21 = __of_node_dup(NULL, "n21");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) unittest(n21, "testcase setup failure %p\n", n21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) nchangeset = of_find_node_by_path("/testcase-data/changeset");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) nremove = of_get_child_by_name(nchangeset, "node-remove");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) unittest(nremove, "testcase setup failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) ppadd = __of_prop_dup(&padd, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) unittest(ppadd, "testcase setup failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) ppname_n1 = __of_prop_dup(&pname_n1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) unittest(ppname_n1, "testcase setup failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) ppname_n2 = __of_prop_dup(&pname_n2, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) unittest(ppname_n2, "testcase setup failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) ppname_n21 = __of_prop_dup(&pname_n21, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) unittest(ppname_n21, "testcase setup failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) ppupdate = __of_prop_dup(&pupdate, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) unittest(ppupdate, "testcase setup failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) parent = nchangeset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) n1->parent = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) n2->parent = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) n21->parent = n2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) ppremove = of_find_property(parent, "prop-remove", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) unittest(ppremove, "failed to find removal prop");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) of_changeset_init(&chgset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) unittest(!of_changeset_attach_node(&chgset, n1), "fail attach n1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) unittest(!of_changeset_add_property(&chgset, n1, ppname_n1), "fail add prop name\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) unittest(!of_changeset_attach_node(&chgset, n2), "fail attach n2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) unittest(!of_changeset_add_property(&chgset, n2, ppname_n2), "fail add prop name\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) unittest(!of_changeset_detach_node(&chgset, nremove), "fail remove node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) unittest(!of_changeset_add_property(&chgset, n21, ppname_n21), "fail add prop name\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) unittest(!of_changeset_attach_node(&chgset, n21), "fail attach n21\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) unittest(!of_changeset_add_property(&chgset, parent, ppadd), "fail add prop prop-add\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) unittest(!of_changeset_update_property(&chgset, parent, ppupdate), "fail update prop\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) unittest(!of_changeset_remove_property(&chgset, parent, ppremove), "fail remove prop\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) unittest(!of_changeset_apply(&chgset), "apply failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) of_node_put(nchangeset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) /* Make sure node names are constructed correctly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) unittest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) "'%pOF' not added\n", n21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) unittest(!of_changeset_revert(&chgset), "revert failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) of_changeset_destroy(&chgset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) of_node_put(n1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) of_node_put(n2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) of_node_put(n21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) static void __init of_unittest_dma_get_max_cpu_address(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) phys_addr_t cpu_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) if (!IS_ENABLED(CONFIG_OF_ADDRESS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) np = of_find_node_by_path("/testcase-data/address-tests");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) cpu_addr = of_dma_get_max_cpu_address(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) unittest(cpu_addr == 0x4fffffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) "of_dma_get_max_cpu_address: wrong CPU addr %pad (expecting %x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) &cpu_addr, 0x4fffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) static void __init of_unittest_dma_ranges_one(const char *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) u64 expect_dma_addr, u64 expect_paddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) #ifdef CONFIG_HAS_DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) const struct bus_dma_region *map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) np = of_find_node_by_path(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) rc = of_dma_get_range(np, &map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) unittest(!rc, "of_dma_get_range failed on node %pOF rc=%i\n", np, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) phys_addr_t paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) dma_addr_t dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) struct device *dev_bogus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) dev_bogus = kzalloc(sizeof(struct device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) if (!dev_bogus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) unittest(0, "kzalloc() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) kfree(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) dev_bogus->dma_range_map = map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) paddr = dma_to_phys(dev_bogus, expect_dma_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) dma_addr = phys_to_dma(dev_bogus, expect_paddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) unittest(paddr == expect_paddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) "of_dma_get_range: wrong phys addr %pap (expecting %llx) on node %pOF\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) &paddr, expect_paddr, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) unittest(dma_addr == expect_dma_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) "of_dma_get_range: wrong DMA addr %pad (expecting %llx) on node %pOF\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) &dma_addr, expect_dma_addr, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) kfree(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) kfree(dev_bogus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) static void __init of_unittest_parse_dma_ranges(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) of_unittest_dma_ranges_one("/testcase-data/address-tests/device@70000000",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) 0x0, 0x20000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) if (IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) of_unittest_dma_ranges_one("/testcase-data/address-tests/bus@80000000/device@1000",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) 0x100000000, 0x20000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) of_unittest_dma_ranges_one("/testcase-data/address-tests/pci@90000000",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) 0x80000000, 0x20000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) static void __init of_unittest_pci_dma_ranges(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) struct of_pci_range range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) struct of_pci_range_parser parser;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) if (!IS_ENABLED(CONFIG_PCI))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) np = of_find_node_by_path("/testcase-data/address-tests/pci@90000000");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (of_pci_dma_range_parser_init(&parser, np)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) pr_err("missing dma-ranges property\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) * Get the dma-ranges from the device tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) for_each_of_pci_range(&parser, &range) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) if (!i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) unittest(range.size == 0x10000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) "for_each_of_pci_range wrong size on node %pOF size=%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) np, range.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) unittest(range.cpu_addr == 0x20000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) "for_each_of_pci_range wrong CPU addr (%llx) on node %pOF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) range.cpu_addr, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) unittest(range.pci_addr == 0x80000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) "for_each_of_pci_range wrong DMA addr (%llx) on node %pOF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) range.pci_addr, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) unittest(range.size == 0x10000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) "for_each_of_pci_range wrong size on node %pOF size=%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) np, range.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) unittest(range.cpu_addr == 0x40000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) "for_each_of_pci_range wrong CPU addr (%llx) on node %pOF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) range.cpu_addr, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) unittest(range.pci_addr == 0xc0000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) "for_each_of_pci_range wrong DMA addr (%llx) on node %pOF",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) range.pci_addr, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static void __init of_unittest_parse_interrupts(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) struct of_phandle_args args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) int i, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) np = of_find_node_by_path("/testcase-data/interrupts/interrupts0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) bool passed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) rc = of_irq_parse_one(np, i, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) passed &= (args.args_count == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) passed &= (args.args[0] == (i + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) unittest(passed, "index %i - data error on node %pOF rc=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) i, args.np, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) np = of_find_node_by_path("/testcase-data/interrupts/interrupts1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) bool passed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) rc = of_irq_parse_one(np, i, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) /* Test the values from tests-phandle.dtsi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) switch (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) passed &= (args.args_count == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) passed &= (args.args[0] == 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) passed &= (args.args_count == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) passed &= (args.args[0] == 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) passed &= (args.args[1] == 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) passed &= (args.args[2] == 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) passed &= (args.args_count == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) passed &= (args.args[0] == 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) passed &= (args.args[1] == 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) passed &= (args.args_count == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) passed &= (args.args[0] == 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) passed &= (args.args[1] == 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) passed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) unittest(passed, "index %i - data error on node %pOF rc=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) i, args.np, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) static void __init of_unittest_parse_interrupts_extended(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) struct of_phandle_args args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) int i, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) np = of_find_node_by_path("/testcase-data/interrupts/interrupts-extended0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) pr_err("missing testcase data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) for (i = 0; i < 7; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) bool passed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) memset(&args, 0, sizeof(args));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) rc = of_irq_parse_one(np, i, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) /* Test the values from tests-phandle.dtsi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) switch (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) passed &= (args.args_count == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) passed &= (args.args[0] == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) passed &= (args.args_count == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) passed &= (args.args[0] == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) passed &= (args.args[1] == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) passed &= (args.args[2] == 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) passed &= (args.args_count == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) passed &= (args.args[0] == 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) passed &= (args.args[1] == 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) passed &= (args.args_count == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) passed &= (args.args[0] == 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) passed &= (args.args_count == 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) passed &= (args.args[0] == 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) passed &= (args.args[1] == 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) passed &= (args.args[2] == 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) passed &= (args.args_count == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) passed &= (args.args[0] == 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) passed &= (args.args[1] == 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) passed &= !rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) passed &= (args.args_count == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) passed &= (args.args[0] == 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) passed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) unittest(passed, "index %i - data error on node %pOF rc=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) i, args.np, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) static const struct of_device_id match_node_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) { .data = "A", .name = "name0", }, /* Name alone is lowest priority */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) { .data = "B", .type = "type1", }, /* followed by type alone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) { .data = "Cc", .name = "name2", .type = "type2", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) { .data = "E", .compatible = "compat3" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) { .data = "G", .compatible = "compat2", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) { .data = "H", .compatible = "compat2", .name = "name5", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) { .data = "I", .compatible = "compat2", .type = "type1", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) { .data = "K", .compatible = "compat2", .name = "name9", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) const char *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) const char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) } match_node_tests[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) { .path = "/testcase-data/match-node/name0", .data = "A", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) { .path = "/testcase-data/match-node/name1", .data = "B", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) { .path = "/testcase-data/match-node/a/name2", .data = "Ca", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) { .path = "/testcase-data/match-node/b/name2", .data = "Cb", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) { .path = "/testcase-data/match-node/c/name2", .data = "Cc", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) { .path = "/testcase-data/match-node/name3", .data = "E", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) { .path = "/testcase-data/match-node/name4", .data = "G", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) { .path = "/testcase-data/match-node/name5", .data = "H", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) { .path = "/testcase-data/match-node/name6", .data = "G", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) { .path = "/testcase-data/match-node/name7", .data = "I", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) { .path = "/testcase-data/match-node/name8", .data = "J", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) { .path = "/testcase-data/match-node/name9", .data = "K", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) static void __init of_unittest_match_node(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) const struct of_device_id *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) np = of_find_node_by_path(match_node_tests[i].path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) unittest(0, "missing testcase node %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) match_node_tests[i].path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) match = of_match_node(match_node_table, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) if (!match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) unittest(0, "%s didn't match anything\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) match_node_tests[i].path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) if (strcmp(match->data, match_node_tests[i].data) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) unittest(0, "%s got wrong match. expected %s, got %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) match_node_tests[i].path, match_node_tests[i].data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) (const char *)match->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) unittest(1, "passed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) static struct resource test_bus_res = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) .start = 0xfffffff8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) .end = 0xfffffff9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) .flags = IORESOURCE_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) static const struct platform_device_info test_bus_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) .name = "unittest-bus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) static void __init of_unittest_platform_populate(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) int irq, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) struct device_node *np, *child, *grandchild;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) struct platform_device *pdev, *test_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) const struct of_device_id match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) { .compatible = "test-device", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) np = of_find_node_by_path("/testcase-data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) of_platform_default_populate(np, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) /* Test that a missing irq domain returns -EPROBE_DEFER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) np = of_find_node_by_path("/testcase-data/testcase-device1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) pdev = of_find_device_by_node(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) unittest(pdev, "device 1 creation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) if (!(of_irq_workarounds & OF_IMAP_OLDWORLD_MAC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) unittest(irq == -EPROBE_DEFER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) "device deferred probe failed - %d\n", irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) /* Test that a parsing failure does not return -EPROBE_DEFER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) np = of_find_node_by_path("/testcase-data/testcase-device2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) pdev = of_find_device_by_node(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) unittest(pdev, "device 2 creation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) "platform testcase-data:testcase-device2: IRQ index 0 not found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) "platform testcase-data:testcase-device2: IRQ index 0 not found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) unittest(irq < 0 && irq != -EPROBE_DEFER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) "device parsing error failed - %d\n", irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) np = of_find_node_by_path("/testcase-data/platform-tests");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) unittest(np, "No testcase data in device tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) test_bus = platform_device_register_full(&test_bus_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) rc = PTR_ERR_OR_ZERO(test_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) unittest(!rc, "testbus registration failed; rc=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) test_bus->dev.of_node = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) * Add a dummy resource to the test bus node after it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) * registered to catch problems with un-inserted resources. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) * DT code doesn't insert the resources, and it has caused the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) * kernel to oops in the past. This makes sure the same bug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) * doesn't crop up again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) platform_device_add_resources(test_bus, &test_bus_res, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) of_platform_populate(np, match, NULL, &test_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) for_each_child_of_node(np, child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) for_each_child_of_node(child, grandchild) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) pdev = of_find_device_by_node(grandchild);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) unittest(pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) "Could not create device for node '%pOFn'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) grandchild);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) of_dev_put(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) of_platform_depopulate(&test_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) for_each_child_of_node(np, child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) for_each_child_of_node(child, grandchild)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) unittest(!of_find_device_by_node(grandchild),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) "device didn't get destroyed '%pOFn'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) grandchild);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) platform_device_unregister(test_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) * update_node_properties - adds the properties
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) * of np into dup node (present in live tree) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) * updates parent of children of np to dup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) * @np: node whose properties are being added to the live tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) * @dup: node present in live tree to be updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) static void update_node_properties(struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) struct device_node *dup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) struct property *save_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) struct device_node *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) for_each_child_of_node(np, child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) child->parent = dup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) * "unittest internal error: unable to add testdata property"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) * If this message reports a property in node '/__symbols__' then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) * the respective unittest overlay contains a label that has the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) * same name as a label in the live devicetree. The label will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) * be in the live devicetree only if the devicetree source was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) * compiled with the '-@' option. If you encounter this error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) * please consider renaming __all__ of the labels in the unittest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) * overlay dts files with an odd prefix that is unlikely to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) * used in a real devicetree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) * open code for_each_property_of_node() because of_add_property()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) * sets prop->next to NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) for (prop = np->properties; prop != NULL; prop = save_next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) save_next = prop->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) ret = of_add_property(dup, prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) if (ret == -EEXIST && !strcmp(prop->name, "name"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) pr_err("unittest internal error: unable to add testdata property %pOF/%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) np, prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) * attach_node_and_children - attaches nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) * and its children to live tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) * CAUTION: misleading function name - if node @np already exists in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) * the live tree then children of @np are *not* attached to the live
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) * tree. This works for the current test devicetree nodes because such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) * nodes do not have child nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) * @np: Node to attach to live tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) static void attach_node_and_children(struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) struct device_node *next, *dup, *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) const char *full_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) full_name = kasprintf(GFP_KERNEL, "%pOF", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (!strcmp(full_name, "/__local_fixups__") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) !strcmp(full_name, "/__fixups__")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) kfree(full_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) dup = of_find_node_by_path(full_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) kfree(full_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) if (dup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) update_node_properties(np, dup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) child = np->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) np->child = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) mutex_lock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) raw_spin_lock_irqsave(&devtree_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) np->sibling = np->parent->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) np->parent->child = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) of_node_clear_flag(np, OF_DETACHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) raw_spin_unlock_irqrestore(&devtree_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) __of_attach_node_sysfs(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) mutex_unlock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) while (child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) next = child->sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) attach_node_and_children(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) child = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) * unittest_data_add - Reads, copies data from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) * linked tree and attaches it to the live tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) static int __init unittest_data_add(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) void *unittest_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) struct device_node *unittest_data_node, *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) * __dtb_testcases_begin[] and __dtb_testcases_end[] are magically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) * created by cmd_dt_S_dtb in scripts/Makefile.lib
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) extern uint8_t __dtb_testcases_begin[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) extern uint8_t __dtb_testcases_end[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) const int size = __dtb_testcases_end - __dtb_testcases_begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) if (!size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) pr_warn("%s: No testcase data to attach; not running tests\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) /* creating copy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) unittest_data = kmemdup(__dtb_testcases_begin, size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) if (!unittest_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) of_fdt_unflatten_tree(unittest_data, NULL, &unittest_data_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) if (!unittest_data_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) pr_warn("%s: No tree to attach; not running tests\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) kfree(unittest_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) * This lock normally encloses of_resolve_phandles()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) of_overlay_mutex_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) rc = of_resolve_phandles(unittest_data_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) of_overlay_mutex_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) if (!of_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) of_root = unittest_data_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) for_each_of_allnodes(np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) __of_attach_node_sysfs(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) of_aliases = of_find_node_by_path("/aliases");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) of_chosen = of_find_node_by_path("/chosen");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) of_overlay_mutex_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) /* attach the sub-tree to live tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) np = unittest_data_node->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) while (np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) struct device_node *next = np->sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) np->parent = of_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) attach_node_and_children(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) np = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) "Duplicate name in testcase-data, renamed to \"duplicate-name#1\"");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) of_overlay_mutex_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) #ifdef CONFIG_OF_OVERLAY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) static int __init overlay_data_apply(const char *overlay_name, int *overlay_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) static int unittest_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) if (np == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) dev_err(dev, "No OF data for device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) of_platform_populate(np, NULL, NULL, &pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) static int unittest_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) static const struct of_device_id unittest_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) { .compatible = "unittest", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) static struct platform_driver unittest_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) .probe = unittest_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) .remove = unittest_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) .name = "unittest",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) .of_match_table = of_match_ptr(unittest_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) /* get the platform device instantiated at the path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) static struct platform_device *of_path_to_platform_device(const char *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) np = of_find_node_by_path(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) if (np == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) pdev = of_find_device_by_node(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) return pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) /* find out if a platform device exists at that path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) static int of_path_platform_device_exists(const char *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) pdev = of_path_to_platform_device(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) platform_device_put(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) return pdev != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) #ifdef CONFIG_OF_GPIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) struct unittest_gpio_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) struct gpio_chip chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) static int unittest_gpio_chip_request_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) static int unittest_gpio_probe_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) static int unittest_gpio_probe_pass_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) static int unittest_gpio_chip_request(struct gpio_chip *chip, unsigned int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) unittest_gpio_chip_request_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) pr_debug("%s(): %s %d %d\n", __func__, chip->label, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) unittest_gpio_chip_request_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) static int unittest_gpio_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) struct unittest_gpio_dev *devptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) unittest_gpio_probe_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) devptr = kzalloc(sizeof(*devptr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) if (!devptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) platform_set_drvdata(pdev, devptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) devptr->chip.of_node = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) devptr->chip.label = "of-unittest-gpio";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) devptr->chip.base = -1; /* dynamic allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) devptr->chip.ngpio = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) devptr->chip.request = unittest_gpio_chip_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) ret = gpiochip_add_data(&devptr->chip, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) unittest(!ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) "gpiochip_add_data() for node @%pOF failed, ret = %d\n", devptr->chip.of_node, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) unittest_gpio_probe_pass_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) static int unittest_gpio_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) struct unittest_gpio_dev *gdev = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) if (!gdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) if (gdev->chip.base != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) gpiochip_remove(&gdev->chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) platform_set_drvdata(pdev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) kfree(gdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) static const struct of_device_id unittest_gpio_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) { .compatible = "unittest-gpio", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) static struct platform_driver unittest_gpio_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) .probe = unittest_gpio_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) .remove = unittest_gpio_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) .name = "unittest-gpio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) .of_match_table = of_match_ptr(unittest_gpio_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) static void __init of_unittest_overlay_gpio(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) int chip_request_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) int probe_pass_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) * tests: apply overlays before registering driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) * Similar to installing a driver as a module, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) * driver is registered after applying the overlays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) * The overlays are applied by overlay_data_apply()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) * instead of of_unittest_apply_overlay() so that they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) * will not be tracked. Thus they will not be removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) * by of_unittest_destroy_tracked_overlays().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) * - apply overlay_gpio_01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) * - apply overlay_gpio_02a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) * - apply overlay_gpio_02b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) * - register driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) * register driver will result in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) * - probe and processing gpio hog for overlay_gpio_01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) * - probe for overlay_gpio_02a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) * - processing gpio for overlay_gpio_02b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) probe_pass_count = unittest_gpio_probe_pass_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) chip_request_count = unittest_gpio_chip_request_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) * overlay_gpio_01 contains gpio node and child gpio hog node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) * overlay_gpio_02a contains gpio node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) * overlay_gpio_02b contains child gpio hog node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) unittest(overlay_data_apply("overlay_gpio_01", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) "Adding overlay 'overlay_gpio_01' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) unittest(overlay_data_apply("overlay_gpio_02a", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) "Adding overlay 'overlay_gpio_02a' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) unittest(overlay_data_apply("overlay_gpio_02b", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) "Adding overlay 'overlay_gpio_02b' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) * messages are the result of the probes, after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) * driver is registered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) "gpio-<<int>> (line-B-input): hogged as input\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) "gpio-<<int>> (line-A-input): hogged as input\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) ret = platform_driver_register(&unittest_gpio_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) if (unittest(ret == 0, "could not register unittest gpio driver\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) "gpio-<<int>> (line-A-input): hogged as input\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) "gpio-<<int>> (line-B-input): hogged as input\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) unittest(probe_pass_count + 2 == unittest_gpio_probe_pass_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) "unittest_gpio_probe() failed or not called\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) unittest(chip_request_count + 2 == unittest_gpio_chip_request_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) "unittest_gpio_chip_request() called %d times (expected 1 time)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) unittest_gpio_chip_request_count - chip_request_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) * tests: apply overlays after registering driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) * Similar to a driver built-in to the kernel, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) * driver is registered before applying the overlays.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) * overlay_gpio_03 contains gpio node and child gpio hog node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) * - apply overlay_gpio_03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) * apply overlay will result in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) * - probe and processing gpio hog.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) probe_pass_count = unittest_gpio_probe_pass_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) chip_request_count = unittest_gpio_chip_request_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) "gpio-<<int>> (line-D-input): hogged as input\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) /* overlay_gpio_03 contains gpio node and child gpio hog node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) unittest(overlay_data_apply("overlay_gpio_03", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) "Adding overlay 'overlay_gpio_03' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) "gpio-<<int>> (line-D-input): hogged as input\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) unittest(probe_pass_count + 1 == unittest_gpio_probe_pass_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) "unittest_gpio_probe() failed or not called\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) unittest(chip_request_count + 1 == unittest_gpio_chip_request_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) "unittest_gpio_chip_request() called %d times (expected 1 time)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) unittest_gpio_chip_request_count - chip_request_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) * overlay_gpio_04a contains gpio node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) * - apply overlay_gpio_04a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) * apply the overlay will result in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) * - probe for overlay_gpio_04a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) probe_pass_count = unittest_gpio_probe_pass_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) chip_request_count = unittest_gpio_chip_request_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) /* overlay_gpio_04a contains gpio node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) unittest(overlay_data_apply("overlay_gpio_04a", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) "Adding overlay 'overlay_gpio_04a' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) unittest(probe_pass_count + 1 == unittest_gpio_probe_pass_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) "unittest_gpio_probe() failed or not called\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) * overlay_gpio_04b contains child gpio hog node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) * - apply overlay_gpio_04b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) * apply the overlay will result in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) * - processing gpio for overlay_gpio_04b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) "gpio-<<int>> (line-C-input): hogged as input\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) /* overlay_gpio_04b contains child gpio hog node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) unittest(overlay_data_apply("overlay_gpio_04b", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) "Adding overlay 'overlay_gpio_04b' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) "gpio-<<int>> (line-C-input): hogged as input\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) unittest(chip_request_count + 1 == unittest_gpio_chip_request_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) "unittest_gpio_chip_request() called %d times (expected 1 time)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) unittest_gpio_chip_request_count - chip_request_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) static void __init of_unittest_overlay_gpio(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) /* skip tests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) #if IS_BUILTIN(CONFIG_I2C)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) /* get the i2c client device instantiated at the path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) static struct i2c_client *of_path_to_i2c_client(const char *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) np = of_find_node_by_path(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) if (np == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) client = of_find_i2c_device_by_node(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) return client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) /* find out if a i2c client device exists at that path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) static int of_path_i2c_client_exists(const char *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) client = of_path_to_i2c_client(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) if (client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) put_device(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) return client != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) static int of_path_i2c_client_exists(const char *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) enum overlay_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) PDEV_OVERLAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) I2C_OVERLAY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) static int of_path_device_type_exists(const char *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) enum overlay_type ovtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) switch (ovtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) case PDEV_OVERLAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) return of_path_platform_device_exists(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) case I2C_OVERLAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) return of_path_i2c_client_exists(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) static const char *unittest_path(int nr, enum overlay_type ovtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) const char *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) static char buf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) switch (ovtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) case PDEV_OVERLAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) base = "/testcase-data/overlay-node/test-bus";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) case I2C_OVERLAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) base = "/testcase-data/overlay-node/test-bus/i2c-test-bus";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) buf[0] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) snprintf(buf, sizeof(buf) - 1, "%s/test-unittest%d", base, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) buf[sizeof(buf) - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) static int of_unittest_device_exists(int unittest_nr, enum overlay_type ovtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) const char *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) path = unittest_path(unittest_nr, ovtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) switch (ovtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) case PDEV_OVERLAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) return of_path_platform_device_exists(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) case I2C_OVERLAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) return of_path_i2c_client_exists(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) static const char *overlay_name_from_nr(int nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) static char buf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) snprintf(buf, sizeof(buf) - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) "overlay_%d", nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) buf[sizeof(buf) - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) static const char *bus_path = "/testcase-data/overlay-node/test-bus";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) /* FIXME: it is NOT guaranteed that overlay ids are assigned in sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) #define MAX_UNITTEST_OVERLAYS 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) static unsigned long overlay_id_bits[BITS_TO_LONGS(MAX_UNITTEST_OVERLAYS)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) static int overlay_first_id = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) static long of_unittest_overlay_tracked(int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) if (WARN_ON(id >= MAX_UNITTEST_OVERLAYS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) return overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) static void of_unittest_track_overlay(int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) if (overlay_first_id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) overlay_first_id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) id -= overlay_first_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) if (WARN_ON(id >= MAX_UNITTEST_OVERLAYS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) overlay_id_bits[BIT_WORD(id)] |= BIT_MASK(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) static void of_unittest_untrack_overlay(int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) if (overlay_first_id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) id -= overlay_first_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) if (WARN_ON(id >= MAX_UNITTEST_OVERLAYS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) static void of_unittest_destroy_tracked_overlays(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) int id, ret, defers, ovcs_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) if (overlay_first_id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) /* try until no defers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) defers = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) /* remove in reverse order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) for (id = MAX_UNITTEST_OVERLAYS - 1; id >= 0; id--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) if (!of_unittest_overlay_tracked(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) ovcs_id = id + overlay_first_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) ret = of_overlay_remove(&ovcs_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) if (ret == -ENODEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) pr_warn("%s: no overlay to destroy for #%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) __func__, id + overlay_first_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) defers++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) pr_warn("%s: overlay destroy failed for #%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) __func__, id + overlay_first_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) of_unittest_untrack_overlay(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) } while (defers > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) static int __init of_unittest_apply_overlay(int overlay_nr, int *overlay_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) const char *overlay_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) overlay_name = overlay_name_from_nr(overlay_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) if (!overlay_data_apply(overlay_name, overlay_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) unittest(0, "could not apply overlay \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) overlay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) of_unittest_track_overlay(*overlay_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) /* apply an overlay while checking before and after states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) static int __init of_unittest_apply_overlay_check(int overlay_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) int unittest_nr, int before, int after,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) enum overlay_type ovtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) int ret, ovcs_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) /* unittest device must not be in before state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) unittest(0, "%s with device @\"%s\" %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) overlay_name_from_nr(overlay_nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) unittest_path(unittest_nr, ovtype),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) !before ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) ovcs_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) /* of_unittest_apply_overlay already called unittest() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) /* unittest device must be to set to after state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) unittest(0, "%s failed to create @\"%s\" %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) overlay_name_from_nr(overlay_nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) unittest_path(unittest_nr, ovtype),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) !after ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) /* apply an overlay and then revert it while checking before, after states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) static int __init of_unittest_apply_revert_overlay_check(int overlay_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) int unittest_nr, int before, int after,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) enum overlay_type ovtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) int ret, ovcs_id, save_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) /* unittest device must be in before state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) if (of_unittest_device_exists(unittest_nr, ovtype) != before) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) unittest(0, "%s with device @\"%s\" %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) overlay_name_from_nr(overlay_nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) unittest_path(unittest_nr, ovtype),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) !before ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) /* apply the overlay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) ovcs_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) /* of_unittest_apply_overlay already called unittest() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) /* unittest device must be in after state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) if (of_unittest_device_exists(unittest_nr, ovtype) != after) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) unittest(0, "%s failed to create @\"%s\" %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) overlay_name_from_nr(overlay_nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) unittest_path(unittest_nr, ovtype),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) !after ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) save_id = ovcs_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) ret = of_overlay_remove(&ovcs_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) unittest(0, "%s failed to be destroyed @\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) overlay_name_from_nr(overlay_nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) unittest_path(unittest_nr, ovtype));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) of_unittest_untrack_overlay(save_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) /* unittest device must be again in before state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) if (of_unittest_device_exists(unittest_nr, PDEV_OVERLAY) != before) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) unittest(0, "%s with device @\"%s\" %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) overlay_name_from_nr(overlay_nr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) unittest_path(unittest_nr, ovtype),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) !before ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) /* test activation of device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) static void __init of_unittest_overlay_0(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest0/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) /* device should enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) ret = of_unittest_apply_overlay_check(0, 0, 0, 1, PDEV_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest0/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) unittest(1, "overlay test %d passed\n", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) /* test deactivation of device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) static void __init of_unittest_overlay_1(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest1/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) /* device should disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) ret = of_unittest_apply_overlay_check(1, 1, 1, 0, PDEV_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest1/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) unittest(1, "overlay test %d passed\n", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) /* test activation of device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) static void __init of_unittest_overlay_2(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest2/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) /* device should enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) ret = of_unittest_apply_overlay_check(2, 2, 0, 1, PDEV_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest2/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) unittest(1, "overlay test %d passed\n", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) /* test deactivation of device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) static void __init of_unittest_overlay_3(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest3/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) /* device should disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) ret = of_unittest_apply_overlay_check(3, 3, 1, 0, PDEV_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest3/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) unittest(1, "overlay test %d passed\n", 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) /* test activation of a full device node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) static void __init of_unittest_overlay_4(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) /* device should disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) if (of_unittest_apply_overlay_check(4, 4, 0, 1, PDEV_OVERLAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) unittest(1, "overlay test %d passed\n", 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) /* test overlay apply/revert sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) static void __init of_unittest_overlay_5(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest5/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) /* device should disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) ret = of_unittest_apply_revert_overlay_check(5, 5, 0, 1, PDEV_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest5/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) unittest(1, "overlay test %d passed\n", 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) /* test overlay application in sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) static void __init of_unittest_overlay_6(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) int i, ov_id[2], ovcs_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) int overlay_nr = 6, unittest_nr = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) int before = 0, after = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) const char *overlay_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) /* unittest device must be in before state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) != before) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) unittest(0, "%s with device @\"%s\" %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) overlay_name_from_nr(overlay_nr + i),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) unittest_path(unittest_nr + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) PDEV_OVERLAY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) !before ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) /* apply the overlays */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest6/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) overlay_name = overlay_name_from_nr(overlay_nr + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) ret = overlay_data_apply(overlay_name, &ovcs_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) ov_id[0] = ovcs_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) of_unittest_track_overlay(ov_id[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest6/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest7/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) overlay_name = overlay_name_from_nr(overlay_nr + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) ret = overlay_data_apply(overlay_name, &ovcs_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) ov_id[1] = ovcs_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) of_unittest_track_overlay(ov_id[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest7/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) /* unittest device must be in after state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) != after) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) unittest(0, "overlay @\"%s\" failed @\"%s\" %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) overlay_name_from_nr(overlay_nr + i),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) unittest_path(unittest_nr + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) PDEV_OVERLAY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) !after ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) for (i = 1; i >= 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) ovcs_id = ov_id[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) if (of_overlay_remove(&ovcs_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) unittest(0, "%s failed destroy @\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) overlay_name_from_nr(overlay_nr + i),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) unittest_path(unittest_nr + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) PDEV_OVERLAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) of_unittest_untrack_overlay(ov_id[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) /* unittest device must be again in before state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) if (of_unittest_device_exists(unittest_nr + i, PDEV_OVERLAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) != before) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) unittest(0, "%s with device @\"%s\" %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) overlay_name_from_nr(overlay_nr + i),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) unittest_path(unittest_nr + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) PDEV_OVERLAY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) !before ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) unittest(1, "overlay test %d passed\n", 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) /* test overlay application in sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) static void __init of_unittest_overlay_8(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) int i, ov_id[2], ovcs_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) int overlay_nr = 8, unittest_nr = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) const char *overlay_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) /* we don't care about device state in this test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) overlay_name = overlay_name_from_nr(overlay_nr + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) ret = overlay_data_apply(overlay_name, &ovcs_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) ov_id[0] = ovcs_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) of_unittest_track_overlay(ov_id[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) overlay_name = overlay_name_from_nr(overlay_nr + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/property-foo");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) /* apply the overlays */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) ret = overlay_data_apply(overlay_name, &ovcs_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/test-unittest8/property-foo");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) unittest(0, "could not apply overlay \"%s\"\n", overlay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) ov_id[1] = ovcs_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) of_unittest_track_overlay(ov_id[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) /* now try to remove first overlay (it should fail) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) ovcs_id = ov_id[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) "OF: overlay: node_overlaps_later_cs: #6 overlaps with #7 @/testcase-data/overlay-node/test-bus/test-unittest8");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) "OF: overlay: overlay #6 is not topmost");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) ret = of_overlay_remove(&ovcs_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) "OF: overlay: overlay #6 is not topmost");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) "OF: overlay: node_overlaps_later_cs: #6 overlaps with #7 @/testcase-data/overlay-node/test-bus/test-unittest8");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) unittest(0, "%s was destroyed @\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) overlay_name_from_nr(overlay_nr + 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) unittest_path(unittest_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) PDEV_OVERLAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) /* removing them in order should work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) for (i = 1; i >= 0; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) ovcs_id = ov_id[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) if (of_overlay_remove(&ovcs_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) unittest(0, "%s not destroyed @\"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) overlay_name_from_nr(overlay_nr + i),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) unittest_path(unittest_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) PDEV_OVERLAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) of_unittest_untrack_overlay(ov_id[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) unittest(1, "overlay test %d passed\n", 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) /* test insertion of a bus with parent devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) static void __init of_unittest_overlay_10(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) char *child_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) /* device should disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) ret = of_unittest_apply_overlay_check(10, 10, 0, 1, PDEV_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) if (unittest(ret == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) "overlay test %d failed; overlay application\n", 10))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) child_path = kasprintf(GFP_KERNEL, "%s/test-unittest101",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) unittest_path(10, PDEV_OVERLAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) if (unittest(child_path, "overlay test %d failed; kasprintf\n", 10))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) ret = of_path_device_type_exists(child_path, PDEV_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) kfree(child_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) unittest(ret, "overlay test %d failed; no child device\n", 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) /* test insertion of a bus with parent devices (and revert) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) static void __init of_unittest_overlay_11(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) /* device should disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) ret = of_unittest_apply_revert_overlay_check(11, 11, 0, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) PDEV_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) unittest(ret == 0, "overlay test %d failed; overlay apply\n", 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) #if IS_BUILTIN(CONFIG_I2C) && IS_ENABLED(CONFIG_OF_OVERLAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) struct unittest_i2c_bus_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) struct i2c_adapter adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) static int unittest_i2c_master_xfer(struct i2c_adapter *adap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) struct i2c_msg *msgs, int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) struct unittest_i2c_bus_data *std = i2c_get_adapdata(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) (void)std;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) static u32 unittest_i2c_functionality(struct i2c_adapter *adap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) static const struct i2c_algorithm unittest_i2c_algo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) .master_xfer = unittest_i2c_master_xfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) .functionality = unittest_i2c_functionality,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) static int unittest_i2c_bus_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) struct unittest_i2c_bus_data *std;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) struct i2c_adapter *adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) if (np == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) dev_err(dev, "No OF data for device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) std = devm_kzalloc(dev, sizeof(*std), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) if (!std)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) /* link them together */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) std->pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) platform_set_drvdata(pdev, std);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) adap = &std->adap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) i2c_set_adapdata(adap, std);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) adap->nr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) strlcpy(adap->name, pdev->name, sizeof(adap->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) adap->class = I2C_CLASS_DEPRECATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) adap->algo = &unittest_i2c_algo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) adap->dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) adap->dev.of_node = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) adap->timeout = 5 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) adap->retries = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) ret = i2c_add_numbered_adapter(adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) dev_err(dev, "Failed to add I2C adapter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) static int unittest_i2c_bus_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) struct unittest_i2c_bus_data *std = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) i2c_del_adapter(&std->adap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) static const struct of_device_id unittest_i2c_bus_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) { .compatible = "unittest-i2c-bus", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) static struct platform_driver unittest_i2c_bus_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) .probe = unittest_i2c_bus_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) .remove = unittest_i2c_bus_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) .name = "unittest-i2c-bus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) .of_match_table = of_match_ptr(unittest_i2c_bus_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) static int unittest_i2c_dev_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) struct device_node *np = client->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) dev_err(dev, "No OF node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) static int unittest_i2c_dev_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) struct device_node *np = client->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) static const struct i2c_device_id unittest_i2c_dev_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) { .name = "unittest-i2c-dev" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) static struct i2c_driver unittest_i2c_dev_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) .name = "unittest-i2c-dev",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) .probe = unittest_i2c_dev_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) .remove = unittest_i2c_dev_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) .id_table = unittest_i2c_dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) #if IS_BUILTIN(CONFIG_I2C_MUX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) static int unittest_i2c_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) static int unittest_i2c_mux_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) int i, nchans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) struct i2c_adapter *adap = client->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) struct device_node *np = client->dev.of_node, *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) struct i2c_mux_core *muxc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) u32 reg, max_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) dev_err(dev, "No OF node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) max_reg = (u32)-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) for_each_child_of_node(np, child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) if (of_property_read_u32(child, "reg", ®))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) if (max_reg == (u32)-1 || reg > max_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) max_reg = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) nchans = max_reg == (u32)-1 ? 0 : max_reg + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) if (nchans == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) dev_err(dev, "No channels\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) muxc = i2c_mux_alloc(adap, dev, nchans, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) unittest_i2c_mux_select_chan, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) if (!muxc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) for (i = 0; i < nchans; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) if (i2c_mux_add_adapter(muxc, 0, i, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) dev_err(dev, "Failed to register mux #%d\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) i2c_mux_del_adapters(muxc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) i2c_set_clientdata(client, muxc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) static int unittest_i2c_mux_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) struct device_node *np = client->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) struct i2c_mux_core *muxc = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) dev_dbg(dev, "%s for node @%pOF\n", __func__, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) i2c_mux_del_adapters(muxc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) static const struct i2c_device_id unittest_i2c_mux_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) { .name = "unittest-i2c-mux" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) static struct i2c_driver unittest_i2c_mux_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) .name = "unittest-i2c-mux",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) .probe = unittest_i2c_mux_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) .remove = unittest_i2c_mux_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) .id_table = unittest_i2c_mux_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) static int of_unittest_overlay_i2c_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) ret = i2c_add_driver(&unittest_i2c_dev_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) if (unittest(ret == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) "could not register unittest i2c device driver\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) ret = platform_driver_register(&unittest_i2c_bus_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) if (unittest(ret == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) "could not register unittest i2c bus driver\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) #if IS_BUILTIN(CONFIG_I2C_MUX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) "i2c i2c-1: Added multiplexed i2c bus 2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) ret = i2c_add_driver(&unittest_i2c_mux_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) "i2c i2c-1: Added multiplexed i2c bus 2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) if (unittest(ret == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) "could not register unittest i2c mux driver\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) static void of_unittest_overlay_i2c_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) #if IS_BUILTIN(CONFIG_I2C_MUX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) i2c_del_driver(&unittest_i2c_mux_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) platform_driver_unregister(&unittest_i2c_bus_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) i2c_del_driver(&unittest_i2c_dev_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) static void __init of_unittest_overlay_i2c_12(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) /* device should enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) ret = of_unittest_apply_overlay_check(12, 12, 0, 1, I2C_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest12/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) unittest(1, "overlay test %d passed\n", 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) /* test deactivation of device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) static void __init of_unittest_overlay_i2c_13(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) /* device should disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) ret = of_unittest_apply_overlay_check(13, 13, 1, 0, I2C_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data/overlay-node/test-bus/i2c-test-bus/test-unittest13/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) unittest(1, "overlay test %d passed\n", 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) /* just check for i2c mux existence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) static void of_unittest_overlay_i2c_14(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) static void __init of_unittest_overlay_i2c_15(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) /* device should enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) EXPECT_BEGIN(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) "i2c i2c-1: Added multiplexed i2c bus 3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) ret = of_unittest_apply_overlay_check(15, 15, 0, 1, I2C_OVERLAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) EXPECT_END(KERN_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) "i2c i2c-1: Added multiplexed i2c bus 3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) unittest(1, "overlay test %d passed\n", 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) static inline void of_unittest_overlay_i2c_14(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) static inline void of_unittest_overlay_i2c_15(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) static void __init of_unittest_overlay(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) struct device_node *bus_np = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) if (platform_driver_register(&unittest_driver)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) unittest(0, "could not register unittest driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) bus_np = of_find_node_by_path(bus_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) if (bus_np == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) unittest(0, "could not find bus_path \"%s\"\n", bus_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) if (of_platform_default_populate(bus_np, NULL, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) unittest(0, "could not populate bus @ \"%s\"\n", bus_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) if (!of_unittest_device_exists(100, PDEV_OVERLAY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) unittest(0, "could not find unittest0 @ \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) unittest_path(100, PDEV_OVERLAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) if (of_unittest_device_exists(101, PDEV_OVERLAY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) unittest(0, "unittest1 @ \"%s\" should not exist\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) unittest_path(101, PDEV_OVERLAY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) unittest(1, "basic infrastructure of overlays passed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) /* tests in sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) of_unittest_overlay_0();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) of_unittest_overlay_1();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) of_unittest_overlay_2();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) of_unittest_overlay_3();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) of_unittest_overlay_4();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) of_unittest_overlay_5();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) of_unittest_overlay_6();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) of_unittest_overlay_8();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) of_unittest_overlay_10();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) of_unittest_overlay_11();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) #if IS_BUILTIN(CONFIG_I2C)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) if (unittest(of_unittest_overlay_i2c_init() == 0, "i2c init failed\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) of_unittest_overlay_i2c_12();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) of_unittest_overlay_i2c_13();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) of_unittest_overlay_i2c_14();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) of_unittest_overlay_i2c_15();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) of_unittest_overlay_i2c_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) of_unittest_overlay_gpio();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) of_unittest_destroy_tracked_overlays();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) of_node_put(bus_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) static inline void __init of_unittest_overlay(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) #ifdef CONFIG_OF_OVERLAY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) * __dtb_ot_begin[] and __dtb_ot_end[] are created by cmd_dt_S_dtb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) * in scripts/Makefile.lib
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) #define OVERLAY_INFO_EXTERN(name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) extern uint8_t __dtb_##name##_begin[]; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) extern uint8_t __dtb_##name##_end[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) #define OVERLAY_INFO(overlay_name, expected) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) { .dtb_begin = __dtb_##overlay_name##_begin, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) .dtb_end = __dtb_##overlay_name##_end, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) .expected_result = expected, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) .name = #overlay_name, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) struct overlay_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) uint8_t *dtb_begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) uint8_t *dtb_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) int expected_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) int overlay_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) OVERLAY_INFO_EXTERN(overlay_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) OVERLAY_INFO_EXTERN(overlay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) OVERLAY_INFO_EXTERN(overlay_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) OVERLAY_INFO_EXTERN(overlay_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) OVERLAY_INFO_EXTERN(overlay_2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) OVERLAY_INFO_EXTERN(overlay_3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) OVERLAY_INFO_EXTERN(overlay_4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) OVERLAY_INFO_EXTERN(overlay_5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) OVERLAY_INFO_EXTERN(overlay_6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) OVERLAY_INFO_EXTERN(overlay_7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) OVERLAY_INFO_EXTERN(overlay_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) OVERLAY_INFO_EXTERN(overlay_9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) OVERLAY_INFO_EXTERN(overlay_10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) OVERLAY_INFO_EXTERN(overlay_11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) OVERLAY_INFO_EXTERN(overlay_12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) OVERLAY_INFO_EXTERN(overlay_13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) OVERLAY_INFO_EXTERN(overlay_15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) OVERLAY_INFO_EXTERN(overlay_gpio_01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) OVERLAY_INFO_EXTERN(overlay_gpio_02a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) OVERLAY_INFO_EXTERN(overlay_gpio_02b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) OVERLAY_INFO_EXTERN(overlay_gpio_03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) OVERLAY_INFO_EXTERN(overlay_gpio_04a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) OVERLAY_INFO_EXTERN(overlay_gpio_04b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) OVERLAY_INFO_EXTERN(overlay_bad_add_dup_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) OVERLAY_INFO_EXTERN(overlay_bad_add_dup_prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) OVERLAY_INFO_EXTERN(overlay_bad_phandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) OVERLAY_INFO_EXTERN(overlay_bad_symbol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) /* entries found by name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) static struct overlay_info overlays[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) OVERLAY_INFO(overlay_base, -9999),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) OVERLAY_INFO(overlay, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) OVERLAY_INFO(overlay_0, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) OVERLAY_INFO(overlay_1, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) OVERLAY_INFO(overlay_2, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) OVERLAY_INFO(overlay_3, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) OVERLAY_INFO(overlay_4, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) OVERLAY_INFO(overlay_5, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) OVERLAY_INFO(overlay_6, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) OVERLAY_INFO(overlay_7, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) OVERLAY_INFO(overlay_8, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) OVERLAY_INFO(overlay_9, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) OVERLAY_INFO(overlay_10, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) OVERLAY_INFO(overlay_11, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) OVERLAY_INFO(overlay_12, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) OVERLAY_INFO(overlay_13, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) OVERLAY_INFO(overlay_15, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) OVERLAY_INFO(overlay_gpio_01, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) OVERLAY_INFO(overlay_gpio_02a, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) OVERLAY_INFO(overlay_gpio_02b, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) OVERLAY_INFO(overlay_gpio_03, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) OVERLAY_INFO(overlay_gpio_04a, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) OVERLAY_INFO(overlay_gpio_04b, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) OVERLAY_INFO(overlay_bad_symbol, -EINVAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) /* end marker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) {.dtb_begin = NULL, .dtb_end = NULL, .expected_result = 0, .name = NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) static struct device_node *overlay_base_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) static void * __init dt_alloc_memory(u64 size, u64 align)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) void *ptr = memblock_alloc(size, align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) panic("%s: Failed to allocate %llu bytes align=0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) __func__, size, align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) * Create base device tree for the overlay unittest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) * This is called from very early boot code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) * Do as much as possible the same way as done in __unflatten_device_tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) * and other early boot steps for the normal FDT so that the overlay base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) * unflattened tree will have the same characteristics as the real tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) * (such as having memory allocated by the early allocator). The goal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) * is to test "the real thing" as much as possible, and test "test setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) * code" as little as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) * Have to stop before resolving phandles, because that uses kmalloc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) void __init unittest_unflatten_overlay_base(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) struct overlay_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) u32 data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) void *new_fdt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) const char *overlay_name = "overlay_base";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) for (info = overlays; info && info->name; info++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) if (!strcmp(overlay_name, info->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) pr_err("no overlay data for %s\n", overlay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) info = &overlays[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) if (info->expected_result != -9999) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) pr_err("No dtb 'overlay_base' to attach\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) data_size = info->dtb_end - info->dtb_begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) if (!data_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) pr_err("No dtb 'overlay_base' to attach\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) size = fdt_totalsize(info->dtb_begin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) if (size != data_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) pr_err("dtb 'overlay_base' header totalsize != actual size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) new_fdt = dt_alloc_memory(size, roundup_pow_of_two(FDT_V17_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) if (!new_fdt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) pr_err("alloc for dtb 'overlay_base' failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) memcpy(new_fdt, info->dtb_begin, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) __unflatten_device_tree(new_fdt, NULL, &overlay_base_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) dt_alloc_memory, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) * The purpose of of_unittest_overlay_data_add is to add an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) * overlay in the normal fashion. This is a test of the whole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) * picture, instead of testing individual elements.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) * A secondary purpose is to be able to verify that the contents of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) * /proc/device-tree/ contains the updated structure and values from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) * the overlay. That must be verified separately in user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) * Return 0 on unexpected error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) static int __init overlay_data_apply(const char *overlay_name, int *overlay_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) struct overlay_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) u32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) for (info = overlays; info && info->name; info++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) if (!strcmp(overlay_name, info->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) pr_err("no overlay data for %s\n", overlay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) size = info->dtb_end - info->dtb_begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) if (!size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) pr_err("no overlay data for %s\n", overlay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) ret = of_overlay_fdt_apply(info->dtb_begin, size, &info->overlay_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) if (overlay_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) *overlay_id = info->overlay_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) pr_debug("%s applied\n", overlay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) if (ret != info->expected_result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) pr_err("of_overlay_fdt_apply() expected %d, ret=%d, %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) info->expected_result, ret, overlay_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) return (ret == info->expected_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) * The purpose of of_unittest_overlay_high_level is to add an overlay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) * in the normal fashion. This is a test of the whole picture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) * instead of individual elements.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) * The first part of the function is _not_ normal overlay usage; it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) * finishing splicing the base overlay device tree into the live tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) static __init void of_unittest_overlay_high_level(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) struct device_node *last_sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) struct device_node *of_symbols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) struct device_node *overlay_base_symbols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) struct device_node **pprev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) struct property *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) if (!overlay_base_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) unittest(0, "overlay_base_root not initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) * Could not fixup phandles in unittest_unflatten_overlay_base()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) * because kmalloc() was not yet available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) of_overlay_mutex_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) of_resolve_phandles(overlay_base_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) of_overlay_mutex_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) * do not allow overlay_base to duplicate any node already in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) * tree, this greatly simplifies the code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) * remove overlay_base_root node "__local_fixups", after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) * being used by of_resolve_phandles()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) pprev = &overlay_base_root->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) for (np = overlay_base_root->child; np; np = np->sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) if (of_node_name_eq(np, "__local_fixups__")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) *pprev = np->sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) pprev = &np->sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) /* remove overlay_base_root node "__symbols__" if in live tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) of_symbols = of_get_child_by_name(of_root, "__symbols__");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) if (of_symbols) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) /* will have to graft properties from node into live tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) pprev = &overlay_base_root->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) for (np = overlay_base_root->child; np; np = np->sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) if (of_node_name_eq(np, "__symbols__")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) overlay_base_symbols = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) *pprev = np->sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) pprev = &np->sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) for_each_child_of_node(overlay_base_root, np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) struct device_node *base_child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) for_each_child_of_node(of_root, base_child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) if (!strcmp(np->full_name, base_child->full_name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) unittest(0, "illegal node name in overlay_base %pOFn",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) * overlay 'overlay_base' is not allowed to have root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) * properties, so only need to splice nodes into main device tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) * root node of *overlay_base_root will not be freed, it is lost
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) * memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) for (np = overlay_base_root->child; np; np = np->sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) np->parent = of_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) mutex_lock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) for (last_sibling = np = of_root->child; np; np = np->sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) last_sibling = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) if (last_sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) last_sibling->sibling = overlay_base_root->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) of_root->child = overlay_base_root->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) for_each_of_allnodes_from(overlay_base_root, np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) __of_attach_node_sysfs(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) if (of_symbols) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) struct property *new_prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) for_each_property_of_node(overlay_base_symbols, prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) new_prop = __of_prop_dup(prop, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) if (!new_prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) unittest(0, "__of_prop_dup() of '%s' from overlay_base node __symbols__",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) if (__of_add_property(of_symbols, new_prop)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) kfree(new_prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) kfree(new_prop->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) kfree(new_prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) /* "name" auto-generated by unflatten */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) if (!strcmp(prop->name, "name"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) unittest(0, "duplicate property '%s' in overlay_base node __symbols__",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) if (__of_add_property_sysfs(of_symbols, new_prop)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) unittest(0, "unable to add property '%s' in overlay_base node __symbols__ to sysfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) mutex_unlock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) /* now do the normal overlay usage test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@30/incline-up");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@40/incline-up");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/color");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/rate");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/hvac_2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_left");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_right");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) ret = overlay_data_apply("overlay", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_right");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200_left");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/ride_200");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /__symbols__/hvac_2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/rate");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/color");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/lights@40000/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@40/incline-up");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/ride@100/track@30/incline-up");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/fairway-1/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) "OF: overlay: WARNING: memory leak will occur if overlay removed, property: /testcase-data-2/substation@100/status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) unittest(ret, "Adding overlay 'overlay' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) unittest(overlay_data_apply("overlay_bad_add_dup_node", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) "Adding overlay 'overlay_bad_add_dup_node' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) EXPECT_BEGIN(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) unittest(overlay_data_apply("overlay_bad_add_dup_prop", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) "Adding overlay 'overlay_bad_add_dup_prop' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) EXPECT_END(KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/electric");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) unittest(overlay_data_apply("overlay_bad_phandle", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) "Adding overlay 'overlay_bad_phandle' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) unittest(overlay_data_apply("overlay_bad_symbol", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) "Adding overlay 'overlay_bad_symbol' failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) err_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) mutex_unlock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) static inline __init void of_unittest_overlay_high_level(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) static int __init of_unittest(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) pr_info("start of unittest - you will see error messages\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) /* adding data for unittest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) if (IS_ENABLED(CONFIG_UML))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) unittest_unflatten_overlay_base();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) res = unittest_data_add();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) if (!of_aliases)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) of_aliases = of_find_node_by_path("/aliases");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) pr_info("No testcase data in device tree; not running tests\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) of_unittest_check_tree_linkage();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) of_unittest_check_phandles();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) of_unittest_find_node_by_name();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) of_unittest_dynamic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) of_unittest_parse_phandle_with_args();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) of_unittest_parse_phandle_with_args_map();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) of_unittest_printf();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) of_unittest_property_string();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) of_unittest_property_copy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) of_unittest_changeset();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) of_unittest_parse_interrupts();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) of_unittest_parse_interrupts_extended();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) of_unittest_dma_get_max_cpu_address();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) of_unittest_parse_dma_ranges();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) of_unittest_pci_dma_ranges();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) of_unittest_match_node();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) of_unittest_platform_populate();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) of_unittest_overlay();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) /* Double check linkage after removing testcase data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) of_unittest_check_tree_linkage();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) of_unittest_overlay_high_level();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) pr_info("end of unittest - %i passed, %i failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) unittest_results.passed, unittest_results.failed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) late_initcall(of_unittest);