[LTP] [PATCH v5] coredump01: New core_pattern specifiers test
Andrea Cervesato
andrea.cervesato@suse.com
Fri Sep 4 08:25:44 CEST 2026
Hi Li,
> > + TST_EXP_PASS(access(dump, F_OK), "core.%%e.%%p.%%s expanded to core.coredump01.%d.%d",
> > + pid, SIGABRT);
>
> Generally this checks is really nice, but it'd be better to
> add more checks for the core dump file?
>
> e.g. file size > 0, ELF magic valid, and type == ET_CORE.
this is already done, but we can introduce ELF type check (read below).
>
> FYI:
>
> +static int verify_core_dump(const char *path, long long expected_size)
> +{
> + int fd;
> + struct stat st;
> + unsigned char magic[SELFMAG];
> + Elf64_Ehdr ehdr;
Ehdr is not portable on 32 bit systems breaking our testing, so I
wouldn't use it in this case. We need Elf32_Half which is in both
32bit and 64bit.
> +
> + if (access(path, F_OK) != 0) {
> + tst_res(TFAIL, "Core dump file %s does not exist", path);
> + return -1;
> + }
> + tst_res(TPASS, "Core dump file %s exists", path);
> +
> + SAFE_STAT(path, &st);
> + TST_EXP_EXPR(st.st_size > 0, "core file size = %ld bytes", st.st_size);
> +
> + if (expected_size > 0 && st.st_size != expected_size) {
> + tst_res(TFAIL, "Core dump size mismatch: expected %lld bytes, got %ld",
> + expected_size, st.st_size);
> + return -1;
> + }
> +
> + fd = SAFE_OPEN(path, O_RDONLY, 0);
> + SAFE_READ(0, fd, magic, SELFMAG);
> + SAFE_CLOSE(fd);
> +
> + TST_EXP_EXPR(!memcmp(magic, ELFMAG, 4),
> + "core file has valid ELF magic");
> +
> + fd = SAFE_OPEN(path, O_RDONLY, 0);
> + SAFE_READ(0, fd, &ehdr, sizeof(ehdr));
> + SAFE_READ(0, fd, &ehdr, sizeof(ehdr));
double read? I guess it's an error
I will send a new version with some of the proposed checks
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com
More information about the ltp
mailing list