diff options
author | Grant Likely <grant.likely@linaro.org> | 2014-11-04 08:14:13 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@linaro.org> | 2014-11-04 11:43:04 -0500 |
commit | 851da976dc1d72becc03e144b38c4efab9e7b361 (patch) | |
tree | 48e6166e60b3bbca8a1608386aed15eb2a3f4c0b /drivers/of | |
parent | 5063e25a302e6a83f6590d9a06bd5f6400b17430 (diff) |
of/unittest: Remove test devices after adding them
The of_platform_populate() test cases don't remove the test devices
after they are added. Fix this by adding tests for
of_platform_depopulate().
At the same time rework the selftest() macro to return the test result
value. This makes it easy to use the macro inside an if() condition.
Signed-off-by: Grant Likely <grant.likely@linaro.org>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/selftest.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index bf7d99317a94..082bb2b6a5ad 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c | |||
@@ -30,15 +30,17 @@ static struct device_node *nodes[NO_OF_NODES]; | |||
30 | static int last_node_index; | 30 | static int last_node_index; |
31 | static bool selftest_live_tree; | 31 | static bool selftest_live_tree; |
32 | 32 | ||
33 | #define selftest(result, fmt, ...) { \ | 33 | #define selftest(result, fmt, ...) ({ \ |
34 | if (!(result)) { \ | 34 | bool failed = !(result); \ |
35 | if (failed) { \ | ||
35 | selftest_results.failed++; \ | 36 | selftest_results.failed++; \ |
36 | pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \ | 37 | pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \ |
37 | } else { \ | 38 | } else { \ |
38 | selftest_results.passed++; \ | 39 | selftest_results.passed++; \ |
39 | pr_debug("pass %s():%i\n", __func__, __LINE__); \ | 40 | pr_debug("pass %s():%i\n", __func__, __LINE__); \ |
40 | } \ | 41 | } \ |
41 | } | 42 | failed; \ |
43 | }) | ||
42 | 44 | ||
43 | static void __init of_selftest_find_node_by_name(void) | 45 | static void __init of_selftest_find_node_by_name(void) |
44 | { | 46 | { |
@@ -694,10 +696,13 @@ static void __init of_selftest_match_node(void) | |||
694 | } | 696 | } |
695 | } | 697 | } |
696 | 698 | ||
699 | struct device test_bus = { | ||
700 | .init_name = "unittest-bus", | ||
701 | }; | ||
697 | static void __init of_selftest_platform_populate(void) | 702 | static void __init of_selftest_platform_populate(void) |
698 | { | 703 | { |
699 | int irq; | 704 | int irq, rc; |
700 | struct device_node *np, *child; | 705 | struct device_node *np, *child, *grandchild; |
701 | struct platform_device *pdev; | 706 | struct platform_device *pdev; |
702 | struct of_device_id match[] = { | 707 | struct of_device_id match[] = { |
703 | { .compatible = "test-device", }, | 708 | { .compatible = "test-device", }, |
@@ -722,20 +727,32 @@ static void __init of_selftest_platform_populate(void) | |||
722 | irq = platform_get_irq(pdev, 0); | 727 | irq = platform_get_irq(pdev, 0); |
723 | selftest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq); | 728 | selftest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq); |
724 | 729 | ||
725 | np = of_find_node_by_path("/testcase-data/platform-tests"); | 730 | if (selftest(np = of_find_node_by_path("/testcase-data/platform-tests"), |
726 | if (!np) { | 731 | "No testcase data in device tree\n")); |
727 | pr_err("No testcase data in device tree\n"); | 732 | return; |
733 | |||
734 | if (selftest(!(rc = device_register(&test_bus)), | ||
735 | "testbus registration failed; rc=%i\n", rc)); | ||
728 | return; | 736 | return; |
729 | } | ||
730 | 737 | ||
731 | for_each_child_of_node(np, child) { | 738 | for_each_child_of_node(np, child) { |
732 | struct device_node *grandchild; | 739 | of_platform_populate(child, match, NULL, &test_bus); |
733 | of_platform_populate(child, match, NULL, NULL); | ||
734 | for_each_child_of_node(child, grandchild) | 740 | for_each_child_of_node(child, grandchild) |
735 | selftest(of_find_device_by_node(grandchild), | 741 | selftest(of_find_device_by_node(grandchild), |
736 | "Could not create device for node '%s'\n", | 742 | "Could not create device for node '%s'\n", |
737 | grandchild->name); | 743 | grandchild->name); |
738 | } | 744 | } |
745 | |||
746 | of_platform_depopulate(&test_bus); | ||
747 | for_each_child_of_node(np, child) { | ||
748 | for_each_child_of_node(child, grandchild) | ||
749 | selftest(!of_find_device_by_node(grandchild), | ||
750 | "device didn't get destroyed '%s'\n", | ||
751 | grandchild->name); | ||
752 | } | ||
753 | |||
754 | device_unregister(&test_bus); | ||
755 | of_node_put(np); | ||
739 | } | 756 | } |
740 | 757 | ||
741 | /** | 758 | /** |