From: John Ogness <john.ogness@linutronix.de>
To: Nam Cao <namcao@linutronix.de>, Christian Brauner <brauner@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Nam Cao <namcao@linutronix.de>
Subject: Re: [PATCH 2/3] selftests: coredump: Use waitpid() instead of busy-wait
Date: Tue, 01 Apr 2025 14:14:28 +0206 [thread overview]
Message-ID: <84y0wkkrsz.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <133d0dc62cebb6fde2764af384b0166d98755a3c.1743438749.git.namcao@linutronix.de>
On 2025-03-31, Nam Cao <namcao@linutronix.de> wrote:
> The test waits for coredump to finish by busy-waiting for the
> stackdump_values file to be created. The maximum wait time is 10 seconds.
>
> This doesn't work for slow machine (qemu-system-riscv64), because coredump
> takes longer.
>
> Switch to use waitpid().
Note that you are now assuming that returning from waitpid() means that:
1. the coredumping has completed
and
2. the STACKDUMP_FILE with all its contents are visible to the parent
process
> With this, the stack_values file doesn't need to be atomically written by
> coredump anymore, therefore simplify the stackdump script.
>
> Fixes: 15858da53542 ("selftests: coredump: Add stackdump test")
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> ---
> tools/testing/selftests/coredump/stackdump | 6 +-----
> tools/testing/selftests/coredump/stackdump_test.c | 13 ++++++-------
> 2 files changed, 7 insertions(+), 12 deletions(-)
>
> diff --git a/tools/testing/selftests/coredump/stackdump b/tools/testing/selftests/coredump/stackdump
> index 96714ce42d12..ad487fd5ff15 100755
> --- a/tools/testing/selftests/coredump/stackdump
> +++ b/tools/testing/selftests/coredump/stackdump
> @@ -4,11 +4,7 @@
> CRASH_PROGRAM_ID=$1
> STACKDUMP_FILE=$2
>
> -TMP=$(mktemp)
> -
> for t in /proc/$CRASH_PROGRAM_ID/task/*; do
> tid=$(basename $t)
> - cat /proc/$tid/stat | awk '{print $29}' >> $TMP
> + cat /proc/$tid/stat | awk '{print $29}' >> $STACKDUMP_FILE
> done
> -
> -mv $TMP $STACKDUMP_FILE
I would leave this as it was. Then the availability of STACKDUMP_FILE
means the full contents are available.
> diff --git a/tools/testing/selftests/coredump/stackdump_test.c b/tools/testing/selftests/coredump/stackdump_test.c
> index 1dc54e128586..733feaa0f895 100644
> --- a/tools/testing/selftests/coredump/stackdump_test.c
> +++ b/tools/testing/selftests/coredump/stackdump_test.c
> @@ -96,7 +96,7 @@ TEST_F(coredump, stackdump)
> char *test_dir, *line;
> size_t line_length;
> char buf[PATH_MAX];
> - int ret, i;
> + int ret, i, status;
> FILE *file;
> pid_t pid;
>
> @@ -131,12 +131,11 @@ TEST_F(coredump, stackdump)
> /*
> * Step 3: Wait for the stackdump script to write the stack pointers to the stackdump file
> */
> - for (i = 0; i < 10; ++i) {
> - file = fopen(STACKDUMP_FILE, "r");
> - if (file)
> - break;
> - sleep(1);
> - }
> + waitpid(pid, &status, 0);
> + ASSERT_TRUE(WIFSIGNALED(status));
> + ASSERT_TRUE(WCOREDUMP(status));
Why not just put these 3 lines above the for-loop? So you would wait for
the process to end, then go into the 20-second timeout loop waiting for
STACKDUMP_FILE to show up.
John Ogness
next prev parent reply other threads:[~2025-04-01 12:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-31 16:50 [PATCH 0/3] selftests: coredump: Some bug fixes Nam Cao
2025-03-31 16:50 ` [PATCH 1/3] selftests: coredump: Properly initialize pointer Nam Cao
2025-04-01 7:56 ` John Ogness
2025-03-31 16:50 ` [PATCH 2/3] selftests: coredump: Use waitpid() instead of busy-wait Nam Cao
2025-04-01 12:08 ` John Ogness [this message]
2025-03-31 16:50 ` [PATCH 3/3] selftests: coredump: Raise timeout to 2 minutes Nam Cao
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=84y0wkkrsz.fsf@jogness.linutronix.de \
--to=john.ogness@linutronix.de \
--cc=brauner@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=namcao@linutronix.de \
--cc=shuah@kernel.org \
/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
all inboxes | Powered by JetHome®