From 606b926f9d76eaab11be2d95cfd7734644e1627c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 20 Oct 2022 18:22:54 -0600 Subject: dm: blk: Add udevice functions At present we have functions called blk_dread(), etc., which take a struct blk_desc * to refer to the block device. Add some functions which use udevice instead, since this is more in keeping with how driver model is supposed to work. Update one of the tests to use this. Note that it would be nice to update the functions in disk-uclass.c to use these new functions. However they are not quite the same. For example, disk_blk_read() adds the partition offset to 'start' when calling the cache read/fill functions, but does not with part_blk_read(), which does the addition itself. So as designed the code is duplicated. Signed-off-by: Simon Glass --- test/dm/usb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'test/dm/usb.c') diff --git a/test/dm/usb.c b/test/dm/usb.c index 5d6ceefce0b..445b21a560b 100644 --- a/test/dm/usb.c +++ b/test/dm/usb.c @@ -43,19 +43,24 @@ DM_TEST(dm_test_usb_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); */ static int dm_test_usb_flash(struct unit_test_state *uts) { - struct udevice *dev; - struct blk_desc *dev_desc; + struct blk_desc *dev_desc, *chk; + struct udevice *dev, *blk; char cmp[1024]; state_set_skip_delays(true); ut_assertok(usb_init()); ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev)); ut_assertok(blk_get_device_by_str("usb", "0", &dev_desc)); + chk = blk_get_by_device(dev); + ut_asserteq_ptr(chk, dev_desc); + + ut_assertok(device_find_first_child_by_uclass(dev, UCLASS_BLK, &blk)); + ut_asserteq_ptr(chk, blk_get_by_device(dev)); /* Read a few blocks and look for the string we expect */ ut_asserteq(512, dev_desc->blksz); memset(cmp, '\0', sizeof(cmp)); - ut_asserteq(2, blk_dread(dev_desc, 0, 2, cmp)); + ut_asserteq(2, blk_read(blk, 0, 2, cmp)); ut_assertok(strcmp(cmp, "this is a test")); ut_assertok(usb_stop()); -- cgit v1.2.3 From 2ff3db3a1c5ef128a4f33c22d7be8ee37fca3613 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 20 Oct 2022 18:22:55 -0600 Subject: usb: Update the test to cover reading and writing Add test coverage for blk_write() as well. The blk_erase() is not tested for now as the USB stor interface does not support erase. Signed-off-by: Simon Glass --- test/dm/usb.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'test/dm/usb.c') diff --git a/test/dm/usb.c b/test/dm/usb.c index 445b21a560b..7671ef156d8 100644 --- a/test/dm/usb.c +++ b/test/dm/usb.c @@ -61,7 +61,24 @@ static int dm_test_usb_flash(struct unit_test_state *uts) ut_asserteq(512, dev_desc->blksz); memset(cmp, '\0', sizeof(cmp)); ut_asserteq(2, blk_read(blk, 0, 2, cmp)); - ut_assertok(strcmp(cmp, "this is a test")); + ut_asserteq_str("this is a test", cmp); + + strcpy(cmp, "another test"); + ut_asserteq(1, blk_write(blk, 1, 1, cmp)); + + memset(cmp, '\0', sizeof(cmp)); + ut_asserteq(2, blk_read(blk, 0, 2, cmp)); + ut_asserteq_str("this is a test", cmp); + ut_asserteq_str("another test", cmp + 512); + + memset(cmp, '\0', sizeof(cmp)); + ut_asserteq(1, blk_write(blk, 1, 1, cmp)); + + memset(cmp, '\0', sizeof(cmp)); + ut_asserteq(2, blk_read(blk, 0, 2, cmp)); + ut_asserteq_str("this is a test", cmp); + ut_asserteq_str("", cmp + 512); + ut_assertok(usb_stop()); return 0; -- cgit v1.2.3