Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH v2 0/3] selftests: coredump: Some bug fixes
@ 2025-04-11 15:09 Nam Cao
  2025-04-11 15:09 ` [PATCH v2 1/3] selftests: coredump: Properly initialize pointer Nam Cao
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Nam Cao @ 2025-04-11 15:09 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Shuah Khan, John Ogness, linux-kselftest, linux-kernel, Nam Cao

Hi,

While trying the coredump test on qemu-system-riscv64, I observed test
failures for various reasons.

This series makes the test works on qemu-system-riscv64.

Best regards,
Nam

v1->v2 https://lore.kernel.org/lkml/cover.1743438749.git.namcao@linutronix.de/
  - use getline() more precisely [John Ogness]
  - be absolutely safe: waitpid() for the child process, and still wait 10s
    for stack_values file to be created [John Ogness]

Nam Cao (3):
  selftests: coredump: Properly initialize pointer
  selftests: coredump: Fix test failure for slow machines
  selftests: coredump: Raise timeout to 2 minutes

 tools/testing/selftests/coredump/stackdump_test.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

-- 
2.39.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] selftests: coredump: Properly initialize pointer
  2025-04-11 15:09 [PATCH v2 0/3] selftests: coredump: Some bug fixes Nam Cao
@ 2025-04-11 15:09 ` Nam Cao
  2025-04-11 15:27   ` ALOK TIWARI
  2025-04-11 15:09 ` [PATCH v2 2/3] selftests: coredump: Fix test failure for slow machines Nam Cao
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Nam Cao @ 2025-04-11 15:09 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Shuah Khan, John Ogness, linux-kselftest, linux-kernel, Nam Cao

The buffer pointer "line" is not initialized. This pointer is passed to
getline().

It can still work if the stack is zero-initialized, because getline() can
work with a NULL pointer as buffer.

But this is obviously broken. This bug shows up while running the test on a
riscv64 machine.

Fix it by properly initializing the pointer.

Fixes: 15858da53542 ("selftests: coredump: Add stackdump test")
Signed-off-by: Nam Cao <namcao@linutronix.de>
---
 tools/testing/selftests/coredump/stackdump_test.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/coredump/stackdump_test.c b/tools/testing/selftests/coredump/stackdump_test.c
index 137b2364a082..c23cf95c3f6d 100644
--- a/tools/testing/selftests/coredump/stackdump_test.c
+++ b/tools/testing/selftests/coredump/stackdump_test.c
@@ -138,10 +138,12 @@ TEST_F(coredump, stackdump)
 	ASSERT_NE(file, NULL);
 
 	/* Step 4: Make sure all stack pointer values are non-zero */
+	line = NULL;
 	for (i = 0; -1 != getline(&line, &line_length, file); ++i) {
 		stack = strtoull(line, NULL, 10);
 		ASSERT_NE(stack, 0);
 	}
+	free(line);
 
 	ASSERT_EQ(i, 1 + NUM_THREAD_SPAWN);
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] selftests: coredump: Fix test failure for slow machines
  2025-04-11 15:09 [PATCH v2 0/3] selftests: coredump: Some bug fixes Nam Cao
  2025-04-11 15:09 ` [PATCH v2 1/3] selftests: coredump: Properly initialize pointer Nam Cao
@ 2025-04-11 15:09 ` Nam Cao
  2025-04-11 15:09 ` [PATCH v2 3/3] selftests: coredump: Raise timeout to 2 minutes Nam Cao
  2025-04-14 11:08 ` [PATCH v2 0/3] selftests: coredump: Some bug fixes Christian Brauner
  3 siblings, 0 replies; 6+ messages in thread
From: Nam Cao @ 2025-04-11 15:09 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Shuah Khan, John Ogness, linux-kselftest, linux-kernel, Nam Cao

The test waits for coredump to finish by busy-waiting for the stack_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.

Fix it by waiting for the crashing child process to finish first.

Fixes: 15858da53542 ("selftests: coredump: Add stackdump test")
Signed-off-by: Nam Cao <namcao@linutronix.de>
---
 tools/testing/selftests/coredump/stackdump_test.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/coredump/stackdump_test.c b/tools/testing/selftests/coredump/stackdump_test.c
index c23cf95c3f6d..9da10fb5e597 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;
 
@@ -129,6 +129,10 @@ TEST_F(coredump, stackdump)
 	/*
 	 * Step 3: Wait for the stackdump script to write the stack pointers to the stackdump file
 	 */
+	waitpid(pid, &status, 0);
+	ASSERT_TRUE(WIFSIGNALED(status));
+	ASSERT_TRUE(WCOREDUMP(status));
+
 	for (i = 0; i < 10; ++i) {
 		file = fopen(STACKDUMP_FILE, "r");
 		if (file)
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] selftests: coredump: Raise timeout to 2 minutes
  2025-04-11 15:09 [PATCH v2 0/3] selftests: coredump: Some bug fixes Nam Cao
  2025-04-11 15:09 ` [PATCH v2 1/3] selftests: coredump: Properly initialize pointer Nam Cao
  2025-04-11 15:09 ` [PATCH v2 2/3] selftests: coredump: Fix test failure for slow machines Nam Cao
