]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
of: Add a testcase for of_find_node_by_path()
authorGrant Likely <grant.likely@linaro.org>
Fri, 14 Mar 2014 13:53:10 +0000 (13:53 +0000)
committerGrant Likely <grant.likely@linaro.org>
Fri, 23 May 2014 02:35:30 +0000 (11:35 +0900)
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>
drivers/of/selftest.c
drivers/of/testcase-data/tests-phandle.dtsi

index 2588faaaa3052d82ccaae31b6522da5eb612f016..077314eebb95c785b1f1cb8f46790f6004464ee3 100644 (file)
@@ -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();
index 788a4c24b8f5b60f0467b97a8cf98126e5d9b8dd..ce0fe083d4062eec02145105b44691741337667d 100644 (file)
@@ -1,6 +1,10 @@
 
 / {
-       testcase-data {
+       aliases {
+               testcase-alias = &testcase;
+       };
+
+       testcase: testcase-data {
                security-password = "password";
                duplicate-name = "duplicate";
                duplicate-name { };