FS/XFS testing framework
 help / color / mirror / Atom feed
From: Zorro Lang <zlang@kernel.org>
To: ChenXiaoSong <chenxiaosong@chenxiaosong.com>
Cc: smfrench@gmail.com, linkinjeon@kernel.org, pc@manguebit.org,
	 ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com,
	bharathsm@microsoft.com,  senozhatsky@chromium.org,
	dhowells@redhat.com, metze@samba.org, linux-cifs@vger.kernel.org,
	 fstests@vger.kernel.org, ChenXiaoSong <chenxiaosong@kylinos.cn>
Subject: Re: [PATCH v3 xfstests 2/2] generic: new test to check nlink returned by fstat()
Date: Tue, 28 Jul 2026 17:56:39 +0800	[thread overview]
Message-ID: <amhXZgFrXgYkuOTb@zlang-mailbox> (raw)
In-Reply-To: <20260724031210.332153-3-chenxiaosong@chenxiaosong.com>

On Fri, Jul 24, 2026 at 03:12:10AM +0000, ChenXiaoSong wrote:
> From: ChenXiaoSong <chenxiaosong@kylinos.cn>
> 
> Add a test to verify that fstat(2) returns the expected
> st_nlink value as hardlinks are created and removed.
> 
> Regression test for kernel commit:
> 9dd1964ac59d ("smb/client: fix incorrect nlink returned by fstat()")
> 
> Suggested-by: Zorro Lang <zlang@kernel.org>
> Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
> ---
>  tests/generic/798     | 60 +++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/798.out |  2 ++
>  2 files changed, 62 insertions(+)
>  create mode 100755 tests/generic/798
>  create mode 100644 tests/generic/798.out
> 
> diff --git a/tests/generic/798 b/tests/generic/798
> new file mode 100755
> index 00000000..e44bb10a
> --- /dev/null
> +++ b/tests/generic/798
> @@ -0,0 +1,60 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2026 KylinSoft Co., Ltd. All rights reserved.
> +# Author(s): ChenXiaoSong <chenxiaosong@kylinos.cn>
> +#
> +# FS QA Test 798
> +#
> +# Check that fstat(2) returns the correct hard link count for a regular file.
> +#
> +#  from
> +#  tests/generic/002
> +#  Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
> +#
> +. ./common/preamble
> +_begin_fstest metadata auto quick hardlink
> +
> +_cleanup()
> +{
> +	cd /
> +	rm -rf "$tmp".* "$testdir"
> +}
> +
> +_require_test
> +_require_hardlinks
> +
> +_fixed_by_fs_commit cifs 9dd1964ac59d \
> +	"smb/client: fix incorrect nlink returned by fstat()"
> +
> +_get_nlink()
> +{
> +	$XFS_IO_PROG -c 'stat -r' "$1" |
> +		sed -n 's/^stat\.nlink = //p'
> +}
> +
> +status=0

We set "status=1" in _begin_fstest. You can remove this line, and then ...

> +testdir=$TEST_DIR/$seq
> +rm -rf "$testdir"
> +mkdir "$testdir"
> +
> +touch "$testdir/tmp.1"
> +for ((l = 2; l <= 20; l++)); do
> +	ln "$testdir/tmp.1" "$testdir/tmp.$l"
> +	nlink=$(_get_nlink "$testdir/tmp.1")
> +	if [ "$nlink" != "$l" ]; then
> +		echo "Expected nlink $l after creating link $l, got ${nlink:-nothing}"
> +		status=1

... The current "echo" output is already sufficient to break the golden image
and cause the test to fail, so set "status=1" isn't necessary. Alternatively,
if you feel there's no need to continue the rest of the loop once a failure is
detected, you can use "_fail" to replace "echo" instead.

> +	fi
> +done
> +
> +for ((l = 20; l >= 1; l--)); do
> +	nlink=$(_get_nlink "$testdir/tmp.1")
> +	if [ "$nlink" != "$l" ]; then
> +		echo "Expected nlink $l before removing link $l, got ${nlink:-nothing}"
> +		status=1

Same here

> +	fi
> +	rm -f "$testdir/tmp.$l"
> +done
> +
> +echo "Silence is golden"
> +exit $status

then you can write "_exit 0" at here.

Thanks,
Zorro

> diff --git a/tests/generic/798.out b/tests/generic/798.out
> new file mode 100644
> index 00000000..216d6e93
> --- /dev/null
> +++ b/tests/generic/798.out
> @@ -0,0 +1,2 @@
> +QA output created by 798
> +Silence is golden
> -- 
> 2.43.0
> 

  reply	other threads:[~2026-07-28  9:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24  3:12 [PATCH v3 xfstests 0/2] generic: new test to check nlink returned by fstat() ChenXiaoSong
2026-07-24  3:12 ` [PATCH v3 xfstests 1/2] generic/002: simplify the hardlink count test ChenXiaoSong
2026-07-28 10:13   ` Zorro Lang
2026-07-24  3:12 ` [PATCH v3 xfstests 2/2] generic: new test to check nlink returned by fstat() ChenXiaoSong
2026-07-28  9:56   ` Zorro Lang [this message]
2026-07-28  3:38 ` [PATCH v3 xfstests 0/2] " Christoph Hellwig

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=amhXZgFrXgYkuOTb@zlang-mailbox \
    --to=zlang@kernel.org \
    --cc=bharathsm@microsoft.com \
    --cc=chenxiaosong@chenxiaosong.com \
    --cc=chenxiaosong@kylinos.cn \
    --cc=dhowells@redhat.com \
    --cc=fstests@vger.kernel.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=metze@samba.org \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=senozhatsky@chromium.org \
    --cc=smfrench@gmail.com \
    --cc=sprasad@microsoft.com \
    --cc=tom@talpey.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