selftests: coredump: Some bug fixes
v2 cover selftests: coredump: Some bug fixes
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/[email protected]/
- 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(-)
Signature · 1 line
2.39.5
PATCH v2 1/3 selftests: coredump: Properly initialize pointer
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.
--- tools/testing/selftests/coredump/stackdump_test.c | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/coredump/stackdump_test.c +2 -0
@@ -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 );
Signature · 1 line
2.39.5
PATCH v2 2/3 selftests: coredump: Fix test failure for slow machines
In reply to Nam CaoThe 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.
--- tools/testing/selftests/coredump/stackdump_test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/testing/selftests/coredump/stackdump_test.c +5 -1
@@ -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)
Signature · 1 line
2.39.5
PATCH v2 3/3 selftests: coredump: Raise timeout to 2 minutes
In reply to Nam CaoThe 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.
--- tools/testing/selftests/coredump/stackdump_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/coredump/stackdump_test.c +1 -1
@@ -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;
Signature · 1 line
2.39.5
Re: [PATCH v2 1/3] selftests: coredump: Properly initialize pointer
In reply to Nam Caotools/testing/selftests/coredump/stackdump_test.c TEST_F(coredump, stackdump) · line 141
Quoted 2 lines · Nam Cao
/* Step 4: Make sure all stack pointer values are non-zero */
tools/testing/selftests/coredump/stackdump_test.c +1
-0+ line =NULL ;
such case it should initialize at declaration time. better to move up char *test_dir, *line = NULL;
Quoted 4 lines
for (i = 0; -1 != getline(&line, &line_length, file); ++i) {
stack = strtoull(line, NULL, 10);
ASSERT_NE(stack, 0);
}Thanks,
Alok
Christian Brauner
AppliedQuoted 9 lines · Nam Cao
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