[PATCH 16/24] test: Move 1MB.fat32.img and 2MB.ext2.img

Simon Glass sjg at chromium.org
Sun Aug 13 16:26:44 CEST 2023


These are currently created in the source directory, which is not ideal.
Move them to the persistent-data directory instead. Update the test so
skip validating the filename, since it now includes a full path.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 test/dm/host.c             | 44 ++++++++++++++++++++++----------------
 test/py/tests/fs_helper.py |  6 ++----
 test/py/tests/test_ut.py   |  6 ++----
 3 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/test/dm/host.c b/test/dm/host.c
index 355ba7770afa..85f21f9839e2 100644
--- a/test/dm/host.c
+++ b/test/dm/host.c
@@ -8,6 +8,7 @@
 #include <blk.h>
 #include <dm.h>
 #include <fs.h>
+#include <os.h>
 #include <sandbox_host.h>
 #include <asm/test.h>
 #include <dm/device-internal.h>
@@ -15,9 +16,6 @@
 #include <test/test.h>
 #include <test/ut.h>
 
-static const char filename[] = "2MB.ext2.img";
-static const char filename2[] = "1MB.fat32.img";
-
 /* Basic test of host interface */
 static int dm_test_host(struct unit_test_state *uts)
 {
@@ -25,6 +23,7 @@ static int dm_test_host(struct unit_test_state *uts)
 	struct udevice *dev, *part, *chk, *blk;
 	struct host_sb_plat *plat;
 	struct blk_desc *desc;
+	char fname[256];
 	ulong mem_start;
 	loff_t actwrite;
 
@@ -40,13 +39,15 @@ static int dm_test_host(struct unit_test_state *uts)
 	ut_assert(label != plat->label);
 	ut_asserteq(0, plat->fd);
 
-	/* Attach a file created in test_host.py */
-	ut_assertok(host_attach_file(dev, filename));
+	/* Attach a file created in test_ut_dm_init */
+	ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
+
+	ut_assertok(host_attach_file(dev, fname));
 	ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
 	ut_asserteq_ptr(chk, dev);
 
-	ut_asserteq_str(filename, plat->filename);
-	ut_assert(filename != plat->filename);
+	ut_asserteq_str(fname, plat->filename);
+	ut_assert(fname != plat->filename);
 	ut_assert(plat->fd != 0);
 
 	/* Get the block device */
@@ -79,12 +80,14 @@ static int dm_test_host_dup(struct unit_test_state *uts)
 {
 	static char label[] = "test";
 	struct udevice *dev, *chk;
+	char fname[256];
 
 	ut_asserteq(0, uclass_id_count(UCLASS_HOST));
 	ut_assertok(host_create_device(label, true, &dev));
 
-	/* Attach a file created in test_host.py */
-	ut_assertok(host_attach_file(dev, filename));
+	/* Attach a file created in test_ut_dm_init */
+	ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
+	ut_assertok(host_attach_file(dev, fname));
 	ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
 	ut_asserteq_ptr(chk, dev);
 	ut_asserteq(1, uclass_id_count(UCLASS_HOST));
@@ -92,8 +95,10 @@ static int dm_test_host_dup(struct unit_test_state *uts)
 	/* Create another device with the same label (should remove old one) */
 	ut_assertok(host_create_device(label, true, &dev));
 
-	/* Attach a different file created in test_host.py */
-	ut_assertok(host_attach_file(dev, filename2));
+	/* Attach a different file created in test_ut_dm_init */
+	ut_assertok(os_persistent_file(fname, sizeof(fname), "1MB.fat32.img"));
+	ut_assertok(host_attach_file(dev, fname));
+
 	ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
 	ut_asserteq_ptr(chk, dev);
 
@@ -109,6 +114,7 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
 {
 	struct udevice *dev, *blk;
 	struct blk_desc *desc;
+	char fname[256];
 
 	console_record_reset();
 
@@ -117,7 +123,8 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
 	ut_assert_nextline("dev       blocks label           path");
 	ut_assert_console_end();
 
-	ut_assertok(run_commandf("host bind -r test2 %s", filename));
+	ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
+	ut_assertok(run_commandf("host bind -r test2 %s", fname));
 
 	/* Check the -r flag worked */
 	ut_assertok(uclass_first_device_err(UCLASS_HOST, &dev));
@@ -127,10 +134,11 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
 
 	ut_assertok(run_command("host info", 0));
 	ut_assert_nextline("dev       blocks label           path");
-	ut_assert_nextline("  0         4096 test2           2MB.ext2.img");
+	ut_assert_nextlinen("  0         4096 test2");
 	ut_assert_console_end();
 
-	ut_assertok(run_commandf("host bind fat %s", filename2));
+	ut_assertok(os_persistent_file(fname, sizeof(fname), "1MB.fat32.img"));
+	ut_assertok(run_commandf("host bind fat %s", fname));
 
 	/* Check it is not removable (no '-r') */
 	ut_assertok(uclass_next_device_err(&dev));
@@ -140,8 +148,8 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
 
 	ut_assertok(run_command("host info", 0));
 	ut_assert_nextline("dev       blocks label           path");
-	ut_assert_nextline("  0         4096 test2           2MB.ext2.img");
-	ut_assert_nextline("  1         2048 fat             1MB.fat32.img");
+	ut_assert_nextlinen("  0         4096 test2");
+	ut_assert_nextlinen("  1         2048 fat");
 	ut_assert_console_end();
 
 	ut_asserteq(1, run_command("host info test", 0));
@@ -150,7 +158,7 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
 
 	ut_assertok(run_command("host info fat", 0));
 	ut_assert_nextline("dev       blocks label           path");
-	ut_assert_nextline("  1         2048 fat             1MB.fat32.img");
+	ut_assert_nextlinen("  1         2048 fat");
 	ut_assert_console_end();
 
 	/* check 'host dev' */
@@ -187,7 +195,7 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
 
 	ut_assertok(run_command("host info", 0));
 	ut_assert_nextline("dev       blocks label           path");
-	ut_assert_nextline("  1         2048 fat             1MB.fat32.img");
+	ut_assert_nextlinen("  1         2048 fat");
 	ut_assert_console_end();
 
 	return 0;
diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
index 17151bcd08ec..9882ddb1daa5 100644
--- a/test/py/tests/fs_helper.py
+++ b/test/py/tests/fs_helper.py
@@ -9,7 +9,7 @@ import re
 import os
 from subprocess import call, check_call, check_output, CalledProcessError
 
-def mk_fs(config, fs_type, size, prefix, use_src_dir=False):
+def mk_fs(config, fs_type, size, prefix):
     """Create a file system volume
 
     Args:
@@ -17,14 +17,12 @@ def mk_fs(config, fs_type, size, prefix, use_src_dir=False):
         fs_type (str): File system type, e.g. 'ext4'
         size (int): Size of file system in bytes
         prefix (str): Prefix string of volume's file name
-        use_src_dir (bool): true to put the file in the source directory
 
     Raises:
         CalledProcessError: if any error occurs when creating the filesystem
     """
     fs_img = f'{prefix}.{fs_type}.img'
-    fs_img = os.path.join(config.source_dir if use_src_dir
-                          else config.persistent_data_dir, fs_img)
+    fs_img = os.path.join(config.persistent_data_dir, fs_img)
 
     if fs_type == 'fat16':
         mkfs_opt = '-F 16'
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index aa1d477cd565..3cc41c2ffb13 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -317,10 +317,8 @@ def test_ut_dm_init(u_boot_console):
         u_boot_utils.run_and_log(
             u_boot_console, f'sfdisk {fn}', stdin=b'type=83')
 
-    fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB',
-                    use_src_dir=True)
-    fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB',
-                    use_src_dir=True)
+    fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB')
+    fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB')
 
 @pytest.mark.buildconfigspec('cmd_bootflow')
 def test_ut_dm_init_bootstd(u_boot_console):
-- 
2.41.0.640.ga95def55d0-goog



More information about the U-Boot mailing list