xref: /linux/tools/testing/selftests/coredump/coredump_test.h (revision 212c4053a1502e5117d8cbbbd1c15579ce1839bb)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef __COREDUMP_TEST_H
4 #define __COREDUMP_TEST_H
5 
6 #include <stdbool.h>
7 #include <sys/types.h>
8 #include <linux/coredump.h>
9 
10 #include "../kselftest_harness.h"
11 #include "../pidfd/pidfd.h"
12 
13 #ifndef PAGE_SIZE
14 #define PAGE_SIZE 4096
15 #endif
16 
17 #define NUM_THREAD_SPAWN 128
18 
19 /* Coredump fixture */
FIXTURE(coredump)20 FIXTURE(coredump)
21 {
22 	char original_core_pattern[256];
23 	pid_t pid_coredump_server;
24 	int fd_tmpfs_detached;
25 };
26 
27 /* Shared helper function declarations */
28 void *do_nothing(void *arg);
29 void crashing_child(void);
30 int create_detached_tmpfs(void);
31 int create_and_listen_unix_socket(const char *path);
32 bool set_core_pattern(const char *pattern);
33 int get_peer_pidfd(int fd);
34 bool get_pidfd_info(int fd_peer_pidfd, struct pidfd_info *info);
35 
36 /* Inline helper that uses harness types */
wait_and_check_coredump_server(pid_t pid_coredump_server,struct __test_metadata * const _metadata,FIXTURE_DATA (coredump)* self)37 static inline void wait_and_check_coredump_server(pid_t pid_coredump_server,
38 						   struct __test_metadata *const _metadata,
39 						   FIXTURE_DATA(coredump) *self)
40 {
41 	int status;
42 	waitpid(pid_coredump_server, &status, 0);
43 	self->pid_coredump_server = -ESRCH;
44 	ASSERT_TRUE(WIFEXITED(status));
45 	ASSERT_EQ(WEXITSTATUS(status), 0);
46 }
47 
48 /* Protocol helper function declarations */
49 ssize_t recv_marker(int fd);
50 bool read_marker(int fd, enum coredump_mark mark);
51 bool read_coredump_req(int fd, struct coredump_req *req);
52 bool send_coredump_ack(int fd, const struct coredump_req *req,
53 		       __u64 mask, size_t size_ack);
54 bool check_coredump_req(const struct coredump_req *req, size_t min_size,
55 			__u64 required_mask);
56 int open_coredump_tmpfile(int fd_tmpfs_detached);
57 void process_coredump_worker(int fd_coredump, int fd_peer_pidfd, int fd_core_file);
58 
59 #endif /* __COREDUMP_TEST_H */
60