All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] test_fs: Allow running unprivileged
@ 2024-08-02  9:33 Richard Weinberger
  2024-08-02  9:33 ` [PATCH 2/3] test_fs: Rename mount dir to scratch Richard Weinberger
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Richard Weinberger @ 2024-08-02  9:33 UTC (permalink / raw)
  To: u-boot
  Cc: upstream+uboot, francis.laniel, glaroque, mkorpershoek, sjg,
	christian.taedcke, trini, Richard Weinberger

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 <richard@nod.at>
---
 test/py/tests/fs_helper.py        |  11 +-
 test/py/tests/test_fs/conftest.py | 175 ++++++------------------------
 test/py/tests/test_ut.py          |   4 +-
 3 files changed, 47 insertions(+), 143 deletions(-)

diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
index 380f4c4dca..154e01264c 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, size_gran = 0x100000):
+def mk_fs(config, fs_type, size, prefix, src_dir, size_gran = 0x100000):
     """Create a file system volume
 
     Args:
@@ -39,6 +39,13 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
     else:
         fs_lnxtype = fs_type
 
+    if src_dir:
+        if fs_lnxtype == 'ext4':
+            mkfs_opt = mkfs_opt + ' -d ' + src_dir
+        elif fs_lnxtype != 'vfat':
+            # Implement src_dir for this fs!
+            raise
+
     count = (size + size_gran - 1) // size_gran
 
     # Some distributions do not add /sbin to the default PATH, where mkfs lives
@@ -55,6 +62,8 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
                                       shell=True).decode()
             if 'metadata_csum' in sb_content:
                 check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True)
+        elif fs_lnxtype == 'vfat' and src_dir:
+            check_call(f'mcopy -i {fs_img} -vsmpQ {src_dir}/* ::/', shell=True)
         return fs_img
     except CalledProcessError:
         call(f'rm -f {fs_img}', shell=True)
diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
index fca5448837..59342a6e3d 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
diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index 05e1583059..3cef6c29fa 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -538,8 +538,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')
-    fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB')
+    fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB', None)
+    fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB', None)
 
     mmc_dev = 6
     fn = os.path.join(u_boot_console.config.source_dir, f'mmc{mmc_dev}.img')
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/3] test_fs: Rename mount dir to scratch
  2024-08-02  9:33 [PATCH 1/3] test_fs: Allow running unprivileged Richard Weinberger
@ 2024-08-02  9:33 ` Richard Weinberger
  2024-08-06 15:32   ` Mattijs Korpershoek
  2024-08-02  9:33 ` [PATCH 3/3] test_ut: Allow running unprivileged Richard Weinberger
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 14+ messages in thread
From: Richard Weinberger @ 2024-08-02  9:33 UTC (permalink / raw)
  To: u-boot
  Cc: upstream+uboot, francis.laniel, glaroque, mkorpershoek, sjg,
	christian.taedcke, trini, Richard Weinberger

Since no mounting happens anymore, rename the "mnt"
directory to "scratch" and the related variables.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 test/py/tests/test_fs/conftest.py | 66 +++++++++++++++----------------
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
index 59342a6e3d..af2adaf164 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)
 
 #
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/3] test_ut: Allow running unprivileged
  2024-08-02  9:33 [PATCH 1/3] test_fs: Allow running unprivileged Richard Weinberger
  2024-08-02  9:33 ` [PATCH 2/3] test_fs: Rename mount dir to scratch Richard Weinberger
@ 2024-08-02  9:33 ` Richard Weinberger
  2024-08-06 15:29 ` [PATCH 1/3] test_fs: " Mattijs Korpershoek
  2024-08-15 22:14 ` Tom Rini
  3 siblings, 0 replies; 14+ messages in thread
From: Richard Weinberger @ 2024-08-02  9:33 UTC (permalink / raw)
  To: u-boot
  Cc: upstream+uboot, francis.laniel, glaroque, mkorpershoek, sjg,
	christian.taedcke, trini, Richard Weinberger

Like for test_fs, no need to mess with loop mounts.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 test/py/tests/test_ut.py | 93 +++++++++++++++-------------------------
 1 file changed, 34 insertions(+), 59 deletions(-)

diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index 3cef6c29fa..41003c14ff 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -2,7 +2,6 @@
 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
 
 import collections
-import getpass
 import gzip
 import os
 import os.path
