diff mbox series

[v2,4/4] btrfs-progs: fix misc/038 test cases

Message ID 909e5e66fdbb40c9afe59175a0ed73741b8e22c8.1717544015.git.wqu@suse.com (mailing list archive)
State New
Headers show
Series btrfs-progs: small bug fixes | expand

Commit Message

Qu Wenruo June 4, 2024, 11:43 p.m. UTC
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.

Furthermore on the github CI, the kernel would commit 2 instead of 1
transaction, resulting the next slot never to match the current
generation/tree root.

The two bugs combined, resulting github CI always pass the test case,
meanwhile for my VM which does the expected one transaction, it would
always fail.

Fix it by:

- Use a proper "if [] then; fi" block to check the tree root bytenr
- Use the generation diff to calculate the expected backup root slot
- Log the full super block dump for debug usage

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 .../038-backup-root-corruption/test.sh           | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/tests/misc-tests/038-backup-root-corruption/test.sh b/tests/misc-tests/038-backup-root-corruption/test.sh
index 9be0cee36239..28aa5baec91e 100755
--- a/tests/misc-tests/038-backup-root-corruption/test.sh
+++ b/tests/misc-tests/038-backup-root-corruption/test.sh
@@ -41,6 +41,9 @@  slot_num=$(echo $found | cut -f1 -d:)
 # To follow the dump-super output, where backup slot starts at 0.
 slot_num=$(($slot_num - 1))
 
+_log "Original superblock:"
+_log "$(dump_super)"
+
 # Save the backup slot info into the log
 _log "Backup slot $slot_num will be utilized"
 dump_super | run_check grep -A9 "backup $slot_num:"
@@ -56,9 +59,14 @@  run_check_mount_test_dev -o usebackuproot
 run_check_umount_test_dev
 
 main_root_ptr=$(dump_super | awk '/^root\t/{print $2}')
-
-# The next slot should be overwritten
-slot_num=$(( ($slot_num + 1) % 4 ))
+cur_gen=$(dump_super | grep ^generation | awk '{print $2}')
+# The slot to be used is based on how many transaction committed.
+slot_num=$(( ($slot_num + $cur_gen - $backup_gen) % 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"
+_log "After the backup usage:"
+_log "$(dump_super)"
+
+if [ "$main_root_ptr" -ne "$backup_new_root_ptr" ]; then
+	_fail "Backup ${slot_num} not overwritten"
+fi