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
33
34 static int g_actionCnt1;
CatchAction1(int param)35 static void CatchAction1(int param)
36 {
37 g_actionCnt1++;
38 printf("---------%d---signum-%d-----\n", g_actionCnt1, param);
39 }
40
Testcase(VOID)41 static UINT32 Testcase(VOID)
42 {
43 int spid, ret;
44 struct sigaction act, oldact;
45 act.sa_handler = CatchAction1;
46 sigemptyset(&act.sa_mask);
47 act.sa_flags = 0;
48 spid = fork();
49 ICUNIT_ASSERT_NOT_EQUAL(spid, -1, spid);
50 if (spid == 0) {
51 ret = sigaction(SIGCHLD, &act, &oldact);
52 if (ret == -1) {
53 exit(-1);
54 }
55 spid = fork();
56 if (spid == 0) {
57 spid = getppid();
58 kill(spid, SIGCHLD);
59 usleep(1000 * 10 * 10); // 1000, 10, 10, Used to calculate the delay time.
60 exit(0);
61 }
62 if (spid == -1) {
63 exit(-1);
64 }
65 ret = 0;
66 while (ret == 0) {
67 ret = waitpid(spid, NULL, WNOHANG);
68 }
69
70 ret = sigaction(SIGCHLD, &oldact, NULL);
71 if (ret == -1) {
72 exit(6); // 6, the value of son process unexpected exit, convenient to debug
73 }
74 sleep(1);
75 printf("---son--cnt check----%d--------\n", g_actionCnt1);
76 exit(g_actionCnt1);
77 }
78 wait(&ret);
79 ICUNIT_ASSERT_EQUAL(WEXITSTATUS(ret), 2, WEXITSTATUS(ret)); // 2, assert that function Result is equal to this.
80 return LOS_OK;
81 }
82
ItIpcSigaction001(void)83 VOID ItIpcSigaction001(void)
84 {
85 TEST_ADD_CASE(__FUNCTION__, Testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION);
86 }
87