diff options
Diffstat (limited to 'drivers/of/selftest.c')
-rw-r--r-- | drivers/of/selftest.c | 77 |
1 files changed, 68 insertions, 9 deletions
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index 78001270a598..e2d79afa9dc6 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c | |||
@@ -339,8 +339,9 @@ static void __init of_selftest_parse_phandle_with_args(void) | |||
339 | selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); | 339 | selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); |
340 | } | 340 | } |
341 | 341 | ||
342 | static void __init of_selftest_property_match_string(void) | 342 | static void __init of_selftest_property_string(void) |
343 | { | 343 | { |
344 | const char *strings[4]; | ||
344 | struct device_node *np; | 345 | struct device_node *np; |
345 | int rc; | 346 | int rc; |
346 | 347 | ||
@@ -357,13 +358,66 @@ static void __init of_selftest_property_match_string(void) | |||
357 | rc = of_property_match_string(np, "phandle-list-names", "third"); | 358 | rc = of_property_match_string(np, "phandle-list-names", "third"); |
358 | selftest(rc == 2, "third expected:0 got:%i\n", rc); | 359 | selftest(rc == 2, "third expected:0 got:%i\n", rc); |
359 | rc = of_property_match_string(np, "phandle-list-names", "fourth"); | 360 | rc = of_property_match_string(np, "phandle-list-names", "fourth"); |
360 | selftest(rc == -ENODATA, "unmatched string; rc=%i", rc); | 361 | selftest(rc == -ENODATA, "unmatched string; rc=%i\n", rc); |
361 | rc = of_property_match_string(np, "missing-property", "blah"); | 362 | rc = of_property_match_string(np, "missing-property", "blah"); |
362 | selftest(rc == -EINVAL, "missing property; rc=%i", rc); | 363 | selftest(rc == -EINVAL, "missing property; rc=%i\n", rc); |
363 | rc = of_property_match_string(np, "empty-property", "blah"); | 364 | rc = of_property_match_string(np, "empty-property", "blah"); |
364 | selftest(rc == -ENODATA, "empty property; rc=%i", rc); | 365 | selftest(rc == -ENODATA, "empty property; rc=%i\n", rc); |
365 | rc = of_property_match_string(np, "unterminated-string", "blah"); | 366 | rc = of_property_match_string(np, "unterminated-string", "blah"); |
366 | selftest(rc == -EILSEQ, "unterminated string; rc=%i", rc); | 367 | selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); |
368 | |||
369 | /* of_property_count_strings() tests */ | ||
370 | rc = of_property_count_strings(np, "string-property"); | ||
371 | selftest(rc == 1, "Incorrect string count; rc=%i\n", rc); | ||
372 | rc = of_property_count_strings(np, "phandle-list-names"); | ||
373 | selftest(rc == 3, "Incorrect string count; rc=%i\n", rc); | ||
374 | rc = of_property_count_strings(np, "unterminated-string"); | ||
375 | selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); | ||
376 | rc = of_property_count_strings(np, "unterminated-string-list"); | ||
377 | selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc); | ||
378 | |||
379 | /* of_property_read_string_index() tests */ | ||
380 | rc = of_property_read_string_index(np, "string-property", 0, strings); | ||
381 | selftest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc); | ||
382 | strings[0] = NULL; | ||
383 | rc = of_property_read_string_index(np, "string-property", 1, strings); | ||
384 | selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); | ||
385 | rc = of_property_read_string_index(np, "phandle-list-names", 0, strings); | ||
386 | selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc); | ||
387 | rc = of_property_read_string_index(np, "phandle-list-names", 1, strings); | ||
388 | selftest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc); | ||
389 | rc = of_property_read_string_index(np, "phandle-list-names", 2, strings); | ||
390 | selftest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc); | ||
391 | strings[0] = NULL; | ||
392 | rc = of_property_read_string_index(np, "phandle-list-names", 3, strings); | ||
393 | selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); | ||
394 | strings[0] = NULL; | ||
395 | rc = of_property_read_string_index(np, "unterminated-string", 0, strings); | ||
396 | selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); | ||
397 | rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings); | ||
398 | selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc); | ||
399 | strings[0] = NULL; | ||
400 | rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */ | ||
401 | selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc); | ||
402 | strings[1] = NULL; | ||
403 | |||
404 | /* of_property_read_string_array() tests */ | ||
405 | rc = of_property_read_string_array(np, "string-property", strings, 4); | ||
406 | selftest(rc == 1, "Incorrect string count; rc=%i\n", rc); | ||
407 | rc = of_property_read_string_array(np, "phandle-list-names", strings, 4); | ||
408 | selftest(rc == 3, "Incorrect string count; rc=%i\n", rc); | ||
409 | rc = of_property_read_string_array(np, "unterminated-string", strings, 4); | ||
410 | selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc); | ||
411 | /* -- An incorrectly formed string should cause a failure */ | ||
412 | rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4); | ||
413 | selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc); | ||
414 | /* -- parsing the correctly formed strings should still work: */ | ||
415 | strings[2] = NULL; | ||
416 | rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2); | ||
417 | selftest(rc == 2 && strings[2] == NULL, "of_property_read_string_array() failure; rc=%i\n", rc); | ||
418 | strings[1] = NULL; | ||
419 | rc = of_property_read_string_array(np, "phandle-list-names", strings, 1); | ||
420 | selftest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]); | ||
367 | } | 421 | } |
368 | 422 | ||
369 | #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \ | 423 | #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \ |
@@ -842,10 +896,14 @@ static void selftest_data_remove(void) | |||
842 | return; | 896 | return; |
843 | } | 897 | } |
844 | 898 | ||
845 | while (last_node_index >= 0) { | 899 | while (last_node_index-- > 0) { |
846 | if (nodes[last_node_index]) { | 900 | if (nodes[last_node_index]) { |
847 | np = of_find_node_by_path(nodes[last_node_index]->full_name); | 901 | np = of_find_node_by_path(nodes[last_node_index]->full_name); |
848 | if (strcmp(np->full_name, "/aliases") != 0) { | 902 | if (np == nodes[last_node_index]) { |
903 | if (of_aliases == np) { | ||
904 | of_node_put(of_aliases); | ||
905 | of_aliases = NULL; | ||
906 | } | ||
849 | detach_node_and_children(np); | 907 | detach_node_and_children(np); |
850 | } else { | 908 | } else { |
851 | for_each_property_of_node(np, prop) { | 909 | for_each_property_of_node(np, prop) { |
@@ -854,7 +912,6 @@ static void selftest_data_remove(void) | |||
854 | } | 912 | } |
855 | } | 913 | } |
856 | } | 914 | } |
857 | last_node_index--; | ||
858 | } | 915 | } |
859 | } | 916 | } |
860 | 917 | ||
@@ -867,6 +924,8 @@ static int __init of_selftest(void) | |||
867 | res = selftest_data_add(); | 924 | res = selftest_data_add(); |
868 | if (res) | 925 | if (res) |
869 | return res; | 926 | return res; |
927 | if (!of_aliases) | ||
928 | of_aliases = of_find_node_by_path("/aliases"); | ||
870 | 929 | ||
871 | np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); | 930 | np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); |
872 | if (!np) { | 931 | if (!np) { |
@@ -881,7 +940,7 @@ static int __init of_selftest(void) | |||
881 | of_selftest_find_node_by_name(); | 940 | of_selftest_find_node_by_name(); |
882 | of_selftest_dynamic(); | 941 | of_selftest_dynamic(); |
883 | of_selftest_parse_phandle_with_args(); | 942 | of_selftest_parse_phandle_with_args(); |
884 | of_selftest_property_match_string(); | 943 | of_selftest_property_string(); |
885 | of_selftest_property_copy(); | 944 | of_selftest_property_copy(); |
886 | of_selftest_changeset(); | 945 | of_selftest_changeset(); |
887 | of_selftest_parse_interrupts(); | 946 | of_selftest_parse_interrupts(); |