• 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_process.h"
32 
33 static const int TEST_COUNT = 10;
34 
ThreadFunc2(void * arg)35 static void *ThreadFunc2(void *arg)
36 {
37     exit(254); // 254, exit args
38 }
39 
ProcessTest001(void)40 static int ProcessTest001(void)
41 {
42     int ret;
43     int status;
44     int pid;
45     int data;
46     int pri;
47     pthread_t newPthread, newPthread1;
48     int count = 4;
49     int currProcessPri = getpriority(PRIO_PROCESS, getpid());
50     ICUNIT_ASSERT_WITHIN_EQUAL(currProcessPri, 0, 31, currProcessPri); // 31, assert that function Result is equal to this.
51 
52     ret = setpriority(PRIO_PROCESS, getpid(), currProcessPri - 2); // 2, Used to calculate priorities.
53     ICUNIT_ASSERT_EQUAL(ret, 0, ret);
54 
55     data = ret;
56     ret = pthread_create(&newPthread, NULL, ThreadFunc2, &data);
57     ICUNIT_ASSERT_EQUAL(ret, 0, ret);
58 
59     exit(255); // 255, exit args
60     return 0;
61 }
62 
Testcase(void)63 static int Testcase(void)
64 {
65     int ret;
66     int status;
67     int pid;
68     int count = TEST_COUNT;
69     int temp = GetCpuCount();
70     if (temp <= 1) {
71         return 0;
72     }
73 
74     while (count > 0) {
75         ret = fork();
76         if (ret == 0) {
77             ret = ProcessTest001();
78             exit(10); // 10, exit args
79         } else if (ret > 0) {
80             pid = ret;
81             ret = wait(&status);
82             status = WEXITSTATUS(status);
83             ICUNIT_ASSERT_EQUAL(ret, pid, ret);
84             ICUNIT_ASSERT_TWO_EQUAL(status, 255, 254, status); // 255, 254, assert that function Result is equal to this.
85         }
86 
87         ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, 100000, ret); // 100000, assert that function Result is equal to this.
88         count--;
89     }
90     return 0;
91 }
92 
ItTestProcess007(void)93 void ItTestProcess007(void)
94 {
95     TEST_ADD_CASE("IT_POSIX_PROCESS_007", Testcase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
96 }
97