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 <pthread.h>
17 #include <signal.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include "functionalext.h"
21
22 static int32_t errorParam = 3;
23
24 /**
25 * @tc.name : pthread_sigmask_0100
26 * @tc.desc : Verify pthread_sigmask process success when define shield signal is SIGUSR1
27 * @tc.level : Level 1
28 */
pthread_sigmask_0100(void)29 void pthread_sigmask_0100(void)
30 {
31 sigset_t set;
32 sigaddset(&set, SIGUSR1);
33 int32_t ret = pthread_sigmask(SIG_BLOCK, &set, NULL);
34 EXPECT_EQ("pthread_sigmask_0100", ret, 0);
35 sigset_t setOne, setEmpty;
36 sigaddset(&setOne, SIGUSR2);
37 sigemptyset(&setEmpty);
38 ret = pthread_sigmask(SIG_BLOCK, &setOne, &setEmpty);
39 EXPECT_EQ("pthread_sigmask_0100", ret, 0);
40 sigismember(&set, SIGUSR1);
41 EXPECT_EQ("pthread_sigmask_0100", sigismember(&set, SIGUSR1), 1);
42 }
43
44 /**
45 * @tc.name : pthread_sigmask_0200
46 * @tc.desc : Verify pthread_sigmask process success when undefine shield signal
47 * @tc.level : Level 1
48 */
pthread_sigmask_0200(void)49 void pthread_sigmask_0200(void)
50 {
51 sigset_t set;
52 sigaddset(&set, SIGUSR1);
53 sigaddset(&set, SIGQUIT);
54 int32_t ret = pthread_sigmask(SIG_BLOCK, &set, NULL);
55 EXPECT_EQ("pthread_sigmask_0200", ret, 0);
56 sigset_t setEmpty;
57 sigemptyset(&setEmpty);
58 ret = pthread_sigmask(SIG_BLOCK, &setEmpty, NULL);
59 EXPECT_EQ("pthread_sigmask_0200", ret, 0);
60 ret = sigismember(&set, SIGUSR1);
61 EXPECT_EQ("pthread_sigmask_0200", ret, 1);
62 ret = sigismember(&set, SIGQUIT);
63 EXPECT_EQ("pthread_sigmask_0200", ret, 1);
64 }
65
66 /**
67 * @tc.name : pthread_sigmask_0300
68 * @tc.desc : Verify pthread_sigmask process fail becaus first param is error
69 * @tc.level : Level 2
70 */
pthread_sigmask_0300(void)71 void pthread_sigmask_0300(void)
72 {
73 sigset_t set;
74 sigaddset(&set, SIGUSR1);
75 sigaddset(&set, SIGQUIT);
76 int32_t ret = pthread_sigmask(SIG_BLOCK + errorParam, &set, NULL);
77 EXPECT_EQ("pthread_sigmask_0300", ret, EINVAL);
78 }
79
80 /**
81 * @tc.name : pthread_sigmask_0400
82 * @tc.desc : Verify pthread_sigmask process success when second and third param is null
83 * @tc.level : Level 2
84 */
pthread_sigmask_0400(void)85 void pthread_sigmask_0400(void)
86 {
87 sigset_t set, setEmpty;
88 sigaddset(&set, SIGUSR1);
89 sigemptyset(&setEmpty);
90 int32_t ret = pthread_sigmask(SIG_BLOCK, &set, NULL);
91 EXPECT_EQ("pthread_setschedparam_0400", ret, 0);
92 ret = pthread_sigmask(SIG_BLOCK, NULL, &setEmpty);
93 EXPECT_EQ("pthread_setschedparam_0400", ret, 0);
94 ret = sigismember(&set, SIGUSR1);
95 EXPECT_EQ("pthread_setschedparam_0400", ret, 1);
96 }
97
main(void)98 int main(void)
99 {
100 pthread_sigmask_0100();
101 pthread_sigmask_0200();
102 pthread_sigmask_0300();
103 pthread_sigmask_0400();
104 return t_status;
105 }