• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *   http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 // Solve the build error of this test code when importing the header file <sys/epoll.h>
17 #ifndef _EPOLL_PWAIT_TEST
18 #define _EPOLL_PWAIT_TEST
19 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
20 #undef _GNU_SOURCE
21 #undef _BSD_SOURCE
22 #endif
23 #endif
24 
25 #include <errno.h>
26 #include <signal.h>
27 #include <sys/epoll.h>
28 #include "test.h"
29 
30 /**
31  * @tc.name      : epoll_pwait_0100
32  * @tc.desc      : epoll_pwait without a sigset
33  * @tc.level     : Level 0
34  */
epoll_pwait_0100(void)35 void epoll_pwait_0100(void)
36 {
37     int epoll_fd = epoll_create(1);
38     if (epoll_fd == -1) {
39         t_error("%s epoll_create failed\n", __func__);
40     }
41 
42     struct epoll_event events[1];
43     int result = epoll_pwait(epoll_fd, events, 1, 1, NULL);
44     if (result != 0) {
45         t_error("%s epoll_pwait failed\n", __func__);
46     }
47 }
48 
49 /**
50  * @tc.name      : epoll_pwait_0200
51  * @tc.desc      : epoll_pwait with a sigset
52  * @tc.level     : Level 0
53  */
epoll_pwait_0200(void)54 void epoll_pwait_0200(void)
55 {
56     int epoll_fd = epoll_create(1);
57     if (epoll_fd == -1) {
58         t_error("%s epoll_create failed\n", __func__);
59     }
60 
61     struct epoll_event events[1];
62     sigset_t ss;
63     sigemptyset(&ss);
64     sigaddset(&ss, SIGPIPE);
65 
66     int result = epoll_pwait(epoll_fd, events, 1, 1, &ss);
67     if (result != 0) {
68         t_error("%s epoll_pwait failed\n", __func__);
69     }
70 }
71 
main(int argc,char * argv[])72 int main(int argc, char *argv[])
73 {
74     epoll_pwait_0100();
75     epoll_pwait_0200();
76     return t_status;
77 }
78 
79 #ifdef _EPOLL_PWAIT_TEST
80 #undef _EPOLL_PWAIT_TEST
81 #endif