@@ -22,8 +21,8 @@ def mkdir_cond(dirname):
     if not os.path.exists(dirname):
         os.mkdir(dirname)
 
-def setup_image(cons, mmc_dev, part_type, second_part=False):
-    """Create a 20MB disk image with a single partition
+def setup_image(cons, mmc_dev, part_type, img_size, second_part=False):
+    """Create a img_size sized disk image with a single partition
 
     Args:
         cons (ConsoleBase): Console to use
@@ -32,45 +31,18 @@ def setup_image(cons, mmc_dev, part_type, second_part=False):
         second_part (bool): True to contain a small second partition
 
     Returns:
-        tuple:
-            str: Filename of MMC image
-            str: Directory name of 'mnt' directory
+        str: Filename of MMC image
     """
     fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img')
-    mnt = os.path.join(cons.config.persistent_data_dir, 'mnt')
-    mkdir_cond(mnt)
 
-    spec = f'type={part_type:x}, size=18M, bootable'
+    spec = f'type={part_type:x}, size={img_size - 2}M, start=1M, bootable'
     if second_part:
         spec += '\ntype=c'
 
-    u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname)
-    u_boot_utils.run_and_log(cons, 'sudo sfdisk %s' % fname,
+    u_boot_utils.run_and_log(cons, f'qemu-img create {fname} {img_size}M')
+    u_boot_utils.run_and_log(cons, 'sfdisk %s' % fname,
                              stdin=spec.encode('utf-8'))
-    return fname, mnt
-
-def mount_image(cons, fname, mnt, fstype):
-    """Create a filesystem and mount it on partition 1
-
-    Args:
-        cons (ConsoleBase): Console to use
-        fname (str): Filename of MMC image
-        mnt (str): Directory name of 'mnt' directory
-        fstype (str): Filesystem type ('vfat' or 'ext4')
-
-    Returns:
-        str: Name of loop device used
-    """
-    out = u_boot_utils.run_and_log(cons, 'sudo losetup --show -f -P %s' % fname)
-    loop = out.strip()
-    part = f'{loop}p1'
-    u_boot_utils.run_and_log(cons, f'sudo mkfs.{fstype} {part}')
-    opts = ''
-    if fstype == 'vfat':
-         opts += f' -o uid={os.getuid()},gid={os.getgid()}'
-    u_boot_utils.run_and_log(cons, f'sudo mount -o loop {part} {mnt}{opts}')
-    u_boot_utils.run_and_log(cons, f'sudo chown {getpass.getuser()} {mnt}')
-    return loop
+    return fname
 
 def copy_prepared_image(cons, mmc_dev, fname):
     """Use a prepared image since we cannot create one
