diff options
Diffstat (limited to 'drivers/of/selftest.c')
-rw-r--r-- | drivers/of/selftest.c | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index f24ffd7088d2..0eb5c38b4e07 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * Self tests for device tree subsystem | 2 | * Self tests for device tree subsystem |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #define pr_fmt(fmt) "### %s(): " fmt, __func__ | 5 | #define pr_fmt(fmt) "### dt-test ### " fmt |
6 | 6 | ||
7 | #include <linux/clk.h> | 7 | #include <linux/clk.h> |
8 | #include <linux/err.h> | 8 | #include <linux/err.h> |
@@ -16,26 +16,30 @@ | |||
16 | 16 | ||
17 | static bool selftest_passed = true; | 17 | static bool selftest_passed = true; |
18 | #define selftest(result, fmt, ...) { \ | 18 | #define selftest(result, fmt, ...) { \ |
19 | selftest_passed &= (result); \ | 19 | if (!(result)) { \ |
20 | if (!(result)) \ | ||
21 | pr_err("FAIL %s:%i " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ | 20 | pr_err("FAIL %s:%i " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \ |
21 | selftest_passed = false; \ | ||
22 | } else { \ | ||
23 | pr_info("pass %s:%i\n", __FILE__, __LINE__); \ | ||
24 | } \ | ||
22 | } | 25 | } |
23 | 26 | ||
24 | static void __init of_selftest_parse_phandle_with_args(void) | 27 | static void __init of_selftest_parse_phandle_with_args(void) |
25 | { | 28 | { |
26 | struct device_node *np; | 29 | struct device_node *np; |
27 | struct of_phandle_args args; | 30 | struct of_phandle_args args; |
28 | int rc, i; | 31 | int i, rc; |
29 | bool passed_all = true; | ||
30 | 32 | ||
31 | pr_info("start\n"); | ||
32 | np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); | 33 | np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); |
33 | if (!np) { | 34 | if (!np) { |
34 | pr_err("missing testcase data\n"); | 35 | pr_err("missing testcase data\n"); |
35 | return; | 36 | return; |
36 | } | 37 | } |
37 | 38 | ||
38 | for (i = 0; i < 7; i++) { | 39 | rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells"); |
40 | selftest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc); | ||
41 | |||
42 | for (i = 0; i < 8; i++) { | ||
39 | bool passed = true; | 43 | bool passed = true; |
40 | rc = of_parse_phandle_with_args(np, "phandle-list", | 44 | rc = of_parse_phandle_with_args(np, "phandle-list", |
41 | "#phandle-cells", i, &args); | 45 | "#phandle-cells", i, &args); |
@@ -79,45 +83,47 @@ static void __init of_selftest_parse_phandle_with_args(void) | |||
79 | passed &= (args.args[0] == (i + 1)); | 83 | passed &= (args.args[0] == (i + 1)); |
80 | break; | 84 | break; |
81 | case 7: | 85 | case 7: |
82 | passed &= (rc == -EINVAL); | 86 | passed &= (rc == -ENOENT); |
83 | break; | 87 | break; |
84 | default: | 88 | default: |
85 | passed = false; | 89 | passed = false; |
86 | } | 90 | } |
87 | 91 | ||
88 | if (!passed) { | 92 | selftest(passed, "index %i - data error on node %s rc=%i\n", |
89 | int j; | 93 | i, args.np->full_name, rc); |
90 | pr_err("index %i - data error on node %s rc=%i regs=[", | ||
91 | i, args.np->full_name, rc); | ||
92 | for (j = 0; j < args.args_count; j++) | ||
93 | printk(" %i", args.args[j]); | ||
94 | printk(" ]\n"); | ||
95 | |||
96 | passed_all = false; | ||
97 | } | ||
98 | } | 94 | } |
99 | 95 | ||
100 | /* Check for missing list property */ | 96 | /* Check for missing list property */ |
101 | rc = of_parse_phandle_with_args(np, "phandle-list-missing", | 97 | rc = of_parse_phandle_with_args(np, "phandle-list-missing", |
102 | "#phandle-cells", 0, &args); | 98 | "#phandle-cells", 0, &args); |
103 | passed_all &= (rc == -EINVAL); | 99 | selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); |
100 | rc = of_count_phandle_with_args(np, "phandle-list-missing", | ||
101 | "#phandle-cells"); | ||
102 | selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); | ||
104 | 103 | ||
105 | /* Check for missing cells property */ | 104 | /* Check for missing cells property */ |
106 | rc = of_parse_phandle_with_args(np, "phandle-list", | 105 | rc = of_parse_phandle_with_args(np, "phandle-list", |
107 | "#phandle-cells-missing", 0, &args); | 106 | "#phandle-cells-missing", 0, &args); |
108 | passed_all &= (rc == -EINVAL); | 107 | selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
108 | rc = of_count_phandle_with_args(np, "phandle-list", | ||
109 | "#phandle-cells-missing"); | ||
110 | selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); | ||
109 | 111 | ||
110 | /* Check for bad phandle in list */ | 112 | /* Check for bad phandle in list */ |
111 | rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle", | 113 | rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle", |
112 | "#phandle-cells", 0, &args); | 114 | "#phandle-cells", 0, &args); |
113 | passed_all &= (rc == -EINVAL); | 115 | selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
116 | rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle", | ||
117 | "#phandle-cells"); | ||
118 | selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); | ||
114 | 119 | ||
115 | /* Check for incorrectly formed argument list */ | 120 | /* Check for incorrectly formed argument list */ |
116 | rc = of_parse_phandle_with_args(np, "phandle-list-bad-args", | 121 | rc = of_parse_phandle_with_args(np, "phandle-list-bad-args", |
117 | "#phandle-cells", 1, &args); | 122 | "#phandle-cells", 1, &args); |
118 | passed_all &= (rc == -EINVAL); | 123 | selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
119 | 124 | rc = of_count_phandle_with_args(np, "phandle-list-bad-args", | |
120 | pr_info("end - %s\n", passed_all ? "PASS" : "FAIL"); | 125 | "#phandle-cells"); |
126 | selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); | ||
121 | } | 127 | } |
122 | 128 | ||
123 | static void __init of_selftest_property_match_string(void) | 129 | static void __init of_selftest_property_match_string(void) |