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 <ulimit.h>
17 #include <stdlib.h>
18 #include "functionalext.h"
19 
20 #define MAX_FILE_SIZE 4096
21 
22 /**
23  * @tc.name      : ulimit_0100
24  * @tc.desc      : Test ulimit() with UL_SETFSIZE
25  * @tc.level     : Level 0
26  */
ulimit_0100(void)27 static void ulimit_0100(void)
28 {
29     int cmd = UL_SETFSIZE;
30     long result = ulimit(cmd, MAX_FILE_SIZE);
31     if (result < 0) {
32         EXPECT_PTRNE("ulimit_0100", result, 0);
33         return;
34     }
35 
36     EXPECT_LONGEQ("ulimit_0100", MAX_FILE_SIZE, result);
37 }
38 
39 /**
40  * @tc.name      : ulimit_0200
41  * @tc.desc      : Test ulimit() with UL_GETFSIZE
42  * @tc.level     : Level 1
43  */
ulimit_0200(void)44 static void ulimit_0200(void)
45 {
46     int cmd = UL_GETFSIZE;
47     long result = ulimit(cmd);
48     if (result < 0) {
49         EXPECT_PTRNE("ulimit_0200", result, 0);
50         return;
51     }
52 
53     EXPECT_LONGEQ("ulimit_0200", MAX_FILE_SIZE, result);
54 }
55 
56 /**
57  * @tc.name      : ulimit_0300
58  * @tc.desc      : Test ulimit() with UL_SETFSIZE and invalid args
59  * @tc.level     : Level 2
60  */
ulimit_0300(void)61 static void ulimit_0300(void)
62 {
63     int cmd = UL_SETFSIZE;
64     long result = ulimit(cmd, -1);
65     if (result >= 0) {
66         EXPECT_PTRNE("ulimit_0300", result, 0);
67         return;
68     }
69 
70     EXPECT_LONGEQ("ulimit_0300", -1, result);
71 }
72 
main(void)73 int main(void)
74 {
75     ulimit_0100();
76     ulimit_0200();
77     ulimit_0300();
78     return t_status;
79 }