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 : munlockall_0100
22 * @tc.desc : Verify munlockall success. When lock all flag is MCL_CURRENT.
23 * @tc.level : Level 0
24 */
munlockall_0100(void)25 void munlockall_0100(void)
26 {
27 size_t memsize = 4096;
28 char *memory = (char *)malloc(memsize);
29 if (memory == NULL) {
30 EXPECT_PTRNE("munlockall_0100", memory, NULL);
31 return;
32 }
33 memset(memory, '\0', memsize);
34 int result = mlockall(MCL_CURRENT);
35 EXPECT_EQ("munlockall_0100", result, 0);
36
37 result = munlockall();
38 EXPECT_EQ("munlockall_0100", result, 0);
39 free(memory);
40 memory = NULL;
41 }
42
43 /**
44 * @tc.name : munlockall_0200
45 * @tc.desc : Verify munlockall success. When lock all flag is MCL_CURRENT.
46 * @tc.level : Level 0
47 */
munlockall_0200(void)48 void munlockall_0200(void)
49 {
50 int result = mlockall(MCL_FUTURE);
51 EXPECT_EQ("munlockall_0200", result, 0);
52 size_t memsize = 4096;
53 char *memory = (char *)malloc(memsize);
54 if (memory == NULL) {
55 EXPECT_PTRNE("munlockall_0200", memory, NULL);
56 return;
57 }
58 memset(memory, '\0', memsize);
59 result = munlockall();
60 EXPECT_EQ("munlockall_0200", result, 0);
61 free(memory);
62 memory = NULL;
63 }
64
main(void)65 int main(void)
66 {
67 munlockall_0100();
68 munlockall_0200();
69 return t_status;
70 }