Commit 7e66c5c74f7348a96d5a3671f8cda4a478242679
1 parent
75b57ecf9d
Exists in
master
and in
13 other branches
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>
Showing 1 changed file with 62 additions and 0 deletions Side-by-side Diff
drivers/of/selftest.c
... | ... | @@ -30,6 +30,67 @@ |
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 | 94 | static void __init of_selftest_parse_phandle_with_args(void) |
34 | 95 | { |
35 | 96 | struct device_node *np; |
... | ... | @@ -378,6 +439,7 @@ |
378 | 439 | of_node_put(np); |
379 | 440 | |
380 | 441 | pr_info("start of selftest - you will see error messages\n"); |
442 | + of_selftest_dynamic(); | |
381 | 443 | of_selftest_parse_phandle_with_args(); |
382 | 444 | of_selftest_property_match_string(); |
383 | 445 | of_selftest_parse_interrupts(); |