mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
selftests/mm: hugetlb-vmemmap: use kselftest framework
Convert hugetlb-vmemmap test to use kselftest framework for reporting and tracking successful and failing runs. Link: https://lore.kernel.org/20260511162840.375890-10-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Donet Tom <donettom@linux.ibm.com> Reviewed-by: Mark Brown <broonie@kernel.org> Tested-by: Sarthak Sharma <sarthak.sharma@arm.com> Tested-by: Luiz Capitulino <luizcap@redhat.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@ziepe.ca> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Lance Yang <lance.yang@linux.dev> Cc: Leon Romanovsky <leon@kernel.org> Cc: Liam Howlett <liam@infradead.org> Cc: Li Wang <li.wang@linux.dev> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Nico Pache <npache@redhat.com> Cc: Peter Xu <peterx@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
f62c93fa8b
commit
40e9e3d760
|
|
@ -63,7 +63,7 @@ static int check_page_flags(unsigned long pfn)
|
|||
read(fd, &pageflags, sizeof(pageflags));
|
||||
if ((pageflags & HEAD_PAGE_FLAGS) != HEAD_PAGE_FLAGS) {
|
||||
close(fd);
|
||||
printf("Head page flags (%lx) is invalid\n", pageflags);
|
||||
ksft_print_msg("Head page flags (%lx) is invalid\n", pageflags);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ static int check_page_flags(unsigned long pfn)
|
|||
if ((pageflags & TAIL_PAGE_FLAGS) != TAIL_PAGE_FLAGS ||
|
||||
(pageflags & HEAD_PAGE_FLAGS) == HEAD_PAGE_FLAGS) {
|
||||
close(fd);
|
||||
printf("Tail page flags (%lx) is invalid\n", pageflags);
|
||||
ksft_print_msg("Tail page flags (%lx) is invalid\n", pageflags);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -91,44 +91,38 @@ int main(int argc, char **argv)
|
|||
{
|
||||
void *addr;
|
||||
unsigned long pfn;
|
||||
int ret;
|
||||
|
||||
ksft_print_header();
|
||||
ksft_set_plan(1);
|
||||
|
||||
pagesize = psize();
|
||||
maplength = default_huge_page_size();
|
||||
if (!maplength) {
|
||||
printf("Unable to determine huge page size\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!maplength)
|
||||
ksft_exit_skip("Unable to determine huge page size\n");
|
||||
|
||||
addr = mmap(NULL, maplength, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
|
||||
if (addr == MAP_FAILED) {
|
||||
perror("mmap");
|
||||
exit(1);
|
||||
}
|
||||
if (addr == MAP_FAILED)
|
||||
ksft_exit_fail_perror("mmap");
|
||||
|
||||
/* Trigger allocation of HugeTLB page. */
|
||||
write_bytes(addr, maplength);
|
||||
|
||||
pfn = virt_to_pfn(addr);
|
||||
if (pfn == -1UL) {
|
||||
ksft_perror("virt_to_pfn");
|
||||
munmap(addr, maplength);
|
||||
perror("virt_to_pfn");
|
||||
exit(1);
|
||||
ksft_exit_fail();
|
||||
}
|
||||
|
||||
printf("Returned address is %p whose pfn is %lx\n", addr, pfn);
|
||||
ksft_print_msg("Returned address is %p whose pfn is %lx\n", addr, pfn);
|
||||
|
||||
if (check_page_flags(pfn) < 0) {
|
||||
munmap(addr, maplength);
|
||||
perror("check_page_flags");
|
||||
exit(1);
|
||||
}
|
||||
ret = check_page_flags(pfn);
|
||||
|
||||
/* munmap() length of MAP_HUGETLB memory must be hugepage aligned */
|
||||
if (munmap(addr, maplength)) {
|
||||
perror("munmap");
|
||||
exit(1);
|
||||
}
|
||||
if (munmap(addr, maplength))
|
||||
ksft_exit_fail_perror("munmap");
|
||||
|
||||
return 0;
|
||||
ksft_test_result(!ret, "HugeTLB vmemmap page flags\n");
|
||||
ksft_finished();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user