mirror of
				https://xff.cz/git/u-boot/
				synced 2025-10-31 18:35:42 +01:00 
			
		
		
		
	test: Move 1MB.fat32.img and 2MB.ext2.img
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@chromium.org>
This commit is contained in:
		| @@ -8,6 +8,7 @@ | |||||||
| #include <blk.h> | #include <blk.h> | ||||||
| #include <dm.h> | #include <dm.h> | ||||||
| #include <fs.h> | #include <fs.h> | ||||||
|  | #include <os.h> | ||||||
| #include <sandbox_host.h> | #include <sandbox_host.h> | ||||||
| #include <asm/test.h> | #include <asm/test.h> | ||||||
| #include <dm/device-internal.h> | #include <dm/device-internal.h> | ||||||
| @@ -15,9 +16,6 @@ | |||||||
| #include <test/test.h> | #include <test/test.h> | ||||||
| #include <test/ut.h> | #include <test/ut.h> | ||||||
|  |  | ||||||
| static const char filename[] = "2MB.ext2.img"; |  | ||||||
| static const char filename2[] = "1MB.fat32.img"; |  | ||||||
|  |  | ||||||
| /* Basic test of host interface */ | /* Basic test of host interface */ | ||||||
| static int dm_test_host(struct unit_test_state *uts) | 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 udevice *dev, *part, *chk, *blk; | ||||||
| 	struct host_sb_plat *plat; | 	struct host_sb_plat *plat; | ||||||
| 	struct blk_desc *desc; | 	struct blk_desc *desc; | ||||||
|  | 	char fname[256]; | ||||||
| 	ulong mem_start; | 	ulong mem_start; | ||||||
| 	loff_t actwrite; | 	loff_t actwrite; | ||||||
|  |  | ||||||
| @@ -40,13 +39,15 @@ static int dm_test_host(struct unit_test_state *uts) | |||||||
| 	ut_assert(label != plat->label); | 	ut_assert(label != plat->label); | ||||||
| 	ut_asserteq(0, plat->fd); | 	ut_asserteq(0, plat->fd); | ||||||
|  |  | ||||||
| 	/* Attach a file created in test_host.py */ | 	/* Attach a file created in test_ut_dm_init */ | ||||||
| 	ut_assertok(host_attach_file(dev, filename)); | 	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_assertok(uclass_first_device_err(UCLASS_HOST, &chk)); | ||||||
| 	ut_asserteq_ptr(chk, dev); | 	ut_asserteq_ptr(chk, dev); | ||||||
|  |  | ||||||
| 	ut_asserteq_str(filename, plat->filename); | 	ut_asserteq_str(fname, plat->filename); | ||||||
| 	ut_assert(filename != plat->filename); | 	ut_assert(fname != plat->filename); | ||||||
| 	ut_assert(plat->fd != 0); | 	ut_assert(plat->fd != 0); | ||||||
|  |  | ||||||
| 	/* Get the block device */ | 	/* Get the block device */ | ||||||
| @@ -79,12 +80,14 @@ static int dm_test_host_dup(struct unit_test_state *uts) | |||||||
| { | { | ||||||
| 	static char label[] = "test"; | 	static char label[] = "test"; | ||||||
| 	struct udevice *dev, *chk; | 	struct udevice *dev, *chk; | ||||||
|  | 	char fname[256]; | ||||||
|  |  | ||||||
| 	ut_asserteq(0, uclass_id_count(UCLASS_HOST)); | 	ut_asserteq(0, uclass_id_count(UCLASS_HOST)); | ||||||
| 	ut_assertok(host_create_device(label, true, &dev)); | 	ut_assertok(host_create_device(label, true, &dev)); | ||||||
|  |  | ||||||
| 	/* Attach a file created in test_host.py */ | 	/* Attach a file created in test_ut_dm_init */ | ||||||
| 	ut_assertok(host_attach_file(dev, filename)); | 	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_assertok(uclass_first_device_err(UCLASS_HOST, &chk)); | ||||||
| 	ut_asserteq_ptr(chk, dev); | 	ut_asserteq_ptr(chk, dev); | ||||||
| 	ut_asserteq(1, uclass_id_count(UCLASS_HOST)); | 	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) */ | 	/* Create another device with the same label (should remove old one) */ | ||||||
| 	ut_assertok(host_create_device(label, true, &dev)); | 	ut_assertok(host_create_device(label, true, &dev)); | ||||||
|  |  | ||||||
| 	/* Attach a different file created in test_host.py */ | 	/* Attach a different file created in test_ut_dm_init */ | ||||||
| 	ut_assertok(host_attach_file(dev, filename2)); | 	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_assertok(uclass_first_device_err(UCLASS_HOST, &chk)); | ||||||
| 	ut_asserteq_ptr(chk, dev); | 	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 udevice *dev, *blk; | ||||||
| 	struct blk_desc *desc; | 	struct blk_desc *desc; | ||||||
|  | 	char fname[256]; | ||||||
|  |  | ||||||
| 	console_record_reset(); | 	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_nextline("dev       blocks label           path"); | ||||||
| 	ut_assert_console_end(); | 	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 */ | 	/* Check the -r flag worked */ | ||||||
| 	ut_assertok(uclass_first_device_err(UCLASS_HOST, &dev)); | 	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_assertok(run_command("host info", 0)); | ||||||
| 	ut_assert_nextline("dev       blocks label           path"); | 	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_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') */ | 	/* Check it is not removable (no '-r') */ | ||||||
| 	ut_assertok(uclass_next_device_err(&dev)); | 	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_assertok(run_command("host info", 0)); | ||||||
| 	ut_assert_nextline("dev       blocks label           path"); | 	ut_assert_nextline("dev       blocks label           path"); | ||||||
| 	ut_assert_nextline("  0         4096 test2           2MB.ext2.img"); | 	ut_assert_nextlinen("  0         4096 test2"); | ||||||
| 	ut_assert_nextline("  1         2048 fat             1MB.fat32.img"); | 	ut_assert_nextlinen("  1         2048 fat"); | ||||||
| 	ut_assert_console_end(); | 	ut_assert_console_end(); | ||||||
|  |  | ||||||
| 	ut_asserteq(1, run_command("host info test", 0)); | 	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_assertok(run_command("host info fat", 0)); | ||||||
| 	ut_assert_nextline("dev       blocks label           path"); | 	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(); | 	ut_assert_console_end(); | ||||||
|  |  | ||||||
| 	/* check 'host dev' */ | 	/* 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_assertok(run_command("host info", 0)); | ||||||
| 	ut_assert_nextline("dev       blocks label           path"); | 	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(); | 	ut_assert_console_end(); | ||||||
|  |  | ||||||
| 	return 0; | 	return 0; | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ import re | |||||||
| import os | import os | ||||||
| from subprocess import call, check_call, check_output, CalledProcessError | 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 |     """Create a file system volume | ||||||
|  |  | ||||||
|     Args: |     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' |         fs_type (str): File system type, e.g. 'ext4' | ||||||
|         size (int): Size of file system in bytes |         size (int): Size of file system in bytes | ||||||
|         prefix (str): Prefix string of volume's file name |         prefix (str): Prefix string of volume's file name | ||||||
|         use_src_dir (bool): true to put the file in the source directory |  | ||||||
|  |  | ||||||
|     Raises: |     Raises: | ||||||
|         CalledProcessError: if any error occurs when creating the filesystem |         CalledProcessError: if any error occurs when creating the filesystem | ||||||
|     """ |     """ | ||||||
|     fs_img = f'{prefix}.{fs_type}.img' |     fs_img = f'{prefix}.{fs_type}.img' | ||||||
|     fs_img = os.path.join(config.source_dir if use_src_dir |     fs_img = os.path.join(config.persistent_data_dir, fs_img) | ||||||
|                           else config.persistent_data_dir, fs_img) |  | ||||||
|  |  | ||||||
|     if fs_type == 'fat16': |     if fs_type == 'fat16': | ||||||
|         mkfs_opt = '-F 16' |         mkfs_opt = '-F 16' | ||||||
|   | |||||||
| @@ -319,10 +319,8 @@ def test_ut_dm_init(u_boot_console): | |||||||
|         u_boot_utils.run_and_log( |         u_boot_utils.run_and_log( | ||||||
|             u_boot_console, f'sfdisk {fn}', stdin=b'type=83') |             u_boot_console, f'sfdisk {fn}', stdin=b'type=83') | ||||||
|  |  | ||||||
|     fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB', |     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') | ||||||
|     fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB', |  | ||||||
|                     use_src_dir=True) |  | ||||||
|  |  | ||||||
| @pytest.mark.buildconfigspec('cmd_bootflow') | @pytest.mark.buildconfigspec('cmd_bootflow') | ||||||
| def test_ut_dm_init_bootstd(u_boot_console): | def test_ut_dm_init_bootstd(u_boot_console): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user