This source file includes following definitions.
- test_body
- test_main
- main
1
2 #include <stdio.h>
3 #include <sys/mman.h>
4 #include <unistd.h>
5
6 #include "utils.h"
7
8
9 #define SIZE (16 * 1024 * 1024)
10
11 static int test_body(void)
12 {
13 void *addr;
14 char *p;
15
16 addr = (void *)0xa0000000;
17
18 p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
19 MAP_HUGETLB | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
20 if (p != MAP_FAILED) {
21
22
23
24
25
26
27
28 if (munmap(addr, SIZE)) {
29 perror("munmap");
30 return 1;
31 }
32 }
33
34 p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
35 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
36 if (p == MAP_FAILED) {
37 printf("Mapping failed @ %p\n", addr);
38 perror("mmap");
39 return 1;
40 }
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 *p = 0xf;
56
57 munmap(addr, SIZE);
58
59 return 0;
60 }
61
62 static int test_main(void)
63 {
64 int i;
65
66
67 for (i = 0; i < 10000; i++)
68 if (test_body())
69 return 1;
70
71 return 0;
72 }
73
74 int main(void)
75 {
76 return test_harness(test_main, "hugetlb_vs_thp");
77 }