@@ -92,14 +64,12 @@ def setup_bootmenu_image(cons):
     This is modelled on Armbian 22.08 Jammy
     """
     mmc_dev = 4
-    fname, mnt = setup_image(cons, mmc_dev, 0x83)
+    fname = setup_image(cons, mmc_dev, 0x83, 20)
 
-    loop = None
-    mounted = False
     complete = False
     try:
-        loop = mount_image(cons, fname, mnt, 'ext4')
-        mounted = True
+        scratch_dir = os.path.join(cons.config.persistent_data_dir, 'scratch')
+        mkdir_cond(scratch_dir)
 
         vmlinux = 'Image'
         initrd = 'uInitrd'
@@ -178,7 +148,7 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
 # Recompile with:
 # mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
 ''' % (mmc_dev)
-        bootdir = os.path.join(mnt, 'boot')
+        bootdir = os.path.join(scratch_dir, 'boot')
         mkdir_cond(bootdir)
         cmd_fname = os.path.join(bootdir, 'boot.cmd')
         scr_fname = os.path.join(bootdir, 'boot.scr')
@@ -209,16 +179,19 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
 
         u_boot_utils.run_and_log(
             cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}')
+
+        fsfile = 'ext18M.img'
+        u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
+        u_boot_utils.run_and_log(cons, f'mkfs.ext4 {fsfile} -d {scratch_dir}')
+        u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
         complete = True
 
     except ValueError as exc:
         print('Falled to create image, failing back to prepared copy: %s',
               str(exc))
     finally:
-        if mounted:
-            u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
-        if loop:
-            u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
+        u_boot_utils.run_and_log(cons, 'rm -rf %s' % scratch_dir)
+        u_boot_utils.run_and_log(cons, 'rm -f %s' % fsfile)
 
     if not complete:
         copy_prepared_image(cons, mmc_dev, fname)
@@ -226,14 +199,12 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
 def setup_bootflow_image(cons):
     """Create a 20MB disk image with a single FAT partition"""
     mmc_dev = 1
-    fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True)
+    fname = setup_image(cons, mmc_dev, 0xc, 20, second_part=True)
 
-    loop = None
-    mounted = False
     complete = False
     try:
-        loop = mount_image(cons, fname, mnt, 'vfat')
-        mounted = True
+        scratch_dir = os.path.join(cons.config.persistent_data_dir, 'scratch')
+        mkdir_cond(scratch_dir)
 
         vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl'
         initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img'
@@ -251,7 +222,7 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
         append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB
         fdtdir /%s/
         initrd /%s''' % (vmlinux, dtbdir, initrd)
-        ext = os.path.join(mnt, 'extlinux')
+        ext = os.path.join(scratch_dir, 'extlinux')
         mkdir_cond(ext)
 
         with open(os.path.join(ext, 'extlinux.conf'), 'w') as fd:
@@ -261,25 +232,29 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
         with open(inf, 'wb') as fd:
             fd.write(gzip.compress(b'vmlinux'))
         u_boot_utils.run_and_log(cons, 'mkimage -f auto -d %s %s' %
-                                 (inf, os.path.join(mnt, vmlinux)))
+                                 (inf, os.path.join(scratch_dir, vmlinux)))
 
-        with open(os.path.join(mnt, initrd), 'w') as fd:
+        with open(os.path.join(scratch_dir, initrd), 'w') as fd:
             print('initrd', file=fd)
 
-        mkdir_cond(os.path.join(mnt, dtbdir))
+        mkdir_cond(os.path.join(scratch_dir, dtbdir))
 
-        dtb_file = os.path.join(mnt, '%s/sandbox.dtb' % dtbdir)
+        dtb_file = os.path.join(scratch_dir, '%s/sandbox.dtb' % dtbdir)
         u_boot_utils.run_and_log(
             cons, 'dtc -o %s' % dtb_file, stdin=b'/dts-v1/; / {};')
+
+        fsfile = 'vfat18M.img'
+        u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
+        u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}')
+        u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -i {fsfile} {scratch_dir}/* ::/'])
+        u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
         complete = True
     except ValueError as exc:
         print('Falled to create image, failing back to prepared copy: %s',
               str(exc))
     finally:
-        if mounted:
-            u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
-        if loop:
-            u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
+        u_boot_utils.run_and_log(cons, 'rm -rf %s' % scratch_dir)
+        u_boot_utils.run_and_log(cons, 'rm -f %s' % fsfile)
 
     if not complete:
         copy_prepared_image(cons, mmc_dev, fname)
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] test_fs: Allow running unprivileged
  2024-08-02  9:33 [PATCH 1/3] test_fs: Allow running unprivileged Richard Weinberger
  2024-08-02  9:33 ` [PATCH 2/3] test_fs: Rename mount dir to scratch Richard Weinberger
  2024-08-02  9:33 ` [PATCH 3/3] test_ut: Allow running unprivileged Richard Weinberger
@ 2024-08-06 15:29 ` Mattijs Korpershoek
  2024-08-15 22:14 ` Tom Rini
  3 siblings, 0 replies; 14+ messages in thread
From: Mattijs Korpershoek @ 2024-08-06 15:29 UTC (permalink / raw)
  To: Richard Weinberger, u-boot
  Cc: upstream+uboot, francis.laniel, glaroque, sjg, christian.taedcke,
	trini, Richard Weinberger

Hi Richard,

Thank you for the patch.

On ven., août 02, 2024 at 11:33, Richard Weinberger <richard@nod.at> wrote:

> 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 <richard@nod.at>

Running:
$ ./test/py/test.py --bd sandbox --build -k test_fs

On master: 100 skipped
With the series applied: no more tests are skipped

Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

> ---
>  test/py/tests/fs_helper.py        |  11 +-
>  test/py/tests/test_fs/conftest.py | 175 ++++++------------------------
>  test/py/tests/test_ut.py          |   4 +-
>  3 files changed, 47 insertions(+), 143 deletions(-)
>
> diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
> index 380f4c4dca..154e01264c 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, size_gran = 0x100000):
> +def mk_fs(config, fs_type, size, prefix, src_dir, size_gran = 0x100000):
>      """Create a file system volume
>  
>      Args:
> @@ -39,6 +39,13 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
>      else:
>          fs_lnxtype = fs_type
>  
> +    if src_dir:
> +        if fs_lnxtype == 'ext4':
> +            mkfs_opt = mkfs_opt + ' -d ' + src_dir
> +        elif fs_lnxtype != 'vfat':
> +            # Implement src_dir for this fs!
> +            raise
> +
>      count = (size + size_gran - 1) // size_gran
>  
>      # Some distributions do not add /sbin to the default PATH, where mkfs lives
> @@ -55,6 +62,8 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
>                                        shell=True).decode()
>              if 'metadata_csum' in sb_content:
>                  check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True)
> +        elif fs_lnxtype == 'vfat' and src_dir:
> +            check_call(f'mcopy -i {fs_img} -vsmpQ {src_dir}/* ::/', shell=True)
>          return fs_img
>      except CalledProcessError:
>          call(f'rm -f {fs_img}', shell=True)
> diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
> index fca5448837..59342a6e3d 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
> diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
> index 05e1583059..3cef6c29fa 100644
> --- a/test/py/tests/test_ut.py
> +++ b/test/py/tests/test_ut.py
> @@ -538,8 +538,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')
> -    fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB')
> +    fs_helper.mk_fs(u_boot_console.config, 'ext2', 0x200000, '2MB', None)
> +    fs_helper.mk_fs(u_boot_console.config, 'fat32', 0x100000, '1MB', None)
>  
>      mmc_dev = 6
>      fn = os.path.join(u_boot_console.config.source_dir, f'mmc{mmc_dev}.img')
> -- 
> 2.35.3

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/3] test_fs: Rename mount dir to scratch
  2024-08-02  9:33 ` [PATCH 2/3] test_fs: Rename mount dir to scratch Richard Weinberger
@ 2024-08-06 15:32   ` Mattijs Korpershoek
  2024-08-06 16:42     ` Richard Weinberger
  0 siblings, 1 reply; 14+ messages in thread
From: Mattijs Korpershoek @ 2024-08-06 15:32 UTC (permalink / raw)
  To: Richard Weinberger, u-boot
  Cc: upstream+uboot, francis.laniel, glaroque, sjg, christian.taedcke,
	trini, Richard Weinberger

Hi Richard,

Thank you for the patch.

On ven., août 02, 2024 at 11:33, Richard Weinberger <richard@nod.at> wrote:

> Since no mounting happens anymore, rename the "mnt"
> directory to "scratch" and the related variables.
>
> Signed-off-by: Richard Weinberger <richard@nod.at>
> ---
>  test/py/tests/test_fs/conftest.py | 66 +++++++++++++++----------------
>  1 file changed, 33 insertions(+), 33 deletions(-)
>
> diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
> index 59342a6e3d..af2adaf164 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))

Should we update the error message here as well?
'Preparing scratch folder failed for filestem: '

Same is true for similar messages below.

With that fixed:

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

>          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)
>  
>  #
> -- 
> 2.35.3

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/3] test_fs: Rename mount dir to scratch
  2024-08-06 15:32   ` Mattijs Korpershoek
