tools/testing/selftests/coredump/coredump_test_helpers.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/coredump/coredump_test_helpers.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/coredump/coredump_test_helpers.c- Extension
.c- Size
- 9319 bytes
- Lines
- 384
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
assert.herrno.hfcntl.hlimits.hlinux/coredump.hlinux/fs.hpthread.hstdbool.hstdio.hstdlib.hstring.hsys/epoll.hsys/ioctl.hsys/socket.hsys/types.hsys/un.hsys/wait.hunistd.h../filesystems/wrappers.h../pidfd/pidfd.h
Detected Declarations
struct __test_metadatastruct _fixture_coredump_datastruct large_ack_for_size_testingfunction crashing_childfunction create_detached_tmpfsfunction create_and_listen_unix_socketfunction set_core_patternfunction get_peer_pidfdfunction get_pidfd_infofunction recv_markerfunction read_markerfunction read_coredump_reqfunction send_coredump_ackfunction check_coredump_reqfunction open_coredump_tmpfilefunction process_coredump_worker
Annotated Snippet
struct _fixture_coredump_data {
char original_core_pattern[256];
pid_t pid_coredump_server;
int fd_tmpfs_detached;
};
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
#define NUM_THREAD_SPAWN 128
void *do_nothing(void *arg)
{
(void)arg;
while (1)
pause();
return NULL;
}
void crashing_child(void)
{
pthread_t thread;
int i;
for (i = 0; i < NUM_THREAD_SPAWN; ++i)
pthread_create(&thread, NULL, do_nothing, NULL);
/* crash on purpose */
i = *(volatile int *)NULL;
}
int create_detached_tmpfs(void)
{
int fd_context, fd_tmpfs;
fd_context = sys_fsopen("tmpfs", 0);
if (fd_context < 0)
return -1;
if (sys_fsconfig(fd_context, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0)
return -1;
fd_tmpfs = sys_fsmount(fd_context, 0, 0);
close(fd_context);
return fd_tmpfs;
}
int create_and_listen_unix_socket(const char *path)
{
struct sockaddr_un addr = {
.sun_family = AF_UNIX,
};
assert(strlen(path) < sizeof(addr.sun_path) - 1);
strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
size_t addr_len =
offsetof(struct sockaddr_un, sun_path) + strlen(path) + 1;
int fd, ret;
fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (fd < 0)
goto out;
ret = bind(fd, (const struct sockaddr *)&addr, addr_len);
if (ret < 0)
goto out;
ret = listen(fd, 128);
if (ret < 0)
goto out;
return fd;
out:
if (fd >= 0)
close(fd);
return -1;
}
bool set_core_pattern(const char *pattern)
{
int fd;
ssize_t ret;
fd = open("/proc/sys/kernel/core_pattern", O_WRONLY | O_CLOEXEC);
if (fd < 0)
return false;
ret = write(fd, pattern, strlen(pattern));
Annotation
- Immediate include surface: `assert.h`, `errno.h`, `fcntl.h`, `limits.h`, `linux/coredump.h`, `linux/fs.h`, `pthread.h`, `stdbool.h`.
- Detected declarations: `struct __test_metadata`, `struct _fixture_coredump_data`, `struct large_ack_for_size_testing`, `function crashing_child`, `function create_detached_tmpfs`, `function create_and_listen_unix_socket`, `function set_core_pattern`, `function get_peer_pidfd`, `function get_pidfd_info`, `function recv_marker`.
- 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.