From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Josef Bacik <josef@toxicpanda.com>, Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: fix a check condition in misc/038
Date: Wed, 5 Jun 2024 07:38:39 +0930 [thread overview]
Message-ID: <b06a8ffc-f45b-4bf3-a5b3-64877771a549@gmx.com> (raw)
In-Reply-To: <20240604155454.GA3413@localhost.localdomain>
在 2024/6/5 01:24, Josef Bacik 写道:
> 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.
Well that's true, but at the same time when one see such line, it will
takes more time to fully understand the check.
Thus that's why I hate such line, it takes me over 15 min to find out
that everything is fine, except the last line.
So I really hope no new comers would spend their time to fall into the
same hole.
>
>> 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
I thought we prefer ${} to be more safe, but since it's followed by a
space, it should be no difference.
I'll update the patch for more debugging, since on CI it fails (not sure
if it's kernel or something else), but I'm afraid the "if [] then; fi"
would be kept.
Thanks,
Qu
>
> [ "$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 22:08 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
2024-06-04 22:08 ` Qu Wenruo [this message]
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=b06a8ffc-f45b-4bf3-a5b3-64877771a549@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=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