[PATCH 8/9] test: dm: sf: Check the block count after re-probing
Daniel Golle
daniel at makrotopia.org
Fri Nov 13 16:12:07 PST 2026
Add a test which removes and probes the SPI flash again, checking that
the number of child block devices stays the same. Compare with the
initial count so the test also works with CONFIG_MTD_BLOCK disabled.
Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
test/dm/sf.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/test/dm/sf.c b/test/dm/sf.c
index 0ec02ac694b..5c3a02d6f79 100644
--- a/test/dm/sf.c
+++ b/test/dm/sf.c
@@ -12,6 +12,7 @@
#include <spi_flash.h>
#include <asm/state.h>
#include <asm/test.h>
+#include <dm/device-internal.h>
#include <dm/test.h>
#include <dm/util.h>
#include <test/test.h>
@@ -106,3 +107,34 @@ static int dm_test_spi_flash_func(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_spi_flash_func, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+static int sf_count_blk(struct udevice *dev)
+{
+ struct udevice *child;
+ int count = 0;
+
+ list_for_each_entry(child, &dev->child_head, sibling_node)
+ if (device_get_uclass_id(child) == UCLASS_BLK)
+ count++;
+
+ return count;
+}
+
+/* Test that probing the flash again does not add a block device */
+static int dm_test_spi_flash_reprobe_blk(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ int count;
+
+ ut_assertok(uclass_first_device_err(UCLASS_SPI_FLASH, &dev));
+ count = sf_count_blk(dev);
+
+ ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
+ ut_assertok(device_probe(dev));
+ ut_asserteq(count, sf_count_blk(dev));
+
+ sandbox_sf_unbind_emul(state_get_current(), 0, 0);
+
+ return 0;
+}
+DM_TEST(dm_test_spi_flash_reprobe_blk, UTF_SCAN_PDATA | UTF_SCAN_FDT);
--
2.56.0
More information about the openwrt-devel
mailing list