1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
4 * Author: Xie Ziyao <xieziyao@huawei.com>
5 */
6
7 /*\
8 * [Description]
9 *
10 * Basic test for epoll_pwait and epoll_pwait2. Checks if data avaiable in a
11 * file descriptor are reported correctly in the syscall return value.
12 */
13
14 #include <sys/epoll.h>
15
16 #include "tst_test.h"
17 #include "epoll_pwait_var.h"
18
19 static int efd, sfd[2];
20 static struct epoll_event e;
21
run(void)22 static void run(void)
23 {
24 TEST(do_epoll_pwait(efd, &e, 1, -1, NULL));
25
26 if (TST_RET == 1) {
27 tst_res(TPASS, "do_epoll_pwait() succeeded");
28 return;
29 }
30 tst_res(TFAIL, "do_epoll_pwait() returned %li, expected 1", TST_RET);
31 }
32
setup(void)33 static void setup(void)
34 {
35 epoll_pwait_init();
36
37 SAFE_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, sfd);
38
39 efd = epoll_create(1);
40 if (efd == -1)
41 tst_brk(TBROK | TERRNO, "epoll_create()");
42
43 e.events = EPOLLIN;
44 if (epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e))
45 tst_brk(TBROK | TERRNO, "epoll_ctl(..., EPOLL_CTL_ADD, ...)");
46 SAFE_WRITE(SAFE_WRITE_ALL, sfd[1], "w", 1);
47 }
48
cleanup(void)49 static void cleanup(void)
50 {
51 if (efd > 0)
52 SAFE_CLOSE(efd);
53
54 if (sfd[0] > 0)
55 SAFE_CLOSE(sfd[0]);
56
57 if (sfd[1] > 0)
58 SAFE_CLOSE(sfd[1]);
59 }
60
61 static struct tst_test test = {
62 .test_all = run,
63 .setup = setup,
64 .cleanup = cleanup,
65 .test_variants = TEST_VARIANTS,
66 };
67