1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2001
4 * Copyright (c) 2008 Vijay Kumar B. <[email protected]>
5 * Copyright (c) Linux Test Project, 2008-2022
6 * Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]>
7 */
8
9 /*\
10 * [Description]
11 *
12 * Test whether eventfd() counter update in child is reflected in the parent.
13 */
14
15 #include <stdlib.h>
16 #include <sys/eventfd.h>
17 #include "tst_test.h"
18
run(void)19 static void run(void)
20 {
21 int fd;
22 uint64_t val;
23 uint64_t to_parent = 0xdeadbeef;
24
25 fd = TST_EXP_FD(eventfd(0, EFD_NONBLOCK));
26
27 if (!SAFE_FORK()) {
28 SAFE_WRITE(0, fd, &to_parent, sizeof(to_parent));
29 exit(0);
30 }
31
32 tst_reap_children();
33
34 SAFE_READ(0, fd, &val, sizeof(val));
35 TST_EXP_EQ_LI(val, to_parent);
36
37 SAFE_CLOSE(fd);
38 }
39
40 static struct tst_test test = {
41 .test_all = run,
42 .forks_child = 1,
43 .needs_kconfigs = (const char *[]) {
44 "CONFIG_EVENTFD",
45 NULL
46 },
47 };
48