@ 2025-04-11 15:09 ` Nam Cao
  2025-04-14 11:08 ` [PATCH v2 0/3] selftests: coredump: Some bug fixes Christian Brauner
  3 siblings, 0 replies; 6+ messages in thread
From: Nam Cao @ 2025-04-11 15:09 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Shuah Khan, John Ogness, linux-kselftest, linux-kernel, Nam Cao

The test's runtime (nearly 20s) is dangerously close to the limit (30s) on
qemu-system-riscv64:

$ time ./stackdump_test > /dev/null
real	0m19.210s
user	0m0.077s
sys	0m0.359s

There could be machines slower than qemu-system-riscv64. Therefore raise
the test timeout to 2 minutes to be safe.

Fixes: 15858da53542 ("selftests: coredump: Add stackdump test")
Signed-off-by: Nam Cao <namcao@linutronix.de>
---
 tools/testing/selftests/coredump/stackdump_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/coredump/stackdump_test.c b/tools/testing/selftests/coredump/stackdump_test.c
index 9da10fb5e597..fe3c728cd6be 100644
--- a/tools/testing/selftests/coredump/stackdump_test.c
+++ b/tools/testing/selftests/coredump/stackdump_test.c
@@ -89,7 +89,7 @@ FIXTURE_TEARDOWN(coredump)
 	fprintf(stderr, "Failed to cleanup stackdump test: %s\n", reason);
 }
 
-TEST_F(coredump, stackdump)
+TEST_F_TIMEOUT(coredump, stackdump, 120)
 {
 	struct sigaction action = {};
 	unsigned long long stack;
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/3] selftests: coredump: Properly initialize pointer
  2025-04-11 15:09 ` [PATCH v2 1/3] selftests: coredump: Properly initialize pointer Nam Cao
@ 2025-04-11 15:27   ` ALOK TIWARI
  0 siblings, 0 replies; 6+ messages in thread
From: ALOK TIWARI @ 2025-04-11 15:27 UTC (permalink / raw)
  To: Nam Cao, Christian Brauner
  Cc: Shuah Khan, John Ogness, linux-kselftest, linux-kernel



On 11-04-2025 20:39, Nam Cao wrote:
>   	/* Step 4: Make sure all stack pointer values are non-zero */
> +	line = NULL;

such case it should initialize at declaration time.
better to move up char *test_dir, *line = NULL;

>   	for (i = 0; -1 != getline(&line, &line_length, file); ++i) {
>   		stack = strtoull(line, NULL, 10);
>   		ASSERT_NE(stack, 0);
>   	}


Thanks,
Alok

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/3] selftests: coredump: Some bug fixes
  2025-04-11 15:09 [PATCH v2 0/3] selftests: coredump: Some bug fixes Nam Cao
                   ` (2 preceding siblings ...)
  2025-04-11 15:09 ` [PATCH v2 3/3] selftests: coredump: Raise timeout to 2 minutes Nam Cao
@ 2025-04-14 11:08 ` Christian Brauner
  3 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2025-04-14 11:08 UTC (permalink / raw)
  To: Nam Cao
  Cc: Christian Brauner, Shuah Khan, John Ogness, linux-kselftest,
	linux-kernel

On Fri, 11 Apr 2025 17:09:40 +0200, Nam Cao wrote:
> While trying the coredump test on qemu-system-riscv64, I observed test
> failures for various reasons.
> 
> This series makes the test works on qemu-system-riscv64.
> 
> Best regards,
> Nam
> 
> [...]

Applied to the vfs-6.16.coredump branch of the vfs/vfs.git tree.
Patches in the vfs-6.16.coredump branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.16.coredump

[1/3] selftests: coredump: Properly initialize pointer
      https://git.kernel.org/vfs/vfs/c/b3da3c6ce9f6
[2/3] selftests: coredump: Fix test failure for slow machines
      https://git.kernel.org/vfs/vfs/c/05ac92f73615
[3/3] selftests: coredump: Raise timeout to 2 minutes
      https://git.kernel.org/vfs/vfs/c/52cfbe664dc9

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-04-14 11:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11 15:09 [PATCH v2 0/3] selftests: coredump: Some bug fixes Nam Cao
2025-04-11 15:09 ` [PATCH v2 1/3] selftests: coredump: Properly initialize pointer Nam Cao
2025-04-11 15:27   ` ALOK TIWARI
2025-04-11 15:09 ` [PATCH v2 2/3] selftests: coredump: Fix test failure for slow machines Nam Cao
2025-04-11 15:09 ` [PATCH v2 3/3] selftests: coredump: Raise timeout to 2 minutes Nam Cao
2025-04-14 11:08 ` [PATCH v2 0/3] selftests: coredump: Some bug fixes Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox