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 <stdio.h>
17 #include <stdlib.h>
18 #include <sys/wait.h>
19 #include "test.h"
20
21 /**
22 * @tc.name : waitid_0100
23 * @tc.desc : Test waitid function for process control
24 * @tc.level : Level 0
25 */
waitid_0100(void)26 void waitid_0100(void)
27 {
28 pid_t pid = fork();
29 if (pid == -1) {
30 t_error("%s waitid fork error\n", __func__);
31 }
32 if (pid == 0)
33 _exit(66);
34 siginfo_t si = {};
35 int result = waitid(P_PID, pid, &si, WEXITED);
36 if (result != 0) {
37 t_error("%s waitid error get result is %d are not want 0\n", __func__, result);
38 }
39 if (pid != si.si_pid) {
40 t_error("%s waitid error pid not = si.si_pid\n", __func__);
41 }
42 if (si.si_status != 66) {
43 t_error("%s waitid error si.si_status not = 66\n", __func__);
44 }
45 if (si.si_code != CLD_EXITED) {
46 t_error("%s waitid error si.si_code not = CLD_EXITED\n", __func__);
47 }
48 }
49
main(int argc,char * argv[])50 int main(int argc, char *argv[])
51 {
52 waitid_0100();
53 return t_status;
54 }