Skip to content

Commit ff1ff01

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: tests: in misc/038 test cases
The test case always fails 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, 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 commits 2 instead of 1 transaction, resulting the next slot never to match the current generation/tree root. The two bugs combined, github CI always passses the test case, while 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> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 0eeb12a commit ff1ff01

File tree

1 file changed

+12
-4
lines changed
  • tests/misc-tests/038-backup-root-corruption

1 file changed

+12
-4
lines changed

tests/misc-tests/038-backup-root-corruption/test.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ slot_num=$(echo $found | cut -f1 -d:)
4141
# To follow the dump-super output, where backup slot starts at 0.
4242
slot_num=$(($slot_num - 1))
4343

44+
_log "Original superblock:"
45+
_log "$(dump_super)"
46+
4447
# Save the backup slot info into the log
4548
_log "Backup slot $slot_num will be utilized"
4649
dump_super | run_check grep -A9 "backup $slot_num:"
@@ -56,9 +59,14 @@ run_check_mount_test_dev -o usebackuproot
5659
run_check_umount_test_dev
5760

5861
main_root_ptr=$(dump_super | awk '/^root\t/{print $2}')
59-
60-
# The next slot should be overwritten
61-
slot_num=$(( ($slot_num + 1) % 4 ))
62+
cur_gen=$(dump_super | grep ^generation | awk '{print $2}')
63+
# The slot to be used is based on how many transaction are committed.
64+
slot_num=$(( ($slot_num + $cur_gen - $backup_gen) % 4 ))
6265
backup_new_root_ptr=$(dump_super | grep -A1 "backup $slot_num" | grep backup_tree_root | awk '{print $2}')
6366

64-
[ "$main_root_ptr" -ne "$backup_new_root_ptr" ] || _fail "Backup 2 not overwritten"
67+
_log "After the backup usage:"
68+
_log "$(dump_super)"
69+
70+
if [ "$main_root_ptr" -ne "$backup_new_root_ptr" ]; then
71+
_fail "Backup ${slot_num} not overwritten"
72+
fi

0 commit comments

Comments
 (0)