Skip to content

Commit b2fe178

Browse files
selftests/mm: hugetlb_fault_after_madv: improve test output
JIRA: https://issues.redhat.com/browse/RHEL-60023 commit f33cea9 Author: David Hildenbrand <david@redhat.com> AuthorDate: Thu Sep 26 17:20:44 2024 +0200 Commit: Andrew Morton <akpm@linux-foundation.org> CommitDate: Tue Nov 5 16:56:25 2024 -0800 selftests/mm: hugetlb_fault_after_madv: improve test output Let's improve the test output. For example, print the proper test result. Install a SIGBUS handler to catch any SIGBUS instead of crashing the test on failure. With unsuitable hugetlb page count: $ ./hugetlb_fault_after_madv TAP version 13 1..1 # [INFO] detected default hugetlb page size: 2048 KiB ok 2 # SKIP This test needs one and only one page to execute. Got 0 # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0 On a failure: $ ./hugetlb_fault_after_madv TAP version 13 1..1 not ok 1 SIGBUS behavior Bail out! 1 out of 1 tests failed On success: $ ./hugetlb_fault_after_madv TAP version 13 1..1 # [INFO] detected default hugetlb page size: 2048 KiB ok 1 SIGBUS behavior # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 Link: https://lkml.kernel.org/r/20240926152044.2205129-3-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Breno Leitao <leitao@debian.org> Tested-by: Mario Casquero <mcasquer@redhat.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: David Hildenbrand <david@redhat.com>
1 parent 8c52409 commit b2fe178

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

tools/testing/selftests/mm/hugetlb_fault_after_madv.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <sys/mman.h>
66
#include <sys/types.h>
77
#include <unistd.h>
8+
#include <setjmp.h>
9+
#include <signal.h>
810

911
#include "vm_util.h"
1012
#include "../kselftest.h"
@@ -14,11 +16,25 @@
1416
static char *huge_ptr;
1517
static size_t huge_page_size;
1618

19+
static sigjmp_buf sigbuf;
20+
static bool sigbus_triggered;
21+
22+
static void signal_handler(int signal)
23+
{
24+
if (signal == SIGBUS) {
25+
sigbus_triggered = true;
26+
siglongjmp(sigbuf, 1);
27+
}
28+
}
29+
1730
/* Touch the memory while it is being madvised() */
1831
void *touch(void *unused)
1932
{
2033
char *ptr = (char *)huge_ptr;
2134

35+
if (sigsetjmp(sigbuf, 1))
36+
return NULL;
37+
2238
for (int i = 0; i < INLOOP_ITER; i++)
2339
ptr[0] = '.';
2440

@@ -44,13 +60,23 @@ int main(void)
4460
* interactions
4561
*/
4662
int max = 10000;
63+
int err;
64+
65+
ksft_print_header();
66+
ksft_set_plan(1);
4767

4868
srand(getpid());
4969

70+
if (signal(SIGBUS, signal_handler) == SIG_ERR)
71+
ksft_exit_skip("Could not register signal handler.");
72+
5073
huge_page_size = default_huge_page_size();
5174
if (!huge_page_size)
5275
ksft_exit_skip("Could not detect default hugetlb page size.");
5376

77+
ksft_print_msg("[INFO] detected default hugetlb page size: %zu KiB\n",
78+
huge_page_size / 1024);
79+
5480
free_hugepages = get_free_hugepages();
5581
if (free_hugepages != 1) {
5682
ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n",
@@ -73,5 +99,11 @@ int main(void)
7399
munmap(huge_ptr, huge_page_size);
74100
}
75101

76-
return KSFT_PASS;
102+
ksft_test_result(!sigbus_triggered, "SIGBUS behavior\n");
103+
104+
err = ksft_get_fail_cnt();
105+
if (err)
106+
ksft_exit_fail_msg("%d out of %d tests failed\n",
107+
err, ksft_test_num());
108+
ksft_exit_pass();
77109
}

0 commit comments

Comments
 (0)