diff options
author | Grant Likely <grant.likely@linaro.org> | 2014-03-14 14:53:10 +0100 |
---|---|---|
committer | Grant Likely <grant.likely@linaro.org> | 2014-05-23 04:35:30 +0200 |
commit | ae91ff72e9132abe47f726424d9420fce004ca04 (patch) | |
tree | 930bda8116afaf11520fe7a9b18a25fc84ce5843 /drivers/of/selftest.c | |
parent | of: Make of_find_node_by_path() handle /aliases (diff) | |
download | linux-ae91ff72e9132abe47f726424d9420fce004ca04.tar.xz linux-ae91ff72e9132abe47f726424d9420fce004ca04.zip |
of: Add a testcase for of_find_node_by_path()
Add a testcase for the find_node_by_path() function to make sure it
handles all the valid scenarios.
Signed-off-by: Grant Likely <grant.likely@linaro.org>
Diffstat (limited to 'drivers/of/selftest.c')
-rw-r--r-- | drivers/of/selftest.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index 2588faaaa305..077314eebb95 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -31,6 +31,51 @@ static struct selftest_results { } \ } +static void __init of_selftest_find_node_by_name(void) +{ + struct device_node *np; + + np = of_find_node_by_path("/testcase-data"); + selftest(np && !strcmp("/testcase-data", np->full_name), + "find /testcase-data failed\n"); + of_node_put(np); + + /* Test if trailing '/' works */ + np = of_find_node_by_path("/testcase-data/"); + selftest(!np, "trailing '/' on /testcase-data/ should fail\n"); + + np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); + selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name), + "find /testcase-data/phandle-tests/consumer-a failed\n"); + of_node_put(np); + + np = of_find_node_by_path("testcase-alias"); + selftest(np && !strcmp("/testcase-data", np->full_name), + "find testcase-alias failed\n"); + of_node_put(np); + + /* Test if trailing '/' works on aliases */ + np = of_find_node_by_path("testcase-alias/"); + selftest(!np, "trailing '/' on testcase-alias/ should fail\n"); + + np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a"); + selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name), + "find testcase-alias/phandle-tests/consumer-a failed\n"); + of_node_put(np); + + np = of_find_node_by_path("/testcase-data/missing-path"); + selftest(!np, "non-existent path returned node %s\n", np->full_name); + of_node_put(np); + + np = of_find_node_by_path("missing-alias"); + selftest(!np, "non-existent alias returned node %s\n", np->full_name); + of_node_put(np); + + np = of_find_node_by_path("testcase-alias/missing-path"); + selftest(!np, "non-existent alias with relative path returned node %s\n", np->full_name); + of_node_put(np); +} + static void __init of_selftest_dynamic(void) { struct device_node *np; @@ -484,6 +529,7 @@ static int __init of_selftest(void) of_node_put(np); pr_info("start of selftest - you will see error messages\n"); + of_selftest_find_node_by_name(); of_selftest_dynamic(); of_selftest_parse_phandle_with_args(); of_selftest_property_match_string(); |