aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@linaro.org>2014-11-04 13:14:13 +0000
committerAlex Shi <alex.shi@linaro.org>2015-12-16 15:09:15 +0800
commitd9b5710317bd9b82f52998c80979d747a9f841c8 (patch)
tree04cb415ecb01a109dbc6c3e4852bf9b26d08c197
parentfa0913420bc5e19e5de644ee6d833136b626bd02 (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> (cherry picked from commit 851da976dc1d72becc03e144b38c4efab9e7b361) Signed-off-by: Alex Shi <alex.shi@linaro.org>
-rw-r--r--drivers/of/unittest.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index e40089ef7839..46af7019d291 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -30,15 +30,17 @@ static struct device_node *nodes[NO_OF_NODES];
static int last_node_index;
static bool selftest_live_tree;
-#define selftest(result, fmt, ...) { \
- if (!(result)) { \
+#define selftest(result, fmt, ...) ({ \
+ bool failed = !(result); \
+ if (failed) { \
selftest_results.failed++; \
pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \
} else { \
selftest_results.passed++; \
pr_debug("pass %s():%i\n", __func__, __LINE__); \
} \
-}
+ failed; \
+})
static void __init of_selftest_find_node_by_name(void)
{
@@ -694,10 +696,13 @@ static void __init of_selftest_match_node(void)
}
}
+struct device test_bus = {
+ .init_name = "unittest-bus",
+};
static void __init of_selftest_platform_populate(void)
{
- int irq;
- struct device_node *np, *child;
+ int irq, rc;
+ struct device_node *np, *child, *grandchild;
struct platform_device *pdev;
struct of_device_id match[] = {
{ .compatible = "test-device", },
@@ -722,20 +727,32 @@ static void __init of_selftest_platform_populate(void)
irq = platform_get_irq(pdev, 0);
selftest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq);
- np = of_find_node_by_path("/testcase-data/platform-tests");
- if (!np) {
- pr_err("No testcase data in device tree\n");
+ if (selftest(np = of_find_node_by_path("/testcase-data/platform-tests"),
+ "No testcase data in device tree\n"));
+ return;
+
+ if (selftest(!(rc = device_register(&test_bus)),
+ "testbus registration failed; rc=%i\n", rc));
return;
- }
for_each_child_of_node(np, child) {
- struct device_node *grandchild;
- of_platform_populate(child, match, NULL, NULL);
+ of_platform_populate(child, match, NULL, &test_bus);
for_each_child_of_node(child, grandchild)
selftest(of_find_device_by_node(grandchild),
"Could not create device for node '%s'\n",
grandchild->name);
}
+
+ of_platform_depopulate(&test_bus);
+ for_each_child_of_node(np, child) {
+ for_each_child_of_node(child, grandchild)
+ selftest(!of_find_device_by_node(grandchild),
+ "device didn't get destroyed '%s'\n",
+ grandchild->name);
+ }
+
+ device_unregister(&test_bus);
+ of_node_put(np);
}
/**