• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  * conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  * of conditions and the following disclaimer in the documentation and/or other materials
13  * provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  * to endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 #include "it_test_signal.h"
32 #include "signal.h"
33 
34 // print the sigset bit by biy
PrintSigset(sigset_t * set)35 static void PrintSigset(sigset_t *set)
36 {
37     for (int i = 0; i < 32; ++i) { // 32, Number of cycles
38         if (sigismember(set, i)) {
39             putchar('1');
40         } else {
41             putchar('0');
42         }
43     }
44     puts("");
45 }
46 
TestSigset()47 static int TestSigset()
48 {
49     // record mask words
50     sigset_t sigset;
51 
52     void *ret;
53     int retValue, status;
54 
55     int fpid = fork();
56     if (fpid == 0) {
57         // clean the signal set
58         printf("EmptySet\n");
59         retValue = sigemptyset(&sigset);
60         if (retValue != 0) {
61             exit(retValue);
62         }
63         printf("Current set is: \n");
64         PrintSigset(&sigset);
65         printf("EmptySet End\n\n");
66 
67         printf("IsEmptySet\n");
68         retValue = sigisemptyset(&sigset);
69         if (retValue != 1) {
70             exit(retValue);
71         }
72         if (retValue == 1) {
73             printf("The set is empty\n");
74         } else {
75             printf("The set is not empty\n");
76         }
77         printf("IsEmptySet End\n\n");
78 
79         printf("AddSet\n");
80         retValue = sigaddset(&sigset, SIGINT);
81         if (retValue != 0) {
82             exit(retValue);
83         }
84         printf("Add SIGINT\n");
85         printf("Current set is: \n");
86         PrintSigset(&sigset);
87         printf("AddSet End\n\n");
88 
89         printf("IsMember\n");
90         retValue = sigismember(&sigset, SIGINT);
91         if (retValue != 1) {
92             exit(retValue);
93         }
94         if (retValue == 1) {
95             printf("The SIGINT is a member of set\n");
96         } else {
97             printf("The SIGINT is not a member of set\n");
98         }
99         printf("IsMember End\n\n");
100 
101         printf("DelSet\n");
102         retValue = sigdelset(&sigset, SIGINT);
103         if (retValue != 0) {
104             exit(retValue);
105         }
106         printf("Delete signal SIGINT\n");
107         printf("Current set is: \n");
108         PrintSigset(&sigset);
109         printf("DelSet End\n\n");
110 
111         printf("FillSet\n");
112         retValue = sigfillset(&sigset);
113         if (retValue != 0) {
114             exit(retValue);
115         }
116         printf("Current set is: \n");
117         PrintSigset(&sigset);
118         printf("FillSet End\n\n");
119 
120         sigset_t sigsetTmp;
121         sigemptyset(&sigsetTmp);
122         sigset_t sigsetTarget;
123         sigfillset(&sigset);
124         printf("AndSet\n");
125         retValue = sigandset(&sigsetTarget, &sigset, &sigsetTmp);
126         if (retValue != 0) {
127             exit(retValue);
128         }
129         printf("And fullset with emptyset\n");
130         printf("Current set is: \n");
131         PrintSigset(&sigset);
132         if (sigisemptyset(&sigsetTarget)) {
133             printf("AndSet Succeed\n");
134         } else {
135             printf("AndSet Fail\n");
136         }
137         printf("AndSet End\n\n");
138 
139         sigemptyset(&sigsetTarget);
140         printf("OrSet\n");
141         retValue = sigorset(&sigsetTarget, &sigset, &sigsetTmp);
142         if (retValue != 0) {
143             exit(retValue);
144         }
145         printf("Or fullset with emptyset\n");
146         printf("Current set is: \n");
147         PrintSigset(&sigset);
148         if (!sigisemptyset(&sigsetTarget)) {
149             printf("OrSet Succeed\n");
150         } else {
151             printf("OrSet Fail\n");
152         }
153         printf("OrSet End\n\n");
154 
155         exit(0);
156     }
157 
158     retValue = waitpid(fpid, &status, 0);
159     ICUNIT_ASSERT_EQUAL(retValue, fpid, retValue);
160     ICUNIT_ASSERT_EQUAL(WEXITSTATUS(status), 0, WEXITSTATUS(status));
161 
162     return 0;
163 }
164 
ItPosixSignal028(void)165 void ItPosixSignal028(void)
166 {
167     TEST_ADD_CASE(__FUNCTION__, TestSigset, TEST_POSIX, TEST_SIGNAL, TEST_LEVEL0, TEST_FUNCTION);
168 }