• 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 #include <sys/stat.h>
17 #include <poll.h>
18 #include <time.h>
19 #include <fcntl.h>
20 #include "functionalext.h"
21 
22 /**
23  * @tc.name      : ppoll_0100
24  * @tc.desc      : Monitor the readable attribute time of the specified file
25  * @tc.level     : Level 0
26  */
ppoll_0100(void)27 void ppoll_0100(void)
28 {
29     int fd = open("ppoll_function_file", O_RDWR | O_CREAT, S_IRWXU);
30     if (fd == -1) {
31         t_error("create file failed\n");
32         return;
33     }
34     struct pollfd pollfds[] = {{.fd = fd, .events = POLLIN, .revents = 0}};
35     struct timespec timeout;
36     timeout.tv_sec = 5;
37     timeout.tv_nsec = 0;
38 
39     int ret = ppoll(pollfds, 1, &timeout, NULL);
40     EXPECT_GT("ppoll_0100", ret, CMPFLAG);
41     EXPECT_EQ("ppoll_0100", pollfds[0].revents, POLLIN);
42     close(fd);
43     ret = access("ppoll_function_file", F_OK);
44     if (ret != -1) {
45         ret = remove("ppoll_function_file");
46         EXPECT_EQ("ppoll_0100", ret, CMPFLAG);
47     }
48 }
49 
50 /**
51  * @tc.name      : ppoll_0200
52  * @tc.desc      : Listen to non-specified file time (timeout returns)
53  * @tc.level     : Level 2
54  */
ppoll_0200(void)55 void ppoll_0200(void)
56 {
57     struct pollfd pollfds[] = {{.fd = -1, .events = POLLIN, .revents = 0}};
58     struct timespec timeout;
59     timeout.tv_sec = 3;
60     timeout.tv_nsec = 0;
61 
62     int ret = ppoll(pollfds, 1, &timeout, NULL);
63     EXPECT_EQ("ppoll_0200", ret, CMPFLAG);
64 }
65 
66 /**
67  * @tc.name      : ppoll_0300
68  * @tc.desc      : Listen for readable file event (illegal parameter)
69  * @tc.level     : Level 2
70  */
ppoll_0300(void)71 void ppoll_0300(void)
72 {
73     struct timespec timeout;
74     timeout.tv_sec = 1;
75     timeout.tv_nsec = 0;
76 
77     int ret = ppoll(NULL, 1, &timeout, NULL);
78     EXPECT_EQ("ppoll_0300", ret, ERREXPECT);
79 }
80 
main(void)81 int main(void)
82 {
83     ppoll_0100();
84     ppoll_0200();
85     ppoll_0300();
86     return t_status;
87 }