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 <stdlib.h>
17 #include <sys/mman.h>
18 #include "functionalext.h"
19
20 /**
21 * @tc.name : mlockall_0100
22 * @tc.desc : Verify mlockall success. When flag is MCL_CURRENT.
23 * @tc.level : Level 0
24 */
mlockall_0100(void)25 void mlockall_0100(void)
26 {
27 size_t memsize = 4096;
28 char *memory = (char *)malloc(memsize);
29 if (memory == NULL) {
30 EXPECT_PTRNE("mlockall_0100", memory, NULL);
31 return;
32 }
33 memset(memory, '\0', memsize);
34 int result = mlockall(MCL_CURRENT);
35 EXPECT_EQ("mlockall_0100", result, 0);
36
37 munlockall();
38 free(memory);
39 memory = NULL;
40 }
41
42 /**
43 * @tc.name : mlockall_0200
44 * @tc.desc : Verify mlockall success. When flag is MCL_FUTURE.
45 * @tc.level : Level 0
46 */
mlockall_0200(void)47 void mlockall_0200(void)
48 {
49 int result = mlockall(MCL_FUTURE);
50 EXPECT_EQ("mlockall_0200", result, 0);
51 size_t memsize = 4096;
52 char *memory = (char *)malloc(memsize);
53 if (memory == NULL) {
54 EXPECT_PTRNE("mlockall_0200", memory, NULL);
55 return;
56 }
57 memset(memory, '\0', memsize);
58 munlockall();
59 free(memory);
60 memory = NULL;
61 }
62
63 /**
64 * @tc.name : mlockall_0300
65 * @tc.desc : Verify mlockall success. When flag is error.
66 * @tc.level : Level 0
67 */
mlockall_0300(void)68 void mlockall_0300(void)
69 {
70 size_t memsize = 4096;
71 char *memory = (char *)malloc(memsize);
72 if (memory == NULL) {
73 EXPECT_PTRNE("mlockall_0300", memory, NULL);
74 return;
75 }
76 memset(memory, '\0', memsize);
77 int result = mlockall(-1);
78 EXPECT_EQ("mlockall_0300", result, ERREXPECT);
79
80 free(memory);
81 memory = NULL;
82 }
83
main(void)84 int main(void)
85 {
86 mlockall_0100();
87 mlockall_0200();
88 mlockall_0300();
89 return t_status;
90 }