• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <sys/stat.h>
18 #include "functionalext.h"
19 
20 /*
21  * @tc.name      : munmap_0100
22  * @tc.desc      : Verify that the parameters are valid to unmap the memory
23  * @tc.level     : Level 0
24  */
munmap_0100(void)25 void munmap_0100(void)
26 {
27     const char *ptr = "/data/test.txt";
28     const char str[] = "this is a sample!";
29     FILE *fptr = fopen(ptr, "w+");
30     EXPECT_PTRNE("munmap_0100", fptr, NULL);
31 
32     struct stat statbuff;
33     fwrite(str, sizeof(char), strlen(str), fptr);
34     fseek(fptr, 0L, SEEK_SET);
35     char *p_map = mmap(NULL, sizeof(char) * 10, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(fptr), 0);
36     fclose(fptr);
37     int data = munmap(p_map, sizeof(char) * 10);
38     EXPECT_EQ("munmap_0100", data, 0);
39     remove(ptr);
40 }
41 
main(int argc,char * argv[])42 int main(int argc, char *argv[])
43 {
44     munmap_0100();
45     return t_status;
46 }