From 463bc7b82e7b3e8298d9cb81b5d03af8b48b2148 Mon Sep 17 00:00:00 2001 From: Richard Weinberger Date: Thu, 21 Nov 2024 15:32:07 -0700 Subject: test_fs: Allow running unprivileged There is no need to mount the filesystem on the host side. All filesystem tools offer some way to fill the fs without mounting. So, create the content on the host side, create and fill the fs without mounting. No more sudo or guestmount needed. This new approach works because the tests don't care about user IDs and no device files are needed. If user IDs start to matter it's still possible to use wrapper tools like fakeroot in future while filling the fs. Signed-off-by: Richard Weinberger Signed-off-by: Simon Glass Tested-by: Mattijs Korpershoek --- test/py/tests/test_fs/conftest.py | 175 ++++++++------------------------------ 1 file changed, 35 insertions(+), 140 deletions(-) (limited to 'test/py/tests/test_fs/conftest.py') diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index fca54488374..59342a6e3dd 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -156,64 +156,6 @@ def tool_is_in_path(tool): return True return False -fuse_mounted = False - -def mount_fs(fs_type, device, mount_point): - """Mount a volume. - - Args: - fs_type: File system type. - device: Volume's file name. - mount_point: Mount point. - - Return: - Nothing. - """ - global fuse_mounted - - try: - check_call('guestmount --pid-file guestmount.pid -a %s -m /dev/sda %s' - % (device, mount_point), shell=True) - fuse_mounted = True - return - except CalledProcessError: - fuse_mounted = False - - mount_opt = 'loop,rw' - if re.match('fat', fs_type): - mount_opt += ',umask=0000' - - check_call('sudo mount -o %s %s %s' - % (mount_opt, device, mount_point), shell=True) - - # may not be effective for some file systems - check_call('sudo chmod a+rw %s' % mount_point, shell=True) - -def umount_fs(mount_point): - """Unmount a volume. - - Args: - mount_point: Mount point. - - Return: - Nothing. - """ - if fuse_mounted: - call('sync') - call('guestunmount %s' % mount_point, shell=True) - - try: - with open("guestmount.pid", "r") as pidfile: - pid = int(pidfile.read()) - util.waitpid(pid, kill=True) - os.remove("guestmount.pid") - - except FileNotFoundError: - pass - - else: - call('sudo umount %s' % mount_point, shell=True) - # # Fixture for basic fs test # derived from test/fs/fs-test.sh @@ -241,14 +183,6 @@ def fs_obj_basic(request, u_boot_config): small_file = mount_dir + '/' + SMALL_FILE big_file = mount_dir + '/' + BIG_FILE - try: - - # 3GiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB') - except CalledProcessError as err: - pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) - return - try: check_call('mkdir -p %s' % mount_dir, shell=True) except CalledProcessError as err: @@ -256,15 +190,6 @@ def fs_obj_basic(request, u_boot_config): call('rm -f %s' % fs_img, shell=True) return - try: - # Mount the image so we can populate it. - mount_fs(fs_type, fs_img, mount_dir) - except CalledProcessError as err: - pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err)) - call('rmdir %s' % mount_dir, shell=True) - call('rm -f %s' % fs_img, shell=True) - return - try: # Create a subdirectory. check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) @@ -326,15 +251,20 @@ def fs_obj_basic(request, u_boot_config): % big_file, shell=True).decode() md5val.append(out.split()[0]) + try: + # 3GiB volume + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB', mount_dir) + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + except CalledProcessError as err: pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err)) - umount_fs(mount_dir) return else: - umount_fs(mount_dir) yield [fs_ubtype, fs_img, md5val] finally: - call('rmdir %s' % mount_dir, shell=True) + call('rm -rf %s' % mount_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -363,14 +293,6 @@ def fs_obj_ext(request, u_boot_config): min_file = mount_dir + '/' + MIN_FILE tmp_file = mount_dir + '/tmpfile' - try: - - # 128MiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') - except CalledProcessError as err: - pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) - return - try: check_call('mkdir -p %s' % mount_dir, shell=True) except CalledProcessError as err: @@ -378,15 +300,6 @@ def fs_obj_ext(request, u_boot_config): call('rm -f %s' % fs_img, shell=True) return - try: - # Mount the image so we can populate it. - mount_fs(fs_type, fs_img, mount_dir) - except CalledProcessError as err: - pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err)) - call('rmdir %s' % mount_dir, shell=True) - call('rm -f %s' % fs_img, shell=True) - return - try: # Create a test directory check_call('mkdir %s/dir1' % mount_dir, shell=True) @@ -427,15 +340,21 @@ def fs_obj_ext(request, u_boot_config): md5val.append(out.split()[0]) check_call('rm %s' % tmp_file, shell=True) + + try: + # 128MiB volume + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir) + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) - umount_fs(mount_dir) return else: - umount_fs(mount_dir) yield [fs_ubtype, fs_img, md5val] finally: - call('rmdir %s' % mount_dir, shell=True) + call('rm -rf %s' % mount_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -461,7 +380,7 @@ def fs_obj_mkdir(request, u_boot_config): try: # 128MiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', None) except: pytest.skip('Setup failed for filesystem: ' + fs_type) return @@ -492,14 +411,6 @@ def fs_obj_unlink(request, u_boot_config): mount_dir = u_boot_config.persistent_data_dir + '/mnt' - try: - - # 128MiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') - except CalledProcessError as err: - pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) - return - try: check_call('mkdir -p %s' % mount_dir, shell=True) except CalledProcessError as err: @@ -507,15 +418,6 @@ def fs_obj_unlink(request, u_boot_config): call('rm -f %s' % fs_img, shell=True) return - try: - # Mount the image so we can populate it. - mount_fs(fs_type, fs_img, mount_dir) - except CalledProcessError as err: - pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err)) - call('rmdir %s' % mount_dir, shell=True) - call('rm -f %s' % fs_img, shell=True) - return - try: # Test Case 1 & 3 check_call('mkdir %s/dir1' % mount_dir, shell=True) @@ -538,15 +440,20 @@ def fs_obj_unlink(request, u_boot_config): check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1' % mount_dir, shell=True) + try: + # 128MiB volume + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir) + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) - umount_fs(mount_dir) return else: - umount_fs(mount_dir) yield [fs_ubtype, fs_img] finally: - call('rmdir %s' % mount_dir, shell=True) + call('rm -rf %s' % mount_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -575,14 +482,6 @@ def fs_obj_symlink(request, u_boot_config): small_file = mount_dir + '/' + SMALL_FILE medium_file = mount_dir + '/' + MEDIUM_FILE - try: - - # 1GiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB') - except CalledProcessError as err: - pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) - return - try: check_call('mkdir -p %s' % mount_dir, shell=True) except CalledProcessError as err: @@ -590,15 +489,6 @@ def fs_obj_symlink(request, u_boot_config): call('rm -f %s' % fs_img, shell=True) return - try: - # Mount the image so we can populate it. - mount_fs(fs_type, fs_img, mount_dir) - except CalledProcessError as err: - pytest.skip('Mounting to folder failed for filesystem: ' + fs_type + '. {}'.format(err)) - call('rmdir %s' % mount_dir, shell=True) - call('rm -f %s' % fs_img, shell=True) - return - try: # Create a subdirectory. check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) @@ -621,15 +511,20 @@ def fs_obj_symlink(request, u_boot_config): % medium_file, shell=True).decode() md5val.extend([out.split()[0]]) + try: + # 1GiB volume + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB', mount_dir) + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) - umount_fs(mount_dir) return else: - umount_fs(mount_dir) yield [fs_ubtype, fs_img, md5val] finally: - call('rmdir %s' % mount_dir, shell=True) + call('rm -rf %s' % mount_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -665,7 +560,7 @@ def fs_obj_fat(request, u_boot_config): try: # the volume size depends on the filesystem - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, fs_size, f'{fs_size}', 1024) + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, fs_size, f'{fs_size}', None, 1024) except: pytest.skip('Setup failed for filesystem: ' + fs_type) return -- cgit v1.2.3 From c6504372c6d93228227ee75b1a869551934b3897 Mon Sep 17 00:00:00 2001 From: Richard Weinberger Date: Thu, 21 Nov 2024 15:32:08 -0700 Subject: test_fs: Rename mount dir to scratch Since no mounting happens anymore, rename the "mnt" directory to "scratch" and the related variables. Signed-off-by: Richard Weinberger Reviewed-by: Mattijs Korpershoek Signed-off-by: Simon Glass --- test/py/tests/test_fs/conftest.py | 66 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'test/py/tests/test_fs/conftest.py') diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index 59342a6e3dd..af2adaf1645 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -178,13 +178,13 @@ def fs_obj_basic(request, u_boot_config): fs_ubtype = fstype_to_ubname(fs_type) check_ubconfig(u_boot_config, fs_ubtype) - mount_dir = u_boot_config.persistent_data_dir + '/mnt' + scratch_dir = u_boot_config.persistent_data_dir + '/scratch' - small_file = mount_dir + '/' + SMALL_FILE - big_file = mount_dir + '/' + BIG_FILE + small_file = scratch_dir + '/' + SMALL_FILE + big_file = scratch_dir + '/' + BIG_FILE try: - check_call('mkdir -p %s' % mount_dir, shell=True) + check_call('mkdir -p %s' % scratch_dir, shell=True) except CalledProcessError as err: pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) call('rm -f %s' % fs_img, shell=True) @@ -192,7 +192,7 @@ def fs_obj_basic(request, u_boot_config): try: # Create a subdirectory. - check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) + check_call('mkdir %s/SUBDIR' % scratch_dir, shell=True) # Create big file in this image. # Note that we work only on the start 1MB, couple MBs in the 2GB range @@ -253,7 +253,7 @@ def fs_obj_basic(request, u_boot_config): try: # 3GiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB', mount_dir) + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB', scratch_dir) except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -264,7 +264,7 @@ def fs_obj_basic(request, u_boot_config): else: yield [fs_ubtype, fs_img, md5val] finally: - call('rm -rf %s' % mount_dir, shell=True) + call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -288,13 +288,13 @@ def fs_obj_ext(request, u_boot_config): fs_ubtype = fstype_to_ubname(fs_type) check_ubconfig(u_boot_config, fs_ubtype) - mount_dir = u_boot_config.persistent_data_dir + '/mnt' + scratch_dir = u_boot_config.persistent_data_dir + '/scratch' - min_file = mount_dir + '/' + MIN_FILE - tmp_file = mount_dir + '/tmpfile' + min_file = scratch_dir + '/' + MIN_FILE + tmp_file = scratch_dir + '/tmpfile' try: - check_call('mkdir -p %s' % mount_dir, shell=True) + check_call('mkdir -p %s' % scratch_dir, shell=True) except CalledProcessError as err: pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) call('rm -f %s' % fs_img, shell=True) @@ -302,7 +302,7 @@ def fs_obj_ext(request, u_boot_config): try: # Create a test directory - check_call('mkdir %s/dir1' % mount_dir, shell=True) + check_call('mkdir %s/dir1' % scratch_dir, shell=True) # Create a small file and calculate md5 check_call('dd if=/dev/urandom of=%s bs=1K count=20' @@ -343,7 +343,7 @@ def fs_obj_ext(request, u_boot_config): try: # 128MiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir) + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', scratch_dir) except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -354,7 +354,7 @@ def fs_obj_ext(request, u_boot_config): else: yield [fs_ubtype, fs_img, md5val] finally: - call('rm -rf %s' % mount_dir, shell=True) + call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -409,10 +409,10 @@ def fs_obj_unlink(request, u_boot_config): fs_ubtype = fstype_to_ubname(fs_type) check_ubconfig(u_boot_config, fs_ubtype) - mount_dir = u_boot_config.persistent_data_dir + '/mnt' + scratch_dir = u_boot_config.persistent_data_dir + '/scratch' try: - check_call('mkdir -p %s' % mount_dir, shell=True) + check_call('mkdir -p %s' % scratch_dir, shell=True) except CalledProcessError as err: pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) call('rm -f %s' % fs_img, shell=True) @@ -420,29 +420,29 @@ def fs_obj_unlink(request, u_boot_config): try: # Test Case 1 & 3 - check_call('mkdir %s/dir1' % mount_dir, shell=True) + check_call('mkdir %s/dir1' % scratch_dir, shell=True) check_call('dd if=/dev/urandom of=%s/dir1/file1 bs=1K count=1' - % mount_dir, shell=True) + % scratch_dir, shell=True) check_call('dd if=/dev/urandom of=%s/dir1/file2 bs=1K count=1' - % mount_dir, shell=True) + % scratch_dir, shell=True) # Test Case 2 - check_call('mkdir %s/dir2' % mount_dir, shell=True) + check_call('mkdir %s/dir2' % scratch_dir, shell=True) for i in range(0, 20): check_call('mkdir %s/dir2/0123456789abcdef%02x' - % (mount_dir, i), shell=True) + % (scratch_dir, i), shell=True) # Test Case 4 - check_call('mkdir %s/dir4' % mount_dir, shell=True) + check_call('mkdir %s/dir4' % scratch_dir, shell=True) # Test Case 5, 6 & 7 - check_call('mkdir %s/dir5' % mount_dir, shell=True) + check_call('mkdir %s/dir5' % scratch_dir, shell=True) check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1' - % mount_dir, shell=True) + % scratch_dir, shell=True) try: # 128MiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', mount_dir) + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x8000000, '128MB', scratch_dir) except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -453,7 +453,7 @@ def fs_obj_unlink(request, u_boot_config): else: yield [fs_ubtype, fs_img] finally: - call('rm -rf %s' % mount_dir, shell=True) + call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # @@ -477,13 +477,13 @@ def fs_obj_symlink(request, u_boot_config): fs_ubtype = fstype_to_ubname(fs_type) check_ubconfig(u_boot_config, fs_ubtype) - mount_dir = u_boot_config.persistent_data_dir + '/mnt' + scratch_dir = u_boot_config.persistent_data_dir + '/scratch' - small_file = mount_dir + '/' + SMALL_FILE - medium_file = mount_dir + '/' + MEDIUM_FILE + small_file = scratch_dir + '/' + SMALL_FILE + medium_file = scratch_dir + '/' + MEDIUM_FILE try: - check_call('mkdir -p %s' % mount_dir, shell=True) + check_call('mkdir -p %s' % scratch_dir, shell=True) except CalledProcessError as err: pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) call('rm -f %s' % fs_img, shell=True) @@ -491,7 +491,7 @@ def fs_obj_symlink(request, u_boot_config): try: # Create a subdirectory. - check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) + check_call('mkdir %s/SUBDIR' % scratch_dir, shell=True) # Create a small file in this image. check_call('dd if=/dev/urandom of=%s bs=1M count=1' @@ -513,7 +513,7 @@ def fs_obj_symlink(request, u_boot_config): try: # 1GiB volume - fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB', mount_dir) + fs_img = fs_helper.mk_fs(u_boot_config, fs_type, 0x40000000, '1GB', scratch_dir) except CalledProcessError as err: pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) return @@ -524,7 +524,7 @@ def fs_obj_symlink(request, u_boot_config): else: yield [fs_ubtype, fs_img, md5val] finally: - call('rm -rf %s' % mount_dir, shell=True) + call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) # -- cgit v1.2.3