Hi Mike!

On 4/18/26 4:24 PM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <[email protected]>
> 
> Convert hugetlb-vmemmap test to use kselftest framework for reporting
> and tracking successful and failing runs.
> 
> Reviewed-by: Mark Brown <[email protected]>
> Reviewed by: Donet Tom <[email protected]>
> Signed-off-by: Mike Rapoport (Microsoft) <[email protected]>

I have run the test before and after applying the patch. The patch
correctly formats the output according to KTAP format with no change in
results.

Tested-by: Sarthak Sharma <[email protected]>

> ---
>  tools/testing/selftests/mm/hugetlb-vmemmap.c | 42 +++++++++-----------
>  1 file changed, 18 insertions(+), 24 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb-vmemmap.c 
> b/tools/testing/selftests/mm/hugetlb-vmemmap.c
> index df366a4d1b92..485a6978b40f 100644
> --- a/tools/testing/selftests/mm/hugetlb-vmemmap.c
> +++ b/tools/testing/selftests/mm/hugetlb-vmemmap.c
> @@ -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();
>  }


Reply via email to