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 <sys/resource.h>
17 #include <stdlib.h>
18 #include "functionalext.h"
19
20 /**
21 * @tc.name : getrlimit_0100
22 * @tc.desc : Verify getrlimit process success
23 * @tc.level : Level 0
24 */
getrlimit_0100(void)25 void getrlimit_0100(void)
26 {
27 static const long lim = 42;
28 static const int r = RLIMIT_NOFILE;
29 struct rlimit rl;
30
31 rl.rlim_max = lim;
32 rl.rlim_cur = lim;
33 int ret = setrlimit(r, &rl);
34 EXPECT_EQ("getrlimit_0100", ret, 0);
35 struct rlimit retrl;
36 ret = getrlimit(r, &retrl);
37 EXPECT_EQ("getrlimit_0100", ret, 0);
38 EXPECT_LONGLONGEQ("getrlimit_0100", retrl.rlim_max, lim);
39 EXPECT_LONGLONGEQ("getrlimit_0100", retrl.rlim_cur, lim);
40 }
41
42 /**
43 * @tc.name : getrlimit_0200
44 * @tc.desc : Verify getrlimit process success fail bacaus param is error
45 * @tc.level : Level 2
46 */
getrlimit_0200(void)47 void getrlimit_0200(void)
48 {
49 struct rlimit limit;
50 int ret = getrlimit(-1, &limit);
51 EXPECT_EQ("getrlimit_0200", ret, -1);
52 }
53
main(void)54 int main(void)
55 {
56 getrlimit_0100();
57 getrlimit_0200();
58 return t_status;
59 }
60