From ff1ff014f0e10c3f53165d3e2aa7f480135e7b66 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Tue, 4 Jun 2024 15:01:25 +0930 Subject: [PATCH] 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 Signed-off-by: David Sterba --- .../038-backup-root-corruption/test.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/misc-tests/038-backup-root-corruption/test.sh b/tests/misc-tests/038-backup-root-corruption/test.sh index 9be0cee3..d276386f 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 are 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