btrfs-progs: selftests fixes
cover btrfs-progs: selftests fixes
There are 3 bugs exposed during my tests for unified mkfs features, and they are all from the selftest itself:
- check_min_kernel_version() doesn't handle 6.x kernels at all The original check never handles major number check properly. And when we change major number, returns in correct number now.
- Missing a space between "!" and function call
This bug is there for a long time.
Without previous fix, one may incorrectly remove the "!" and cause new problems.
- Convert/022 doesn't check if we have support for reiserfs
Qu Wenruo (3):
btrfs-progs: tests: fix the wrong kernel version check
btrfs-progs: mkfs-tests/025: fix the wrong function call
btrfs-progs: convert-tests/022: add reiserfs support check
tests/common | 23 +++++++++++++++---- .../022-reiserfs-parent-ref/test.sh | 5 ++++ tests/mkfs-tests/025-zoned-parallel/test.sh | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-)
Signature · 1 line
2.37.3
PATCH 1/3 btrfs-progs: tests: fix the wrong kernel version check
[BUG]
After upgrading to kernel v6.0-rc, btrfs-progs selftest mkfs/001 no longer checks single device RAID0 and other new features introduced in v5.13:
# make TEST=001\* test-mkfs
[TEST] mkfs-tests.sh
[TEST/mkfs] 001-basic-profiles
$ grep -IR "RAID0\/1" tests/mkfs-tests-results.txt
^^^ No output[CAUSE]
The existing check_min_kernel_version() is doing an incorrect check.
The old check looks like this:
[ "$unamemajor" -lt "$argmajor" ] || return 1 [ "$unameminor" -lt "$argminor" ] || return 1
return 0
For 6.0-rc kernels, we have the following values for mkfs/001
$unamemajor = 6
$unameminor = 0
$argmajor = 5
$argminor = 12
The first check doesn't exit immediately, as 6 > 5. Then we check the minor, which is already incorrect.
If our major is larger than target major, we should exit immediate with 0.
[FIX]
Fix the check and add extra comment.
Personally speaking I'm not a fan or short compare and return, thus all the checks will explicit "if []; then fi" checks.
Now mkfs/001 works as expected:
# make TEST=001\* test-mkfs
[TEST] mkfs-tests.sh
[TEST/mkfs] 001-basic-profiles
$ grep -IR "RAID0\/1" tests/mkfs-tests-results.txt
Data,RAID0/1: 204.75MiB
Metadata,RAID0/1: 204.75MiB
System,RAID0/1: 8.00MiB--- tests/common | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
tests/common +19 -4
@@ -659,6 +659,9 @@ check_kernel_support() # compare running kernel version to the given parameter, return success # if running is newer than requested (let caller decide if to fail or skip) # $1: minimum version of running kernel in major.minor format (eg. 4.19) +# +# Return 0 if we meet the minimal version requirement. +# Return 1 if not. check_min_kernel_version() { local unamemajor
@@ -672,10 +675,22 @@ check_min_kernel_version() uname=${uname%%-*} IFS=. read unamemajor unameminor tmp <<< "$uname" IFS=. read argmajor argminor tmp <<< "$1" - # "compare versions: ${unamemajor}.${unameminor} ? ${argmajor}.${argminor}" - [ "$unamemajor" -lt "$argmajor" ] || return 1 - [ "$unameminor" -lt "$argminor" ] || return 1 - return 0 + # If our major > target major, we definitely meet the requirement. + # If our major < target major, we definitely don't meet the requirement. + if [ "$unamemajor" -gt "$argmajor" ]; then + return 0 + fi + if [ "$unamemajor" -lt "$argmajor" ]; then + return 1 + fi + + # Only when our major is the same as the target, we need to compare + # the minor number. + # In this case, if our minor >= target minor, we meet the requirement. + if [ "$unameminor" -ge "$argminor" ]; then + return 0; + fi + return 1 } # Get subvolume id for specified path
Signature · 1 line
2.37.3
Re: [PATCH 1/3] btrfs-progs: tests: fix the wrong kernel version check
Quoted 30 lines · Qu Wenruo
[BUG]
After upgrading to kernel v6.0-rc, btrfs-progs selftest mkfs/001 no longer checks single device RAID0 and other new features introduced in v5.13:# make TEST=001\* test-mkfs [TEST] mkfs-tests.sh [TEST/mkfs] 001-basic-profiles $ grep -IR "RAID0\/1" tests/mkfs-tests-results.txt ^^^ No output[CAUSE]
The existingcheck_min_kernel_version()is doing an incorrect check.The old check looks like this:
[ "$unamemajor" -lt "$argmajor" ] || return 1 [ "$unameminor" -lt "$argminor" ] || return 1return 0
For 6.0-rc kernels, we have the following values for mkfs/001
$unamemajor = 6
$unameminor = 0
$argmajor = 5
$argminor = 12The first check doesn't exit immediately, as 6 > 5. Then we check the minor, which is already incorrect.
Quoted 8 lines
If our major is larger than target major, we should exit immediate with 0.
[FIX]
Fix the check and add extra comment.Personally speaking I'm not a fan or short compare and return, thus all the checks will explicit "if []; then fi" checks.
Agreed the explicit if should be used in most cases, what is probably ok a 'command || _fail' pattern for simple commands. I try to unify the shell coding style in new patches but some bits may slip through.
PATCH 2/3 btrfs-progs: mkfs-tests/025: fix the wrong function call
In reply to Qu Wenruo[BUG]
Btrfs-progs test case mkfs/025 will output the following error:
# make TEST=025\* test-mkfs
[TEST] mkfs-tests.sh
[TEST/mkfs] 025-zoned-parallel
./test.sh: line 11: !check_min_kernel_version: command not found[CAUSE]
There lacks a space between "!" and the function we called.
[FIX]
Add back the missing space.
Note that, this requires the previous fix on check_min_kernel_version(), or it will not properly work on v6.x kernels.
--- tests/mkfs-tests/025-zoned-parallel/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/mkfs-tests/025-zoned-parallel/test.sh +1 -1
@@ -8,7 +8,7 @@ source "$TEST_TOP/common" setup_root_helper prepare_test_dev -if !check_min_kernel_version 5.12; then +if ! check_min_kernel_version 5.12; then _notrun "zoned tests need kernel 5.12 and newer" fi
Signature · 1 line
2.37.3
Re: [PATCH 2/3] btrfs-progs: mkfs-tests/025: fix the wrong function call
Hi,
Quoted 27 lines
[BUG]
Btrfs-progs test case mkfs/025 will output the following error:# make TEST=025\* test-mkfs [TEST] mkfs-tests.sh [TEST/mkfs] 025-zoned-parallel ./test.sh: line 11: !check_min_kernel_version: command not found[CAUSE]
There lacks a space between "!" and the function we called.[FIX]
Add back the missing space.Note that, this requires the previous fix on
check_min_kernel_version(), or it will not properly work on v6.x kernels.Signed-off-by Qu Wenruo <[email protected]>--- tests/mkfs-tests/025-zoned-parallel/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/mkfs-tests/025-zoned-parallel/test.sh +0
-0
tests/mkfs-tests/025-zoned-parallel/test.sh source "$TEST_TOP/common" · line 13
Quoted 7 lines
tests/mkfs-tests/025-zoned-parallel/test.sh +1
-1@@ -8,7 +8,7 @@ source "$TEST_TOP/common" setup_root_helper prepare_test_dev -if !check_min_kernel_version 5.12; then +if ! check_min_kernel_version 5.12; then _notrun "zoned tests need kernel 5.12 and newer" fi
'_notrun' should be changed to '_not_run' too.
Best Regards
Wang Yugui ([email protected])
2022/10/05
Quoted 3 lines
Signature · 2 lines
-- 2.37.3
Re: [PATCH 2/3] btrfs-progs: mkfs-tests/025: fix the wrong function call
Quoted 32 lines · Wang Yugui
Hi,
Quoted 30 lines
[BUG]
Btrfs-progs test case mkfs/025 will output the following error:# make TEST=025\* test-mkfs [TEST] mkfs-tests.sh [TEST/mkfs] 025-zoned-parallel ./test.sh: line 11: !check_min_kernel_version: command not found[CAUSE]
There lacks a space between "!" and the function we called.[FIX]
Add back the missing space.Note that, this requires the previous fix on
check_min_kernel_version(), or it will not properly work on v6.x kernels.Signed-off-by Qu Wenruo <[email protected]>--- tests/mkfs-tests/025-zoned-parallel/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/mkfs-tests/025-zoned-parallel/test.sh +0
-0@@ -8,7 +8,7 @@ source "$TEST_TOP/common" setup_root_helper prepare_test_dev
Quoted 6 lines
tests/mkfs-tests/025-zoned-parallel/test.sh source "$TEST_TOP/common" · line 13
Quoted 4 lines
tests/mkfs-tests/025-zoned-parallel/test.sh +1
-1-if !check_min_kernel_version 5.12; then +if ! check_min_kernel_version 5.12; then _notrun "zoned tests need kernel 5.12 and newer" fi'
_notrun' should be changed to '_not_run' too.
That's right, I forgot this as my previous patch would render the path unreachable for newer kernels.
David, can you fix it when merging?
Thanks,
Qu
Quoted 10 lines
Best Regards
Wang Yugui ([email protected])
2022/10/05Quoted 3 lines
tests/mkfs-tests/025-zoned-parallel/test.sh +0
-1--2.37.3
Re: [PATCH 2/3] btrfs-progs: mkfs-tests/025: fix the wrong function call
Quoted 19 lines · Qu Wenruo
Quoted 11 lines · Wang Yugui
Quoted 11 lines
tests/mkfs-tests/025-zoned-parallel/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/mkfs-tests/025-zoned-parallel/test.sh +0
-0@@ -8,7 +8,7 @@ source "$TEST_TOP/common" setup_root_helper prepare_test_devQuoted 6 lines
tests/mkfs-tests/025-zoned-parallel/test.sh source "$TEST_TOP/common" · line 13
Quoted 4 lines
tests/mkfs-tests/025-zoned-parallel/test.sh +1
-1-if !check_min_kernel_version 5.12; then +if ! check_min_kernel_version 5.12; then _notrun "zoned tests need kernel 5.12 and newer" fi'
_notrun' should be changed to '_not_run' too.
Quoted 4 lines
That's right, I forgot this as my previous patch would render the path unreachable for newer kernels.
David, can you fix it when merging?
Fixed and pushed, thanks.
PATCH 3/3 btrfs-progs: convert-tests/022: add reiserfs support check
In reply to Qu Wenruo[BUG]
Btrfs-progs test case convert/022 will fail if the system doesn't have reiserfs support nor reiserfs user space tools:
# make TEST=022\* test-convert
[TEST] convert-tests.sh
WARNING: reiserfs filesystem not listed in /proc/filesystems, some tests might be skipped
[TEST/conv] 022-reiserfs-parent-ref
Failed system wide prerequisities: mkreiserfs
test failed for case 022-reiserfs-parent-ref
make: *** [Makefile:443: test-convert] Error 1[CAUSE]
Unlike other test cases, convert/022 doesn't even check if we have kernel support for it.
[FIX]
Add the proper check before doing system wide prerequisities checks.
--- tests/convert-tests/022-reiserfs-parent-ref/test.sh | 5 +++++ 1 file changed, 5 insertions(+)
tests/convert-tests/022-reiserfs-parent-ref/test.sh +5 -0
@@ -2,6 +2,11 @@ # Test that only toplevel directory self-reference is created source "$TEST_TOP/common" +source "$TEST_TOP/common.convert" + +if ! check_kernel_support_reiserfs >/dev/null; then + _not_run "no reiserfs support" +fi setup_root_helper prepare_test_dev
Signature · 1 line
2.37.3
Re: [PATCH 3/3] btrfs-progs: convert-tests/022: add reiserfs support check
Quoted 12 lines · Qu Wenruo
[BUG]
Btrfs-progs test case convert/022 will fail if the system doesn't have reiserfs support nor reiserfs user space tools:# make TEST=022\* test-convert [TEST] convert-tests.sh WARNING: reiserfs filesystem not listed in /proc/filesystems, some tests might be skipped [TEST/conv] 022-reiserfs-parent-ref Failed system wide prerequisities: mkreiserfs test failed for case 022-reiserfs-parent-ref make: *** [Makefile:443: test-convert] Error 1
Quoted 6 lines
[CAUSE]
Unlike other test cases, convert/022 doesn't even check if we have kernel support for it.[FIX]
Add the proper check before doing system wide prerequisities checks.
I've moved it before the mkreiserfs check, I'd like to keep the setup_root_helper and prepare_test_dev first in the list for consistency.
Quoted 13 lines · Qu Wenruo
There are 3 bugs exposed during my tests for unified mkfs features, and they are all from the selftest itself:
-
check_min_kernel_version()doesn't handle 6.x kernels at all The original check never handles major number check properly. And when we change major number, returns in correct number now.- Missing a space between "!" and function call
This bug is there for a long time.Without previous fix, one may incorrectly remove the "!" and cause new problems.
Quoted 6 lines
- Convert/022 doesn't check if we have support for reiserfs
Qu Wenruo (3):
btrfs-progs: tests: fix the wrong kernel version check
btrfs-progs: mkfs-tests/025: fix the wrong function call
btrfs-progs: convert-tests/022: add reiserfs support check
I've foled patch 2 to the one that that introduced it so we don't have broken tests. The other two merged to devel, thanks.