mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:24:47 +01:00
So far the userland VMA tests have been established as a rough expression of what's been possible. Adapt it into a more usable form by separating out tests and shared helper functions. Since we test functions that are declared statically in mm/vma.c, we make use of the trick of #include'ing kernel C files directly. In order for the tests to continue to function, we must therefore also this way into the tests/ directory. We try to keep as much shared logic actually modularised into a separate compilation unit in shared.c, however the merge_existing() and attach_vma() helpers rely on statically declared mm/vma.c functions so these must be declared in main.c. Link: https://lkml.kernel.org/r/a0455ccfe4fdcd1c962c64f76304f612e5662a4e.1769097829.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Barry Song <baohua@kernel.org> Cc: David Hildenbrand <david@kernel.org> Cc: Dev Jain <dev.jain@arm.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Zi Yan <ziy@nvidia.com> Cc: Damien Le Moal <dlemoal@kernel.org> Cc: "Darrick J. Wong" <djwong@kernel.org> Cc: Jarkko Sakkinen <jarkko@kernel.org> Cc: Yury Norov <ynorov@nvidia.com> Cc: Chris Mason <clm@fb.com> Cc: Pedro Falcato <pfalcato@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
57 lines
1.4 KiB
C
57 lines
1.4 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
static bool test_mmap_region_basic(void)
|
|
{
|
|
struct mm_struct mm = {};
|
|
unsigned long addr;
|
|
struct vm_area_struct *vma;
|
|
VMA_ITERATOR(vmi, &mm, 0);
|
|
|
|
current->mm = &mm;
|
|
|
|
/* Map at 0x300000, length 0x3000. */
|
|
addr = __mmap_region(NULL, 0x300000, 0x3000,
|
|
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE,
|
|
0x300, NULL);
|
|
ASSERT_EQ(addr, 0x300000);
|
|
|
|
/* Map at 0x250000, length 0x3000. */
|
|
addr = __mmap_region(NULL, 0x250000, 0x3000,
|
|
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE,
|
|
0x250, NULL);
|
|
ASSERT_EQ(addr, 0x250000);
|
|
|
|
/* Map at 0x303000, merging to 0x300000 of length 0x6000. */
|
|
addr = __mmap_region(NULL, 0x303000, 0x3000,
|
|
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE,
|
|
0x303, NULL);
|
|
ASSERT_EQ(addr, 0x303000);
|
|
|
|
/* Map at 0x24d000, merging to 0x250000 of length 0x6000. */
|
|
addr = __mmap_region(NULL, 0x24d000, 0x3000,
|
|
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE,
|
|
0x24d, NULL);
|
|
ASSERT_EQ(addr, 0x24d000);
|
|
|
|
ASSERT_EQ(mm.map_count, 2);
|
|
|
|
for_each_vma(vmi, vma) {
|
|
if (vma->vm_start == 0x300000) {
|
|
ASSERT_EQ(vma->vm_end, 0x306000);
|
|
ASSERT_EQ(vma->vm_pgoff, 0x300);
|
|
} else if (vma->vm_start == 0x24d000) {
|
|
ASSERT_EQ(vma->vm_end, 0x253000);
|
|
ASSERT_EQ(vma->vm_pgoff, 0x24d);
|
|
} else {
|
|
ASSERT_FALSE(true);
|
|
}
|
|
}
|
|
|
|
cleanup_mm(&mm, &vmi);
|
|
return true;
|
|
}
|
|
|
|
static void run_mmap_tests(int *num_tests, int *num_fail)
|
|
{
|
|
TEST(mmap_region_basic);
|
|
}
|