Re: [PATCH v2 10/53] selftests/mm: hugetlb_madv_vs_map: use kselftest framework

Sarthak Sharma
2026-04-27T08:50:49Z

Hi Mike!

On 4/18/26 4:24 PM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
>
> Convert hugetlb_madv_vs_map test to use kselftest framework for
> reporting and tracking successful and failing runs.
>
> Reviewed-by: Mark Brown <broonie@kernel.org>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> .../testing/selftests/mm/hugetlb_madv_vs_map.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> index efd774b41389..c7105c6d319b 100644
> --- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> +++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> @@ -25,7 +25,6 @@
> #include <unistd.h>
>
> #include "vm_util.h"
> -#include "kselftest.h"
>
> #define INLOOP_ITER 100
>
> @@ -86,12 +85,14 @@ int main(void)
> */
> int max = 10;
>
> + ksft_print_header();
> + ksft_set_plan(1);
> +
> free_hugepages = get_free_hugepages();
>
> - if (free_hugepages != 1) {
> + if (free_hugepages != 1)
> ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n",
> free_hugepages);
> - }

There is a comment in kselftest.h which says "
/*
* FIXME: several tests misuse ksft_exit_skip so produce
* something sensible if some tests have already been run
* or a plan has been printed. Those tests should use
* ksft_test_result_skip or ksft_exit_fail_msg instead.
*/
"

When I ran this test after setting nr_hugepages to be anything other
than 1, I got this output:

TAP version 13
1..1
ok 2 # SKIP This test needs one and only one page to execute. Got 128
# 1 skipped test(s) detected. Consider enabling relevant config options
to improve coverage.
# Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0

where the result should have been reported as ok 1, not ok 2.

Seems like there is something wrong in ksft_exit_skip(). Should we
change this ksft_exit_skip() to ksft_test_result_skip() followed by
ksft_finished()?

>
> mmap_size = default_huge_page_size();
>
> @@ -100,10 +101,8 @@ int main(void)
> MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
> -1, 0);
>
> - if ((unsigned long)huge_ptr == -1) {
> - ksft_test_result_fail("Failed to allocate huge page\n");
> - return KSFT_FAIL;
> - }
> + if ((unsigned long)huge_ptr == -1)
> + ksft_exit_fail_msg("Failed to allocate huge page\n");
>
> pthread_create(&thread1, NULL, madv, NULL);
> pthread_create(&thread2, NULL, touch, NULL);
> @@ -115,12 +114,13 @@ int main(void)
>
> if (ret) {
> ksft_test_result_fail("Unexpected huge page allocation\n");
> - return KSFT_FAIL;
> + ksft_finished();
> }
>
> /* Unmap and restart */
> munmap(huge_ptr, mmap_size);
> }
>
> - return KSFT_PASS;
> + ksft_test_result_pass("No unexpected huge page allocations\n");
> + ksft_finished();
> }