aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-02-28 12:08:35 -0700
committerTom Rini <trini@konsulko.com>2022-04-06 14:03:17 -0400
commit49e8668181df501f263751b2e9bbb5ff737819d1 (patch)
tree50ba086e7342efbdb50046c69326f25fb9687d09 /test
parente86b6f71002e5892c28acd206e68d13adc76c4b7 (diff)
downloadu-boot-49e8668181df501f263751b2e9bbb5ff737819d1.zip
u-boot-49e8668181df501f263751b2e9bbb5ff737819d1.tar.gz
u-boot-49e8668181df501f263751b2e9bbb5ff737819d1.tar.bz2
dm: blk: Expand iteration and add testsWIP/2022-04-06-various-verified-boot-bugfixes
Add some functions which support iteration before probing. Also add tests for the functions. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/dm/blk.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/test/dm/blk.c b/test/dm/blk.c
index deccf05..8556cc7 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -217,3 +217,114 @@ static int dm_test_blk_iter(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_blk_iter, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test finding fixed/removable block devices */
+static int dm_test_blk_flags(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+
+ /* Iterate through devices without probing them */
+ ut_assertok(blk_find_first(BLKF_BOTH, &dev));
+ ut_assertnonnull(dev);
+ ut_asserteq_str("mmc2.blk", dev->name);
+
+ ut_assertok(blk_find_next(BLKF_BOTH, &dev));
+ ut_assertnonnull(dev);
+ ut_asserteq_str("mmc1.blk", dev->name);
+
+ ut_assertok(blk_find_next(BLKF_BOTH, &dev));
+ ut_assertnonnull(dev);
+ ut_asserteq_str("mmc0.blk", dev->name);
+
+ ut_asserteq(-ENODEV, blk_find_next(BLKF_BOTH, &dev));
+ ut_assertnull(dev);
+
+ /* All devices are removable until probed */
+ ut_asserteq(-ENODEV, blk_find_first(BLKF_FIXED, &dev));
+
+ ut_assertok(blk_find_first(BLKF_REMOVABLE, &dev));
+ ut_assertnonnull(dev);
+ ut_asserteq_str("mmc2.blk", dev->name);
+
+ /* Now probe them and iterate again */
+ ut_assertok(blk_first_device_err(BLKF_BOTH, &dev));
+ ut_assertnonnull(dev);
+ ut_asserteq_str("mmc2.blk", dev->name);
+
+ ut_assertok(blk_next_device_err(BLKF_BOTH, &dev));
+ ut_assertnonnull(dev);
+ ut_asserteq_str("mmc1.blk", dev->name);
+
+ ut_assertok(blk_next_device_err(BLKF_BOTH, &dev));
+ ut_assertnonnull(dev);
+ ut_asserteq_str("mmc0.blk", dev->name);
+
+ ut_asserteq(-ENODEV, blk_next_device_err(BLKF_BOTH, &dev));
+
+ /* Look only for fixed devices */
+ ut_assertok(blk_first_device_err(BLKF_FIXED, &dev));
+ ut_assertnonnull(dev);
+ ut_asserteq_str("mmc2.blk", dev->name);
+
+ ut_asserteq(-ENODEV, blk_next_device_err(BLKF_FIXED, &dev));
+
+ /* Look only for removable devices */
+ ut_assertok(blk_first_device_err(BLKF_REMOVABLE, &dev));
+ ut_assertnonnull(dev);
+ ut_asserteq_str("mmc1.blk", dev->name);
+
+ ut_assertok(blk_next_device_err(BLKF_REMOVABLE, &dev));
+ ut_assertnonnull(dev);
+ ut_asserteq_str("mmc0.blk", dev->name);
+
+ ut_asserteq(-ENODEV, blk_next_device_err(BLKF_REMOVABLE, &dev));
+
+ return 0;
+}
+DM_TEST(dm_test_blk_flags, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test blk_foreach() and friend */
+static int dm_test_blk_foreach(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ int found;
+
+ /* Test blk_foreach() - use the 3rd bytes of the name (0/1/2) */
+ found = 0;
+ blk_foreach(BLKF_BOTH, dev)
+ found |= 1 << dectoul(&dev->name[3], NULL);
+ ut_asserteq(7, found);
+
+ /* All devices are removable until probed */
+ found = 0;
+ blk_foreach(BLKF_FIXED, dev)
+ found |= 1 << dectoul(&dev->name[3], NULL);
+ ut_asserteq(0, found);
+
+ found = 0;
+ blk_foreach(BLKF_REMOVABLE, dev)
+ found |= 1 << dectoul(&dev->name[3], NULL);
+ ut_asserteq(7, found);
+
+ /* Now try again with the probing functions */
+ found = 0;
+ blk_foreach_probe(BLKF_BOTH, dev)
+ found |= 1 << dectoul(&dev->name[3], NULL);
+ ut_asserteq(7, found);
+ ut_asserteq(3, blk_count_devices(BLKF_BOTH));
+
+ found = 0;
+ blk_foreach_probe(BLKF_FIXED, dev)
+ found |= 1 << dectoul(&dev->name[3], NULL);
+ ut_asserteq(4, found);
+ ut_asserteq(1, blk_count_devices(BLKF_FIXED));
+
+ found = 0;
+ blk_foreach_probe(BLKF_REMOVABLE, dev)
+ found |= 1 << dectoul(&dev->name[3], NULL);
+ ut_asserteq(3, found);
+ ut_asserteq(2, blk_count_devices(BLKF_REMOVABLE));
+
+ return 0;
+}
+DM_TEST(dm_test_blk_foreach, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);