Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/testing/vma/tests/mmap.c
121838 views
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
3
static bool test_mmap_region_basic(void)
4
{
5
struct mm_struct mm = {};
6
unsigned long addr;
7
struct vm_area_struct *vma;
8
VMA_ITERATOR(vmi, &mm, 0);
9
10
current->mm = &mm;
11
12
/* Map at 0x300000, length 0x3000. */
13
addr = __mmap_region(NULL, 0x300000, 0x3000,
14
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE,
15
0x300, NULL);
16
ASSERT_EQ(addr, 0x300000);
17
18
/* Map at 0x250000, length 0x3000. */
19
addr = __mmap_region(NULL, 0x250000, 0x3000,
20
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE,
21
0x250, NULL);
22
ASSERT_EQ(addr, 0x250000);
23
24
/* Map at 0x303000, merging to 0x300000 of length 0x6000. */
25
addr = __mmap_region(NULL, 0x303000, 0x3000,
26
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE,
27
0x303, NULL);
28
ASSERT_EQ(addr, 0x303000);
29
30
/* Map at 0x24d000, merging to 0x250000 of length 0x6000. */
31
addr = __mmap_region(NULL, 0x24d000, 0x3000,
32
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE,
33
0x24d, NULL);
34
ASSERT_EQ(addr, 0x24d000);
35
36
ASSERT_EQ(mm.map_count, 2);
37
38
for_each_vma(vmi, vma) {
39
if (vma->vm_start == 0x300000) {
40
ASSERT_EQ(vma->vm_end, 0x306000);
41
ASSERT_EQ(vma->vm_pgoff, 0x300);
42
} else if (vma->vm_start == 0x24d000) {
43
ASSERT_EQ(vma->vm_end, 0x253000);
44
ASSERT_EQ(vma->vm_pgoff, 0x24d);
45
} else {
46
ASSERT_FALSE(true);
47
}
48
}
49
50
cleanup_mm(&mm, &vmi);
51
return true;
52
}
53
54
static void run_mmap_tests(int *num_tests, int *num_fail)
55
{
56
TEST(mmap_region_basic);
57
}
58
59