Skip to contentSkip to conversation

fstests: btrfs/253: fix false alert due to _set_fs_sysfs_attr changes

PATCH In review Qu Wenruo 2 participants 2 messages Apr 21, 2025 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH v2 1/1 fstests: btrfs/253: fix false alert due to _set_fs_sysfs_attr changes

[FALSE FAILURE]
Test btrfs/253 now fails like the following:

btrfs/253 2s ... - output mismatch (see ~/xfstests/results//btrfs/253.out.bad)
--- tests/btrfs/253.out 2022-05-11 11:25:30.753333331 +0930
+++ ~/xfstests/results//btrfs/253.out.bad 2025-04-20 17:28:39.139180394 +0930
@@ -5,6 +5,7 @@
Calculate request size so last memory allocation cannot be completely fullfilled.
Third allocation.
Force allocation of system block type must fail.
+./common/rc: line 5213: echo: write error: No space left on device
Verify first allocation.
Verify second allocation.
Verify third allocation.
...
(Run 'diff -u ~/xfstests/tests/btrfs/253.out ~/xfstests/results//btrfs/253.out.bad' to see the entire diff)

[CAUSE]
Since commit 0a9011ae6a36 ("fstests: common/rc: set_fs_sysfs_attr:
redirect errors to stdout") the function _set_fs_sysfs_attr() always output everything into stdout, thus the stderr redirection makes no sense anymore.

And the expected failure will cause output difference and fail the test.

[FIX]
Use the helper _set_sysfs_policy_must_fail() instead, which will handle the failure.
And update the golden output to include the expected ENOSPC error message.

Fixes 0a9011ae6a36 ("fstests: common/rc: set_fs_sysfs_attr: redirect errors to stdout")

---
Changelog:
v2:
- use _set_sysfs_policy_must_fail() helper instead

---
 tests/btrfs/253     | 3 ++-
 tests/btrfs/253.out | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
tests/btrfs/253 +2 -1
index adbc6bfb..96ab140f 100755
@@ -25,6 +25,7 @@
 #       value is in megabytes.
 #
 . ./common/preamble
+. ./common/sysfs
 _begin_fstest auto
 
 seq=`basename $0`
@@ -228,7 +229,7 @@ alloc_size "Data" FOURTH_DATA_SIZE_MB
 # Force chunk allocation of system block type must fail.
 #
 echo "Force allocation of system block type must fail."
-_set_fs_sysfs_attr ${SCRATCH_BDEV} allocation/system/force_chunk_alloc 1 2>/dev/null
+_set_sysfs_policy_must_fail ${SCRATCH_BDEV} allocation/system/force_chunk_alloc 1
 
 #
 # Verification of initial allocation.
tests/btrfs/253.out +1 -0
index 6eea60f0..5aa75d54 100644
@@ -5,6 +5,7 @@ Second allocation.
 Calculate request size so last memory allocation cannot be completely fullfilled.
 Third allocation.
 Force allocation of system block type must fail.
+No space left on device
 Verify first allocation.
 Verify second allocation.
 Verify third allocation.
Signature · 1 line
2.47.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 26 lines · Qu Wenruo

[FALSE FAILURE]
Test btrfs/253 now fails like the following:

btrfs/253 2s ... - output mismatch (see ~/xfstests/results//btrfs/253.out.bad)
--- tests/btrfs/253.out 2022-05-11 11:25:30.753333331 +0930
+++ ~/xfstests/results//btrfs/253.out.bad 2025-04-20 17:28:39.139180394 +0930
@@ -5,6 +5,7 @@
Calculate request size so last memory allocation cannot be completely fullfilled.
Third allocation.
Force allocation of system block type must fail.
+./common/rc: line 5213: echo: write error: No space left on device
Verify first allocation.
Verify second allocation.
Verify third allocation.
...
(Run 'diff -u ~/xfstests/tests/btrfs/253.out ~/xfstests/results//btrfs/253.out.bad' to see the entire diff)

[CAUSE]
Since commit 0a9011ae6a36 ("fstests: common/rc: set_fs_sysfs_attr:
redirect errors to stdout") the function _set_fs_sysfs_attr() always output everything into stdout, thus the stderr redirection makes no sense anymore.

Quoted 8 lines

And the expected failure will cause output difference and fail the test.

[FIX]
Use the helper _set_sysfs_policy_must_fail() instead, which will handle the failure.
And update the golden output to include the expected ENOSPC error message.

Yep. If we expect an error, sending it to /dev/null isn't ideal — it should be in the golden output. All good now.

Added to for-next.

Thanks, Anand

Quoted 44 lines
Fixes 0a9011ae6a36 ("fstests: common/rc: set_fs_sysfs_attr: redirect errors to stdout")

---
Changelog:
v2:
- use _set_sysfs_policy_must_fail() helper instead

---
  tests/btrfs/253     | 3 ++-
  tests/btrfs/253.out | 1 +
  2 files changed, 3 insertions(+), 1 deletion(-)
tests/btrfs/253 +2 -1
index adbc6bfb..96ab140f 100755
@@ -25,6 +25,7 @@
  #       value is in megabytes.
  #
  . ./common/preamble
+. ./common/sysfs
  _begin_fstest auto
 
  seq=`basename $0`
@@ -228,7 +229,7 @@ alloc_size "Data" FOURTH_DATA_SIZE_MB
  # Force chunk allocation of system block type must fail.
  #
  echo "Force allocation of system block type must fail."
-_set_fs_sysfs_attr ${SCRATCH_BDEV} allocation/system/force_chunk_alloc 1 2>/dev/null
+_set_sysfs_policy_must_fail ${SCRATCH_BDEV} allocation/system/force_chunk_alloc 1
 
  #
  # Verification of initial allocation.
tests/btrfs/253.out +1 -0
index 6eea60f0..5aa75d54 100644
@@ -5,6 +5,7 @@ Second allocation.
  Calculate request size so last memory allocation cannot be completely fullfilled.
  Third allocation.
  Force allocation of system block type must fail.
+No space left on device
  Verify first allocation.
  Verify second allocation.
  Verify third allocation.