diff options
author | Grant Likely <grant.likely@linaro.org> | 2013-11-15 12:19:09 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@linaro.org> | 2014-03-11 16:48:29 -0400 |
commit | 7e66c5c74f7348a96d5a3671f8cda4a478242679 (patch) | |
tree | 23ec3fb3c8643d65e17aba709991f6677c3e6421 /drivers/of | |
parent | 75b57ecf9d1d1e17d099ab13b8f48e6e038676be (diff) |
of/selftest: Add self tests for manipulation of properties
Adds a few simple test cases to ensure that addition, update and removal
of device tree node properties works correctly.
Signed-off-by: Grant Likely <grant.likely@linaro.org>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: David S. Miller <davem@davemloft.net>
Cc: Nathan Fontenot <nfont@linux.vnet.ibm.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/selftest.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index 6643d1920985..ae4450070503 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c | |||
@@ -30,6 +30,67 @@ static struct selftest_results { | |||
30 | } \ | 30 | } \ |
31 | } | 31 | } |
32 | 32 | ||
33 | static void __init of_selftest_dynamic(void) | ||
34 | { | ||
35 | struct device_node *np; | ||
36 | struct property *prop; | ||
37 | |||
38 | np = of_find_node_by_path("/testcase-data"); | ||
39 | if (!np) { | ||
40 | pr_err("missing testcase data\n"); | ||
41 | return; | ||
42 | } | ||
43 | |||
44 | /* Array of 4 properties for the purpose of testing */ | ||
45 | prop = kzalloc(sizeof(*prop) * 4, GFP_KERNEL); | ||
46 | if (!prop) { | ||
47 | selftest(0, "kzalloc() failed\n"); | ||
48 | return; | ||
49 | } | ||
50 | |||
51 | /* Add a new property - should pass*/ | ||
52 | prop->name = "new-property"; | ||
53 | prop->value = "new-property-data"; | ||
54 | prop->length = strlen(prop->value); | ||
55 | selftest(of_add_property(np, prop) == 0, "Adding a new property failed\n"); | ||
56 | |||
57 | /* Try to add an existing property - should fail */ | ||
58 | prop++; | ||
59 | prop->name = "new-property"; | ||
60 | prop->value = "new-property-data-should-fail"; | ||
61 | prop->length = strlen(prop->value); | ||
62 | selftest(of_add_property(np, prop) != 0, | ||
63 | "Adding an existing property should have failed\n"); | ||
64 | |||
65 | /* Try to modify an existing property - should pass */ | ||
66 | prop->value = "modify-property-data-should-pass"; | ||
67 | prop->length = strlen(prop->value); | ||
68 | selftest(of_update_property(np, prop) == 0, | ||
69 | "Updating an existing property should have passed\n"); | ||
70 | |||
71 | /* Try to modify non-existent property - should pass*/ | ||
72 | prop++; | ||
73 | prop->name = "modify-property"; | ||
74 | prop->value = "modify-missing-property-data-should-pass"; | ||
75 | prop->length = strlen(prop->value); | ||
76 | selftest(of_update_property(np, prop) == 0, | ||
77 | "Updating a missing property should have passed\n"); | ||
78 | |||
79 | /* Remove property - should pass */ | ||
80 | selftest(of_remove_property(np, prop) == 0, | ||
81 | "Removing a property should have passed\n"); | ||
82 | |||
83 | /* Adding very large property - should pass */ | ||
84 | prop++; | ||
85 | prop->name = "large-property-PAGE_SIZEx8"; | ||
86 | prop->length = PAGE_SIZE * 8; | ||
87 | prop->value = kzalloc(prop->length, GFP_KERNEL); | ||
88 | selftest(prop->value != NULL, "Unable to allocate large buffer\n"); | ||
89 | if (prop->value) | ||
90 | selftest(of_add_property(np, prop) == 0, | ||
91 | "Adding a large property should have passed\n"); | ||
92 | } | ||
93 | |||
33 | static void __init of_selftest_parse_phandle_with_args(void) | 94 | static void __init of_selftest_parse_phandle_with_args(void) |
34 | { | 95 | { |
35 | struct device_node *np; | 96 | struct device_node *np; |
@@ -378,6 +439,7 @@ static int __init of_selftest(void) | |||
378 | of_node_put(np); | 439 | of_node_put(np); |
379 | 440 | ||
380 | pr_info("start of selftest - you will see error messages\n"); | 441 | pr_info("start of selftest - you will see error messages\n"); |
442 | of_selftest_dynamic(); | ||
381 | of_selftest_parse_phandle_with_args(); | 443 | of_selftest_parse_phandle_with_args(); |
382 | of_selftest_property_match_string(); | 444 | of_selftest_property_match_string(); |
383 | of_selftest_parse_interrupts(); | 445 | of_selftest_parse_interrupts(); |