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 <unistd.h>
17 #include <signal.h>
18 #include <sys/wait.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include "functionalext.h"
22 
23 static int exit_flag = 0;
24 
Killfunc(int signal)25 void Killfunc(int signal)
26 {
27     switch (signal) {
28         case SIGUSR1:
29             exit_flag = 1;
30             break;
31         default:
32             break;
33     }
34     return;
35 }
36 
37 /**
38  * @tc.name      : kill_0100
39  * @tc.desc      : Determine whether the child process successfully receives the signal to
40  *                 the main process and respond accordingly
41  * @tc.level     : Level 1
42  */
kill_0100(void)43 void kill_0100(void)
44 {
45     int status;
46     pid_t pid = fork();
47     if (pid == 0) {
48         sleep(1);
49         kill(getppid(), SIGUSR1);
50         exit(EXIT_SUCCESS);
51     } else if (pid > 0) {
52         signal(SIGUSR1, Killfunc);
53 
54         while (!exit_flag) {
55             sleep(1);
56         }
57         wait(NULL);
58         EXPECT_EQ("kill_0100", exit_flag, 1);
59     } else {
60         printf("Fork wrong\n");
61         exit(EXIT_FAILURE);
62     }
63 }
64 
65 /**
66  * @tc.name      : kill_0200
67  * @tc.desc      : Outlier judgment
68  * @tc.level     : Level 2
69  */
kill_0200(void)70 void kill_0200(void)
71 {
72     int rev = kill(0, 1000);
73     EXPECT_EQ("kill_0200", rev, ERREXPECT);
74 }
75 
main(void)76 int main(void)
77 {
78     kill_0100();
79     kill_0200();
80 
81     return t_status;
82 }