Skip to content

Commit ae91ff7

Browse files
committed
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 <[email protected]>
1 parent c22e650 commit ae91ff7

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

drivers/of/selftest.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,51 @@ static struct selftest_results {
3131
} \
3232
}
3333

34+
static void __init of_selftest_find_node_by_name(void)
35+
{
36+
struct device_node *np;
37+
38+
np = of_find_node_by_path("/testcase-data");
39+
selftest(np && !strcmp("/testcase-data", np->full_name),
40+
"find /testcase-data failed\n");
41+
of_node_put(np);
42+
43+
/* Test if trailing '/' works */
44+
np = of_find_node_by_path("/testcase-data/");
45+
selftest(!np, "trailing '/' on /testcase-data/ should fail\n");
46+
47+
np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
48+
selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name),
49+
"find /testcase-data/phandle-tests/consumer-a failed\n");
50+
of_node_put(np);
51+
52+
np = of_find_node_by_path("testcase-alias");
53+
selftest(np && !strcmp("/testcase-data", np->full_name),
54+
"find testcase-alias failed\n");
55+
of_node_put(np);
56+
57+
/* Test if trailing '/' works on aliases */
58+
np = of_find_node_by_path("testcase-alias/");
59+
selftest(!np, "trailing '/' on testcase-alias/ should fail\n");
60+
61+
np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a");
62+
selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name),
63+
"find testcase-alias/phandle-tests/consumer-a failed\n");
64+
of_node_put(np);
65+
66+
np = of_find_node_by_path("/testcase-data/missing-path");
67+
selftest(!np, "non-existent path returned node %s\n", np->full_name);
68+
of_node_put(np);
69+
70+
np = of_find_node_by_path("missing-alias");
71+
selftest(!np, "non-existent alias returned node %s\n", np->full_name);
72+
of_node_put(np);
73+
74+
np = of_find_node_by_path("testcase-alias/missing-path");
75+
selftest(!np, "non-existent alias with relative path returned node %s\n", np->full_name);
76+
of_node_put(np);
77+
}
78+
3479
static void __init of_selftest_dynamic(void)
3580
{
3681
struct device_node *np;
@@ -484,6 +529,7 @@ static int __init of_selftest(void)
484529
of_node_put(np);
485530

486531
pr_info("start of selftest - you will see error messages\n");
532+
of_selftest_find_node_by_name();
487533
of_selftest_dynamic();
488534
of_selftest_parse_phandle_with_args();
489535
of_selftest_property_match_string();

drivers/of/testcase-data/tests-phandle.dtsi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
/ {
3-
testcase-data {
3+
aliases {
4+
testcase-alias = &testcase;
5+
};
6+
7+
testcase: testcase-data {
48
security-password = "password";
59
duplicate-name = "duplicate";
610
duplicate-name { };

0 commit comments

Comments
 (0)