@ 2024-08-06 16:42     ` Richard Weinberger
  0 siblings, 0 replies; 14+ messages in thread
From: Richard Weinberger @ 2024-08-06 16:42 UTC (permalink / raw)
  To: Richard Weinberger, u-boot, upstream, Mattijs Korpershoek
  Cc: upstream+uboot, francis.laniel, glaroque, sjg, christian.taedcke,
	trini

Mattijs,

Am Dienstag, 6. August 2024, 17:32:58 CEST schrieb Mattijs Korpershoek:
> Hi Richard,
> 
> Thank you for the patch.
> 
> On ven., août 02, 2024 at 11:33, Richard Weinberger <richard@nod.at> wrote:
> 
> > Since no mounting happens anymore, rename the "mnt"
> > directory to "scratch" and the related variables.
> >
> > Signed-off-by: Richard Weinberger <richard@nod.at>
> > ---
> >  test/py/tests/test_fs/conftest.py | 66 +++++++++++++++----------------
> >  1 file changed, 33 insertions(+), 33 deletions(-)
> >
> > diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
> > index 59342a6e3d..af2adaf164 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))
> 
> Should we update the error message here as well?

Sure, thanks for pointing out!
I'll send a v2.

Thanks,
//richard

-- 
​​​​​sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT
UID/VAT Nr: ATU 66964118 | FN: 374287y



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] test_fs: Allow running unprivileged
  2024-08-02  9:33 [PATCH 1/3] test_fs: Allow running unprivileged Richard Weinberger
                   ` (2 preceding siblings ...)
  2024-08-06 15:29 ` [PATCH 1/3] test_fs: " Mattijs Korpershoek
@ 2024-08-15 22:14 ` Tom Rini
  2024-08-18  9:11   ` Richard Weinberger
  3 siblings, 1 reply; 14+ messages in thread
From: Tom Rini @ 2024-08-15 22:14 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: u-boot, upstream+uboot, francis.laniel, glaroque, mkorpershoek,
	sjg, christian.taedcke

[-- Attachment #1: Type: text/plain, Size: 2221 bytes --]

On Fri, Aug 02, 2024 at 11:33:20AM +0200, Richard Weinberger wrote:

> 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 <richard@nod.at>
> Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> ---
>  test/py/tests/fs_helper.py        |  11 +-
>  test/py/tests/test_fs/conftest.py | 175 ++++++------------------------
>  test/py/tests/test_ut.py          |   4 +-
>  3 files changed, 47 insertions(+), 143 deletions(-)
> 
> diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
> index 380f4c4dca..154e01264c 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, size_gran = 0x100000):
> +def mk_fs(config, fs_type, size, prefix, src_dir, size_gran = 0x100000):
>      """Create a file system volume
>  
>      Args:
> @@ -39,6 +39,13 @@ def mk_fs(config, fs_type, size, prefix, size_gran = 0x100000):
>      else:
>          fs_lnxtype = fs_type
>  
> +    if src_dir:
> +        if fs_lnxtype == 'ext4':
> +            mkfs_opt = mkfs_opt + ' -d ' + src_dir
> +        elif fs_lnxtype != 'vfat':
> +            # Implement src_dir for this fs!
> +            raise
> +
>      count = (size + size_gran - 1) // size_gran
>  
>      # Some distributions do not add /sbin to the default PATH, where mkfs lives

This brings two new pylint errors:
test/py/tests/fs_helper.py:47:12: E0704: The raise statement is not inside an except clause (misplaced-bare-raise)
test/py/tests/fs_helper.py:78:4: E1120: No value for argument 'src_dir' in function call (no-value-for-parameter)

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] test_fs: Allow running unprivileged
  2024-08-15 22:14 ` Tom Rini
