test: Include /sbin to the PATH when creating ext4 disk image
PATCH v2 1/4 test: Include /sbin to the PATH when creating ext4 disk image
On some distributions the mkfs.ext4 is under /sbin and /sbin is not set for mere users. Include /sbin to the PATH when creating ext4 disk image, so that users won't get a scary traceback from Python.
---
v2: used '/sbin' as is (Simon)
test/py/tests/test_env.py | 2 ++ 1 file changed, 2 insertions(+)
test/py/tests/test_env.py +2 -0
@@ -414,6 +414,8 @@ def mk_env_ext4(state_test_env): if os.path.exists(persistent): c.log.action('Disk image file ' + persistent + ' already exists') else: + # Some distributions do not add /sbin to the default PATH, where mkfs.ext4 lives + os.environ["PATH"] += os.pathsep + '/sbin' try: u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent) u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)
Signature · 1 line
2.30.0
PATCH v2 2/4 test: Allow simple glob pattern in the test name
When run ut dm [test name] allow to use simple pattern to run all tests started with given prefix. For example, to run all ACPI test cases:
ut dm acpi*
---
v2: rebased against dm/test-working branch (Simon)
test/test-main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
test/test-main.c +9 -2
@@ -128,10 +128,17 @@ static bool ut_test_run_on_flattree(struct unit_test *test)static bool test_matches (const char *prefix,const char *test_name,const char *select_name) { +size_t len; +if (!select_name)return true; -if (!strcmp (test_name, select_name)) +/* Allow glob expansion in the test name */ + len = select_name[strlen (select_name) -1 ] =='*' ?strlen (select_name) :0 ; +if (len-- ==1 ) +return true; + +if (!strncmp (test_name, select_name, len))return true;if (!prefix) {
@@ -146,7 +153,7 @@ static bool test_matches(const char *prefix, const char *test_name, test_name +=strlen (prefix); } -if (!strcmp (test_name, select_name)) +if (!strncmp (test_name, select_name, len))return true;return false;
Signature · 1 line
2.30.0
PATCH v2 3/4 test: Use positive conditional in test_matches()
In reply to Andy ShevchenkoIt is easier to read the positive conditional.
While at it, convert hard coded length of "_test_" to strlen("_test_") which will be converted to a constant bu optimizing compiler.
---
v2: new patch
test/test-main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
test/test-main.c +6 -6
@@ -141,16 +141,16 @@ static bool test_matches(const char *prefix, const char *test_name,if (!strncmp (test_name, select_name, len))return true; -if (!prefix) { +if (prefix) { +/* All tests have this prefix */ +if (!strncmp (test_name, prefix,strlen (prefix))) + test_name +=strlen (prefix); + }else {const char *p =strstr (test_name,"_test_" );/* convert xxx_test_yyy to yyy, i.e. remove the suite name */ if (p) - test_name = p +6 ; - }else { -/* All tests have this prefix */ -if (!strncmp (test_name, prefix,strlen (prefix))) - test_name +=strlen (prefix); + test_name = p +strlen ("_test_" ); }if (!strncmp (test_name, select_name, len))
Signature · 1 line
2.30.0
PATCH v2 4/4 test: Don't unmount not (yet) mounted system
In reply to Andy ShevchenkoWhen test suite tries to create a file for a new filesystem test case and fails, the clean up of the exception tries to unmount the image, that has not yet been mounted. When it happens, the fuse_mounted global variable is set to False and inconveniently the test case tries to use sudo, so without this change the admin of the machine gets an (annoying) email:
Subject: *** SECURITY information for example.com ***
example.com : Feb 5 19:43:47 : ... COMMAND=/bin/umount .../build-sandbox/persistent-data/mnt
and second run of the test cases on uncleaned build folder will ask for sudo which is not what expected.
Besides that there is a double unmount calls during successfully run test case.
All of these due to over engineered Python try-except clause and people didn't get it properly at all. The rule of thumb is that don't use more keywords than try-except in the exception handling code. Nevertheless, here we adjust code to be less intrusive to the initial logic behind that complex and unclear constructions in the test case, although it adds a lot of lines of the code, i.e. splits one exception handler to three, so on each step we know what cleanup shall perform.
---
v2: new patch
test/py/tests/test_fs/conftest.py | 78 ++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 22 deletions(-)
test/py/tests/test_fs/conftest.py +56 -22
@@ -270,9 +270,20 @@ def fs_obj_basic(request, u_boot_config): # 3GiB volume fs_img = mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB') + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return - # Mount the image so we can populate it. + try: check_call('mkdir -p %s' % mount_dir, shell=True) + except CalledProcessError as err: + pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + finally: + call('rm -f %s' % fs_img, shell=True) + + try: + # Mount the image so we can populate it. mount_fs(fs_type, fs_img, mount_dir) # Create a subdirectory.
@@ -335,18 +346,15 @@ def fs_obj_basic(request, u_boot_config): % big_file, shell=True).decode() md5val.append(out.split()[0]) - umount_fs(mount_dir) except CalledProcessError as err: - pytest.skip('Setup failed for filesystem: ' + fs_type + \ - '. {}'.format(err)) + pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err)) return else: yield [fs_ubtype, fs_img, md5val] finally: umount_fs(mount_dir) call('rmdir %s' % mount_dir, shell=True) - if fs_img: - call('rm -f %s' % fs_img, shell=True) + call('rm -f %s' % fs_img, shell=True) # # Fixture for extended fs test
@@ -378,9 +386,20 @@ def fs_obj_ext(request, u_boot_config): # 128MiB volume fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return - # Mount the image so we can populate it. + try: check_call('mkdir -p %s' % mount_dir, shell=True) + except CalledProcessError as err: + pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + finally: + call('rm -f %s' % fs_img, shell=True) + + try: + # Mount the image so we can populate it. mount_fs(fs_type, fs_img, mount_dir) # Create a test directory
@@ -422,7 +441,6 @@ def fs_obj_ext(request, u_boot_config): md5val.append(out.split()[0]) check_call('rm %s' % tmp_file, shell=True) - umount_fs(mount_dir) except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) return
@@ -431,8 +449,7 @@ def fs_obj_ext(request, u_boot_config): finally: umount_fs(mount_dir) call('rmdir %s' % mount_dir, shell=True) - if fs_img: - call('rm -f %s' % fs_img, shell=True) + call('rm -f %s' % fs_img, shell=True) # # Fixture for mkdir test
@@ -460,11 +477,10 @@ def fs_obj_mkdir(request, u_boot_config): fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') except: pytest.skip('Setup failed for filesystem: ' + fs_type) + return else: yield [fs_ubtype, fs_img] - finally: - if fs_img: - call('rm -f %s' % fs_img, shell=True) + call('rm -f %s' % fs_img, shell=True) # # Fixture for unlink test
@@ -493,9 +509,20 @@ def fs_obj_unlink(request, u_boot_config): # 128MiB volume fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return - # Mount the image so we can populate it. + try: check_call('mkdir -p %s' % mount_dir, shell=True) + except CalledProcessError as err: + pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + finally: + call('rm -f %s' % fs_img, shell=True) + + try: + # Mount the image so we can populate it. mount_fs(fs_type, fs_img, mount_dir) # Test Case 1 & 3
@@ -519,7 +546,6 @@ 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) - umount_fs(mount_dir) except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) return
@@ -528,8 +554,7 @@ def fs_obj_unlink(request, u_boot_config): finally: umount_fs(mount_dir) call('rmdir %s' % mount_dir, shell=True) - if fs_img: - call('rm -f %s' % fs_img, shell=True) + call('rm -f %s' % fs_img, shell=True) # # Fixture for symlink fs test
@@ -559,11 +584,22 @@ def fs_obj_symlink(request, u_boot_config): try: - # 3GiB volume + # 1GiB volume fs_img = mk_fs(u_boot_config, fs_type, 0x40000000, '1GB') + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return - # Mount the image so we can populate it. + try: check_call('mkdir -p %s' % mount_dir, shell=True) + except CalledProcessError as err: + pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + finally: + call('rm -f %s' % fs_img, shell=True) + + try: + # Mount the image so we can populate it. mount_fs(fs_type, fs_img, mount_dir) # Create a subdirectory.
@@ -587,7 +623,6 @@ def fs_obj_symlink(request, u_boot_config): % medium_file, shell=True).decode() md5val.extend([out.split()[0]]) - umount_fs(mount_dir) except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) return
@@ -596,5 +631,4 @@ def fs_obj_symlink(request, u_boot_config): finally: umount_fs(mount_dir) call('rmdir %s' % mount_dir, shell=True) - if fs_img: - call('rm -f %s' % fs_img, shell=True) + call('rm -f %s' % fs_img, shell=True)
Signature · 1 line
2.30.0
PATCH v2 1/4 test: Include /sbin to the PATH when creating ext4 disk image
In reply to Andy ShevchenkoQuoted 3 lines · Andy Shevchenko
On some distributions the mkfs.ext4 is under /sbin and /sbin is not set for mere users. Include /sbin to the PATH when creating ext4 disk image, so that users won't get a scary traceback from Python.
Note, patches 1 and 4 may be applied to U-Boot sources directly (while patches 2 and 3 are based on top of dm/test-working). Moreover, patch 4 fixes a quite annoying fix, without which I have got reprimanded by an admin of our build system.
Please, consider to apply patch 4 ASAP.
Quoted 23 lines
Cc Patrick Delaunay <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>---
v2: used '/sbin' as is (Simon)test/py/tests/test_env.py | 2 ++ 1 file changed, 2 insertions(+)test/py/tests/test_env.py +2
-0@@ -414,6 +414,8 @@ def mk_env_ext4(state_test_env): if os.path.exists(persistent): c.log.action('Disk image file ' + persistent + ' already exists') else: + # Some distributions do not add /sbin to the default PATH, where mkfs.ext4 lives + os.environ["PATH"] += os.pathsep + '/sbin' try: u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent) u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)Signature · 1 line
2.30.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 1/4 test: Include /sbin to the PATH when creating ext4 disk image
In reply to Andy ShevchenkoQuoted 11 lines · Andy Shevchenko
On some distributions the mkfs.ext4 is under /sbin and /sbin is not set for mere users. Include /sbin to the PATH when creating ext4 disk image, so that users won't get a scary traceback from Python.
Cc Patrick Delaunay <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>---
v2: used '/sbin' as is (Simon)test/py/tests/test_env.py | 2 ++ 1 file changed, 2 insertions(+)
PATCH v2 2/4 test: Allow simple glob pattern in the test name
In reply to Andy ShevchenkoQuoted 8 lines · Andy Shevchenko
When run
ut dm [test name]allow to use simple pattern to run all tests started with given prefix. For example, to run all ACPI test cases:
ut dm acpi*Signed-off-by Andy Shevchenko <[email protected]>---
v2: rebased against dm/test-working branch (Simon)
Sadly that is deferred, but we can pick this patch up later.
Quoted 2 lines
test/test-main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
PATCH v2 3/4 test: Use positive conditional in test_matches()
In reply to Andy ShevchenkoQuoted 11 lines · Andy Shevchenko
It is easier to read the positive conditional.
While at it, convert hard coded length of "_test_" to
strlen("_test_")which will be converted to a constant bu optimizing compiler.Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchtest/test-main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
PATCH v2 4/4 test: Don't unmount not (yet) mounted system
In reply to Andy ShevchenkoHi Andy,
Quoted 24 lines · Andy Shevchenko
When test suite tries to create a file for a new filesystem test case and fails, the clean up of the exception tries to unmount the image, that has not yet been mounted. When it happens, the
fuse_mountedglobal variable is set to False and inconveniently the test case tries to use sudo, so without this change the admin of the machine gets an (annoying) email:Subject: *** SECURITY information for example.com ***
example.com : Feb 5 19:43:47 : ... COMMAND=/bin/umount .../build-sandbox/persistent-data/mnt
and second run of the test cases on uncleaned build folder will ask for sudo which is not what expected.
Besides that there is a double unmount calls during successfully run test case.
All of these due to over engineered Python try-except clause and people didn't get it properly at all. The rule of thumb is that don't use more keywords than try-except in the exception handling code. Nevertheless, here we adjust code to be less intrusive to the initial logic behind that complex and unclear constructions in the test case, although it adds a lot of lines of the code, i.e. splits one exception handler to three, so on each step we know what cleanup shall perform.
Quoted 6 lines
Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchtest/py/tests/test_fs/conftest.py | 78 ++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 22 deletions(-)
This looks OK to me, but there is a lot of duplication in the code, isn't there? Perhaps another forray?
Regards,
Simon
PATCH v2 4/4 test: Don't unmount not (yet) mounted system
Quoted 36 lines · Simon Glass
Hi Andy,
Quoted 24 lines · Andy Shevchenko
When test suite tries to create a file for a new filesystem test case and fails, the clean up of the exception tries to unmount the image, that has not yet been mounted. When it happens, the
fuse_mountedglobal variable is set to False and inconveniently the test case tries to use sudo, so without this change the admin of the machine gets an (annoying) email:Subject: *** SECURITY information for example.com ***
example.com : Feb 5 19:43:47 : ... COMMAND=/bin/umount .../build-sandbox/persistent-data/mnt
and second run of the test cases on uncleaned build folder will ask for sudo which is not what expected.
Besides that there is a double unmount calls during successfully run test case.
All of these due to over engineered Python try-except clause and people didn't get it properly at all. The rule of thumb is that don't use more keywords than try-except in the exception handling code. Nevertheless, here we adjust code to be less intrusive to the initial logic behind that complex and unclear constructions in the test case, although it adds a lot of lines of the code, i.e. splits one exception handler to three, so on each step we know what cleanup shall perform.
Quoted 6 lines
Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchtest/py/tests/test_fs/conftest.py | 78 ++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 22 deletions(-)
Quoted 2 lines
This looks OK to me, but there is a lot of duplication in the code, isn't there? Perhaps another forray?
Can we apply this fix as is and think about optimisations later, please? W/o this I'm really blocked from running tests against U-Boot.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 4/4 test: Don't unmount not (yet) mounted system
Quoted 38 lines · Andy Shevchenko
Quoted 36 lines · Simon Glass
Hi Andy,
Quoted 30 lines · Andy Shevchenko
When test suite tries to create a file for a new filesystem test case and fails, the clean up of the exception tries to unmount the image, that has not yet been mounted. When it happens, the
fuse_mountedglobal variable is set to False and inconveniently the test case tries to use sudo, so without this change the admin of the machine gets an (annoying) email:Subject: *** SECURITY information for example.com ***
example.com : Feb 5 19:43:47 : ... COMMAND=/bin/umount .../build-sandbox/persistent-data/mnt
and second run of the test cases on uncleaned build folder will ask for sudo which is not what expected.
Besides that there is a double unmount calls during successfully run test case.
All of these due to over engineered Python try-except clause and people didn't get it properly at all. The rule of thumb is that don't use more keywords than try-except in the exception handling code. Nevertheless, here we adjust code to be less intrusive to the initial logic behind that complex and unclear constructions in the test case, although it adds a lot of lines of the code, i.e. splits one exception handler to three, so on each step we know what cleanup shall perform.
Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchtest/py/tests/test_fs/conftest.py | 78 ++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 22 deletions(-)
Quoted 5 lines
Quoted 2 lines
This looks OK to me, but there is a lot of duplication in the code, isn't there? Perhaps another forray?
Can we apply this fix as is and think about optimisations later, please? W/o this I'm really blocked from running tests against U-Boot.
'make qcheck' bypasses this.
+Heinrich Schuchardt
PATCH v2 1/4 test: Include /sbin to the PATH when creating ext4 disk image
In reply to Andy ShevchenkoQuoted 3 lines · Andy Shevchenko
On some distributions the mkfs.ext4 is under /sbin and /sbin is not set for mere users. Include /sbin to the PATH when creating ext4 disk image, so that users won't get a scary traceback from Python.
It has been a long. Is it any news about this series? Can it be applied (at least patches that are fine against U-Boot current master)?
Quoted 23 lines
Cc Patrick Delaunay <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>---
v2: used '/sbin' as is (Simon)test/py/tests/test_env.py | 2 ++ 1 file changed, 2 insertions(+)test/py/tests/test_env.py +2
-0@@ -414,6 +414,8 @@ def mk_env_ext4(state_test_env): if os.path.exists(persistent): c.log.action('Disk image file ' + persistent + ' already exists') else: + # Some distributions do not add /sbin to the default PATH, where mkfs.ext4 lives + os.environ["PATH"] += os.pathsep + '/sbin' try: u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent) u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)Signature · 1 line
2.30.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 1/4 test: Include /sbin to the PATH when creating ext4 disk image
In reply to Andy ShevchenkoQuoted 7 lines · Andy Shevchenko
On some distributions the mkfs.ext4 is under /sbin and /sbin is not set for mere users. Include /sbin to the PATH when creating ext4 disk image, so that users won't get a scary traceback from Python.
Cc Patrick Delaunay <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210318/f0849983/attachment.sig>
PATCH v2 4/4 test: Don't unmount not (yet) mounted system
In reply to Simon GlassQuoted 38 lines · Simon Glass
Quoted 37 lines · Andy Shevchenko
Quoted 35 lines · Simon Glass
Quoted 24 lines · Andy Shevchenko
When test suite tries to create a file for a new filesystem test case and fails, the clean up of the exception tries to unmount the image, that has not yet been mounted. When it happens, the
fuse_mountedglobal variable is set to False and inconveniently the test case tries to use sudo, so without this change the admin of the machine gets an (annoying) email:Subject: *** SECURITY information for example.com ***
example.com : Feb 5 19:43:47 : ... COMMAND=/bin/umount .../build-sandbox/persistent-data/mnt
and second run of the test cases on uncleaned build folder will ask for sudo which is not what expected.
Besides that there is a double unmount calls during successfully run test case.
All of these due to over engineered Python try-except clause and people didn't get it properly at all. The rule of thumb is that don't use more keywords than try-except in the exception handling code. Nevertheless, here we adjust code to be less intrusive to the initial logic behind that complex and unclear constructions in the test case, although it adds a lot of lines of the code, i.e. splits one exception handler to three, so on each step we know what cleanup shall perform.
Quoted 6 lines
Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchtest/py/tests/test_fs/conftest.py | 78 ++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 22 deletions(-)This looks OK to me, but there is a lot of duplication in the code, isn't there? Perhaps another forray?
Quoted 8 lines
Quoted 2 lines
Can we apply this fix as is and think about optimisations later, please? W/o this I'm really blocked from running tests against U-Boot.
'make qcheck' bypasses this.
+Heinrich Schuchardt
Reviewed-by Simon Glass <[email protected]>
Thanks!
Tom, I don't see this being applied. Can we actually get it in?
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 4/4 test: Don't unmount not (yet) mounted system
Quoted 44 lines · Andy Shevchenko
Quoted 43 lines · Simon Glass
Quoted 34 lines · Andy Shevchenko
Quoted 33 lines · Simon Glass
Quoted 30 lines · Andy Shevchenko
When test suite tries to create a file for a new filesystem test case and fails, the clean up of the exception tries to unmount the image, that has not yet been mounted. When it happens, the
fuse_mountedglobal variable is set to False and inconveniently the test case tries to use sudo, so without this change the admin of the machine gets an (annoying) email:Subject: *** SECURITY information for example.com ***
example.com : Feb 5 19:43:47 : ... COMMAND=/bin/umount .../build-sandbox/persistent-data/mnt
and second run of the test cases on uncleaned build folder will ask for sudo which is not what expected.
Besides that there is a double unmount calls during successfully run test case.
All of these due to over engineered Python try-except clause and people didn't get it properly at all. The rule of thumb is that don't use more keywords than try-except in the exception handling code. Nevertheless, here we adjust code to be less intrusive to the initial logic behind that complex and unclear constructions in the test case, although it adds a lot of lines of the code, i.e. splits one exception handler to three, so on each step we know what cleanup shall perform.
Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchtest/py/tests/test_fs/conftest.py | 78 ++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 22 deletions(-)Quoted 5 lines
Quoted 2 lines
This looks OK to me, but there is a lot of duplication in the code, isn't there? Perhaps another forray?
Can we apply this fix as is and think about optimisations later, please? W/o this I'm really blocked from running tests against U-Boot.
'make qcheck' bypasses this.
Quoted 7 lines
Quoted 3 lines
+Heinrich Schuchardt
Reviewed-by Simon Glass <[email protected]>Thanks!
Tom, I don't see this being applied. Can we actually get it in?
Does this apply cleanly to master? I thought only 1/4 did so I applied that.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210330/b7c5d39c/attachment.sig>
PATCH v2 4/4 test: Don't unmount not (yet) mounted system
Quoted 65 lines · Tom Rini
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Simon Glass
On Thu, 18 Feb 2021 at 03:56, Andy Shevchenko <
Quoted 1 line · andy.shevchenko at gmail.com> wrote:
Quoted 1 line
Quoted 1 line
On Thu, Feb 18, 2021 at 6:46 AM Simon Glass <[email protected]>
Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines · Andy Shevchenko
When test suite tries to create a file for a new filesystem test
case and fails,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
the clean up of the exception tries to unmount the image, that
has not yet been
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
mounted. When it happens, the
fuse_mountedglobal variable isset to False and
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
inconveniently the test case tries to use sudo, so without this
change the
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
admin of the machine gets an (annoying) email:
Subject: *** SECURITY information for example.com ***
example.com : Feb 5 19:43:47 : ... COMMAND=/bin/umount
.../build-sandbox/persistent-data/mnt
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
and second run of the test cases on uncleaned build folder will
ask for sudo
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
which is not what expected.
Besides that there is a double unmount calls during successfully
run test case.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
All of these due to over engineered Python try-except clause and
people didn't
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
get it properly at all. The rule of thumb is that don't use more
keywords than
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
try-except in the exception handling code. Nevertheless, here we
adjust code
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
to be less intrusive to the initial logic behind that complex
and unclear
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
constructions in the test case, although it adds a lot of lines
of the code,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
i.e. splits one exception handler to three, so on each step we
know what
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
cleanup shall perform.
Signed-off-by Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
---
v2: new patchtest/py/tests/test_fs/conftest.py | 78++++++++++++++++++++++---------
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
1 file changed, 56 insertions(+), 22 deletions(-)This looks OK to me, but there is a lot of duplication in the code, isn't there? Perhaps another forray?
Can we apply this fix as is and think about optimisations later,
please?
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
W/o this I'm really blocked from running tests against U-Boot.
'make qcheck' bypasses this.
+Heinrich Schuchardt
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Reviewed-by Simon Glass <[email protected]>Thanks!
Tom, I don't see this being applied. Can we actually get it in?
Does this apply cleanly to master? I thought only 1/4 did so I applied that.
Patches 2&3 are against Simon?s tree, patches 1&4 are against main branch
Quoted 4 lines
--
Tom
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 4/4 test: Don't unmount not (yet) mounted system
In reply to Andy ShevchenkoQuoted 23 lines · Andy Shevchenko
When test suite tries to create a file for a new filesystem test case and fails, the clean up of the exception tries to unmount the image, that has not yet been mounted. When it happens, the
fuse_mountedglobal variable is set to False and inconveniently the test case tries to use sudo, so without this change the admin of the machine gets an (annoying) email:Subject: *** SECURITY information for example.com ***
example.com : Feb 5 19:43:47 : ... COMMAND=/bin/umount .../build-sandbox/persistent-data/mnt
and second run of the test cases on uncleaned build folder will ask for sudo which is not what expected.
Besides that there is a double unmount calls during successfully run test case.
All of these due to over engineered Python try-except clause and people didn't get it properly at all. The rule of thumb is that don't use more keywords than try-except in the exception handling code. Nevertheless, here we adjust code to be less intrusive to the initial logic behind that complex and unclear constructions in the test case, although it adds a lot of lines of the code, i.e. splits one exception handler to three, so on each step we know what cleanup shall perform.
Quoted 2 lines
Signed-off-by Andy Shevchenko <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210331/a5480e83/attachment.sig>
PATCH v2 3/4 test: Use positive conditional in test_matches()
In reply to Simon GlassQuoted 11 lines · Andy Shevchenko
It is easier to read the positive conditional.
While at it, convert hard coded length of "_test_" to
strlen("_test_")which will be converted to a constant bu optimizing compiler.Signed-off-by Andy Shevchenko <[email protected]>---
v2: new patchtest/test-main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 2/4 test: Allow simple glob pattern in the test name
In reply to Simon GlassQuoted 8 lines · Andy Shevchenko
When run
ut dm [test name]allow to use simple pattern to run all tests started with given prefix. For example, to run all ACPI test cases:
ut dm acpi*Signed-off-by Andy Shevchenko <[email protected]>---
v2: rebased against dm/test-working branch (Simon)
Sadly that is deferred, but we can pick this patch up later.
Quoted 2 lines
test/test-main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 4/4 test: Don't unmount not (yet) mounted system
In reply to Andy ShevchenkoQuoted 23 lines · Andy Shevchenko
When test suite tries to create a file for a new filesystem test case and fails, the clean up of the exception tries to unmount the image, that has not yet been mounted. When it happens, the
fuse_mountedglobal variable is set to False and inconveniently the test case tries to use sudo, so without this change the admin of the machine gets an (annoying) email:Subject: *** SECURITY information for example.com ***
example.com : Feb 5 19:43:47 : ... COMMAND=/bin/umount .../build-sandbox/persistent-data/mntand second run of the test cases on uncleaned build folder will ask for sudo which is not what expected.
Besides that there is a double unmount calls during successfully run test case.
All of these due to over engineered Python try-except clause and people didn't get it properly at all. The rule of thumb is that don't use more keywords than try-except in the exception handling code. Nevertheless, here we adjust code to be less intrusive to the initial logic behind that complex and unclear constructions in the test case, although it adds a lot of lines of the code, i.e. splits one exception handler to three, so on each step we know what cleanup shall perform.
Quoted 1 line
Signed-off-by Andy Shevchenko <[email protected]>
Dear Andy,
with this merged patch the following tests are not executed anymore locally:
test/py/tests/test_fs/test_basic.pytest/py/tests/test_fs/test_ext.py
SKIPPED [13] test/py/tests/test_fs/conftest.py:350: Setup failed for
filesystem: ext4. Command 'guestmount -a build-sandbox/persistent-data/3GB.ext4.img -m /dev/sda build-sandbox/persistent-data/mnt' returned non-zero exit status 1.
Please, revert the patch or fix it.
Best regards
Heinrich
Quoted 188 lines
Reviewed-by Simon Glass <[email protected]>---
v2: new patchtest/py/tests/test_fs/conftest.py | 78 ++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 22 deletions(-)test/py/tests/test_fs/conftest.py +56
-22@@ -270,9 +270,20 @@ def fs_obj_basic(request, u_boot_config): # 3GiB volume fs_img = mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB') + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return - # Mount the image so we can populate it. + try: check_call('mkdir -p %s' % mount_dir, shell=True) + except CalledProcessError as err: + pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + finally: + call('rm -f %s' % fs_img, shell=True) + + try: + # Mount the image so we can populate it. mount_fs(fs_type, fs_img, mount_dir) # Create a subdirectory.@@ -335,18 +346,15 @@ def fs_obj_basic(request, u_boot_config): % big_file, shell=True).decode() md5val.append(out.split()[0]) - umount_fs(mount_dir) except CalledProcessError as err: - pytest.skip('Setup failed for filesystem: ' + fs_type + \ - '. {}'.format(err)) + pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err)) return else: yield [fs_ubtype, fs_img, md5val] finally: umount_fs(mount_dir) call('rmdir %s' % mount_dir, shell=True) - if fs_img: - call('rm -f %s' % fs_img, shell=True) + call('rm -f %s' % fs_img, shell=True) # # Fixture for extended fs test@@ -378,9 +386,20 @@ def fs_obj_ext(request, u_boot_config): # 128MiB volume fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return - # Mount the image so we can populate it. + try: check_call('mkdir -p %s' % mount_dir, shell=True) + except CalledProcessError as err: + pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + finally: + call('rm -f %s' % fs_img, shell=True) + + try: + # Mount the image so we can populate it. mount_fs(fs_type, fs_img, mount_dir) # Create a test directory@@ -422,7 +441,6 @@ def fs_obj_ext(request, u_boot_config): md5val.append(out.split()[0]) check_call('rm %s' % tmp_file, shell=True) - umount_fs(mount_dir) except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) return@@ -431,8 +449,7 @@ def fs_obj_ext(request, u_boot_config): finally: umount_fs(mount_dir) call('rmdir %s' % mount_dir, shell=True) - if fs_img: - call('rm -f %s' % fs_img, shell=True) + call('rm -f %s' % fs_img, shell=True) # # Fixture for mkdir test@@ -460,11 +477,10 @@ def fs_obj_mkdir(request, u_boot_config): fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') except: pytest.skip('Setup failed for filesystem: ' + fs_type) + return else: yield [fs_ubtype, fs_img] - finally: - if fs_img: - call('rm -f %s' % fs_img, shell=True) + call('rm -f %s' % fs_img, shell=True) # # Fixture for unlink test@@ -493,9 +509,20 @@ def fs_obj_unlink(request, u_boot_config): # 128MiB volume fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return - # Mount the image so we can populate it. + try: check_call('mkdir -p %s' % mount_dir, shell=True) + except CalledProcessError as err: + pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + finally: + call('rm -f %s' % fs_img, shell=True) + + try: + # Mount the image so we can populate it. mount_fs(fs_type, fs_img, mount_dir) # Test Case 1 & 3@@ -519,7 +546,6 @@ 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) - umount_fs(mount_dir) except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) return@@ -528,8 +554,7 @@ def fs_obj_unlink(request, u_boot_config): finally: umount_fs(mount_dir) call('rmdir %s' % mount_dir, shell=True) - if fs_img: - call('rm -f %s' % fs_img, shell=True) + call('rm -f %s' % fs_img, shell=True) # # Fixture for symlink fs test@@ -559,11 +584,22 @@ def fs_obj_symlink(request, u_boot_config): try: - # 3GiB volume + # 1GiB volume fs_img = mk_fs(u_boot_config, fs_type, 0x40000000, '1GB') + except CalledProcessError as err: + pytest.skip('Creating failed for filesystem: ' + fs_type + '. {}'.format(err)) + return - # Mount the image so we can populate it. + try: check_call('mkdir -p %s' % mount_dir, shell=True) + except CalledProcessError as err: + pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type + '. {}'.format(err)) + return + finally: + call('rm -f %s' % fs_img, shell=True) + + try: + # Mount the image so we can populate it. mount_fs(fs_type, fs_img, mount_dir) # Create a subdirectory.@@ -587,7 +623,6 @@ def fs_obj_symlink(request, u_boot_config): % medium_file, shell=True).decode() md5val.extend([out.split()[0]]) - umount_fs(mount_dir) except CalledProcessError: pytest.skip('Setup failed for filesystem: ' + fs_type) return@@ -596,5 +631,4 @@ def fs_obj_symlink(request, u_boot_config): finally: umount_fs(mount_dir) call('rmdir %s' % mount_dir, shell=True) - if fs_img: - call('rm -f %s' % fs_img, shell=True) + call('rm -f %s' % fs_img, shell=True)
PATCH v2 4/4 test: Don't unmount not (yet) mounted system
Quoted 33 lines · Heinrich Schuchardt
Quoted 23 lines · Andy Shevchenko
When test suite tries to create a file for a new filesystem test case and fails, the clean up of the exception tries to unmount the image, that has not yet been mounted. When it happens, the
fuse_mountedglobal variable is set to False and inconveniently the test case tries to use sudo, so without this change the admin of the machine gets an (annoying) email:Subject: *** SECURITY information for example.com ***
example.com : Feb 5 19:43:47 : ... COMMAND=/bin/umount .../build-sandbox/persistent-data/mntand second run of the test cases on uncleaned build folder will ask for sudo which is not what expected.
Besides that there is a double unmount calls during successfully run test case.
All of these due to over engineered Python try-except clause and people didn't get it properly at all. The rule of thumb is that don't use more keywords than try-except in the exception handling code. Nevertheless, here we adjust code to be less intrusive to the initial logic behind that complex and unclear constructions in the test case, although it adds a lot of lines of the code, i.e. splits one exception handler to three, so on each step we know what cleanup shall perform.
Quoted 1 line
Signed-off-by Andy Shevchenko <[email protected]>Dear Andy,
with this merged patch the following tests are not executed anymore locally:
test/py/tests/test_fs/test_basic.pytest/py/tests/test_fs/test_ext.py
Quoted 6 lines
SKIPPED [13]
test/py/tests/test_fs/conftest.py:350: Setup failed for
filesystem: ext4. Command 'guestmount -a build-sandbox/persistent-data/3GB.ext4.img -m/dev/sdabuild-sandbox/persistent-data/mnt' returned non-zero exit status 1.Please, revert the patch or fix it.
Thanks for the report, let's investigate it.
And for the consistency let's continue this under the revert thread,
Signature · 2 lines
With Best Regards, Andy Shevchenko