• 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 <errno.h>
17 #include <signal.h>
18 
19 #include "test.h"
20 
21 static int handler_count = 0;
22 
handler(int sig)23 void handler(int sig)
24 {
25     handler_count++;
26 }
27 
28 /**
29  * @tc.name      : sigpause_0100
30  * @tc.desc      : atomically release blocked signals
31  * @tc.level     : Level 0
32  */
sigpause_0100(void)33 void sigpause_0100(void)
34 {
35     handler_count = 0;
36 
37     int sig = SIGALRM;
38     struct sigaction act = {.sa_flags = 0, .sa_handler = handler};
39     struct sigaction old_act = {0};
40     int result = sigaction(sig, &act, &old_act);
41     if (result != 0) {
42         t_error("%s failed: result = %d\n", __func__, result);
43         return;
44     }
45 
46     result = sighold(sig);
47     if (result != 0) {
48         t_error("%s failed: result = %d\n", __func__, result);
49         return;
50     }
51 
52     sigset_t set = {0};
53     result = sigprocmask(SIG_SETMASK, NULL, &set);
54     if (result != 0) {
55         t_error("%s failed: result = %d\n", __func__, result);
56         return;
57     }
58 
59     result = sigismember(&set, sig);
60     if (result == 0) {
61         t_error("%s failed: result = %d\n", __func__, result);
62         return;
63     }
64 
65     result = raise(sig);
66     if (result != 0 || handler_count != 0) {
67         t_error("%s failed: result = %d\n", __func__, result);
68         t_error("%s failed: handler_count = %d\n", __func__, handler_count);
69     }
70 
71     errno = 0;
72     result = sigpause(sig);
73     if (result != -1 || errno != EINTR) {
74         t_error("%s failed: result = %d\n", __func__, result);
75         t_error("%s failed: errno = %d\n", __func__, errno);
76     }
77 
78     if (handler_count != 1) {
79         t_error("%s failed: handler_count = %d\n", __func__, handler_count);
80     }
81 }
82 
main(int argc,char * argv[])83 int main(int argc, char *argv[])
84 {
85     sigpause_0100();
86 
87     return t_status;
88 }
89