@ 2024-08-18  9:11   ` Richard Weinberger
  2024-08-18 15:25     ` Simon Glass
  0 siblings, 1 reply; 14+ messages in thread
From: Richard Weinberger @ 2024-08-18  9:11 UTC (permalink / raw)
  To: u-boot, Tom Rini
  Cc: Richard Weinberger, upstream+uboot, francis.laniel, glaroque,
	mkorpershoek, sjg, christian.taedcke

Am Freitag, 16. August 2024, 00:14:18 CEST schrieb Tom Rini:
> This brings two new pylint errors:
> test/py/tests/fs_helper.py:47:12: E0704: The raise statement is not inside an except clause (misplaced-bare-raise)

This raise was on purpose, I wanted the test to fail when an unsupported filesystem is used.
I have changed it to an assert 0.

> test/py/tests/fs_helper.py:78:4: E1120: No value for argument 'src_dir' in function call (no-value-for-parameter)

Fixed too.

But I'm still wrestling with the Azure pipeline.
After wasting^wspending a full afternoon, I think I know what is going on.

With my patches applied, it always failed like that:

___________________________ test_ut_dm_init_bootstd ____________________________
test/py/tests/test_ut.py:234: in setup_bootflow_image
    u_boot_utils.run_and_log(cons, 'mkimage -f auto -d %s %s' %
test/py/u_boot_utils.py:181: in run_and_log
    output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin, env=env)
test/py/multiplexed_log.py:183: in run
    raise exception
test/py/multiplexed_log.py:141: in run
    p = subprocess.Popen(cmd, cwd=cwd,
/usr/lib/python3.10/subprocess.py:971: in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
/usr/lib/python3.10/subprocess.py:1863: in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
E   FileNotFoundError: [Errno 2] No such file or directory: 'mkimage'

This makes little sense because I'm not touching mkimage nor PATH.

It turned out that without my changes, mount_image() always fails
inside the Azure pipeline.
So, in setup_bootflow_image() the whole try/catch block around
image creating, mounting it, etc.. fails and it always falls back
to the prepared image via copy_prepared_image().
The log print('Falled to create image, failing back to prepared copy: %s', str(exc))
is never shown because the test itself succeeds.

My patches change the tests to work without root privileges, so mount_image()
is no longer needed and no exception occurs.
As a consequence, mkimage is used the very first time on the Azure pipeline via:
u_boot_utils.run_and_log(cons, 'mkimage -f auto -d %s %s' % (inf, os.path.join(scratch_dir, vmlinux)))

To my best knowledge, u-boot-tools are not installed in the docker image,
nor does the test framework install mkimage.
So, the failure is expected.  Running test_ut.my manually always worked
within my test bed because I had mkimage installed.

So, can we please have mkimage inside the Docker image?

Thanks,
//richard

-- 
​​​​​sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT
UID/VAT Nr: ATU 66964118 | FN: 374287y



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] test_fs: Allow running unprivileged
  2024-08-18  9:11   ` Richard Weinberger
@ 2024-08-18 15:25     ` Simon Glass
  2024-08-18 15:37       ` Richard Weinberger
  0 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2024-08-18 15:25 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: U-Boot Mailing List, Tom Rini, Richard Weinberger, upstream+uboot,
	Francis Laniel, Guillaume La Roque, Mattijs Korpershoek,
	Christian Taedcke

Hi Richard,

On Sun, Aug 18, 2024, 03:11 Richard Weinberger <richard@sigma-star.at> wrote:
>
> Am Freitag, 16. August 2024, 00:14:18 CEST schrieb Tom Rini:
> > This brings two new pylint errors:
> > test/py/tests/fs_helper.py:47:12: E0704: The raise statement is not inside an except clause (misplaced-bare-raise)
>
> This raise was on purpose, I wanted the test to fail when an unsupported filesystem is used.
> I have changed it to an assert 0.
>
> > test/py/tests/fs_helper.py:78:4: E1120: No value for argument 'src_dir' in function call (no-value-for-parameter)
>
> Fixed too.
>
> But I'm still wrestling with the Azure pipeline.
> After wasting^wspending a full afternoon, I think I know what is going on.
>
> With my patches applied, it always failed like that:
>
> ___________________________ test_ut_dm_init_bootstd ____________________________
> test/py/tests/test_ut.py:234: in setup_bootflow_image
>     u_boot_utils.run_and_log(cons, 'mkimage -f auto -d %s %s' %
> test/py/u_boot_utils.py:181: in run_and_log
>     output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin, env=env)
> test/py/multiplexed_log.py:183: in run
>     raise exception
> test/py/multiplexed_log.py:141: in run
>     p = subprocess.Popen(cmd, cwd=cwd,
> /usr/lib/python3.10/subprocess.py:971: in __init__
>     self._execute_child(args, executable, preexec_fn, close_fds,
> /usr/lib/python3.10/subprocess.py:1863: in _execute_child
>     raise child_exception_type(errno_num, err_msg, err_filename)
> E   FileNotFoundError: [Errno 2] No such file or directory: 'mkimage'
>
> This makes little sense because I'm not touching mkimage nor PATH.
>
> It turned out that without my changes, mount_image() always fails
> inside the Azure pipeline.
> So, in setup_bootflow_image() the whole try/catch block around
> image creating, mounting it, etc.. fails and it always falls back
> to the prepared image via copy_prepared_image().
> The log print('Falled to create image, failing back to prepared copy: %s', str(exc))
> is never shown because the test itself succeeds.


> My patches change the tests to work without root privileges, so mount_image()
> is no longer needed and no exception occurs.
> As a consequence, mkimage is used the very first time on the Azure pipeline via:
> u_boot_utils.run_and_log(cons, 'mkimage -f auto -d %s %s' % (inf, os.path.join(scratch_dir, vmlinux)))
>
> To my best knowledge, u-boot-tools are not installed in the docker image,
> nor does the test framework install mkimage.
> So, the failure is expected.  Running test_ut.my manually always worked
> within my test bed because I had mkimage installed.
>
> So, can we please have mkimage inside the Docker image?

Sorry about all your trouble. Perhaps we should add a comment about
specifically what the code is for. Also, once you get all this in, we
can perhaps remove the fallbacks. I still get errors from qemu-img on
Ubuntu unless I chmod a+r /boot/* but presumably you don't use that
tool.

For mkinage, it would be better to use the version that is built in
CI, for sandbox. That is how the tools tests work.

Regards,
Simon

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] test_fs: Allow running unprivileged
  2024-08-18 15:25     ` Simon Glass
