From: Josef Bacik <josef@toxicpanda.com>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: fix a check condition in misc/038
Date: Tue, 4 Jun 2024 11:54:54 -0400 [thread overview]
Message-ID: <20240604155454.GA3413@localhost.localdomain> (raw)
In-Reply-To: <a49e6b43e3c140995567fea035017309b4bcd53c.1717480797.git.wqu@suse.com>
On Tue, Jun 04, 2024 at 03:30:00PM +0930, Qu Wenruo wrote:
> 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.
>
Except we do this all of the time, we should be used to it by now.
> 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"
Don't we prefer just "$slot_num"? I feel like I've gotten yelld at for this
before. Just change the existing thing to be correct
[ "$main_root_ptr" -eq "$backup_new_root_ptr" ] || _fail "Backup $slot_num not overwritten"
Thanks,
Josef
next prev parent reply other threads:[~2024-06-04 15:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-04 6:00 [PATCH] btrfs-progs: fix a check condition in misc/038 Qu Wenruo
2024-06-04 15:54 ` Josef Bacik [this message]
2024-06-04 22:08 ` Qu Wenruo
2024-06-05 18:02 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240604155454.GA3413@localhost.localdomain \
--to=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox