tools/testing/selftests/coredump/stackdump_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/coredump/stackdump_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/coredump/stackdump_test.c- Extension
.c- Size
- 3651 bytes
- Lines
- 170
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
assert.hfcntl.hinttypes.hlibgen.hlimits.hlinux/coredump.hlinux/fs.hlinux/limits.hpthread.hstring.hsys/mount.hpoll.hsys/epoll.hsys/resource.hsys/stat.hsys/socket.hsys/un.hunistd.hkselftest_harness.h../filesystems/wrappers.h../pidfd/pidfd.hcoredump_test.h
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
if (ret < 0) {
reason = "Unable to close detached tmpfs";
goto fail;
}
self->fd_tmpfs_detached = -1;
}
return;
fail:
/* This should never happen */
fprintf(stderr, "Failed to cleanup stackdump test: %s\n", reason);
}
TEST_F_TIMEOUT(coredump, stackdump, 120)
{
unsigned long long stack;
char *test_dir, *line;
size_t line_length;
char buf[PAGE_SIZE];
int ret, i, status;
FILE *file;
pid_t pid;
/*
* Step 1: Setup core_pattern so that the stackdump script is executed when the child
* process crashes
*/
ret = readlink("/proc/self/exe", buf, sizeof(buf));
ASSERT_NE(-1, ret);
ASSERT_LT(ret, sizeof(buf));
buf[ret] = '\0';
test_dir = dirname(buf);
file = fopen("/proc/sys/kernel/core_pattern", "w");
ASSERT_NE(NULL, file);
ret = fprintf(file, "|%1$s/%2$s %%P %1$s/%3$s", test_dir, STACKDUMP_SCRIPT, STACKDUMP_FILE);
ASSERT_LT(0, ret);
ret = fclose(file);
ASSERT_EQ(0, ret);
/* Step 2: Create a process who spawns some threads then crashes */
pid = fork();
ASSERT_TRUE(pid >= 0);
if (pid == 0)
crashing_child();
/*
* 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)
break;
sleep(1);
}
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);
fclose(file);
}
TEST_HARNESS_MAIN
Annotation
- Immediate include surface: `assert.h`, `fcntl.h`, `inttypes.h`, `libgen.h`, `limits.h`, `linux/coredump.h`, `linux/fs.h`, `linux/limits.h`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.