@ 2024-08-18 15:37       ` Richard Weinberger
  2024-08-18 15:47         ` Simon Glass
  0 siblings, 1 reply; 14+ messages in thread
From: Richard Weinberger @ 2024-08-18 15:37 UTC (permalink / raw)
  To: Simon Glass
  Cc: U-Boot Mailing List, Tom Rini, Richard Weinberger, upstream+uboot,
	Francis Laniel, Guillaume La Roque, Mattijs Korpershoek,
	Christian Taedcke

Simon,

Am Sonntag, 18. August 2024, 17:25:37 CEST schrieb Simon Glass:
> > So, can we please have mkimage inside the Docker image?
> 
> Sorry about all your trouble. Perhaps we should add a comment about

No need to worry. :)

> specifically what the code is for. Also, once you get all this in, we
> can perhaps remove the fallbacks. I still get errors from qemu-img on

I hope we can remove all these fall backs.
IMHO, unit tests have to behave always the same way.

> Ubuntu unless I chmod a+r /boot/* but presumably you don't use that
> tool.

On recent Ubuntu releases this should be resolved:
https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1673431

> For mkinage, it would be better to use the version that is built in
> CI, for sandbox. That is how the tools tests work.

True that!
Off the head, I don't know how to achieve this, but my knowledge of
the Azure pipeline setup is limited.

Thanks,
//richard

-- 
​​​​​sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT
UID/VAT Nr: ATU 66964118 | FN: 374287y



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] test_fs: Allow running unprivileged
  2024-08-18 15:37       ` Richard Weinberger
@ 2024-08-18 15:47         ` Simon Glass
  2024-08-18 20:06           ` Richard Weinberger
  0 siblings, 1 reply; 14+ messages in thread
From: Simon Glass @ 2024-08-18 15:47 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: U-Boot Mailing List, Tom Rini, Richard Weinberger, upstream+uboot,
	Francis Laniel, Guillaume La Roque, Mattijs Korpershoek,
	Christian Taedcke

Hi Richard,

On Sun, 18 Aug 2024 at 16:37, Richard Weinberger <richard@sigma-star.at> wrote:
>
> Simon,
>
> Am Sonntag, 18. August 2024, 17:25:37 CEST schrieb Simon Glass:
> > > So, can we please have mkimage inside the Docker image?
> >
> > Sorry about all your trouble. Perhaps we should add a comment about
>
> No need to worry. :)
>
> > specifically what the code is for. Also, once you get all this in, we
> > can perhaps remove the fallbacks. I still get errors from qemu-img on
>
> I hope we can remove all these fall backs.
> IMHO, unit tests have to behave always the same way.

Indeed.

>
> > Ubuntu unless I chmod a+r /boot/* but presumably you don't use that
> > tool.
>
> On recent Ubuntu releases this should be resolved:
> https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1673431
>
> > For mkinage, it would be better to use the version that is built in
> > CI, for sandbox. That is how the tools tests work.
>
> True that!
> Off the head, I don't know how to achieve this, but my knowledge of
> the Azure pipeline setup is limited.

In that file, this is the line that builds the tools:

          ./tools/buildman/buildman -T0 -o ${UBOOT_TRAVIS_BUILD_DIR}
-w --board tools-only

and this adds the built scripts/dtc to the path, but you could just as
easily add tools/

          export PATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}

Regards,
Simon

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] test_fs: Allow running unprivileged
  2024-08-18 15:47         ` Simon Glass
@ 2024-08-18 20:06           ` Richard Weinberger
  2024-08-19 17:11             ` Tom Rini
  0 siblings, 1 reply; 14+ messages in thread
From: Richard Weinberger @ 2024-08-18 20:06 UTC (permalink / raw)
  To: Simon Glass
  Cc: U-Boot Mailing List, Tom Rini, Richard Weinberger, upstream+uboot,
	Francis Laniel, Guillaume La Roque, Mattijs Korpershoek,
	Christian Taedcke

Simon,

Am Sonntag, 18. August 2024, 17:47:01 CEST schrieb Simon Glass:
> In that file, this is the line that builds the tools:
> 
>           ./tools/buildman/buildman -T0 -o ${UBOOT_TRAVIS_BUILD_DIR}
> -w --board tools-only
> 
> and this adds the built scripts/dtc to the path, but you could just as
> easily add tools/
> 
>           export PATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}

Sounds good. I guess this needs to go into master first before it shows
an effect on my branch?

Thanks,
//richard

-- 
​​​​​sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT
UID/VAT Nr: ATU 66964118 | FN: 374287y



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] test_fs: Allow running unprivileged
  2024-08-18 20:06           ` Richard Weinberger
@ 2024-08-19 17:11             ` Tom Rini
  2024-09-17 17:24               ` Tom Rini
  0 siblings, 1 reply; 14+ messages in thread
From: Tom Rini @ 2024-08-19 17:11 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: Simon Glass, U-Boot Mailing List, Richard Weinberger,
	upstream+uboot, Francis Laniel, Guillaume La Roque,
	Mattijs Korpershoek, Christian Taedcke

[-- Attachment #1: Type: text/plain, Size: 715 bytes --]

On Sun, Aug 18, 2024 at 10:06:05PM +0200, Richard Weinberger wrote:
> Simon,
> 
> Am Sonntag, 18. August 2024, 17:47:01 CEST schrieb Simon Glass:
> > In that file, this is the line that builds the tools:
> > 
> >           ./tools/buildman/buildman -T0 -o ${UBOOT_TRAVIS_BUILD_DIR}
> > -w --board tools-only
> > 
> > and this adds the built scripts/dtc to the path, but you could just as
> > easily add tools/
> > 
> >           export PATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}
> 
> Sounds good. I guess this needs to go into master first before it shows
> an effect on my branch?

Can you please just work that in to your series here? Thanks again for
cleaning all this up!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/3] test_fs: Allow running unprivileged
  2024-08-19 17:11             ` Tom Rini
@ 2024-09-17 17:24               ` Tom Rini
  0 siblings, 0 replies; 14+ messages in thread
From: Tom Rini @ 2024-09-17 17:24 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: Simon Glass, U-Boot Mailing List, Richard Weinberger,
	upstream+uboot, Francis Laniel, Guillaume La Roque,
	Mattijs Korpershoek, Christian Taedcke

[-- Attachment #1: Type: text/plain, Size: 873 bytes --]

On Mon, Aug 19, 2024 at 11:11:36AM -0600, Tom Rini wrote:
> On Sun, Aug 18, 2024 at 10:06:05PM +0200, Richard Weinberger wrote:
> > Simon,
> > 
> > Am Sonntag, 18. August 2024, 17:47:01 CEST schrieb Simon Glass:
> > > In that file, this is the line that builds the tools:
> > > 
> > >           ./tools/buildman/buildman -T0 -o ${UBOOT_TRAVIS_BUILD_DIR}
> > > -w --board tools-only
> > > 
> > > and this adds the built scripts/dtc to the path, but you could just as
> > > easily add tools/
> > > 
> > >           export PATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}
> > 
> > Sounds good. I guess this needs to go into master first before it shows
> > an effect on my branch?
> 
> Can you please just work that in to your series here? Thanks again for
> cleaning all this up!

Have you had a chance to get back to this series? Thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-09-17 17:24 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02  9:33 [PATCH 1/3] test_fs: Allow running unprivileged Richard Weinberger
2024-08-02  9:33 ` [PATCH 2/3] test_fs: Rename mount dir to scratch Richard Weinberger
2024-08-06 15:32   ` Mattijs Korpershoek
2024-08-06 16:42     ` Richard Weinberger
2024-08-02  9:33 ` [PATCH 3/3] test_ut: Allow running unprivileged Richard Weinberger
2024-08-06 15:29 ` [PATCH 1/3] test_fs: " Mattijs Korpershoek
2024-08-15 22:14 ` Tom Rini
2024-08-18  9:11   ` Richard Weinberger
2024-08-18 15:25     ` Simon Glass
2024-08-18 15:37       ` Richard Weinberger
2024-08-18 15:47         ` Simon Glass
2024-08-18 20:06           ` Richard Weinberger
2024-08-19 17:11             ` Tom Rini
2024-09-17 17:24               ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.