diff options
Diffstat (limited to 'test/dm/blk.c')
-rw-r--r-- | test/dm/blk.c | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/test/dm/blk.c b/test/dm/blk.c index 012bf4cab5..5c5eb829a0 100644 --- a/test/dm/blk.c +++ b/test/dm/blk.c @@ -83,14 +83,70 @@ static int dm_test_blk_usb(struct unit_test_state *uts) ut_asserteq_ptr(usb_dev, dev_get_parent(dev)); /* Check we have one block device for each mass storage device */ - ut_asserteq(4, count_blk_devices()); + ut_asserteq(6, count_blk_devices()); /* Now go around again, making sure the old devices were unbound */ ut_assertok(usb_stop()); ut_assertok(usb_init()); - ut_asserteq(4, count_blk_devices()); + ut_asserteq(6, count_blk_devices()); ut_assertok(usb_stop()); return 0; } DM_TEST(dm_test_blk_usb, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test that we can find block devices without probing them */ +static int dm_test_blk_find(struct unit_test_state *uts) +{ + struct udevice *blk, *dev; + + ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test", + IF_TYPE_HOST, 1, 512, 1024, &blk)); + ut_asserteq(-ENODEV, blk_find_device(IF_TYPE_HOST, 0, &dev)); + ut_assertok(blk_find_device(IF_TYPE_HOST, 1, &dev)); + ut_asserteq_ptr(blk, dev); + ut_asserteq(false, device_active(dev)); + + /* Now activate it */ + ut_assertok(blk_get_device(IF_TYPE_HOST, 1, &dev)); + ut_asserteq_ptr(blk, dev); + ut_asserteq(true, device_active(dev)); + + return 0; +} +DM_TEST(dm_test_blk_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test that block device numbering works as expected */ +static int dm_test_blk_devnum(struct unit_test_state *uts) +{ + struct udevice *dev, *mmc_dev, *parent; + int i; + + /* + * Probe the devices, with the first one being probed last. This is the + * one with no alias / sequence numnber. + */ + ut_assertok(uclass_get_device(UCLASS_MMC, 1, &dev)); + ut_assertok(uclass_get_device(UCLASS_MMC, 2, &dev)); + ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); + for (i = 0; i < 3; i++) { + struct blk_desc *desc; + + /* Check that the bblock device is attached */ + ut_assertok(uclass_get_device_by_seq(UCLASS_MMC, i, &mmc_dev)); + ut_assertok(blk_find_device(IF_TYPE_MMC, i, &dev)); + parent = dev_get_parent(dev); + ut_asserteq_ptr(parent, mmc_dev); + ut_asserteq(trailing_strtol(mmc_dev->name), i); + + /* + * Check that the block device devnum matches its parent's + * sequence number + */ + desc = dev_get_uclass_platdata(dev); + ut_asserteq(desc->devnum, i); + } + + return 0; +} +DM_TEST(dm_test_blk_devnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |