Skip to content

Commit

Permalink
of/unittest: Fix of_platform_depopulate test case
Browse files Browse the repository at this point in the history
The previous commit, "of/unittest: early return from test skips tests"
exposed broken tests for the of_platform_unpopulate() function. The
problem was the populate and depopulate calls were not symmetrical like
they were intended to be, and unpopulate depends on the parent device to
have it's of_node pointer pointing to the parent device node. Fix these
bugs so that the test case works correctly.

In the process, the test_bus used as a container for the test devices
has been changed from a statically allocated struct device (which is
bad) to a properly allocated device with a .release() method (which is
good). This stops the test code from being a bad example of abusing the
device model.

Signed-off-by: Grant Likely <[email protected]>
Cc: Frank Rowand <[email protected]>
Cc: Pantelis Antoniou <[email protected]>
Cc: Pawel Moll <[email protected]>
  • Loading branch information
glikely committed Mar 29, 2015
1 parent 716e1d4 commit 37791b6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions drivers/of/unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,14 @@ static void __init of_selftest_match_node(void)
}
}

struct device test_bus = {
.init_name = "unittest-bus",
static const struct platform_device_info test_bus_info = {
.name = "unittest-bus",
};
static void __init of_selftest_platform_populate(void)
{
int irq, rc;
struct device_node *np, *child, *grandchild;
struct platform_device *pdev;
struct platform_device *pdev, *test_bus;
const struct of_device_id match[] = {
{ .compatible = "test-device", },
{}
Expand Down Expand Up @@ -787,28 +787,30 @@ static void __init of_selftest_platform_populate(void)
if (!np)
return;

rc = device_register(&test_bus);
test_bus = platform_device_register_full(&test_bus_info);
rc = PTR_ERR_OR_ZERO(test_bus);
selftest(!rc, "testbus registration failed; rc=%i\n", rc);
if (rc)
return;
test_bus->dev.of_node = np;

of_platform_populate(np, match, NULL, &test_bus->dev);
for_each_child_of_node(np, child) {
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);
of_platform_depopulate(&test_bus->dev);
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);
platform_device_unregister(test_bus);
of_node_put(np);
}

Expand Down

0 comments on commit 37791b6

Please sign in to comment.