Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: fix a check condition in misc/038
@ 2024-06-04  6:00 Qu Wenruo
  2024-06-04 15:54 ` Josef Bacik
  0 siblings, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2024-06-04  6:00 UTC (permalink / raw)
  To: linux-btrfs

The test case always fail in my VM, with the following error:

 $ sudo TEST=038\* make test-misc
    [TEST]   misc-tests.sh
    [TEST/misc]   038-backup-root-corruption
 Backup 2 not overwritten
 test failed for case 038-backup-root-corruption

After more debugging, the it turns out that there is nothing wrong
except the final check:

 [ "$main_root_ptr" -ne "$backup_new_root_ptr" ] || _fail "Backup 2 not overwritten"

The _fail() is only triggered if the previous check returns false, which
is completely the opposite.

In fact the "[ check ] || _fail" pattern is the worst thing in the bash
world, super easy to cause the opposite check condition.

Fix it by use a proper "if []; then fi" block, and since we're here also
update the error message to use the newest slot number instead.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 tests/misc-tests/038-backup-root-corruption/test.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/misc-tests/038-backup-root-corruption/test.sh b/tests/misc-tests/038-backup-root-corruption/test.sh
index 9be0cee36239..0f97577849cc 100755
--- a/tests/misc-tests/038-backup-root-corruption/test.sh
+++ b/tests/misc-tests/038-backup-root-corruption/test.sh
@@ -61,4 +61,6 @@ main_root_ptr=$(dump_super | awk '/^root\t/{print $2}')
 slot_num=$(( ($slot_num + 1) % 4 ))
 backup_new_root_ptr=$(dump_super | grep -A1 "backup $slot_num" | grep backup_tree_root | awk '{print $2}')
 
-[ "$main_root_ptr" -ne "$backup_new_root_ptr" ] || _fail "Backup 2 not overwritten"
+if [ "$main_root_ptr" -ne "$backup_new_root_ptr" ]; then
+	_fail "Backup ${slot_num} not overwritten"
+fi
-- 
2.45.2


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

end of thread, other threads:[~2024-06-05 18:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-04  6:00 [PATCH] btrfs-progs: fix a check condition in misc/038 Qu Wenruo
2024-06-04 15:54 ` Josef Bacik
2024-06-04 22:08   ` Qu Wenruo
2024-06-05 18:02     ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox