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(-)
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);
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
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)
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;
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
linux-kselftest-mirror@lists.linaro.org