summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2019-12-29 21:19:28 -0700
committerSimon Glass <sjg@chromium.org>2020-01-07 16:02:39 -0700
commit42a0ce576f33ad413662e7178f05db2f36de9896 (patch)
treeaf97557d5426841d06a5942688ed3621dfc2e514 /test
parentaf68411dd1e9ef69ada074963333a5a5b8e278a4 (diff)
downloadu-boot-42a0ce576f33ad413662e7178f05db2f36de9896.tar.gz
dm: devres: Add a new OFDATA phase
Since the ofdata_to_platdata() method can allocate resources, add it as a new devres phase. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/dm/devres.c14
-rw-r--r--test/dm/test-fdt.c11
2 files changed, 22 insertions, 3 deletions
diff --git a/test/dm/devres.c b/test/dm/devres.c
index c351844db9..e7331897de 100644
--- a/test/dm/devres.c
+++ b/test/dm/devres.c
@@ -140,6 +140,7 @@ static int dm_test_devres_kcalloc(struct unit_test_state *uts)
}
DM_TEST(dm_test_devres_kcalloc, DM_TESTF_SCAN_PDATA);
+/* Test devres releases resources automatically as expected */
static int dm_test_devres_phase(struct unit_test_state *uts)
{
struct devres_stats stats;
@@ -154,14 +155,21 @@ static int dm_test_devres_phase(struct unit_test_state *uts)
ut_asserteq(1, stats.allocs);
ut_asserteq(TEST_DEVRES_SIZE, stats.total_size);
+ /* Getting platdata should add one allocation */
+ ut_assertok(device_ofdata_to_platdata(dev));
+ devres_get_stats(dev, &stats);
+ ut_asserteq(2, stats.allocs);
+ ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE3, stats.total_size);
+
/* Probing the device should add one allocation */
ut_assertok(uclass_first_device(UCLASS_TEST_DEVRES, &dev));
ut_assert(dev != NULL);
devres_get_stats(dev, &stats);
- ut_asserteq(2, stats.allocs);
- ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE2, stats.total_size);
+ ut_asserteq(3, stats.allocs);
+ ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE2 + TEST_DEVRES_SIZE3,
+ stats.total_size);
- /* Removing the device should drop one allocation */
+ /* Removing the device should drop both those allocations */
device_remove(dev, DM_REMOVE_NORMAL);
devres_get_stats(dev, &stats);
ut_asserteq(1, stats.allocs);
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index bbac37761d..d59c449ce0 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -159,6 +159,7 @@ struct dm_testdevres_pdata {
struct dm_testdevres_priv {
void *ptr;
+ void *ptr_ofdata;
};
static int testdevres_drv_bind(struct udevice *dev)
@@ -170,6 +171,15 @@ static int testdevres_drv_bind(struct udevice *dev)
return 0;
}
+static int testdevres_drv_ofdata_to_platdata(struct udevice *dev)
+{
+ struct dm_testdevres_priv *priv = dev_get_priv(dev);
+
+ priv->ptr_ofdata = devm_kmalloc(dev, TEST_DEVRES_SIZE3, 0);
+
+ return 0;
+}
+
static int testdevres_drv_probe(struct udevice *dev)
{
struct dm_testdevres_priv *priv = dev_get_priv(dev);
@@ -189,6 +199,7 @@ U_BOOT_DRIVER(testdevres_drv) = {
.of_match = testdevres_ids,
.id = UCLASS_TEST_DEVRES,
.bind = testdevres_drv_bind,
+ .ofdata_to_platdata = testdevres_drv_ofdata_to_platdata,
.probe = testdevres_drv_probe,
.platdata_auto_alloc_size = sizeof(struct dm_testdevres_pdata),
.priv_auto_alloc_size = sizeof(struct dm_testdevres_priv),