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 <sys/resource.h>
18 #include "functionalext.h"
19
20 /**
21 * @tc.name : prlimit_0100
22 * @tc.desc : Set the heap size of the process, and re-get the heap size value of the process
23 * @tc.level : Level 0
24 */
prlimit_0100(void)25 void prlimit_0100(void)
26 {
27 static const unsigned long long lim = 4;
28 struct rlimit new_limit = {.rlim_cur = lim, .rlim_max = lim};
29
30 struct rlimit old_limit = {.rlim_cur = 0, .rlim_max = 0};
31
32 int ret = prlimit(getpid(), RLIMIT_STACK, &new_limit, NULL);
33 EXPECT_EQ("prlimit_0100", ret, CMPFLAG);
34 ret = prlimit(getpid(), RLIMIT_STACK, NULL, &old_limit);
35 EXPECT_EQ("prlimit_0100", ret, CMPFLAG);
36 EXPECT_LONGLONGEQ("prlimit_0100", old_limit.rlim_cur, lim);
37 EXPECT_LONGLONGEQ("prlimit_0100", old_limit.rlim_max, lim);
38 }
39
40 /**
41 * @tc.name : prlimit_0200
42 * @tc.desc : An illegal parameter was passed in, setting the process limit parameter failed
43 * @tc.level : Level 2
44 */
prlimit_0200(void)45 void prlimit_0200(void)
46 {
47 static const unsigned long long lim = 4;
48 struct rlimit new_limit = {.rlim_cur = lim, .rlim_max = lim};
49
50 int ret = prlimit(getpid(), -1, &new_limit, NULL);
51 EXPECT_EQ("prlimit_0200", ret, ERREXPECT);
52
53 new_limit.rlim_cur = lim + 1;
54 ret = prlimit(getpid(), RLIMIT_STACK, &new_limit, NULL);
55 EXPECT_EQ("prlimit_0200", ret, ERREXPECT);
56 }
57
main(void)58 int main(void)
59 {
60 prlimit_0100();
61 prlimit_0200();
62
63 return t_status;
64 }