coredump testing suite
v6 cover coredump testing suite
Add a simple coredump01 test that simulate a coredump and verify that it actually works. This is a small coverage that is missing inside LTP testing suite.
---
Changes in v6:
- coredump01 check Elf
- add coredump02 test for Elf validation
- Link to v5: https://lore.kernel.org/[email protected]
Changes in v5:
- resolve path from root for helper
- Link to v4: https://lore.kernel.org/[email protected]
Changes in v4:
- read back core_pattern after writing and abort with TBROK on mismatch
- read CONFIG_STATIC_USERMODEHELPER once in setup() and cache the result
- remove namespace visibility scaffolding and skip logic from verify_pipe_pattern()
- resolve helper path with tst_get_path() instead of /proc/self/exe readlink
- Link to v3: https://lore.kernel.org/[email protected]
Changes in v3:
- check for CONFIG_COREDUMP=y
- Link to v2: https://lore.kernel.org/[email protected]
Changes in v2:
- fix CI agent spotted errors
- Link to v1: https://lore.kernel.org/[email protected]
To: Linux Test Project <[email protected]>
---
Andrea Cervesato (2):
coredump01: New core_pattern specifiers test
coredump02: Verify ELF structure and notes
runtest/kernel_misc | 2 + testcases/kernel/Makefile | 1 + testcases/kernel/coredump/.gitignore | 3 + testcases/kernel/coredump/Makefile | 7 + testcases/kernel/coredump/coredump01.c | 212 +++++++++++++++++++++ testcases/kernel/coredump/coredump01_helper.c | 73 ++++++++ testcases/kernel/coredump/coredump02.c | 253 ++++++++++++++++++++++++++ 7 files changed, 551 insertions(+)
---
base-commit: d377d1cff1ec393459a136eec85088ffd5729430
change-id: 20260820-coredump-22fc731bde08
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 1/2 coredump01: New core_pattern specifiers test
From: Andrea Cervesato <[email protected]>
LTP has no coverage for the core_pattern specifiers expansion, neither for the pipe flavor of core_pattern, where the kernel spawns a user space helper and writes the core dump into its standard input.
The new test verifies that %e, %p and %s are expanded both in the core file name and in the arguments of a piped helper, checking also that the helper really receives an ELF core dump.
Root is required to rewrite the system wide core_pattern, which is restored by the test library on all exit paths.
--- runtest/kernel_misc | 1 + testcases/kernel/Makefile | 1 + testcases/kernel/coredump/.gitignore | 2 + testcases/kernel/coredump/Makefile | 7 + testcases/kernel/coredump/coredump01.c | 212 ++++++++++++++++++++++++++ testcases/kernel/coredump/coredump01_helper.c | 73 +++++++++ 6 files changed, 296 insertions(+)
runtest/kernel_misc +1 -0
@@ -17,3 +17,4 @@ zram02 zram02.sh zram03 zram03 umip_basic_test umip_basic_test aslr01 aslr01 +coredump01 coredump01
testcases/kernel/Makefile +1 -0
@@ -19,6 +19,7 @@ SUBDIRS += lib SUBDIRS += connectors \ containers \ controllers \ + coredump \ crypto \ device-drivers \ firmware \
testcases/kernel/coredump/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/coredump01 +/coredump01_helper
testcases/kernel/coredump/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2026 Linux Test Project + +top_srcdir ?= ../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/coredump/coredump01.c new file +212 -0
212 lines not on this page · raw message
testcases/kernel/coredump/coredump01_helper.c new file +73 -0
73 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] coredump01: New core_pattern specifiers test
Hi Andrea,
Quoted 1 line · Andrea Cervesato
coredump01: New
core_patternspecifiers test
--- [PATCH 2/2] ---
Quoted 3 lines
Verify that a kernel-generated core dump contains a valid ELF header, expected program headers (
PT_NOTEandPT_LOAD), and valid process metadata notes (NT_PRPSINFOandNT_PRSTATUS).
The commit message only restates what the test verifies. Please explain why this coverage is needed or what problem it addresses.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 2/2 coredump02: Verify ELF structure and notes
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that a kernel-generated core dump contains a valid ELF header, expected program headers (PT_NOTE and PT_LOAD), and valid process metadata notes (NT_PRPSINFO and NT_PRSTATUS).
--- runtest/kernel_misc | 1 + testcases/kernel/coredump/.gitignore | 1 + testcases/kernel/coredump/coredump02.c | 253 +++++++++++++++++++++++++++++++++ 3 files changed, 255 insertions(+)
runtest/kernel_misc +1 -0
@@ -18,3 +18,4 @@ zram03 zram03 umip_basic_test umip_basic_test aslr01 aslr01 coredump01 coredump01 +coredump02 coredump02
testcases/kernel/coredump/.gitignore +1 -0
@@ -1,2 +1,3 @@ /coredump01 /coredump01_helper +/coredump02
testcases/kernel/coredump/coredump02.c new file +253 -0
253 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 2/2] coredump02: Verify ELF structure and notes
Hi Andrea,
Overall the test methodology looks good, with just a few minor code cleanup points below.
Quoted 30 lines
testcases/kernel/coredump/coredump02.c new file +30
-0+static void set_pattern (const char *fmt, ...) +{ +char pattern[PATTERN_MAX ]; +char readback[PATTERN_MAX ]; +va_list va; +int len; + +va_start (va, fmt); + len =vsnprintf (pattern,sizeof (pattern), fmt, va); +va_end (va); + +if (len >=PATTERN_MAX ) +tst_brk (TCONF ,"core_pattern does not fit into %i bytes" ,PATTERN_MAX -1 ); + +SAFE_FILE_PRINTF (PATH_KERN_CORE_PATTERN ,"%s" , pattern); +SAFE_FILE_LINES_SCANF (PATH_KERN_CORE_PATTERN ,"%127[^\n]" , readback); + +if (strcmp (pattern, readback)) +tst_brk (TBROK ,"core_pattern readback mismatch: wrote '%s', read '%s'" , + pattern, readback); + +tst_res (TINFO ,"core_pattern is '%s'" , pattern); +} + +static pid_t crash_child (void ) +{ +int status; +pid_t pid; + + pid =SAFE_FORK ();
testcases/kernel/coredump/coredump02.c line 97
Quoted 10 lines
testcases/kernel/coredump/coredump02.c new file +10
-0+if (!pid) +abort (); + +SAFE_WAITPID (pid, &status,0 ); + +if (!WIFSIGNALED (status) || !WCOREDUMP (status)) +tst_brk (TFAIL ,"Child did not dump core" ); + +return pid; +}
Splitting the core file parsing into a separate test is fine. For the duplicated code, there are two approaches - I'm okay with either.
1. create a seperate coredump_common.h
#cat coredump_common.h
...
#ifndef COREDUMP_COMMON_H
#define COREDUMP_COMMON_H
#include <elf.h>
#include <sys/wait.h>
#include "tst_test.h"
#include "lapi/prctl.h"
#define PATTERN_MAX 128
static char cwd[PATH_MAX];
static void set_pattern(const char *fmt, ...)
{
// ...
}
static pid_t crash_child(void)
{
// ...
}
static void coredump_setup(void)
{
struct rlimit rl = {RLIM_INFINITY, RLIM_INFINITY};
SAFE_SETRLIMIT(RLIMIT_CORE, &rl);
SAFE_PRCTL(PR_SET_DUMPABLE, 1, 0, 0, 0);
SAFE_GETCWD(cwd, sizeof(cwd));
}
#endif /* COREDUMP_COMMON_H */2. Merge coredump02 method into coredump01 with use tcnt=3.
static void run(unsigned int n)
{
switch (n) {
case 0:
verify_file_pattern_specifiers();
break;
case 1:
verify_file_pattern_content();
break;
case 2:
verify_pipe_pattern();
break;
}
}
static struct tst_test test = {
.test = run,
.tcnt = 3,
// ...
};Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 2/2] coredump02: Verify ELF structure and notes
Hi Li,
Quoted 5 lines
Splitting the core file parsing into a separate test is fine. For the duplicated code, there are two approaches - I'm okay with either.
1. create a seperate
coredump_common.h
It makes sense, I would stick with this one, because I'm trying to keep tests as atomic as possible. They are way easier to maintain and to debug
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp