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/mman.h>
17#include <stdlib.h>
18
19#include "functionalext.h"
20
21/**
22 * @tc.name      : mlock_0100
23 * @tc.desc      : Assert whether locking 4k memory is successful, release resources after use
24 * @tc.level     : Level 0
25 */
26void mlock_0100(void)
27{
28    size_t memsize = 4096;
29    char *memory = (char *)malloc(memsize);
30    if (memory == NULL) {
31        EXPECT_PTRNE("mlock_0100", memory, NULL);
32        return;
33    }
34    memset(memory, '\0', memsize);
35    int result = mlock(memory, memsize);
36    EXPECT_NE("mlock_0100", result, ERREXPECT);
37
38    munlock(memory, memsize);
39    free(memory);
40    memory = NULL;
41}
42
43int main(void)
44{
45    mlock_0100();
46
47    return t_status;
48}