[PATCH 11/11] test: boot: imagemap: reset driver-model state between tests

Simon Glass sjg at chromium.org
Thu Oct 1 09:00:40 PDT 2026


Hi Daniel,

On 2026-09-29T00:04:16, Daniel Golle <daniel at makrotopia.org> wrote:
> test: boot: imagemap: reset driver-model state between tests
>
> The tests bind and probe devices under dm_root() and the storage tests
> depend on real driver-model state, but none of them asks for the DM
> init and uninit the test framework provides. A test that fails before
> imagemap_cleanup() therefore leaves its bound device behind, and the next
> one trips over the name clash in device_bind_driver().
>
> Pass UTF_DM throughout, and UTF_SCAN_FDT for the two tests that walk
> device-tree partitions. Those two are also marked UTF_LIVE_TREE: they
> drive mtd_probe_devices(), which cannot parse the partitions of a master
> bound from a flat tree.

I'm not sure about this. add_mtd_partitions_of() reads the partitions
with the ofnode API (mtd_get_ofnode(), ofnode_find_subnode(),
ofnode_for_each_subnode()), so I would expect it to work with a flat
tree too. What actually fails in the flat-tree run? If the cause is
something else, such as the static old_mtdparts /
mtd_dev_list_updated() state in mtd_probe_devices() or MTD state left
over from the live-tree run, please can you describe that instead?
Otherwise UTF_LIVE_TREE just hides the problem.

>
> Fixes: 05c1fbbfa79f ("test: boot: add imagemap unit tests")
> Signed-off-by: Daniel Golle <daniel at makrotopia.org>
>
> test/boot/imagemap.c | 28 +++++++++++++++-------------
>  1 file changed, 15 insertions(+), 13 deletions(-)

> diff --git a/test/boot/imagemap.c b/test/boot/imagemap.c
> @@ -649,5 +650,6 @@ static int imagemap_test_ubiblock(struct unit_test_state *uts)
> -IMAGEMAP_TEST(imagemap_test_ubiblock, 0);
> +
> +IMAGEMAP_TEST(imagemap_test_ubiblock, UTF_DM | UTF_SCAN_FDT | UTF_LIVE_TREE);

The motivation is a test that fails part-way, but for this test UTF_DM
makes that case worse. If an assertion fails after ubi_part(), the
test returns without calling ubi_detach(), and dm_test_post_run() then
destroys every uclass. That frees the sand-nand device and its chips,
which UBI still points to, as well as the ubi_blk device.
nand_unregister() cannot delete the MTD either, since UBI holds a use
count. Without UTF_DM, the leading ubi_detach() from patch 10 would
clean up properly.

Please can you make sure every failure after ubi_part() calls
imagemap_cleanup(), free() and ubi_detach() (see my comment on patch
10), so the DM teardown never runs while UBI is still attached?
Alternatively, keep this test out of UTF_DM. What do you think?

> diff --git a/test/boot/imagemap.c b/test/boot/imagemap.c
> @@ -571,7 +571,8 @@ static int imagemap_test_mtd_blk(struct unit_test_state *uts)
> -IMAGEMAP_TEST(imagemap_test_mtd_blk, 0);
> +
> +IMAGEMAP_TEST(imagemap_test_mtd_blk, UTF_DM | UTF_SCAN_FDT | UTF_LIVE_TREE);

Regards,
Simon



More information about the openwrt-devel mailing list